10 #define SHA1_HASH_SIZE 20
12 extern const u8 zero_hash[SHA1_HASH_SIZE];
15 copy_hash(u8 dest[SHA1_HASH_SIZE], const u8 src[SHA1_HASH_SIZE])
17 memcpy(dest, src, SHA1_HASH_SIZE);
21 random_hash(u8 hash[SHA1_HASH_SIZE])
23 randomize_byte_array(hash, SHA1_HASH_SIZE);
27 hashes_equal(const u8 h1[SHA1_HASH_SIZE], const u8 h2[SHA1_HASH_SIZE])
29 return memcmp(h1, h2, SHA1_HASH_SIZE) == 0;
33 hashes_cmp(const u8 h1[SHA1_HASH_SIZE],
34 const u8 h2[SHA1_HASH_SIZE])
36 return memcmp(h1, h2, SHA1_HASH_SIZE);
40 print_hash(const u8 hash[SHA1_HASH_SIZE], FILE *out)
42 print_byte_field(hash, SHA1_HASH_SIZE, out);
46 is_zero_hash(const u8 hash[SHA1_HASH_SIZE])
49 for (u8 i = 0; i < SHA1_HASH_SIZE / 4; i++)
56 zero_out_hash(u8 hash[SHA1_HASH_SIZE])
58 memset(hash, 0, SHA1_HASH_SIZE);
64 #include <openssl/sha.h>
66 sha1_buffer(const void *buffer, size_t len, u8 hash[SHA1_HASH_SIZE])
68 SHA1(buffer, len, hash);
70 #define sha1_init SHA1_Init
71 #define sha1_update SHA1_Update
72 #define sha1_final SHA1_Final
74 #else /* WITH_LIBCRYPTO */
83 sha1_buffer(const void *buffer, size_t len, u8 hash[SHA1_HASH_SIZE]);
86 sha1_init(SHA_CTX *ctx);
89 sha1_update(SHA_CTX *ctx, const void *data, size_t len);
92 sha1_final(u8 hash[SHA1_HASH_SIZE], SHA_CTX *ctx);
94 #endif /* !WITH_LIBCRYPTO */
97 sha1sum(const tchar *filename, u8 hash[SHA1_HASH_SIZE]);
99 #endif /* _WIMLIB_SHA1_H */