From bf3de205108efcb4a4a987df3d67d53e6ae6111d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 25 Jun 2026 07:46:52 +0000 Subject: [PATCH 1/3] chore: sync ncrypto from Node.js v26.4.0 Node-Base-Commit: cfd7920d5a2d84905c4292362d01d07870047e93 Node-Target-Commit: 2022edf3e32ce28ee08b17f8566243a090dacd95 --- .github/sync-node-ncrypto.json | 2 +- include/ncrypto.h | 186 ++++++++++++++++++++++++++++++++- src/ncrypto.cpp | 103 ++++++++++++++++-- 3 files changed, 280 insertions(+), 11 deletions(-) diff --git a/.github/sync-node-ncrypto.json b/.github/sync-node-ncrypto.json index a9596c7..7c8001c 100644 --- a/.github/sync-node-ncrypto.json +++ b/.github/sync-node-ncrypto.json @@ -1,3 +1,3 @@ { - "node_commit": "cfd7920d5a2d84905c4292362d01d07870047e93" + "node_commit": "2022edf3e32ce28ee08b17f8566243a090dacd95" } diff --git a/include/ncrypto.h b/include/ncrypto.h index b6b6ac6..6445ba2 100644 --- a/include/ncrypto.h +++ b/include/ncrypto.h @@ -75,9 +75,9 @@ #endif #if OPENSSL_VERSION_PREREQ(3, 0) -#define OPENSSL_WITH_KMAC 1 +#define OPENSSL_WITH_EVP_MAC 1 #else -#define OPENSSL_WITH_KMAC 0 +#define OPENSSL_WITH_EVP_MAC 0 #endif #if defined(OPENSSL_IS_BORINGSSL) || OPENSSL_VERSION_PREREQ(3, 2) @@ -831,6 +831,155 @@ class BIOPointer final { mutable DeleteFnPtr bio_; }; +<<<<<<< nodejs/ncrypto:include/ncrypto.h +||||||| nodejs/node:deps/ncrypto/ncrypto.h@cfd7920d5a2d +class BignumPointer final { + public: + BignumPointer() = default; + explicit BignumPointer(BIGNUM* bignum); + explicit BignumPointer(const unsigned char* data, size_t len); + BignumPointer(BignumPointer&& other) noexcept; + BignumPointer& operator=(BignumPointer&& other) noexcept; + NCRYPTO_DISALLOW_COPY(BignumPointer) + ~BignumPointer(); + + int operator<=>(const BignumPointer& other) const noexcept; + int operator<=>(const BIGNUM* other) const noexcept; + inline operator bool() const { return bn_ != nullptr; } + inline BIGNUM* get() const noexcept { return bn_.get(); } + void reset(BIGNUM* bn = nullptr); + void reset(const unsigned char* data, size_t len); + BIGNUM* release(); + + bool isZero() const; + bool isOne() const; + + bool setWord(unsigned long w); // NOLINT(runtime/int) + unsigned long getWord() const; // NOLINT(runtime/int) + + size_t byteLength() const; + + DataPointer toHex() const; + DataPointer encode() const; + DataPointer encodePadded(size_t size) const; + size_t encodeInto(unsigned char* out) const; + size_t encodePaddedInto(unsigned char* out, size_t size) const; + + using PrimeCheckCallback = std::function; + int isPrime(int checks, + PrimeCheckCallback cb = defaultPrimeCheckCallback) const; + struct PrimeConfig { + int bits; + bool safe = false; + const BignumPointer& add; + const BignumPointer& rem; + }; + + static BignumPointer NewPrime( + const PrimeConfig& params, + PrimeCheckCallback cb = defaultPrimeCheckCallback); + + bool generate(const PrimeConfig& params, + PrimeCheckCallback cb = defaultPrimeCheckCallback) const; + + static BignumPointer New(); + static BignumPointer NewSecure(); + static BignumPointer NewSub(const BignumPointer& a, const BignumPointer& b); + static BignumPointer NewLShift(size_t length); + + static DataPointer Encode(const BIGNUM* bn); + static DataPointer EncodePadded(const BIGNUM* bn, size_t size); + static size_t EncodePaddedInto(const BIGNUM* bn, + unsigned char* out, + size_t size); + static int GetBitCount(const BIGNUM* bn); + static int GetByteCount(const BIGNUM* bn); + static unsigned long GetWord(const BIGNUM* bn); // NOLINT(runtime/int) + static const BIGNUM* One(); + + BignumPointer clone(); + + private: + DeleteFnPtr bn_; + + static bool defaultPrimeCheckCallback(int, int) { return 1; } +}; + +======= +class BignumPointer final { + public: + BignumPointer() = default; + explicit BignumPointer(BIGNUM* bignum); + explicit BignumPointer(const unsigned char* data, size_t len); + BignumPointer(BignumPointer&& other) noexcept; + BignumPointer& operator=(BignumPointer&& other) noexcept; + NCRYPTO_DISALLOW_COPY(BignumPointer) + ~BignumPointer(); + + int operator<=>(const BignumPointer& other) const noexcept; + int operator<=>(const BIGNUM* other) const noexcept; + inline operator bool() const { return bn_ != nullptr; } + inline BIGNUM* get() const noexcept { return bn_.get(); } + void reset(BIGNUM* bn = nullptr); + void reset(const unsigned char* data, size_t len); + BIGNUM* release(); + + bool isZero() const; + bool isOne() const; + + bool setWord(unsigned long w); // NOLINT(runtime/int) + std::optional getWord() const; // NOLINT(runtime/int) + + size_t byteLength() const; + + DataPointer toHex() const; + DataPointer encode() const; + DataPointer encodePadded(size_t size) const; + size_t encodeInto(unsigned char* out) const; + size_t encodePaddedInto(unsigned char* out, size_t size) const; + + using PrimeCheckCallback = std::function; + int isPrime(int checks, + PrimeCheckCallback cb = defaultPrimeCheckCallback) const; + struct PrimeConfig { + int bits; + bool safe = false; + const BignumPointer& add; + const BignumPointer& rem; + }; + + static BignumPointer NewPrime( + const PrimeConfig& params, + PrimeCheckCallback cb = defaultPrimeCheckCallback); + + bool generate(const PrimeConfig& params, + PrimeCheckCallback cb = defaultPrimeCheckCallback) const; + + static BignumPointer New(); + static BignumPointer NewSecure(); + static BignumPointer NewSub(const BignumPointer& a, const BignumPointer& b); + static BignumPointer NewLShift(size_t length); + + static DataPointer Encode(const BIGNUM* bn); + static DataPointer EncodePadded(const BIGNUM* bn, size_t size); + static size_t EncodePaddedInto(const BIGNUM* bn, + unsigned char* out, + size_t size); + static int GetBitCount(const BIGNUM* bn); + static int GetByteCount(const BIGNUM* bn); + static std::optional GetWord( // NOLINT(runtime/int) + const BIGNUM* bn); + static const BIGNUM* One(); + + BignumPointer clone(); + + private: + DeleteFnPtr bn_; + + static bool defaultPrimeCheckCallback(int, int) { return 1; } +}; + +>>>>>>> nodejs/node:deps/ncrypto/ncrypto.h@2022edf3e32c class CipherCtxPointer final { public: static CipherCtxPointer New(); @@ -1569,6 +1718,7 @@ class EVPMDCtxPointer final { DeleteFnPtr ctx_; }; +#if !OPENSSL_WITH_EVP_MAC class HMACCtxPointer final { public: HMACCtxPointer(); @@ -1595,8 +1745,9 @@ class HMACCtxPointer final { private: DeleteFnPtr ctx_; }; +#endif // !OPENSSL_WITH_EVP_MAC -#if OPENSSL_WITH_KMAC +#if OPENSSL_WITH_EVP_MAC class EVPMacPointer final { public: EVPMacPointer() = default; @@ -1644,7 +1795,34 @@ class EVPMacCtxPointer final { private: DeleteFnPtr ctx_; }; -#endif // OPENSSL_WITH_KMAC + +class HMACCtxPointer final { + public: + HMACCtxPointer(); + HMACCtxPointer(HMACCtxPointer&& other) noexcept; + HMACCtxPointer& operator=(HMACCtxPointer&& other) noexcept; + NCRYPTO_DISALLOW_COPY(HMACCtxPointer) + ~HMACCtxPointer(); + + inline bool operator==(std::nullptr_t) noexcept { return ctx_ == nullptr; } + inline operator bool() const { return ctx_ != nullptr; } + void reset(); + + bool init(const Buffer& buf, const Digest& md); + bool update(const Buffer& buf); + DataPointer digest(); + bool digestInto(Buffer* buf); + + static HMACCtxPointer New(); + + private: + HMACCtxPointer(EVPMacPointer&& mac, EVPMacCtxPointer&& ctx); + + EVPMacPointer mac_; + EVPMacCtxPointer ctx_; + size_t md_size_ = 0; +}; +#endif // OPENSSL_WITH_EVP_MAC #ifndef OPENSSL_NO_ENGINE class EnginePointer final { diff --git a/src/ncrypto.cpp b/src/ncrypto.cpp index 2e6020a..16d9d89 100644 --- a/src/ncrypto.cpp +++ b/src/ncrypto.cpp @@ -431,12 +431,16 @@ bool BignumPointer::setWord(unsigned long w) { // NOLINT(runtime/int) return BN_set_word(bn_.get(), w) == 1; } -unsigned long BignumPointer::GetWord(const BIGNUM* bn) { // NOLINT(runtime/int) - return BN_get_word(bn); +std::optional BignumPointer::GetWord( // NOLINT(runtime/int) + const BIGNUM* bn) { + BN_ULONG ret = BN_get_word(bn); + if (ret == static_cast(-1)) return std::nullopt; + return ret; } -unsigned long BignumPointer::getWord() const { // NOLINT(runtime/int) - if (!bn_) return 0; +std::optional BignumPointer::getWord() // NOLINT(runtime/int) + const { + if (!bn_) return std::nullopt; return GetWord(bn_.get()); } @@ -4805,6 +4809,7 @@ bool extractP1363(const Buffer& buf, // ============================================================================ +#if !OPENSSL_WITH_EVP_MAC HMACCtxPointer::HMACCtxPointer() : ctx_(nullptr) {} HMACCtxPointer::HMACCtxPointer(HMAC_CTX* ctx) : ctx_(ctx) {} @@ -4864,8 +4869,9 @@ bool HMACCtxPointer::digestInto(Buffer* buf) { HMACCtxPointer HMACCtxPointer::New() { return HMACCtxPointer(HMAC_CTX_new()); } +#endif // !OPENSSL_WITH_EVP_MAC -#if OPENSSL_WITH_KMAC +#if OPENSSL_WITH_EVP_MAC EVPMacPointer::EVPMacPointer(EVP_MAC* mac) : mac_(mac) {} EVPMacPointer::EVPMacPointer(EVPMacPointer&& other) noexcept @@ -4953,7 +4959,92 @@ EVPMacCtxPointer EVPMacCtxPointer::New(EVP_MAC* mac) { if (!mac) return EVPMacCtxPointer(); return EVPMacCtxPointer(EVP_MAC_CTX_new(mac)); } -#endif // OPENSSL_WITH_KMAC + +HMACCtxPointer::HMACCtxPointer() = default; + +HMACCtxPointer::HMACCtxPointer(EVPMacPointer&& mac, EVPMacCtxPointer&& ctx) + : mac_(std::move(mac)), ctx_(std::move(ctx)) {} + +HMACCtxPointer::HMACCtxPointer(HMACCtxPointer&& other) noexcept + : mac_(std::move(other.mac_)), + ctx_(std::move(other.ctx_)), + md_size_(other.md_size_) { + other.md_size_ = 0; +} + +HMACCtxPointer& HMACCtxPointer::operator=(HMACCtxPointer&& other) noexcept { + if (this == &other) return *this; + mac_ = std::move(other.mac_); + ctx_ = std::move(other.ctx_); + md_size_ = other.md_size_; + other.md_size_ = 0; + return *this; +} + +HMACCtxPointer::~HMACCtxPointer() { + reset(); +} + +void HMACCtxPointer::reset() { + ctx_.reset(); + mac_.reset(); + md_size_ = 0; +} + +bool HMACCtxPointer::init(const Buffer& buf, const Digest& md) { + if (!ctx_ || !md) return false; + + const char* md_name = EVP_MD_get0_name(md); + if (md_name == nullptr) return false; + + OSSL_PARAM params[] = { + OSSL_PARAM_construct_utf8_string( + OSSL_MAC_PARAM_DIGEST, const_cast(md_name), 0), + OSSL_PARAM_construct_end(), + }; + + if (!ctx_.init(buf, params)) return false; + md_size_ = md.size(); + return true; +} + +bool HMACCtxPointer::update(const Buffer& buf) { + if (!ctx_) return false; + return ctx_.update(buf); +} + +DataPointer HMACCtxPointer::digest() { + if (md_size_ == 0) return {}; + auto data = DataPointer::Alloc(md_size_); + if (!data) return {}; + Buffer buf = data; + if (!digestInto(&buf)) return {}; + return data.resize(buf.len); +} + +bool HMACCtxPointer::digestInto(Buffer* buf) { + if (!ctx_) return false; + + size_t len = buf->len; + if (EVP_MAC_final( + ctx_.get(), static_cast(buf->data), &len, buf->len) != + 1) + return false; + + buf->len = len; + return true; +} + +HMACCtxPointer HMACCtxPointer::New() { + auto mac = EVPMacPointer::Fetch(OSSL_MAC_NAME_HMAC); + if (!mac) return {}; + + auto ctx = EVPMacCtxPointer::New(mac.get()); + if (!ctx) return {}; + + return HMACCtxPointer(std::move(mac), std::move(ctx)); +} +#endif // OPENSSL_WITH_EVP_MAC DataPointer hashDigest(const Buffer& buf, const EVP_MD* md) { From a021db919ba4869172775b9da9460e0851f69c38 Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Thu, 25 Jun 2026 09:58:01 +0200 Subject: [PATCH 2/3] fixup! chore: sync ncrypto from Node.js v26.4.0 --- include/ncrypto.h | 154 +--------------------------------------------- 1 file changed, 3 insertions(+), 151 deletions(-) diff --git a/include/ncrypto.h b/include/ncrypto.h index 6445ba2..abbb161 100644 --- a/include/ncrypto.h +++ b/include/ncrypto.h @@ -617,7 +617,7 @@ class BignumPointer final { bool isOne() const; bool setWord(unsigned long w); // NOLINT(runtime/int) - unsigned long getWord() const; // NOLINT(runtime/int) + std::optional getWord() const; // NOLINT(runtime/int) size_t byteLength() const; size_t bitLength() const; @@ -657,7 +657,8 @@ class BignumPointer final { size_t size); static int GetBitCount(const BIGNUM* bn); static int GetByteCount(const BIGNUM* bn); - static unsigned long GetWord(const BIGNUM* bn); // NOLINT(runtime/int) + static std::optional GetWord( // NOLINT(runtime/int) + const BIGNUM* bn); static const BIGNUM* One(); BignumPointer clone(); @@ -831,155 +832,6 @@ class BIOPointer final { mutable DeleteFnPtr bio_; }; -<<<<<<< nodejs/ncrypto:include/ncrypto.h -||||||| nodejs/node:deps/ncrypto/ncrypto.h@cfd7920d5a2d -class BignumPointer final { - public: - BignumPointer() = default; - explicit BignumPointer(BIGNUM* bignum); - explicit BignumPointer(const unsigned char* data, size_t len); - BignumPointer(BignumPointer&& other) noexcept; - BignumPointer& operator=(BignumPointer&& other) noexcept; - NCRYPTO_DISALLOW_COPY(BignumPointer) - ~BignumPointer(); - - int operator<=>(const BignumPointer& other) const noexcept; - int operator<=>(const BIGNUM* other) const noexcept; - inline operator bool() const { return bn_ != nullptr; } - inline BIGNUM* get() const noexcept { return bn_.get(); } - void reset(BIGNUM* bn = nullptr); - void reset(const unsigned char* data, size_t len); - BIGNUM* release(); - - bool isZero() const; - bool isOne() const; - - bool setWord(unsigned long w); // NOLINT(runtime/int) - unsigned long getWord() const; // NOLINT(runtime/int) - - size_t byteLength() const; - - DataPointer toHex() const; - DataPointer encode() const; - DataPointer encodePadded(size_t size) const; - size_t encodeInto(unsigned char* out) const; - size_t encodePaddedInto(unsigned char* out, size_t size) const; - - using PrimeCheckCallback = std::function; - int isPrime(int checks, - PrimeCheckCallback cb = defaultPrimeCheckCallback) const; - struct PrimeConfig { - int bits; - bool safe = false; - const BignumPointer& add; - const BignumPointer& rem; - }; - - static BignumPointer NewPrime( - const PrimeConfig& params, - PrimeCheckCallback cb = defaultPrimeCheckCallback); - - bool generate(const PrimeConfig& params, - PrimeCheckCallback cb = defaultPrimeCheckCallback) const; - - static BignumPointer New(); - static BignumPointer NewSecure(); - static BignumPointer NewSub(const BignumPointer& a, const BignumPointer& b); - static BignumPointer NewLShift(size_t length); - - static DataPointer Encode(const BIGNUM* bn); - static DataPointer EncodePadded(const BIGNUM* bn, size_t size); - static size_t EncodePaddedInto(const BIGNUM* bn, - unsigned char* out, - size_t size); - static int GetBitCount(const BIGNUM* bn); - static int GetByteCount(const BIGNUM* bn); - static unsigned long GetWord(const BIGNUM* bn); // NOLINT(runtime/int) - static const BIGNUM* One(); - - BignumPointer clone(); - - private: - DeleteFnPtr bn_; - - static bool defaultPrimeCheckCallback(int, int) { return 1; } -}; - -======= -class BignumPointer final { - public: - BignumPointer() = default; - explicit BignumPointer(BIGNUM* bignum); - explicit BignumPointer(const unsigned char* data, size_t len); - BignumPointer(BignumPointer&& other) noexcept; - BignumPointer& operator=(BignumPointer&& other) noexcept; - NCRYPTO_DISALLOW_COPY(BignumPointer) - ~BignumPointer(); - - int operator<=>(const BignumPointer& other) const noexcept; - int operator<=>(const BIGNUM* other) const noexcept; - inline operator bool() const { return bn_ != nullptr; } - inline BIGNUM* get() const noexcept { return bn_.get(); } - void reset(BIGNUM* bn = nullptr); - void reset(const unsigned char* data, size_t len); - BIGNUM* release(); - - bool isZero() const; - bool isOne() const; - - bool setWord(unsigned long w); // NOLINT(runtime/int) - std::optional getWord() const; // NOLINT(runtime/int) - - size_t byteLength() const; - - DataPointer toHex() const; - DataPointer encode() const; - DataPointer encodePadded(size_t size) const; - size_t encodeInto(unsigned char* out) const; - size_t encodePaddedInto(unsigned char* out, size_t size) const; - - using PrimeCheckCallback = std::function; - int isPrime(int checks, - PrimeCheckCallback cb = defaultPrimeCheckCallback) const; - struct PrimeConfig { - int bits; - bool safe = false; - const BignumPointer& add; - const BignumPointer& rem; - }; - - static BignumPointer NewPrime( - const PrimeConfig& params, - PrimeCheckCallback cb = defaultPrimeCheckCallback); - - bool generate(const PrimeConfig& params, - PrimeCheckCallback cb = defaultPrimeCheckCallback) const; - - static BignumPointer New(); - static BignumPointer NewSecure(); - static BignumPointer NewSub(const BignumPointer& a, const BignumPointer& b); - static BignumPointer NewLShift(size_t length); - - static DataPointer Encode(const BIGNUM* bn); - static DataPointer EncodePadded(const BIGNUM* bn, size_t size); - static size_t EncodePaddedInto(const BIGNUM* bn, - unsigned char* out, - size_t size); - static int GetBitCount(const BIGNUM* bn); - static int GetByteCount(const BIGNUM* bn); - static std::optional GetWord( // NOLINT(runtime/int) - const BIGNUM* bn); - static const BIGNUM* One(); - - BignumPointer clone(); - - private: - DeleteFnPtr bn_; - - static bool defaultPrimeCheckCallback(int, int) { return 1; } -}; - ->>>>>>> nodejs/node:deps/ncrypto/ncrypto.h@2022edf3e32c class CipherCtxPointer final { public: static CipherCtxPointer New(); From 7a206cb2e5d62a78503387be0c595d3e6718b14c Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Thu, 25 Jun 2026 10:06:02 +0200 Subject: [PATCH 3/3] fixup! chore: sync ncrypto from Node.js v26.4.0 --- .github/workflows/visual-studio.yml | 2 +- include/ncrypto.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/visual-studio.yml b/.github/workflows/visual-studio.yml index 0eb78f8..3acc0db 100644 --- a/.github/workflows/visual-studio.yml +++ b/.github/workflows/visual-studio.yml @@ -22,7 +22,7 @@ concurrency: jobs: build: - runs-on: windows-2025 + runs-on: windows-2022 strategy: fail-fast: false matrix: diff --git a/include/ncrypto.h b/include/ncrypto.h index abbb161..8a817c1 100644 --- a/include/ncrypto.h +++ b/include/ncrypto.h @@ -616,7 +616,7 @@ class BignumPointer final { bool isZero() const; bool isOne() const; - bool setWord(unsigned long w); // NOLINT(runtime/int) + bool setWord(unsigned long w); // NOLINT(runtime/int) std::optional getWord() const; // NOLINT(runtime/int) size_t byteLength() const;