]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libarchive/archive_hash.h
Always check memory allocation failure. If driver encounter memory
[FreeBSD/FreeBSD.git] / lib / libarchive / archive_hash.h
1 /*-
2  * Copyright (c) 2009 Joerg Sonnenberger
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17  * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  * $FreeBSD$
26  */
27
28 #ifndef __LIBARCHIVE_BUILD
29 #error This header is only to be used internally to libarchive.
30 #endif
31
32 /*
33  * Hash function support in various Operating Systems:
34  *
35  * NetBSD:
36  * - MD5 and SHA1 in libc: without _ after algorithm name
37  * - SHA2 in libc: with _ after algorithm name
38  *
39  * OpenBSD:
40  * - MD5, SHA1 and SHA2 in libc: without _ after algorithm name
41  * - OpenBSD 4.4 and earlier have SHA2 in libc with _ after algorithm name
42  *
43  * DragonFly and FreeBSD (XXX not used yet):
44  * - MD5 and SHA1 in libmd: without _ after algorithm name
45  * - SHA256: with _ after algorithm name
46  *
47  * OpenSSL:
48  * - MD5, SHA1 and SHA2 in libcrypto: with _ after algorithm name
49  */
50
51 #if defined(HAVE_MD5_H) && defined(HAVE_MD5INIT)
52 #  include <md5.h>
53 #  define ARCHIVE_HAS_MD5
54 typedef MD5_CTX archive_md5_ctx;
55 #  define archive_md5_init(ctx)                 MD5Init(ctx)
56 #  define archive_md5_final(ctx, buf)           MD5Final(buf, ctx)
57 #  define archive_md5_update(ctx, buf, n)       MD5Update(ctx, buf, n)
58 #elif defined(HAVE_OPENSSL_MD5_H)
59 #  include <openssl/md5.h>
60 #  define ARCHIVE_HAS_MD5
61 typedef MD5_CTX archive_md5_ctx;
62 #  define archive_md5_init(ctx)                 MD5_Init(ctx)
63 #  define archive_md5_final(ctx, buf)           MD5_Final(buf, ctx)
64 #  define archive_md5_update(ctx, buf, n)       MD5_Update(ctx, buf, n)
65 #elif defined(_WIN32) && !defined(__CYGWIN__) && defined(CALG_MD5)
66 #  define ARCHIVE_HAS_MD5
67 typedef MD5_CTX archive_md5_ctx;
68 #  define archive_md5_init(ctx)                 MD5_Init(ctx)
69 #  define archive_md5_final(ctx, buf)           MD5_Final(buf, ctx)
70 #  define archive_md5_update(ctx, buf, n)       MD5_Update(ctx, buf, n)
71 #endif
72
73 #if defined(HAVE_RMD160_H) && defined(HAVE_RMD160INIT)
74 #  include <rmd160.h>
75 #  define ARCHIVE_HAS_RMD160
76 typedef RMD160_CTX archive_rmd160_ctx;
77 #  define archive_rmd160_init(ctx)              RMD160Init(ctx)
78 #  define archive_rmd160_final(ctx, buf)        RMD160Final(buf, ctx)
79 #  define archive_rmd160_update(ctx, buf, n)    RMD160Update(ctx, buf, n)
80 #elif defined(HAVE_OPENSSL_RIPEMD_H)
81 #  include <openssl/ripemd.h>
82 #  define ARCHIVE_HAS_RMD160
83 typedef RIPEMD160_CTX archive_rmd160_ctx;
84 #  define archive_rmd160_init(ctx)              RIPEMD160_Init(ctx)
85 #  define archive_rmd160_final(ctx, buf)        RIPEMD160_Final(buf, ctx)
86 #  define archive_rmd160_update(ctx, buf, n)    RIPEMD160_Update(ctx, buf, n)
87 #endif
88
89 #if defined(HAVE_SHA1_H) && defined(HAVE_SHA1INIT)
90 #  include <sha1.h>
91 #  define ARCHIVE_HAS_SHA1
92 typedef SHA1_CTX archive_sha1_ctx;
93 #  define archive_sha1_init(ctx)                SHA1Init(ctx)
94 #  define archive_sha1_final(ctx, buf)          SHA1Final(buf, ctx)
95 #  define archive_sha1_update(ctx, buf, n)      SHA1Update(ctx, buf, n)
96 #elif defined(HAVE_OPENSSL_SHA_H)
97 #  include <openssl/sha.h>
98 #  define ARCHIVE_HAS_SHA1
99 typedef SHA_CTX archive_sha1_ctx;
100 #  define archive_sha1_init(ctx)                SHA1_Init(ctx)
101 #  define archive_sha1_final(ctx, buf)          SHA1_Final(buf, ctx)
102 #  define archive_sha1_update(ctx, buf, n)      SHA1_Update(ctx, buf, n)
103 #elif defined(_WIN32) && !defined(__CYGWIN__) && defined(CALG_SHA1)
104 #  define ARCHIVE_HAS_SHA1
105 typedef SHA1_CTX archive_sha1_ctx;
106 #  define archive_sha1_init(ctx)                SHA1_Init(ctx)
107 #  define archive_sha1_final(ctx, buf)          SHA1_Final(buf, ctx)
108 #  define archive_sha1_update(ctx, buf, n)      SHA1_Update(ctx, buf, n)
109 #endif
110
111 #if defined(HAVE_SHA2_H) && defined(HAVE_SHA256_INIT)
112 #  include <sha2.h>
113 #  define ARCHIVE_HAS_SHA256
114 typedef SHA256_CTX archive_sha256_ctx;
115 #  define archive_sha256_init(ctx)              SHA256_Init(ctx)
116 #  define archive_sha256_final(ctx, buf)        SHA256_Final(buf, ctx)
117 #  define archive_sha256_update(ctx, buf, n)    SHA256_Update(ctx, buf, n)
118 #elif defined(HAVE_SHA2_H) && defined(HAVE_SHA256INIT)
119 #  include <sha2.h>
120 #  define ARCHIVE_HAS_SHA256
121 typedef SHA256_CTX archive_sha256_ctx;
122 #  define archive_sha256_init(ctx)              SHA256Init(ctx)
123 #  define archive_sha256_final(ctx, buf)        SHA256Final(buf, ctx)
124 #  define archive_sha256_update(ctx, buf, n)    SHA256Update(ctx, buf, n)
125 #elif defined(HAVE_OPENSSL_SHA_H) && defined(HAVE_OPENSSL_SHA256_INIT)
126 #  include <openssl/sha.h>
127 #  define ARCHIVE_HAS_SHA256
128 typedef SHA256_CTX archive_sha256_ctx;
129 #  define archive_sha256_init(ctx)              SHA256_Init(ctx)
130 #  define archive_sha256_final(ctx, buf)        SHA256_Final(buf, ctx)
131 #  define archive_sha256_update(ctx, buf, n)    SHA256_Update(ctx, buf, n)
132 #elif defined(_WIN32) && !defined(__CYGWIN__) && defined(CALG_SHA_256)
133 #  define ARCHIVE_HAS_SHA256
134 typedef SHA256_CTX archive_sha256_ctx;
135 #  define archive_sha256_init(ctx)              SHA256_Init(ctx)
136 #  define archive_sha256_final(ctx, buf)        SHA256_Final(buf, ctx)
137 #  define archive_sha256_update(ctx, buf, n)    SHA256_Update(ctx, buf, n)
138 #endif
139
140 #if defined(HAVE_SHA2_H) && defined(HAVE_SHA384_INIT)
141 #  include <sha2.h>
142 #  define ARCHIVE_HAS_SHA384
143 typedef SHA384_CTX archive_sha384_ctx;
144 #  define archive_sha384_init(ctx)              SHA384_Init(ctx)
145 #  define archive_sha384_final(ctx, buf)        SHA384_Final(buf, ctx)
146 #  define archive_sha384_update(ctx, buf, n)    SHA384_Update(ctx, buf, n)
147 #elif defined(HAVE_SHA2_H) && defined(HAVE_SHA384INIT)
148 #  include <sha2.h>
149 #  define ARCHIVE_HAS_SHA384
150 typedef SHA384_CTX archive_sha384_ctx;
151 #  define archive_sha384_init(ctx)              SHA384Init(ctx)
152 #  define archive_sha384_final(ctx, buf)        SHA384Final(buf, ctx)
153 #  define archive_sha384_update(ctx, buf, n)    SHA384Update(ctx, buf, n)
154 #elif defined(HAVE_OPENSSL_SHA_H) && defined(HAVE_OPENSSL_SHA384_INIT)
155 #  include <openssl/sha.h>
156 #  define ARCHIVE_HAS_SHA384
157 typedef SHA512_CTX archive_sha384_ctx;
158 #  define archive_sha384_init(ctx)              SHA384_Init(ctx)
159 #  define archive_sha384_final(ctx, buf)        SHA384_Final(buf, ctx)
160 #  define archive_sha384_update(ctx, buf, n)    SHA384_Update(ctx, buf, n)
161 #elif defined(_WIN32) && !defined(__CYGWIN__) && defined(CALG_SHA_384)
162 #  define ARCHIVE_HAS_SHA384
163 typedef SHA512_CTX archive_sha384_ctx;
164 #  define archive_sha384_init(ctx)              SHA384_Init(ctx)
165 #  define archive_sha384_final(ctx, buf)        SHA384_Final(buf, ctx)
166 #  define archive_sha384_update(ctx, buf, n)    SHA384_Update(ctx, buf, n)
167 #endif
168
169 #if defined(HAVE_SHA2_H) && defined(HAVE_SHA512_INIT)
170 #  include <sha2.h>
171 #  define ARCHIVE_HAS_SHA512
172 typedef SHA512_CTX archive_sha512_ctx;
173 #  define archive_sha512_init(ctx)              SHA512_Init(ctx)
174 #  define archive_sha512_final(ctx, buf)        SHA512_Final(buf, ctx)
175 #  define archive_sha512_update(ctx, buf, n)    SHA512_Update(ctx, buf, n)
176 #elif defined(HAVE_SHA2_H) && defined(HAVE_SHA512INIT)
177 #  include <sha2.h>
178 #  define ARCHIVE_HAS_SHA512
179 typedef SHA512_CTX archive_sha512_ctx;
180 #  define archive_sha512_init(ctx)              SHA512Init(ctx)
181 #  define archive_sha512_final(ctx, buf)        SHA512Final(buf, ctx)
182 #  define archive_sha512_update(ctx, buf, n)    SHA512Update(ctx, buf, n)
183 #elif defined(HAVE_OPENSSL_SHA_H) && defined(HAVE_OPENSSL_SHA512_INIT)
184 #  include <openssl/sha.h>
185 #  define ARCHIVE_HAS_SHA512
186 typedef SHA512_CTX archive_sha512_ctx;
187 #  define archive_sha512_init(ctx)              SHA512_Init(ctx)
188 #  define archive_sha512_final(ctx, buf)        SHA512_Final(buf, ctx)
189 #  define archive_sha512_update(ctx, buf, n)    SHA512_Update(ctx, buf, n)
190 #elif defined(_WIN32) && !defined(__CYGWIN__) && defined(CALG_SHA_512)
191 #  define ARCHIVE_HAS_SHA512
192 typedef SHA512_CTX archive_sha512_ctx;
193 #  define archive_sha512_init(ctx)              SHA512_Init(ctx)
194 #  define archive_sha512_final(ctx, buf)        SHA512_Final(buf, ctx)
195 #  define archive_sha512_update(ctx, buf, n)    SHA512_Update(ctx, buf, n)
196 #endif