Skip to content

Commit 3867c1c

Browse files
committed
Use blake2b as hash for random generator from Argon2 is used.
1 parent eadb02d commit 3867c1c

30 files changed

+134
-75
lines changed

src/Common/Crypto.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ static Hash Hashes[] =
133133
{ BLAKE2S, L"BLAKE2s-256", FALSE, TRUE },
134134
{ WHIRLPOOL, L"Whirlpool", FALSE, FALSE },
135135
{ STREEBOG, L"Streebog", FALSE, FALSE },
136-
{ ARGON2, L"Argon2", FALSE, FALSE },
136+
{ ARGON2, L"BLAKE2b-512", FALSE, FALSE },
137137
#endif
138138
{ 0, 0, 0 }
139139
};
@@ -780,7 +780,7 @@ BOOL HashForSystemEncryption (int hashId)
780780

781781
BOOL HashIsAvailable (int hashId)
782782
{
783-
return (hashId != ARGON2) && (HashGet(hashId) != 0); // Argon2 is not a hash function
783+
return (HashGet(hashId) != 0);
784784
}
785785

786786
// Returns the largest key size needed by an EA for the specified mode of operation

src/Common/Crypto.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,12 @@ typedef struct
200200
#endif
201201
#include "Twofish.h"
202202

203-
#include "blake2.h"
203+
#include "blake2s.h"
204204
#ifndef TC_WINDOWS_BOOT
205205
# include "Sha2.h"
206206
# include "Whirlpool.h"
207207
# include "argon2.h"
208+
# include "blake2b.h"
208209
# include "Streebog.h"
209210
# include "kuznyechik.h"
210211
# include "Camellia.h"

src/Common/Dlgcode.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6343,20 +6343,18 @@ static BOOL PerformBenchmark(HWND hBenchDlg, HWND hwndDlg)
63436343
{
63446344
BYTE digest [MAX_DIGESTSIZE];
63456345
#ifndef WOLFCRYPT_BACKEND
6346-
WHIRLPOOL_CTX wctx;
6346+
WHIRLPOOL_CTX wctx;
63476347
STREEBOG_CTX stctx;
6348-
blake2s_state bctx;
6349-
#endif
6348+
blake2s_state bctx;
6349+
blake2b_state b2ctx;
6350+
#endif
63506351
sha512_ctx s2ctx;
63516352
sha256_ctx s256ctx;
63526353

63536354
int hid, i;
63546355

63556356
for (hid = FIRST_PRF_ID; hid <= LAST_PRF_ID; hid++)
63566357
{
6357-
// Skip Argon2 since it is not a hash function
6358-
if (hid == ARGON2)
6359-
continue;
63606358
if (QueryPerformanceCounter (&performanceCountStart) == 0)
63616359
goto counter_error;
63626360

@@ -6394,6 +6392,12 @@ static BOOL PerformBenchmark(HWND hBenchDlg, HWND hwndDlg)
63946392
STREEBOG_add(&stctx, lpTestBuffer, benchmarkBufferSize);
63956393
STREEBOG_finalize(&stctx, (unsigned char *)digest);
63966394
break;
6395+
case ARGON2:
6396+
// For Argon2, we measure speed of the underlying blake2b hash function
6397+
blake2b_init(&b2ctx, BLAKE2B_OUTBYTES);
6398+
blake2b_update(&b2ctx, lpTestBuffer, benchmarkBufferSize);
6399+
blake2b_final(&b2ctx, digest, BLAKE2B_OUTBYTES);
6400+
break;
63976401

63986402
}
63996403
#endif

src/Common/Pkcs5.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include <memory.h>
1717
#include <stdlib.h>
1818
#endif
19-
#include "blake2.h"
19+
#include "blake2s.h"
2020
#ifndef TC_WINDOWS_BOOT
2121
#include "Sha2.h"
2222
#include "Whirlpool.h"

src/Common/Random.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,9 @@ BOOL Randmix ()
258258
{
259259
unsigned char hashOutputBuffer [MAX_DIGESTSIZE];
260260
#ifndef WOLFCRYPT_BACKEND
261-
WHIRLPOOL_CTX wctx;
262-
blake2s_state bctx;
261+
WHIRLPOOL_CTX wctx;
262+
blake2s_state bctx;
263+
blake2b_state b2ctx;
263264
STREEBOG_CTX stctx;
264265
#endif
265266
sha512_ctx sctx;
@@ -314,9 +315,8 @@ BOOL Randmix ()
314315
sha256_end (hashOutputBuffer, &s256ctx);
315316
break;
316317

317-
#ifndef WOLFCRYPT_BACKEND
318-
case BLAKE2S:
319-
case ARGON2: // in case of Argon2, we use Blake2s
318+
#ifndef WOLFCRYPT_BACKEND
319+
case BLAKE2S:
320320
blake2s_init(&bctx);
321321
blake2s_update(&bctx, pRandPool, RNG_POOL_SIZE);
322322
blake2s_final(&bctx, hashOutputBuffer);
@@ -333,7 +333,14 @@ BOOL Randmix ()
333333
STREEBOG_add (&stctx, pRandPool, RNG_POOL_SIZE);
334334
STREEBOG_finalize (&stctx, hashOutputBuffer);
335335
break;
336-
#endif
336+
337+
case ARGON2:
338+
// For Argon2, we use the underlying Blake2b hash function
339+
blake2b_init(&b2ctx, BLAKE2B_OUTBYTES);
340+
blake2b_update(&b2ctx, pRandPool, RNG_POOL_SIZE);
341+
blake2b_final(&b2ctx, hashOutputBuffer, BLAKE2B_OUTBYTES);
342+
break;
343+
#endif
337344
default:
338345
// Unknown/wrong ID
339346
TC_THROW_FATAL_EXCEPTION;

src/Crypto/Argon2/src/blake2/blake2b.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "Crypto/config.h"
1919
#include "Crypto/cpu.h"
2020
#include "Crypto/misc.h"
21-
#include "blake2.h"
21+
#include "blake2b.h"
2222
#include "blake2-impl.h"
2323

2424
static const uint64_t blake2b_IV[8] = {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ typedef struct __blake2b_state {
6161
/* Ensure param structs have not been wrongly padded */
6262
/* Poor man's static_assert */
6363
enum {
64-
blake2_size_check_0 = 1 / !!(CHAR_BIT == 8),
64+
blake2_size_check_0 = 1 / (!!(CHAR_BIT == 8) ? 1 : 0),
6565
blake2_size_check_2 =
66-
1 / !!(sizeof(blake2b_param) == sizeof(uint64_t) * CHAR_BIT)
66+
1 / (!!(sizeof(blake2b_param) == sizeof(uint64_t) * CHAR_BIT) ? 1 : 0)
6767
};
6868

6969
/* Streaming API */

src/Crypto/Argon2/src/blake2/blamka-round-ref.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#ifndef BLAKE_ROUND_MKA_H
1919
#define BLAKE_ROUND_MKA_H
2020

21-
#include "blake2.h"
21+
#include "blake2b.h"
2222
#include "blake2-impl.h"
2323

2424
/* designed by the Lyra PHC team */

src/Crypto/Argon2/src/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#endif
2727
#include "Crypto/cpu.h"
2828
#include "Crypto/misc.h"
29-
#include "blake2/blake2.h"
29+
#include "blake2/blake2b.h"
3030
#include "blake2/blake2-impl.h"
3131

3232
#define secure_wipe_memory(v, n) burn((v), (n))

src/Crypto/Argon2/src/opt_avx2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
#if defined(__AVX2__)
2828

29-
#include "blake2/blake2.h"
29+
#include "blake2/blake2b.h"
3030
#include "blake2/blamka-round-opt.h"
3131

3232
/*

0 commit comments

Comments
 (0)