Debian Codegraph @

Modules/_hacl/Hacl_Hash_Blake2s_Simd128.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_Blake2s_Simd128_H
27 #define Hacl_Hash_Blake2s_Simd128_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 #include "Hacl_Hash_Blake2b.h"
41
42 #define HACL_HASH_BLAKE2S_SIMD128_BLOCK_BYTES (64U)
43
44 #define HACL_HASH_BLAKE2S_SIMD128_OUT_BYTES (32U)
45
46 #define HACL_HASH_BLAKE2S_SIMD128_KEY_BYTES (32U)
47
48 #define HACL_HASH_BLAKE2S_SIMD128_SALT_BYTES (8U)
49
50 #define HACL_HASH_BLAKE2S_SIMD128_PERSONAL_BYTES (8U)
51
52 typedef struct Hacl_Hash_Blake2s_Simd128_block_state_t_s
53 Hacl_Hash_Blake2s_Simd128_block_state_t;
54
55 typedef struct Hacl_Hash_Blake2s_Simd128_state_t_s Hacl_Hash_Blake2s_Simd128_state_t;
56
57 /**
58 General-purpose allocation function that gives control over all
59 Blake2 parameters, including the key. Further resettings of the state SHALL be
60 done with `reset_with_params_and_key`, and SHALL feature the exact same values
61 for the `key_length` and `digest_length` fields as passed here. In other words,
62 once you commit to a digest and key length, the only way to change these
63 parameters is to allocate a new object.
64
65 The caller must satisfy the following requirements.
66 - The length of the key k MUST match the value of the field key_length in the
67 parameters.
68 - The key_length must not exceed 128 for S, 64 for B.
69 - The digest_length must not exceed 128 for S, 64 for B.
70
71 */
72 Hacl_Hash_Blake2s_Simd128_state_t
73 *Hacl_Hash_Blake2s_Simd128_malloc_with_params_and_key(
74 Hacl_Hash_Blake2b_blake2_params *p,
75 bool last_node,
76 uint8_t *k
77 );
78
79 /**
80 Specialized allocation function that picks default values for all
81 parameters, except for the key_length. Further resettings of the state SHALL be
82 done with `reset_with_key`, and SHALL feature the exact same key length `kk` as
83 passed here. In other words, once you commit to a key length, the only way to
84 change this parameter is to allocate a new object.
85
86 The caller must satisfy the following requirements.
87 - The key_length must not exceed 128 for S, 64 for B.
88
89 */
90 Hacl_Hash_Blake2s_Simd128_state_t
91 *Hacl_Hash_Blake2s_Simd128_malloc_with_key(uint8_t *k, uint8_t kk);
92
93 /**
94 Specialized allocation function that picks default values for all
95 parameters, and has no key. Effectively, this is what you want if you intend to
96 use Blake2 as a hash function. Further resettings of the state SHALL be done with `reset`.
97 */
98 Hacl_Hash_Blake2s_Simd128_state_t *Hacl_Hash_Blake2s_Simd128_malloc(void);
99
100 /**
101 General-purpose re-initialization function with parameters and
102 key. You cannot change digest_length, key_length, or last_node, meaning those values in
103 the parameters object must be the same as originally decided via one of the
104 malloc functions. All other values of the parameter can be changed. The behavior
105 is unspecified if you violate this precondition.
106 */
107 void
108 Hacl_Hash_Blake2s_Simd128_reset_with_key_and_params(
109 Hacl_Hash_Blake2s_Simd128_state_t *s,
110 Hacl_Hash_Blake2b_blake2_params *p,
111 uint8_t *k
112 );
113
114 /**
115 Specialized-purpose re-initialization function with no parameters,
116 and a key. The key length must be the same as originally decided via your choice
117 of malloc function. All other parameters are reset to their default values. The
118 original call to malloc MUST have set digest_length to the default value. The
119 behavior is unspecified if you violate this precondition.
120 */
121 void
122 Hacl_Hash_Blake2s_Simd128_reset_with_key(Hacl_Hash_Blake2s_Simd128_state_t *s, uint8_t *k);
123
124 /**
125 Specialized-purpose re-initialization function with no parameters
126 and no key. This is what you want if you intend to use Blake2 as a hash
127 function. The key length and digest length must have been set to their
128 respective default values via your choice of malloc function (always true if you
129 used `malloc`). All other parameters are reset to their default values. The
130 behavior is unspecified if you violate this precondition.
131 */
132 void Hacl_Hash_Blake2s_Simd128_reset(Hacl_Hash_Blake2s_Simd128_state_t *s);
133
134 /**
135 Update function; 0 = success, 1 = max length exceeded
136 */
137 Hacl_Streaming_Types_error_code
138 Hacl_Hash_Blake2s_Simd128_update(
139 Hacl_Hash_Blake2s_Simd128_state_t *state,
140 uint8_t *chunk,
141 uint32_t chunk_len
142 );
143
144 /**
145 Digest function. This function expects the `output` array to hold
146 at least `digest_length` bytes, where `digest_length` was determined by your
147 choice of `malloc` function. Concretely, if you used `malloc` or
148 `malloc_with_key`, then the expected length is 128 for S, or 64 for B (default
149 digest length). If you used `malloc_with_params_and_key`, then the expected
150 length is whatever you chose for the `digest_length` field of your parameters.
151 For convenience, this function returns `digest_length`. When in doubt, callers
152 can pass an array of size HACL_BLAKE2S_128_OUT_BYTES, then use the return value
153 to see how many bytes were actually written.
154 */
155 uint8_t Hacl_Hash_Blake2s_Simd128_digest(Hacl_Hash_Blake2s_Simd128_state_t *s, uint8_t *dst);
156
157 Hacl_Hash_Blake2b_index Hacl_Hash_Blake2s_Simd128_info(Hacl_Hash_Blake2s_Simd128_state_t *s);
158
159 /**
160 Free state function when there is no key
161 */
162 void Hacl_Hash_Blake2s_Simd128_free(Hacl_Hash_Blake2s_Simd128_state_t *state);
163
164 /**
165 Copying. This preserves all parameters.
166 */
167 Hacl_Hash_Blake2s_Simd128_state_t
168 *Hacl_Hash_Blake2s_Simd128_copy(Hacl_Hash_Blake2s_Simd128_state_t *state);
169
170 /**
171 Write the BLAKE2s digest of message `input` using key `key` into `output`.
172
173 @param output Pointer to `output_len` bytes of memory where the digest is written to.
174 @param output_len Length of the to-be-generated digest with 1 <= `output_len` <= 64.
175 @param input Pointer to `input_len` bytes of memory where the input message is read from.
176 @param input_len Length of the input message.
177 @param key Pointer to `key_len` bytes of memory where the key is read from.
178 @param key_len Length of the key. Can be 0.
179 */
180 void
181 Hacl_Hash_Blake2s_Simd128_hash_with_key(
182 uint8_t *output,
183 uint32_t output_len,
184 uint8_t *input,
185 uint32_t input_len,
186 uint8_t *key,
187 uint32_t key_len
188 );
189
190 /**
191 Write the BLAKE2s digest of message `input` using key `key` and
192 parameters `params` into `output`. The `key` array must be of length
193 `params.key_length`. The `output` array must be of length
194 `params.digest_length`.
195 */
196 void
197 Hacl_Hash_Blake2s_Simd128_hash_with_key_and_params(
198 uint8_t *output,
199 uint8_t *input,
200 uint32_t input_len,
201 Hacl_Hash_Blake2b_blake2_params params,
202 uint8_t *key
203 );
204
205 #if defined(__cplusplus)
206 }
207 #endif
208
209 #define Hacl_Hash_Blake2s_Simd128_H_DEFINED
210 #endif /* Hacl_Hash_Blake2s_Simd128_H */