4 * The author dedicates this file to the public domain.
5 * You can do whatever you want with this file.
11 #include "wimlib/types.h"
12 #include "wimlib/util.h"
16 #define SHA1_HASH_SIZE 20
18 extern const u8 zero_hash[SHA1_HASH_SIZE];
21 sprint_hash(const u8 hash[SHA1_HASH_SIZE], tchar strbuf[SHA1_HASH_SIZE * 2 + 1]);
24 copy_hash(u8 dest[SHA1_HASH_SIZE], const u8 src[SHA1_HASH_SIZE])
26 memcpy(dest, src, SHA1_HASH_SIZE);
30 random_hash(u8 hash[SHA1_HASH_SIZE])
32 randomize_byte_array(hash, SHA1_HASH_SIZE);
36 hashes_cmp(const u8 h1[SHA1_HASH_SIZE], const u8 h2[SHA1_HASH_SIZE])
38 return memcmp(h1, h2, SHA1_HASH_SIZE);
42 hashes_equal(const u8 h1[SHA1_HASH_SIZE], const u8 h2[SHA1_HASH_SIZE])
44 return !hashes_cmp(h1, h2);
48 is_zero_hash(const u8 *hash)
50 return (hash == zero_hash || hashes_equal(hash, zero_hash));
54 zero_out_hash(u8 hash[SHA1_HASH_SIZE])
56 copy_hash(hash, zero_hash);
61 #include <openssl/sha.h>
63 #define sha1_init SHA1_Init
64 #define sha1_update SHA1_Update
65 #define sha1_final SHA1_Final
68 sha1_buffer(const void *buffer, size_t len, u8 hash[SHA1_HASH_SIZE])
70 SHA1(buffer, len, hash);
73 #else /* WITH_LIBCRYPTO */
82 sha1_init(SHA_CTX *ctx);
85 sha1_update(SHA_CTX *ctx, const void *data, size_t len);
88 sha1_final(u8 hash[SHA1_HASH_SIZE], SHA_CTX *ctx);
91 sha1_buffer(const void *buffer, size_t len, u8 hash[SHA1_HASH_SIZE]);
93 #endif /* !WITH_LIBCRYPTO */
95 #endif /* _WIMLIB_SHA1_H */