]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - wimboot/wimboot-2.7.3/src/sha1.h
1.1.07 release
[Ventoy.git] / wimboot / wimboot-2.7.3 / src / sha1.h
1 #ifndef _SHA1_H
2 #define _SHA1_H
3
4 /** @file
5 *
6 * SHA-1 algorithm
7 *
8 */
9
10 #include <stdint.h>
11
12 /** An SHA-1 digest */
13 struct sha1_digest {
14 /** Hash output */
15 uint32_t h[5];
16 };
17
18 /** An SHA-1 data block */
19 union sha1_block {
20 /** Raw bytes */
21 uint8_t byte[64];
22 /** Raw dwords */
23 uint32_t dword[16];
24 /** Final block structure */
25 struct {
26 /** Padding */
27 uint8_t pad[56];
28 /** Length in bits */
29 uint64_t len;
30 } final;
31 };
32
33 /** SHA-1 digest and data block
34 *
35 * The order of fields within this structure is designed to minimise
36 * code size.
37 */
38 struct sha1_digest_data {
39 /** Digest of data already processed */
40 struct sha1_digest digest;
41 /** Accumulated data */
42 union sha1_block data;
43 } __attribute__ (( packed ));
44
45 /** SHA-1 digest and data block */
46 union sha1_digest_data_dwords {
47 /** Digest and data block */
48 struct sha1_digest_data dd;
49 /** Raw dwords */
50 uint32_t dword[ sizeof ( struct sha1_digest_data ) /
51 sizeof ( uint32_t ) ];
52 };
53
54 /** An SHA-1 context */
55 struct sha1_context {
56 /** Amount of accumulated data */
57 size_t len;
58 /** Digest and accumulated data */
59 union sha1_digest_data_dwords ddd;
60 } __attribute__ (( packed ));
61
62 /** SHA-1 context size */
63 #define SHA1_CTX_SIZE sizeof ( struct sha1_context )
64
65 /** SHA-1 digest size */
66 #define SHA1_DIGEST_SIZE sizeof ( struct sha1_digest )
67
68 extern void sha1_init ( void *ctx );
69 extern void sha1_update ( void *ctx, const void *data, size_t len );
70 extern void sha1_final ( void *ctx, void *out );
71
72 #endif /* _SHA1_H */