mirror of
https://github.com/BLAKE2/BLAKE2
synced 2024-11-08 14:59:19 +01:00
sse genkats
This commit is contained in:
parent
25f38cbc5e
commit
8b6442c3af
@ -65,12 +65,58 @@ 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 = 1; 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 + 1 ) == LENGTH ? "\n" : 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)
|
||||
|
||||
#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( size_t i = 1; i <= LENGTH; ++i ) \
|
||||
{ \
|
||||
name( hash, i, in, LENGTH, key, size_prefix ## _KEYBYTES ); \
|
||||
printf( "\t{\n\t\t" ); \
|
||||
\
|
||||
for( int j = 0; j < i; ++j ) \
|
||||
printf( "0x%02X%s", hash[j], ( j + 1 ) == LENGTH ? "\n" : 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 )
|
||||
{
|
||||
uint8_t key[64] = {0};
|
||||
uint8_t in[LENGTH] = {0};
|
||||
uint8_t hash[64] = {0};
|
||||
uint8_t hash[LENGTH] = {0};
|
||||
|
||||
for( size_t i = 0; i < sizeof( in ); ++i )
|
||||
in[i] = i;
|
||||
@ -90,6 +136,10 @@ int main( int argc, char **argv )
|
||||
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;
|
||||
}
|
||||
|
@ -75,12 +75,62 @@ do \
|
||||
}\
|
||||
} while (0)
|
||||
|
||||
#define MAKE_XOF_KAT(name) \
|
||||
do \
|
||||
{ \
|
||||
for( size_t i = 1; i <= LENGTH; ++i ) \
|
||||
{ \
|
||||
printf("\n{\n");\
|
||||
\
|
||||
printf(" \"hash\": \"" #name "\",\n");\
|
||||
printf(" \"in\": \"");\
|
||||
for( int j = 0; j < LENGTH; ++j ) printf( "%02x", in[j]);\
|
||||
\
|
||||
printf( "\",\n" ); \
|
||||
printf(" \"key\": \"\",\n");\
|
||||
printf(" \"out\": \"");\
|
||||
\
|
||||
name( hash, i, in, LENGTH, NULL, 0 ); \
|
||||
\
|
||||
for( int j = 0; j < i; ++j ) \
|
||||
printf( "%02x", hash[j]);\
|
||||
printf( "\"\n" ); \
|
||||
printf( "}," ); \
|
||||
}\
|
||||
} while (0)
|
||||
|
||||
#define MAKE_XOF_KEYED_KAT(name,size_prefix) \
|
||||
do \
|
||||
{ \
|
||||
for( size_t i = 1; i <= LENGTH; ++i ) \
|
||||
{ \
|
||||
printf("\n{\n");\
|
||||
\
|
||||
printf(" \"hash\": \"" #name "\",\n");\
|
||||
printf(" \"in\": \"");\
|
||||
for( int j = 0; j < LENGTH; ++j ) printf( "%02x", in[j]);\
|
||||
\
|
||||
printf( "\",\n" ); \
|
||||
printf(" \"key\": \"");\
|
||||
for( int 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( int j = 0; j < i; ++j ) \
|
||||
printf( "%02x", hash[j]);\
|
||||
printf( "\"\n" ); \
|
||||
printf( "}," ); \
|
||||
}\
|
||||
} while (0)
|
||||
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
uint8_t key[64] = {0};
|
||||
uint8_t in[LENGTH] = {0};
|
||||
uint8_t hash[64] = {0};
|
||||
uint8_t hash[LENGTH] = {0};
|
||||
|
||||
for( size_t i = 0; i < sizeof( in ); ++i )
|
||||
in[i] = i;
|
||||
@ -97,6 +147,10 @@ int main( int argc, char **argv )
|
||||
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;
|
||||
|
@ -37,4 +37,4 @@ kat:
|
||||
./genkat-json > blake2-kat.json
|
||||
|
||||
clean:
|
||||
rm -rf *.o genkat-c genkat-json $(BLAKE2BINS)
|
||||
rm -rf *.o genkat-c genkat-json $(BLAKEBINS)
|
||||
|
Loading…
Reference in New Issue
Block a user