]> wimlib.net Git - wimlib/blob - src/sha1.h
7ec8456d20cee8cf633c51ef04617bfa1024cdf0
[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
9 #define SHA1_HASH_SIZE 20
10
11 extern const u8 empty_file_sha1sum[SHA1_HASH_SIZE];
12
13 static inline bool is_empty_file_hash(const u8 hash[SHA1_HASH_SIZE])
14 {
15         return memcmp(hash, empty_file_sha1sum, SHA1_HASH_SIZE) == 0;
16 }
17
18 /* Compute SHA1 message digest for bytes read from STREAM.  The
19    resulting message digest number will be written into the 20 bytes
20    beginning at RESBLOCK.  */
21 extern int sha1_stream(FILE * stream, void *resblock);
22
23 #ifdef WITH_LIBCRYPTO
24 #include <openssl/sha.h>
25 static inline void *sha1_buffer(const char *buffer, size_t len, void *resblock)
26 {
27         return SHA1(buffer, len, resblock);
28 }
29 #else
30 /* Compute SHA1 message digest for LEN bytes beginning at BUFFER.  The
31    result is always in little endian byte order, so that a byte-wise
32    output yields to the wanted ASCII representation of the message
33    digest.  */
34 extern void *sha1_buffer(const char *buffer, size_t len, void *resblock);
35 #endif
36
37
38 #endif /* _WIMLIB_SHA1_H */