Skip to content

Commit 3e90a73

Browse files
committed
fixup! crypto: add KMAC Web Cryptography algorithms
1 parent dbbe58e commit 3e90a73

14 files changed

+27
-35
lines changed

deps/ncrypto/ncrypto.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4413,7 +4413,7 @@ HMACCtxPointer HMACCtxPointer::New() {
44134413
return HMACCtxPointer(HMAC_CTX_new());
44144414
}
44154415

4416-
#if OPENSSL_VERSION_NUMBER >= 0x30100000L
4416+
#if OPENSSL_VERSION_MAJOR >= 3
44174417
EVPMacPointer::EVPMacPointer(EVP_MAC* mac) : mac_(mac) {}
44184418

44194419
EVPMacPointer::EVPMacPointer(EVPMacPointer&& other) noexcept
@@ -4501,7 +4501,7 @@ EVPMacCtxPointer EVPMacCtxPointer::New(EVP_MAC* mac) {
45014501
if (!mac) return EVPMacCtxPointer();
45024502
return EVPMacCtxPointer(EVP_MAC_CTX_new(mac));
45034503
}
4504-
#endif // OPENSSL_VERSION_NUMBER >= 0x30100000L
4504+
#endif // OPENSSL_VERSION_MAJOR >= 3
45054505

45064506
DataPointer hashDigest(const Buffer<const unsigned char>& buf,
45074507
const EVP_MD* md) {

deps/ncrypto/ncrypto.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,7 +1453,7 @@ class HMACCtxPointer final {
14531453
DeleteFnPtr<HMAC_CTX, HMAC_CTX_free> ctx_;
14541454
};
14551455

1456-
#if OPENSSL_VERSION_NUMBER >= 0x30100000L
1456+
#if OPENSSL_VERSION_MAJOR >= 3
14571457
class EVPMacPointer final {
14581458
public:
14591459
EVPMacPointer() = default;
@@ -1501,7 +1501,7 @@ class EVPMacCtxPointer final {
15011501
private:
15021502
DeleteFnPtr<EVP_MAC_CTX, EVP_MAC_CTX_free> ctx_;
15031503
};
1504-
#endif // OPENSSL_VERSION_NUMBER >= 0x30100000L
1504+
#endif // OPENSSL_VERSION_MAJOR >= 3
15051505

15061506
#ifndef OPENSSL_NO_ENGINE
15071507
class EnginePointer final {

doc/api/webcrypto.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ Algorithms:
120120
* `'ChaCha20-Poly1305'`
121121
* `'cSHAKE128'`
122122
* `'cSHAKE256'`
123-
* `'KMAC128'`[^openssl31]
124-
* `'KMAC256'`[^openssl31]
123+
* `'KMAC128'`[^openssl30]
124+
* `'KMAC256'`[^openssl30]
125125
* `'ML-DSA-44'`[^openssl35]
126126
* `'ML-DSA-65'`[^openssl35]
127127
* `'ML-DSA-87'`[^openssl35]
@@ -2684,8 +2684,6 @@ The length (in bytes) of the random salt to use.
26842684
26852685
[^openssl30]: Requires OpenSSL >= 3.0
26862686
2687-
[^openssl31]: Requires OpenSSL >= 3.1
2688-
26892687
[^openssl32]: Requires OpenSSL >= 3.2
26902688
26912689
[^openssl35]: Requires OpenSSL >= 3.5

src/crypto/crypto_kmac.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "node_internals.h"
44
#include "threadpoolwork-inl.h"
55

6-
#if OPENSSL_VERSION_NUMBER >= 0x30100000L
6+
#if OPENSSL_VERSION_MAJOR >= 3
77
#include <openssl/core_names.h>
88
#include <openssl/params.h>
99
#include "crypto/crypto_keys.h"

src/crypto/crypto_kmac.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
namespace node::crypto {
1212

13-
// KMAC (Keccak Message Authentication Code) is available in OpenSSL 3.1+.
14-
#if OPENSSL_VERSION_NUMBER >= 0x30100000L
13+
// KMAC (Keccak Message Authentication Code) is available since OpenSSL 3.0.
14+
#if OPENSSL_VERSION_MAJOR >= 3
1515

1616
struct KmacConfig final : public MemoryRetainer {
1717
CryptoJobMode job_mode;

src/node_crypto.cc

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,13 @@ namespace crypto {
6666
#define ARGON2_NAMESPACE_LIST(V)
6767
#endif // !OPENSSL_NO_ARGON2 && OpenSSL >= 3.2
6868

69-
#if OPENSSL_VERSION_NUMBER >= 0x30100000L
70-
#define KMAC_NAMESPACE_LIST(V) V(Kmac)
71-
#else
72-
#define KMAC_NAMESPACE_LIST(V)
73-
#endif // OpenSSL >= 3.1
74-
75-
// KEM functionality requires OpenSSL 3.0.0 or later
69+
// KEM and KMAC functionality requires OpenSSL 3.0.0 or later
7670
#if OPENSSL_VERSION_MAJOR >= 3
7771
#define KEM_NAMESPACE_LIST(V) V(KEM)
72+
#define KMAC_NAMESPACE_LIST(V) V(Kmac)
7873
#else
7974
#define KEM_NAMESPACE_LIST(V)
75+
#define KMAC_NAMESPACE_LIST(V)
8076
#endif
8177

8278
#ifdef OPENSSL_NO_SCRYPT

test/fixtures/webcrypto/supports-modern-algorithms.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const shake128 = crypto.getHashes().includes('shake128');
88
const shake256 = crypto.getHashes().includes('shake256');
99
const chacha = crypto.getCiphers().includes('chacha20-poly1305');
1010
const ocb = hasOpenSSL(3);
11-
const kmac = hasOpenSSL(3, 1);
11+
const kmac = hasOpenSSL(3);
1212

1313
const { subtle } = globalThis.crypto;
1414
const X25519 = await subtle.generateKey('X25519', false, ['deriveBits', 'deriveKey']);

test/parallel/test-crypto-key-objects-to-crypto-key.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ if (hasOpenSSL(3, 5)) {
206206
}
207207
}
208208

209-
if (hasOpenSSL(3, 1)) {
209+
if (hasOpenSSL(3)) {
210210
for (const algorithm of ['KMAC128', 'KMAC256']) {
211211
const hmac = createSecretKey(randomBytes(32));
212212
const usages = ['sign', 'verify'];

test/parallel/test-webcrypto-derivekey.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ const { KeyObject } = require('crypto');
168168
// [{ name: 'HMAC', hash: 'SHA3-512' }, 'sign', 512],
169169
];
170170

171-
if (hasOpenSSL(3, 1)) {
171+
if (hasOpenSSL(3)) {
172172
vectors.push(
173173
['KMAC128', 'sign', 128],
174174
[{ name: 'KMAC128', length: 384 }, 'sign', 384],
@@ -221,7 +221,7 @@ const { KeyObject } = require('crypto');
221221
// [{ name: 'HMAC', hash: 'SHA3-512' }, 'sign', 512],
222222
];
223223

224-
if (hasOpenSSL(3, 1)) {
224+
if (hasOpenSSL(3)) {
225225
vectors.push(
226226
['KMAC128', 'sign', 128],
227227
[{ name: 'KMAC128', length: 384 }, 'sign', 384],

test/parallel/test-webcrypto-export-import.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ const { createPrivateKey, createPublicKey, createSecretKey } = require('crypto')
167167
}
168168

169169
// Import/Export KMAC Secret Key
170-
if (hasOpenSSL(3, 1)) {
170+
if (hasOpenSSL(3)) {
171171
async function test(name) {
172172
const keyData = globalThis.crypto.getRandomValues(new Uint8Array(32));
173173
const key = await subtle.importKey(

0 commit comments

Comments
 (0)