Skip to content

Commit 507f048

Browse files
committed
only keep publics in Hacl_Hash_Blake2b_Simd256.h
and move all privates into internal/Hacl_Hash_Blake2b_Simd256.h
1 parent 30e8924 commit 507f048

File tree

4 files changed

+143
-145
lines changed

4 files changed

+143
-145
lines changed

Modules/_hacl/Hacl_Hash_Blake2b_Simd256.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ The caller must satisfy the following requirements.
670670
- The digest_length must not exceed 256 for S, 64 for B.
671671
672672
*/
673-
Hacl_Hash_Blake2b_Simd256_state_t
673+
void
674674
*Hacl_Hash_Blake2b_Simd256_malloc_with_params_and_key(
675675
Hacl_Hash_Blake2b_blake2_params *p,
676676
bool last_node,
@@ -901,11 +901,12 @@ void Hacl_Hash_Blake2b_Simd256_reset(Hacl_Hash_Blake2b_Simd256_state_t *s)
901901
*/
902902
Hacl_Streaming_Types_error_code
903903
Hacl_Hash_Blake2b_Simd256_update(
904-
Hacl_Hash_Blake2b_Simd256_state_t *state,
904+
void *state_in,
905905
uint8_t *chunk,
906906
uint32_t chunk_len
907907
)
908908
{
909+
Hacl_Hash_Blake2b_Simd256_state_t* state = (Hacl_Hash_Blake2b_Simd256_state_t*)state_in;
909910
Hacl_Hash_Blake2b_Simd256_state_t s = *state;
910911
uint64_t total_len = s.total_len;
911912
if ((uint64_t)chunk_len > 0xffffffffffffffffULL - total_len)
@@ -1122,8 +1123,9 @@ For convenience, this function returns `digest_length`. When in doubt, callers
11221123
can pass an array of size HACL_BLAKE2B_256_OUT_BYTES, then use the return value
11231124
to see how many bytes were actually written.
11241125
*/
1125-
uint8_t Hacl_Hash_Blake2b_Simd256_digest(Hacl_Hash_Blake2b_Simd256_state_t *s, uint8_t *dst)
1126+
uint8_t Hacl_Hash_Blake2b_Simd256_digest(void * state, uint8_t *dst)
11261127
{
1128+
Hacl_Hash_Blake2b_Simd256_state_t* s = (Hacl_Hash_Blake2b_Simd256_state_t*)state;
11271129
Hacl_Hash_Blake2b_Simd256_block_state_t block_state0 = (*s).block_state;
11281130
bool last_node0 = block_state0.thd;
11291131
uint8_t nn0 = block_state0.snd;
@@ -1203,8 +1205,9 @@ uint8_t Hacl_Hash_Blake2b_Simd256_digest(Hacl_Hash_Blake2b_Simd256_state_t *s, u
12031205
((Hacl_Hash_Blake2b_index){ .key_length = kk, .digest_length = nn, .last_node = last_node }).digest_length;
12041206
}
12051207

1206-
Hacl_Hash_Blake2b_index Hacl_Hash_Blake2b_Simd256_info(Hacl_Hash_Blake2b_Simd256_state_t *s)
1208+
Hacl_Hash_Blake2b_index Hacl_Hash_Blake2b_Simd256_info(void * state)
12071209
{
1210+
Hacl_Hash_Blake2b_Simd256_state_t* s = (Hacl_Hash_Blake2b_Simd256_state_t*)state;
12081211
Hacl_Hash_Blake2b_Simd256_block_state_t block_state = (*s).block_state;
12091212
bool last_node = block_state.thd;
12101213
uint8_t nn = block_state.snd;
@@ -1216,8 +1219,9 @@ Hacl_Hash_Blake2b_index Hacl_Hash_Blake2b_Simd256_info(Hacl_Hash_Blake2b_Simd256
12161219
/**
12171220
Free state function when there is no key
12181221
*/
1219-
void Hacl_Hash_Blake2b_Simd256_free(Hacl_Hash_Blake2b_Simd256_state_t *state)
1222+
void Hacl_Hash_Blake2b_Simd256_free(void *state_in)
12201223
{
1224+
Hacl_Hash_Blake2b_Simd256_state_t* state = (Hacl_Hash_Blake2b_Simd256_state_t*)state_in;
12211225
Hacl_Hash_Blake2b_Simd256_state_t scrut = *state;
12221226
uint8_t *buf = scrut.buf;
12231227
Hacl_Hash_Blake2b_Simd256_block_state_t block_state = scrut.block_state;
@@ -1232,9 +1236,10 @@ void Hacl_Hash_Blake2b_Simd256_free(Hacl_Hash_Blake2b_Simd256_state_t *state)
12321236
/**
12331237
Copying. This preserves all parameters.
12341238
*/
1235-
Hacl_Hash_Blake2b_Simd256_state_t
1236-
*Hacl_Hash_Blake2b_Simd256_copy(Hacl_Hash_Blake2b_Simd256_state_t *state)
1239+
void
1240+
*Hacl_Hash_Blake2b_Simd256_copy(void * state_in)
12371241
{
1242+
Hacl_Hash_Blake2b_Simd256_state_t* state = (Hacl_Hash_Blake2b_Simd256_state_t*)state_in;
12381243
Hacl_Hash_Blake2b_Simd256_state_t scrut = *state;
12391244
Hacl_Hash_Blake2b_Simd256_block_state_t block_state0 = scrut.block_state;
12401245
uint8_t *buf0 = scrut.buf;

Modules/_hacl/Hacl_Hash_Blake2b_Simd256.h

Lines changed: 6 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -30,50 +30,11 @@
3030
extern "C" {
3131
#endif
3232

33-
#include <string.h>
3433
#include "python_hacl_namespaces.h"
35-
#include "krml/types.h"
36-
#include "krml/lowstar_endianness.h"
37-
#include "krml/internal/target.h"
3834

3935
#include "Hacl_Streaming_Types.h"
4036

4137
#include "Hacl_Hash_Blake2b.h"
42-
#include "libintvector.h"
43-
44-
#define HACL_HASH_BLAKE2B_SIMD256_BLOCK_BYTES (128U)
45-
46-
#define HACL_HASH_BLAKE2B_SIMD256_OUT_BYTES (64U)
47-
48-
#define HACL_HASH_BLAKE2B_SIMD256_KEY_BYTES (64U)
49-
50-
#define HACL_HASH_BLAKE2B_SIMD256_SALT_BYTES (16U)
51-
52-
#define HACL_HASH_BLAKE2B_SIMD256_PERSONAL_BYTES (16U)
53-
54-
typedef struct K____Lib_IntVector_Intrinsics_vec256___Lib_IntVector_Intrinsics_vec256__s
55-
{
56-
Lib_IntVector_Intrinsics_vec256 *fst;
57-
Lib_IntVector_Intrinsics_vec256 *snd;
58-
}
59-
K____Lib_IntVector_Intrinsics_vec256___Lib_IntVector_Intrinsics_vec256_;
60-
61-
typedef struct Hacl_Hash_Blake2b_Simd256_block_state_t_s
62-
{
63-
uint8_t fst;
64-
uint8_t snd;
65-
bool thd;
66-
K____Lib_IntVector_Intrinsics_vec256___Lib_IntVector_Intrinsics_vec256_ f3;
67-
}
68-
Hacl_Hash_Blake2b_Simd256_block_state_t;
69-
70-
typedef struct Hacl_Hash_Blake2b_Simd256_state_t_s
71-
{
72-
Hacl_Hash_Blake2b_Simd256_block_state_t block_state;
73-
uint8_t *buf;
74-
uint64_t total_len;
75-
}
76-
Hacl_Hash_Blake2b_Simd256_state_t;
7738

7839
/**
7940
General-purpose allocation function that gives control over all
@@ -90,74 +51,19 @@ The caller must satisfy the following requirements.
9051
- The digest_length must not exceed 256 for S, 64 for B.
9152
9253
*/
93-
Hacl_Hash_Blake2b_Simd256_state_t
54+
void
9455
*Hacl_Hash_Blake2b_Simd256_malloc_with_params_and_key(
9556
Hacl_Hash_Blake2b_blake2_params *p,
9657
bool last_node,
9758
uint8_t *k
9859
);
9960

100-
/**
101-
Specialized allocation function that picks default values for all
102-
parameters, except for the key_length. Further resettings of the state SHALL be
103-
done with `reset_with_key`, and SHALL feature the exact same key length `kk` as
104-
passed here. In other words, once you commit to a key length, the only way to
105-
change this parameter is to allocate a new object.
106-
107-
The caller must satisfy the following requirements.
108-
- The key_length must not exceed 256 for S, 64 for B.
109-
110-
*/
111-
Hacl_Hash_Blake2b_Simd256_state_t
112-
*Hacl_Hash_Blake2b_Simd256_malloc_with_key0(uint8_t *k, uint8_t kk);
113-
114-
/**
115-
Specialized allocation function that picks default values for all
116-
parameters, and has no key. Effectively, this is what you want if you intend to
117-
use Blake2 as a hash function. Further resettings of the state SHALL be done with `reset`.
118-
*/
119-
Hacl_Hash_Blake2b_Simd256_state_t *Hacl_Hash_Blake2b_Simd256_malloc(void);
120-
121-
/**
122-
General-purpose re-initialization function with parameters and
123-
key. You cannot change digest_length, key_length, or last_node, meaning those values in
124-
the parameters object must be the same as originally decided via one of the
125-
malloc functions. All other values of the parameter can be changed. The behavior
126-
is unspecified if you violate this precondition.
127-
*/
128-
void
129-
Hacl_Hash_Blake2b_Simd256_reset_with_key_and_params(
130-
Hacl_Hash_Blake2b_Simd256_state_t *s,
131-
Hacl_Hash_Blake2b_blake2_params *p,
132-
uint8_t *k
133-
);
134-
135-
/**
136-
Specialized-purpose re-initialization function with no parameters,
137-
and a key. The key length must be the same as originally decided via your choice
138-
of malloc function. All other parameters are reset to their default values. The
139-
original call to malloc MUST have set digest_length to the default value. The
140-
behavior is unspecified if you violate this precondition.
141-
*/
142-
void
143-
Hacl_Hash_Blake2b_Simd256_reset_with_key(Hacl_Hash_Blake2b_Simd256_state_t *s, uint8_t *k);
144-
145-
/**
146-
Specialized-purpose re-initialization function with no parameters
147-
and no key. This is what you want if you intend to use Blake2 as a hash
148-
function. The key length and digest length must have been set to their
149-
respective default values via your choice of malloc function (always true if you
150-
used `malloc`). All other parameters are reset to their default values. The
151-
behavior is unspecified if you violate this precondition.
152-
*/
153-
void Hacl_Hash_Blake2b_Simd256_reset(Hacl_Hash_Blake2b_Simd256_state_t *s);
154-
15561
/**
15662
Update function; 0 = success, 1 = max length exceeded
15763
*/
15864
Hacl_Streaming_Types_error_code
15965
Hacl_Hash_Blake2b_Simd256_update(
160-
Hacl_Hash_Blake2b_Simd256_state_t *state,
66+
void *state,
16167
uint8_t *chunk,
16268
uint32_t chunk_len
16369
);
@@ -173,55 +79,20 @@ For convenience, this function returns `digest_length`. When in doubt, callers
17379
can pass an array of size HACL_BLAKE2B_256_OUT_BYTES, then use the return value
17480
to see how many bytes were actually written.
17581
*/
176-
uint8_t Hacl_Hash_Blake2b_Simd256_digest(Hacl_Hash_Blake2b_Simd256_state_t *s, uint8_t *dst);
82+
uint8_t Hacl_Hash_Blake2b_Simd256_digest(void *s, uint8_t *dst);
17783

178-
Hacl_Hash_Blake2b_index Hacl_Hash_Blake2b_Simd256_info(Hacl_Hash_Blake2b_Simd256_state_t *s);
84+
Hacl_Hash_Blake2b_index Hacl_Hash_Blake2b_Simd256_info(void *s);
17985

18086
/**
18187
Free state function when there is no key
18288
*/
183-
void Hacl_Hash_Blake2b_Simd256_free(Hacl_Hash_Blake2b_Simd256_state_t *state);
89+
void Hacl_Hash_Blake2b_Simd256_free(void *state);
18490

18591
/**
18692
Copying. This preserves all parameters.
18793
*/
188-
Hacl_Hash_Blake2b_Simd256_state_t
189-
*Hacl_Hash_Blake2b_Simd256_copy(Hacl_Hash_Blake2b_Simd256_state_t *state);
190-
191-
/**
192-
Write the BLAKE2b digest of message `input` using key `key` into `output`.
193-
194-
@param output Pointer to `output_len` bytes of memory where the digest is written to.
195-
@param output_len Length of the to-be-generated digest with 1 <= `output_len` <= 64.
196-
@param input Pointer to `input_len` bytes of memory where the input message is read from.
197-
@param input_len Length of the input message.
198-
@param key Pointer to `key_len` bytes of memory where the key is read from.
199-
@param key_len Length of the key. Can be 0.
200-
*/
20194
void
202-
Hacl_Hash_Blake2b_Simd256_hash_with_key(
203-
uint8_t *output,
204-
uint32_t output_len,
205-
uint8_t *input,
206-
uint32_t input_len,
207-
uint8_t *key,
208-
uint32_t key_len
209-
);
210-
211-
/**
212-
Write the BLAKE2b digest of message `input` using key `key` and
213-
parameters `params` into `output`. The `key` array must be of length
214-
`params.key_length`. The `output` array must be of length
215-
`params.digest_length`.
216-
*/
217-
void
218-
Hacl_Hash_Blake2b_Simd256_hash_with_key_and_params(
219-
uint8_t *output,
220-
uint8_t *input,
221-
uint32_t input_len,
222-
Hacl_Hash_Blake2b_blake2_params params,
223-
uint8_t *key
224-
);
95+
*Hacl_Hash_Blake2b_Simd256_copy(void *state);
22596

22697
#if defined(__cplusplus)
22798
}

Modules/_hacl/internal/Hacl_Hash_Blake2b_Simd256.h

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,130 @@ extern "C" {
4040
#include "../Hacl_Hash_Blake2b_Simd256.h"
4141
#include "libintvector.h"
4242

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+
53+
typedef struct K____Lib_IntVector_Intrinsics_vec256___Lib_IntVector_Intrinsics_vec256__s
54+
{
55+
Lib_IntVector_Intrinsics_vec256 *fst;
56+
Lib_IntVector_Intrinsics_vec256 *snd;
57+
}
58+
K____Lib_IntVector_Intrinsics_vec256___Lib_IntVector_Intrinsics_vec256_;
59+
60+
typedef struct Hacl_Hash_Blake2b_Simd256_block_state_t_s
61+
{
62+
uint8_t fst;
63+
uint8_t snd;
64+
bool thd;
65+
K____Lib_IntVector_Intrinsics_vec256___Lib_IntVector_Intrinsics_vec256_ f3;
66+
}
67+
Hacl_Hash_Blake2b_Simd256_block_state_t;
68+
69+
typedef struct Hacl_Hash_Blake2b_Simd256_state_t_s
70+
{
71+
Hacl_Hash_Blake2b_Simd256_block_state_t block_state;
72+
uint8_t *buf;
73+
uint64_t total_len;
74+
}
75+
Hacl_Hash_Blake2b_Simd256_state_t;
76+
77+
/**
78+
Specialized allocation function that picks default values for all
79+
parameters, except for the key_length. Further resettings of the state SHALL be
80+
done with `reset_with_key`, and SHALL feature the exact same key length `kk` as
81+
passed here. In other words, once you commit to a key length, the only way to
82+
change this parameter is to allocate a new object.
83+
84+
The caller must satisfy the following requirements.
85+
- The key_length must not exceed 256 for S, 64 for B.
86+
87+
*/
88+
Hacl_Hash_Blake2b_Simd256_state_t
89+
*Hacl_Hash_Blake2b_Simd256_malloc_with_key0(uint8_t *k, uint8_t kk);
90+
91+
/**
92+
Specialized allocation function that picks default values for all
93+
parameters, and has no key. Effectively, this is what you want if you intend to
94+
use Blake2 as a hash function. Further resettings of the state SHALL be done with `reset`.
95+
*/
96+
Hacl_Hash_Blake2b_Simd256_state_t *Hacl_Hash_Blake2b_Simd256_malloc(void);
97+
98+
/**
99+
General-purpose re-initialization function with parameters and
100+
key. You cannot change digest_length, key_length, or last_node, meaning those values in
101+
the parameters object must be the same as originally decided via one of the
102+
malloc functions. All other values of the parameter can be changed. The behavior
103+
is unspecified if you violate this precondition.
104+
*/
105+
void
106+
Hacl_Hash_Blake2b_Simd256_reset_with_key_and_params(
107+
Hacl_Hash_Blake2b_Simd256_state_t *s,
108+
Hacl_Hash_Blake2b_blake2_params *p,
109+
uint8_t *k
110+
);
111+
112+
/**
113+
Specialized-purpose re-initialization function with no parameters,
114+
and a key. The key length must be the same as originally decided via your choice
115+
of malloc function. All other parameters are reset to their default values. The
116+
original call to malloc MUST have set digest_length to the default value. The
117+
behavior is unspecified if you violate this precondition.
118+
*/
119+
void
120+
Hacl_Hash_Blake2b_Simd256_reset_with_key(Hacl_Hash_Blake2b_Simd256_state_t *s, uint8_t *k);
121+
122+
/**
123+
Specialized-purpose re-initialization function with no parameters
124+
and no key. This is what you want if you intend to use Blake2 as a hash
125+
function. The key length and digest length must have been set to their
126+
respective default values via your choice of malloc function (always true if you
127+
used `malloc`). All other parameters are reset to their default values. The
128+
behavior is unspecified if you violate this precondition.
129+
*/
130+
void Hacl_Hash_Blake2b_Simd256_reset(Hacl_Hash_Blake2b_Simd256_state_t *s);
131+
132+
/**
133+
Write the BLAKE2b digest of message `input` using key `key` into `output`.
134+
135+
@param output Pointer to `output_len` bytes of memory where the digest is written to.
136+
@param output_len Length of the to-be-generated digest with 1 <= `output_len` <= 64.
137+
@param input Pointer to `input_len` bytes of memory where the input message is read from.
138+
@param input_len Length of the input message.
139+
@param key Pointer to `key_len` bytes of memory where the key is read from.
140+
@param key_len Length of the key. Can be 0.
141+
*/
142+
void
143+
Hacl_Hash_Blake2b_Simd256_hash_with_key(
144+
uint8_t *output,
145+
uint32_t output_len,
146+
uint8_t *input,
147+
uint32_t input_len,
148+
uint8_t *key,
149+
uint32_t key_len
150+
);
151+
152+
/**
153+
Write the BLAKE2b digest of message `input` using key `key` and
154+
parameters `params` into `output`. The `key` array must be of length
155+
`params.key_length`. The `output` array must be of length
156+
`params.digest_length`.
157+
*/
158+
void
159+
Hacl_Hash_Blake2b_Simd256_hash_with_key_and_params(
160+
uint8_t *output,
161+
uint8_t *input,
162+
uint32_t input_len,
163+
Hacl_Hash_Blake2b_blake2_params params,
164+
uint8_t *key
165+
);
166+
43167
void
44168
Hacl_Hash_Blake2b_Simd256_init(Lib_IntVector_Intrinsics_vec256 *hash, uint32_t kk, uint32_t nn);
45169

0 commit comments

Comments
 (0)