diff --git a/tool/speed.cc b/tool/speed.cc index 18a8282bd3..fde748495f 100644 --- a/tool/speed.cc +++ b/tool/speed.cc @@ -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; @@ -1624,6 +1624,7 @@ static bool SpeedECMULCurve(const std::string &name, int nid, BM_NAMESPACE::UniquePtr scalar0(BN_new()); BM_NAMESPACE::UniquePtr scalar1(BN_new()); BM_NAMESPACE::UniquePtr pin0(EC_POINT_new(group.get())); + BM_NAMESPACE::UniquePtr pin1(EC_POINT_new(group.get())); BM_NAMESPACE::UniquePtr pout(EC_POINT_new(group.get())); @@ -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())) { @@ -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; } } @@ -2699,7 +2725,7 @@ bool Speed(const std::vector &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