Skip to content

Commit 823dce3

Browse files
panvatargos
authored andcommitted
src: update OpenSSL pqc checks
PR-URL: #59436 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Richard Lau <richard.lau@ibm.com>
1 parent f54ace6 commit 823dce3

File tree

6 files changed

+22
-19
lines changed

6 files changed

+22
-19
lines changed

deps/ncrypto/ncrypto.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,7 +1897,7 @@ EVPKeyPointer EVPKeyPointer::NewRawPrivate(
18971897
EVP_PKEY_new_raw_private_key(id, nullptr, data.data, data.len));
18981898
}
18991899

1900-
#if OPENSSL_VERSION_MAJOR >= 3 && OPENSSL_VERSION_MINOR >= 5
1900+
#if OPENSSL_WITH_PQC
19011901
EVPKeyPointer EVPKeyPointer::NewRawSeed(
19021902
int id, const Buffer<const unsigned char>& data) {
19031903
if (id == 0) return {};
@@ -1968,7 +1968,7 @@ EVP_PKEY* EVPKeyPointer::release() {
19681968
int EVPKeyPointer::id(const EVP_PKEY* key) {
19691969
if (key == nullptr) return 0;
19701970
int type = EVP_PKEY_id(key);
1971-
#if OPENSSL_VERSION_MAJOR >= 3 && OPENSSL_VERSION_MINOR >= 5
1971+
#if OPENSSL_WITH_PQC
19721972
// https://github.com/openssl/openssl/issues/27738#issuecomment-3013215870
19731973
if (type == -1) {
19741974
if (EVP_PKEY_is_a(key, "ML-DSA-44")) return EVP_PKEY_ML_DSA_44;
@@ -2032,7 +2032,7 @@ DataPointer EVPKeyPointer::rawPublicKey() const {
20322032
return {};
20332033
}
20342034

2035-
#if OPENSSL_VERSION_MAJOR >= 3 && OPENSSL_VERSION_MINOR >= 5
2035+
#if OPENSSL_WITH_PQC
20362036
DataPointer EVPKeyPointer::rawSeed() const {
20372037
if (!pkey_) return {};
20382038
switch (id()) {
@@ -2515,7 +2515,7 @@ bool EVPKeyPointer::isOneShotVariant() const {
25152515
switch (type) {
25162516
case EVP_PKEY_ED25519:
25172517
case EVP_PKEY_ED448:
2518-
#if OPENSSL_VERSION_MAJOR >= 3 && OPENSSL_VERSION_MINOR >= 5
2518+
#if OPENSSL_WITH_PQC
25192519
case EVP_PKEY_ML_DSA_44:
25202520
case EVP_PKEY_ML_DSA_65:
25212521
case EVP_PKEY_ML_DSA_87:

deps/ncrypto/ncrypto.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,14 @@
2828
#include <openssl/fips.h>
2929
#endif // OPENSSL_FIPS
3030

31-
#if OPENSSL_VERSION_MAJOR >= 3
32-
#define OSSL3_CONST const
33-
#if OPENSSL_VERSION_MINOR >= 5
31+
// Define OPENSSL_WITH_PQC for post-quantum cryptography support
32+
#if OPENSSL_VERSION_NUMBER >= 0x30500000L
33+
#define OPENSSL_WITH_PQC 1
3434
#include <openssl/core_names.h>
3535
#endif
36+
37+
#if OPENSSL_VERSION_MAJOR >= 3
38+
#define OSSL3_CONST const
3639
#else
3740
#define OSSL3_CONST
3841
#endif
@@ -820,7 +823,7 @@ class EVPKeyPointer final {
820823
const Buffer<const unsigned char>& data);
821824
static EVPKeyPointer NewRawPrivate(int id,
822825
const Buffer<const unsigned char>& data);
823-
#if OPENSSL_VERSION_MAJOR >= 3 && OPENSSL_VERSION_MINOR >= 5
826+
#if OPENSSL_WITH_PQC
824827
static EVPKeyPointer NewRawSeed(int id,
825828
const Buffer<const unsigned char>& data);
826829
#endif
@@ -917,7 +920,7 @@ class EVPKeyPointer final {
917920
DataPointer rawPrivateKey() const;
918921
BIOPointer derPublicKey() const;
919922

920-
#if OPENSSL_VERSION_MAJOR >= 3 && OPENSSL_VERSION_MINOR >= 5
923+
#if OPENSSL_WITH_PQC
921924
DataPointer rawSeed() const;
922925
#endif
923926

src/crypto/crypto_keys.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ bool ExportJWKAsymmetricKey(Environment* env,
177177
// Fall through
178178
case EVP_PKEY_X448:
179179
return ExportJWKEdKey(env, key, target);
180-
#if OPENSSL_VERSION_MAJOR >= 3 && OPENSSL_VERSION_MINOR >= 5
180+
#if OPENSSL_WITH_PQC
181181
case EVP_PKEY_ML_DSA_44:
182182
// Fall through
183183
case EVP_PKEY_ML_DSA_65:
@@ -280,7 +280,7 @@ int GetNidFromName(const char* name) {
280280
nid = EVP_PKEY_X25519;
281281
} else if (strcmp(name, "X448") == 0) {
282282
nid = EVP_PKEY_X448;
283-
#if OPENSSL_VERSION_MAJOR >= 3 && OPENSSL_VERSION_MINOR >= 5
283+
#if OPENSSL_WITH_PQC
284284
} else if (strcmp(name, "ML-DSA-44") == 0) {
285285
nid = EVP_PKEY_ML_DSA_44;
286286
} else if (strcmp(name, "ML-DSA-65") == 0) {
@@ -620,7 +620,7 @@ Local<Function> KeyObjectHandle::Initialize(Environment* env) {
620620
SetProtoMethod(isolate, templ, "exportJwk", ExportJWK);
621621
SetProtoMethod(isolate, templ, "initECRaw", InitECRaw);
622622
SetProtoMethod(isolate, templ, "initEDRaw", InitEDRaw);
623-
#if OPENSSL_VERSION_MAJOR >= 3 && OPENSSL_VERSION_MINOR >= 5
623+
#if OPENSSL_WITH_PQC
624624
SetProtoMethod(isolate, templ, "initMlDsaRaw", InitMlDsaRaw);
625625
#endif
626626
SetProtoMethod(isolate, templ, "initJwk", InitJWK);
@@ -643,7 +643,7 @@ void KeyObjectHandle::RegisterExternalReferences(
643643
registry->Register(ExportJWK);
644644
registry->Register(InitECRaw);
645645
registry->Register(InitEDRaw);
646-
#if OPENSSL_VERSION_MAJOR >= 3 && OPENSSL_VERSION_MINOR >= 5
646+
#if OPENSSL_WITH_PQC
647647
registry->Register(InitMlDsaRaw);
648648
#endif
649649
registry->Register(InitJWK);
@@ -838,7 +838,7 @@ void KeyObjectHandle::InitEDRaw(const FunctionCallbackInfo<Value>& args) {
838838
args.GetReturnValue().Set(true);
839839
}
840840

841-
#if OPENSSL_VERSION_MAJOR >= 3 && OPENSSL_VERSION_MINOR >= 5
841+
#if OPENSSL_WITH_PQC
842842
void KeyObjectHandle::InitMlDsaRaw(const FunctionCallbackInfo<Value>& args) {
843843
Environment* env = Environment::GetCurrent(args);
844844
KeyObjectHandle* key;
@@ -971,7 +971,7 @@ Local<Value> KeyObjectHandle::GetAsymmetricKeyType() const {
971971
return env()->crypto_x25519_string();
972972
case EVP_PKEY_X448:
973973
return env()->crypto_x448_string();
974-
#if OPENSSL_VERSION_MAJOR >= 3 && OPENSSL_VERSION_MINOR >= 5
974+
#if OPENSSL_WITH_PQC
975975
case EVP_PKEY_ML_DSA_44:
976976
return env()->crypto_ml_dsa_44_string();
977977
case EVP_PKEY_ML_DSA_65:
@@ -1254,7 +1254,7 @@ void Initialize(Environment* env, Local<Object> target) {
12541254
NODE_DEFINE_CONSTANT(target, kWebCryptoKeyFormatJWK);
12551255
NODE_DEFINE_CONSTANT(target, EVP_PKEY_ED25519);
12561256
NODE_DEFINE_CONSTANT(target, EVP_PKEY_ED448);
1257-
#if OPENSSL_VERSION_MAJOR >= 3 && OPENSSL_VERSION_MINOR >= 5
1257+
#if OPENSSL_WITH_PQC
12581258
NODE_DEFINE_CONSTANT(target, EVP_PKEY_ML_DSA_44);
12591259
NODE_DEFINE_CONSTANT(target, EVP_PKEY_ML_DSA_65);
12601260
NODE_DEFINE_CONSTANT(target, EVP_PKEY_ML_DSA_87);

src/crypto/crypto_keys.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class KeyObjectHandle : public BaseObject {
152152
static void Init(const v8::FunctionCallbackInfo<v8::Value>& args);
153153
static void InitECRaw(const v8::FunctionCallbackInfo<v8::Value>& args);
154154
static void InitEDRaw(const v8::FunctionCallbackInfo<v8::Value>& args);
155-
#if OPENSSL_VERSION_MAJOR >= 3 && OPENSSL_VERSION_MINOR >= 5
155+
#if OPENSSL_WITH_PQC
156156
static void InitMlDsaRaw(const v8::FunctionCallbackInfo<v8::Value>& args);
157157
#endif
158158
static void InitJWK(const v8::FunctionCallbackInfo<v8::Value>& args);

src/crypto/crypto_ml_dsa.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ using v8::Value;
1414

1515
namespace crypto {
1616

17-
#if OPENSSL_VERSION_MAJOR >= 3 && OPENSSL_VERSION_MINOR >= 5
17+
#if OPENSSL_WITH_PQC
1818
constexpr const char* GetMlDsaAlgorithmName(int id) {
1919
switch (id) {
2020
case EVP_PKEY_ML_DSA_44:

src/crypto/crypto_ml_dsa.h

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

1010
namespace node {
1111
namespace crypto {
12-
#if OPENSSL_VERSION_MAJOR >= 3 && OPENSSL_VERSION_MINOR >= 5
12+
#if OPENSSL_WITH_PQC
1313
bool ExportJwkMlDsaKey(Environment* env,
1414
const KeyObjectData& key,
1515
v8::Local<v8::Object> target);

0 commit comments

Comments
 (0)