diff --git a/deps/ncrypto/ncrypto.cc b/deps/ncrypto/ncrypto.cc index a2bfe874650..741c3510e19 100644 --- a/deps/ncrypto/ncrypto.cc +++ b/deps/ncrypto/ncrypto.cc @@ -1897,7 +1897,7 @@ EVPKeyPointer EVPKeyPointer::NewRawPrivate( EVP_PKEY_new_raw_private_key(id, nullptr, data.data, data.len)); } -#if OPENSSL_VERSION_MAJOR >= 3 && OPENSSL_VERSION_MINOR >= 5 +#if OPENSSL_WITH_PQC EVPKeyPointer EVPKeyPointer::NewRawSeed( int id, const Buffer& data) { if (id == 0) return {}; @@ -1968,7 +1968,7 @@ EVP_PKEY* EVPKeyPointer::release() { int EVPKeyPointer::id(const EVP_PKEY* key) { if (key == nullptr) return 0; int type = EVP_PKEY_id(key); -#if OPENSSL_VERSION_MAJOR >= 3 && OPENSSL_VERSION_MINOR >= 5 +#if OPENSSL_WITH_PQC // https://github.com/openssl/openssl/issues/27738#issuecomment-3013215870 if (type == -1) { if (EVP_PKEY_is_a(key, "ML-DSA-44")) return EVP_PKEY_ML_DSA_44; @@ -2032,7 +2032,7 @@ DataPointer EVPKeyPointer::rawPublicKey() const { return {}; } -#if OPENSSL_VERSION_MAJOR >= 3 && OPENSSL_VERSION_MINOR >= 5 +#if OPENSSL_WITH_PQC DataPointer EVPKeyPointer::rawSeed() const { if (!pkey_) return {}; switch (id()) { @@ -2515,7 +2515,7 @@ bool EVPKeyPointer::isOneShotVariant() const { switch (type) { case EVP_PKEY_ED25519: case EVP_PKEY_ED448: -#if OPENSSL_VERSION_MAJOR >= 3 && OPENSSL_VERSION_MINOR >= 5 +#if OPENSSL_WITH_PQC case EVP_PKEY_ML_DSA_44: case EVP_PKEY_ML_DSA_65: case EVP_PKEY_ML_DSA_87: diff --git a/deps/ncrypto/ncrypto.h b/deps/ncrypto/ncrypto.h index 82af70798f3..f8f63411175 100644 --- a/deps/ncrypto/ncrypto.h +++ b/deps/ncrypto/ncrypto.h @@ -28,11 +28,14 @@ #include #endif // OPENSSL_FIPS -#if OPENSSL_VERSION_MAJOR >= 3 -#define OSSL3_CONST const -#if OPENSSL_VERSION_MINOR >= 5 +// Define OPENSSL_WITH_PQC for post-quantum cryptography support +#if OPENSSL_VERSION_NUMBER >= 0x30500000L +#define OPENSSL_WITH_PQC 1 #include #endif + +#if OPENSSL_VERSION_MAJOR >= 3 +#define OSSL3_CONST const #else #define OSSL3_CONST #endif @@ -820,7 +823,7 @@ class EVPKeyPointer final { const Buffer& data); static EVPKeyPointer NewRawPrivate(int id, const Buffer& data); -#if OPENSSL_VERSION_MAJOR >= 3 && OPENSSL_VERSION_MINOR >= 5 +#if OPENSSL_WITH_PQC static EVPKeyPointer NewRawSeed(int id, const Buffer& data); #endif @@ -917,7 +920,7 @@ class EVPKeyPointer final { DataPointer rawPrivateKey() const; BIOPointer derPublicKey() const; -#if OPENSSL_VERSION_MAJOR >= 3 && OPENSSL_VERSION_MINOR >= 5 +#if OPENSSL_WITH_PQC DataPointer rawSeed() const; #endif diff --git a/src/crypto/crypto_keys.cc b/src/crypto/crypto_keys.cc index 167018d7d20..91044a94dc6 100644 --- a/src/crypto/crypto_keys.cc +++ b/src/crypto/crypto_keys.cc @@ -177,7 +177,7 @@ bool ExportJWKAsymmetricKey(Environment* env, // Fall through case EVP_PKEY_X448: return ExportJWKEdKey(env, key, target); -#if OPENSSL_VERSION_MAJOR >= 3 && OPENSSL_VERSION_MINOR >= 5 +#if OPENSSL_WITH_PQC case EVP_PKEY_ML_DSA_44: // Fall through case EVP_PKEY_ML_DSA_65: @@ -280,7 +280,7 @@ int GetNidFromName(const char* name) { nid = EVP_PKEY_X25519; } else if (strcmp(name, "X448") == 0) { nid = EVP_PKEY_X448; -#if OPENSSL_VERSION_MAJOR >= 3 && OPENSSL_VERSION_MINOR >= 5 +#if OPENSSL_WITH_PQC } else if (strcmp(name, "ML-DSA-44") == 0) { nid = EVP_PKEY_ML_DSA_44; } else if (strcmp(name, "ML-DSA-65") == 0) { @@ -620,7 +620,7 @@ Local KeyObjectHandle::Initialize(Environment* env) { SetProtoMethod(isolate, templ, "exportJwk", ExportJWK); SetProtoMethod(isolate, templ, "initECRaw", InitECRaw); SetProtoMethod(isolate, templ, "initEDRaw", InitEDRaw); -#if OPENSSL_VERSION_MAJOR >= 3 && OPENSSL_VERSION_MINOR >= 5 +#if OPENSSL_WITH_PQC SetProtoMethod(isolate, templ, "initMlDsaRaw", InitMlDsaRaw); #endif SetProtoMethod(isolate, templ, "initJwk", InitJWK); @@ -643,7 +643,7 @@ void KeyObjectHandle::RegisterExternalReferences( registry->Register(ExportJWK); registry->Register(InitECRaw); registry->Register(InitEDRaw); -#if OPENSSL_VERSION_MAJOR >= 3 && OPENSSL_VERSION_MINOR >= 5 +#if OPENSSL_WITH_PQC registry->Register(InitMlDsaRaw); #endif registry->Register(InitJWK); @@ -838,7 +838,7 @@ void KeyObjectHandle::InitEDRaw(const FunctionCallbackInfo& args) { args.GetReturnValue().Set(true); } -#if OPENSSL_VERSION_MAJOR >= 3 && OPENSSL_VERSION_MINOR >= 5 +#if OPENSSL_WITH_PQC void KeyObjectHandle::InitMlDsaRaw(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); KeyObjectHandle* key; @@ -971,7 +971,7 @@ Local KeyObjectHandle::GetAsymmetricKeyType() const { return env()->crypto_x25519_string(); case EVP_PKEY_X448: return env()->crypto_x448_string(); -#if OPENSSL_VERSION_MAJOR >= 3 && OPENSSL_VERSION_MINOR >= 5 +#if OPENSSL_WITH_PQC case EVP_PKEY_ML_DSA_44: return env()->crypto_ml_dsa_44_string(); case EVP_PKEY_ML_DSA_65: @@ -1254,7 +1254,7 @@ void Initialize(Environment* env, Local target) { NODE_DEFINE_CONSTANT(target, kWebCryptoKeyFormatJWK); NODE_DEFINE_CONSTANT(target, EVP_PKEY_ED25519); NODE_DEFINE_CONSTANT(target, EVP_PKEY_ED448); -#if OPENSSL_VERSION_MAJOR >= 3 && OPENSSL_VERSION_MINOR >= 5 +#if OPENSSL_WITH_PQC NODE_DEFINE_CONSTANT(target, EVP_PKEY_ML_DSA_44); NODE_DEFINE_CONSTANT(target, EVP_PKEY_ML_DSA_65); NODE_DEFINE_CONSTANT(target, EVP_PKEY_ML_DSA_87); diff --git a/src/crypto/crypto_keys.h b/src/crypto/crypto_keys.h index 2a2a38ebe0e..f18e3b023c0 100644 --- a/src/crypto/crypto_keys.h +++ b/src/crypto/crypto_keys.h @@ -152,7 +152,7 @@ class KeyObjectHandle : public BaseObject { static void Init(const v8::FunctionCallbackInfo& args); static void InitECRaw(const v8::FunctionCallbackInfo& args); static void InitEDRaw(const v8::FunctionCallbackInfo& args); -#if OPENSSL_VERSION_MAJOR >= 3 && OPENSSL_VERSION_MINOR >= 5 +#if OPENSSL_WITH_PQC static void InitMlDsaRaw(const v8::FunctionCallbackInfo& args); #endif static void InitJWK(const v8::FunctionCallbackInfo& args); diff --git a/src/crypto/crypto_ml_dsa.cc b/src/crypto/crypto_ml_dsa.cc index 119597c634c..65f7053cc1f 100644 --- a/src/crypto/crypto_ml_dsa.cc +++ b/src/crypto/crypto_ml_dsa.cc @@ -14,7 +14,7 @@ using v8::Value; namespace crypto { -#if OPENSSL_VERSION_MAJOR >= 3 && OPENSSL_VERSION_MINOR >= 5 +#if OPENSSL_WITH_PQC constexpr const char* GetMlDsaAlgorithmName(int id) { switch (id) { case EVP_PKEY_ML_DSA_44: diff --git a/src/crypto/crypto_ml_dsa.h b/src/crypto/crypto_ml_dsa.h index 6ecdedaee12..e4739fcdd7f 100644 --- a/src/crypto/crypto_ml_dsa.h +++ b/src/crypto/crypto_ml_dsa.h @@ -9,7 +9,7 @@ namespace node { namespace crypto { -#if OPENSSL_VERSION_MAJOR >= 3 && OPENSSL_VERSION_MINOR >= 5 +#if OPENSSL_WITH_PQC bool ExportJwkMlDsaKey(Environment* env, const KeyObjectData& key, v8::Local target);