]> wimlib.net Git - wimlib/blob - src/sha1.h
db524e6de60d5a579804ace47682423e73dc9d60
[wimlib] / src / sha1.h
1 #ifndef _WIMLIB_SHA1_H
2 #define _WIMLIB_SHA1_H
3
4 #include "config.h"
5 #include <stdio.h>
6 #include <stddef.h>
7 #include "string.h"
8 #include "util.h"
9
10 #define SHA1_HASH_SIZE 20
11
12 static inline void copy_hash(u8 dest[SHA1_HASH_SIZE],
13                              const u8 src[SHA1_HASH_SIZE])
14 {
15         memcpy(dest, src, SHA1_HASH_SIZE);
16 }
17
18 static inline void random_hash(u8 hash[SHA1_HASH_SIZE])
19 {
20         randomize_byte_array(hash, SHA1_HASH_SIZE);
21 }
22
23 static inline bool hashes_equal(const u8 h1[SHA1_HASH_SIZE],
24                                 const u8 h2[SHA1_HASH_SIZE])
25 {
26         return memcmp(h1, h2, SHA1_HASH_SIZE) == 0;
27 }
28
29 /* Prints a hash code field. */
30 static inline void print_hash(const u8 hash[])
31 {
32         print_byte_field(hash, SHA1_HASH_SIZE);
33 }
34
35 extern int sha1sum(const char *filename, void *md);
36
37 #ifdef WITH_LIBCRYPTO
38 #include <openssl/sha.h>
39 static inline void sha1_buffer(const void *buffer, size_t len, void *md)
40 {
41         SHA1(buffer, len, md);
42 }
43 #else
44 extern void sha1_buffer(const void *buffer, size_t len, void *md);
45 #endif
46
47 #endif /* _WIMLIB_SHA1_H */