diff options
Diffstat (limited to 'src/microhttpd/sha1.h')
-rw-r--r-- | src/microhttpd/sha1.h | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/src/microhttpd/sha1.h b/src/microhttpd/sha1.h new file mode 100644 index 00000000..800a4909 --- /dev/null +++ b/src/microhttpd/sha1.h | |||
@@ -0,0 +1,98 @@ | |||
1 | /* | ||
2 | This file is part of libmicrohttpd | ||
3 | Copyright (C) 2019-2021 Karlson2k (Evgeny Grin) | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2.1 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library. | ||
17 | If not, see <http://www.gnu.org/licenses/>. | ||
18 | */ | ||
19 | |||
20 | /** | ||
21 | * @file microhttpd/sha1.h | ||
22 | * @brief Calculation of SHA-1 digest | ||
23 | * @author Karlson2k (Evgeny Grin) | ||
24 | */ | ||
25 | |||
26 | #ifndef MHD_SHA1_H | ||
27 | #define MHD_SHA1_H 1 | ||
28 | |||
29 | #include "mhd_options.h" | ||
30 | #include <stdint.h> | ||
31 | #include <stddef.h> | ||
32 | |||
33 | /** | ||
34 | * SHA-1 digest is kept internally as 5 32-bit words. | ||
35 | */ | ||
36 | #define _SHA1_DIGEST_LENGTH 5 | ||
37 | |||
38 | /** | ||
39 | * Size of SHA-1 digest in bytes | ||
40 | */ | ||
41 | #define SHA1_DIGEST_SIZE (_SHA1_DIGEST_LENGTH * 4) | ||
42 | |||
43 | /** | ||
44 | * Size of SHA-1 digest string in chars including termination NUL | ||
45 | */ | ||
46 | #define SHA1_DIGEST_STRING_SIZE ((SHA1_DIGEST_SIZE) * 2 + 1) | ||
47 | |||
48 | /** | ||
49 | * Size of single processing block in bits | ||
50 | */ | ||
51 | #define SHA1_BLOCK_SIZE_BITS 512 | ||
52 | |||
53 | /** | ||
54 | * Size of single processing block in bytes | ||
55 | */ | ||
56 | #define SHA1_BLOCK_SIZE (SHA1_BLOCK_SIZE_BITS / 8) | ||
57 | |||
58 | |||
59 | struct sha1_ctx | ||
60 | { | ||
61 | uint32_t H[_SHA1_DIGEST_LENGTH]; /**< Intermediate hash value / digest at end of calculation */ | ||
62 | uint8_t buffer[SHA1_BLOCK_SIZE]; /**< SHA256 input data buffer */ | ||
63 | uint64_t count; /**< number of bytes, mod 2^64 */ | ||
64 | }; | ||
65 | |||
66 | /** | ||
67 | * Initialise structure for SHA-1 calculation. | ||
68 | * | ||
69 | * @param ctx must be a `struct sha1_ctx *` | ||
70 | */ | ||
71 | void | ||
72 | MHD_SHA1_init (void *ctx_); | ||
73 | |||
74 | |||
75 | /** | ||
76 | * Process portion of bytes. | ||
77 | * | ||
78 | * @param ctx_ must be a `struct sha1_ctx *` | ||
79 | * @param data bytes to add to hash | ||
80 | * @param length number of bytes in @a data | ||
81 | */ | ||
82 | void | ||
83 | MHD_SHA1_update (void *ctx_, | ||
84 | const uint8_t *data, | ||
85 | size_t length); | ||
86 | |||
87 | |||
88 | /** | ||
89 | * Finalise SHA-1 calculation, return digest. | ||
90 | * | ||
91 | * @param ctx_ must be a `struct sha1_ctx *` | ||
92 | * @param[out] digest set to the hash, must be #SHA1_DIGEST_SIZE bytes | ||
93 | */ | ||
94 | void | ||
95 | MHD_SHA1_finish (void *ctx_, | ||
96 | uint8_t digest[SHA1_DIGEST_SIZE]); | ||
97 | |||
98 | #endif /* MHD_SHA1_H */ | ||