4 * The following copying information applies to this specific source code file:
6 * Written in 2013-2015 by Eric Biggers <ebiggers3@gmail.com>
8 * To the extent possible under law, the author(s) have dedicated all copyright
9 * and related and neighboring rights to this software to the public domain
10 * worldwide via the Creative Commons Zero 1.0 Universal Public Domain
11 * Dedication (the "CC0").
13 * This software is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the CC0 for more details.
17 * You should have received a copy of the CC0 along with this software; if not
18 * see <http://creativecommons.org/publicdomain/zero/1.0/>.
21 #ifndef _WIMLIB_SHA1_H
22 #define _WIMLIB_SHA1_H
26 #include "wimlib/types.h"
27 #include "wimlib/util.h"
29 #define SHA1_HASH_SIZE 20
31 extern const u8 zero_hash[SHA1_HASH_SIZE];
34 sprint_hash(const u8 hash[SHA1_HASH_SIZE], tchar strbuf[SHA1_HASH_SIZE * 2 + 1]);
37 copy_hash(u8 dest[SHA1_HASH_SIZE], const u8 src[SHA1_HASH_SIZE])
39 memcpy(dest, src, SHA1_HASH_SIZE);
43 hashes_cmp(const u8 h1[SHA1_HASH_SIZE], const u8 h2[SHA1_HASH_SIZE])
45 return memcmp(h1, h2, SHA1_HASH_SIZE);
49 hashes_equal(const u8 h1[SHA1_HASH_SIZE], const u8 h2[SHA1_HASH_SIZE])
51 return !hashes_cmp(h1, h2);
55 is_zero_hash(const u8 *hash)
57 return (hash == zero_hash || hashes_equal(hash, zero_hash));
62 #include <openssl/sha.h>
64 #define sha1_init SHA1_Init
65 #define sha1_update SHA1_Update
66 #define sha1_final SHA1_Final
69 sha1_buffer(const void *buffer, size_t len, u8 hash[SHA1_HASH_SIZE])
71 SHA1(buffer, len, hash);
74 #else /* WITH_LIBCRYPTO */
83 sha1_init(SHA_CTX *ctx);
86 sha1_update(SHA_CTX *ctx, const void *data, size_t len);
89 sha1_final(u8 hash[SHA1_HASH_SIZE], SHA_CTX *ctx);
92 sha1_buffer(const void *buffer, size_t len, u8 hash[SHA1_HASH_SIZE]);
94 #endif /* !WITH_LIBCRYPTO */
96 #endif /* _WIMLIB_SHA1_H */