From f55636bd4346ee2124a41c591b310cf2015c0996 Mon Sep 17 00:00:00 2001 From: George Pollard Date: Tue, 6 Mar 2018 18:05:02 +1300 Subject: [PATCH 01/12] Add `hmacLazy` for lazy `ByteString`s Modeled off `hashLazy`. --- Crypto/MAC/HMAC.hs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Crypto/MAC/HMAC.hs b/Crypto/MAC/HMAC.hs index 77582e3..6f109cd 100644 --- a/Crypto/MAC/HMAC.hs +++ b/Crypto/MAC/HMAC.hs @@ -12,6 +12,7 @@ {-# LANGUAGE GeneralizedNewtypeDeriving #-} module Crypto.MAC.HMAC ( hmac + , hmacLazy , HMAC(..) -- * Incremental , Context(..) @@ -24,11 +25,12 @@ module Crypto.MAC.HMAC import Crypto.Hash hiding (Context) import qualified Crypto.Hash as Hash (Context) import Crypto.Hash.IO -import Crypto.Internal.ByteArray (ScrubbedBytes, ByteArray, ByteArrayAccess) +import Crypto.Internal.ByteArray (ScrubbedBytes, ByteArrayAccess) import qualified Crypto.Internal.ByteArray as B import Data.Memory.PtrMethods import Crypto.Internal.Compat import Crypto.Internal.Imports +import qualified Data.ByteString.Lazy as L -- | Represent an HMAC that is a phantom type with the hash used to produce the mac. -- @@ -39,13 +41,20 @@ newtype HMAC a = HMAC { hmacGetDigest :: Digest a } instance Eq (HMAC a) where (HMAC b1) == (HMAC b2) = B.constEq b1 b2 --- | compute a MAC using the supplied hashing function +-- | Compute a MAC using the supplied hashing function hmac :: (ByteArrayAccess key, ByteArrayAccess message, HashAlgorithm a) => key -- ^ Secret key -> message -- ^ Message to MAC -> HMAC a hmac secret msg = finalize $ updates (initialize secret) [msg] +-- | Compute a MAC using the supplied hashing function, for a lazy input +hmacLazy :: (ByteArrayAccess key, HashAlgorithm a) + => key -- ^ Secret key + -> L.ByteString -- ^ Message to MAC + -> HMAC a +hmacLazy secret msg = finalize $ updates (initialize secret) (L.toChunks msg) + -- | Represent an ongoing HMAC state, that can be appended with 'update' -- and finalize to an HMAC with 'hmacFinalize' data Context hashalg = Context !(Hash.Context hashalg) !(Hash.Context hashalg) From e9c9c770d369ec8d0417742f5b2341aeec25e1e5 Mon Sep 17 00:00:00 2001 From: George Pollard Date: Thu, 3 Jun 2021 08:34:34 +1200 Subject: [PATCH 02/12] Update HMAC.hs --- Crypto/MAC/HMAC.hs | 1 - 1 file changed, 1 deletion(-) diff --git a/Crypto/MAC/HMAC.hs b/Crypto/MAC/HMAC.hs index 35b8d11..0bd1e86 100644 --- a/Crypto/MAC/HMAC.hs +++ b/Crypto/MAC/HMAC.hs @@ -29,7 +29,6 @@ import Crypto.Internal.ByteArray (ScrubbedBytes, ByteArrayAccess) import qualified Crypto.Internal.ByteArray as B import Data.Memory.PtrMethods import Crypto.Internal.Compat -import Crypto.Internal.Imports import qualified Data.ByteString.Lazy as L -- | Represent an HMAC that is a phantom type with the hash used to produce the mac. From b3db979ca07c89ed8fef14c60d8258d091c83a19 Mon Sep 17 00:00:00 2001 From: Robert Vollmert Date: Fri, 10 Sep 2021 17:47:53 +0200 Subject: [PATCH 03/12] Fix alignment in gfmul_generic (closes #334) This fixes a test-suite segfault on Darwin with -O0. Before this change: $ cabal run -O0 test-cryptonite -- -p AE1 Segmentation fault: 11 with Thread 0 Crashed:: Dispatch queue: com.apple.main-thread 0 test-cryptonite 0x0000000108f7f61f gfmul_generic + 47 1 test-cryptonite 0x0000000108f76f17 ghash_add + 71 2 test-cryptonite 0x0000000108f743b4 cryptonite_aesni_gcm_encrypt128 + 2244 3 test-cryptonite 0x0000000108f97f20 cryptonite_aes_gcm_encrypt + 96 4 test-cryptonite 0x0000000108eeadf5 Lc8Pq_info + 197 --- cbits/aes/x86ni.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cbits/aes/x86ni.c b/cbits/aes/x86ni.c index 75aae55..ce244bd 100644 --- a/cbits/aes/x86ni.c +++ b/cbits/aes/x86ni.c @@ -165,7 +165,7 @@ static __m128i gfmulx(__m128i v) TARGET_AESNI static __m128i gfmul_generic(__m128i tag, const table_4bit htable) { - aes_block _t; + aes_block _t ALIGNMENT(16); _mm_store_si128((__m128i *) &_t, tag); cryptonite_aes_generic_gf_mul(&_t, htable); tag = _mm_load_si128((__m128i *) &_t); From a8d1d401bc16b488970086d995df726542a52019 Mon Sep 17 00:00:00 2001 From: iquerejeta Date: Mon, 13 Sep 2021 15:11:27 +0100 Subject: [PATCH 04/12] linker complaints --- cbits/argon2/core.c | 68 ++++++++++++++--------------- cbits/blake2/ref/blake2.h | 66 ++++++++++++++-------------- cbits/blake2/ref/blake2b-ref.c | 80 +++++++++++++++++----------------- cbits/blake2/sse/blake2.h | 66 ++++++++++++++-------------- cbits/blake2/sse/blake2b.c | 2 +- cbits/blake2/sse/blake2bp.c | 50 ++++++++++----------- cbits/blake2/sse/blake2s.c | 10 ++--- cbits/blake2/sse/blake2sp.c | 50 ++++++++++----------- cbits/blake2/sse/blake2xb.c | 42 +++++++++--------- cbits/blake2/sse/blake2xs.c | 42 +++++++++--------- cbits/cryptonite_blake2b.c | 6 +-- cbits/cryptonite_blake2bp.c | 6 +-- cbits/cryptonite_blake2s.c | 6 +-- cbits/cryptonite_blake2sp.c | 6 +-- 14 files changed, 250 insertions(+), 250 deletions(-) diff --git a/cbits/argon2/core.c b/cbits/argon2/core.c index fb5233e..cc22a74 100644 --- a/cbits/argon2/core.c +++ b/cbits/argon2/core.c @@ -4,7 +4,7 @@ * Copyright 2015 * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves * - * You may use this work under the terms of a Creative Commons CC0 1.0 + * You may use this work under the terms of a Creative Commons CC0 1.0 * License/Waiver or the Apache Public License 2.0, at your option. The terms of * these licenses can be found at: * @@ -83,25 +83,25 @@ static int blake2b_long(void *pout, size_t outlen, const void *in, size_t inlen) } while ((void)0, 0) if (outlen <= BLAKE2B_OUTBYTES) { - TRY(blake2b_init(&blake_state, outlen)); - TRY(blake2b_update(&blake_state, outlen_bytes, sizeof(outlen_bytes))); - TRY(blake2b_update(&blake_state, in, inlen)); - TRY(blake2b_final(&blake_state, out, outlen)); + TRY(_cryptonite_blake2b_init(&blake_state, outlen)); + TRY(_cryptonite_blake2b_update(&blake_state, outlen_bytes, sizeof(outlen_bytes))); + TRY(_cryptonite_blake2b_update(&blake_state, in, inlen)); + TRY(_cryptonite_blake2b_final(&blake_state, out, outlen)); } else { uint32_t toproduce; uint8_t out_buffer[BLAKE2B_OUTBYTES]; uint8_t in_buffer[BLAKE2B_OUTBYTES]; - TRY(blake2b_init(&blake_state, BLAKE2B_OUTBYTES)); - TRY(blake2b_update(&blake_state, outlen_bytes, sizeof(outlen_bytes))); - TRY(blake2b_update(&blake_state, in, inlen)); - TRY(blake2b_final(&blake_state, out_buffer, BLAKE2B_OUTBYTES)); + TRY(_cryptonite_blake2b_init(&blake_state, BLAKE2B_OUTBYTES)); + TRY(_cryptonite_blake2b_update(&blake_state, outlen_bytes, sizeof(outlen_bytes))); + TRY(_cryptonite_blake2b_update(&blake_state, in, inlen)); + TRY(_cryptonite_blake2b_final(&blake_state, out_buffer, BLAKE2B_OUTBYTES)); memcpy(out, out_buffer, BLAKE2B_OUTBYTES / 2); out += BLAKE2B_OUTBYTES / 2; toproduce = (uint32_t)outlen - BLAKE2B_OUTBYTES / 2; while (toproduce > BLAKE2B_OUTBYTES) { memcpy(in_buffer, out_buffer, BLAKE2B_OUTBYTES); - TRY(blake2b(out_buffer, BLAKE2B_OUTBYTES, in_buffer, + TRY(_cryptonite_blake2b(out_buffer, BLAKE2B_OUTBYTES, in_buffer, BLAKE2B_OUTBYTES, NULL, 0)); memcpy(out, out_buffer, BLAKE2B_OUTBYTES / 2); out += BLAKE2B_OUTBYTES / 2; @@ -109,7 +109,7 @@ static int blake2b_long(void *pout, size_t outlen, const void *in, size_t inlen) } memcpy(in_buffer, out_buffer, BLAKE2B_OUTBYTES); - TRY(blake2b(out_buffer, toproduce, in_buffer, BLAKE2B_OUTBYTES, NULL, + TRY(_cryptonite_blake2b(out_buffer, toproduce, in_buffer, BLAKE2B_OUTBYTES, NULL, 0)); memcpy(out, out_buffer, toproduce); } @@ -149,7 +149,7 @@ static void store_block(void *output, const block *src) { } /***************Memory functions*****************/ -static +static int allocate_memory(const argon2_context *context, uint8_t **memory, size_t num, size_t size) { size_t memory_size = num*size; @@ -175,7 +175,7 @@ int allocate_memory(const argon2_context *context, uint8_t **memory, return ARGON2_OK; } -static +static void free_memory(const argon2_context *context, uint8_t *memory, size_t num, size_t size) { size_t memory_size = num*size; @@ -425,7 +425,7 @@ fail: } #endif /* ARGON2_NO_THREADS */ -static +static int fill_memory_blocks(argon2_instance_t *instance) { if (instance == NULL || instance->lanes == 0) { return ARGON2_INCORRECT_PARAMETER; @@ -437,7 +437,7 @@ int fill_memory_blocks(argon2_instance_t *instance) { fill_memory_blocks_st(instance) : fill_memory_blocks_mt(instance); #endif } -static +static int validate_inputs(const argon2_context *context) { if (NULL == context) { return ARGON2_INCORRECT_PARAMETER; @@ -564,7 +564,7 @@ int validate_inputs(const argon2_context *context) { return ARGON2_OK; } -static +static void fill_first_blocks(uint8_t *blockhash, const argon2_instance_t *instance) { uint32_t l; /* Make the first and second block in each lane as G(H0||i||0) or @@ -587,7 +587,7 @@ void fill_first_blocks(uint8_t *blockhash, const argon2_instance_t *instance) { } clear_internal_memory(blockhash_bytes, ARGON2_BLOCK_SIZE); } -static +static void initial_hash(uint8_t *blockhash, argon2_context *context, argon2_type type) { blake2b_state BlakeHash; @@ -597,31 +597,31 @@ void initial_hash(uint8_t *blockhash, argon2_context *context, return; } - blake2b_init(&BlakeHash, ARGON2_PREHASH_DIGEST_LENGTH); + _cryptonite_blake2b_init(&BlakeHash, ARGON2_PREHASH_DIGEST_LENGTH); store32(&value, context->lanes); - blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); + _cryptonite_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); store32(&value, context->outlen); - blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); + _cryptonite_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); store32(&value, context->m_cost); - blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); + _cryptonite_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); store32(&value, context->t_cost); - blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); + _cryptonite_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); store32(&value, context->version); - blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); + _cryptonite_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); store32(&value, (uint32_t)type); - blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); + _cryptonite_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); store32(&value, context->pwdlen); - blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); + _cryptonite_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); if (context->pwd != NULL) { - blake2b_update(&BlakeHash, (const uint8_t *)context->pwd, + _cryptonite_blake2b_update(&BlakeHash, (const uint8_t *)context->pwd, context->pwdlen); if (context->flags & ARGON2_FLAG_CLEAR_PASSWORD) { @@ -631,18 +631,18 @@ void initial_hash(uint8_t *blockhash, argon2_context *context, } store32(&value, context->saltlen); - blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); + _cryptonite_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); if (context->salt != NULL) { - blake2b_update(&BlakeHash, (const uint8_t *)context->salt, + _cryptonite_blake2b_update(&BlakeHash, (const uint8_t *)context->salt, context->saltlen); } store32(&value, context->secretlen); - blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); + _cryptonite_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); if (context->secret != NULL) { - blake2b_update(&BlakeHash, (const uint8_t *)context->secret, + _cryptonite_blake2b_update(&BlakeHash, (const uint8_t *)context->secret, context->secretlen); if (context->flags & ARGON2_FLAG_CLEAR_SECRET) { @@ -652,16 +652,16 @@ void initial_hash(uint8_t *blockhash, argon2_context *context, } store32(&value, context->adlen); - blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); + _cryptonite_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); if (context->ad != NULL) { - blake2b_update(&BlakeHash, (const uint8_t *)context->ad, + _cryptonite_blake2b_update(&BlakeHash, (const uint8_t *)context->ad, context->adlen); } - blake2b_final(&BlakeHash, blockhash, ARGON2_PREHASH_DIGEST_LENGTH); + _cryptonite_blake2b_final(&BlakeHash, blockhash, ARGON2_PREHASH_DIGEST_LENGTH); } -static +static int initialize(argon2_instance_t *instance, argon2_context *context) { uint8_t blockhash[ARGON2_PREHASH_SEED_LENGTH]; int result = ARGON2_OK; diff --git a/cbits/blake2/ref/blake2.h b/cbits/blake2/ref/blake2.h index ad62f26..fd83b84 100644 --- a/cbits/blake2/ref/blake2.h +++ b/cbits/blake2/ref/blake2.h @@ -142,51 +142,51 @@ extern "C" { }; /* Streaming API */ - int blake2s_init( blake2s_state *S, size_t outlen ); - int blake2s_init_key( blake2s_state *S, size_t outlen, const void *key, size_t keylen ); - int blake2s_init_param( blake2s_state *S, const blake2s_param *P ); - int blake2s_update( blake2s_state *S, const void *in, size_t inlen ); - int blake2s_final( blake2s_state *S, void *out, size_t outlen ); + int _cryptonite_blake2s_init( blake2s_state *S, size_t outlen ); + int _cryptonite_blake2s_init_key( blake2s_state *S, size_t outlen, const void *key, size_t keylen ); + int _cryptonite_blake2s_init_param( blake2s_state *S, const blake2s_param *P ); + int _cryptonite_blake2s_update( blake2s_state *S, const void *in, size_t inlen ); + int _cryptonite_blake2s_final( blake2s_state *S, void *out, size_t outlen ); - int blake2b_init( blake2b_state *S, size_t outlen ); - int blake2b_init_key( blake2b_state *S, size_t outlen, const void *key, size_t keylen ); - int blake2b_init_param( blake2b_state *S, const blake2b_param *P ); - int blake2b_update( blake2b_state *S, const void *in, size_t inlen ); - int blake2b_final( blake2b_state *S, void *out, size_t outlen ); + int _cryptonite__cryptonite_blake2b_init( blake2b_state *S, size_t outlen ); + int _cryptonite_blake2b_init_key( blake2b_state *S, size_t outlen, const void *key, size_t keylen ); + int _cryptonite_blake2b_init_param( blake2b_state *S, const blake2b_param *P ); + int _cryptonite_blake2b_update( blake2b_state *S, const void *in, size_t inlen ); + int _cryptonite_blake2b_final( blake2b_state *S, void *out, size_t outlen ); - int blake2sp_init( blake2sp_state *S, size_t outlen ); - int blake2sp_init_key( blake2sp_state *S, size_t outlen, const void *key, size_t keylen ); - int blake2sp_update( blake2sp_state *S, const void *in, size_t inlen ); - int blake2sp_final( blake2sp_state *S, void *out, size_t outlen ); + int _cryptonite_blake2sp_init( blake2sp_state *S, size_t outlen ); + int _cryptonite_blake2sp_init_key( blake2sp_state *S, size_t outlen, const void *key, size_t keylen ); + int _cryptonite_blake2sp_update( blake2sp_state *S, const void *in, size_t inlen ); + int _cryptonite_blake2sp_final( blake2sp_state *S, void *out, size_t outlen ); - int blake2bp_init( blake2bp_state *S, size_t outlen ); - int blake2bp_init_key( blake2bp_state *S, size_t outlen, const void *key, size_t keylen ); - int blake2bp_update( blake2bp_state *S, const void *in, size_t inlen ); - int blake2bp_final( blake2bp_state *S, void *out, size_t outlen ); + int _cryptonite_blake2bp_init( blake2bp_state *S, size_t outlen ); + int _cryptonite_blake2bp_init_key( blake2bp_state *S, size_t outlen, const void *key, size_t keylen ); + int _cryptonite_blake2bp_update( blake2bp_state *S, const void *in, size_t inlen ); + int _cryptonite_blake2bp_final( blake2bp_state *S, void *out, size_t outlen ); /* Variable output length API */ - int blake2xs_init( blake2xs_state *S, const size_t outlen ); - int blake2xs_init_key( blake2xs_state *S, const size_t outlen, const void *key, size_t keylen ); - int blake2xs_update( blake2xs_state *S, const void *in, size_t inlen ); - int blake2xs_final(blake2xs_state *S, void *out, size_t outlen); + int _cryptonite_blake2xs_init( blake2xs_state *S, const size_t outlen ); + int _cryptonite_blake2xs_init_key( blake2xs_state *S, const size_t outlen, const void *key, size_t keylen ); + int _cryptonite_blake2xs_update( blake2xs_state *S, const void *in, size_t inlen ); + int _cryptonite_blake2xs_final(blake2xs_state *S, void *out, size_t outlen); - int blake2xb_init( blake2xb_state *S, const size_t outlen ); - int blake2xb_init_key( 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); + int _cryptonite_blake2xb_init( blake2xb_state *S, const size_t outlen ); + int _cryptonite_blake2xb_init_key( blake2xb_state *S, const size_t outlen, const void *key, size_t keylen ); + int _cryptonite_blake2xb_update( blake2xb_state *S, const void *in, size_t inlen ); + int _cryptonite_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 ); - int blake2b( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen ); + int _cryptonite_blake2s( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen ); + int _cryptonite_blake2b( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen ); - 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 _cryptonite_blake2sp( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen ); + int _cryptonite_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 ); + int _cryptonite_blake2xs( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen ); + int _cryptonite_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 ); + int _cryptonite_blake2( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen ); #if defined(__cplusplus) } diff --git a/cbits/blake2/ref/blake2b-ref.c b/cbits/blake2/ref/blake2b-ref.c index cd38b1b..c20924b 100644 --- a/cbits/blake2/ref/blake2b-ref.c +++ b/cbits/blake2/ref/blake2b-ref.c @@ -45,31 +45,31 @@ static const uint8_t blake2b_sigma[12][16] = }; -static void blake2b_set_lastnode( blake2b_state *S ) +static void _cryptonite_blake2b_set_lastnode( blake2b_state *S ) { S->f[1] = (uint64_t)-1; } /* Some helper functions, not necessarily useful */ -static int blake2b_is_lastblock( const blake2b_state *S ) +static int _cryptonite_blake2b_is_lastblock( const blake2b_state *S ) { return S->f[0] != 0; } -static void blake2b_set_lastblock( blake2b_state *S ) +static void _cryptonite_blake2b_set_lastblock( blake2b_state *S ) { - if( S->last_node ) blake2b_set_lastnode( S ); + if( S->last_node ) _cryptonite_blake2b_set_lastnode( S ); S->f[0] = (uint64_t)-1; } -static void blake2b_increment_counter( blake2b_state *S, const uint64_t inc ) +static void _cryptonite_blake2b_increment_counter( blake2b_state *S, const uint64_t inc ) { S->t[0] += inc; S->t[1] += ( S->t[0] < inc ); } -static void blake2b_init0( blake2b_state *S ) +static void _cryptonite_blake2b_init0( blake2b_state *S ) { size_t i; memset( S, 0, sizeof( blake2b_state ) ); @@ -78,12 +78,12 @@ static void blake2b_init0( blake2b_state *S ) } /* init xors IV with input parameter block */ -int blake2b_init_param( blake2b_state *S, const blake2b_param *P ) +int _cryptonite_blake2b_init_param( blake2b_state *S, const blake2b_param *P ) { const uint8_t *p = ( const uint8_t * )( P ); size_t i; - blake2b_init0( S ); + _cryptonite_blake2b_init0( S ); /* IV XOR ParamBlock */ for( i = 0; i < 8; ++i ) @@ -95,11 +95,11 @@ int blake2b_init_param( blake2b_state *S, const blake2b_param *P ) -int blake2b_init( blake2b_state *S, size_t outlen ) +int _cryptonite_blake2b_init( blake2b_state *S, size_t outlen ) { blake2b_param P[1]; - if ( ( !outlen ) || ( outlen > BLAKE2B_OUTBYTES ) ) return -1; + if ( ( !outlen ) || ( outlen > blake2B_OUTBYTES ) ) return -1; P->digest_length = (uint8_t)outlen; P->key_length = 0; @@ -113,11 +113,11 @@ int blake2b_init( blake2b_state *S, size_t outlen ) memset( P->reserved, 0, sizeof( P->reserved ) ); memset( P->salt, 0, sizeof( P->salt ) ); memset( P->personal, 0, sizeof( P->personal ) ); - return blake2b_init_param( S, P ); + return _cryptonite_blake2b_init_param( S, P ); } -int blake2b_init_key( blake2b_state *S, size_t outlen, const void *key, size_t keylen ) +int _cryptonite_blake2b_init_key( blake2b_state *S, size_t outlen, const void *key, size_t keylen ) { blake2b_param P[1]; @@ -138,13 +138,13 @@ int blake2b_init_key( blake2b_state *S, size_t outlen, const void *key, size_t k memset( P->salt, 0, sizeof( P->salt ) ); memset( P->personal, 0, sizeof( P->personal ) ); - if( blake2b_init_param( S, P ) < 0 ) return -1; + if( _cryptonite_blake2b_init_param( S, P ) < 0 ) return -1; { uint8_t block[BLAKE2B_BLOCKBYTES]; memset( block, 0, BLAKE2B_BLOCKBYTES ); memcpy( block, key, keylen ); - blake2b_update( S, block, BLAKE2B_BLOCKBYTES ); + _cryptonite_blake2b_update( S, block, BLAKE2B_BLOCKBYTES ); secure_zero_memory( block, BLAKE2B_BLOCKBYTES ); /* Burn the key from stack */ } return 0; @@ -174,7 +174,7 @@ int blake2b_init_key( blake2b_state *S, size_t outlen, const void *key, size_t k G(r,7,v[ 3],v[ 4],v[ 9],v[14]); \ } while(0) -static void blake2b_compress( blake2b_state *S, const uint8_t block[BLAKE2B_BLOCKBYTES] ) +static void _cryptonite_blake2b_compress( blake2b_state *S, const uint8_t block[BLAKE2B_BLOCKBYTES] ) { uint64_t m[16]; uint64_t v[16]; @@ -218,7 +218,7 @@ static void blake2b_compress( blake2b_state *S, const uint8_t block[BLAKE2B_BLOC #undef G #undef ROUND -int blake2b_update( blake2b_state *S, const void *pin, size_t inlen ) +int _cryptonite_blake2b_update( blake2b_state *S, const void *pin, size_t inlen ) { const unsigned char * in = (const unsigned char *)pin; if( inlen > 0 ) @@ -229,12 +229,12 @@ int blake2b_update( blake2b_state *S, const void *pin, size_t inlen ) { S->buflen = 0; memcpy( S->buf + left, in, fill ); /* Fill buffer */ - blake2b_increment_counter( S, BLAKE2B_BLOCKBYTES ); - blake2b_compress( S, S->buf ); /* Compress */ + _cryptonite_blake2b_increment_counter( S, BLAKE2B_BLOCKBYTES ); + _cryptonite_blake2b_compress( S, S->buf ); /* Compress */ in += fill; inlen -= fill; while(inlen > BLAKE2B_BLOCKBYTES) { - blake2b_increment_counter(S, BLAKE2B_BLOCKBYTES); - blake2b_compress( S, in ); + _cryptonite_blake2b_increment_counter(S, BLAKE2B_BLOCKBYTES); + _cryptonite_blake2b_compress( S, in ); in += BLAKE2B_BLOCKBYTES; inlen -= BLAKE2B_BLOCKBYTES; } @@ -245,7 +245,7 @@ int blake2b_update( blake2b_state *S, const void *pin, size_t inlen ) return 0; } -int blake2b_final( blake2b_state *S, void *out, size_t outlen ) +int _cryptonite_blake2b_final( blake2b_state *S, void *out, size_t outlen ) { uint8_t buffer[BLAKE2B_OUTBYTES] = {0}; size_t i; @@ -253,13 +253,13 @@ int blake2b_final( blake2b_state *S, void *out, size_t outlen ) if( out == NULL || outlen < S->outlen ) return -1; - if( blake2b_is_lastblock( S ) ) + if( _cryptonite_blake2b_is_lastblock( S ) ) return -1; - blake2b_increment_counter( S, S->buflen ); - blake2b_set_lastblock( S ); + _cryptonite_blake2b_increment_counter( S, S->buflen ); + _cryptonite_blake2b_set_lastblock( S ); memset( S->buf + S->buflen, 0, BLAKE2B_BLOCKBYTES - S->buflen ); /* Padding */ - blake2b_compress( S, S->buf ); + _cryptonite_blake2b_compress( S, S->buf ); for( i = 0; i < 8; ++i ) /* Output full hash to temp buffer */ store64( buffer + sizeof( S->h[i] ) * i, S->h[i] ); @@ -270,7 +270,7 @@ int blake2b_final( blake2b_state *S, void *out, size_t outlen ) } /* inlen, at least, should be uint64_t. Others can be size_t. */ -int blake2b( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen ) +int _cryptonite_blake2b( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen ) { blake2b_state S[1]; @@ -287,26 +287,26 @@ int blake2b( void *out, size_t outlen, const void *in, size_t inlen, const void if( keylen > 0 ) { - if( blake2b_init_key( S, outlen, key, keylen ) < 0 ) return -1; + if( _cryptonite_blake2b_init_key( S, outlen, key, keylen ) < 0 ) return -1; } else { - if( blake2b_init( S, outlen ) < 0 ) return -1; + if( _cryptonite_blake2b_init( S, outlen ) < 0 ) return -1; } - blake2b_update( S, ( const uint8_t * )in, inlen ); - blake2b_final( S, out, outlen ); + _cryptonite_blake2b_update( S, ( const uint8_t * )in, inlen ); + _cryptonite_blake2b_final( S, out, outlen ); return 0; } -int blake2( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen ) { - return blake2b(out, outlen, in, inlen, key, keylen); +int _cryptonite_blake2( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen ) { + return _cryptonite_blake2b(out, outlen, in, inlen, key, keylen); } #if defined(SUPERCOP) int crypto_hash( unsigned char *out, unsigned char *in, unsigned long long inlen ) { - return blake2b( out, BLAKE2B_OUTBYTES, in, inlen, NULL, 0 ); + return _cryptonite_blake2b( out, BLAKE2B_OUTBYTES, in, inlen, NULL, 0 ); } #endif @@ -329,9 +329,9 @@ int main( void ) for( i = 0; i < BLAKE2_KAT_LENGTH; ++i ) { uint8_t hash[BLAKE2B_OUTBYTES]; - blake2b( hash, BLAKE2B_OUTBYTES, buf, i, key, BLAKE2B_KEYBYTES ); + _cryptonite_blake2b( hash, BLAKE2B_OUTBYTES, buf, i, key, BLAKE2B_KEYBYTES ); - if( 0 != memcmp( hash, blake2b_keyed_kat[i], BLAKE2B_OUTBYTES ) ) + if( 0 != memcmp( hash, _cryptonite_blake2b_keyed_kat[i], BLAKE2B_OUTBYTES ) ) { goto fail; } @@ -346,25 +346,25 @@ int main( void ) size_t mlen = i; int err = 0; - if( (err = blake2b_init_key(&S, BLAKE2B_OUTBYTES, key, BLAKE2B_KEYBYTES)) < 0 ) { + if( (err = _cryptonite_blake2b_init_key(&S, BLAKE2B_OUTBYTES, key, BLAKE2B_KEYBYTES)) < 0 ) { goto fail; } while (mlen >= step) { - if ( (err = blake2b_update(&S, p, step)) < 0 ) { + if ( (err = _cryptonite_blake2b_update(&S, p, step)) < 0 ) { goto fail; } mlen -= step; p += step; } - if ( (err = blake2b_update(&S, p, mlen)) < 0) { + if ( (err = _cryptonite_blake2b_update(&S, p, mlen)) < 0) { goto fail; } - if ( (err = blake2b_final(&S, hash, BLAKE2B_OUTBYTES)) < 0) { + if ( (err = _cryptonite_blake2b_final(&S, hash, BLAKE2B_OUTBYTES)) < 0) { goto fail; } - if (0 != memcmp(hash, blake2b_keyed_kat[i], BLAKE2B_OUTBYTES)) { + if (0 != memcmp(hash, _cryptonite_blake2b_keyed_kat[i], BLAKE2B_OUTBYTES)) { goto fail; } } diff --git a/cbits/blake2/sse/blake2.h b/cbits/blake2/sse/blake2.h index ad62f26..d69b087 100644 --- a/cbits/blake2/sse/blake2.h +++ b/cbits/blake2/sse/blake2.h @@ -142,51 +142,51 @@ extern "C" { }; /* Streaming API */ - int blake2s_init( blake2s_state *S, size_t outlen ); - int blake2s_init_key( blake2s_state *S, size_t outlen, const void *key, size_t keylen ); - int blake2s_init_param( blake2s_state *S, const blake2s_param *P ); - int blake2s_update( blake2s_state *S, const void *in, size_t inlen ); - int blake2s_final( blake2s_state *S, void *out, size_t outlen ); + int _cryptonite_blake2s_init( blake2s_state *S, size_t outlen ); + int _cryptonite_blake2s_init_key( blake2s_state *S, size_t outlen, const void *key, size_t keylen ); + int _cryptonite_blake2s_init_param( blake2s_state *S, const blake2s_param *P ); + int _cryptonite_blake2s_update( blake2s_state *S, const void *in, size_t inlen ); + int _cryptonite_blake2s_final( blake2s_state *S, void *out, size_t outlen ); - int blake2b_init( blake2b_state *S, size_t outlen ); - int blake2b_init_key( blake2b_state *S, size_t outlen, const void *key, size_t keylen ); - int blake2b_init_param( blake2b_state *S, const blake2b_param *P ); - int blake2b_update( blake2b_state *S, const void *in, size_t inlen ); - int blake2b_final( blake2b_state *S, void *out, size_t outlen ); + int _cryptonite_blake2b_init( blake2b_state *S, size_t outlen ); + int _cryptonite_blake2b_init_key( blake2b_state *S, size_t outlen, const void *key, size_t keylen ); + int _cryptonite_blake2b_init_param( blake2b_state *S, const blake2b_param *P ); + int _cryptonite_blake2b_update( blake2b_state *S, const void *in, size_t inlen ); + int _cryptonite_blake2b_final( blake2b_state *S, void *out, size_t outlen ); - int blake2sp_init( blake2sp_state *S, size_t outlen ); - int blake2sp_init_key( blake2sp_state *S, size_t outlen, const void *key, size_t keylen ); - int blake2sp_update( blake2sp_state *S, const void *in, size_t inlen ); - int blake2sp_final( blake2sp_state *S, void *out, size_t outlen ); + int _cryptonite_blake2sp_init( blake2sp_state *S, size_t outlen ); + int _cryptonite_blake2sp_init_key( blake2sp_state *S, size_t outlen, const void *key, size_t keylen ); + int _cryptonite_blake2sp_update( blake2sp_state *S, const void *in, size_t inlen ); + int _cryptonite_blake2sp_final( blake2sp_state *S, void *out, size_t outlen ); - int blake2bp_init( blake2bp_state *S, size_t outlen ); - int blake2bp_init_key( blake2bp_state *S, size_t outlen, const void *key, size_t keylen ); - int blake2bp_update( blake2bp_state *S, const void *in, size_t inlen ); - int blake2bp_final( blake2bp_state *S, void *out, size_t outlen ); + int _cryptonite_blake2bp_init( blake2bp_state *S, size_t outlen ); + int _cryptonite_blake2bp_init_key( blake2bp_state *S, size_t outlen, const void *key, size_t keylen ); + int _cryptonite_blake2bp_update( blake2bp_state *S, const void *in, size_t inlen ); + int _cryptonite_blake2bp_final( blake2bp_state *S, void *out, size_t outlen ); /* Variable output length API */ - int blake2xs_init( blake2xs_state *S, const size_t outlen ); - int blake2xs_init_key( blake2xs_state *S, const size_t outlen, const void *key, size_t keylen ); - int blake2xs_update( blake2xs_state *S, const void *in, size_t inlen ); - int blake2xs_final(blake2xs_state *S, void *out, size_t outlen); + int _cryptonite_blake2xs_init( blake2xs_state *S, const size_t outlen ); + int _cryptonite_blake2xs_init_key( blake2xs_state *S, const size_t outlen, const void *key, size_t keylen ); + int _cryptonite_blake2xs_update( blake2xs_state *S, const void *in, size_t inlen ); + int _cryptonite_blake2xs_final(blake2xs_state *S, void *out, size_t outlen); - int blake2xb_init( blake2xb_state *S, const size_t outlen ); - int blake2xb_init_key( 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); + int _cryptonite_blake2xb_init( blake2xb_state *S, const size_t outlen ); + int _cryptonite_blake2xb_init_key( blake2xb_state *S, const size_t outlen, const void *key, size_t keylen ); + int _cryptonite_blake2xb_update( blake2xb_state *S, const void *in, size_t inlen ); + int _cryptonite_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 ); - int blake2b( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen ); + int _cryptonite_blake2s( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen ); + int _cryptonite_blake2b( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen ); - 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 _cryptonite_blake2sp( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen ); + int _cryptonite_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 ); + int _cryptonite_blake2xs( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen ); + int _cryptonite_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 ); + int _cryptonite_blake2( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen ); #if defined(__cplusplus) } diff --git a/cbits/blake2/sse/blake2b.c b/cbits/blake2/sse/blake2b.c index c8c1c5f..3df0c8d 100644 --- a/cbits/blake2/sse/blake2b.c +++ b/cbits/blake2/sse/blake2b.c @@ -142,7 +142,7 @@ int blake2b_init_key( blake2b_state *S, size_t outlen, const void *key, size_t k uint8_t block[BLAKE2B_BLOCKBYTES]; memset( block, 0, BLAKE2B_BLOCKBYTES ); memcpy( block, key, keylen ); - blake2b_update( S, block, BLAKE2B_BLOCKBYTES ); + _cryptonite_blake2b_update( S, block, BLAKE2B_BLOCKBYTES ); secure_zero_memory( block, BLAKE2B_BLOCKBYTES ); /* Burn the key from stack */ } return 0; diff --git a/cbits/blake2/sse/blake2bp.c b/cbits/blake2/sse/blake2bp.c index 3eb95d0..b51edb4 100644 --- a/cbits/blake2/sse/blake2bp.c +++ b/cbits/blake2/sse/blake2bp.c @@ -36,7 +36,7 @@ */ static int blake2bp_init_leaf_param( blake2b_state *S, const blake2b_param *P ) { - int err = blake2b_init_param(S, P); + int err = _cryptonite_blake2b_init_param(S, P); S->outlen = P->inner_length; return err; } @@ -74,11 +74,11 @@ static int blake2bp_init_root( blake2b_state *S, size_t outlen, size_t keylen ) memset( P->reserved, 0, sizeof( P->reserved ) ); memset( P->salt, 0, sizeof( P->salt ) ); memset( P->personal, 0, sizeof( P->personal ) ); - return blake2b_init_param( S, P ); + return _cryptonite_blake2b_init_param( S, P ); } -int blake2bp_init( blake2bp_state *S, size_t outlen ) +int _cryptonite_blake2bp_init( blake2bp_state *S, size_t outlen ) { size_t i; if( !outlen || outlen > BLAKE2B_OUTBYTES ) return -1; @@ -98,7 +98,7 @@ int blake2bp_init( blake2bp_state *S, size_t outlen ) return 0; } -int blake2bp_init_key( blake2bp_state *S, size_t outlen, const void *key, size_t keylen ) +int _cryptonite_blake2bp_init_key( blake2bp_state *S, size_t outlen, const void *key, size_t keylen ) { size_t i; @@ -124,7 +124,7 @@ int blake2bp_init_key( blake2bp_state *S, size_t outlen, const void *key, size_t memcpy( block, key, keylen ); for( i = 0; i < PARALLELISM_DEGREE; ++i ) - blake2b_update( S->S[i], block, BLAKE2B_BLOCKBYTES ); + _cryptonite_blake2b_update( S->S[i], block, BLAKE2B_BLOCKBYTES ); secure_zero_memory( block, BLAKE2B_BLOCKBYTES ); /* Burn the key from stack */ } @@ -132,7 +132,7 @@ int blake2bp_init_key( blake2bp_state *S, size_t outlen, const void *key, size_t } -int blake2bp_update( blake2bp_state *S, const void *pin, size_t inlen ) +int _cryptonite_blake2bp_update( blake2bp_state *S, const void *pin, size_t inlen ) { const unsigned char * in = (const unsigned char *)pin; size_t left = S->buflen; @@ -144,7 +144,7 @@ int blake2bp_update( blake2bp_state *S, const void *pin, size_t inlen ) memcpy( S->buf + left, in, fill ); for( i = 0; i < PARALLELISM_DEGREE; ++i ) - blake2b_update( S->S[i], S->buf + i * BLAKE2B_BLOCKBYTES, BLAKE2B_BLOCKBYTES ); + _cryptonite_blake2b_update( S->S[i], S->buf + i * BLAKE2B_BLOCKBYTES, BLAKE2B_BLOCKBYTES ); in += fill; inlen -= fill; @@ -167,7 +167,7 @@ int blake2bp_update( blake2bp_state *S, const void *pin, size_t inlen ) while( inlen__ >= PARALLELISM_DEGREE * BLAKE2B_BLOCKBYTES ) { - blake2b_update( S->S[i], in__, BLAKE2B_BLOCKBYTES ); + _cryptonite_blake2b_update( S->S[i], in__, BLAKE2B_BLOCKBYTES ); in__ += PARALLELISM_DEGREE * BLAKE2B_BLOCKBYTES; inlen__ -= PARALLELISM_DEGREE * BLAKE2B_BLOCKBYTES; } @@ -185,7 +185,7 @@ int blake2bp_update( blake2bp_state *S, const void *pin, size_t inlen ) -int blake2bp_final( blake2bp_state *S, void *out, size_t outlen ) +int _cryptonite_blake2bp_final( blake2bp_state *S, void *out, size_t outlen ) { uint8_t hash[PARALLELISM_DEGREE][BLAKE2B_OUTBYTES]; size_t i; @@ -202,19 +202,19 @@ int blake2bp_final( blake2bp_state *S, void *out, size_t outlen ) if( left > BLAKE2B_BLOCKBYTES ) left = BLAKE2B_BLOCKBYTES; - blake2b_update( S->S[i], S->buf + i * BLAKE2B_BLOCKBYTES, left ); + _cryptonite_blake2b_update( S->S[i], S->buf + i * BLAKE2B_BLOCKBYTES, left ); } - blake2b_final( S->S[i], hash[i], BLAKE2B_OUTBYTES ); + _cryptonite_blake2b_final( S->S[i], hash[i], BLAKE2B_OUTBYTES ); } for( i = 0; i < PARALLELISM_DEGREE; ++i ) - blake2b_update( S->R, hash[i], BLAKE2B_OUTBYTES ); + _cryptonite_blake2b_update( S->R, hash[i], BLAKE2B_OUTBYTES ); - return blake2b_final( S->R, out, S->outlen ); + return _cryptonite_blake2b_final( S->R, out, S->outlen ); } -int blake2bp( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen ) +int _cryptonite_blake2bp( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen ) { uint8_t hash[PARALLELISM_DEGREE][BLAKE2B_OUTBYTES]; blake2b_state S[PARALLELISM_DEGREE][1]; @@ -244,7 +244,7 @@ int blake2bp( void *out, size_t outlen, const void *in, size_t inlen, const void memcpy( block, key, keylen ); for( i = 0; i < PARALLELISM_DEGREE; ++i ) - blake2b_update( S[i], block, BLAKE2B_BLOCKBYTES ); + _cryptonite_blake2b_update( S[i], block, BLAKE2B_BLOCKBYTES ); secure_zero_memory( block, BLAKE2B_BLOCKBYTES ); /* Burn the key from stack */ } @@ -265,7 +265,7 @@ int blake2bp( void *out, size_t outlen, const void *in, size_t inlen, const void while( inlen__ >= PARALLELISM_DEGREE * BLAKE2B_BLOCKBYTES ) { - blake2b_update( S[i], in__, BLAKE2B_BLOCKBYTES ); + _cryptonite_blake2b_update( S[i], in__, BLAKE2B_BLOCKBYTES ); in__ += PARALLELISM_DEGREE * BLAKE2B_BLOCKBYTES; inlen__ -= PARALLELISM_DEGREE * BLAKE2B_BLOCKBYTES; } @@ -274,10 +274,10 @@ int blake2bp( void *out, size_t outlen, const void *in, size_t inlen, const void { const size_t left = inlen__ - i * BLAKE2B_BLOCKBYTES; const size_t len = left <= BLAKE2B_BLOCKBYTES ? left : BLAKE2B_BLOCKBYTES; - blake2b_update( S[i], in__, len ); + _cryptonite_blake2b_update( S[i], in__, len ); } - blake2b_final( S[i], hash[i], BLAKE2B_OUTBYTES ); + _cryptonite_blake2b_final( S[i], hash[i], BLAKE2B_OUTBYTES ); } if( blake2bp_init_root( FS, outlen, keylen ) < 0 ) @@ -286,9 +286,9 @@ int blake2bp( void *out, size_t outlen, const void *in, size_t inlen, const void FS->last_node = 1; /* Mark as last node */ for( i = 0; i < PARALLELISM_DEGREE; ++i ) - blake2b_update( FS, hash[i], BLAKE2B_OUTBYTES ); + _cryptonite_blake2b_update( FS, hash[i], BLAKE2B_OUTBYTES ); - return blake2b_final( FS, out, outlen ); + return _cryptonite_blake2b_final( FS, out, outlen ); } @@ -311,7 +311,7 @@ int main( void ) for( i = 0; i < BLAKE2_KAT_LENGTH; ++i ) { uint8_t hash[BLAKE2B_OUTBYTES]; - blake2bp( hash, BLAKE2B_OUTBYTES, buf, i, key, BLAKE2B_KEYBYTES ); + _cryptonite_blake2bp( hash, BLAKE2B_OUTBYTES, buf, i, key, BLAKE2B_KEYBYTES ); if( 0 != memcmp( hash, blake2bp_keyed_kat[i], BLAKE2B_OUTBYTES ) ) { @@ -328,21 +328,21 @@ int main( void ) size_t mlen = i; int err = 0; - if( (err = blake2bp_init_key(&S, BLAKE2B_OUTBYTES, key, BLAKE2B_KEYBYTES)) < 0 ) { + if( (err = _cryptonite_blake2bp_init_key(&S, BLAKE2B_OUTBYTES, key, BLAKE2B_KEYBYTES)) < 0 ) { goto fail; } while (mlen >= step) { - if ( (err = blake2bp_update(&S, p, step)) < 0 ) { + if ( (err = _cryptonite_blake2bp_update(&S, p, step)) < 0 ) { goto fail; } mlen -= step; p += step; } - if ( (err = blake2bp_update(&S, p, mlen)) < 0) { + if ( (err = _cryptonite_blake2bp_update(&S, p, mlen)) < 0) { goto fail; } - if ( (err = blake2bp_final(&S, hash, BLAKE2B_OUTBYTES)) < 0) { + if ( (err = _cryptonite_blake2bp_final(&S, hash, BLAKE2B_OUTBYTES)) < 0) { goto fail; } diff --git a/cbits/blake2/sse/blake2s.c b/cbits/blake2/sse/blake2s.c index 569c210..df636a3 100644 --- a/cbits/blake2/sse/blake2s.c +++ b/cbits/blake2/sse/blake2s.c @@ -143,7 +143,7 @@ int blake2s_init_key( blake2s_state *S, size_t outlen, const void *key, size_t k uint8_t block[BLAKE2S_BLOCKBYTES]; memset( block, 0, BLAKE2S_BLOCKBYTES ); memcpy( block, key, keylen ); - blake2s_update( S, block, BLAKE2S_BLOCKBYTES ); + _cryptonite_blake2s_update( S, block, BLAKE2S_BLOCKBYTES ); secure_zero_memory( block, BLAKE2S_BLOCKBYTES ); /* Burn the key from stack */ } return 0; @@ -206,7 +206,7 @@ static void blake2s_compress( blake2s_state *S, const uint8_t block[BLAKE2S_BLOC STOREU( &S->h[4], _mm_xor_si128( ff1, _mm_xor_si128( row2, row4 ) ) ); } -int blake2s_update( blake2s_state *S, const void *pin, size_t inlen ) +int _cryptonite_blake2s_update( blake2s_state *S, const void *pin, size_t inlen ) { const unsigned char * in = (const unsigned char *)pin; if( inlen > 0 ) @@ -282,7 +282,7 @@ int blake2s( void *out, size_t outlen, const void *in, size_t inlen, const void if( blake2s_init( S, outlen ) < 0 ) return -1; } - blake2s_update( S, ( const uint8_t * )in, inlen ); + _cryptonite_blake2s_update( S, ( const uint8_t * )in, inlen ); blake2s_final( S, out, outlen ); return 0; } @@ -335,13 +335,13 @@ int main( void ) } while (mlen >= step) { - if ( (err = blake2s_update(&S, p, step)) < 0 ) { + if ( (err = _cryptonite_blake2s_update(&S, p, step)) < 0 ) { goto fail; } mlen -= step; p += step; } - if ( (err = blake2s_update(&S, p, mlen)) < 0) { + if ( (err = _cryptonite_blake2s_update(&S, p, mlen)) < 0) { goto fail; } if ( (err = blake2s_final(&S, hash, BLAKE2S_OUTBYTES)) < 0) { diff --git a/cbits/blake2/sse/blake2sp.c b/cbits/blake2/sse/blake2sp.c index ed0e1ad..550c313 100644 --- a/cbits/blake2/sse/blake2sp.c +++ b/cbits/blake2/sse/blake2sp.c @@ -35,7 +35,7 @@ */ static int blake2sp_init_leaf_param( blake2s_state *S, const blake2s_param *P ) { - int err = blake2s_init_param(S, P); + int err = _cryptonite_blake2s_init_param(S, P); S->outlen = P->inner_length; return err; } @@ -71,11 +71,11 @@ static int blake2sp_init_root( blake2s_state *S, size_t outlen, size_t keylen ) P->inner_length = BLAKE2S_OUTBYTES; memset( P->salt, 0, sizeof( P->salt ) ); memset( P->personal, 0, sizeof( P->personal ) ); - return blake2s_init_param( S, P ); + return _cryptonite_blake2s_init_param( S, P ); } -int blake2sp_init( blake2sp_state *S, size_t outlen ) +int _cryptonite_blake2sp_init( blake2sp_state *S, size_t outlen ) { size_t i; @@ -96,7 +96,7 @@ int blake2sp_init( blake2sp_state *S, size_t outlen ) return 0; } -int blake2sp_init_key( blake2sp_state *S, size_t outlen, const void *key, size_t keylen ) +int _cryptonite_blake2sp_init_key( blake2sp_state *S, size_t outlen, const void *key, size_t keylen ) { size_t i; @@ -122,7 +122,7 @@ int blake2sp_init_key( blake2sp_state *S, size_t outlen, const void *key, size_t memcpy( block, key, keylen ); for( i = 0; i < PARALLELISM_DEGREE; ++i ) - blake2s_update( S->S[i], block, BLAKE2S_BLOCKBYTES ); + _cryptonite_blake2s_update( S->S[i], block, BLAKE2S_BLOCKBYTES ); secure_zero_memory( block, BLAKE2S_BLOCKBYTES ); /* Burn the key from stack */ } @@ -130,7 +130,7 @@ int blake2sp_init_key( blake2sp_state *S, size_t outlen, const void *key, size_t } -int blake2sp_update( blake2sp_state *S, const void *pin, size_t inlen ) +int _cryptonite_blake2sp_update( blake2sp_state *S, const void *pin, size_t inlen ) { const unsigned char * in = (const unsigned char *)pin; size_t left = S->buflen; @@ -142,7 +142,7 @@ int blake2sp_update( blake2sp_state *S, const void *pin, size_t inlen ) memcpy( S->buf + left, in, fill ); for( i = 0; i < PARALLELISM_DEGREE; ++i ) - blake2s_update( S->S[i], S->buf + i * BLAKE2S_BLOCKBYTES, BLAKE2S_BLOCKBYTES ); + _cryptonite_blake2s_update( S->S[i], S->buf + i * BLAKE2S_BLOCKBYTES, BLAKE2S_BLOCKBYTES ); in += fill; inlen -= fill; @@ -165,7 +165,7 @@ int blake2sp_update( blake2sp_state *S, const void *pin, size_t inlen ) while( inlen__ >= PARALLELISM_DEGREE * BLAKE2S_BLOCKBYTES ) { - blake2s_update( S->S[i], in__, BLAKE2S_BLOCKBYTES ); + _cryptonite_blake2s_update( S->S[i], in__, BLAKE2S_BLOCKBYTES ); in__ += PARALLELISM_DEGREE * BLAKE2S_BLOCKBYTES; inlen__ -= PARALLELISM_DEGREE * BLAKE2S_BLOCKBYTES; } @@ -182,7 +182,7 @@ int blake2sp_update( blake2sp_state *S, const void *pin, size_t inlen ) } -int blake2sp_final( blake2sp_state *S, void *out, size_t outlen ) +int _cryptonite_blake2sp_final( blake2sp_state *S, void *out, size_t outlen ) { uint8_t hash[PARALLELISM_DEGREE][BLAKE2S_OUTBYTES]; size_t i; @@ -199,20 +199,20 @@ int blake2sp_final( blake2sp_state *S, void *out, size_t outlen ) if( left > BLAKE2S_BLOCKBYTES ) left = BLAKE2S_BLOCKBYTES; - blake2s_update( S->S[i], S->buf + i * BLAKE2S_BLOCKBYTES, left ); + _cryptonite_blake2s_update( S->S[i], S->buf + i * BLAKE2S_BLOCKBYTES, left ); } - blake2s_final( S->S[i], hash[i], BLAKE2S_OUTBYTES ); + _cryptonite_blake2s_final( S->S[i], hash[i], BLAKE2S_OUTBYTES ); } for( i = 0; i < PARALLELISM_DEGREE; ++i ) - blake2s_update( S->R, hash[i], BLAKE2S_OUTBYTES ); + _cryptonite_blake2s_update( S->R, hash[i], BLAKE2S_OUTBYTES ); - return blake2s_final( S->R, out, S->outlen ); + return _cryptonite_blake2s_final( S->R, out, S->outlen ); } -int blake2sp( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen ) +int _cryptonite_blake2sp( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen ) { uint8_t hash[PARALLELISM_DEGREE][BLAKE2S_OUTBYTES]; blake2s_state S[PARALLELISM_DEGREE][1]; @@ -242,7 +242,7 @@ int blake2sp( void *out, size_t outlen, const void *in, size_t inlen, const void memcpy( block, key, keylen ); for( i = 0; i < PARALLELISM_DEGREE; ++i ) - blake2s_update( S[i], block, BLAKE2S_BLOCKBYTES ); + _cryptonite_blake2s_update( S[i], block, BLAKE2S_BLOCKBYTES ); secure_zero_memory( block, BLAKE2S_BLOCKBYTES ); /* Burn the key from stack */ } @@ -263,7 +263,7 @@ int blake2sp( void *out, size_t outlen, const void *in, size_t inlen, const void while( inlen__ >= PARALLELISM_DEGREE * BLAKE2S_BLOCKBYTES ) { - blake2s_update( S[i], in__, BLAKE2S_BLOCKBYTES ); + _cryptonite_blake2s_update( S[i], in__, BLAKE2S_BLOCKBYTES ); in__ += PARALLELISM_DEGREE * BLAKE2S_BLOCKBYTES; inlen__ -= PARALLELISM_DEGREE * BLAKE2S_BLOCKBYTES; } @@ -272,10 +272,10 @@ int blake2sp( void *out, size_t outlen, const void *in, size_t inlen, const void { const size_t left = inlen__ - i * BLAKE2S_BLOCKBYTES; const size_t len = left <= BLAKE2S_BLOCKBYTES ? left : BLAKE2S_BLOCKBYTES; - blake2s_update( S[i], in__, len ); + _cryptonite_blake2s_update( S[i], in__, len ); } - blake2s_final( S[i], hash[i], BLAKE2S_OUTBYTES ); + _cryptonite_blake2s_final( S[i], hash[i], BLAKE2S_OUTBYTES ); } if( blake2sp_init_root( FS, outlen, keylen ) < 0 ) @@ -284,9 +284,9 @@ int blake2sp( void *out, size_t outlen, const void *in, size_t inlen, const void FS->last_node = 1; for( i = 0; i < PARALLELISM_DEGREE; ++i ) - blake2s_update( FS, hash[i], BLAKE2S_OUTBYTES ); + _cryptonite_blake2s_update( FS, hash[i], BLAKE2S_OUTBYTES ); - return blake2s_final( FS, out, outlen ); + return _cryptonite_blake2s_final( FS, out, outlen ); } #if defined(BLAKE2SP_SELFTEST) @@ -308,7 +308,7 @@ int main( void ) for( i = 0; i < BLAKE2_KAT_LENGTH; ++i ) { uint8_t hash[BLAKE2S_OUTBYTES]; - blake2sp( hash, BLAKE2S_OUTBYTES, buf, i, key, BLAKE2S_KEYBYTES ); + _cryptonite_blake2sp( hash, BLAKE2S_OUTBYTES, buf, i, key, BLAKE2S_KEYBYTES ); if( 0 != memcmp( hash, blake2sp_keyed_kat[i], BLAKE2S_OUTBYTES ) ) { @@ -325,21 +325,21 @@ int main( void ) size_t mlen = i; int err = 0; - if( (err = blake2sp_init_key(&S, BLAKE2S_OUTBYTES, key, BLAKE2S_KEYBYTES)) < 0 ) { + if( (err = _cryptonite_blake2sp_init_key(&S, BLAKE2S_OUTBYTES, key, BLAKE2S_KEYBYTES)) < 0 ) { goto fail; } while (mlen >= step) { - if ( (err = blake2sp_update(&S, p, step)) < 0 ) { + if ( (err = _cryptonite_blake2sp_update(&S, p, step)) < 0 ) { goto fail; } mlen -= step; p += step; } - if ( (err = blake2sp_update(&S, p, mlen)) < 0) { + if ( (err = _cryptonite_blake2sp_update(&S, p, mlen)) < 0) { goto fail; } - if ( (err = blake2sp_final(&S, hash, BLAKE2S_OUTBYTES)) < 0) { + if ( (err = _cryptonite_blake2sp_final(&S, hash, BLAKE2S_OUTBYTES)) < 0) { goto fail; } diff --git a/cbits/blake2/sse/blake2xb.c b/cbits/blake2/sse/blake2xb.c index 2da56ae..07df9be 100644 --- a/cbits/blake2/sse/blake2xb.c +++ b/cbits/blake2/sse/blake2xb.c @@ -23,11 +23,11 @@ #include "blake2.h" #include "blake2-impl.h" -int blake2xb_init( blake2xb_state *S, const size_t outlen ) { - return blake2xb_init_key(S, outlen, NULL, 0); +int _cryptonite_blake2xb_init( blake2xb_state *S, const size_t outlen ) { + return _cryptonite_blake2xb_init_key(S, outlen, NULL, 0); } -int blake2xb_init_key( blake2xb_state *S, const size_t outlen, const void *key, size_t keylen) +int _cryptonite_blake2xb_init_key( blake2xb_state *S, const size_t outlen, const void *key, size_t keylen) { if ( outlen == 0 || outlen > 0xFFFFFFFFUL ) { return -1; @@ -55,7 +55,7 @@ int blake2xb_init_key( blake2xb_state *S, const size_t outlen, const void *key, memset( S->P->salt, 0, sizeof( S->P->salt ) ); memset( S->P->personal, 0, sizeof( S->P->personal ) ); - if( blake2b_init_param( S->S, S->P ) < 0 ) { + if( _cryptonite_blake2b_init_param( S->S, S->P ) < 0 ) { return -1; } @@ -63,17 +63,17 @@ int blake2xb_init_key( blake2xb_state *S, const size_t outlen, const void *key, uint8_t block[BLAKE2B_BLOCKBYTES]; memset(block, 0, BLAKE2B_BLOCKBYTES); memcpy(block, key, keylen); - blake2b_update(S->S, block, BLAKE2B_BLOCKBYTES); + _cryptonite_blake2b_update(S->S, block, BLAKE2B_BLOCKBYTES); secure_zero_memory(block, BLAKE2B_BLOCKBYTES); } return 0; } -int blake2xb_update( blake2xb_state *S, const void *in, size_t inlen ) { - return blake2b_update( S->S, in, inlen ); +int _cryptonite_blake2xb_update( blake2xb_state *S, const void *in, size_t inlen ) { + return _cryptonite_blake2b_update( S->S, in, inlen ); } -int blake2xb_final( blake2xb_state *S, void *out, size_t outlen) { +int _cryptonite_blake2xb_final( blake2xb_state *S, void *out, size_t outlen) { blake2b_state C[1]; blake2b_param P[1]; @@ -98,7 +98,7 @@ int blake2xb_final( blake2xb_state *S, void *out, size_t outlen) { } /* Finalize the root hash */ - if (blake2b_final(S->S, root, BLAKE2B_OUTBYTES) < 0) { + if (_cryptonite_blake2b_final(S->S, root, BLAKE2B_OUTBYTES) < 0) { return -1; } @@ -117,10 +117,10 @@ int blake2xb_final( blake2xb_state *S, void *out, size_t outlen) { /* Initialize state */ P->digest_length = block_size; store32(&P->node_offset, i); - blake2b_init_param(C, P); + _cryptonite_blake2b_init_param(C, P); /* Process key if needed */ - blake2b_update(C, root, BLAKE2B_OUTBYTES); - if (blake2b_final(C, (uint8_t *)out + i * BLAKE2B_OUTBYTES, block_size) < 0 ) { + _cryptonite_blake2b_update(C, root, BLAKE2B_OUTBYTES); + if (_cryptonite_blake2b_final(C, (uint8_t *)out + i * BLAKE2B_OUTBYTES, block_size) < 0 ) { return -1; } outlen -= block_size; @@ -133,7 +133,7 @@ int blake2xb_final( blake2xb_state *S, void *out, size_t outlen) { } -int blake2xb(void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen) +int _cryptonite_blake2xb(void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen) { blake2xb_state S[1]; @@ -154,15 +154,15 @@ int blake2xb(void *out, size_t outlen, const void *in, size_t inlen, const void return -1; /* Initialize the root block structure */ - if (blake2xb_init_key(S, outlen, key, keylen) < 0) { + if (_cryptonite_blake2xb_init_key(S, outlen, key, keylen) < 0) { return -1; } /* Absorb the input message */ - blake2xb_update(S, in, inlen); + _cryptonite_blake2xb_update(S, in, inlen); /* Compute the root node of the tree and the final hash using the counter construction */ - return blake2xb_final(S, out, outlen); + return _cryptonite_blake2xb_final(S, out, outlen); } #if defined(BLAKE2XB_SELFTEST) @@ -189,7 +189,7 @@ int main( void ) for( outlen = 1; outlen <= BLAKE2_KAT_LENGTH; ++outlen ) { uint8_t hash[BLAKE2_KAT_LENGTH] = {0}; - if( blake2xb( hash, outlen, buf, BLAKE2_KAT_LENGTH, key, BLAKE2B_KEYBYTES ) < 0 ) { + if( _cryptonite_blake2xb( hash, outlen, buf, BLAKE2_KAT_LENGTH, key, BLAKE2B_KEYBYTES ) < 0 ) { goto fail; } @@ -208,21 +208,21 @@ int main( void ) size_t mlen = BLAKE2_KAT_LENGTH; int err = 0; - if( (err = blake2xb_init_key(&S, outlen, key, BLAKE2B_KEYBYTES)) < 0 ) { + if( (err = _cryptonite_blake2xb_init_key(&S, outlen, key, BLAKE2B_KEYBYTES)) < 0 ) { goto fail; } while (mlen >= step) { - if ( (err = blake2xb_update(&S, p, step)) < 0 ) { + if ( (err = _cryptonite_blake2xb_update(&S, p, step)) < 0 ) { goto fail; } mlen -= step; p += step; } - if ( (err = blake2xb_update(&S, p, mlen)) < 0) { + if ( (err = _cryptonite_blake2xb_update(&S, p, mlen)) < 0) { goto fail; } - if ( (err = blake2xb_final(&S, hash, outlen)) < 0) { + if ( (err = _cryptonite_blake2xb_final(&S, hash, outlen)) < 0) { goto fail; } diff --git a/cbits/blake2/sse/blake2xs.c b/cbits/blake2/sse/blake2xs.c index 625693e..8b6951c 100644 --- a/cbits/blake2/sse/blake2xs.c +++ b/cbits/blake2/sse/blake2xs.c @@ -23,11 +23,11 @@ #include "blake2.h" #include "blake2-impl.h" -int blake2xs_init( blake2xs_state *S, const size_t outlen ) { - return blake2xs_init_key(S, outlen, NULL, 0); +int _cryptonite_blake2xs_init( blake2xs_state *S, const size_t outlen ) { + return _cryptonite_blake2xs_init_key(S, outlen, NULL, 0); } -int blake2xs_init_key( blake2xs_state *S, const size_t outlen, const void *key, size_t keylen ) +int _cryptonite_blake2xs_init_key( blake2xs_state *S, const size_t outlen, const void *key, size_t keylen ) { if ( outlen == 0 || outlen > 0xFFFFUL ) { return -1; @@ -54,7 +54,7 @@ int blake2xs_init_key( blake2xs_state *S, const size_t outlen, const void *key, memset( S->P->salt, 0, sizeof( S->P->salt ) ); memset( S->P->personal, 0, sizeof( S->P->personal ) ); - if( blake2s_init_param( S->S, S->P ) < 0 ) { + if( _cryptonite_blake2s_init_param( S->S, S->P ) < 0 ) { return -1; } @@ -62,17 +62,17 @@ int blake2xs_init_key( blake2xs_state *S, const size_t outlen, const void *key, uint8_t block[BLAKE2S_BLOCKBYTES]; memset(block, 0, BLAKE2S_BLOCKBYTES); memcpy(block, key, keylen); - blake2s_update(S->S, block, BLAKE2S_BLOCKBYTES); + _cryptonite_blake2s_update(S->S, block, BLAKE2S_BLOCKBYTES); secure_zero_memory(block, BLAKE2S_BLOCKBYTES); } return 0; } -int blake2xs_update( blake2xs_state *S, const void *in, size_t inlen ) { - return blake2s_update( S->S, in, inlen ); +int _cryptonite_blake2xs_update( blake2xs_state *S, const void *in, size_t inlen ) { + return _cryptonite_blake2s_update( S->S, in, inlen ); } -int blake2xs_final(blake2xs_state *S, void *out, size_t outlen) { +int _cryptonite_blake2xs_final(blake2xs_state *S, void *out, size_t outlen) { blake2s_state C[1]; blake2s_param P[1]; @@ -97,7 +97,7 @@ int blake2xs_final(blake2xs_state *S, void *out, size_t outlen) { } /* Finalize the root hash */ - if (blake2s_final(S->S, root, BLAKE2S_OUTBYTES) < 0) { + if (_cryptonite_blake2s_final(S->S, root, BLAKE2S_OUTBYTES) < 0) { return -1; } @@ -116,10 +116,10 @@ int blake2xs_final(blake2xs_state *S, void *out, size_t outlen) { /* Initialize state */ P->digest_length = block_size; store32(&P->node_offset, i); - blake2s_init_param(C, P); + _cryptonite_blake2s_init_param(C, P); /* Process key if needed */ - blake2s_update(C, root, BLAKE2S_OUTBYTES); - if (blake2s_final(C, (uint8_t *)out + i * BLAKE2S_OUTBYTES, block_size) < 0) { + _cryptonite_blake2s_update(C, root, BLAKE2S_OUTBYTES); + if (_cryptonite_blake2s_final(C, (uint8_t *)out + i * BLAKE2S_OUTBYTES, block_size) < 0) { return -1; } outlen -= block_size; @@ -131,7 +131,7 @@ int blake2xs_final(blake2xs_state *S, void *out, size_t outlen) { return 0; } -int blake2xs(void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen) +int _cryptonite_blake2xs(void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen) { blake2xs_state S[1]; @@ -152,15 +152,15 @@ int blake2xs(void *out, size_t outlen, const void *in, size_t inlen, const void return -1; /* Initialize the root block structure */ - if (blake2xs_init_key(S, outlen, key, keylen) < 0) { + if (_cryptonite_blake2xs_init_key(S, outlen, key, keylen) < 0) { return -1; } /* Absorb the input message */ - blake2xs_update(S, in, inlen); + _cryptonite_blake2xs_update(S, in, inlen); /* Compute the root node of the tree and the final hash using the counter construction */ - return blake2xs_final(S, out, outlen); + return _cryptonite_blake2xs_final(S, out, outlen); } #if defined(BLAKE2XS_SELFTEST) @@ -187,7 +187,7 @@ int main( void ) for( outlen = 1; outlen <= BLAKE2_KAT_LENGTH; ++outlen ) { uint8_t hash[BLAKE2_KAT_LENGTH] = {0}; - if( blake2xs( hash, outlen, buf, BLAKE2_KAT_LENGTH, key, BLAKE2S_KEYBYTES ) < 0 ) { + if( _cryptonite_blake2xs( hash, outlen, buf, BLAKE2_KAT_LENGTH, key, BLAKE2S_KEYBYTES ) < 0 ) { goto fail; } @@ -206,21 +206,21 @@ int main( void ) size_t mlen = BLAKE2_KAT_LENGTH; int err = 0; - if( (err = blake2xs_init_key(&S, outlen, key, BLAKE2S_KEYBYTES)) < 0 ) { + if( (err = _cryptonite_blake2xs_init_key(&S, outlen, key, BLAKE2S_KEYBYTES)) < 0 ) { goto fail; } while (mlen >= step) { - if ( (err = blake2xs_update(&S, p, step)) < 0 ) { + if ( (err = _cryptonite_blake2xs_update(&S, p, step)) < 0 ) { goto fail; } mlen -= step; p += step; } - if ( (err = blake2xs_update(&S, p, mlen)) < 0) { + if ( (err = _cryptonite_blake2xs_update(&S, p, mlen)) < 0) { goto fail; } - if ( (err = blake2xs_final(&S, hash, outlen)) < 0) { + if ( (err = _cryptonite_blake2xs_final(&S, hash, outlen)) < 0) { goto fail; } diff --git a/cbits/cryptonite_blake2b.c b/cbits/cryptonite_blake2b.c index dbaff93..6dd3722 100644 --- a/cbits/cryptonite_blake2b.c +++ b/cbits/cryptonite_blake2b.c @@ -2,15 +2,15 @@ void cryptonite_blake2b_init(blake2b_ctx *ctx, uint32_t hashlen) { - blake2b_init(ctx, hashlen / 8); + _cryptonite_blake2b_init(ctx, hashlen / 8); } void cryptonite_blake2b_update(blake2b_ctx *ctx, const uint8_t *data, uint32_t len) { - blake2b_update(ctx, data, len); + _cryptonite_blake2b_update(ctx, data, len); } void cryptonite_blake2b_finalize(blake2b_ctx *ctx, uint32_t hashlen, uint8_t *out) { - blake2b_final(ctx, out, hashlen / 8); + _cryptonite_blake2b_final(ctx, out, hashlen / 8); } diff --git a/cbits/cryptonite_blake2bp.c b/cbits/cryptonite_blake2bp.c index ce565f5..e4d7531 100644 --- a/cbits/cryptonite_blake2bp.c +++ b/cbits/cryptonite_blake2bp.c @@ -2,15 +2,15 @@ void cryptonite_blake2bp_init(blake2bp_ctx *ctx, uint32_t hashlen) { - blake2bp_init(ctx, hashlen / 8); + _cryptonite_blake2bp_init(ctx, hashlen / 8); } void cryptonite_blake2bp_update(blake2bp_ctx *ctx, const uint8_t *data, uint32_t len) { - blake2bp_update(ctx, data, len); + _cryptonite_blake2bp_update(ctx, data, len); } void cryptonite_blake2bp_finalize(blake2bp_ctx *ctx, uint32_t hashlen, uint8_t *out) { - blake2bp_final(ctx, out, hashlen / 8); + _cryptonite_blake2bp_final(ctx, out, hashlen / 8); } diff --git a/cbits/cryptonite_blake2s.c b/cbits/cryptonite_blake2s.c index 0f85a57..8076a13 100644 --- a/cbits/cryptonite_blake2s.c +++ b/cbits/cryptonite_blake2s.c @@ -2,15 +2,15 @@ void cryptonite_blake2s_init(blake2s_ctx *ctx, uint32_t hashlen) { - blake2s_init(ctx, hashlen / 8); + _cryptonite_blake2s_init(ctx, hashlen / 8); } void cryptonite_blake2s_update(blake2s_ctx *ctx, const uint8_t *data, uint32_t len) { - blake2s_update(ctx, data, len); + _cryptonite_blake2s_update(ctx, data, len); } void cryptonite_blake2s_finalize(blake2s_ctx *ctx, uint32_t hashlen, uint8_t *out) { - blake2s_final(ctx, out, hashlen / 8); + _cryptonite_blake2s_final(ctx, out, hashlen / 8); } diff --git a/cbits/cryptonite_blake2sp.c b/cbits/cryptonite_blake2sp.c index 8791473..7a125d5 100644 --- a/cbits/cryptonite_blake2sp.c +++ b/cbits/cryptonite_blake2sp.c @@ -2,15 +2,15 @@ void cryptonite_blake2sp_init(blake2sp_ctx *ctx, uint32_t hashlen) { - blake2sp_init(ctx, hashlen / 8); + _cryptonite_blake2sp_init(ctx, hashlen / 8); } void cryptonite_blake2sp_update(blake2sp_ctx *ctx, const uint8_t *data, uint32_t len) { - blake2sp_update(ctx, data, len); + _cryptonite_blake2sp_update(ctx, data, len); } void cryptonite_blake2sp_finalize(blake2sp_ctx *ctx, uint32_t hashlen, uint8_t *out) { - blake2sp_final(ctx, out, hashlen / 8); + _cryptonite_blake2sp_final(ctx, out, hashlen / 8); } From 93f50b49b7d67f7579b03f71242be9d23bfaa574 Mon Sep 17 00:00:00 2001 From: iquerejeta Date: Wed, 15 Sep 2021 12:28:06 +0100 Subject: [PATCH 05/12] ref folder changes, and minor sse --- cbits/blake2/ref/blake2.h | 2 +- cbits/blake2/ref/blake2b-ref.c | 32 +++++++++++------------ cbits/blake2/ref/blake2bp-ref.c | 44 +++++++++++++++---------------- cbits/blake2/ref/blake2s-ref.c | 38 +++++++++++++-------------- cbits/blake2/ref/blake2sp-ref.c | 46 ++++++++++++++++----------------- cbits/blake2/ref/blake2xb-ref.c | 42 +++++++++++++++--------------- cbits/blake2/ref/blake2xs-ref.c | 42 +++++++++++++++--------------- cbits/blake2/sse/blake2b.c | 38 +++++++++++++-------------- 8 files changed, 142 insertions(+), 142 deletions(-) diff --git a/cbits/blake2/ref/blake2.h b/cbits/blake2/ref/blake2.h index fd83b84..d69b087 100644 --- a/cbits/blake2/ref/blake2.h +++ b/cbits/blake2/ref/blake2.h @@ -148,7 +148,7 @@ extern "C" { int _cryptonite_blake2s_update( blake2s_state *S, const void *in, size_t inlen ); int _cryptonite_blake2s_final( blake2s_state *S, void *out, size_t outlen ); - int _cryptonite__cryptonite_blake2b_init( blake2b_state *S, size_t outlen ); + int _cryptonite_blake2b_init( blake2b_state *S, size_t outlen ); int _cryptonite_blake2b_init_key( blake2b_state *S, size_t outlen, const void *key, size_t keylen ); int _cryptonite_blake2b_init_param( blake2b_state *S, const blake2b_param *P ); int _cryptonite_blake2b_update( blake2b_state *S, const void *in, size_t inlen ); diff --git a/cbits/blake2/ref/blake2b-ref.c b/cbits/blake2/ref/blake2b-ref.c index c20924b..b6d30cf 100644 --- a/cbits/blake2/ref/blake2b-ref.c +++ b/cbits/blake2/ref/blake2b-ref.c @@ -45,31 +45,31 @@ static const uint8_t blake2b_sigma[12][16] = }; -static void _cryptonite_blake2b_set_lastnode( blake2b_state *S ) +static void blake2b_set_lastnode( blake2b_state *S ) { S->f[1] = (uint64_t)-1; } /* Some helper functions, not necessarily useful */ -static int _cryptonite_blake2b_is_lastblock( const blake2b_state *S ) +static int blake2b_is_lastblock( const blake2b_state *S ) { return S->f[0] != 0; } -static void _cryptonite_blake2b_set_lastblock( blake2b_state *S ) +static void blake2b_set_lastblock( blake2b_state *S ) { - if( S->last_node ) _cryptonite_blake2b_set_lastnode( S ); + if( S->last_node ) blake2b_set_lastnode( S ); S->f[0] = (uint64_t)-1; } -static void _cryptonite_blake2b_increment_counter( blake2b_state *S, const uint64_t inc ) +static void blake2b_increment_counter( blake2b_state *S, const uint64_t inc ) { S->t[0] += inc; S->t[1] += ( S->t[0] < inc ); } -static void _cryptonite_blake2b_init0( blake2b_state *S ) +static void blake2b_init0( blake2b_state *S ) { size_t i; memset( S, 0, sizeof( blake2b_state ) ); @@ -83,7 +83,7 @@ int _cryptonite_blake2b_init_param( blake2b_state *S, const blake2b_param *P ) const uint8_t *p = ( const uint8_t * )( P ); size_t i; - _cryptonite_blake2b_init0( S ); + blake2b_init0( S ); /* IV XOR ParamBlock */ for( i = 0; i < 8; ++i ) @@ -174,7 +174,7 @@ int _cryptonite_blake2b_init_key( blake2b_state *S, size_t outlen, const void *k G(r,7,v[ 3],v[ 4],v[ 9],v[14]); \ } while(0) -static void _cryptonite_blake2b_compress( blake2b_state *S, const uint8_t block[BLAKE2B_BLOCKBYTES] ) +static void blake2b_compress( blake2b_state *S, const uint8_t block[BLAKE2B_BLOCKBYTES] ) { uint64_t m[16]; uint64_t v[16]; @@ -229,12 +229,12 @@ int _cryptonite_blake2b_update( blake2b_state *S, const void *pin, size_t inlen { S->buflen = 0; memcpy( S->buf + left, in, fill ); /* Fill buffer */ - _cryptonite_blake2b_increment_counter( S, BLAKE2B_BLOCKBYTES ); - _cryptonite_blake2b_compress( S, S->buf ); /* Compress */ + blake2b_increment_counter( S, BLAKE2B_BLOCKBYTES ); + blake2b_compress( S, S->buf ); /* Compress */ in += fill; inlen -= fill; while(inlen > BLAKE2B_BLOCKBYTES) { - _cryptonite_blake2b_increment_counter(S, BLAKE2B_BLOCKBYTES); - _cryptonite_blake2b_compress( S, in ); + blake2b_increment_counter(S, BLAKE2B_BLOCKBYTES); + blake2b_compress( S, in ); in += BLAKE2B_BLOCKBYTES; inlen -= BLAKE2B_BLOCKBYTES; } @@ -253,13 +253,13 @@ int _cryptonite_blake2b_final( blake2b_state *S, void *out, size_t outlen ) if( out == NULL || outlen < S->outlen ) return -1; - if( _cryptonite_blake2b_is_lastblock( S ) ) + if( blake2b_is_lastblock( S ) ) return -1; - _cryptonite_blake2b_increment_counter( S, S->buflen ); - _cryptonite_blake2b_set_lastblock( S ); + blake2b_increment_counter( S, S->buflen ); + blake2b_set_lastblock( S ); memset( S->buf + S->buflen, 0, BLAKE2B_BLOCKBYTES - S->buflen ); /* Padding */ - _cryptonite_blake2b_compress( S, S->buf ); + blake2b_compress( S, S->buf ); for( i = 0; i < 8; ++i ) /* Output full hash to temp buffer */ store64( buffer + sizeof( S->h[i] ) * i, S->h[i] ); diff --git a/cbits/blake2/ref/blake2bp-ref.c b/cbits/blake2/ref/blake2bp-ref.c index d58a152..51f795e 100644 --- a/cbits/blake2/ref/blake2bp-ref.c +++ b/cbits/blake2/ref/blake2bp-ref.c @@ -78,7 +78,7 @@ static int blake2bp_init_root( blake2b_state *S, size_t outlen, size_t keylen ) } -int blake2bp_init( blake2bp_state *S, size_t outlen ) +int _cryptonite_blake2bp_init( blake2bp_state *S, size_t outlen ) { size_t i; @@ -99,7 +99,7 @@ int blake2bp_init( blake2bp_state *S, size_t outlen ) return 0; } -int blake2bp_init_key( blake2bp_state *S, size_t outlen, const void *key, size_t keylen ) +int _cryptonite_blake2bp_init_key( blake2bp_state *S, size_t outlen, const void *key, size_t keylen ) { size_t i; @@ -125,7 +125,7 @@ int blake2bp_init_key( blake2bp_state *S, size_t outlen, const void *key, size_t memcpy( block, key, keylen ); for( i = 0; i < PARALLELISM_DEGREE; ++i ) - blake2b_update( S->S[i], block, BLAKE2B_BLOCKBYTES ); + _cryptonite_blake2b_update( S->S[i], block, BLAKE2B_BLOCKBYTES ); secure_zero_memory( block, BLAKE2B_BLOCKBYTES ); /* Burn the key from stack */ } @@ -133,7 +133,7 @@ int blake2bp_init_key( blake2bp_state *S, size_t outlen, const void *key, size_t } -int blake2bp_update( blake2bp_state *S, const void *pin, size_t inlen ) +int _cryptonite_blake2bp_update( blake2bp_state *S, const void *pin, size_t inlen ) { const unsigned char * in = (const unsigned char *)pin; size_t left = S->buflen; @@ -145,7 +145,7 @@ int blake2bp_update( blake2bp_state *S, const void *pin, size_t inlen ) memcpy( S->buf + left, in, fill ); for( i = 0; i < PARALLELISM_DEGREE; ++i ) - blake2b_update( S->S[i], S->buf + i * BLAKE2B_BLOCKBYTES, BLAKE2B_BLOCKBYTES ); + _cryptonite_blake2b_update( S->S[i], S->buf + i * BLAKE2B_BLOCKBYTES, BLAKE2B_BLOCKBYTES ); in += fill; inlen -= fill; @@ -168,7 +168,7 @@ int blake2bp_update( blake2bp_state *S, const void *pin, size_t inlen ) while( inlen__ >= PARALLELISM_DEGREE * BLAKE2B_BLOCKBYTES ) { - blake2b_update( S->S[i], in__, BLAKE2B_BLOCKBYTES ); + _cryptonite_blake2b_update( S->S[i], in__, BLAKE2B_BLOCKBYTES ); in__ += PARALLELISM_DEGREE * BLAKE2B_BLOCKBYTES; inlen__ -= PARALLELISM_DEGREE * BLAKE2B_BLOCKBYTES; } @@ -184,7 +184,7 @@ int blake2bp_update( blake2bp_state *S, const void *pin, size_t inlen ) return 0; } -int blake2bp_final( blake2bp_state *S, void *out, size_t outlen ) +int _cryptonite_blake2bp_final( blake2bp_state *S, void *out, size_t outlen ) { uint8_t hash[PARALLELISM_DEGREE][BLAKE2B_OUTBYTES]; size_t i; @@ -201,19 +201,19 @@ int blake2bp_final( blake2bp_state *S, void *out, size_t outlen ) if( left > BLAKE2B_BLOCKBYTES ) left = BLAKE2B_BLOCKBYTES; - blake2b_update( S->S[i], S->buf + i * BLAKE2B_BLOCKBYTES, left ); + _cryptonite_blake2b_update( S->S[i], S->buf + i * BLAKE2B_BLOCKBYTES, left ); } - blake2b_final( S->S[i], hash[i], BLAKE2B_OUTBYTES ); + _cryptonite_blake2b_final( S->S[i], hash[i], BLAKE2B_OUTBYTES ); } for( i = 0; i < PARALLELISM_DEGREE; ++i ) - blake2b_update( S->R, hash[i], BLAKE2B_OUTBYTES ); + _cryptonite_blake2b_update( S->R, hash[i], BLAKE2B_OUTBYTES ); - return blake2b_final( S->R, out, S->outlen ); + return _cryptonite_blake2b_final( S->R, out, S->outlen ); } -int blake2bp( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen ) +int _cryptonite_blake2bp( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen ) { uint8_t hash[PARALLELISM_DEGREE][BLAKE2B_OUTBYTES]; blake2b_state S[PARALLELISM_DEGREE][1]; @@ -243,7 +243,7 @@ int blake2bp( void *out, size_t outlen, const void *in, size_t inlen, const void memcpy( block, key, keylen ); for( i = 0; i < PARALLELISM_DEGREE; ++i ) - blake2b_update( S[i], block, BLAKE2B_BLOCKBYTES ); + _cryptonite_blake2b_update( S[i], block, BLAKE2B_BLOCKBYTES ); secure_zero_memory( block, BLAKE2B_BLOCKBYTES ); /* Burn the key from stack */ } @@ -264,7 +264,7 @@ int blake2bp( void *out, size_t outlen, const void *in, size_t inlen, const void while( inlen__ >= PARALLELISM_DEGREE * BLAKE2B_BLOCKBYTES ) { - blake2b_update( S[i], in__, BLAKE2B_BLOCKBYTES ); + _cryptonite_blake2b_update( S[i], in__, BLAKE2B_BLOCKBYTES ); in__ += PARALLELISM_DEGREE * BLAKE2B_BLOCKBYTES; inlen__ -= PARALLELISM_DEGREE * BLAKE2B_BLOCKBYTES; } @@ -273,10 +273,10 @@ int blake2bp( void *out, size_t outlen, const void *in, size_t inlen, const void { const size_t left = inlen__ - i * BLAKE2B_BLOCKBYTES; const size_t len = left <= BLAKE2B_BLOCKBYTES ? left : BLAKE2B_BLOCKBYTES; - blake2b_update( S[i], in__, len ); + _cryptonite_blake2b_update( S[i], in__, len ); } - blake2b_final( S[i], hash[i], BLAKE2B_OUTBYTES ); + _cryptonite_blake2b_final( S[i], hash[i], BLAKE2B_OUTBYTES ); } if( blake2bp_init_root( FS, outlen, keylen ) < 0 ) @@ -285,9 +285,9 @@ int blake2bp( void *out, size_t outlen, const void *in, size_t inlen, const void FS->last_node = 1; /* Mark as last node */ for( i = 0; i < PARALLELISM_DEGREE; ++i ) - blake2b_update( FS, hash[i], BLAKE2B_OUTBYTES ); + _cryptonite_blake2b_update( FS, hash[i], BLAKE2B_OUTBYTES ); - return blake2b_final( FS, out, outlen );; + return _cryptonite_blake2b_final( FS, out, outlen );; } #if defined(BLAKE2BP_SELFTEST) @@ -326,21 +326,21 @@ int main( void ) size_t mlen = i; int err = 0; - if( (err = blake2bp_init_key(&S, BLAKE2B_OUTBYTES, key, BLAKE2B_KEYBYTES)) < 0 ) { + if( (err = _cryptonite_blake2bp_init_key(&S, BLAKE2B_OUTBYTES, key, BLAKE2B_KEYBYTES)) < 0 ) { goto fail; } while (mlen >= step) { - if ( (err = blake2bp_update(&S, p, step)) < 0 ) { + if ( (err = _cryptonite_blake2bp_update(&S, p, step)) < 0 ) { goto fail; } mlen -= step; p += step; } - if ( (err = blake2bp_update(&S, p, mlen)) < 0) { + if ( (err = _cryptonite_blake2bp_update(&S, p, mlen)) < 0) { goto fail; } - if ( (err = blake2bp_final(&S, hash, BLAKE2B_OUTBYTES)) < 0) { + if ( (err = _cryptonite_blake2bp_final(&S, hash, BLAKE2B_OUTBYTES)) < 0) { goto fail; } diff --git a/cbits/blake2/ref/blake2s-ref.c b/cbits/blake2/ref/blake2s-ref.c index c8b035f..bb8256d 100644 --- a/cbits/blake2/ref/blake2s-ref.c +++ b/cbits/blake2/ref/blake2s-ref.c @@ -73,7 +73,7 @@ static void blake2s_init0( blake2s_state *S ) } /* init2 xors IV with input parameter block */ -int blake2s_init_param( blake2s_state *S, const blake2s_param *P ) +int _cryptonite_blake2s_init_param( blake2s_state *S, const blake2s_param *P ) { const unsigned char *p = ( const unsigned char * )( P ); size_t i; @@ -90,7 +90,7 @@ int blake2s_init_param( blake2s_state *S, const blake2s_param *P ) /* Sequential blake2s initialization */ -int blake2s_init( blake2s_state *S, size_t outlen ) +int _cryptonite_blake2s_init( blake2s_state *S, size_t outlen ) { blake2s_param P[1]; @@ -109,10 +109,10 @@ int blake2s_init( blake2s_state *S, size_t outlen ) /* memset(P->reserved, 0, sizeof(P->reserved) ); */ memset( P->salt, 0, sizeof( P->salt ) ); memset( P->personal, 0, sizeof( P->personal ) ); - return blake2s_init_param( S, P ); + return _cryptonite_blake2s_init_param( S, P ); } -int blake2s_init_key( blake2s_state *S, size_t outlen, const void *key, size_t keylen ) +int _cryptonite_blake2s_init_key( blake2s_state *S, size_t outlen, const void *key, size_t keylen ) { blake2s_param P[1]; @@ -133,13 +133,13 @@ int blake2s_init_key( blake2s_state *S, size_t outlen, const void *key, size_t k memset( P->salt, 0, sizeof( P->salt ) ); memset( P->personal, 0, sizeof( P->personal ) ); - if( blake2s_init_param( S, P ) < 0 ) return -1; + if( _cryptonite_blake2s_init_param( S, P ) < 0 ) return -1; { uint8_t block[BLAKE2S_BLOCKBYTES]; memset( block, 0, BLAKE2S_BLOCKBYTES ); memcpy( block, key, keylen ); - blake2s_update( S, block, BLAKE2S_BLOCKBYTES ); + _cryptonite_blake2s_update( S, block, BLAKE2S_BLOCKBYTES ); secure_zero_memory( block, BLAKE2S_BLOCKBYTES ); /* Burn the key from stack */ } return 0; @@ -211,7 +211,7 @@ static void blake2s_compress( blake2s_state *S, const uint8_t in[BLAKE2S_BLOCKBY #undef G #undef ROUND -int blake2s_update( blake2s_state *S, const void *pin, size_t inlen ) +int _cryptonite_blake2s_update( blake2s_state *S, const void *pin, size_t inlen ) { const unsigned char * in = (const unsigned char *)pin; if( inlen > 0 ) @@ -238,7 +238,7 @@ int blake2s_update( blake2s_state *S, const void *pin, size_t inlen ) return 0; } -int blake2s_final( blake2s_state *S, void *out, size_t outlen ) +int _cryptonite_blake2s_final( blake2s_state *S, void *out, size_t outlen ) { uint8_t buffer[BLAKE2S_OUTBYTES] = {0}; size_t i; @@ -262,7 +262,7 @@ int blake2s_final( blake2s_state *S, void *out, size_t outlen ) return 0; } -int blake2s( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen ) +int _cryptonite_blake2s( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen ) { blake2s_state S[1]; @@ -279,22 +279,22 @@ int blake2s( void *out, size_t outlen, const void *in, size_t inlen, const void if( keylen > 0 ) { - if( blake2s_init_key( S, outlen, key, keylen ) < 0 ) return -1; + if( _cryptonite_blake2s_init_key( S, outlen, key, keylen ) < 0 ) return -1; } else { - if( blake2s_init( S, outlen ) < 0 ) return -1; + if( _cryptonite_blake2s_init( S, outlen ) < 0 ) return -1; } - blake2s_update( S, ( const uint8_t * )in, inlen ); - blake2s_final( S, out, outlen ); + _cryptonite_blake2s_update( S, ( const uint8_t * )in, inlen ); + _cryptonite_blake2s_final( S, out, outlen ); return 0; } #if defined(SUPERCOP) int crypto_hash( unsigned char *out, unsigned char *in, unsigned long long inlen ) { - return blake2s( out, BLAKE2S_OUTBYTES, in, inlen, NULL, 0 ); + return _cryptonite_blake2s( out, BLAKE2S_OUTBYTES, in, inlen, NULL, 0 ); } #endif @@ -317,7 +317,7 @@ int main( void ) for( i = 0; i < BLAKE2_KAT_LENGTH; ++i ) { uint8_t hash[BLAKE2S_OUTBYTES]; - blake2s( hash, BLAKE2S_OUTBYTES, buf, i, key, BLAKE2S_KEYBYTES ); + _cryptonite_blake2s( hash, BLAKE2S_OUTBYTES, buf, i, key, BLAKE2S_KEYBYTES ); if( 0 != memcmp( hash, blake2s_keyed_kat[i], BLAKE2S_OUTBYTES ) ) { @@ -334,21 +334,21 @@ int main( void ) size_t mlen = i; int err = 0; - if( (err = blake2s_init_key(&S, BLAKE2S_OUTBYTES, key, BLAKE2S_KEYBYTES)) < 0 ) { + if( (err = _cryptonite_blake2s_init_key(&S, BLAKE2S_OUTBYTES, key, BLAKE2S_KEYBYTES)) < 0 ) { goto fail; } while (mlen >= step) { - if ( (err = blake2s_update(&S, p, step)) < 0 ) { + if ( (err = _cryptonite_blake2s_update(&S, p, step)) < 0 ) { goto fail; } mlen -= step; p += step; } - if ( (err = blake2s_update(&S, p, mlen)) < 0) { + if ( (err = _cryptonite_blake2s_update(&S, p, mlen)) < 0) { goto fail; } - if ( (err = blake2s_final(&S, hash, BLAKE2S_OUTBYTES)) < 0) { + if ( (err = _cryptonite_blake2s_final(&S, hash, BLAKE2S_OUTBYTES)) < 0) { goto fail; } diff --git a/cbits/blake2/ref/blake2sp-ref.c b/cbits/blake2/ref/blake2sp-ref.c index b0e9bae..159266e 100644 --- a/cbits/blake2/ref/blake2sp-ref.c +++ b/cbits/blake2/ref/blake2sp-ref.c @@ -75,7 +75,7 @@ static int blake2sp_init_root( blake2s_state *S, size_t outlen, size_t keylen ) } -int blake2sp_init( blake2sp_state *S, size_t outlen ) +int _cryptonite_blake2sp_init( blake2sp_state *S, size_t outlen ) { size_t i; @@ -96,7 +96,7 @@ int blake2sp_init( blake2sp_state *S, size_t outlen ) return 0; } -int blake2sp_init_key( blake2sp_state *S, size_t outlen, const void *key, size_t keylen ) +int _cryptonite_blake2sp_init_key( blake2sp_state *S, size_t outlen, const void *key, size_t keylen ) { size_t i; @@ -122,7 +122,7 @@ int blake2sp_init_key( blake2sp_state *S, size_t outlen, const void *key, size_t memcpy( block, key, keylen ); for( i = 0; i < PARALLELISM_DEGREE; ++i ) - blake2s_update( S->S[i], block, BLAKE2S_BLOCKBYTES ); + _cryptonite_blake2s_update( S->S[i], block, BLAKE2S_BLOCKBYTES ); secure_zero_memory( block, BLAKE2S_BLOCKBYTES ); /* Burn the key from stack */ } @@ -130,7 +130,7 @@ int blake2sp_init_key( blake2sp_state *S, size_t outlen, const void *key, size_t } -int blake2sp_update( blake2sp_state *S, const void *pin, size_t inlen ) +int _cryptonite_blake2sp_update( blake2sp_state *S, const void *pin, size_t inlen ) { const unsigned char * in = (const unsigned char *)pin; size_t left = S->buflen; @@ -142,7 +142,7 @@ int blake2sp_update( blake2sp_state *S, const void *pin, size_t inlen ) memcpy( S->buf + left, in, fill ); for( i = 0; i < PARALLELISM_DEGREE; ++i ) - blake2s_update( S->S[i], S->buf + i * BLAKE2S_BLOCKBYTES, BLAKE2S_BLOCKBYTES ); + _cryptonite_blake2s_update( S->S[i], S->buf + i * BLAKE2S_BLOCKBYTES, BLAKE2S_BLOCKBYTES ); in += fill; inlen -= fill; @@ -164,7 +164,7 @@ int blake2sp_update( blake2sp_state *S, const void *pin, size_t inlen ) while( inlen__ >= PARALLELISM_DEGREE * BLAKE2S_BLOCKBYTES ) { - blake2s_update( S->S[i], in__, BLAKE2S_BLOCKBYTES ); + _cryptonite_blake2s_update( S->S[i], in__, BLAKE2S_BLOCKBYTES ); in__ += PARALLELISM_DEGREE * BLAKE2S_BLOCKBYTES; inlen__ -= PARALLELISM_DEGREE * BLAKE2S_BLOCKBYTES; } @@ -181,7 +181,7 @@ int blake2sp_update( blake2sp_state *S, const void *pin, size_t inlen ) } -int blake2sp_final( blake2sp_state *S, void *out, size_t outlen ) +int _cryptonite_blake2sp_final( blake2sp_state *S, void *out, size_t outlen ) { uint8_t hash[PARALLELISM_DEGREE][BLAKE2S_OUTBYTES]; size_t i; @@ -198,20 +198,20 @@ int blake2sp_final( blake2sp_state *S, void *out, size_t outlen ) if( left > BLAKE2S_BLOCKBYTES ) left = BLAKE2S_BLOCKBYTES; - blake2s_update( S->S[i], S->buf + i * BLAKE2S_BLOCKBYTES, left ); + _cryptonite_blake2s_update( S->S[i], S->buf + i * BLAKE2S_BLOCKBYTES, left ); } - blake2s_final( S->S[i], hash[i], BLAKE2S_OUTBYTES ); + _cryptonite_blake2s_final( S->S[i], hash[i], BLAKE2S_OUTBYTES ); } for( i = 0; i < PARALLELISM_DEGREE; ++i ) - blake2s_update( S->R, hash[i], BLAKE2S_OUTBYTES ); + _cryptonite_blake2s_update( S->R, hash[i], BLAKE2S_OUTBYTES ); - return blake2s_final( S->R, out, S->outlen ); + return _cryptonite_blake2s_final( S->R, out, S->outlen ); } -int blake2sp( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen ) +int _cryptonite_blake2sp( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen ) { uint8_t hash[PARALLELISM_DEGREE][BLAKE2S_OUTBYTES]; blake2s_state S[PARALLELISM_DEGREE][1]; @@ -241,7 +241,7 @@ int blake2sp( void *out, size_t outlen, const void *in, size_t inlen, const void memcpy( block, key, keylen ); for( i = 0; i < PARALLELISM_DEGREE; ++i ) - blake2s_update( S[i], block, BLAKE2S_BLOCKBYTES ); + _cryptonite_blake2s_update( S[i], block, BLAKE2S_BLOCKBYTES ); secure_zero_memory( block, BLAKE2S_BLOCKBYTES ); /* Burn the key from stack */ } @@ -262,7 +262,7 @@ int blake2sp( void *out, size_t outlen, const void *in, size_t inlen, const void while( inlen__ >= PARALLELISM_DEGREE * BLAKE2S_BLOCKBYTES ) { - blake2s_update( S[i], in__, BLAKE2S_BLOCKBYTES ); + _cryptonite_blake2s_update( S[i], in__, BLAKE2S_BLOCKBYTES ); in__ += PARALLELISM_DEGREE * BLAKE2S_BLOCKBYTES; inlen__ -= PARALLELISM_DEGREE * BLAKE2S_BLOCKBYTES; } @@ -271,10 +271,10 @@ int blake2sp( void *out, size_t outlen, const void *in, size_t inlen, const void { const size_t left = inlen__ - i * BLAKE2S_BLOCKBYTES; const size_t len = left <= BLAKE2S_BLOCKBYTES ? left : BLAKE2S_BLOCKBYTES; - blake2s_update( S[i], in__, len ); + _cryptonite_blake2s_update( S[i], in__, len ); } - blake2s_final( S[i], hash[i], BLAKE2S_OUTBYTES ); + _cryptonite_blake2s_final( S[i], hash[i], BLAKE2S_OUTBYTES ); } if( blake2sp_init_root( FS, outlen, keylen ) < 0 ) @@ -283,9 +283,9 @@ int blake2sp( void *out, size_t outlen, const void *in, size_t inlen, const void FS->last_node = 1; for( i = 0; i < PARALLELISM_DEGREE; ++i ) - blake2s_update( FS, hash[i], BLAKE2S_OUTBYTES ); + _cryptonite_blake2s_update( FS, hash[i], BLAKE2S_OUTBYTES ); - return blake2s_final( FS, out, outlen ); + return _cryptonite_blake2s_final( FS, out, outlen ); } @@ -309,7 +309,7 @@ int main( void ) for( i = 0; i < BLAKE2_KAT_LENGTH; ++i ) { uint8_t hash[BLAKE2S_OUTBYTES]; - blake2sp( hash, BLAKE2S_OUTBYTES, buf, i, key, BLAKE2S_KEYBYTES ); + _cryptonite_blake2sp( hash, BLAKE2S_OUTBYTES, buf, i, key, BLAKE2S_KEYBYTES ); if( 0 != memcmp( hash, blake2sp_keyed_kat[i], BLAKE2S_OUTBYTES ) ) { @@ -326,21 +326,21 @@ int main( void ) size_t mlen = i; int err = 0; - if( (err = blake2sp_init_key(&S, BLAKE2S_OUTBYTES, key, BLAKE2S_KEYBYTES)) < 0 ) { + if( (err = _cryptonite_blake2sp_init_key(&S, BLAKE2S_OUTBYTES, key, BLAKE2S_KEYBYTES)) < 0 ) { goto fail; } while (mlen >= step) { - if ( (err = blake2sp_update(&S, p, step)) < 0 ) { + if ( (err = _cryptonite_blake2sp_update(&S, p, step)) < 0 ) { goto fail; } mlen -= step; p += step; } - if ( (err = blake2sp_update(&S, p, mlen)) < 0) { + if ( (err = _cryptonite_blake2sp_update(&S, p, mlen)) < 0) { goto fail; } - if ( (err = blake2sp_final(&S, hash, BLAKE2S_OUTBYTES)) < 0) { + if ( (err = _cryptonite_blake2sp_final(&S, hash, BLAKE2S_OUTBYTES)) < 0) { goto fail; } diff --git a/cbits/blake2/ref/blake2xb-ref.c b/cbits/blake2/ref/blake2xb-ref.c index b369ee7..adad24f 100644 --- a/cbits/blake2/ref/blake2xb-ref.c +++ b/cbits/blake2/ref/blake2xb-ref.c @@ -23,11 +23,11 @@ #include "blake2.h" #include "blake2-impl.h" -int blake2xb_init( blake2xb_state *S, const size_t outlen ) { - return blake2xb_init_key(S, outlen, NULL, 0); +int _cryptonite_blake2xb_init( blake2xb_state *S, const size_t outlen ) { + return _cryptonite_blake2xb_init_key(S, outlen, NULL, 0); } -int blake2xb_init_key( blake2xb_state *S, const size_t outlen, const void *key, size_t keylen) +int _cryptonite_blake2xb_init_key( blake2xb_state *S, const size_t outlen, const void *key, size_t keylen) { if ( outlen == 0 || outlen > 0xFFFFFFFFUL ) { return -1; @@ -55,7 +55,7 @@ int blake2xb_init_key( blake2xb_state *S, const size_t outlen, const void *key, memset( S->P->salt, 0, sizeof( S->P->salt ) ); memset( S->P->personal, 0, sizeof( S->P->personal ) ); - if( blake2b_init_param( S->S, S->P ) < 0 ) { + if( _cryptonite_blake2b_init_param( S->S, S->P ) < 0 ) { return -1; } @@ -63,17 +63,17 @@ int blake2xb_init_key( blake2xb_state *S, const size_t outlen, const void *key, uint8_t block[BLAKE2B_BLOCKBYTES]; memset(block, 0, BLAKE2B_BLOCKBYTES); memcpy(block, key, keylen); - blake2b_update(S->S, block, BLAKE2B_BLOCKBYTES); + _cryptonite_blake2b_update(S->S, block, BLAKE2B_BLOCKBYTES); secure_zero_memory(block, BLAKE2B_BLOCKBYTES); } return 0; } -int blake2xb_update( blake2xb_state *S, const void *in, size_t inlen ) { - return blake2b_update( S->S, in, inlen ); +int _cryptonite_blake2xb_update( blake2xb_state *S, const void *in, size_t inlen ) { + return _cryptonite_blake2b_update( S->S, in, inlen ); } -int blake2xb_final( blake2xb_state *S, void *out, size_t outlen) { +int _cryptonite_blake2xb_final( blake2xb_state *S, void *out, size_t outlen) { blake2b_state C[1]; blake2b_param P[1]; @@ -98,7 +98,7 @@ int blake2xb_final( blake2xb_state *S, void *out, size_t outlen) { } /* Finalize the root hash */ - if (blake2b_final(S->S, root, BLAKE2B_OUTBYTES) < 0) { + if (_cryptonite_blake2b_final(S->S, root, BLAKE2B_OUTBYTES) < 0) { return -1; } @@ -117,10 +117,10 @@ int blake2xb_final( blake2xb_state *S, void *out, size_t outlen) { /* Initialize state */ P->digest_length = block_size; store32(&P->node_offset, i); - blake2b_init_param(C, P); + _cryptonite_blake2b_init_param(C, P); /* Process key if needed */ - blake2b_update(C, root, BLAKE2B_OUTBYTES); - if (blake2b_final(C, (uint8_t *)out + i * BLAKE2B_OUTBYTES, block_size) < 0 ) { + _cryptonite_blake2b_update(C, root, BLAKE2B_OUTBYTES); + if (_cryptonite_blake2b_final(C, (uint8_t *)out + i * BLAKE2B_OUTBYTES, block_size) < 0 ) { return -1; } outlen -= block_size; @@ -133,7 +133,7 @@ int blake2xb_final( blake2xb_state *S, void *out, size_t outlen) { } -int blake2xb(void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen) +int _cryptonite_blake2xb(void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen) { blake2xb_state S[1]; @@ -154,15 +154,15 @@ int blake2xb(void *out, size_t outlen, const void *in, size_t inlen, const void return -1; /* Initialize the root block structure */ - if (blake2xb_init_key(S, outlen, key, keylen) < 0) { + if (_cryptonite_blake2xb_init_key(S, outlen, key, keylen) < 0) { return -1; } /* Absorb the input message */ - blake2xb_update(S, in, inlen); + _cryptonite_blake2xb_update(S, in, inlen); /* Compute the root node of the tree and the final hash using the counter construction */ - return blake2xb_final(S, out, outlen); + return _cryptonite_blake2xb_final(S, out, outlen); } #if defined(BLAKE2XB_SELFTEST) @@ -189,7 +189,7 @@ int main( void ) for( outlen = 1; outlen <= BLAKE2_KAT_LENGTH; ++outlen ) { uint8_t hash[BLAKE2_KAT_LENGTH] = {0}; - if( blake2xb( hash, outlen, buf, BLAKE2_KAT_LENGTH, key, BLAKE2B_KEYBYTES ) < 0 ) { + if( _cryptonite_blake2xb( hash, outlen, buf, BLAKE2_KAT_LENGTH, key, BLAKE2B_KEYBYTES ) < 0 ) { goto fail; } @@ -208,21 +208,21 @@ int main( void ) size_t mlen = BLAKE2_KAT_LENGTH; int err = 0; - if( (err = blake2xb_init_key(&S, outlen, key, BLAKE2B_KEYBYTES)) < 0 ) { + if( (err = _cryptonite_blake2xb_init_key(&S, outlen, key, BLAKE2B_KEYBYTES)) < 0 ) { goto fail; } while (mlen >= step) { - if ( (err = blake2xb_update(&S, p, step)) < 0 ) { + if ( (err = _cryptonite_blake2xb_update(&S, p, step)) < 0 ) { goto fail; } mlen -= step; p += step; } - if ( (err = blake2xb_update(&S, p, mlen)) < 0) { + if ( (err = _cryptonite_blake2xb_update(&S, p, mlen)) < 0) { goto fail; } - if ( (err = blake2xb_final(&S, hash, outlen)) < 0) { + if ( (err = _cryptonite_blake2xb_final(&S, hash, outlen)) < 0) { goto fail; } diff --git a/cbits/blake2/ref/blake2xs-ref.c b/cbits/blake2/ref/blake2xs-ref.c index e7a89f8..05c57dc 100644 --- a/cbits/blake2/ref/blake2xs-ref.c +++ b/cbits/blake2/ref/blake2xs-ref.c @@ -23,11 +23,11 @@ #include "blake2.h" #include "blake2-impl.h" -int blake2xs_init( blake2xs_state *S, const size_t outlen ) { - return blake2xs_init_key(S, outlen, NULL, 0); +int _cryptonite_blake2xs_init( blake2xs_state *S, const size_t outlen ) { + return _cryptonite_blake2xs_init_key(S, outlen, NULL, 0); } -int blake2xs_init_key( blake2xs_state *S, const size_t outlen, const void *key, size_t keylen ) +int _cryptonite_blake2xs_init_key( blake2xs_state *S, const size_t outlen, const void *key, size_t keylen ) { if ( outlen == 0 || outlen > 0xFFFFUL ) { return -1; @@ -54,7 +54,7 @@ int blake2xs_init_key( blake2xs_state *S, const size_t outlen, const void *key, memset( S->P->salt, 0, sizeof( S->P->salt ) ); memset( S->P->personal, 0, sizeof( S->P->personal ) ); - if( blake2s_init_param( S->S, S->P ) < 0 ) { + if( _cryptonite_blake2s_init_param( S->S, S->P ) < 0 ) { return -1; } @@ -62,17 +62,17 @@ int blake2xs_init_key( blake2xs_state *S, const size_t outlen, const void *key, uint8_t block[BLAKE2S_BLOCKBYTES]; memset(block, 0, BLAKE2S_BLOCKBYTES); memcpy(block, key, keylen); - blake2s_update(S->S, block, BLAKE2S_BLOCKBYTES); + _cryptonite_blake2s_update(S->S, block, BLAKE2S_BLOCKBYTES); secure_zero_memory(block, BLAKE2S_BLOCKBYTES); } return 0; } -int blake2xs_update( blake2xs_state *S, const void *in, size_t inlen ) { - return blake2s_update( S->S, in, inlen ); +int _cryptonite_blake2xs_update( blake2xs_state *S, const void *in, size_t inlen ) { + return _cryptonite_blake2s_update( S->S, in, inlen ); } -int blake2xs_final(blake2xs_state *S, void *out, size_t outlen) { +int _cryptonite_blake2xs_final(blake2xs_state *S, void *out, size_t outlen) { blake2s_state C[1]; blake2s_param P[1]; @@ -97,7 +97,7 @@ int blake2xs_final(blake2xs_state *S, void *out, size_t outlen) { } /* Finalize the root hash */ - if (blake2s_final(S->S, root, BLAKE2S_OUTBYTES) < 0) { + if (_cryptonite_blake2s_final(S->S, root, BLAKE2S_OUTBYTES) < 0) { return -1; } @@ -116,10 +116,10 @@ int blake2xs_final(blake2xs_state *S, void *out, size_t outlen) { /* Initialize state */ P->digest_length = block_size; store32(&P->node_offset, i); - blake2s_init_param(C, P); + _cryptonite_blake2s_init_param(C, P); /* Process key if needed */ - blake2s_update(C, root, BLAKE2S_OUTBYTES); - if (blake2s_final(C, (uint8_t *)out + i * BLAKE2S_OUTBYTES, block_size) < 0) { + _cryptonite_blake2s_update(C, root, BLAKE2S_OUTBYTES); + if (_cryptonite_blake2s_final(C, (uint8_t *)out + i * BLAKE2S_OUTBYTES, block_size) < 0) { return -1; } outlen -= block_size; @@ -131,7 +131,7 @@ int blake2xs_final(blake2xs_state *S, void *out, size_t outlen) { return 0; } -int blake2xs(void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen) +int _cryptonite_blake2xs(void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen) { blake2xs_state S[1]; @@ -152,15 +152,15 @@ int blake2xs(void *out, size_t outlen, const void *in, size_t inlen, const void return -1; /* Initialize the root block structure */ - if (blake2xs_init_key(S, outlen, key, keylen) < 0) { + if (_cryptonite_blake2xs_init_key(S, outlen, key, keylen) < 0) { return -1; } /* Absorb the input message */ - blake2xs_update(S, in, inlen); + _cryptonite_blake2xs_update(S, in, inlen); /* Compute the root node of the tree and the final hash using the counter construction */ - return blake2xs_final(S, out, outlen); + return _cryptonite_blake2xs_final(S, out, outlen); } #if defined(BLAKE2XS_SELFTEST) @@ -187,7 +187,7 @@ int main( void ) for( outlen = 1; outlen <= BLAKE2_KAT_LENGTH; ++outlen ) { uint8_t hash[BLAKE2_KAT_LENGTH] = {0}; - if( blake2xs( hash, outlen, buf, BLAKE2_KAT_LENGTH, key, BLAKE2S_KEYBYTES ) < 0 ) { + if( _cryptonite_blake2xs( hash, outlen, buf, BLAKE2_KAT_LENGTH, key, BLAKE2S_KEYBYTES ) < 0 ) { goto fail; } @@ -206,21 +206,21 @@ int main( void ) size_t mlen = BLAKE2_KAT_LENGTH; int err = 0; - if( (err = blake2xs_init_key(&S, outlen, key, BLAKE2S_KEYBYTES)) < 0 ) { + if( (err = _cryptonite_blake2xs_init_key(&S, outlen, key, BLAKE2S_KEYBYTES)) < 0 ) { goto fail; } while (mlen >= step) { - if ( (err = blake2xs_update(&S, p, step)) < 0 ) { + if ( (err = _cryptonite_blake2xs_update(&S, p, step)) < 0 ) { goto fail; } mlen -= step; p += step; } - if ( (err = blake2xs_update(&S, p, mlen)) < 0) { + if ( (err = _cryptonite_blake2xs_update(&S, p, mlen)) < 0) { goto fail; } - if ( (err = blake2xs_final(&S, hash, outlen)) < 0) { + if ( (err = _cryptonite_blake2xs_final(&S, hash, outlen)) < 0) { goto fail; } diff --git a/cbits/blake2/sse/blake2b.c b/cbits/blake2/sse/blake2b.c index 3df0c8d..23f4b25 100644 --- a/cbits/blake2/sse/blake2b.c +++ b/cbits/blake2/sse/blake2b.c @@ -74,7 +74,7 @@ static void blake2b_increment_counter( blake2b_state *S, const uint64_t inc ) } /* init xors IV with input parameter block */ -int blake2b_init_param( blake2b_state *S, const blake2b_param *P ) +int _cryptonite_blake2b_init_param( blake2b_state *S, const blake2b_param *P ) { size_t i; /*blake2b_init0( S ); */ @@ -92,7 +92,7 @@ int blake2b_init_param( blake2b_state *S, const blake2b_param *P ) /* Some sort of default parameter block initialization, for sequential blake2b */ -int blake2b_init( blake2b_state *S, size_t outlen ) +int _cryptonite_blake2b_init( blake2b_state *S, size_t outlen ) { blake2b_param P[1]; @@ -111,10 +111,10 @@ int blake2b_init( blake2b_state *S, size_t outlen ) memset( P->salt, 0, sizeof( P->salt ) ); memset( P->personal, 0, sizeof( P->personal ) ); - return blake2b_init_param( S, P ); + return _cryptonite_blake2b_init_param( S, P ); } -int blake2b_init_key( blake2b_state *S, size_t outlen, const void *key, size_t keylen ) +int _cryptonite_blake2b_init_key( blake2b_state *S, size_t outlen, const void *key, size_t keylen ) { blake2b_param P[1]; @@ -135,7 +135,7 @@ int blake2b_init_key( blake2b_state *S, size_t outlen, const void *key, size_t k memset( P->salt, 0, sizeof( P->salt ) ); memset( P->personal, 0, sizeof( P->personal ) ); - if( blake2b_init_param( S, P ) < 0 ) + if( _cryptonite_blake2b_init_param( S, P ) < 0 ) return 0; { @@ -218,7 +218,7 @@ static void blake2b_compress( blake2b_state *S, const uint8_t block[BLAKE2B_BLOC } -int blake2b_update( blake2b_state *S, const void *pin, size_t inlen ) +int _cryptonite_blake2b_update( blake2b_state *S, const void *pin, size_t inlen ) { const unsigned char * in = (const unsigned char *)pin; if( inlen > 0 ) @@ -246,7 +246,7 @@ int blake2b_update( blake2b_state *S, const void *pin, size_t inlen ) } -int blake2b_final( blake2b_state *S, void *out, size_t outlen ) +int _cryptonite_blake2b_final( blake2b_state *S, void *out, size_t outlen ) { if( out == NULL || outlen < S->outlen ) return -1; @@ -264,7 +264,7 @@ int blake2b_final( blake2b_state *S, void *out, size_t outlen ) } -int blake2b( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen ) +int _cryptonite_blake2b( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen ) { blake2b_state S[1]; @@ -281,26 +281,26 @@ int blake2b( void *out, size_t outlen, const void *in, size_t inlen, const void if( keylen ) { - if( blake2b_init_key( S, outlen, key, keylen ) < 0 ) return -1; + if( _cryptonite_blake2b_init_key( S, outlen, key, keylen ) < 0 ) return -1; } else { - if( blake2b_init( S, outlen ) < 0 ) return -1; + if( _cryptonite_blake2b_init( S, outlen ) < 0 ) return -1; } - blake2b_update( S, ( const uint8_t * )in, inlen ); - blake2b_final( S, out, outlen ); + _cryptonite_blake2b_update( S, ( const uint8_t * )in, inlen ); + _cryptonite_blake2b_final( S, out, outlen ); return 0; } -int blake2( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen ) { - return blake2b(out, outlen, in, inlen, key, keylen); +int _cryptonite_blake2( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen ) { + return _cryptonite_blake2b(out, outlen, in, inlen, key, keylen); } #if defined(SUPERCOP) int crypto_hash( unsigned char *out, unsigned char *in, unsigned long long inlen ) { - return blake2b( out, BLAKE2B_OUTBYTES, in, inlen, NULL, 0 ); + return _cryptonite_blake2b( out, BLAKE2B_OUTBYTES, in, inlen, NULL, 0 ); } #endif @@ -340,21 +340,21 @@ int main( void ) size_t mlen = i; int err = 0; - if( (err = blake2b_init_key(&S, BLAKE2B_OUTBYTES, key, BLAKE2B_KEYBYTES)) < 0 ) { + if( (err = _cryptonite_blake2b_init_key(&S, BLAKE2B_OUTBYTES, key, BLAKE2B_KEYBYTES)) < 0 ) { goto fail; } while (mlen >= step) { - if ( (err = blake2b_update(&S, p, step)) < 0 ) { + if ( (err = _cryptonite_blake2b_update(&S, p, step)) < 0 ) { goto fail; } mlen -= step; p += step; } - if ( (err = blake2b_update(&S, p, mlen)) < 0) { + if ( (err = _cryptonite_blake2b_update(&S, p, mlen)) < 0) { goto fail; } - if ( (err = blake2b_final(&S, hash, BLAKE2B_OUTBYTES)) < 0) { + if ( (err = _cryptonite_blake2b_final(&S, hash, BLAKE2B_OUTBYTES)) < 0) { goto fail; } From f4f92b702c1d8d70da741a44f68ea27296e5a917 Mon Sep 17 00:00:00 2001 From: iquerejeta Date: Thu, 28 Oct 2021 10:57:03 +0200 Subject: [PATCH 06/12] recapitalised constant --- cbits/blake2/ref/blake2b-ref.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cbits/blake2/ref/blake2b-ref.c b/cbits/blake2/ref/blake2b-ref.c index b6d30cf..c0b876c 100644 --- a/cbits/blake2/ref/blake2b-ref.c +++ b/cbits/blake2/ref/blake2b-ref.c @@ -99,7 +99,7 @@ int _cryptonite_blake2b_init( blake2b_state *S, size_t outlen ) { blake2b_param P[1]; - if ( ( !outlen ) || ( outlen > blake2B_OUTBYTES ) ) return -1; + if ( ( !outlen ) || ( outlen > BLAKE2B_OUTBYTES ) ) return -1; P->digest_length = (uint8_t)outlen; P->key_length = 0; From 309abe378da29bb0d840d1c76fd7cde6424f9968 Mon Sep 17 00:00:00 2001 From: Vincent Hanquez Date: Thu, 28 Oct 2021 20:27:17 +0800 Subject: [PATCH 07/12] missing symbols renaming --- cbits/blake2/ref/blake2bp-ref.c | 4 ++-- cbits/blake2/ref/blake2sp-ref.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cbits/blake2/ref/blake2bp-ref.c b/cbits/blake2/ref/blake2bp-ref.c index 51f795e..2d0f3ff 100644 --- a/cbits/blake2/ref/blake2bp-ref.c +++ b/cbits/blake2/ref/blake2bp-ref.c @@ -36,7 +36,7 @@ */ static int blake2bp_init_leaf_param( blake2b_state *S, const blake2b_param *P ) { - int err = blake2b_init_param(S, P); + int err = _cryptonite_blake2b_init_param(S, P); S->outlen = P->inner_length; return err; } @@ -74,7 +74,7 @@ static int blake2bp_init_root( blake2b_state *S, size_t outlen, size_t keylen ) memset( P->reserved, 0, sizeof( P->reserved ) ); memset( P->salt, 0, sizeof( P->salt ) ); memset( P->personal, 0, sizeof( P->personal ) ); - return blake2b_init_param( S, P ); + return _cryptonite_blake2b_init_param( S, P ); } diff --git a/cbits/blake2/ref/blake2sp-ref.c b/cbits/blake2/ref/blake2sp-ref.c index 159266e..454a992 100644 --- a/cbits/blake2/ref/blake2sp-ref.c +++ b/cbits/blake2/ref/blake2sp-ref.c @@ -35,7 +35,7 @@ */ static int blake2sp_init_leaf_param( blake2s_state *S, const blake2s_param *P ) { - int err = blake2s_init_param(S, P); + int err = _cryptonite_blake2s_init_param(S, P); S->outlen = P->inner_length; return err; } @@ -71,7 +71,7 @@ static int blake2sp_init_root( blake2s_state *S, size_t outlen, size_t keylen ) P->inner_length = BLAKE2S_OUTBYTES; memset( P->salt, 0, sizeof( P->salt ) ); memset( P->personal, 0, sizeof( P->personal ) ); - return blake2s_init_param( S, P ); + return _cryptonite_blake2s_init_param( S, P ); } From 495eca0bb5cf8b11ac7a78bf0c42e39d35802d49 Mon Sep 17 00:00:00 2001 From: iquerejeta Date: Thu, 17 Feb 2022 11:43:52 +0000 Subject: [PATCH 08/12] include prefix to missing functions --- cbits/blake2/sse/blake2s.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/cbits/blake2/sse/blake2s.c b/cbits/blake2/sse/blake2s.c index df636a3..b983465 100644 --- a/cbits/blake2/sse/blake2s.c +++ b/cbits/blake2/sse/blake2s.c @@ -72,7 +72,7 @@ static void blake2s_increment_counter( blake2s_state *S, const uint32_t inc ) } /* init2 xors IV with input parameter block */ -int blake2s_init_param( blake2s_state *S, const blake2s_param *P ) +int _cryptonite_blake2s_init_param( blake2s_state *S, const blake2s_param *P ) { size_t i; /*blake2s_init0( S ); */ @@ -90,7 +90,7 @@ int blake2s_init_param( blake2s_state *S, const blake2s_param *P ) /* Some sort of default parameter block initialization, for sequential blake2s */ -int blake2s_init( blake2s_state *S, size_t outlen ) +int _cryptonite_blake2s_init( blake2s_state *S, size_t outlen ) { blake2s_param P[1]; @@ -110,11 +110,11 @@ int blake2s_init( blake2s_state *S, size_t outlen ) memset( P->salt, 0, sizeof( P->salt ) ); memset( P->personal, 0, sizeof( P->personal ) ); - return blake2s_init_param( S, P ); + return _cryptonite_blake2s_init_param( S, P ); } -int blake2s_init_key( blake2s_state *S, size_t outlen, const void *key, size_t keylen ) +int _cryptonite_blake2s_init_key( blake2s_state *S, size_t outlen, const void *key, size_t keylen ) { blake2s_param P[1]; @@ -136,7 +136,7 @@ int blake2s_init_key( blake2s_state *S, size_t outlen, const void *key, size_t k memset( P->salt, 0, sizeof( P->salt ) ); memset( P->personal, 0, sizeof( P->personal ) ); - if( blake2s_init_param( S, P ) < 0 ) + if( _cryptonite_blake2s_init_param( S, P ) < 0 ) return -1; { @@ -233,7 +233,7 @@ int _cryptonite_blake2s_update( blake2s_state *S, const void *pin, size_t inlen return 0; } -int blake2s_final( blake2s_state *S, void *out, size_t outlen ) +int _cryptonite_blake2s_final( blake2s_state *S, void *out, size_t outlen ) { uint8_t buffer[BLAKE2S_OUTBYTES] = {0}; size_t i; @@ -275,15 +275,15 @@ int blake2s( void *out, size_t outlen, const void *in, size_t inlen, const void if( keylen > 0 ) { - if( blake2s_init_key( S, outlen, key, keylen ) < 0 ) return -1; + if( _cryptonite_blake2s_init_key( S, outlen, key, keylen ) < 0 ) return -1; } else { - if( blake2s_init( S, outlen ) < 0 ) return -1; + if( _cryptonite_blake2s_init( S, outlen ) < 0 ) return -1; } _cryptonite_blake2s_update( S, ( const uint8_t * )in, inlen ); - blake2s_final( S, out, outlen ); + _cryptonite_blake2s_final( S, out, outlen ); return 0; } @@ -330,7 +330,7 @@ int main( void ) size_t mlen = i; int err = 0; - if( (err = blake2s_init_key(&S, BLAKE2S_OUTBYTES, key, BLAKE2S_KEYBYTES)) < 0 ) { + if( (err = _cryptonite_blake2s_init_key(&S, BLAKE2S_OUTBYTES, key, BLAKE2S_KEYBYTES)) < 0 ) { goto fail; } @@ -344,7 +344,7 @@ int main( void ) if ( (err = _cryptonite_blake2s_update(&S, p, mlen)) < 0) { goto fail; } - if ( (err = blake2s_final(&S, hash, BLAKE2S_OUTBYTES)) < 0) { + if ( (err = _cryptonite_blake2s_final(&S, hash, BLAKE2S_OUTBYTES)) < 0) { goto fail; } From 20b194fc97eed03be8bc382af1f67803f53dce6d Mon Sep 17 00:00:00 2001 From: Vincent Hanquez Date: Sun, 13 Mar 2022 20:49:11 +0800 Subject: [PATCH 09/12] fix byteswap32 to work on Word32# instead of Word# (with compat for ghc < 9.2) --- Crypto/Internal/CompatPrim.hs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/Crypto/Internal/CompatPrim.hs b/Crypto/Internal/CompatPrim.hs index abfc79d..e223ec3 100644 --- a/Crypto/Internal/CompatPrim.hs +++ b/Crypto/Internal/CompatPrim.hs @@ -23,15 +23,21 @@ module Crypto.Internal.CompatPrim , convert4To32 ) where -import GHC.Prim #if !defined(ARCH_IS_LITTLE_ENDIAN) && !defined(ARCH_IS_BIG_ENDIAN) import Data.Memory.Endian (getSystemEndianness, Endianness(..)) #endif +#if __GLASGOW_HASKELL__ >= 902 +import GHC.Prim +#else +import GHC.Prim hiding (Word32#) +type Word32# = Word# +#endif + -- | Byteswap Word# to or from Big Endian -- -- On a big endian machine, this function is a nop. -be32Prim :: Word# -> Word# +be32Prim :: Word32# -> Word32# #ifdef ARCH_IS_LITTLE_ENDIAN be32Prim = byteswap32Prim #elif defined(ARCH_IS_BIG_ENDIAN) @@ -43,7 +49,7 @@ be32Prim w = if getSystemEndianness == LittleEndian then byteswap32Prim w else w -- | Byteswap Word# to or from Little Endian -- -- On a little endian machine, this function is a nop. -le32Prim :: Word# -> Word# +le32Prim :: Word32# -> Word32# #ifdef ARCH_IS_LITTLE_ENDIAN le32Prim w = w #elif defined(ARCH_IS_BIG_ENDIAN) @@ -54,16 +60,11 @@ le32Prim w = if getSystemEndianness == LittleEndian then w else byteswap32Prim w -- | Simple compatibility for byteswap the lower 32 bits of a Word# -- at the primitive level -byteswap32Prim :: Word# -> Word# -#if __GLASGOW_HASKELL__ >= 708 -byteswap32Prim w = byteSwap32# w +byteswap32Prim :: Word32# -> Word32# +#if __GLASGOW_HASKELL__ >= 902 +byteswap32Prim w = wordToWord32# (byteSwap32# (word32ToWord# w)) #else -byteswap32Prim w = - let !a = uncheckedShiftL# w 24# - !b = and# (uncheckedShiftL# w 8#) 0x00ff0000## - !c = and# (uncheckedShiftRL# w 8#) 0x0000ff00## - !d = and# (uncheckedShiftRL# w 24#) 0x000000ff## - in or# a (or# b (or# c d)) +byteswap32Prim w = byteSwap32# w #endif -- | Combine 4 word8 [a,b,c,d] to a word32 representing [a,b,c,d] From aca61fa1b6ac17c49dcede0387f14207a1f372fa Mon Sep 17 00:00:00 2001 From: Vincent Hanquez Date: Sun, 13 Mar 2022 20:49:31 +0800 Subject: [PATCH 10/12] update stackage --- stack.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stack.yaml b/stack.yaml index 0353574..35fc5e1 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,3 +1,3 @@ # ~*~ auto-generated by haskell-ci with config : 4fdddfa41dd039e198b8d125a70471f7dd140fa01001d99126af56fb31429ece ~*~ -{ resolver: lts-14.27, packages: [ '.' ], extra-deps: [], flags: {} } +{ resolver: nightly-2022-03-12, packages: [ '.' ], extra-deps: [ memory-0.17.0 ], flags: {} } From 7dfaf914e6d25181e2aef42e742e6e4efacd700a Mon Sep 17 00:00:00 2001 From: Vincent Hanquez Date: Sun, 13 Mar 2022 20:54:14 +0800 Subject: [PATCH 11/12] release 0.30 --- CHANGELOG.md | 12 ++++++++++++ cryptonite.cabal | 6 +++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index faa4468..e6a49d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,15 @@ +## 0.30 + +* Fix some C symbol blake2b prefix to be cryptonite_ prefix (fix mixing with other C library) +* add hmac-lazy +* Fix compilation with GHC 9.2 +* Drop support for GHC8.0, GHC8.2, GHC8.4, GHC8.6 + +## 0.29 + +* advance compilation with gmp breakage due to change upstream +* Add native EdDSA support + ## 0.28 * Add hash constant time capability diff --git a/cryptonite.cabal b/cryptonite.cabal index 83d100b..ac07d7e 100644 --- a/cryptonite.cabal +++ b/cryptonite.cabal @@ -1,5 +1,5 @@ Name: cryptonite -version: 0.29 +version: 0.30 Synopsis: Cryptography Primitives sink Description: A repository of cryptographic primitives. @@ -36,7 +36,7 @@ Build-Type: Simple Homepage: https://github.com/haskell-crypto/cryptonite Bug-reports: https://github.com/haskell-crypto/cryptonite/issues Cabal-Version: 1.18 -tested-with: GHC==8.8.2, GHC==8.6.5, GHC==8.4.4, GHC==8.2.2, GHC==8.0.2 +tested-with: GHC==9.2.2, GHC==9.0.2, GHC==8.10.7, GHC==8.8.4 extra-doc-files: README.md CHANGELOG.md extra-source-files: cbits/*.h cbits/aes/*.h @@ -245,7 +245,7 @@ Library Crypto.Internal.Nat Crypto.Internal.Words Crypto.Internal.WordArray - if impl(ghc < 8.0) + if impl(ghc < 8.8) Buildable: False else Build-depends: base From 9401b4e3fdc232d83e3e9b28a5e4e1d48297c4ca Mon Sep 17 00:00:00 2001 From: Felix Paulusma Date: Mon, 3 Oct 2022 01:01:30 +0200 Subject: [PATCH 12/12] Small refactor The same parameter was matched on twice, so why not just do it once? --- Crypto/Random/Entropy/Unsafe.hs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Crypto/Random/Entropy/Unsafe.hs b/Crypto/Random/Entropy/Unsafe.hs index 672e9c2..eb2ad06 100644 --- a/Crypto/Random/Entropy/Unsafe.hs +++ b/Crypto/Random/Entropy/Unsafe.hs @@ -25,10 +25,9 @@ replenish :: Int -> [EntropyBackend] -> Ptr Word8 -> IO () replenish _ [] _ = fail "cryptonite: random: cannot get any source of entropy on this system" replenish poolSize backends ptr = loop 0 backends ptr poolSize where loop :: Int -> [EntropyBackend] -> Ptr Word8 -> Int -> IO () - loop retry [] p n | n == 0 = return () - | retry == 3 = error "cryptonite: random: cannot fully replenish" + loop _ _ _ 0 = return () + loop retry [] p n | retry == 3 = error "cryptonite: random: cannot fully replenish" | otherwise = loop (retry+1) backends p n - loop _ (_:_) _ 0 = return () loop retry (b:bs) p n = do r <- gatherBackend b p n loop retry bs (p `plusPtr` r) (n - r)