mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
src: update ECGroupPointer in ncrypto
PR-URL: https://github.com/nodejs/node/pull/56526 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
1 parent
6e23885d18
commit
d3cb7c0b96
3 files changed
+56
-9
No files matched your search
Vendored
+30
@@ -2677,4 +2677,34 @@ Buffer<unsigned char> ECDSASigPointer::encode() const {
|
||||
return buf;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
|
||||
ECGroupPointer::ECGroupPointer() : group_(nullptr) {}
|
||||
|
||||
ECGroupPointer::ECGroupPointer(EC_GROUP* group) : group_(group) {}
|
||||
|
||||
ECGroupPointer::ECGroupPointer(ECGroupPointer&& other) noexcept
|
||||
: group_(other.release()) {}
|
||||
|
||||
ECGroupPointer& ECGroupPointer::operator=(ECGroupPointer&& other) noexcept {
|
||||
group_.reset(other.release());
|
||||
return *this;
|
||||
}
|
||||
|
||||
ECGroupPointer::~ECGroupPointer() {
|
||||
reset();
|
||||
}
|
||||
|
||||
void ECGroupPointer::reset(EC_GROUP* group) {
|
||||
group_.reset();
|
||||
}
|
||||
|
||||
EC_GROUP* ECGroupPointer::release() {
|
||||
return group_.release();
|
||||
}
|
||||
|
||||
ECGroupPointer ECGroupPointer::NewByCurveName(int nid) {
|
||||
return ECGroupPointer(EC_GROUP_new_by_curve_name(nid));
|
||||
}
|
||||
|
||||
} // namespace ncrypto
|
||||
Vendored
+22
-1
@@ -197,7 +197,6 @@ using DeleteFnPtr = typename FunctionDeleter<T, function>::Pointer;
|
||||
|
||||
using BignumCtxPointer = DeleteFnPtr<BN_CTX, BN_CTX_free>;
|
||||
using BignumGenCallbackPointer = DeleteFnPtr<BN_GENCB, BN_GENCB_free>;
|
||||
using ECGroupPointer = DeleteFnPtr<EC_GROUP, EC_GROUP_free>;
|
||||
using ECKeyPointer = DeleteFnPtr<EC_KEY, EC_KEY_free>;
|
||||
using ECPointPointer = DeleteFnPtr<EC_POINT, EC_POINT_free>;
|
||||
using EVPKeyCtxPointer = DeleteFnPtr<EVP_PKEY_CTX, EVP_PKEY_CTX_free>;
|
||||
@@ -852,6 +851,28 @@ class ECDSASigPointer final {
|
||||
const BIGNUM* ps_ = nullptr;
|
||||
};
|
||||
|
||||
class ECGroupPointer final {
|
||||
public:
|
||||
explicit ECGroupPointer();
|
||||
explicit ECGroupPointer(EC_GROUP* group);
|
||||
ECGroupPointer(ECGroupPointer&& other) noexcept;
|
||||
ECGroupPointer& operator=(ECGroupPointer&& other) noexcept;
|
||||
NCRYPTO_DISALLOW_COPY(ECGroupPointer)
|
||||
~ECGroupPointer();
|
||||
|
||||
inline bool operator==(std::nullptr_t) noexcept { return group_ == nullptr; }
|
||||
inline operator bool() const { return group_ != nullptr; }
|
||||
inline EC_GROUP* get() const { return group_.get(); }
|
||||
inline operator EC_GROUP*() const { return group_.get(); }
|
||||
void reset(EC_GROUP* group = nullptr);
|
||||
EC_GROUP* release();
|
||||
|
||||
static ECGroupPointer NewByCurveName(int nid);
|
||||
|
||||
private:
|
||||
DeleteFnPtr<EC_GROUP, EC_GROUP_free> group_;
|
||||
};
|
||||
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
class EnginePointer final {
|
||||
public:
|
||||
|
||||
@@ -399,15 +399,11 @@ void ECDH::ConvertKey(const FunctionCallbackInfo<Value>& args) {
|
||||
if (nid == NID_undef)
|
||||
return THROW_ERR_CRYPTO_INVALID_CURVE(env);
|
||||
|
||||
ECGroupPointer group(
|
||||
EC_GROUP_new_by_curve_name(nid));
|
||||
if (group == nullptr)
|
||||
auto group = ECGroupPointer::NewByCurveName(nid);
|
||||
if (!group)
|
||||
return THROW_ERR_CRYPTO_OPERATION_FAILED(env, "Failed to get EC_GROUP");
|
||||
|
||||
ECPointPointer pub(
|
||||
ECDH::BufferToPoint(env,
|
||||
group.get(),
|
||||
args[0]));
|
||||
ECPointPointer pub(ECDH::BufferToPoint(env, group, args[0]));
|
||||
|
||||
if (pub == nullptr) {
|
||||
return THROW_ERR_CRYPTO_OPERATION_FAILED(env,
|
||||
@@ -420,7 +416,7 @@ void ECDH::ConvertKey(const FunctionCallbackInfo<Value>& args) {
|
||||
|
||||
const char* error;
|
||||
Local<Object> buf;
|
||||
if (!ECPointToBuffer(env, group.get(), pub.get(), form, &error).ToLocal(&buf))
|
||||
if (!ECPointToBuffer(env, group, pub.get(), form, &error).ToLocal(&buf))
|
||||
return THROW_ERR_CRYPTO_OPERATION_FAILED(env, error);
|
||||
args.GetReturnValue().Set(buf);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user