Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EC point add/dbl to speed.cc #1545

Merged
merged 3 commits into from
Apr 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions tool/speed.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1613,7 +1613,7 @@ static bool SpeedEvpEcdh(const std::string &selected) {
return SpeedEvpEcdhCurve("EVP ECDH X25519", NID_X25519, selected);
}

static bool SpeedECMULCurve(const std::string &name, int nid,
static bool SpeedECPOINTCurve(const std::string &name, int nid,
const std::string &selected) {
if (!selected.empty() && name.find(selected) == std::string::npos) {
return true;
Expand All @@ -1624,6 +1624,7 @@ static bool SpeedECMULCurve(const std::string &name, int nid,
BM_NAMESPACE::UniquePtr<BIGNUM> scalar0(BN_new());
BM_NAMESPACE::UniquePtr<BIGNUM> scalar1(BN_new());
BM_NAMESPACE::UniquePtr<EC_POINT> pin0(EC_POINT_new(group.get()));
BM_NAMESPACE::UniquePtr<EC_POINT> pin1(EC_POINT_new(group.get()));
BM_NAMESPACE::UniquePtr<EC_POINT> pout(EC_POINT_new(group.get()));


Expand All @@ -1633,11 +1634,36 @@ static bool SpeedECMULCurve(const std::string &name, int nid,
return false;
}

// Generate one random EC point.
// Generate two random EC point.
EC_POINT_mul(group.get(), pin0.get(), scalar0.get(), nullptr, nullptr, ctx.get());
EC_POINT_mul(group.get(), pin1.get(), scalar1.get(), nullptr, nullptr, ctx.get());

TimeResults results;

// Measure point doubling.
if (!TimeFunction(&results, [&group, &pout, &ctx, &pin0]() -> bool {
if (!EC_POINT_dbl(group.get(), pout.get(), pin0.get(), ctx.get())) {
return false;
}

return true;
})) {
return false;
}
results.Print(name + " dbl");

// Measure point addition.
if (!TimeFunction(&results, [&group, &pout, &ctx, &pin0, &pin1]() -> bool {
if (!EC_POINT_add(group.get(), pout.get(), pin0.get(), pin1.get(), ctx.get())) {
return false;
}

return true;
})) {
return false;
}
results.Print(name + " add");

// Measure scalar multiplication of an arbitrary curve point.
if (!TimeFunction(&results, [&group, &pout, &ctx, &pin0, &scalar0]() -> bool {
if (!EC_POINT_mul(group.get(), pout.get(), nullptr, pin0.get(), scalar0.get(), ctx.get())) {
Expand Down Expand Up @@ -1677,10 +1703,10 @@ static bool SpeedECMULCurve(const std::string &name, int nid,
return true;
}

static bool SpeedECMUL(const std::string &selected) {
static bool SpeedECPOINT(const std::string &selected) {
for (const auto& config : supported_curves) {
std::string message = "ECMUL " + config.name;
if(!SpeedECMULCurve(message, config.nid, selected)) {
std::string message = "EC POINT " + config.name;
if(!SpeedECPOINTCurve(message, config.nid, selected)) {
return false;
}
}
Expand Down Expand Up @@ -2699,7 +2725,7 @@ bool Speed(const std::vector<std::string> &args) {
// OpenSSL 1.0.2 is missing functions e.g. |EVP_PKEY_get0_EC_KEY| and
// doesn't implement X255519 either.
!SpeedEvpEcdh(selected) ||
!SpeedECMUL(selected) ||
!SpeedECPOINT(selected) ||
// OpenSSL 1.0 doesn't support Scrypt
!SpeedScrypt(selected) ||
#endif
Expand Down
Loading