mirror of
https://github.com/BLAKE2/BLAKE2
synced 2024-11-22 02:31:57 +01:00
formatting, more c89
This commit is contained in:
parent
7a39ee4736
commit
c19dd2bd83
@ -1,14 +1,14 @@
|
||||
/*
|
||||
BLAKE2 reference source code package - b2sum tool
|
||||
|
||||
|
||||
Copyright 2012, Samuel Neves <sneves@dei.uc.pt>. You may use this under the
|
||||
terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at
|
||||
your option. The terms of these licenses can be found at:
|
||||
|
||||
|
||||
- CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
|
||||
- OpenSSL license : https://www.openssl.org/source/license.html
|
||||
- Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
|
||||
More information about the BLAKE2 hash function can be found at
|
||||
https://blake2.net.
|
||||
*/
|
||||
@ -256,12 +256,11 @@ int main( int argc, char **argv )
|
||||
unsigned long outbytes = 0;
|
||||
unsigned char hash[BLAKE2B_OUTBYTES] = {0};
|
||||
bool bsdstyle = false;
|
||||
int c;
|
||||
int c, i;
|
||||
opterr = 1;
|
||||
|
||||
while( 1 )
|
||||
{
|
||||
int this_option_optind = optind ? optind : 1;
|
||||
int option_index = 0;
|
||||
char *end = NULL;
|
||||
unsigned long outbits;
|
||||
@ -343,7 +342,7 @@ int main( int argc, char **argv )
|
||||
if( optind == argc )
|
||||
argv[argc++] = (char *) "-";
|
||||
|
||||
for( int i = optind; i < argc; ++i )
|
||||
for( i = optind; i < argc; ++i )
|
||||
{
|
||||
FILE *f = NULL;
|
||||
if( argv[i][0] == '-' && argv[i][1] == '\0' )
|
||||
@ -363,6 +362,7 @@ int main( int argc, char **argv )
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t j;
|
||||
if( bsdstyle )
|
||||
{
|
||||
if( outbytes < maxbytes )
|
||||
@ -371,7 +371,7 @@ int main( int argc, char **argv )
|
||||
printf( "%s (%s) = ", algorithm, argv[i] );
|
||||
}
|
||||
|
||||
for( size_t j = 0; j < outbytes; ++j )
|
||||
for( j = 0; j < outbytes; ++j )
|
||||
printf( "%02x", hash[j] );
|
||||
|
||||
if( bsdstyle )
|
||||
|
@ -5,12 +5,12 @@ NO_OPENMP?=0
|
||||
NO_OPENMP_0=-fopenmp
|
||||
NO_OPENMP_1=
|
||||
CC?=gcc
|
||||
CFLAGS?=-O3 -march=native -Werror=declaration-after-statement
|
||||
CFLAGS+=-std=c99 -I../sse
|
||||
CFLAGS?=-O3 -march=native
|
||||
CFLAGS+=-std=c89 -Wall -Wextra -pedantic -Wno-long-long -I../sse
|
||||
CFLAGS+=$(NO_OPENMP_$(NO_OPENMP))
|
||||
LIBS=
|
||||
#FILES=b2sum.c ../ref/blake2b-ref.c ../ref/blake2s-ref.c ../ref/blake2bp-ref.c ../ref/blake2sp-ref.c
|
||||
FILES=b2sum.c ../sse/blake2b.c ../sse/blake2s.c ../sse/blake2bp.c ../sse/blake2sp.c
|
||||
#FILES=b2sum.c ../ref/blake2b-ref.c ../ref/blake2s-ref.c ../ref/blake2bp-ref.c ../ref/blake2sp-ref.c
|
||||
FILES=b2sum.c ../sse/blake2b.c ../sse/blake2s.c ../sse/blake2bp.c ../sse/blake2sp.c
|
||||
all: $(FILES)
|
||||
$(CC) $(FILES) $(CFLAGS) $(LIBS) -o $(PROG)
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
CC=gcc
|
||||
# std to gnu99 to support inline asm
|
||||
CFLAGS=-O3 -march=native -DSUPERCOP # -DHAVE_XOP # uncomment on XOP-enabled CPUs
|
||||
CFLAGS=-O3 -march=native -Wall -Wextra -DSUPERCOP # -DHAVE_XOP # uncomment on XOP-enabled CPUs
|
||||
FILES=bench.c
|
||||
|
||||
all: bench
|
||||
@ -9,7 +9,7 @@ bench: bench.c
|
||||
$(CC) $(FILES) $(CFLAGS) ../sse/blake2b.c -o blake2b
|
||||
$(CC) $(FILES) $(CFLAGS) ../sse/blake2s.c -o blake2s
|
||||
$(CC) $(FILES) $(CFLAGS) md5.c -o md5 -lcrypto -lz
|
||||
|
||||
|
||||
plot: bench
|
||||
./blake2b > blake2b.data
|
||||
./blake2s > blake2s.data
|
||||
|
207
ref/genkat-c.c
207
ref/genkat-c.c
@ -1,14 +1,14 @@
|
||||
/*
|
||||
BLAKE2 reference source code package - reference C implementations
|
||||
|
||||
|
||||
Copyright 2012, Samuel Neves <sneves@dei.uc.pt>. You may use this under the
|
||||
terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at
|
||||
your option. The terms of these licenses can be found at:
|
||||
|
||||
|
||||
- CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
|
||||
- OpenSSL license : https://www.openssl.org/source/license.html
|
||||
- Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
|
||||
More information about the BLAKE2 hash function can be found at
|
||||
https://blake2.net.
|
||||
*/
|
||||
@ -25,122 +25,115 @@
|
||||
|
||||
#define LENGTH 256
|
||||
|
||||
#define MAKE_KAT(name,size_prefix) \
|
||||
do \
|
||||
{ \
|
||||
printf( "static const uint8_t " #name "_kat[BLAKE2_KAT_LENGTH][" #size_prefix "_OUTBYTES] = \n{\n" ); \
|
||||
\
|
||||
for( i = 0; i < LENGTH; ++i ) \
|
||||
{ \
|
||||
name( hash, size_prefix ## _OUTBYTES, in, i, NULL, 0 ); \
|
||||
printf( "\t{\n\t\t" ); \
|
||||
\
|
||||
for( j = 0; j < size_prefix ## _OUTBYTES; ++j ) \
|
||||
printf( "0x%02X%s", hash[j], ( j + 1 ) == size_prefix ## _OUTBYTES ? "\n" : j && !( ( j + 1 ) % 8 ) ? ",\n\t\t" : ", " ); \
|
||||
\
|
||||
printf( "\t},\n" ); \
|
||||
} \
|
||||
\
|
||||
printf( "};\n\n\n\n\n" ); \
|
||||
\
|
||||
} while (0)
|
||||
#define MAKE_KAT(name, size_prefix) \
|
||||
do { \
|
||||
printf("static const uint8_t " #name "_kat[BLAKE2_KAT_LENGTH][" #size_prefix \
|
||||
"_OUTBYTES] = \n{\n"); \
|
||||
\
|
||||
for (i = 0; i < LENGTH; ++i) { \
|
||||
name(hash, size_prefix##_OUTBYTES, in, i, NULL, 0); \
|
||||
printf("\t{\n\t\t"); \
|
||||
\
|
||||
for (j = 0; j < size_prefix##_OUTBYTES; ++j) \
|
||||
printf("0x%02X%s", hash[j], \
|
||||
(j + 1) == size_prefix##_OUTBYTES ? "\n" : j && !((j + 1) % 8) ? ",\n\t\t" : ", "); \
|
||||
\
|
||||
printf("\t},\n"); \
|
||||
} \
|
||||
\
|
||||
printf("};\n\n\n\n\n"); \
|
||||
} while (0)
|
||||
|
||||
#define MAKE_KEYED_KAT(name,size_prefix) \
|
||||
do \
|
||||
{ \
|
||||
printf( "static const uint8_t " #name "_keyed_kat[BLAKE2_KAT_LENGTH][" #size_prefix "_OUTBYTES] = \n{\n" ); \
|
||||
\
|
||||
for( i = 0; i < LENGTH; ++i ) \
|
||||
{ \
|
||||
name( hash, size_prefix ## _OUTBYTES, in, i, key, size_prefix ## _KEYBYTES ); \
|
||||
printf( "\t{\n\t\t" ); \
|
||||
\
|
||||
for( j = 0; j < size_prefix ## _OUTBYTES; ++j ) \
|
||||
printf( "0x%02X%s", hash[j], ( j + 1 ) == size_prefix ## _OUTBYTES ? "\n" : j && !( ( j + 1 ) % 8 ) ? ",\n\t\t" : ", " ); \
|
||||
\
|
||||
printf( "\t},\n" ); \
|
||||
} \
|
||||
\
|
||||
printf( "};\n\n\n\n\n" ); \
|
||||
\
|
||||
} while (0)
|
||||
#define MAKE_KEYED_KAT(name, size_prefix) \
|
||||
do { \
|
||||
printf("static const uint8_t " #name "_keyed_kat[BLAKE2_KAT_LENGTH][" #size_prefix \
|
||||
"_OUTBYTES] = \n{\n"); \
|
||||
\
|
||||
for (i = 0; i < LENGTH; ++i) { \
|
||||
name(hash, size_prefix##_OUTBYTES, in, i, key, size_prefix##_KEYBYTES); \
|
||||
printf("\t{\n\t\t"); \
|
||||
\
|
||||
for (j = 0; j < size_prefix##_OUTBYTES; ++j) \
|
||||
printf("0x%02X%s", hash[j], \
|
||||
(j + 1) == size_prefix##_OUTBYTES ? "\n" : j && !((j + 1) % 8) ? ",\n\t\t" : ", "); \
|
||||
\
|
||||
printf("\t},\n"); \
|
||||
} \
|
||||
\
|
||||
printf("};\n\n\n\n\n"); \
|
||||
} while (0)
|
||||
|
||||
#define MAKE_XOF_KAT(name) \
|
||||
do \
|
||||
{ \
|
||||
printf( "static const uint8_t " #name "_kat[BLAKE2_KAT_LENGTH][BLAKE2_KAT_LENGTH] = \n{\n" ); \
|
||||
\
|
||||
for( i = 1; i <= LENGTH; ++i ) \
|
||||
{ \
|
||||
name( hash, i, in, LENGTH, NULL, 0 ); \
|
||||
printf( "\t{\n\t\t" ); \
|
||||
\
|
||||
for( j = 0; j < i; ++j ) \
|
||||
printf( "0x%02X%s", hash[j], ( j + 1 ) == LENGTH ? "\n" : j && !( ( j + 1 ) % 8 ) ? ",\n\t\t" : ", " ); \
|
||||
\
|
||||
for( 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)
|
||||
#define MAKE_XOF_KAT(name) \
|
||||
do { \
|
||||
printf("static const uint8_t " #name "_kat[BLAKE2_KAT_LENGTH][BLAKE2_KAT_LENGTH] = \n{\n"); \
|
||||
\
|
||||
for (i = 1; i <= LENGTH; ++i) { \
|
||||
name(hash, i, in, LENGTH, NULL, 0); \
|
||||
printf("\t{\n\t\t"); \
|
||||
\
|
||||
for (j = 0; j < i; ++j) \
|
||||
printf("0x%02X%s", hash[j], \
|
||||
(j + 1) == LENGTH ? "\n" : j && !((j + 1) % 8) ? ",\n\t\t" : ", "); \
|
||||
\
|
||||
for (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)
|
||||
|
||||
#define MAKE_XOF_KEYED_KAT(name,size_prefix) \
|
||||
do \
|
||||
{ \
|
||||
printf( "static const uint8_t " #name "_keyed_kat[BLAKE2_KAT_LENGTH][BLAKE2_KAT_LENGTH] = \n{\n" ); \
|
||||
\
|
||||
for( i = 1; i <= LENGTH; ++i ) \
|
||||
{ \
|
||||
name( hash, i, in, LENGTH, key, size_prefix ## _KEYBYTES ); \
|
||||
printf( "\t{\n\t\t" ); \
|
||||
\
|
||||
for( j = 0; j < i; ++j ) \
|
||||
printf( "0x%02X%s", hash[j], ( j + 1 ) == LENGTH ? "\n" : j && !( ( j + 1 ) % 8 ) ? ",\n\t\t" : ", " ); \
|
||||
\
|
||||
for( 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)
|
||||
#define MAKE_XOF_KEYED_KAT(name, size_prefix) \
|
||||
do { \
|
||||
printf("static const uint8_t " #name \
|
||||
"_keyed_kat[BLAKE2_KAT_LENGTH][BLAKE2_KAT_LENGTH] = \n{\n"); \
|
||||
\
|
||||
for (i = 1; i <= LENGTH; ++i) { \
|
||||
name(hash, i, in, LENGTH, key, size_prefix##_KEYBYTES); \
|
||||
printf("\t{\n\t\t"); \
|
||||
\
|
||||
for (j = 0; j < i; ++j) \
|
||||
printf("0x%02X%s", hash[j], \
|
||||
(j + 1) == LENGTH ? "\n" : j && !((j + 1) % 8) ? ",\n\t\t" : ", "); \
|
||||
\
|
||||
for (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 main() {
|
||||
uint8_t key[64] = {0};
|
||||
uint8_t in[LENGTH] = {0};
|
||||
uint8_t hash[LENGTH] = {0};
|
||||
size_t i, j;
|
||||
|
||||
for( i = 0; i < sizeof( in ); ++i )
|
||||
for (i = 0; i < sizeof(in); ++i)
|
||||
in[i] = i;
|
||||
|
||||
for( i = 0; i < sizeof( key ); ++i )
|
||||
for (i = 0; i < sizeof(key); ++i)
|
||||
key[i] = i;
|
||||
|
||||
puts( "#ifndef BLAKE2_KAT_H\n"
|
||||
"#define BLAKE2_KAT_H\n\n\n"
|
||||
"#include <stdint.h>\n\n"
|
||||
"#define BLAKE2_KAT_LENGTH " STR( LENGTH ) "\n\n\n" );
|
||||
MAKE_KAT( blake2s, BLAKE2S );
|
||||
MAKE_KEYED_KAT( blake2s, BLAKE2S );
|
||||
MAKE_KAT( blake2b, BLAKE2B );
|
||||
MAKE_KEYED_KAT( blake2b, BLAKE2B );
|
||||
MAKE_KAT( blake2sp, BLAKE2S );
|
||||
MAKE_KEYED_KAT( blake2sp, BLAKE2S );
|
||||
MAKE_KAT( blake2bp, BLAKE2B );
|
||||
MAKE_KEYED_KAT( blake2bp, BLAKE2B );
|
||||
MAKE_XOF_KAT( blake2xs );
|
||||
MAKE_XOF_KEYED_KAT( blake2xs, BLAKE2S );
|
||||
MAKE_XOF_KAT( blake2xb );
|
||||
MAKE_XOF_KEYED_KAT( blake2xb, BLAKE2B );
|
||||
puts( "#endif" );
|
||||
puts("#ifndef BLAKE2_KAT_H\n"
|
||||
"#define BLAKE2_KAT_H\n\n\n"
|
||||
"#include <stdint.h>\n\n"
|
||||
"#define BLAKE2_KAT_LENGTH " STR(LENGTH) "\n\n\n");
|
||||
MAKE_KAT(blake2s, BLAKE2S);
|
||||
MAKE_KEYED_KAT(blake2s, BLAKE2S);
|
||||
MAKE_KAT(blake2b, BLAKE2B);
|
||||
MAKE_KEYED_KAT(blake2b, BLAKE2B);
|
||||
MAKE_KAT(blake2sp, BLAKE2S);
|
||||
MAKE_KEYED_KAT(blake2sp, BLAKE2S);
|
||||
MAKE_KAT(blake2bp, BLAKE2B);
|
||||
MAKE_KEYED_KAT(blake2bp, BLAKE2B);
|
||||
MAKE_XOF_KAT(blake2xs);
|
||||
MAKE_XOF_KEYED_KAT(blake2xs, BLAKE2S);
|
||||
MAKE_XOF_KAT(blake2xb);
|
||||
MAKE_XOF_KEYED_KAT(blake2xb, BLAKE2B);
|
||||
puts("#endif");
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
/*
|
||||
BLAKE2 reference source code package - reference C implementations
|
||||
|
||||
|
||||
Copyright 2012, Samuel Neves <sneves@dei.uc.pt>. You may use this under the
|
||||
terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at
|
||||
your option. The terms of these licenses can be found at:
|
||||
|
||||
|
||||
- CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
|
||||
- OpenSSL license : https://www.openssl.org/source/license.html
|
||||
- Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
|
||||
More information about the BLAKE2 hash function can be found at
|
||||
https://blake2.net.
|
||||
*/
|
||||
@ -25,133 +25,129 @@
|
||||
|
||||
#define LENGTH 256
|
||||
|
||||
#define MAKE_KAT(name,size_prefix) \
|
||||
do \
|
||||
{ \
|
||||
for( i = 0; i < LENGTH; ++i ) \
|
||||
{ \
|
||||
printf("\n{\n");\
|
||||
\
|
||||
printf(" \"hash\": \"" #name "\",\n");\
|
||||
printf(" \"in\": \"");\
|
||||
for( j = 0; j < i; ++j ) printf( "%02x", in[j]);\
|
||||
\
|
||||
printf( "\",\n" ); \
|
||||
printf(" \"key\": \"\",\n");\
|
||||
printf(" \"out\": \"");\
|
||||
\
|
||||
name( hash, size_prefix ## _OUTBYTES, in, i, NULL, 0 ); \
|
||||
\
|
||||
for( j = 0; j < size_prefix ## _OUTBYTES; ++j ) \
|
||||
printf( "%02x", hash[j]);\
|
||||
printf( "\"\n" ); \
|
||||
printf( "}," ); \
|
||||
}\
|
||||
} while (0)
|
||||
#define MAKE_KAT(name, size_prefix) \
|
||||
do { \
|
||||
for (i = 0; i < LENGTH; ++i) { \
|
||||
printf("\n{\n"); \
|
||||
\
|
||||
printf(" \"hash\": \"" #name "\",\n"); \
|
||||
printf(" \"in\": \""); \
|
||||
for (j = 0; j < i; ++j) \
|
||||
printf("%02x", in[j]); \
|
||||
\
|
||||
printf("\",\n"); \
|
||||
printf(" \"key\": \"\",\n"); \
|
||||
printf(" \"out\": \""); \
|
||||
\
|
||||
name(hash, size_prefix##_OUTBYTES, in, i, NULL, 0); \
|
||||
\
|
||||
for (j = 0; j < size_prefix##_OUTBYTES; ++j) \
|
||||
printf("%02x", hash[j]); \
|
||||
printf("\"\n"); \
|
||||
printf("},"); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define MAKE_KEYED_KAT(name,size_prefix) \
|
||||
do \
|
||||
{ \
|
||||
for( i = 0; i < LENGTH; ++i ) \
|
||||
{ \
|
||||
printf("\n{\n");\
|
||||
\
|
||||
printf(" \"hash\": \"" #name "\",\n");\
|
||||
printf(" \"in\": \"");\
|
||||
for( j = 0; j < i; ++j ) printf( "%02x", in[j]);\
|
||||
\
|
||||
printf( "\",\n" ); \
|
||||
printf(" \"key\": \"");\
|
||||
for( j = 0; j < size_prefix ## _KEYBYTES; ++j ) printf( "%02x", key[j]);\
|
||||
printf("\",\n");\
|
||||
printf(" \"out\": \"");\
|
||||
\
|
||||
name( hash, size_prefix ## _OUTBYTES, in, i, key, size_prefix ## _KEYBYTES ); \
|
||||
\
|
||||
for( j = 0; j < size_prefix ## _OUTBYTES; ++j ) \
|
||||
printf( "%02x", hash[j]);\
|
||||
printf( "\"\n" ); \
|
||||
printf( "}," ); \
|
||||
}\
|
||||
} while (0)
|
||||
#define MAKE_KEYED_KAT(name, size_prefix) \
|
||||
do { \
|
||||
for (i = 0; i < LENGTH; ++i) { \
|
||||
printf("\n{\n"); \
|
||||
\
|
||||
printf(" \"hash\": \"" #name "\",\n"); \
|
||||
printf(" \"in\": \""); \
|
||||
for (j = 0; j < i; ++j) \
|
||||
printf("%02x", in[j]); \
|
||||
\
|
||||
printf("\",\n"); \
|
||||
printf(" \"key\": \""); \
|
||||
for (j = 0; j < size_prefix##_KEYBYTES; ++j) \
|
||||
printf("%02x", key[j]); \
|
||||
printf("\",\n"); \
|
||||
printf(" \"out\": \""); \
|
||||
\
|
||||
name(hash, size_prefix##_OUTBYTES, in, i, key, size_prefix##_KEYBYTES); \
|
||||
\
|
||||
for (j = 0; j < size_prefix##_OUTBYTES; ++j) \
|
||||
printf("%02x", hash[j]); \
|
||||
printf("\"\n"); \
|
||||
printf("},"); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define MAKE_XOF_KAT(name) \
|
||||
do \
|
||||
{ \
|
||||
for( i = 1; i <= LENGTH; ++i ) \
|
||||
{ \
|
||||
printf("\n{\n");\
|
||||
\
|
||||
printf(" \"hash\": \"" #name "\",\n");\
|
||||
printf(" \"in\": \"");\
|
||||
for( j = 0; j < LENGTH; ++j ) printf( "%02x", in[j]);\
|
||||
\
|
||||
printf( "\",\n" ); \
|
||||
printf(" \"key\": \"\",\n");\
|
||||
printf(" \"out\": \"");\
|
||||
\
|
||||
name( hash, i, in, LENGTH, NULL, 0 ); \
|
||||
\
|
||||
for( j = 0; j < i; ++j ) \
|
||||
printf( "%02x", hash[j]);\
|
||||
printf( "\"\n" ); \
|
||||
printf( "}," ); \
|
||||
}\
|
||||
} while (0)
|
||||
#define MAKE_XOF_KAT(name) \
|
||||
do { \
|
||||
for (i = 1; i <= LENGTH; ++i) { \
|
||||
printf("\n{\n"); \
|
||||
\
|
||||
printf(" \"hash\": \"" #name "\",\n"); \
|
||||
printf(" \"in\": \""); \
|
||||
for (j = 0; j < LENGTH; ++j) \
|
||||
printf("%02x", in[j]); \
|
||||
\
|
||||
printf("\",\n"); \
|
||||
printf(" \"key\": \"\",\n"); \
|
||||
printf(" \"out\": \""); \
|
||||
\
|
||||
name(hash, i, in, LENGTH, NULL, 0); \
|
||||
\
|
||||
for (j = 0; j < i; ++j) \
|
||||
printf("%02x", hash[j]); \
|
||||
printf("\"\n"); \
|
||||
printf("},"); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define MAKE_XOF_KEYED_KAT(name,size_prefix) \
|
||||
do \
|
||||
{ \
|
||||
for( i = 1; i <= LENGTH; ++i ) \
|
||||
{ \
|
||||
printf("\n{\n");\
|
||||
\
|
||||
printf(" \"hash\": \"" #name "\",\n");\
|
||||
printf(" \"in\": \"");\
|
||||
for( j = 0; j < LENGTH; ++j ) printf( "%02x", in[j]);\
|
||||
\
|
||||
printf( "\",\n" ); \
|
||||
printf(" \"key\": \"");\
|
||||
for( j = 0; j < size_prefix ## _KEYBYTES; ++j ) printf( "%02x", key[j]);\
|
||||
printf("\",\n");\
|
||||
printf(" \"out\": \"");\
|
||||
\
|
||||
name( hash, i, in, LENGTH, key, size_prefix ## _KEYBYTES ); \
|
||||
\
|
||||
for( j = 0; j < i; ++j ) \
|
||||
printf( "%02x", hash[j]);\
|
||||
printf( "\"\n" ); \
|
||||
printf( "}," ); \
|
||||
}\
|
||||
} while (0)
|
||||
#define MAKE_XOF_KEYED_KAT(name, size_prefix) \
|
||||
do { \
|
||||
for (i = 1; i <= LENGTH; ++i) { \
|
||||
printf("\n{\n"); \
|
||||
\
|
||||
printf(" \"hash\": \"" #name "\",\n"); \
|
||||
printf(" \"in\": \""); \
|
||||
for (j = 0; j < LENGTH; ++j) \
|
||||
printf("%02x", in[j]); \
|
||||
\
|
||||
printf("\",\n"); \
|
||||
printf(" \"key\": \""); \
|
||||
for (j = 0; j < size_prefix##_KEYBYTES; ++j) \
|
||||
printf("%02x", key[j]); \
|
||||
printf("\",\n"); \
|
||||
printf(" \"out\": \""); \
|
||||
\
|
||||
name(hash, i, in, LENGTH, key, size_prefix##_KEYBYTES); \
|
||||
\
|
||||
for (j = 0; j < i; ++j) \
|
||||
printf("%02x", hash[j]); \
|
||||
printf("\"\n"); \
|
||||
printf("},"); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
int main() {
|
||||
uint8_t key[64] = {0};
|
||||
uint8_t in[LENGTH] = {0};
|
||||
uint8_t hash[LENGTH] = {0};
|
||||
size_t i, j;
|
||||
|
||||
for( i = 0; i < sizeof( in ); ++i )
|
||||
for (i = 0; i < sizeof(in); ++i)
|
||||
in[i] = i;
|
||||
|
||||
for( i = 0; i < sizeof( key ); ++i )
|
||||
for (i = 0; i < sizeof(key); ++i)
|
||||
key[i] = i;
|
||||
|
||||
printf("[");
|
||||
MAKE_KAT( blake2s, BLAKE2S );
|
||||
MAKE_KEYED_KAT( blake2s, BLAKE2S );
|
||||
MAKE_KAT( blake2b, BLAKE2B );
|
||||
MAKE_KEYED_KAT( blake2b, BLAKE2B );
|
||||
MAKE_KAT( blake2sp, BLAKE2S );
|
||||
MAKE_KEYED_KAT( blake2sp, BLAKE2S );
|
||||
MAKE_KAT( blake2bp, BLAKE2B );
|
||||
MAKE_KEYED_KAT( blake2bp, BLAKE2B );
|
||||
MAKE_XOF_KAT( blake2xs );
|
||||
MAKE_XOF_KEYED_KAT( blake2xs, BLAKE2S );
|
||||
MAKE_XOF_KAT( blake2xb );
|
||||
MAKE_XOF_KEYED_KAT( blake2xb, BLAKE2B );
|
||||
MAKE_KAT(blake2s, BLAKE2S);
|
||||
MAKE_KEYED_KAT(blake2s, BLAKE2S);
|
||||
MAKE_KAT(blake2b, BLAKE2B);
|
||||
MAKE_KEYED_KAT(blake2b, BLAKE2B);
|
||||
MAKE_KAT(blake2sp, BLAKE2S);
|
||||
MAKE_KEYED_KAT(blake2sp, BLAKE2S);
|
||||
MAKE_KAT(blake2bp, BLAKE2B);
|
||||
MAKE_KEYED_KAT(blake2bp, BLAKE2B);
|
||||
MAKE_XOF_KAT(blake2xs);
|
||||
MAKE_XOF_KEYED_KAT(blake2xs, BLAKE2S);
|
||||
MAKE_XOF_KAT(blake2xb);
|
||||
MAKE_XOF_KEYED_KAT(blake2xb, BLAKE2B);
|
||||
printf("\n]\n");
|
||||
fflush(stdout);
|
||||
return 0;
|
||||
|
@ -1,5 +1,5 @@
|
||||
CC=gcc
|
||||
CFLAGS=-O2 -I../testvectors -Wall --std=c89
|
||||
CFLAGS=-O2 -I../testvectors -Wall -Wextra -std=c89 -pedantic -Wno-long-long
|
||||
BLAKEBINS=blake2s blake2b blake2sp blake2bp blake2xs blake2xb
|
||||
|
||||
all: $(BLAKEBINS) check
|
||||
|
207
sse/genkat-c.c
207
sse/genkat-c.c
@ -1,14 +1,14 @@
|
||||
/*
|
||||
BLAKE2 reference source code package - reference C implementations
|
||||
|
||||
|
||||
Copyright 2012, Samuel Neves <sneves@dei.uc.pt>. You may use this under the
|
||||
terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at
|
||||
your option. The terms of these licenses can be found at:
|
||||
|
||||
|
||||
- CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
|
||||
- OpenSSL license : https://www.openssl.org/source/license.html
|
||||
- Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
|
||||
More information about the BLAKE2 hash function can be found at
|
||||
https://blake2.net.
|
||||
*/
|
||||
@ -25,122 +25,115 @@
|
||||
|
||||
#define LENGTH 256
|
||||
|
||||
#define MAKE_KAT(name,size_prefix) \
|
||||
do \
|
||||
{ \
|
||||
printf( "static const uint8_t " #name "_kat[BLAKE2_KAT_LENGTH][" #size_prefix "_OUTBYTES] = \n{\n" ); \
|
||||
\
|
||||
for( i = 0; i < LENGTH; ++i ) \
|
||||
{ \
|
||||
name( hash, size_prefix ## _OUTBYTES, in, i, NULL, 0 ); \
|
||||
printf( "\t{\n\t\t" ); \
|
||||
\
|
||||
for( j = 0; j < size_prefix ## _OUTBYTES; ++j ) \
|
||||
printf( "0x%02X%s", hash[j], ( j + 1 ) == size_prefix ## _OUTBYTES ? "\n" : j && !( ( j + 1 ) % 8 ) ? ",\n\t\t" : ", " ); \
|
||||
\
|
||||
printf( "\t},\n" ); \
|
||||
} \
|
||||
\
|
||||
printf( "};\n\n\n\n\n" ); \
|
||||
\
|
||||
} while (0)
|
||||
#define MAKE_KAT(name, size_prefix) \
|
||||
do { \
|
||||
printf("static const uint8_t " #name "_kat[BLAKE2_KAT_LENGTH][" #size_prefix \
|
||||
"_OUTBYTES] = \n{\n"); \
|
||||
\
|
||||
for (i = 0; i < LENGTH; ++i) { \
|
||||
name(hash, size_prefix##_OUTBYTES, in, i, NULL, 0); \
|
||||
printf("\t{\n\t\t"); \
|
||||
\
|
||||
for (j = 0; j < size_prefix##_OUTBYTES; ++j) \
|
||||
printf("0x%02X%s", hash[j], \
|
||||
(j + 1) == size_prefix##_OUTBYTES ? "\n" : j && !((j + 1) % 8) ? ",\n\t\t" : ", "); \
|
||||
\
|
||||
printf("\t},\n"); \
|
||||
} \
|
||||
\
|
||||
printf("};\n\n\n\n\n"); \
|
||||
} while (0)
|
||||
|
||||
#define MAKE_KEYED_KAT(name,size_prefix) \
|
||||
do \
|
||||
{ \
|
||||
printf( "static const uint8_t " #name "_keyed_kat[BLAKE2_KAT_LENGTH][" #size_prefix "_OUTBYTES] = \n{\n" ); \
|
||||
\
|
||||
for( i = 0; i < LENGTH; ++i ) \
|
||||
{ \
|
||||
name( hash, size_prefix ## _OUTBYTES, in, i, key, size_prefix ## _KEYBYTES ); \
|
||||
printf( "\t{\n\t\t" ); \
|
||||
\
|
||||
for( j = 0; j < size_prefix ## _OUTBYTES; ++j ) \
|
||||
printf( "0x%02X%s", hash[j], ( j + 1 ) == size_prefix ## _OUTBYTES ? "\n" : j && !( ( j + 1 ) % 8 ) ? ",\n\t\t" : ", " ); \
|
||||
\
|
||||
printf( "\t},\n" ); \
|
||||
} \
|
||||
\
|
||||
printf( "};\n\n\n\n\n" ); \
|
||||
\
|
||||
} while (0)
|
||||
#define MAKE_KEYED_KAT(name, size_prefix) \
|
||||
do { \
|
||||
printf("static const uint8_t " #name "_keyed_kat[BLAKE2_KAT_LENGTH][" #size_prefix \
|
||||
"_OUTBYTES] = \n{\n"); \
|
||||
\
|
||||
for (i = 0; i < LENGTH; ++i) { \
|
||||
name(hash, size_prefix##_OUTBYTES, in, i, key, size_prefix##_KEYBYTES); \
|
||||
printf("\t{\n\t\t"); \
|
||||
\
|
||||
for (j = 0; j < size_prefix##_OUTBYTES; ++j) \
|
||||
printf("0x%02X%s", hash[j], \
|
||||
(j + 1) == size_prefix##_OUTBYTES ? "\n" : j && !((j + 1) % 8) ? ",\n\t\t" : ", "); \
|
||||
\
|
||||
printf("\t},\n"); \
|
||||
} \
|
||||
\
|
||||
printf("};\n\n\n\n\n"); \
|
||||
} while (0)
|
||||
|
||||
#define MAKE_XOF_KAT(name) \
|
||||
do \
|
||||
{ \
|
||||
printf( "static const uint8_t " #name "_kat[BLAKE2_KAT_LENGTH][BLAKE2_KAT_LENGTH] = \n{\n" ); \
|
||||
\
|
||||
for( i = 1; i <= LENGTH; ++i ) \
|
||||
{ \
|
||||
name( hash, i, in, LENGTH, NULL, 0 ); \
|
||||
printf( "\t{\n\t\t" ); \
|
||||
\
|
||||
for( j = 0; j < i; ++j ) \
|
||||
printf( "0x%02X%s", hash[j], ( j + 1 ) == LENGTH ? "\n" : j && !( ( j + 1 ) % 8 ) ? ",\n\t\t" : ", " ); \
|
||||
\
|
||||
for( 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)
|
||||
#define MAKE_XOF_KAT(name) \
|
||||
do { \
|
||||
printf("static const uint8_t " #name "_kat[BLAKE2_KAT_LENGTH][BLAKE2_KAT_LENGTH] = \n{\n"); \
|
||||
\
|
||||
for (i = 1; i <= LENGTH; ++i) { \
|
||||
name(hash, i, in, LENGTH, NULL, 0); \
|
||||
printf("\t{\n\t\t"); \
|
||||
\
|
||||
for (j = 0; j < i; ++j) \
|
||||
printf("0x%02X%s", hash[j], \
|
||||
(j + 1) == LENGTH ? "\n" : j && !((j + 1) % 8) ? ",\n\t\t" : ", "); \
|
||||
\
|
||||
for (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)
|
||||
|
||||
#define MAKE_XOF_KEYED_KAT(name,size_prefix) \
|
||||
do \
|
||||
{ \
|
||||
printf( "static const uint8_t " #name "_keyed_kat[BLAKE2_KAT_LENGTH][BLAKE2_KAT_LENGTH] = \n{\n" ); \
|
||||
\
|
||||
for( i = 1; i <= LENGTH; ++i ) \
|
||||
{ \
|
||||
name( hash, i, in, LENGTH, key, size_prefix ## _KEYBYTES ); \
|
||||
printf( "\t{\n\t\t" ); \
|
||||
\
|
||||
for( j = 0; j < i; ++j ) \
|
||||
printf( "0x%02X%s", hash[j], ( j + 1 ) == LENGTH ? "\n" : j && !( ( j + 1 ) % 8 ) ? ",\n\t\t" : ", " ); \
|
||||
\
|
||||
for( 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)
|
||||
#define MAKE_XOF_KEYED_KAT(name, size_prefix) \
|
||||
do { \
|
||||
printf("static const uint8_t " #name \
|
||||
"_keyed_kat[BLAKE2_KAT_LENGTH][BLAKE2_KAT_LENGTH] = \n{\n"); \
|
||||
\
|
||||
for (i = 1; i <= LENGTH; ++i) { \
|
||||
name(hash, i, in, LENGTH, key, size_prefix##_KEYBYTES); \
|
||||
printf("\t{\n\t\t"); \
|
||||
\
|
||||
for (j = 0; j < i; ++j) \
|
||||
printf("0x%02X%s", hash[j], \
|
||||
(j + 1) == LENGTH ? "\n" : j && !((j + 1) % 8) ? ",\n\t\t" : ", "); \
|
||||
\
|
||||
for (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 main() {
|
||||
uint8_t key[64] = {0};
|
||||
uint8_t in[LENGTH] = {0};
|
||||
uint8_t hash[LENGTH] = {0};
|
||||
size_t i, j;
|
||||
|
||||
for( i = 0; i < sizeof( in ); ++i )
|
||||
for (i = 0; i < sizeof(in); ++i)
|
||||
in[i] = i;
|
||||
|
||||
for( i = 0; i < sizeof( key ); ++i )
|
||||
for (i = 0; i < sizeof(key); ++i)
|
||||
key[i] = i;
|
||||
|
||||
puts( "#ifndef BLAKE2_KAT_H\n"
|
||||
"#define BLAKE2_KAT_H\n\n\n"
|
||||
"#include <stdint.h>\n\n"
|
||||
"#define BLAKE2_KAT_LENGTH " STR( LENGTH ) "\n\n\n" );
|
||||
MAKE_KAT( blake2s, BLAKE2S );
|
||||
MAKE_KEYED_KAT( blake2s, BLAKE2S );
|
||||
MAKE_KAT( blake2b, BLAKE2B );
|
||||
MAKE_KEYED_KAT( blake2b, BLAKE2B );
|
||||
MAKE_KAT( blake2sp, BLAKE2S );
|
||||
MAKE_KEYED_KAT( blake2sp, BLAKE2S );
|
||||
MAKE_KAT( blake2bp, BLAKE2B );
|
||||
MAKE_KEYED_KAT( blake2bp, BLAKE2B );
|
||||
MAKE_XOF_KAT( blake2xs );
|
||||
MAKE_XOF_KEYED_KAT( blake2xs, BLAKE2S );
|
||||
MAKE_XOF_KAT( blake2xb );
|
||||
MAKE_XOF_KEYED_KAT( blake2xb, BLAKE2B );
|
||||
puts( "#endif" );
|
||||
puts("#ifndef BLAKE2_KAT_H\n"
|
||||
"#define BLAKE2_KAT_H\n\n\n"
|
||||
"#include <stdint.h>\n\n"
|
||||
"#define BLAKE2_KAT_LENGTH " STR(LENGTH) "\n\n\n");
|
||||
MAKE_KAT(blake2s, BLAKE2S);
|
||||
MAKE_KEYED_KAT(blake2s, BLAKE2S);
|
||||
MAKE_KAT(blake2b, BLAKE2B);
|
||||
MAKE_KEYED_KAT(blake2b, BLAKE2B);
|
||||
MAKE_KAT(blake2sp, BLAKE2S);
|
||||
MAKE_KEYED_KAT(blake2sp, BLAKE2S);
|
||||
MAKE_KAT(blake2bp, BLAKE2B);
|
||||
MAKE_KEYED_KAT(blake2bp, BLAKE2B);
|
||||
MAKE_XOF_KAT(blake2xs);
|
||||
MAKE_XOF_KEYED_KAT(blake2xs, BLAKE2S);
|
||||
MAKE_XOF_KAT(blake2xb);
|
||||
MAKE_XOF_KEYED_KAT(blake2xb, BLAKE2B);
|
||||
puts("#endif");
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
/*
|
||||
BLAKE2 reference source code package - reference C implementations
|
||||
|
||||
|
||||
Copyright 2012, Samuel Neves <sneves@dei.uc.pt>. You may use this under the
|
||||
terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at
|
||||
your option. The terms of these licenses can be found at:
|
||||
|
||||
|
||||
- CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
|
||||
- OpenSSL license : https://www.openssl.org/source/license.html
|
||||
- Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
|
||||
More information about the BLAKE2 hash function can be found at
|
||||
https://blake2.net.
|
||||
*/
|
||||
@ -25,133 +25,129 @@
|
||||
|
||||
#define LENGTH 256
|
||||
|
||||
#define MAKE_KAT(name,size_prefix) \
|
||||
do \
|
||||
{ \
|
||||
for( i = 0; i < LENGTH; ++i ) \
|
||||
{ \
|
||||
printf("\n{\n");\
|
||||
\
|
||||
printf(" \"hash\": \"" #name "\",\n");\
|
||||
printf(" \"in\": \"");\
|
||||
for( j = 0; j < i; ++j ) printf( "%02x", in[j]);\
|
||||
\
|
||||
printf( "\",\n" ); \
|
||||
printf(" \"key\": \"\",\n");\
|
||||
printf(" \"out\": \"");\
|
||||
\
|
||||
name( hash, size_prefix ## _OUTBYTES, in, i, NULL, 0 ); \
|
||||
\
|
||||
for( j = 0; j < size_prefix ## _OUTBYTES; ++j ) \
|
||||
printf( "%02x", hash[j]);\
|
||||
printf( "\"\n" ); \
|
||||
printf( "}," ); \
|
||||
}\
|
||||
} while (0)
|
||||
#define MAKE_KAT(name, size_prefix) \
|
||||
do { \
|
||||
for (i = 0; i < LENGTH; ++i) { \
|
||||
printf("\n{\n"); \
|
||||
\
|
||||
printf(" \"hash\": \"" #name "\",\n"); \
|
||||
printf(" \"in\": \""); \
|
||||
for (j = 0; j < i; ++j) \
|
||||
printf("%02x", in[j]); \
|
||||
\
|
||||
printf("\",\n"); \
|
||||
printf(" \"key\": \"\",\n"); \
|
||||
printf(" \"out\": \""); \
|
||||
\
|
||||
name(hash, size_prefix##_OUTBYTES, in, i, NULL, 0); \
|
||||
\
|
||||
for (j = 0; j < size_prefix##_OUTBYTES; ++j) \
|
||||
printf("%02x", hash[j]); \
|
||||
printf("\"\n"); \
|
||||
printf("},"); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define MAKE_KEYED_KAT(name,size_prefix) \
|
||||
do \
|
||||
{ \
|
||||
for( i = 0; i < LENGTH; ++i ) \
|
||||
{ \
|
||||
printf("\n{\n");\
|
||||
\
|
||||
printf(" \"hash\": \"" #name "\",\n");\
|
||||
printf(" \"in\": \"");\
|
||||
for( j = 0; j < i; ++j ) printf( "%02x", in[j]);\
|
||||
\
|
||||
printf( "\",\n" ); \
|
||||
printf(" \"key\": \"");\
|
||||
for( j = 0; j < size_prefix ## _KEYBYTES; ++j ) printf( "%02x", key[j]);\
|
||||
printf("\",\n");\
|
||||
printf(" \"out\": \"");\
|
||||
\
|
||||
name( hash, size_prefix ## _OUTBYTES, in, i, key, size_prefix ## _KEYBYTES ); \
|
||||
\
|
||||
for( j = 0; j < size_prefix ## _OUTBYTES; ++j ) \
|
||||
printf( "%02x", hash[j]);\
|
||||
printf( "\"\n" ); \
|
||||
printf( "}," ); \
|
||||
}\
|
||||
} while (0)
|
||||
#define MAKE_KEYED_KAT(name, size_prefix) \
|
||||
do { \
|
||||
for (i = 0; i < LENGTH; ++i) { \
|
||||
printf("\n{\n"); \
|
||||
\
|
||||
printf(" \"hash\": \"" #name "\",\n"); \
|
||||
printf(" \"in\": \""); \
|
||||
for (j = 0; j < i; ++j) \
|
||||
printf("%02x", in[j]); \
|
||||
\
|
||||
printf("\",\n"); \
|
||||
printf(" \"key\": \""); \
|
||||
for (j = 0; j < size_prefix##_KEYBYTES; ++j) \
|
||||
printf("%02x", key[j]); \
|
||||
printf("\",\n"); \
|
||||
printf(" \"out\": \""); \
|
||||
\
|
||||
name(hash, size_prefix##_OUTBYTES, in, i, key, size_prefix##_KEYBYTES); \
|
||||
\
|
||||
for (j = 0; j < size_prefix##_OUTBYTES; ++j) \
|
||||
printf("%02x", hash[j]); \
|
||||
printf("\"\n"); \
|
||||
printf("},"); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define MAKE_XOF_KAT(name) \
|
||||
do \
|
||||
{ \
|
||||
for( i = 1; i <= LENGTH; ++i ) \
|
||||
{ \
|
||||
printf("\n{\n");\
|
||||
\
|
||||
printf(" \"hash\": \"" #name "\",\n");\
|
||||
printf(" \"in\": \"");\
|
||||
for( j = 0; j < LENGTH; ++j ) printf( "%02x", in[j]);\
|
||||
\
|
||||
printf( "\",\n" ); \
|
||||
printf(" \"key\": \"\",\n");\
|
||||
printf(" \"out\": \"");\
|
||||
\
|
||||
name( hash, i, in, LENGTH, NULL, 0 ); \
|
||||
\
|
||||
for( j = 0; j < i; ++j ) \
|
||||
printf( "%02x", hash[j]);\
|
||||
printf( "\"\n" ); \
|
||||
printf( "}," ); \
|
||||
}\
|
||||
} while (0)
|
||||
#define MAKE_XOF_KAT(name) \
|
||||
do { \
|
||||
for (i = 1; i <= LENGTH; ++i) { \
|
||||
printf("\n{\n"); \
|
||||
\
|
||||
printf(" \"hash\": \"" #name "\",\n"); \
|
||||
printf(" \"in\": \""); \
|
||||
for (j = 0; j < LENGTH; ++j) \
|
||||
printf("%02x", in[j]); \
|
||||
\
|
||||
printf("\",\n"); \
|
||||
printf(" \"key\": \"\",\n"); \
|
||||
printf(" \"out\": \""); \
|
||||
\
|
||||
name(hash, i, in, LENGTH, NULL, 0); \
|
||||
\
|
||||
for (j = 0; j < i; ++j) \
|
||||
printf("%02x", hash[j]); \
|
||||
printf("\"\n"); \
|
||||
printf("},"); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define MAKE_XOF_KEYED_KAT(name,size_prefix) \
|
||||
do \
|
||||
{ \
|
||||
for( i = 1; i <= LENGTH; ++i ) \
|
||||
{ \
|
||||
printf("\n{\n");\
|
||||
\
|
||||
printf(" \"hash\": \"" #name "\",\n");\
|
||||
printf(" \"in\": \"");\
|
||||
for( j = 0; j < LENGTH; ++j ) printf( "%02x", in[j]);\
|
||||
\
|
||||
printf( "\",\n" ); \
|
||||
printf(" \"key\": \"");\
|
||||
for( j = 0; j < size_prefix ## _KEYBYTES; ++j ) printf( "%02x", key[j]);\
|
||||
printf("\",\n");\
|
||||
printf(" \"out\": \"");\
|
||||
\
|
||||
name( hash, i, in, LENGTH, key, size_prefix ## _KEYBYTES ); \
|
||||
\
|
||||
for( j = 0; j < i; ++j ) \
|
||||
printf( "%02x", hash[j]);\
|
||||
printf( "\"\n" ); \
|
||||
printf( "}," ); \
|
||||
}\
|
||||
} while (0)
|
||||
#define MAKE_XOF_KEYED_KAT(name, size_prefix) \
|
||||
do { \
|
||||
for (i = 1; i <= LENGTH; ++i) { \
|
||||
printf("\n{\n"); \
|
||||
\
|
||||
printf(" \"hash\": \"" #name "\",\n"); \
|
||||
printf(" \"in\": \""); \
|
||||
for (j = 0; j < LENGTH; ++j) \
|
||||
printf("%02x", in[j]); \
|
||||
\
|
||||
printf("\",\n"); \
|
||||
printf(" \"key\": \""); \
|
||||
for (j = 0; j < size_prefix##_KEYBYTES; ++j) \
|
||||
printf("%02x", key[j]); \
|
||||
printf("\",\n"); \
|
||||
printf(" \"out\": \""); \
|
||||
\
|
||||
name(hash, i, in, LENGTH, key, size_prefix##_KEYBYTES); \
|
||||
\
|
||||
for (j = 0; j < i; ++j) \
|
||||
printf("%02x", hash[j]); \
|
||||
printf("\"\n"); \
|
||||
printf("},"); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
int main() {
|
||||
uint8_t key[64] = {0};
|
||||
uint8_t in[LENGTH] = {0};
|
||||
uint8_t hash[LENGTH] = {0};
|
||||
size_t i, j;
|
||||
|
||||
for( i = 0; i < sizeof( in ); ++i )
|
||||
for (i = 0; i < sizeof(in); ++i)
|
||||
in[i] = i;
|
||||
|
||||
for( i = 0; i < sizeof( key ); ++i )
|
||||
for (i = 0; i < sizeof(key); ++i)
|
||||
key[i] = i;
|
||||
|
||||
printf("[");
|
||||
MAKE_KAT( blake2s, BLAKE2S );
|
||||
MAKE_KEYED_KAT( blake2s, BLAKE2S );
|
||||
MAKE_KAT( blake2b, BLAKE2B );
|
||||
MAKE_KEYED_KAT( blake2b, BLAKE2B );
|
||||
MAKE_KAT( blake2sp, BLAKE2S );
|
||||
MAKE_KEYED_KAT( blake2sp, BLAKE2S );
|
||||
MAKE_KAT( blake2bp, BLAKE2B );
|
||||
MAKE_KEYED_KAT( blake2bp, BLAKE2B );
|
||||
MAKE_XOF_KAT( blake2xs );
|
||||
MAKE_XOF_KEYED_KAT( blake2xs, BLAKE2S );
|
||||
MAKE_XOF_KAT( blake2xb );
|
||||
MAKE_XOF_KEYED_KAT( blake2xb, BLAKE2B );
|
||||
MAKE_KAT(blake2s, BLAKE2S);
|
||||
MAKE_KEYED_KAT(blake2s, BLAKE2S);
|
||||
MAKE_KAT(blake2b, BLAKE2B);
|
||||
MAKE_KEYED_KAT(blake2b, BLAKE2B);
|
||||
MAKE_KAT(blake2sp, BLAKE2S);
|
||||
MAKE_KEYED_KAT(blake2sp, BLAKE2S);
|
||||
MAKE_KAT(blake2bp, BLAKE2B);
|
||||
MAKE_KEYED_KAT(blake2bp, BLAKE2B);
|
||||
MAKE_XOF_KAT(blake2xs);
|
||||
MAKE_XOF_KEYED_KAT(blake2xs, BLAKE2S);
|
||||
MAKE_XOF_KAT(blake2xb);
|
||||
MAKE_XOF_KEYED_KAT(blake2xb, BLAKE2B);
|
||||
printf("\n]\n");
|
||||
fflush(stdout);
|
||||
return 0;
|
||||
|
@ -1,5 +1,5 @@
|
||||
CC=gcc
|
||||
CFLAGS=-O3 -I../testvectors -Wall --std=c89
|
||||
CFLAGS=-O3 -I../testvectors -Wall -Wextra -std=c89 -pedantic -Wno-long-long
|
||||
BLAKEBINS=blake2s blake2b blake2sp blake2bp blake2xs blake2xb
|
||||
|
||||
all: $(BLAKEBINS) check
|
||||
|
Loading…
Reference in New Issue
Block a user