Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit 93f50b4

Browse files
committed
ref folder changes, and minor sse
1 parent a8d1d40 commit 93f50b4

File tree

8 files changed

+142
-142
lines changed

8 files changed

+142
-142
lines changed

cbits/blake2/ref/blake2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ extern "C" {
148148
int _cryptonite_blake2s_update( blake2s_state *S, const void *in, size_t inlen );
149149
int _cryptonite_blake2s_final( blake2s_state *S, void *out, size_t outlen );
150150

151-
int _cryptonite__cryptonite_blake2b_init( blake2b_state *S, size_t outlen );
151+
int _cryptonite_blake2b_init( blake2b_state *S, size_t outlen );
152152
int _cryptonite_blake2b_init_key( blake2b_state *S, size_t outlen, const void *key, size_t keylen );
153153
int _cryptonite_blake2b_init_param( blake2b_state *S, const blake2b_param *P );
154154
int _cryptonite_blake2b_update( blake2b_state *S, const void *in, size_t inlen );

cbits/blake2/ref/blake2b-ref.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,31 +45,31 @@ static const uint8_t blake2b_sigma[12][16] =
4545
};
4646

4747

48-
static void _cryptonite_blake2b_set_lastnode( blake2b_state *S )
48+
static void blake2b_set_lastnode( blake2b_state *S )
4949
{
5050
S->f[1] = (uint64_t)-1;
5151
}
5252

5353
/* Some helper functions, not necessarily useful */
54-
static int _cryptonite_blake2b_is_lastblock( const blake2b_state *S )
54+
static int blake2b_is_lastblock( const blake2b_state *S )
5555
{
5656
return S->f[0] != 0;
5757
}
5858

59-
static void _cryptonite_blake2b_set_lastblock( blake2b_state *S )
59+
static void blake2b_set_lastblock( blake2b_state *S )
6060
{
61-
if( S->last_node ) _cryptonite_blake2b_set_lastnode( S );
61+
if( S->last_node ) blake2b_set_lastnode( S );
6262

6363
S->f[0] = (uint64_t)-1;
6464
}
6565

66-
static void _cryptonite_blake2b_increment_counter( blake2b_state *S, const uint64_t inc )
66+
static void blake2b_increment_counter( blake2b_state *S, const uint64_t inc )
6767
{
6868
S->t[0] += inc;
6969
S->t[1] += ( S->t[0] < inc );
7070
}
7171

72-
static void _cryptonite_blake2b_init0( blake2b_state *S )
72+
static void blake2b_init0( blake2b_state *S )
7373
{
7474
size_t i;
7575
memset( S, 0, sizeof( blake2b_state ) );
@@ -83,7 +83,7 @@ int _cryptonite_blake2b_init_param( blake2b_state *S, const blake2b_param *P )
8383
const uint8_t *p = ( const uint8_t * )( P );
8484
size_t i;
8585

86-
_cryptonite_blake2b_init0( S );
86+
blake2b_init0( S );
8787

8888
/* IV XOR ParamBlock */
8989
for( i = 0; i < 8; ++i )
@@ -174,7 +174,7 @@ int _cryptonite_blake2b_init_key( blake2b_state *S, size_t outlen, const void *k
174174
G(r,7,v[ 3],v[ 4],v[ 9],v[14]); \
175175
} while(0)
176176

177-
static void _cryptonite_blake2b_compress( blake2b_state *S, const uint8_t block[BLAKE2B_BLOCKBYTES] )
177+
static void blake2b_compress( blake2b_state *S, const uint8_t block[BLAKE2B_BLOCKBYTES] )
178178
{
179179
uint64_t m[16];
180180
uint64_t v[16];
@@ -229,12 +229,12 @@ int _cryptonite_blake2b_update( blake2b_state *S, const void *pin, size_t inlen
229229
{
230230
S->buflen = 0;
231231
memcpy( S->buf + left, in, fill ); /* Fill buffer */
232-
_cryptonite_blake2b_increment_counter( S, BLAKE2B_BLOCKBYTES );
233-
_cryptonite_blake2b_compress( S, S->buf ); /* Compress */
232+
blake2b_increment_counter( S, BLAKE2B_BLOCKBYTES );
233+
blake2b_compress( S, S->buf ); /* Compress */
234234
in += fill; inlen -= fill;
235235
while(inlen > BLAKE2B_BLOCKBYTES) {
236-
_cryptonite_blake2b_increment_counter(S, BLAKE2B_BLOCKBYTES);
237-
_cryptonite_blake2b_compress( S, in );
236+
blake2b_increment_counter(S, BLAKE2B_BLOCKBYTES);
237+
blake2b_compress( S, in );
238238
in += BLAKE2B_BLOCKBYTES;
239239
inlen -= BLAKE2B_BLOCKBYTES;
240240
}
@@ -253,13 +253,13 @@ int _cryptonite_blake2b_final( blake2b_state *S, void *out, size_t outlen )
253253
if( out == NULL || outlen < S->outlen )
254254
return -1;
255255

256-
if( _cryptonite_blake2b_is_lastblock( S ) )
256+
if( blake2b_is_lastblock( S ) )
257257
return -1;
258258

259-
_cryptonite_blake2b_increment_counter( S, S->buflen );
260-
_cryptonite_blake2b_set_lastblock( S );
259+
blake2b_increment_counter( S, S->buflen );
260+
blake2b_set_lastblock( S );
261261
memset( S->buf + S->buflen, 0, BLAKE2B_BLOCKBYTES - S->buflen ); /* Padding */
262-
_cryptonite_blake2b_compress( S, S->buf );
262+
blake2b_compress( S, S->buf );
263263

264264
for( i = 0; i < 8; ++i ) /* Output full hash to temp buffer */
265265
store64( buffer + sizeof( S->h[i] ) * i, S->h[i] );

cbits/blake2/ref/blake2bp-ref.c

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static int blake2bp_init_root( blake2b_state *S, size_t outlen, size_t keylen )
7878
}
7979

8080

81-
int blake2bp_init( blake2bp_state *S, size_t outlen )
81+
int _cryptonite_blake2bp_init( blake2bp_state *S, size_t outlen )
8282
{
8383
size_t i;
8484

@@ -99,7 +99,7 @@ int blake2bp_init( blake2bp_state *S, size_t outlen )
9999
return 0;
100100
}
101101

102-
int blake2bp_init_key( blake2bp_state *S, size_t outlen, const void *key, size_t keylen )
102+
int _cryptonite_blake2bp_init_key( blake2bp_state *S, size_t outlen, const void *key, size_t keylen )
103103
{
104104
size_t i;
105105

@@ -125,15 +125,15 @@ int blake2bp_init_key( blake2bp_state *S, size_t outlen, const void *key, size_t
125125
memcpy( block, key, keylen );
126126

127127
for( i = 0; i < PARALLELISM_DEGREE; ++i )
128-
blake2b_update( S->S[i], block, BLAKE2B_BLOCKBYTES );
128+
_cryptonite_blake2b_update( S->S[i], block, BLAKE2B_BLOCKBYTES );
129129

130130
secure_zero_memory( block, BLAKE2B_BLOCKBYTES ); /* Burn the key from stack */
131131
}
132132
return 0;
133133
}
134134

135135

136-
int blake2bp_update( blake2bp_state *S, const void *pin, size_t inlen )
136+
int _cryptonite_blake2bp_update( blake2bp_state *S, const void *pin, size_t inlen )
137137
{
138138
const unsigned char * in = (const unsigned char *)pin;
139139
size_t left = S->buflen;
@@ -145,7 +145,7 @@ int blake2bp_update( blake2bp_state *S, const void *pin, size_t inlen )
145145
memcpy( S->buf + left, in, fill );
146146

147147
for( i = 0; i < PARALLELISM_DEGREE; ++i )
148-
blake2b_update( S->S[i], S->buf + i * BLAKE2B_BLOCKBYTES, BLAKE2B_BLOCKBYTES );
148+
_cryptonite_blake2b_update( S->S[i], S->buf + i * BLAKE2B_BLOCKBYTES, BLAKE2B_BLOCKBYTES );
149149

150150
in += fill;
151151
inlen -= fill;
@@ -168,7 +168,7 @@ int blake2bp_update( blake2bp_state *S, const void *pin, size_t inlen )
168168

169169
while( inlen__ >= PARALLELISM_DEGREE * BLAKE2B_BLOCKBYTES )
170170
{
171-
blake2b_update( S->S[i], in__, BLAKE2B_BLOCKBYTES );
171+
_cryptonite_blake2b_update( S->S[i], in__, BLAKE2B_BLOCKBYTES );
172172
in__ += PARALLELISM_DEGREE * BLAKE2B_BLOCKBYTES;
173173
inlen__ -= PARALLELISM_DEGREE * BLAKE2B_BLOCKBYTES;
174174
}
@@ -184,7 +184,7 @@ int blake2bp_update( blake2bp_state *S, const void *pin, size_t inlen )
184184
return 0;
185185
}
186186

187-
int blake2bp_final( blake2bp_state *S, void *out, size_t outlen )
187+
int _cryptonite_blake2bp_final( blake2bp_state *S, void *out, size_t outlen )
188188
{
189189
uint8_t hash[PARALLELISM_DEGREE][BLAKE2B_OUTBYTES];
190190
size_t i;
@@ -201,19 +201,19 @@ int blake2bp_final( blake2bp_state *S, void *out, size_t outlen )
201201

202202
if( left > BLAKE2B_BLOCKBYTES ) left = BLAKE2B_BLOCKBYTES;
203203

204-
blake2b_update( S->S[i], S->buf + i * BLAKE2B_BLOCKBYTES, left );
204+
_cryptonite_blake2b_update( S->S[i], S->buf + i * BLAKE2B_BLOCKBYTES, left );
205205
}
206206

207-
blake2b_final( S->S[i], hash[i], BLAKE2B_OUTBYTES );
207+
_cryptonite_blake2b_final( S->S[i], hash[i], BLAKE2B_OUTBYTES );
208208
}
209209

210210
for( i = 0; i < PARALLELISM_DEGREE; ++i )
211-
blake2b_update( S->R, hash[i], BLAKE2B_OUTBYTES );
211+
_cryptonite_blake2b_update( S->R, hash[i], BLAKE2B_OUTBYTES );
212212

213-
return blake2b_final( S->R, out, S->outlen );
213+
return _cryptonite_blake2b_final( S->R, out, S->outlen );
214214
}
215215

216-
int blake2bp( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen )
216+
int _cryptonite_blake2bp( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen )
217217
{
218218
uint8_t hash[PARALLELISM_DEGREE][BLAKE2B_OUTBYTES];
219219
blake2b_state S[PARALLELISM_DEGREE][1];
@@ -243,7 +243,7 @@ int blake2bp( void *out, size_t outlen, const void *in, size_t inlen, const void
243243
memcpy( block, key, keylen );
244244

245245
for( i = 0; i < PARALLELISM_DEGREE; ++i )
246-
blake2b_update( S[i], block, BLAKE2B_BLOCKBYTES );
246+
_cryptonite_blake2b_update( S[i], block, BLAKE2B_BLOCKBYTES );
247247

248248
secure_zero_memory( block, BLAKE2B_BLOCKBYTES ); /* Burn the key from stack */
249249
}
@@ -264,7 +264,7 @@ int blake2bp( void *out, size_t outlen, const void *in, size_t inlen, const void
264264

265265
while( inlen__ >= PARALLELISM_DEGREE * BLAKE2B_BLOCKBYTES )
266266
{
267-
blake2b_update( S[i], in__, BLAKE2B_BLOCKBYTES );
267+
_cryptonite_blake2b_update( S[i], in__, BLAKE2B_BLOCKBYTES );
268268
in__ += PARALLELISM_DEGREE * BLAKE2B_BLOCKBYTES;
269269
inlen__ -= PARALLELISM_DEGREE * BLAKE2B_BLOCKBYTES;
270270
}
@@ -273,10 +273,10 @@ int blake2bp( void *out, size_t outlen, const void *in, size_t inlen, const void
273273
{
274274
const size_t left = inlen__ - i * BLAKE2B_BLOCKBYTES;
275275
const size_t len = left <= BLAKE2B_BLOCKBYTES ? left : BLAKE2B_BLOCKBYTES;
276-
blake2b_update( S[i], in__, len );
276+
_cryptonite_blake2b_update( S[i], in__, len );
277277
}
278278

279-
blake2b_final( S[i], hash[i], BLAKE2B_OUTBYTES );
279+
_cryptonite_blake2b_final( S[i], hash[i], BLAKE2B_OUTBYTES );
280280
}
281281

282282
if( blake2bp_init_root( FS, outlen, keylen ) < 0 )
@@ -285,9 +285,9 @@ int blake2bp( void *out, size_t outlen, const void *in, size_t inlen, const void
285285
FS->last_node = 1; /* Mark as last node */
286286

287287
for( i = 0; i < PARALLELISM_DEGREE; ++i )
288-
blake2b_update( FS, hash[i], BLAKE2B_OUTBYTES );
288+
_cryptonite_blake2b_update( FS, hash[i], BLAKE2B_OUTBYTES );
289289

290-
return blake2b_final( FS, out, outlen );;
290+
return _cryptonite_blake2b_final( FS, out, outlen );;
291291
}
292292

293293
#if defined(BLAKE2BP_SELFTEST)
@@ -326,21 +326,21 @@ int main( void )
326326
size_t mlen = i;
327327
int err = 0;
328328

329-
if( (err = blake2bp_init_key(&S, BLAKE2B_OUTBYTES, key, BLAKE2B_KEYBYTES)) < 0 ) {
329+
if( (err = _cryptonite_blake2bp_init_key(&S, BLAKE2B_OUTBYTES, key, BLAKE2B_KEYBYTES)) < 0 ) {
330330
goto fail;
331331
}
332332

333333
while (mlen >= step) {
334-
if ( (err = blake2bp_update(&S, p, step)) < 0 ) {
334+
if ( (err = _cryptonite_blake2bp_update(&S, p, step)) < 0 ) {
335335
goto fail;
336336
}
337337
mlen -= step;
338338
p += step;
339339
}
340-
if ( (err = blake2bp_update(&S, p, mlen)) < 0) {
340+
if ( (err = _cryptonite_blake2bp_update(&S, p, mlen)) < 0) {
341341
goto fail;
342342
}
343-
if ( (err = blake2bp_final(&S, hash, BLAKE2B_OUTBYTES)) < 0) {
343+
if ( (err = _cryptonite_blake2bp_final(&S, hash, BLAKE2B_OUTBYTES)) < 0) {
344344
goto fail;
345345
}
346346

cbits/blake2/ref/blake2s-ref.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static void blake2s_init0( blake2s_state *S )
7373
}
7474

7575
/* init2 xors IV with input parameter block */
76-
int blake2s_init_param( blake2s_state *S, const blake2s_param *P )
76+
int _cryptonite_blake2s_init_param( blake2s_state *S, const blake2s_param *P )
7777
{
7878
const unsigned char *p = ( const unsigned char * )( P );
7979
size_t i;
@@ -90,7 +90,7 @@ int blake2s_init_param( blake2s_state *S, const blake2s_param *P )
9090

9191

9292
/* Sequential blake2s initialization */
93-
int blake2s_init( blake2s_state *S, size_t outlen )
93+
int _cryptonite_blake2s_init( blake2s_state *S, size_t outlen )
9494
{
9595
blake2s_param P[1];
9696

@@ -109,10 +109,10 @@ int blake2s_init( blake2s_state *S, size_t outlen )
109109
/* memset(P->reserved, 0, sizeof(P->reserved) ); */
110110
memset( P->salt, 0, sizeof( P->salt ) );
111111
memset( P->personal, 0, sizeof( P->personal ) );
112-
return blake2s_init_param( S, P );
112+
return _cryptonite_blake2s_init_param( S, P );
113113
}
114114

115-
int blake2s_init_key( blake2s_state *S, size_t outlen, const void *key, size_t keylen )
115+
int _cryptonite_blake2s_init_key( blake2s_state *S, size_t outlen, const void *key, size_t keylen )
116116
{
117117
blake2s_param P[1];
118118

@@ -133,13 +133,13 @@ int blake2s_init_key( blake2s_state *S, size_t outlen, const void *key, size_t k
133133
memset( P->salt, 0, sizeof( P->salt ) );
134134
memset( P->personal, 0, sizeof( P->personal ) );
135135

136-
if( blake2s_init_param( S, P ) < 0 ) return -1;
136+
if( _cryptonite_blake2s_init_param( S, P ) < 0 ) return -1;
137137

138138
{
139139
uint8_t block[BLAKE2S_BLOCKBYTES];
140140
memset( block, 0, BLAKE2S_BLOCKBYTES );
141141
memcpy( block, key, keylen );
142-
blake2s_update( S, block, BLAKE2S_BLOCKBYTES );
142+
_cryptonite_blake2s_update( S, block, BLAKE2S_BLOCKBYTES );
143143
secure_zero_memory( block, BLAKE2S_BLOCKBYTES ); /* Burn the key from stack */
144144
}
145145
return 0;
@@ -211,7 +211,7 @@ static void blake2s_compress( blake2s_state *S, const uint8_t in[BLAKE2S_BLOCKBY
211211
#undef G
212212
#undef ROUND
213213

214-
int blake2s_update( blake2s_state *S, const void *pin, size_t inlen )
214+
int _cryptonite_blake2s_update( blake2s_state *S, const void *pin, size_t inlen )
215215
{
216216
const unsigned char * in = (const unsigned char *)pin;
217217
if( inlen > 0 )
@@ -238,7 +238,7 @@ int blake2s_update( blake2s_state *S, const void *pin, size_t inlen )
238238
return 0;
239239
}
240240

241-
int blake2s_final( blake2s_state *S, void *out, size_t outlen )
241+
int _cryptonite_blake2s_final( blake2s_state *S, void *out, size_t outlen )
242242
{
243243
uint8_t buffer[BLAKE2S_OUTBYTES] = {0};
244244
size_t i;
@@ -262,7 +262,7 @@ int blake2s_final( blake2s_state *S, void *out, size_t outlen )
262262
return 0;
263263
}
264264

265-
int blake2s( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen )
265+
int _cryptonite_blake2s( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen )
266266
{
267267
blake2s_state S[1];
268268

@@ -279,22 +279,22 @@ int blake2s( void *out, size_t outlen, const void *in, size_t inlen, const void
279279

280280
if( keylen > 0 )
281281
{
282-
if( blake2s_init_key( S, outlen, key, keylen ) < 0 ) return -1;
282+
if( _cryptonite_blake2s_init_key( S, outlen, key, keylen ) < 0 ) return -1;
283283
}
284284
else
285285
{
286-
if( blake2s_init( S, outlen ) < 0 ) return -1;
286+
if( _cryptonite_blake2s_init( S, outlen ) < 0 ) return -1;
287287
}
288288

289-
blake2s_update( S, ( const uint8_t * )in, inlen );
290-
blake2s_final( S, out, outlen );
289+
_cryptonite_blake2s_update( S, ( const uint8_t * )in, inlen );
290+
_cryptonite_blake2s_final( S, out, outlen );
291291
return 0;
292292
}
293293

294294
#if defined(SUPERCOP)
295295
int crypto_hash( unsigned char *out, unsigned char *in, unsigned long long inlen )
296296
{
297-
return blake2s( out, BLAKE2S_OUTBYTES, in, inlen, NULL, 0 );
297+
return _cryptonite_blake2s( out, BLAKE2S_OUTBYTES, in, inlen, NULL, 0 );
298298
}
299299
#endif
300300

@@ -317,7 +317,7 @@ int main( void )
317317
for( i = 0; i < BLAKE2_KAT_LENGTH; ++i )
318318
{
319319
uint8_t hash[BLAKE2S_OUTBYTES];
320-
blake2s( hash, BLAKE2S_OUTBYTES, buf, i, key, BLAKE2S_KEYBYTES );
320+
_cryptonite_blake2s( hash, BLAKE2S_OUTBYTES, buf, i, key, BLAKE2S_KEYBYTES );
321321

322322
if( 0 != memcmp( hash, blake2s_keyed_kat[i], BLAKE2S_OUTBYTES ) )
323323
{
@@ -334,21 +334,21 @@ int main( void )
334334
size_t mlen = i;
335335
int err = 0;
336336

337-
if( (err = blake2s_init_key(&S, BLAKE2S_OUTBYTES, key, BLAKE2S_KEYBYTES)) < 0 ) {
337+
if( (err = _cryptonite_blake2s_init_key(&S, BLAKE2S_OUTBYTES, key, BLAKE2S_KEYBYTES)) < 0 ) {
338338
goto fail;
339339
}
340340

341341
while (mlen >= step) {
342-
if ( (err = blake2s_update(&S, p, step)) < 0 ) {
342+
if ( (err = _cryptonite_blake2s_update(&S, p, step)) < 0 ) {
343343
goto fail;
344344
}
345345
mlen -= step;
346346
p += step;
347347
}
348-
if ( (err = blake2s_update(&S, p, mlen)) < 0) {
348+
if ( (err = _cryptonite_blake2s_update(&S, p, mlen)) < 0) {
349349
goto fail;
350350
}
351-
if ( (err = blake2s_final(&S, hash, BLAKE2S_OUTBYTES)) < 0) {
351+
if ( (err = _cryptonite_blake2s_final(&S, hash, BLAKE2S_OUTBYTES)) < 0) {
352352
goto fail;
353353
}
354354

0 commit comments

Comments
 (0)