| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c863c75 commit 677ca7e
13 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,7 +20,7 @@ | |||
| 20 | 20 | #include <openssl/core_names.h> | |
| 21 | 21 | #include <openssl/params.h> | |
| 22 | 22 | #include <openssl/provider.h> | |
| 23 | - #if OPENSSL_VERSION_NUMBER >= 0x30200000L | ||
| 23 | + #if OPENSSL_WITH_ARGON2 | ||
| 24 | 24 | #include <openssl/thread.h> | |
| 25 | 25 | #endif | |
| 26 | 26 | #endif | |
@@ -1955,8 +1955,7 @@ DataPointer pbkdf2(const Digest& md, | |||
| 1955 | 1955 | return {}; | |
| 1956 | 1956 | } | |
| 1957 | 1957 | ||
| 1958 | - #if OPENSSL_VERSION_NUMBER >= 0x30200000L | ||
| 1959 | - #ifndef OPENSSL_NO_ARGON2 | ||
| 1958 | + #if OPENSSL_WITH_ARGON2 | ||
| 1960 | 1959 | DataPointer argon2(const Buffer<const char>& pass, | |
| 1961 | 1960 | const Buffer<const unsigned char>& salt, | |
| 1962 | 1961 | uint32_t lanes, | |
@@ -2049,7 +2048,6 @@ DataPointer argon2(const Buffer<const char>& pass, | |||
| 2049 | 2048 | return {}; | |
| 2050 | 2049 | } | |
| 2051 | 2050 | #endif | |
| 2052 | - #endif | ||
| 2053 | 2051 | ||
| 2054 | 2052 | // ============================================================================ | |
| 2055 | 2053 | ||
@@ -4614,7 +4612,7 @@ HMACCtxPointer HMACCtxPointer::New() { | |||
| 4614 | 4612 | return HMACCtxPointer(HMAC_CTX_new()); | |
| 4615 | 4613 | } | |
| 4616 | 4614 | ||
| 4617 | - #if OPENSSL_VERSION_MAJOR >= 3 | ||
| 4615 | + #if OPENSSL_WITH_KMAC | ||
| 4618 | 4616 | EVPMacPointer::EVPMacPointer(EVP_MAC* mac) : mac_(mac) {} | |
| 4619 | 4617 | ||
| 4620 | 4618 | EVPMacPointer::EVPMacPointer(EVPMacPointer&& other) noexcept | |
@@ -4702,7 +4700,7 @@ EVPMacCtxPointer EVPMacCtxPointer::New(EVP_MAC* mac) { | |||
| 4702 | 4700 | if (!mac) return EVPMacCtxPointer(); | |
| 4703 | 4701 | return EVPMacCtxPointer(EVP_MAC_CTX_new(mac)); | |
| 4704 | 4702 | } | |
| 4705 | - #endif // OPENSSL_VERSION_MAJOR >= 3 | ||
| 4703 | + #endif // OPENSSL_WITH_KMAC | ||
| 4706 | 4704 | ||
| 4707 | 4705 | DataPointer hashDigest(const Buffer<const unsigned char>& buf, | |
| 4708 | 4706 | const EVP_MD* md) { | |
@@ -4849,16 +4847,16 @@ const Digest Digest::FromName(const char* name) { | |||
| 4849 | 4847 | ||
| 4850 | 4848 | // ============================================================================ | |
| 4851 | 4849 | // KEM Implementation | |
| 4852 | - #if OPENSSL_VERSION_MAJOR >= 3 | ||
| 4853 | - #if !OPENSSL_VERSION_PREREQ(3, 5) | ||
| 4850 | + #if OPENSSL_WITH_KEM | ||
| 4851 | + #if OPENSSL_WITH_KEM_OPERATION_PARAM | ||
| 4854 | 4852 | bool KEM::SetOperationParameter(EVP_PKEY_CTX* ctx, const EVPKeyPointer& key) { | |
| 4855 | 4853 | const char* operation = nullptr; | |
| 4856 | 4854 | ||
| 4857 | 4855 | switch (EVP_PKEY_id(key.get())) { | |
| 4858 | 4856 | case EVP_PKEY_RSA: | |
| 4859 | 4857 | operation = OSSL_KEM_PARAM_OPERATION_RSASVE; | |
| 4860 | 4858 | break; | |
| 4861 | - #if OPENSSL_VERSION_PREREQ(3, 2) | ||
| 4859 | + #if OPENSSL_WITH_OPENSSL_DHKEM | ||
| 4862 | 4860 | case EVP_PKEY_EC: | |
| 4863 | 4861 | case EVP_PKEY_X25519: | |
| 4864 | 4862 | case EVP_PKEY_X448: | |
@@ -4895,7 +4893,7 @@ std::optional<KEM::EncapsulateResult> KEM::Encapsulate( | |||
| 4895 | 4893 | return std::nullopt; | |
| 4896 | 4894 | } | |
| 4897 | 4895 | ||
| 4898 | - #if !OPENSSL_VERSION_PREREQ(3, 5) | ||
| 4896 | + #if OPENSSL_WITH_KEM_OPERATION_PARAM | ||
| 4899 | 4897 | if (!SetOperationParameter(ctx.get(), public_key)) { | |
| 4900 | 4898 | return std::nullopt; | |
| 4901 | 4899 | } | |
@@ -4936,7 +4934,7 @@ DataPointer KEM::Decapsulate(const EVPKeyPointer& private_key, | |||
| 4936 | 4934 | return {}; | |
| 4937 | 4935 | } | |
| 4938 | 4936 | ||
| 4939 | - #if !OPENSSL_VERSION_PREREQ(3, 5) | ||
| 4937 | + #if OPENSSL_WITH_KEM_OPERATION_PARAM | ||
| 4940 | 4938 | if (!SetOperationParameter(ctx.get(), private_key)) { | |
| 4941 | 4939 | return {}; | |
| 4942 | 4940 | } | |
@@ -4966,6 +4964,6 @@ DataPointer KEM::Decapsulate(const EVPKeyPointer& private_key, | |||
| 4966 | 4964 | return shared_key; | |
| 4967 | 4965 | } | |
| 4968 | 4966 | ||
| 4969 | - #endif // OPENSSL_VERSION_MAJOR >= 3 | ||
| 4967 | + #endif // OPENSSL_WITH_KEM | ||
| 4970 | 4968 | ||
| 4971 | 4969 | } // namespace ncrypto | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -42,20 +42,67 @@ | |||
| 42 | 42 | ||
| 43 | 43 | // The FIPS-related functions are only available | |
| 44 | 44 | // when the OpenSSL itself was compiled with FIPS support. | |
| 45 | - #if defined(OPENSSL_FIPS) && OPENSSL_VERSION_MAJOR < 3 | ||
| 45 | + #if defined(OPENSSL_FIPS) && !OPENSSL_VERSION_PREREQ(3, 0) | ||
| 46 | 46 | #include <openssl/fips.h> | |
| 47 | 47 | #endif // OPENSSL_FIPS | |
| 48 | 48 | ||
| 49 | - // Define OPENSSL_WITH_PQC for post-quantum cryptography support | ||
| 50 | - #if OPENSSL_VERSION_NUMBER >= 0x30500000L | ||
| 49 | + #if OPENSSL_VERSION_PREREQ(3, 0) | ||
| 50 | + #define OPENSSL_WITH_AES_OCB 1 | ||
| 51 | + #else | ||
| 52 | + #define OPENSSL_WITH_AES_OCB 0 | ||
| 53 | + #endif | ||
| 54 | + | ||
| 55 | + #if !defined(OPENSSL_NO_ARGON2) && OPENSSL_VERSION_PREREQ(3, 2) | ||
| 56 | + #define OPENSSL_WITH_ARGON2 1 | ||
| 57 | + #else | ||
| 58 | + #define OPENSSL_WITH_ARGON2 0 | ||
| 59 | + #endif | ||
| 60 | + | ||
| 61 | + #if OPENSSL_VERSION_PREREQ(3, 0) | ||
| 62 | + #define OPENSSL_WITH_KEM 1 | ||
| 63 | + #else | ||
| 64 | + #define OPENSSL_WITH_KEM 0 | ||
| 65 | + #endif | ||
| 66 | + | ||
| 67 | + #if OPENSSL_VERSION_PREREQ(3, 0) | ||
| 68 | + #define OPENSSL_WITH_KMAC 1 | ||
| 69 | + #else | ||
| 70 | + #define OPENSSL_WITH_KMAC 0 | ||
| 71 | + #endif | ||
| 72 | + | ||
| 73 | + #if OPENSSL_VERSION_PREREQ(3, 2) | ||
| 74 | + #define OPENSSL_WITH_SIGNATURE_CONTEXT_STRING 1 | ||
| 75 | + #else | ||
| 76 | + #define OPENSSL_WITH_SIGNATURE_CONTEXT_STRING 0 | ||
| 77 | + #endif | ||
| 78 | + | ||
| 79 | + #if !defined(OPENSSL_IS_BORINGSSL) && OPENSSL_VERSION_PREREQ(3, 2) | ||
| 80 | + #define OPENSSL_WITH_OPENSSL_DHKEM 1 | ||
| 81 | + #else | ||
| 82 | + #define OPENSSL_WITH_OPENSSL_DHKEM 0 | ||
| 83 | + #endif | ||
| 84 | + | ||
| 85 | + #if OPENSSL_WITH_KEM && !OPENSSL_VERSION_PREREQ(3, 5) | ||
| 86 | + #define OPENSSL_WITH_KEM_OPERATION_PARAM 1 | ||
| 87 | + #else | ||
| 88 | + #define OPENSSL_WITH_KEM_OPERATION_PARAM 0 | ||
| 89 | + #endif | ||
| 90 | + | ||
| 91 | + // Define OPENSSL_WITH_PQC for post-quantum cryptography support. | ||
| 92 | + #if OPENSSL_VERSION_PREREQ(3, 5) | ||
| 51 | 93 | #define OPENSSL_WITH_PQC 1 | |
| 94 | + #else | ||
| 95 | + #define OPENSSL_WITH_PQC 0 | ||
| 96 | + #endif | ||
| 97 | + | ||
| 98 | + #if OPENSSL_WITH_PQC | ||
| 52 | 99 | #define EVP_PKEY_ML_KEM_512 NID_ML_KEM_512 | |
| 53 | 100 | #define EVP_PKEY_ML_KEM_768 NID_ML_KEM_768 | |
| 54 | 101 | #define EVP_PKEY_ML_KEM_1024 NID_ML_KEM_1024 | |
| 55 | 102 | #include <openssl/core_names.h> | |
| 56 | 103 | #endif | |
| 57 | 104 | ||
| 58 | - #if OPENSSL_VERSION_MAJOR >= 3 | ||
| 105 | + #if OPENSSL_VERSION_PREREQ(3, 0) | ||
| 59 | 106 | #define OSSL3_CONST const | |
| 60 | 107 | #else | |
| 61 | 108 | #define OSSL3_CONST | |
@@ -1492,7 +1539,7 @@ class HMACCtxPointer final { | |||
| 1492 | 1539 | DeleteFnPtr<HMAC_CTX, HMAC_CTX_free> ctx_; | |
| 1493 | 1540 | }; | |
| 1494 | 1541 | ||
| 1495 | - #if OPENSSL_VERSION_MAJOR >= 3 | ||
| 1542 | + #if OPENSSL_WITH_KMAC | ||
| 1496 | 1543 | class EVPMacPointer final { | |
| 1497 | 1544 | public: | |
| 1498 | 1545 | EVPMacPointer() = default; | |
@@ -1540,7 +1587,7 @@ class EVPMacCtxPointer final { | |||
| 1540 | 1587 | private: | |
| 1541 | 1588 | DeleteFnPtr<EVP_MAC_CTX, EVP_MAC_CTX_free> ctx_; | |
| 1542 | 1589 | }; | |
| 1543 | - #endif // OPENSSL_VERSION_MAJOR >= 3 | ||
| 1590 | + #endif // OPENSSL_WITH_KMAC | ||
| 1544 | 1591 | ||
| 1545 | 1592 | #ifndef OPENSSL_NO_ENGINE | |
| 1546 | 1593 | class EnginePointer final { | |
@@ -1653,8 +1700,7 @@ DataPointer pbkdf2(const Digest& md, | |||
| 1653 | 1700 | uint32_t iterations, | |
| 1654 | 1701 | size_t length); | |
| 1655 | 1702 | ||
| 1656 | - #if OPENSSL_VERSION_NUMBER >= 0x30200000L | ||
| 1657 | - #ifndef OPENSSL_NO_ARGON2 | ||
| 1703 | + #if OPENSSL_WITH_ARGON2 | ||
| 1658 | 1704 | enum class Argon2Type { ARGON2D, ARGON2I, ARGON2ID }; | |
| 1659 | 1705 | ||
| 1660 | 1706 | DataPointer argon2(const Buffer<const char>& pass, | |
@@ -1668,11 +1714,10 @@ DataPointer argon2(const Buffer<const char>& pass, | |||
| 1668 | 1714 | const Buffer<const unsigned char>& ad, | |
| 1669 | 1715 | Argon2Type type); | |
| 1670 | 1716 | #endif | |
| 1671 | - #endif | ||
| 1672 | 1717 | ||
| 1673 | 1718 | // ============================================================================ | |
| 1674 | 1719 | // KEM (Key Encapsulation Mechanism) | |
| 1675 | - #if OPENSSL_VERSION_MAJOR >= 3 | ||
| 1720 | + #if OPENSSL_WITH_KEM | ||
| 1676 | 1721 | ||
| 1677 | 1722 | class KEM final { | |
| 1678 | 1723 | public: | |
@@ -1696,13 +1741,13 @@ class KEM final { | |||
| 1696 | 1741 | const Buffer<const void>& ciphertext); | |
| 1697 | 1742 | ||
| 1698 | 1743 | private: | |
| 1699 | - #if !OPENSSL_VERSION_PREREQ(3, 5) | ||
| 1744 | + #if OPENSSL_WITH_KEM_OPERATION_PARAM | ||
| 1700 | 1745 | static bool SetOperationParameter(EVP_PKEY_CTX* ctx, | |
| 1701 | 1746 | const EVPKeyPointer& key); | |
| 1702 | 1747 | #endif | |
| 1703 | 1748 | }; | |
| 1704 | 1749 | ||
| 1705 | - #endif // OPENSSL_VERSION_MAJOR >= 3 | ||
| 1750 | + #endif // OPENSSL_WITH_KEM | ||
| 1706 | 1751 | ||
| 1707 | 1752 | // ============================================================================ | |
| 1708 | 1753 | // Version metadata | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,7 +26,7 @@ constexpr unsigned kNoAuthTagLength = static_cast<unsigned>(-1); | |||
| 26 | 26 | V(KW_192, AES_Cipher, ncrypto::Cipher::AES_192_KW) \ | |
| 27 | 27 | V(KW_256, AES_Cipher, ncrypto::Cipher::AES_256_KW) | |
| 28 | 28 | ||
| 29 | - #if OPENSSL_VERSION_MAJOR >= 3 | ||
| 29 | + #if OPENSSL_WITH_AES_OCB | ||
| 30 | 30 | #define VARIANTS_OCB(V) \ | |
| 31 | 31 | V(OCB_128, AES_Cipher, ncrypto::Cipher::AES_128_OCB) \ | |
| 32 | 32 | V(OCB_192, AES_Cipher, ncrypto::Cipher::AES_192_OCB) \ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,8 +2,7 @@ | |||
| 2 | 2 | #include "async_wrap-inl.h" | |
| 3 | 3 | #include "threadpoolwork-inl.h" | |
| 4 | 4 | ||
| 5 | - #if OPENSSL_VERSION_NUMBER >= 0x30200000L | ||
| 6 | - #ifndef OPENSSL_NO_ARGON2 | ||
| 5 | + #if OPENSSL_WITH_ARGON2 | ||
| 7 | 6 | #include <openssl/core_names.h> | |
| 8 | 7 | ||
| 9 | 8 | namespace node::crypto { | |
@@ -155,4 +154,3 @@ void Argon2::RegisterExternalReferences(ExternalReferenceRegistry* registry) { | |||
| 155 | 154 | } // namespace node::crypto | |
| 156 | 155 | ||
| 157 | 156 | #endif | |
| 158 | - #endif | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,7 +6,7 @@ | |||
| 6 | 6 | #include "crypto/crypto_util.h" | |
| 7 | 7 | ||
| 8 | 8 | namespace node::crypto { | |
| 9 | - #if !defined(OPENSSL_NO_ARGON2) && OPENSSL_VERSION_NUMBER >= 0x30200000L | ||
| 9 | + #if OPENSSL_WITH_ARGON2 | ||
| 10 | 10 | ||
| 11 | 11 | // Argon2 is a password-based key derivation algorithm | |
| 12 | 12 | // defined in https://datatracker.ietf.org/doc/html/rfc9106 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -738,7 +738,7 @@ bool CipherBase::Final(std::unique_ptr<BackingStore>* out) { | |||
| 738 | 738 | static_cast<size_t>(ctx_.getBlockSize()), | |
| 739 | 739 | BackingStoreInitializationMode::kUninitialized); | |
| 740 | 740 | ||
| 741 | - #if (OPENSSL_VERSION_NUMBER < 0x30000000L) | ||
| 741 | + #if !OPENSSL_VERSION_PREREQ(3, 0) | ||
| 742 | 742 | // OpenSSL v1.x doesn't verify the presence of the auth tag so do | |
| 743 | 743 | // it ourselves, see https://github.com/nodejs/node/issues/45874. | |
| 744 | 744 | if (kind_ == kDecipher && ctx_.isChaCha20Poly1305() && | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,6 @@ | |||
| 1 | 1 | #include "crypto/crypto_kem.h" | |
| 2 | 2 | ||
| 3 | - #if OPENSSL_VERSION_MAJOR >= 3 | ||
| 3 | + #if OPENSSL_WITH_KEM | ||
| 4 | 4 | ||
| 5 | 5 | #include "async_wrap-inl.h" | |
| 6 | 6 | #include "base_object-inl.h" | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,7 +10,7 @@ | |||
| 10 | 10 | #include "memory_tracker.h" | |
| 11 | 11 | #include "node_external_reference.h" | |
| 12 | 12 | ||
| 13 | - #if OPENSSL_VERSION_MAJOR >= 3 | ||
| 13 | + #if OPENSSL_WITH_KEM | ||
| 14 | 14 | ||
| 15 | 15 | namespace node { | |
| 16 | 16 | namespace crypto { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,7 +3,7 @@ | |||
| 3 | 3 | #include "node_internals.h" | |
| 4 | 4 | #include "threadpoolwork-inl.h" | |
| 5 | 5 | ||
| 6 | - #if OPENSSL_VERSION_MAJOR >= 3 | ||
| 6 | + #if OPENSSL_WITH_KMAC | ||
| 7 | 7 | #include <openssl/core_names.h> | |
| 8 | 8 | #include <openssl/params.h> | |
| 9 | 9 | #include "crypto/crypto_keys.h" | |
@@ -218,4 +218,4 @@ void Kmac::RegisterExternalReferences(ExternalReferenceRegistry* registry) { | |||
| 218 | 218 | ||
| 219 | 219 | } // namespace node::crypto | |
| 220 | 220 | ||
| 221 | - #endif | ||
| 221 | + #endif // OPENSSL_WITH_KMAC | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,8 +10,7 @@ | |||
| 10 | 10 | ||
| 11 | 11 | namespace node::crypto { | |
| 12 | 12 | ||
| 13 | - // KMAC (Keccak Message Authentication Code) is available since OpenSSL 3.0. | ||
| 14 | - #if OPENSSL_VERSION_MAJOR >= 3 | ||
| 13 | + #if OPENSSL_WITH_KMAC | ||
| 15 | 14 | ||
| 16 | 15 | enum class KmacVariant { KMAC128, KMAC256 }; | |
| 17 | 16 | ||
@@ -71,7 +70,7 @@ namespace Kmac { | |||
| 71 | 70 | void Initialize(Environment* env, v8::Local<v8::Object> target) {} | |
| 72 | 71 | void RegisterExternalReferences(ExternalReferenceRegistry* registry) {} | |
| 73 | 72 | } // namespace Kmac | |
| 74 | - #endif | ||
| 73 | + #endif // OPENSSL_WITH_KMAC | ||
| 75 | 74 | ||
| 76 | 75 | } // namespace node::crypto | |
| 77 | 76 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments