Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/BLAKE2/BLAKE2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Neves <sneves@dei.uc.pt>2016-06-11 14:22:35 +0300
committerSamuel Neves <sneves@dei.uc.pt>2016-06-11 14:22:35 +0300
commit64cafcff1620ab778d23057e1c7559087d7bd4e6 (patch)
tree24e415f6b2a08f3381427c37ca25a0df87df5ef7 /sse/blake2bp.c
parent8a007c8cbb18d860f5e6491b150f7d3bd3c9c616 (diff)
test streaming api
Diffstat (limited to 'sse/blake2bp.c')
-rw-r--r--sse/blake2bp.c48
1 files changed, 40 insertions, 8 deletions
diff --git a/sse/blake2bp.c b/sse/blake2bp.c
index 952a498..a18b99b 100644
--- a/sse/blake2bp.c
+++ b/sse/blake2bp.c
@@ -277,7 +277,7 @@ int main( void )
{
uint8_t key[BLAKE2B_KEYBYTES];
uint8_t buf[BLAKE2_KAT_LENGTH];
- size_t i;
+ size_t i, step;
for( i = 0; i < BLAKE2B_KEYBYTES; ++i )
key[i] = ( uint8_t )i;
@@ -285,24 +285,56 @@ int main( void )
for( i = 0; i < BLAKE2_KAT_LENGTH; ++i )
buf[i] = ( uint8_t )i;
+ /* Test simple API */
for( i = 0; i < BLAKE2_KAT_LENGTH; ++i )
{
uint8_t hash[BLAKE2B_OUTBYTES];
- /*blake2bp( hash, buf, key, BLAKE2B_OUTBYTES, i, BLAKE2B_KEYBYTES ); */
- blake2bp_state S[1];
- blake2bp_init_key( S, BLAKE2B_OUTBYTES, key, BLAKE2B_KEYBYTES );
- blake2bp_update( S, buf, i );
- blake2bp_final( S, hash, BLAKE2B_OUTBYTES );
+ blake2bp( hash, BLAKE2B_OUTBYTES, buf, i, key, BLAKE2B_KEYBYTES );
if( 0 != memcmp( hash, blake2bp_keyed_kat[i], BLAKE2B_OUTBYTES ) )
{
- puts( "error" );
- return -1;
+ goto fail;
+ }
+ }
+
+ /* Test streaming API */
+ for(step = 1; step < BLAKE2B_BLOCKBYTES; ++step) {
+ for (i = 0; i < BLAKE2_KAT_LENGTH; ++i) {
+ uint8_t hash[BLAKE2B_OUTBYTES];
+ blake2bp_state S;
+ uint8_t * p = buf;
+ size_t mlen = i;
+ int err = 0;
+
+ if( (err = blake2bp_init_key(&S, BLAKE2B_OUTBYTES, key, BLAKE2B_KEYBYTES)) < 0 ) {
+ goto fail;
+ }
+
+ while (mlen >= step) {
+ if ( (err = blake2bp_update(&S, p, step)) < 0 ) {
+ goto fail;
+ }
+ mlen -= step;
+ p += step;
+ }
+ if ( (err = blake2bp_update(&S, p, mlen)) < 0) {
+ goto fail;
+ }
+ if ( (err = blake2bp_final(&S, hash, BLAKE2B_OUTBYTES)) < 0) {
+ goto fail;
+ }
+
+ if (0 != memcmp(hash, blake2bp_keyed_kat[i], BLAKE2B_OUTBYTES)) {
+ goto fail;
+ }
}
}
puts( "ok" );
return 0;
+fail:
+ puts("error");
+ return -1;
}
#endif