Skip to content

Commit 6db8774

Browse files
committed
fixup! crypto: add argon2() and argon2Sync() methods
1 parent cf81cfa commit 6db8774

File tree

6 files changed

+19
-11
lines changed

6 files changed

+19
-11
lines changed

deps/ncrypto/ncrypto.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1857,7 +1857,7 @@ DataPointer pbkdf2(const Digest& md,
18571857
return {};
18581858
}
18591859

1860-
#if OPENSSL_VERSION_PREREQ(3, 2)
1860+
#if OPENSSL_VERSION_NUMBER >= 0x30200000L
18611861
#ifndef OPENSSL_NO_ARGON2
18621862
DataPointer argon2(const Buffer<const char>& pass,
18631863
const Buffer<const unsigned char>& salt,
@@ -1914,7 +1914,9 @@ DataPointer argon2(const Buffer<const char>& pass,
19141914
params.reserve(9);
19151915

19161916
params.push_back(OSSL_PARAM_construct_octet_string(
1917-
OSSL_KDF_PARAM_PASSWORD, const_cast<char*>(pass.data), pass.len));
1917+
OSSL_KDF_PARAM_PASSWORD,
1918+
const_cast<char*>(pass.len > 0 ? pass.data : ""),
1919+
pass.len));
19181920
params.push_back(OSSL_PARAM_construct_octet_string(
19191921
OSSL_KDF_PARAM_SALT, const_cast<unsigned char*>(salt.data), salt.len));
19201922
params.push_back(OSSL_PARAM_construct_uint32(OSSL_KDF_PARAM_THREADS, &lanes));

deps/ncrypto/ncrypto.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1553,7 +1553,7 @@ DataPointer pbkdf2(const Digest& md,
15531553
uint32_t iterations,
15541554
size_t length);
15551555

1556-
#if OPENSSL_VERSION_PREREQ(3, 2)
1556+
#if OPENSSL_VERSION_NUMBER >= 0x30200000L
15571557
#ifndef OPENSSL_NO_ARGON2
15581558
enum class Argon2Type { ARGON2D, ARGON2I, ARGON2ID };
15591559

src/crypto/crypto_argon2.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#include "crypto/crypto_argon2.h"
22
#include "async_wrap-inl.h"
3+
#include "threadpoolwork-inl.h"
34

4-
#if OPENSSL_VERSION_PREREQ(3, 2)
5+
#if OPENSSL_VERSION_NUMBER >= 0x30200000L
56
#ifndef OPENSSL_NO_ARGON2
67
#include <openssl/core_names.h>
78

src/crypto/crypto_argon2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "crypto/crypto_util.h"
77

88
namespace node::crypto {
9-
#if !defined(OPENSSL_NO_ARGON2) && OPENSSL_VERSION_PREREQ(3, 2)
9+
#if !defined(OPENSSL_NO_ARGON2) && OPENSSL_VERSION_NUMBER >= 0x30200000L
1010

1111
// Argon2 is a password-based key derivation algorithm
1212
// defined in https://datatracker.ietf.org/doc/html/rfc9106

src/node_crypto.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ namespace crypto {
5959
V(Verify) \
6060
V(X509Certificate)
6161

62-
#if !defined(OPENSSL_NO_ARGON2) && OPENSSL_VERSION_PREREQ(3, 2)
62+
#if !defined(OPENSSL_NO_ARGON2) && OPENSSL_VERSION_NUMBER >= 0x30200000L
6363
#define ARGON2_NAMESPACE_LIST(V) V(Argon2)
6464
#else
6565
#define ARGON2_NAMESPACE_LIST(V)

test/parallel/test-crypto-argon2.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const associatedData = Buffer.alloc(12, 0x04);
2929
const defaults = { message, nonce, parallelism: 1, tagLength: 64, memory: 8, passes: 3 };
3030

3131
const good = [
32-
// test vectors from RFC 9106 https://www.rfc-editor.org/rfc/rfc9106.html#name-test-vectors
32+
// Test vectors from RFC 9106 https://www.rfc-editor.org/rfc/rfc9106.html#name-test-vectors
3333
// and OpenSSL 3.2 https://github.com/openssl/openssl/blob/6dfa998f7ea150f9c6d4e4727cf6d5c82a68a8da/test/recipes/30-test_evp_data/evpkdf_argon2.txt
3434
//
3535
// OpenSSL defaults are:
@@ -56,7 +56,8 @@ const good = [
5656
[
5757
'argon2d',
5858
{ message: '1234567890', nonce: 'saltsalt' },
59-
'd16ad773b1c6400d3193bc3e66271603e9de72bace20af3f89c236f5434cdec99072ddfc6b9c77ea9f386c0e8d7cb0c37cec6ec3277a22c92d5be58ef67c7eaa',
59+
'd16ad773b1c6400d3193bc3e66271603e9de72bace20af3f89c236f5434cdec9' +
60+
'9072ddfc6b9c77ea9f386c0e8d7cb0c37cec6ec3277a22c92d5be58ef67c7eaa',
6061
],
6162
[
6263
'argon2id',
@@ -66,7 +67,8 @@ const good = [
6667
[
6768
'argon2d',
6869
{ message: '1234567890', nonce: 'saltsalt', parallelism: 2, memory: 65536 },
69-
'5ca0ab135de1241454840172696c301c7b8fd99a788cd11cf9699044cadf7fca0a6e3762cb3043a71adf6553db3fd7925101b0ccf8868b098492a4addb2486bc',
70+
'5ca0ab135de1241454840172696c301c7b8fd99a788cd11cf9699044cadf7fca' +
71+
'0a6e3762cb3043a71adf6553db3fd7925101b0ccf8868b098492a4addb2486bc',
7072
],
7173
[
7274
'argon2i',
@@ -81,7 +83,10 @@ const good = [
8183
[
8284
'argon2d',
8385
{ message: '1234567890', nonce: 'saltsalt', parallelism: 2, tagLength: 128, memory: 65536 },
84-
'a86c83a19f0b234ecba8c275d16d059153f961e4c39ec9b1be98b3e73d791789363682443ad594334048634e91c493affed0bc29fd329a0e553c00149d6db19af4e4a354aec14dbd575d78ba87d4a4bc4746666e7a4e6ee1572bbffc2eba308a2d825cb7b41fde3a95d5cff0dfa2d0fdd636b32aea8b4a3c532742d330bd1b90',
86+
'a86c83a19f0b234ecba8c275d16d059153f961e4c39ec9b1be98b3e73d791789' +
87+
'363682443ad594334048634e91c493affed0bc29fd329a0e553c00149d6db19a' +
88+
'f4e4a354aec14dbd575d78ba87d4a4bc4746666e7a4e6ee1572bbffc2eba308a' +
89+
'2d825cb7b41fde3a95d5cff0dfa2d0fdd636b32aea8b4a3c532742d330bd1b90',
8590
],
8691
];
8792

@@ -117,7 +122,7 @@ for (const [algorithm, overrides, param] of bad) {
117122
for (const key of Object.keys(defaults)) {
118123
const expected = {
119124
code: 'ERR_INVALID_ARG_TYPE',
120-
message: new RegExp(`"parameters.${key}"`),
125+
message: new RegExp(`"parameters\\.${key}"`),
121126
};
122127
const parameters = { ...defaults };
123128
delete parameters[key];

0 commit comments

Comments
 (0)