4 #include "wimlib/types.h"
5 #include "wimlib/util.h"
9 #define SHA1_HASH_SIZE 20
11 extern const u8 zero_hash[SHA1_HASH_SIZE];
14 copy_hash(u8 dest[SHA1_HASH_SIZE], const u8 src[SHA1_HASH_SIZE])
16 memcpy(dest, src, SHA1_HASH_SIZE);
20 random_hash(u8 hash[SHA1_HASH_SIZE])
22 randomize_byte_array(hash, SHA1_HASH_SIZE);
26 hashes_cmp(const u8 h1[SHA1_HASH_SIZE], const u8 h2[SHA1_HASH_SIZE])
28 return memcmp(h1, h2, SHA1_HASH_SIZE);
32 hashes_equal(const u8 h1[SHA1_HASH_SIZE], const u8 h2[SHA1_HASH_SIZE])
34 return !hashes_cmp(h1, h2);
38 print_hash(const u8 hash[SHA1_HASH_SIZE], FILE *out)
40 print_byte_field(hash, SHA1_HASH_SIZE, out);
44 is_zero_hash(const u8 *hash)
46 return (hash == zero_hash || hashes_equal(hash, zero_hash));
50 zero_out_hash(u8 hash[SHA1_HASH_SIZE])
52 copy_hash(hash, zero_hash);
57 #include <openssl/sha.h>
59 #define sha1_init SHA1_Init
60 #define sha1_update SHA1_Update
61 #define sha1_final SHA1_Final
64 sha1_buffer(const void *buffer, size_t len, u8 hash[SHA1_HASH_SIZE])
66 SHA1(buffer, len, hash);
69 #else /* WITH_LIBCRYPTO */
78 sha1_init(SHA_CTX *ctx);
81 sha1_update(SHA_CTX *ctx, const void *data, size_t len);
84 sha1_final(u8 hash[SHA1_HASH_SIZE], SHA_CTX *ctx);
87 sha1_buffer(const void *buffer, size_t len, u8 hash[SHA1_HASH_SIZE]);
89 #endif /* !WITH_LIBCRYPTO */
91 #endif /* _WIMLIB_SHA1_H */