10 #define SHA1_HASH_SIZE 20
12 static inline void copy_hash(u8 dest[SHA1_HASH_SIZE],
13 const u8 src[SHA1_HASH_SIZE])
15 memcpy(dest, src, SHA1_HASH_SIZE);
18 static inline void random_hash(u8 hash[SHA1_HASH_SIZE])
20 randomize_byte_array(hash, SHA1_HASH_SIZE);
23 static inline bool hashes_equal(const u8 h1[SHA1_HASH_SIZE],
24 const u8 h2[SHA1_HASH_SIZE])
26 return memcmp(h1, h2, SHA1_HASH_SIZE) == 0;
29 /* Prints a hash code field. */
30 static inline void print_hash(const u8 hash[SHA1_HASH_SIZE])
32 print_byte_field(hash, SHA1_HASH_SIZE);
35 static inline bool is_zero_hash(const u8 hash[SHA1_HASH_SIZE])
37 for (u8 i = 0; i < SHA1_HASH_SIZE / 4; i++)
43 static void zero_hash(u8 hash[SHA1_HASH_SIZE])
45 memset(hash, 0, SHA1_HASH_SIZE);
51 #include <openssl/sha.h>
52 #define sha1_buffer SHA1
53 #define sha1_init SHA1_Init
54 #define sha1_update SHA1_Update
55 #define sha1_final SHA1_Final
57 #else /* WITH_LIBCRYPTO */
65 extern void sha1_buffer(const u8 buffer[], size_t len, u8 hash[SHA1_HASH_SIZE]);
66 extern void sha1_init(SHA_CTX *ctx);
67 extern void sha1_update(SHA_CTX *ctx, const u8 data[], size_t len);
68 extern void sha1_final(u8 hash[SHA1_HASH_SIZE], SHA_CTX *ctx);
70 #endif /* !WITH_LIBCRYPTO */
72 extern int sha1sum(const char *filename, u8 hash[SHA1_HASH_SIZE]);
76 #endif /* _WIMLIB_SHA1_H */