]> wimlib.net Git - wimlib/blob - src/sha1.h
More timestamp changes: Set timestamp on extracted files
[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 extern const u8 empty_file_sha1sum[SHA1_HASH_SIZE];
13
14 static inline bool is_empty_file_hash(const u8 hash[SHA1_HASH_SIZE])
15 {
16         return memcmp(hash, empty_file_sha1sum, SHA1_HASH_SIZE) == 0;
17 }
18
19 static inline void copy_hash(u8 dest[SHA1_HASH_SIZE],
20                              const u8 src[SHA1_HASH_SIZE])
21 {
22         memcpy(dest, src, SHA1_HASH_SIZE);
23 }
24
25 static inline void random_hash(u8 hash[SHA1_HASH_SIZE])
26 {
27         randomize_byte_array(hash, SHA1_HASH_SIZE);
28 }
29
30 static inline bool hashes_equal(const u8 h1[SHA1_HASH_SIZE],
31                                 const u8 h2[SHA1_HASH_SIZE])
32 {
33         return memcmp(h1, h2, SHA1_HASH_SIZE) == 0;
34 }
35
36 /* Prints a hash code field. */
37 static inline void print_hash(const u8 hash[])
38 {
39         print_byte_field(hash, SHA1_HASH_SIZE);
40 }
41
42 extern int sha1sum(const char *filename, void *md);
43
44 #ifdef WITH_LIBCRYPTO
45 #include <openssl/sha.h>
46 static inline void sha1_buffer(const void *buffer, size_t len, void *md)
47 {
48         SHA1(buffer, len, md);
49 }
50 #else
51 extern void sha1_buffer(const void *buffer, size_t len, void *md);
52 #endif
53
54 #endif /* _WIMLIB_SHA1_H */