Debian Codegraph @

Modules/_hacl/Hacl_Hash_SHA3.h

raw
1 /* MIT License
2 *
3 * Copyright (c) 2016-2022 INRIA, CMU and Microsoft Corporation
4 * Copyright (c) 2022-2023 HACL* Contributors
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
25
26 #ifndef Hacl_Hash_SHA3_H
27 #define Hacl_Hash_SHA3_H
28
29 #if defined(__cplusplus)
30 extern "C" {
31 #endif
32
33 #include <string.h>
34 #include "python_hacl_namespaces.h"
35 #include "krml/internal/types.h"
36 #include "krml/lowstar_endianness.h"
37 #include "krml/internal/target.h"
38
39 #include "Hacl_Streaming_Types.h"
40
41 typedef struct Hacl_Hash_SHA3_state_t_s Hacl_Hash_SHA3_state_t;
42
43 Spec_Hash_Definitions_hash_alg Hacl_Hash_SHA3_get_alg(Hacl_Hash_SHA3_state_t *s);
44
45 Hacl_Hash_SHA3_state_t *Hacl_Hash_SHA3_malloc(Spec_Hash_Definitions_hash_alg a);
46
47 void Hacl_Hash_SHA3_free(Hacl_Hash_SHA3_state_t *state);
48
49 Hacl_Hash_SHA3_state_t *Hacl_Hash_SHA3_copy(Hacl_Hash_SHA3_state_t *state);
50
51 void Hacl_Hash_SHA3_reset(Hacl_Hash_SHA3_state_t *state);
52
53 Hacl_Streaming_Types_error_code
54 Hacl_Hash_SHA3_update(Hacl_Hash_SHA3_state_t *state, uint8_t *chunk, uint32_t chunk_len);
55
56 Hacl_Streaming_Types_error_code
57 Hacl_Hash_SHA3_digest(Hacl_Hash_SHA3_state_t *state, uint8_t *output);
58
59 Hacl_Streaming_Types_error_code
60 Hacl_Hash_SHA3_squeeze(Hacl_Hash_SHA3_state_t *s, uint8_t *dst, uint32_t l);
61
62 uint32_t Hacl_Hash_SHA3_block_len(Hacl_Hash_SHA3_state_t *s);
63
64 uint32_t Hacl_Hash_SHA3_hash_len(Hacl_Hash_SHA3_state_t *s);
65
66 bool Hacl_Hash_SHA3_is_shake(Hacl_Hash_SHA3_state_t *s);
67
68 void Hacl_Hash_SHA3_absorb_inner_32(uint32_t rateInBytes, uint8_t *b, uint64_t *s);
69
70 void
71 Hacl_Hash_SHA3_shake128(
72 uint8_t *output,
73 uint32_t outputByteLen,
74 uint8_t *input,
75 uint32_t inputByteLen
76 );
77
78 void
79 Hacl_Hash_SHA3_shake256(
80 uint8_t *output,
81 uint32_t outputByteLen,
82 uint8_t *input,
83 uint32_t inputByteLen
84 );
85
86 void Hacl_Hash_SHA3_sha3_224(uint8_t *output, uint8_t *input, uint32_t inputByteLen);
87
88 void Hacl_Hash_SHA3_sha3_256(uint8_t *output, uint8_t *input, uint32_t inputByteLen);
89
90 void Hacl_Hash_SHA3_sha3_384(uint8_t *output, uint8_t *input, uint32_t inputByteLen);
91
92 void Hacl_Hash_SHA3_sha3_512(uint8_t *output, uint8_t *input, uint32_t inputByteLen);
93
94 /**
95 Allocate state buffer of 200-bytes
96 */
97 uint64_t *Hacl_Hash_SHA3_state_malloc(void);
98
99 /**
100 Free state buffer
101 */
102 void Hacl_Hash_SHA3_state_free(uint64_t *s);
103
104 /**
105 Absorb number of input blocks and write the output state
106
107 This function is intended to receive a hash state and input buffer.
108 It processes an input of multiple of 168-bytes (SHAKE128 block size),
109 any additional bytes of final partial block are ignored.
110
111 The argument `state` (IN/OUT) points to hash state, i.e., uint64_t[25]
112 The argument `input` (IN) points to `inputByteLen` bytes of valid memory,
113 i.e., uint8_t[inputByteLen]
114 */
115 void
116 Hacl_Hash_SHA3_shake128_absorb_nblocks(uint64_t *state, uint8_t *input, uint32_t inputByteLen);
117
118 /**
119 Absorb a final partial block of input and write the output state
120
121 This function is intended to receive a hash state and input buffer.
122 It processes a sequence of bytes at end of input buffer that is less
123 than 168-bytes (SHAKE128 block size),
124 any bytes of full blocks at start of input buffer are ignored.
125
126 The argument `state` (IN/OUT) points to hash state, i.e., uint64_t[25]
127 The argument `input` (IN) points to `inputByteLen` bytes of valid memory,
128 i.e., uint8_t[inputByteLen]
129
130 Note: Full size of input buffer must be passed to `inputByteLen` including
131 the number of full-block bytes at start of input buffer that are ignored
132 */
133 void
134 Hacl_Hash_SHA3_shake128_absorb_final(uint64_t *state, uint8_t *input, uint32_t inputByteLen);
135
136 /**
137 Squeeze a hash state to output buffer
138
139 This function is intended to receive a hash state and output buffer.
140 It produces an output of multiple of 168-bytes (SHAKE128 block size),
141 any additional bytes of final partial block are ignored.
142
143 The argument `state` (IN) points to hash state, i.e., uint64_t[25]
144 The argument `output` (OUT) points to `outputByteLen` bytes of valid memory,
145 i.e., uint8_t[outputByteLen]
146 */
147 void
148 Hacl_Hash_SHA3_shake128_squeeze_nblocks(
149 uint64_t *state,
150 uint8_t *output,
151 uint32_t outputByteLen
152 );
153
154 #if defined(__cplusplus)
155 }
156 #endif
157
158 #define Hacl_Hash_SHA3_H_DEFINED
159 #endif /* Hacl_Hash_SHA3_H */