MCPcopy Create free account
hub / github.com/F-Stack/f-stack / blake2sp

Function blake2sp

freebsd/contrib/libb2/blake2sp.c:194–270  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

192
193
194int blake2sp( uint8_t *out, const void *in, const void *key, size_t outlen, size_t inlen, size_t keylen )
195{
196 uint8_t hash[PARALLELISM_DEGREE][BLAKE2S_OUTBYTES];
197 blake2s_state S[PARALLELISM_DEGREE][1];
198 blake2s_state FS[1];
199
200 /* Verify parameters */
201 if ( NULL == in && inlen > 0 ) return -1;
202
203 if ( NULL == out ) return -1;
204
205 if ( NULL == key && keylen > 0 ) return -1;
206
207 if( !outlen || outlen > BLAKE2S_OUTBYTES ) return -1;
208
209 if( keylen > BLAKE2S_KEYBYTES ) return -1;
210
211 for( size_t i = 0; i < PARALLELISM_DEGREE; ++i )
212 if( blake2sp_init_leaf( S[i], ( uint8_t ) outlen, ( uint8_t ) keylen, i ) < 0 )
213 return -1;
214
215 S[PARALLELISM_DEGREE - 1]->last_node = 1; // mark last node
216
217 if( keylen > 0 )
218 {
219 uint8_t block[BLAKE2S_BLOCKBYTES];
220 memset( block, 0, BLAKE2S_BLOCKBYTES );
221 memcpy( block, key, keylen );
222
223 for( size_t i = 0; i < PARALLELISM_DEGREE; ++i )
224 blake2s_update( S[i], block, BLAKE2S_BLOCKBYTES );
225
226 secure_zero_memory( block, BLAKE2S_BLOCKBYTES ); /* Burn the key from stack */
227 }
228
229#if defined(_OPENMP)
230 omp_set_num_threads(PARALLELISM_DEGREE);
231 #pragma omp parallel shared(S,hash)
232#else
233
234 for( size_t id__ = 0; id__ < PARALLELISM_DEGREE; ++id__ )
235#endif
236 {
237#if defined(_OPENMP)
238 size_t id__ = ( size_t ) omp_get_thread_num();
239#endif
240 size_t inlen__ = inlen;
241 const uint8_t *in__ = ( const uint8_t * )in;
242 in__ += id__ * BLAKE2S_BLOCKBYTES;
243
244 while( inlen__ >= PARALLELISM_DEGREE * BLAKE2S_BLOCKBYTES )
245 {
246 blake2s_update( S[id__], in__, BLAKE2S_BLOCKBYTES );
247 in__ += PARALLELISM_DEGREE * BLAKE2S_BLOCKBYTES;
248 inlen__ -= PARALLELISM_DEGREE * BLAKE2S_BLOCKBYTES;
249 }
250
251 if( inlen__ > id__ * BLAKE2S_BLOCKBYTES )

Callers

nothing calls this directly

Calls 7

blake2sp_init_leafFunction · 0.85
memsetFunction · 0.85
secure_zero_memoryFunction · 0.85
blake2sp_init_rootFunction · 0.85
blake2s_updateFunction · 0.70
blake2s_finalFunction · 0.70
memcpyFunction · 0.50

Tested by

no test coverage detected