forked from wolfSSL/wolfssl
blake2 ctc api, test vecs
This commit is contained in:
@ -400,7 +400,7 @@ AC_ARG_ENABLE([blake2],
|
|||||||
|
|
||||||
if test "$ENABLED_BLAKE2" = "yes"
|
if test "$ENABLED_BLAKE2" = "yes"
|
||||||
then
|
then
|
||||||
AM_CFLAGS="$AM_CFLAGS -DCYASSL_BLAKE2"
|
AM_CFLAGS="$AM_CFLAGS -DHAVE_BLAKE2"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
AM_CONDITIONAL([BUILD_BLAKE2], [test "x$ENABLED_BLAKE2" = "xyes"])
|
AM_CONDITIONAL([BUILD_BLAKE2], [test "x$ENABLED_BLAKE2" = "xyes"])
|
||||||
|
@ -55,7 +55,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef CYASSL_BLAKE2
|
#ifdef HAVE_BLAKE2
|
||||||
#include <cyassl/ctaocrypt/blake2.h>
|
#include <cyassl/ctaocrypt/blake2.h>
|
||||||
void bench_blake2(void);
|
void bench_blake2(void);
|
||||||
#endif
|
#endif
|
||||||
@ -172,7 +172,7 @@ int main(int argc, char** argv)
|
|||||||
#ifdef CYASSL_RIPEMD
|
#ifdef CYASSL_RIPEMD
|
||||||
bench_ripemd();
|
bench_ripemd();
|
||||||
#endif
|
#endif
|
||||||
#ifdef CYASSL_BLAKE2
|
#ifdef HAVE_BLAKE2
|
||||||
bench_blake2();
|
bench_blake2();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -622,21 +622,21 @@ void bench_ripemd(void)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef CYASSL_BLAKE2
|
#ifdef HAVE_BLAKE2
|
||||||
void bench_blake2(void)
|
void bench_blake2(void)
|
||||||
{
|
{
|
||||||
blake2b_state S[1];
|
Blake2 b2;
|
||||||
byte digest[32];
|
byte digest[32];
|
||||||
double start, total, persec;
|
double start, total, persec;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
blake2b_init(S, 32);
|
InitBlake2(&b2, 32);
|
||||||
start = current_time(1);
|
start = current_time(1);
|
||||||
|
|
||||||
for(i = 0; i < numBlocks; i++)
|
for(i = 0; i < numBlocks; i++)
|
||||||
blake2b_update(S, plain, sizeof(plain));
|
Blake2Update(&b2, plain, sizeof(plain));
|
||||||
|
|
||||||
blake2b_final(S, digest, 32);
|
Blake2Final(&b2, digest, 32);
|
||||||
|
|
||||||
total = current_time(0) - start;
|
total = current_time(0) - start;
|
||||||
persec = 1 / total * numBlocks;
|
persec = 1 / total * numBlocks;
|
||||||
|
@ -36,6 +36,8 @@
|
|||||||
#include <config.h>
|
#include <config.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_BLAKE2
|
||||||
|
|
||||||
#include <cyassl/ctaocrypt/blake2.h>
|
#include <cyassl/ctaocrypt/blake2.h>
|
||||||
#include <cyassl/ctaocrypt/blake2-impl.h>
|
#include <cyassl/ctaocrypt/blake2-impl.h>
|
||||||
|
|
||||||
@ -429,3 +431,35 @@ int main( int argc, char **argv )
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* CTaoCrypt API */
|
||||||
|
|
||||||
|
/* Init Blake2 digest, track size incase final doesn't want to "remember" */
|
||||||
|
int InitBlake2(Blake2* b2, word32 digestSz)
|
||||||
|
{
|
||||||
|
b2->digestSz = digestSz;
|
||||||
|
|
||||||
|
return blake2b_init(b2->S, (byte)digestSz);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Blake2 Update */
|
||||||
|
int Blake2Update(Blake2* b2, const byte* data, word32 sz)
|
||||||
|
{
|
||||||
|
return blake2b_update(b2->S, data, sz);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Blake2 Final, if pass in zero size we use init digestSz */
|
||||||
|
int Blake2Final(Blake2* b2, byte* final, word32 requestSz)
|
||||||
|
{
|
||||||
|
word32 sz = requestSz ? requestSz : b2->digestSz;
|
||||||
|
|
||||||
|
return blake2b_final(b2->S, final, (byte)sz);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* end CTaoCrypt API */
|
||||||
|
|
||||||
|
#endif /* HAVE_BLAKE2 */
|
||||||
|
|
||||||
|
@ -51,6 +51,9 @@
|
|||||||
#ifdef HAVE_ECC
|
#ifdef HAVE_ECC
|
||||||
#include <cyassl/ctaocrypt/ecc.h>
|
#include <cyassl/ctaocrypt/ecc.h>
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef HAVE_BLAKE2
|
||||||
|
#include <cyassl/ctaocrypt/blake2.h>
|
||||||
|
#endif
|
||||||
#ifdef HAVE_LIBZ
|
#ifdef HAVE_LIBZ
|
||||||
#include <cyassl/ctaocrypt/compress.h>
|
#include <cyassl/ctaocrypt/compress.h>
|
||||||
#endif
|
#endif
|
||||||
@ -142,6 +145,9 @@ int pbkdf2_test(void);
|
|||||||
#ifdef HAVE_ECC
|
#ifdef HAVE_ECC
|
||||||
int ecc_test(void);
|
int ecc_test(void);
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef HAVE_BLAKE2
|
||||||
|
int blake2_test(void);
|
||||||
|
#endif
|
||||||
#ifdef HAVE_LIBZ
|
#ifdef HAVE_LIBZ
|
||||||
int compress_test(void);
|
int compress_test(void);
|
||||||
#endif
|
#endif
|
||||||
@ -240,6 +246,13 @@ void ctaocrypt_test(void* args)
|
|||||||
printf( "RIPEMD test passed!\n");
|
printf( "RIPEMD test passed!\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_BLAKE2
|
||||||
|
if ( (ret = blake2_test()) )
|
||||||
|
err_sys("BLAKE2 test failed!\n", ret);
|
||||||
|
else
|
||||||
|
printf( "BLAKE2 test passed!\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef NO_HMAC
|
#ifndef NO_HMAC
|
||||||
#ifndef NO_MD5
|
#ifndef NO_MD5
|
||||||
if ( (ret = hmac_md5_test()) )
|
if ( (ret = hmac_md5_test()) )
|
||||||
@ -781,6 +794,72 @@ int ripemd_test(void)
|
|||||||
#endif /* CYASSL_RIPEMD */
|
#endif /* CYASSL_RIPEMD */
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef HAVE_BLAKE2
|
||||||
|
|
||||||
|
|
||||||
|
#define BLAKE2_TESTS 3
|
||||||
|
|
||||||
|
static const byte blake2b_vec[BLAKE2_TESTS][BLAKE2B_OUTBYTES] =
|
||||||
|
{
|
||||||
|
{
|
||||||
|
0x78, 0x6A, 0x02, 0xF7, 0x42, 0x01, 0x59, 0x03,
|
||||||
|
0xC6, 0xC6, 0xFD, 0x85, 0x25, 0x52, 0xD2, 0x72,
|
||||||
|
0x91, 0x2F, 0x47, 0x40, 0xE1, 0x58, 0x47, 0x61,
|
||||||
|
0x8A, 0x86, 0xE2, 0x17, 0xF7, 0x1F, 0x54, 0x19,
|
||||||
|
0xD2, 0x5E, 0x10, 0x31, 0xAF, 0xEE, 0x58, 0x53,
|
||||||
|
0x13, 0x89, 0x64, 0x44, 0x93, 0x4E, 0xB0, 0x4B,
|
||||||
|
0x90, 0x3A, 0x68, 0x5B, 0x14, 0x48, 0xB7, 0x55,
|
||||||
|
0xD5, 0x6F, 0x70, 0x1A, 0xFE, 0x9B, 0xE2, 0xCE
|
||||||
|
},
|
||||||
|
{
|
||||||
|
0x2F, 0xA3, 0xF6, 0x86, 0xDF, 0x87, 0x69, 0x95,
|
||||||
|
0x16, 0x7E, 0x7C, 0x2E, 0x5D, 0x74, 0xC4, 0xC7,
|
||||||
|
0xB6, 0xE4, 0x8F, 0x80, 0x68, 0xFE, 0x0E, 0x44,
|
||||||
|
0x20, 0x83, 0x44, 0xD4, 0x80, 0xF7, 0x90, 0x4C,
|
||||||
|
0x36, 0x96, 0x3E, 0x44, 0x11, 0x5F, 0xE3, 0xEB,
|
||||||
|
0x2A, 0x3A, 0xC8, 0x69, 0x4C, 0x28, 0xBC, 0xB4,
|
||||||
|
0xF5, 0xA0, 0xF3, 0x27, 0x6F, 0x2E, 0x79, 0x48,
|
||||||
|
0x7D, 0x82, 0x19, 0x05, 0x7A, 0x50, 0x6E, 0x4B
|
||||||
|
},
|
||||||
|
{
|
||||||
|
0x1C, 0x08, 0x79, 0x8D, 0xC6, 0x41, 0xAB, 0xA9,
|
||||||
|
0xDE, 0xE4, 0x35, 0xE2, 0x25, 0x19, 0xA4, 0x72,
|
||||||
|
0x9A, 0x09, 0xB2, 0xBF, 0xE0, 0xFF, 0x00, 0xEF,
|
||||||
|
0x2D, 0xCD, 0x8E, 0xD6, 0xF8, 0xA0, 0x7D, 0x15,
|
||||||
|
0xEA, 0xF4, 0xAE, 0xE5, 0x2B, 0xBF, 0x18, 0xAB,
|
||||||
|
0x56, 0x08, 0xA6, 0x19, 0x0F, 0x70, 0xB9, 0x04,
|
||||||
|
0x86, 0xC8, 0xA7, 0xD4, 0x87, 0x37, 0x10, 0xB1,
|
||||||
|
0x11, 0x5D, 0x3D, 0xEB, 0xBB, 0x43, 0x27, 0xB5
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int blake2_test(void)
|
||||||
|
{
|
||||||
|
Blake2 b2;
|
||||||
|
byte digest[64];
|
||||||
|
byte input[64];
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < (int)sizeof(input); i++)
|
||||||
|
input[i] = (byte)i;
|
||||||
|
|
||||||
|
for (i = 0; i < BLAKE2_TESTS; i++) {
|
||||||
|
InitBlake2(&b2, 64);
|
||||||
|
Blake2Update(&b2, input, i);
|
||||||
|
Blake2Final(&b2, digest, 64);
|
||||||
|
|
||||||
|
if (memcmp(digest, blake2b_vec[i], 64) != 0) {
|
||||||
|
return -300 - i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif /* HAVE_BLAKE2 */
|
||||||
|
|
||||||
|
|
||||||
#ifndef NO_SHA256
|
#ifndef NO_SHA256
|
||||||
int sha256_test(void)
|
int sha256_test(void)
|
||||||
{
|
{
|
||||||
|
183
cyassl/ctaocrypt/blake2-int.h
Normal file
183
cyassl/ctaocrypt/blake2-int.h
Normal file
@ -0,0 +1,183 @@
|
|||||||
|
/*
|
||||||
|
BLAKE2 reference source code package - reference C implementations
|
||||||
|
|
||||||
|
Written in 2012 by Samuel Neves <sneves@dei.uc.pt>
|
||||||
|
|
||||||
|
To the extent possible under law, the author(s) have dedicated all copyright
|
||||||
|
and related and neighboring rights to this software to the public domain
|
||||||
|
worldwide. This software is distributed without any warranty.
|
||||||
|
|
||||||
|
You should have received a copy of the CC0 Public Domain Dedication along with
|
||||||
|
this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||||
|
*/
|
||||||
|
/* blake2-int.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2013 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of CyaSSL.
|
||||||
|
*
|
||||||
|
* CyaSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* CyaSSL is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef CTAOCRYPT_BLAKE2_INT_H
|
||||||
|
#define CTAOCRYPT_BLAKE2_INT_H
|
||||||
|
|
||||||
|
#include <cyassl/ctaocrypt/types.h>
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
#define ALIGN(x) __declspec(align(x))
|
||||||
|
#elif defined(__GNUC__)
|
||||||
|
#define ALIGN(x) __attribute__((aligned(x)))
|
||||||
|
#else
|
||||||
|
#define ALIGN(x)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
enum blake2s_constant
|
||||||
|
{
|
||||||
|
BLAKE2S_BLOCKBYTES = 64,
|
||||||
|
BLAKE2S_OUTBYTES = 32,
|
||||||
|
BLAKE2S_KEYBYTES = 32,
|
||||||
|
BLAKE2S_SALTBYTES = 8,
|
||||||
|
BLAKE2S_PERSONALBYTES = 8
|
||||||
|
};
|
||||||
|
|
||||||
|
enum blake2b_constant
|
||||||
|
{
|
||||||
|
BLAKE2B_BLOCKBYTES = 128,
|
||||||
|
BLAKE2B_OUTBYTES = 64,
|
||||||
|
BLAKE2B_KEYBYTES = 64,
|
||||||
|
BLAKE2B_SALTBYTES = 16,
|
||||||
|
BLAKE2B_PERSONALBYTES = 16
|
||||||
|
};
|
||||||
|
|
||||||
|
#pragma pack(push, 1)
|
||||||
|
typedef struct __blake2s_param
|
||||||
|
{
|
||||||
|
byte digest_length; /* 1 */
|
||||||
|
byte key_length; /* 2 */
|
||||||
|
byte fanout; /* 3 */
|
||||||
|
byte depth; /* 4 */
|
||||||
|
word32 leaf_length; /* 8 */
|
||||||
|
byte node_offset[6];/* 14 */
|
||||||
|
byte node_depth; /* 15 */
|
||||||
|
byte inner_length; /* 16 */
|
||||||
|
/* byte reserved[0]; */
|
||||||
|
byte salt[BLAKE2B_SALTBYTES]; /* 24 */
|
||||||
|
byte personal[BLAKE2S_PERSONALBYTES]; /* 32 */
|
||||||
|
} blake2s_param;
|
||||||
|
|
||||||
|
ALIGN( 64 ) typedef struct __blake2s_state
|
||||||
|
{
|
||||||
|
word32 h[8];
|
||||||
|
word32 t[2];
|
||||||
|
word32 f[2];
|
||||||
|
byte buf[2 * BLAKE2S_BLOCKBYTES];
|
||||||
|
word64 buflen;
|
||||||
|
byte last_node;
|
||||||
|
} blake2s_state ;
|
||||||
|
|
||||||
|
typedef struct __blake2b_param
|
||||||
|
{
|
||||||
|
byte digest_length; /* 1 */
|
||||||
|
byte key_length; /* 2 */
|
||||||
|
byte fanout; /* 3 */
|
||||||
|
byte depth; /* 4 */
|
||||||
|
word32 leaf_length; /* 8 */
|
||||||
|
word64 node_offset; /* 16 */
|
||||||
|
byte node_depth; /* 17 */
|
||||||
|
byte inner_length; /* 18 */
|
||||||
|
byte reserved[14]; /* 32 */
|
||||||
|
byte salt[BLAKE2B_SALTBYTES]; /* 48 */
|
||||||
|
byte personal[BLAKE2B_PERSONALBYTES]; /* 64 */
|
||||||
|
} blake2b_param;
|
||||||
|
|
||||||
|
ALIGN( 64 ) typedef struct __blake2b_state
|
||||||
|
{
|
||||||
|
word64 h[8];
|
||||||
|
word64 t[2];
|
||||||
|
word64 f[2];
|
||||||
|
byte buf[2 * BLAKE2B_BLOCKBYTES];
|
||||||
|
word64 buflen;
|
||||||
|
byte last_node;
|
||||||
|
} blake2b_state;
|
||||||
|
|
||||||
|
typedef struct __blake2sp_state
|
||||||
|
{
|
||||||
|
blake2s_state S[8][1];
|
||||||
|
blake2s_state R[1];
|
||||||
|
byte buf[8 * BLAKE2S_BLOCKBYTES];
|
||||||
|
word64 buflen;
|
||||||
|
} blake2sp_state;
|
||||||
|
|
||||||
|
typedef struct __blake2bp_state
|
||||||
|
{
|
||||||
|
blake2b_state S[4][1];
|
||||||
|
blake2b_state R[1];
|
||||||
|
byte buf[4 * BLAKE2B_BLOCKBYTES];
|
||||||
|
word64 buflen;
|
||||||
|
} blake2bp_state;
|
||||||
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
/* Streaming API */
|
||||||
|
int blake2s_init( blake2s_state *S, const byte outlen );
|
||||||
|
int blake2s_init_key( blake2s_state *S, const byte outlen, const void *key, const byte keylen );
|
||||||
|
int blake2s_init_param( blake2s_state *S, const blake2s_param *P );
|
||||||
|
int blake2s_update( blake2s_state *S, const byte *in, word64 inlen );
|
||||||
|
int blake2s_final( blake2s_state *S, byte *out, byte outlen );
|
||||||
|
|
||||||
|
int blake2b_init( blake2b_state *S, const byte outlen );
|
||||||
|
int blake2b_init_key( blake2b_state *S, const byte outlen, const void *key, const byte keylen );
|
||||||
|
int blake2b_init_param( blake2b_state *S, const blake2b_param *P );
|
||||||
|
int blake2b_update( blake2b_state *S, const byte *in, word64 inlen );
|
||||||
|
int blake2b_final( blake2b_state *S, byte *out, byte outlen );
|
||||||
|
|
||||||
|
int blake2sp_init( blake2sp_state *S, const byte outlen );
|
||||||
|
int blake2sp_init_key( blake2sp_state *S, const byte outlen, const void *key, const byte keylen );
|
||||||
|
int blake2sp_update( blake2sp_state *S, const byte *in, word64 inlen );
|
||||||
|
int blake2sp_final( blake2sp_state *S, byte *out, byte outlen );
|
||||||
|
|
||||||
|
int blake2bp_init( blake2bp_state *S, const byte outlen );
|
||||||
|
int blake2bp_init_key( blake2bp_state *S, const byte outlen, const void *key, const byte keylen );
|
||||||
|
int blake2bp_update( blake2bp_state *S, const byte *in, word64 inlen );
|
||||||
|
int blake2bp_final( blake2bp_state *S, byte *out, byte outlen );
|
||||||
|
|
||||||
|
/* Simple API */
|
||||||
|
int blake2s( byte *out, const void *in, const void *key, const byte outlen, const word64 inlen, byte keylen );
|
||||||
|
int blake2b( byte *out, const void *in, const void *key, const byte outlen, const word64 inlen, byte keylen );
|
||||||
|
|
||||||
|
int blake2sp( byte *out, const void *in, const void *key, const byte outlen, const word64 inlen, byte keylen );
|
||||||
|
int blake2bp( byte *out, const void *in, const void *key, const byte outlen, const word64 inlen, byte keylen );
|
||||||
|
|
||||||
|
static inline int blake2( byte *out, const void *in, const void *key, const byte outlen, const word64 inlen, byte keylen )
|
||||||
|
{
|
||||||
|
return blake2b( out, in, key, outlen, inlen, keylen );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* CTAOCRYPT_BLAKE2_INT_H */
|
||||||
|
|
@ -1,15 +1,3 @@
|
|||||||
/*
|
|
||||||
BLAKE2 reference source code package - reference C implementations
|
|
||||||
|
|
||||||
Written in 2012 by Samuel Neves <sneves@dei.uc.pt>
|
|
||||||
|
|
||||||
To the extent possible under law, the author(s) have dedicated all copyright
|
|
||||||
and related and neighboring rights to this software to the public domain
|
|
||||||
worldwide. This software is distributed without any warranty.
|
|
||||||
|
|
||||||
You should have received a copy of the CC0 Public Domain Dedication along with
|
|
||||||
this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
|
|
||||||
*/
|
|
||||||
/* blake2.h
|
/* blake2.h
|
||||||
*
|
*
|
||||||
* Copyright (C) 2006-2013 wolfSSL Inc.
|
* Copyright (C) 2006-2013 wolfSSL Inc.
|
||||||
@ -31,152 +19,38 @@
|
|||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef HAVE_BLAKE2
|
||||||
|
|
||||||
#ifndef CTAOCRYPT_BLAKE2_H
|
#ifndef CTAOCRYPT_BLAKE2_H
|
||||||
#define CTAOCRYPT_BLAKE2_H
|
#define CTAOCRYPT_BLAKE2_H
|
||||||
|
|
||||||
#include <cyassl/ctaocrypt/types.h>
|
#include <cyassl/ctaocrypt/blake2-int.h>
|
||||||
|
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
/* in bytes, variable digest size up to 512 bits (64 bytes) */
|
||||||
#define ALIGN(x) __declspec(align(x))
|
enum {
|
||||||
#elif defined(__GNUC__)
|
BLAKE2_ID = 7 /* hash type unique */
|
||||||
#define ALIGN(x) __attribute__((aligned(x)))
|
};
|
||||||
#else
|
|
||||||
#define ALIGN(x)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
/* BLAKE2 digest */
|
||||||
extern "C" {
|
typedef struct Blake2 {
|
||||||
#endif
|
blake2b_state S[1]; /* our state */
|
||||||
|
word32 digestSz; /* digest size used on init */
|
||||||
enum blake2s_constant
|
} Blake2;
|
||||||
{
|
|
||||||
BLAKE2S_BLOCKBYTES = 64,
|
|
||||||
BLAKE2S_OUTBYTES = 32,
|
CYASSL_API int InitBlake2(Blake2*, word32);
|
||||||
BLAKE2S_KEYBYTES = 32,
|
CYASSL_API int Blake2Update(Blake2*, const byte*, word32);
|
||||||
BLAKE2S_SALTBYTES = 8,
|
CYASSL_API int Blake2Final(Blake2*, byte*, word32);
|
||||||
BLAKE2S_PERSONALBYTES = 8
|
|
||||||
};
|
|
||||||
|
|
||||||
enum blake2b_constant
|
|
||||||
{
|
|
||||||
BLAKE2B_BLOCKBYTES = 128,
|
|
||||||
BLAKE2B_OUTBYTES = 64,
|
|
||||||
BLAKE2B_KEYBYTES = 64,
|
|
||||||
BLAKE2B_SALTBYTES = 16,
|
|
||||||
BLAKE2B_PERSONALBYTES = 16
|
|
||||||
};
|
|
||||||
|
|
||||||
#pragma pack(push, 1)
|
|
||||||
typedef struct __blake2s_param
|
|
||||||
{
|
|
||||||
byte digest_length; /* 1 */
|
|
||||||
byte key_length; /* 2 */
|
|
||||||
byte fanout; /* 3 */
|
|
||||||
byte depth; /* 4 */
|
|
||||||
word32 leaf_length; /* 8 */
|
|
||||||
byte node_offset[6];/* 14 */
|
|
||||||
byte node_depth; /* 15 */
|
|
||||||
byte inner_length; /* 16 */
|
|
||||||
/* byte reserved[0]; */
|
|
||||||
byte salt[BLAKE2B_SALTBYTES]; /* 24 */
|
|
||||||
byte personal[BLAKE2S_PERSONALBYTES]; /* 32 */
|
|
||||||
} blake2s_param;
|
|
||||||
|
|
||||||
ALIGN( 64 ) typedef struct __blake2s_state
|
|
||||||
{
|
|
||||||
word32 h[8];
|
|
||||||
word32 t[2];
|
|
||||||
word32 f[2];
|
|
||||||
byte buf[2 * BLAKE2S_BLOCKBYTES];
|
|
||||||
word64 buflen;
|
|
||||||
byte last_node;
|
|
||||||
} blake2s_state ;
|
|
||||||
|
|
||||||
typedef struct __blake2b_param
|
|
||||||
{
|
|
||||||
byte digest_length; /* 1 */
|
|
||||||
byte key_length; /* 2 */
|
|
||||||
byte fanout; /* 3 */
|
|
||||||
byte depth; /* 4 */
|
|
||||||
word32 leaf_length; /* 8 */
|
|
||||||
word64 node_offset; /* 16 */
|
|
||||||
byte node_depth; /* 17 */
|
|
||||||
byte inner_length; /* 18 */
|
|
||||||
byte reserved[14]; /* 32 */
|
|
||||||
byte salt[BLAKE2B_SALTBYTES]; /* 48 */
|
|
||||||
byte personal[BLAKE2B_PERSONALBYTES]; /* 64 */
|
|
||||||
} blake2b_param;
|
|
||||||
|
|
||||||
ALIGN( 64 ) typedef struct __blake2b_state
|
|
||||||
{
|
|
||||||
word64 h[8];
|
|
||||||
word64 t[2];
|
|
||||||
word64 f[2];
|
|
||||||
byte buf[2 * BLAKE2B_BLOCKBYTES];
|
|
||||||
word64 buflen;
|
|
||||||
byte last_node;
|
|
||||||
} blake2b_state;
|
|
||||||
|
|
||||||
typedef struct __blake2sp_state
|
|
||||||
{
|
|
||||||
blake2s_state S[8][1];
|
|
||||||
blake2s_state R[1];
|
|
||||||
byte buf[8 * BLAKE2S_BLOCKBYTES];
|
|
||||||
word64 buflen;
|
|
||||||
} blake2sp_state;
|
|
||||||
|
|
||||||
typedef struct __blake2bp_state
|
|
||||||
{
|
|
||||||
blake2b_state S[4][1];
|
|
||||||
blake2b_state R[1];
|
|
||||||
byte buf[4 * BLAKE2B_BLOCKBYTES];
|
|
||||||
word64 buflen;
|
|
||||||
} blake2bp_state;
|
|
||||||
#pragma pack(pop)
|
|
||||||
|
|
||||||
/* Streaming API */
|
|
||||||
int blake2s_init( blake2s_state *S, const byte outlen );
|
|
||||||
int blake2s_init_key( blake2s_state *S, const byte outlen, const void *key, const byte keylen );
|
|
||||||
int blake2s_init_param( blake2s_state *S, const blake2s_param *P );
|
|
||||||
int blake2s_update( blake2s_state *S, const byte *in, word64 inlen );
|
|
||||||
int blake2s_final( blake2s_state *S, byte *out, byte outlen );
|
|
||||||
|
|
||||||
CYASSL_API int blake2b_init( blake2b_state *S, const byte outlen );
|
|
||||||
int blake2b_init_key( blake2b_state *S, const byte outlen, const void *key, const byte keylen );
|
|
||||||
int blake2b_init_param( blake2b_state *S, const blake2b_param *P );
|
|
||||||
CYASSL_API int blake2b_update( blake2b_state *S, const byte *in, word64 inlen );
|
|
||||||
CYASSL_API int blake2b_final( blake2b_state *S, byte *out, byte outlen );
|
|
||||||
|
|
||||||
int blake2sp_init( blake2sp_state *S, const byte outlen );
|
|
||||||
int blake2sp_init_key( blake2sp_state *S, const byte outlen, const void *key, const byte keylen );
|
|
||||||
int blake2sp_update( blake2sp_state *S, const byte *in, word64 inlen );
|
|
||||||
int blake2sp_final( blake2sp_state *S, byte *out, byte outlen );
|
|
||||||
|
|
||||||
int blake2bp_init( blake2bp_state *S, const byte outlen );
|
|
||||||
int blake2bp_init_key( blake2bp_state *S, const byte outlen, const void *key, const byte keylen );
|
|
||||||
int blake2bp_update( blake2bp_state *S, const byte *in, word64 inlen );
|
|
||||||
int blake2bp_final( blake2bp_state *S, byte *out, byte outlen );
|
|
||||||
|
|
||||||
/* Simple API */
|
|
||||||
int blake2s( byte *out, const void *in, const void *key, const byte outlen, const word64 inlen, byte keylen );
|
|
||||||
int blake2b( byte *out, const void *in, const void *key, const byte outlen, const word64 inlen, byte keylen );
|
|
||||||
|
|
||||||
int blake2sp( byte *out, const void *in, const void *key, const byte outlen, const word64 inlen, byte keylen );
|
|
||||||
int blake2bp( byte *out, const void *in, const void *key, const byte outlen, const word64 inlen, byte keylen );
|
|
||||||
|
|
||||||
static inline int blake2( byte *out, const void *in, const void *key, const byte outlen, const word64 inlen, byte keylen )
|
|
||||||
{
|
|
||||||
return blake2b( out, in, key, outlen, inlen, keylen );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* CTaoCrypt API */
|
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* CTAOCRYPT_BLAKE2_H */
|
#endif /* CTAOCRYPT_BLAKE2_H */
|
||||||
|
#endif /* HAVE_BLAKE2 */
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user