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 benchmarks for EC_KEY_generate_key(_fips) #969

Merged
merged 1 commit into from
May 3, 2023
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
48 changes: 47 additions & 1 deletion tool/speed.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,37 @@ static bool SpeedECDHCurve(const std::string &name, int nid,
return true;
}


static bool SpeedECKeyGenerateKey(bool is_fips, const std::string &name,
int nid, const std::string &selected) {
if (!selected.empty() && name.find(selected) == std::string::npos) {
return true;
}
BM_NAMESPACE::UniquePtr<EC_KEY> key(EC_KEY_new_by_curve_name(nid));

TimeResults results;
if (is_fips) {
#if !defined(OPENSSL_BENCHMARK)
if (!TimeFunction(&results, [&key]() -> bool {
return EC_KEY_generate_key_fips(key.get()) == 1;
})) {
return false;
}
#else
return true;
#endif
} else {
if (!TimeFunction(&results, [&key]() -> bool {
return EC_KEY_generate_key(key.get()) == 1;
})) {
return false;
}
}
results.Print(is_fips ? name + " with EC_KEY_generate_key_fips"
: name + " with EC_KEY_generate_key");
return true;
}

static bool SpeedECKeyGenCurve(const std::string &name, int nid,
const std::string &selected) {
if (!selected.empty() && name.find(selected) == std::string::npos) {
Expand Down Expand Up @@ -1221,7 +1252,7 @@ static bool SpeedECKeyGenCurve(const std::string &name, int nid,
})) {
return false;
}
results.Print(name);
results.Print(name + " with EVP_PKEY_keygen");
return true;
}

Expand Down Expand Up @@ -1267,6 +1298,19 @@ static bool SpeedECDSACurve(const std::string &name, int nid,
return true;
}

static bool SpeedECKeyGenerateKey(bool is_fips, const std::string &selected) {
return SpeedECKeyGenerateKey(is_fips, "Generate P-224", NID_secp224r1,
selected) &&
SpeedECKeyGenerateKey(is_fips, "Generate P-256",
NID_X9_62_prime256v1, selected) &&
SpeedECKeyGenerateKey(is_fips, "Generate P-384", NID_secp384r1,
selected) &&
SpeedECKeyGenerateKey(is_fips, "Generate P-521", NID_secp521r1,
selected) &&
SpeedECKeyGenerateKey(is_fips, "Generate secp256k1",
NID_secp256k1, selected);
}

static bool SpeedECDH(const std::string &selected) {
return SpeedECDHCurve("ECDH P-224", NID_secp224r1, selected) &&
SpeedECDHCurve("ECDH P-256", NID_X9_62_prime256v1, selected) &&
Expand Down Expand Up @@ -2298,6 +2342,7 @@ bool Speed(const std::vector<std::string> &args) {
!SpeedECDH(selected) ||
!SpeedECDSA(selected) ||
!SpeedECKeyGen(selected) ||
!SpeedECKeyGenerateKey(false, selected) ||
#if !defined(OPENSSL_1_0_BENCHMARK)
!SpeedECMUL(selected) ||
// OpenSSL 1.0 doesn't support Scrypt
Expand Down Expand Up @@ -2329,6 +2374,7 @@ bool Speed(const std::vector<std::string> &args) {
!SpeedRSAKeyGen(true, selected) ||
!SpeedHRSS(selected) ||
!SpeedHash(EVP_blake2b256(), "BLAKE2b-256", selected) ||
!SpeedECKeyGenerateKey(true, selected) ||
#if defined(INTERNAL_TOOL)
!SpeedHashToCurve(selected) ||
!SpeedTrustToken("TrustToken-Exp1-Batch1", TRUST_TOKEN_experiment_v1(), 1, selected) ||
Expand Down