1
1
mirror of https://github.com/BLAKE2/BLAKE2 synced 2024-09-16 08:31:34 +02:00

json kats

This commit is contained in:
JP Aumasson 2016-10-11 21:55:56 +02:00
parent d113d9c26d
commit 2994ec582c
5 changed files with 6214 additions and 14 deletions

View File

@ -123,6 +123,18 @@ extern "C" {
typedef struct blake2b_param__ blake2b_param;
typedef struct blake2xs_state__
{
blake2s_state S[1];
blake2s_param P[1];
} blake2xs_state;
typedef struct blake2xb_state__
{
blake2b_state S[1];
blake2b_param P[1];
} blake2xb_state;
/* Padded structs result in a compile-time error */
enum {
BLAKE2_DUMMY_1 = 1/(sizeof(blake2s_param) == BLAKE2S_OUTBYTES),
@ -156,9 +168,9 @@ int blake2xs_init( blake2xs_state *S, const size_t outlen, const void *key, size
int blake2xs_update( blake2xs_state *S, const void *in, size_t inlen );
int blake2xs_final(blake2xs_state *S, void *out, size_t outlen);
int blake2xb_init( blake2xs_state *S, const size_t outlen, const void *key, size_t keylen );
int blake2xb_update( blake2xs_state *S, const void *in, size_t inlen );
int blake2xb_final(blake2xs_state *S, void *out, size_t outlen);
int blake2xb_init( blake2xb_state *S, const size_t outlen, const void *key, size_t keylen );
int blake2xb_update( blake2xb_state *S, const void *in, size_t inlen );
int blake2xb_final(blake2xb_state *S, void *out, size_t outlen);
/* Simple API */
int blake2s( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen );

View File

@ -5,11 +5,6 @@
#include "blake2.h"
#include "blake2-impl.h"
typedef struct blake2xb_state__ {
blake2b_state S[1];
blake2b_param P[1];
} blake2xb_state;
int blake2xb_init( blake2xb_state *S, const size_t outlen, const void *key, size_t keylen)
{

View File

@ -5,11 +5,6 @@
#include "blake2.h"
#include "blake2-impl.h"
typedef struct blake2xs_state__ {
blake2s_state S[1];
blake2s_param P[1];
} blake2xs_state;
int blake2xs_init( blake2xs_state *S, const size_t outlen, const void *key, size_t keylen )
{

View File

@ -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 < i; ++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;

File diff suppressed because it is too large Load Diff