Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c008b15

Browse filesBrowse files
jasnelladuh95
authored andcommitted
src: update ECGroupPointer in ncrypto
PR-URL: #56526 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 5673dc7 commit c008b15
Copy full SHA for c008b15

File tree

Expand file treeCollapse file tree

3 files changed

+56
-9
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+56
-9
lines changed
Open diff view settings
Collapse file

‎deps/ncrypto/ncrypto.cc‎

Copy file name to clipboardExpand all lines: deps/ncrypto/ncrypto.cc
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2677,4 +2677,34 @@ Buffer<unsigned char> ECDSASigPointer::encode() const {
26772677
return buf;
26782678
}
26792679

2680+
// ============================================================================
2681+
2682+
ECGroupPointer::ECGroupPointer() : group_(nullptr) {}
2683+
2684+
ECGroupPointer::ECGroupPointer(EC_GROUP* group) : group_(group) {}
2685+
2686+
ECGroupPointer::ECGroupPointer(ECGroupPointer&& other) noexcept
2687+
: group_(other.release()) {}
2688+
2689+
ECGroupPointer& ECGroupPointer::operator=(ECGroupPointer&& other) noexcept {
2690+
group_.reset(other.release());
2691+
return *this;
2692+
}
2693+
2694+
ECGroupPointer::~ECGroupPointer() {
2695+
reset();
2696+
}
2697+
2698+
void ECGroupPointer::reset(EC_GROUP* group) {
2699+
group_.reset();
2700+
}
2701+
2702+
EC_GROUP* ECGroupPointer::release() {
2703+
return group_.release();
2704+
}
2705+
2706+
ECGroupPointer ECGroupPointer::NewByCurveName(int nid) {
2707+
return ECGroupPointer(EC_GROUP_new_by_curve_name(nid));
2708+
}
2709+
26802710
} // namespace ncrypto
Collapse file

‎deps/ncrypto/ncrypto.h‎

Copy file name to clipboardExpand all lines: deps/ncrypto/ncrypto.h
+22-1Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ using DeleteFnPtr = typename FunctionDeleter<T, function>::Pointer;
197197

198198
using BignumCtxPointer = DeleteFnPtr<BN_CTX, BN_CTX_free>;
199199
using BignumGenCallbackPointer = DeleteFnPtr<BN_GENCB, BN_GENCB_free>;
200-
using ECGroupPointer = DeleteFnPtr<EC_GROUP, EC_GROUP_free>;
201200
using ECKeyPointer = DeleteFnPtr<EC_KEY, EC_KEY_free>;
202201
using ECPointPointer = DeleteFnPtr<EC_POINT, EC_POINT_free>;
203202
using EVPKeyCtxPointer = DeleteFnPtr<EVP_PKEY_CTX, EVP_PKEY_CTX_free>;
@@ -852,6 +851,28 @@ class ECDSASigPointer final {
852851
const BIGNUM* ps_ = nullptr;
853852
};
854853

854+
class ECGroupPointer final {
855+
public:
856+
explicit ECGroupPointer();
857+
explicit ECGroupPointer(EC_GROUP* group);
858+
ECGroupPointer(ECGroupPointer&& other) noexcept;
859+
ECGroupPointer& operator=(ECGroupPointer&& other) noexcept;
860+
NCRYPTO_DISALLOW_COPY(ECGroupPointer)
861+
~ECGroupPointer();
862+
863+
inline bool operator==(std::nullptr_t) noexcept { return group_ == nullptr; }
864+
inline operator bool() const { return group_ != nullptr; }
865+
inline EC_GROUP* get() const { return group_.get(); }
866+
inline operator EC_GROUP*() const { return group_.get(); }
867+
void reset(EC_GROUP* group = nullptr);
868+
EC_GROUP* release();
869+
870+
static ECGroupPointer NewByCurveName(int nid);
871+
872+
private:
873+
DeleteFnPtr<EC_GROUP, EC_GROUP_free> group_;
874+
};
875+
855876
#ifndef OPENSSL_NO_ENGINE
856877
class EnginePointer final {
857878
public:
Collapse file

‎src/crypto/crypto_ec.cc‎

Copy file name to clipboardExpand all lines: src/crypto/crypto_ec.cc
+4-8Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -399,15 +399,11 @@ void ECDH::ConvertKey(const FunctionCallbackInfo<Value>& args) {
399399
if (nid == NID_undef)
400400
return THROW_ERR_CRYPTO_INVALID_CURVE(env);
401401

402-
ECGroupPointer group(
403-
EC_GROUP_new_by_curve_name(nid));
404-
if (group == nullptr)
402+
auto group = ECGroupPointer::NewByCurveName(nid);
403+
if (!group)
405404
return THROW_ERR_CRYPTO_OPERATION_FAILED(env, "Failed to get EC_GROUP");
406405

407-
ECPointPointer pub(
408-
ECDH::BufferToPoint(env,
409-
group.get(),
410-
args[0]));
406+
ECPointPointer pub(ECDH::BufferToPoint(env, group, args[0]));
411407

412408
if (pub == nullptr) {
413409
return THROW_ERR_CRYPTO_OPERATION_FAILED(env,
@@ -420,7 +416,7 @@ void ECDH::ConvertKey(const FunctionCallbackInfo<Value>& args) {
420416

421417
const char* error;
422418
Local<Object> buf;
423-
if (!ECPointToBuffer(env, group.get(), pub.get(), form, &error).ToLocal(&buf))
419+
if (!ECPointToBuffer(env, group, pub.get(), form, &error).ToLocal(&buf))
424420
return THROW_ERR_CRYPTO_OPERATION_FAILED(env, error);
425421
args.GetReturnValue().Set(buf);
426422
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.