@@ -40,6 +40,16 @@ extern "C" {
40
40
#include "Hacl_Hash_Blake2b.h"
41
41
#include "libintvector.h"
42
42
43
+ #define HACL_HASH_BLAKE2B_SIMD256_BLOCK_BYTES (128U)
44
+
45
+ #define HACL_HASH_BLAKE2B_SIMD256_OUT_BYTES (64U)
46
+
47
+ #define HACL_HASH_BLAKE2B_SIMD256_KEY_BYTES (64U)
48
+
49
+ #define HACL_HASH_BLAKE2B_SIMD256_SALT_BYTES (16U)
50
+
51
+ #define HACL_HASH_BLAKE2B_SIMD256_PERSONAL_BYTES (16U)
52
+
43
53
typedef struct K____Lib_IntVector_Intrinsics_vec256___Lib_IntVector_Intrinsics_vec256__s
44
54
{
45
55
Lib_IntVector_Intrinsics_vec256 * fst ;
@@ -51,7 +61,8 @@ typedef struct Hacl_Hash_Blake2b_Simd256_block_state_t_s
51
61
{
52
62
uint8_t fst ;
53
63
uint8_t snd ;
54
- K____Lib_IntVector_Intrinsics_vec256___Lib_IntVector_Intrinsics_vec256_ thd ;
64
+ bool thd ;
65
+ K____Lib_IntVector_Intrinsics_vec256___Lib_IntVector_Intrinsics_vec256_ f3 ;
55
66
}
56
67
Hacl_Hash_Blake2b_Simd256_block_state_t ;
57
68
@@ -64,34 +75,54 @@ typedef struct Hacl_Hash_Blake2b_Simd256_state_t_s
64
75
Hacl_Hash_Blake2b_Simd256_state_t ;
65
76
66
77
/**
67
- State allocation function when there are parameters and a key. The
68
- length of the key k MUST match the value of the field key_length in the
69
- parameters. Furthermore, there is a static (not dynamically checked) requirement
70
- that key_length does not exceed max_key (256 for S, 64 for B).)
78
+ General-purpose allocation function that gives control over all
79
+ Blake2 parameters, including the key. Further resettings of the state SHALL be
80
+ done with `reset_with_params_and_key`, and SHALL feature the exact same values
81
+ for the `key_length` and `digest_length` fields as passed here. In other words,
82
+ once you commit to a digest and key length, the only way to change these
83
+ parameters is to allocate a new object.
84
+
85
+ The caller must satisfy the following requirements.
86
+ - The length of the key k MUST match the value of the field key_length in the
87
+ parameters.
88
+ - The key_length must not exceed 256 for S, 64 for B.
89
+ - The digest_length must not exceed 256 for S, 64 for B.
90
+
71
91
*/
72
92
Hacl_Hash_Blake2b_Simd256_state_t
73
93
* Hacl_Hash_Blake2b_Simd256_malloc_with_params_and_key (
74
94
Hacl_Hash_Blake2b_blake2_params * p ,
95
+ bool last_node ,
75
96
uint8_t * k
76
97
);
77
98
78
99
/**
79
- State allocation function when there is just a custom key. All
80
- other parameters are set to their respective default values, meaning the output
81
- length is the maximum allowed output (256 for S, 64 for B).
100
+ Specialized allocation function that picks default values for all
101
+ parameters, except for the key_length. Further resettings of the state SHALL be
102
+ done with `reset_with_key`, and SHALL feature the exact same key length `kk` as
103
+ passed here. In other words, once you commit to a key length, the only way to
104
+ change this parameter is to allocate a new object.
105
+
106
+ The caller must satisfy the following requirements.
107
+ - The key_length must not exceed 256 for S, 64 for B.
108
+
82
109
*/
83
110
Hacl_Hash_Blake2b_Simd256_state_t
84
111
* Hacl_Hash_Blake2b_Simd256_malloc_with_key0 (uint8_t * k , uint8_t kk );
85
112
86
113
/**
87
- State allocation function when there is no key
114
+ Specialized allocation function that picks default values for all
115
+ parameters, and has no key. Effectively, this is what you want if you intend to
116
+ use Blake2 as a hash function. Further resettings of the state SHALL be done with `reset`.
88
117
*/
89
118
Hacl_Hash_Blake2b_Simd256_state_t * Hacl_Hash_Blake2b_Simd256_malloc (void );
90
119
91
120
/**
92
- Re-initialization function. The reinitialization API is tricky --
93
- you MUST reuse the same original parameters for digest (output) length and key
94
- length.
121
+ General-purpose re-initialization function with parameters and
122
+ key. You cannot change digest_length, key_length, or last_node, meaning those values in
123
+ the parameters object must be the same as originally decided via one of the
124
+ malloc functions. All other values of the parameter can be changed. The behavior
125
+ is unspecified if you violate this precondition.
95
126
*/
96
127
void
97
128
Hacl_Hash_Blake2b_Simd256_reset_with_key_and_params (
@@ -101,21 +132,27 @@ Hacl_Hash_Blake2b_Simd256_reset_with_key_and_params(
101
132
);
102
133
103
134
/**
104
- Re-initialization function when there is a key. Note that the key
105
- size is not allowed to change, which is why this function does not take a key
106
- length -- the key has to be same key size that was originally passed to
107
- `malloc_with_key`
135
+ Specialized-purpose re-initialization function with no parameters,
136
+ and a key. The key length must be the same as originally decided via your choice
137
+ of malloc function. All other parameters are reset to their default values. The
138
+ original call to malloc MUST have set digest_length to the default value. The
139
+ behavior is unspecified if you violate this precondition.
108
140
*/
109
141
void
110
142
Hacl_Hash_Blake2b_Simd256_reset_with_key (Hacl_Hash_Blake2b_Simd256_state_t * s , uint8_t * k );
111
143
112
144
/**
113
- Re-initialization function when there is no key
145
+ Specialized-purpose re-initialization function with no parameters
146
+ and no key. This is what you want if you intend to use Blake2 as a hash
147
+ function. The key length and digest length must have been set to their
148
+ respective default values via your choice of malloc function (always true if you
149
+ used `malloc`). All other parameters are reset to their default values. The
150
+ behavior is unspecified if you violate this precondition.
114
151
*/
115
152
void Hacl_Hash_Blake2b_Simd256_reset (Hacl_Hash_Blake2b_Simd256_state_t * s );
116
153
117
154
/**
118
- Update function when there is no key ; 0 = success, 1 = max length exceeded
155
+ Update function; 0 = success, 1 = max length exceeded
119
156
*/
120
157
Hacl_Streaming_Types_error_code
121
158
Hacl_Hash_Blake2b_Simd256_update (
@@ -125,18 +162,27 @@ Hacl_Hash_Blake2b_Simd256_update(
125
162
);
126
163
127
164
/**
128
- Finish function when there is no key
165
+ Digest function. This function expects the `output` array to hold
166
+ at least `digest_length` bytes, where `digest_length` was determined by your
167
+ choice of `malloc` function. Concretely, if you used `malloc` or
168
+ `malloc_with_key`, then the expected length is 256 for S, or 64 for B (default
169
+ digest length). If you used `malloc_with_params_and_key`, then the expected
170
+ length is whatever you chose for the `digest_length` field of your parameters.
171
+ For convenience, this function returns `digest_length`. When in doubt, callers
172
+ can pass an array of size HACL_BLAKE2B_256_OUT_BYTES, then use the return value
173
+ to see how many bytes were actually written.
129
174
*/
130
- void
131
- Hacl_Hash_Blake2b_Simd256_digest (Hacl_Hash_Blake2b_Simd256_state_t * state , uint8_t * output );
175
+ uint8_t Hacl_Hash_Blake2b_Simd256_digest (Hacl_Hash_Blake2b_Simd256_state_t * s , uint8_t * dst );
176
+
177
+ Hacl_Hash_Blake2b_index Hacl_Hash_Blake2b_Simd256_info (Hacl_Hash_Blake2b_Simd256_state_t * s );
132
178
133
179
/**
134
180
Free state function when there is no key
135
181
*/
136
182
void Hacl_Hash_Blake2b_Simd256_free (Hacl_Hash_Blake2b_Simd256_state_t * state );
137
183
138
184
/**
139
- Copying. The key length (or absence thereof) must match between source and destination .
185
+ Copying. This preserves all parameters .
140
186
*/
141
187
Hacl_Hash_Blake2b_Simd256_state_t
142
188
* Hacl_Hash_Blake2b_Simd256_copy (Hacl_Hash_Blake2b_Simd256_state_t * state );
@@ -161,8 +207,14 @@ Hacl_Hash_Blake2b_Simd256_hash_with_key(
161
207
uint32_t key_len
162
208
);
163
209
210
+ /**
211
+ Write the BLAKE2b digest of message `input` using key `key` and
212
+ parameters `params` into `output`. The `key` array must be of length
213
+ `params.key_length`. The `output` array must be of length
214
+ `params.digest_length`.
215
+ */
164
216
void
165
- Hacl_Hash_Blake2b_Simd256_hash_with_key_and_paramas (
217
+ Hacl_Hash_Blake2b_Simd256_hash_with_key_and_params (
166
218
uint8_t * output ,
167
219
uint8_t * input ,
168
220
uint32_t input_len ,
0 commit comments