Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: nodejs/node
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: d4aebbb92b23ccd896b05126f30a577894930ff6
Choose a base ref
..
head repository: nodejs/node
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0f03843469b0bfcabf6a10e55bd0545aa131236f
Choose a head ref
Showing with 38 additions and 33 deletions.
  1. +2 βˆ’2 lib/internal/crypto/keygen.js
  2. +2 βˆ’2 lib/internal/crypto/rsa.js
  3. +31 βˆ’26 lib/internal/crypto/util.js
  4. +1 βˆ’1 src/crypto/crypto_rsa.cc
  5. +2 βˆ’2 src/crypto/crypto_rsa.h
4 changes: 2 additions & 2 deletions lib/internal/crypto/keygen.js
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ const {
kCryptoJobAsync,
kCryptoJobSync,
kKeyVariantRSA_PSS,
kKeyVariantRSA_SSA_PKCS1_V1_5,
kKeyVariantRSA_SSA_PKCS1_v1_5,
EVP_PKEY_ED25519,
EVP_PKEY_ED448,
EVP_PKEY_X25519,
@@ -183,7 +183,7 @@ function createJob(mode, type, options) {
if (type === 'rsa') {
return new RsaKeyPairGenJob(
mode,
kKeyVariantRSA_SSA_PKCS1_V1_5, // Used also for RSA-OAEP
kKeyVariantRSA_SSA_PKCS1_v1_5, // Used also for RSA-OAEP
modulusLength,
publicExponent,
...encoding);
4 changes: 2 additions & 2 deletions lib/internal/crypto/rsa.js
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ const {
kCryptoJobAsync,
kSignJobModeSign,
kSignJobModeVerify,
kKeyVariantRSA_SSA_PKCS1_V1_5,
kKeyVariantRSA_SSA_PKCS1_v1_5,
kKeyVariantRSA_PSS,
kKeyVariantRSA_OAEP,
kKeyTypePrivate,
@@ -66,7 +66,7 @@ const {
} = require('internal/crypto/keygen');

const kRsaVariants = {
'RSASSA-PKCS1-v1_5': kKeyVariantRSA_SSA_PKCS1_V1_5,
'RSASSA-PKCS1-v1_5': kKeyVariantRSA_SSA_PKCS1_v1_5,
'RSA-PSS': kKeyVariantRSA_PSS,
'RSA-OAEP': kKeyVariantRSA_OAEP,
};
57 changes: 31 additions & 26 deletions lib/internal/crypto/util.js
Original file line number Diff line number Diff line change
@@ -6,9 +6,9 @@ const {
BigInt,
FunctionPrototypeBind,
Number,
ObjectKeys,
Promise,
StringPrototypeToLowerCase,
StringPrototypeToUpperCase,
Symbol,
} = primordials;

@@ -159,31 +159,32 @@ const kAesKeyLengths = [128, 192, 256];

// These are the only algorithms we currently support
// via the Web Crypto API
const kAlgorithms = [
'rsassa-pkcs1-v1_5',
'rsa-pss',
'rsa-oaep',
'ecdsa',
'ecdh',
'aes-ctr',
'aes-cbc',
'aes-gcm',
'aes-kw',
'hmac',
'sha-1',
'sha-256',
'sha-384',
'sha-512',
'hkdf',
'pbkdf2',
const kAlgorithms = {
'rsassa-pkcs1-v1_5': 'RSASSA-PKCS1-v1_5',
'rsa-pss': 'RSA-PSS',
'rsa-oaep': 'RSA-OAEP',
'ecdsa': 'ECDSA',
'ecdh': 'ECDH',
'aes-ctr': 'AES-CTR',
'aes-cbc': 'AES-CBC',
'aes-gcm': 'AES-GCM',
'aes-kw': 'AES-KW',
'hmac': 'HMAC',
'sha-1': 'SHA-1',
'sha-256': 'SHA-256',
'sha-384': 'SHA-384',
'sha-512': 'SHA-512',
'hkdf': 'HKDF',
'pbkdf2': 'PBKDF2',
// Following here are Node.js specific extensions. All
// should be prefixed with 'node-'
'node-dsa',
'node-dh',
'node-scrypt',
'node-ed25519',
'node-ed448',
];
'node-dsa': 'NODE-DSA',
'node-dh': 'NODE-DH',
'node-scrypt': 'NODE-SCRYPT',
'node-ed25519': 'NODE-ED25519',
'node-ed448': 'NODE-ED448',
};
const kAlgorithmsKeys = ObjectKeys(kAlgorithms);

// These are the only export and import formats we currently
// support via the Web Crypto API
@@ -221,7 +222,7 @@ function normalizeAlgorithm(algorithm, label = 'algorithm') {
let hash;
if (typeof name !== 'string' ||
!ArrayPrototypeIncludes(
kAlgorithms,
kAlgorithmsKeys,
StringPrototypeToLowerCase(name))) {
throw lazyDOMException('Unrecognized name.', 'NotSupportedError');
}
@@ -230,7 +231,11 @@ function normalizeAlgorithm(algorithm, label = 'algorithm') {
if (!ArrayPrototypeIncludes(kHashTypes, hash.name))
throw lazyDOMException('Unrecognized name.', 'NotSupportedError');
}
return { ...algorithm, name: StringPrototypeToUpperCase(name), hash };
return {
...algorithm,
name: kAlgorithms[StringPrototypeToLowerCase(name)],
hash,
};
}
}
throw lazyDOMException('Unrecognized name.', 'NotSupportedError');
2 changes: 1 addition & 1 deletion src/crypto/crypto_rsa.cc
Original file line number Diff line number Diff line change
@@ -559,7 +559,7 @@ void Initialize(Environment* env, Local<Object> target) {
RSAKeyExportJob::Initialize(env, target);
RSACipherJob::Initialize(env, target);

NODE_DEFINE_CONSTANT(target, kKeyVariantRSA_SSA_PKCS1_V1_5);
NODE_DEFINE_CONSTANT(target, kKeyVariantRSA_SSA_PKCS1_v1_5);
NODE_DEFINE_CONSTANT(target, kKeyVariantRSA_PSS);
NODE_DEFINE_CONSTANT(target, kKeyVariantRSA_OAEP);
}
4 changes: 2 additions & 2 deletions src/crypto/crypto_rsa.h
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
namespace node {
namespace crypto {
enum RSAKeyVariant {
kKeyVariantRSA_SSA_PKCS1_V1_5,
kKeyVariantRSA_SSA_PKCS1_v1_5,
kKeyVariantRSA_PSS,
kKeyVariantRSA_OAEP
};
@@ -53,7 +53,7 @@ struct RsaKeyGenTraits final {
using RSAKeyPairGenJob = KeyGenJob<KeyPairGenTraits<RsaKeyGenTraits>>;

struct RSAKeyExportConfig final : public MemoryRetainer {
RSAKeyVariant variant = kKeyVariantRSA_SSA_PKCS1_V1_5;
RSAKeyVariant variant = kKeyVariantRSA_SSA_PKCS1_v1_5;
SET_NO_MEMORY_INFO()
SET_MEMORY_INFO_NAME(RSAKeyExportConfig)
SET_SELF_SIZE(RSAKeyExportConfig)