Include |BN_MONT_CTX| construction in RSA verification speed test.

Change-Id: I30d6560156bedeac781b12c16a65cfede7891bb7
Reviewed-on: https://boringssl-review.googlesource.com/10522
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: Adam Langley <agl@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
This commit is contained in:
Brian Smith 2016-08-19 15:11:20 -10:00 committed by CQ bot account: commit-bot@chromium.org
parent 7c04075617
commit 7bee853d18

View File

@ -147,6 +147,9 @@ static bool SpeedRSA(const std::string &key_name, RSA *key,
TimeResults results;
if (!TimeFunction(&results,
[key, &sig, &fake_sha256_hash, &sig_len]() -> bool {
/* Usually during RSA signing we're using a long-lived |RSA| that has
* already had all of its |BN_MONT_CTX|s constructed, so it makes
* sense to use |key| directly here. */
return RSA_sign(NID_sha256, fake_sha256_hash, sizeof(fake_sha256_hash),
sig.get(), &sig_len, key);
})) {
@ -158,6 +161,21 @@ static bool SpeedRSA(const std::string &key_name, RSA *key,
if (!TimeFunction(&results,
[key, &fake_sha256_hash, &sig, sig_len]() -> bool {
/* Usually during RSA verification we have to parse an RSA key from a
* certificate or similar, in which case we'd need to construct a new
* RSA key, with a new |BN_MONT_CTX| for the public modulus. If we were
* to use |key| directly instead, then these costs wouldn't be
* accounted for. */
ScopedRSA verify_key(RSA_new());
if (!verify_key) {
return false;
}
verify_key->n = BN_dup(key->n);
verify_key->e = BN_dup(key->e);
if (!verify_key->n ||
!verify_key->e) {
return false;
}
return RSA_verify(NID_sha256, fake_sha256_hash,
sizeof(fake_sha256_hash), sig.get(), sig_len, key);
})) {