From 73dd9e9038e5d8ca8efad8c19efce70335292f17 Mon Sep 17 00:00:00 2001 From: JP Aumasson Date: Tue, 11 Oct 2016 20:48:16 +0200 Subject: [PATCH] b2s xof unkeyed kats --- ref/blake2.h | 3 +++ ref/blake2bp-ref.c | 6 ++++-- ref/blake2sp-ref.c | 6 ++++-- ref/genkat-c.c | 24 ++++++++++++++++++++++++ ref/makefile | 4 ++-- 5 files changed, 37 insertions(+), 6 deletions(-) diff --git a/ref/blake2.h b/ref/blake2.h index 8e8de54..cef9bf2 100644 --- a/ref/blake2.h +++ b/ref/blake2.h @@ -159,6 +159,9 @@ extern "C" { int blake2sp( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen ); int blake2bp( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen ); + int blake2xs( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen ); + int blake2xb( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen ); + /* This is simply an alias for blake2b */ int blake2( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen ); diff --git a/ref/blake2bp-ref.c b/ref/blake2bp-ref.c index 8bbe305..ae48861 100644 --- a/ref/blake2bp-ref.c +++ b/ref/blake2bp-ref.c @@ -35,7 +35,8 @@ static int blake2bp_init_leaf( blake2b_state *S, size_t outlen, size_t keylen, u P->fanout = PARALLELISM_DEGREE; P->depth = 2; store32( &P->leaf_length, 0 ); - store64( &P->node_offset, offset ); + store32( &P->node_offset, offset ); + store32( &P->xof_length, 0 ); P->node_depth = 0; P->inner_length = BLAKE2B_OUTBYTES; memset( P->reserved, 0, sizeof( P->reserved ) ); @@ -52,7 +53,8 @@ static int blake2bp_init_root( blake2b_state *S, size_t outlen, size_t keylen ) P->fanout = PARALLELISM_DEGREE; P->depth = 2; store32( &P->leaf_length, 0 ); - store64( &P->node_offset, 0 ); + store32( &P->node_offset, 0 ); + store32( &P->xof_length, 0 ); P->node_depth = 1; P->inner_length = BLAKE2B_OUTBYTES; memset( P->reserved, 0, sizeof( P->reserved ) ); diff --git a/ref/blake2sp-ref.c b/ref/blake2sp-ref.c index 8c617ad..3e6be19 100644 --- a/ref/blake2sp-ref.c +++ b/ref/blake2sp-ref.c @@ -34,7 +34,8 @@ static int blake2sp_init_leaf( blake2s_state *S, size_t outlen, size_t keylen, u P->fanout = PARALLELISM_DEGREE; P->depth = 2; store32( &P->leaf_length, 0 ); - store48( P->node_offset, offset ); + store32( &P->node_offset, offset ); + store16( &P->xof_length, 0 ); P->node_depth = 0; P->inner_length = BLAKE2S_OUTBYTES; memset( P->salt, 0, sizeof( P->salt ) ); @@ -50,7 +51,8 @@ static int blake2sp_init_root( blake2s_state *S, size_t outlen, size_t keylen ) P->fanout = PARALLELISM_DEGREE; P->depth = 2; store32( &P->leaf_length, 0 ); - store48( P->node_offset, 0ULL ); + store32( &P->node_offset, 0ULL ); + store16( &P->xof_length, 0ULL ); P->node_depth = 1; P->inner_length = BLAKE2S_OUTBYTES; memset( P->salt, 0, sizeof( P->salt ) ); diff --git a/ref/genkat-c.c b/ref/genkat-c.c index 1525f8d..52df0ee 100644 --- a/ref/genkat-c.c +++ b/ref/genkat-c.c @@ -65,6 +65,29 @@ do \ \ } while (0) +#define MAKE_XOF_KAT(name) \ +do \ +{ \ + printf( "static const uint8_t " #name "_kat[BLAKE2_KAT_LENGTH][BLAKE2_KAT_LENGTH] = \n{\n" ); \ + \ + for( size_t i = 0; i < LENGTH; ++i ) \ + { \ + name( hash, i, in, LENGTH, NULL, 0 ); \ + printf( "\t{\n\t\t" ); \ + \ + for( int j = 0; j < i; ++j ) \ + printf( "0x%02X%s", hash[j], j && !( ( j + 1 ) % 8 ) ? ",\n\t\t" : ", " ); \ + \ + for( int j = i; j < LENGTH; ++j ) \ + printf( "0x00%s", ( j + 1 ) == LENGTH ? "\n" : j && !( ( j + 1 ) % 8 ) ? ",\n\t\t" : ", " ); \ + \ + printf( "\t},\n" ); \ + } \ + \ + printf( "};\n\n\n\n\n" ); \ + \ +} while (0) + int main( int argc, char **argv ) { @@ -90,6 +113,7 @@ int main( int argc, char **argv ) MAKE_KEYED_KAT( blake2sp, BLAKE2S ); MAKE_KAT( blake2bp, BLAKE2B ); MAKE_KEYED_KAT( blake2bp, BLAKE2B ); + MAKE_XOF_KAT( blake2xs ); puts( "#endif" ); return 0; } diff --git a/ref/makefile b/ref/makefile index 7835313..ecf0f09 100644 --- a/ref/makefile +++ b/ref/makefile @@ -31,8 +31,8 @@ check: blake2s blake2b blake2sp blake2bp blake2xs blake2xb ./blake2xb kat: - $(CC) $(CFLAGS) -o genkat-c genkat-c.c blake2b-ref.c blake2s-ref.c blake2sp-ref.c blake2bp-ref.c - $(CC) $(CFLAGS) -g -o genkat-json genkat-json.c blake2b-ref.c blake2s-ref.c blake2sp-ref.c blake2bp-ref.c + $(CC) $(CFLAGS) -o genkat-c genkat-c.c blake2b-ref.c blake2s-ref.c blake2sp-ref.c blake2bp-ref.c blake2xs-ref.c blake2xb-ref.c + $(CC) $(CFLAGS) -o genkat-json genkat-json.c blake2b-ref.c blake2s-ref.c blake2sp-ref.c blake2bp-ref.c blake2xs-ref.c blake2xb-ref.c ./genkat-c > blake2-kat.h ./genkat-json > blake2-kat.json