| 6 | * |
| 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
| 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ |
| 14 |
| 15 | #include <algorithm> |
| 16 | #include <string> |
| 17 | #include <functional> |
| 18 | #include <memory> |
| 19 | #include <vector> |
| 20 |
| 21 | #include <assert.h> |
| 22 | #include <errno.h> |
| 23 | #include <stdint.h> |
| 24 | #include <stdlib.h> |
| 25 | #include <string.h> |
| 26 |
| 27 | #include <openssl/aead.h> |
| 28 | #include <openssl/aes.h> |
| 29 | #include <openssl/bn.h> |
| 30 | #include <openssl/curve25519.h> |
| 31 | #include <openssl/digest.h> |
| 32 | #include <openssl/err.h> |
| 33 | #include <openssl/ec.h> |
| 34 | #include <openssl/ecdsa.h> |
| 35 | #include <openssl/ec_key.h> |
| 36 | #include <openssl/evp.h> |
| 37 | #include <openssl/hrss.h> |
| 38 | #include <openssl/nid.h> |
| 39 | #include <openssl/rand.h> |
| 40 | #include <openssl/rsa.h> |
| 41 |
| 42 | #if defined(OPENSSL_WINDOWS) |
| 43 | OPENSSL_MSVC_PRAGMA(warning(push, 3)) |
| 44 | #include <windows.h> |
| 45 | OPENSSL_MSVC_PRAGMA(warning(pop)) |
| 46 | #elif defined(OPENSSL_APPLE) |
| 47 | #include <sys/time.h> |
| 48 | #else |
| 49 | #include <time.h> |
| 50 | #endif |
| 51 |
| 52 | #include "../crypto/internal.h" |
| 53 | #include "internal.h" |
| 54 |
| 55 | #include "../third_party/sike/sike.h" |
| 56 |
| 57 |
| 58 | // TimeResults represents the results of benchmarking a function. |
| 59 | struct TimeResults { |
| 60 | // num_calls is the number of function calls done in the time period. |
| 61 | unsigned num_calls; |
| 62 | // us is the number of microseconds that elapsed in the time period. |
| 63 | unsigned us; |
| 64 |
| 65 | void Print(const std::string &description) { |
| 66 | printf("Did %u %s operations in %uus (%.1f ops/sec)\n", num_calls, |
| 67 | description.c_str(), us, |
| 68 | (static_cast<double>(num_calls) / us) * 1000000); |
| 69 | } |
| 70 |
| 71 | void PrintWithBytes(const std::string &description, size_t bytes_per_call) { |
| 72 | printf("Did %u %s operations in %uus (%.1f ops/sec): %.1f MB/s\n", |
| 73 | num_calls, description.c_str(), us, |
| 74 | (static_cast<double>(num_calls) / us) * 1000000, |
| 75 | static_cast<double>(bytes_per_call * num_calls) / us); |
| 76 | } |
| 77 | }; |
| 78 |
| 79 | #if defined(OPENSSL_WINDOWS) |
| 80 | static uint64_t time_now() { return GetTickCount64() * 1000; } |
| 81 | #elif defined(OPENSSL_APPLE) |
| 82 | static uint64_t time_now() { |
| 83 | struct timeval tv; |
| 84 | uint64_t ret; |
| 85 |
| 86 | gettimeofday(&tv, NULL); |
| 87 | ret = tv.tv_sec; |
| 88 | ret *= 1000000; |
| 89 | ret += tv.tv_usec; |
| 90 | return ret; |
| 91 | } |
| 92 | #else |
| 93 | static uint64_t time_now() { |
| 94 | struct timespec ts; |
| 95 | clock_gettime(CLOCK_MONOTONIC, &ts); |
| 96 |
| 97 | uint64_t ret = ts.tv_sec; |
| 98 | ret *= 1000000; |
| 99 | ret += ts.tv_nsec / 1000; |
| 100 | return ret; |
| 101 | } |
| 102 | #endif |
| 103 |
| 104 | static uint64_t g_timeout_seconds = 1; |
| 105 | static std::vector<size_t> g_chunk_lengths = {16, 256, 1350, 8192, 16384}; |
| 106 |
| 107 | static bool TimeFunction(TimeResults *results, std::function<bool()> func) { |
| 108 | // total_us is the total amount of time that we'll aim to measure a function |
| 109 | // for. |
| 110 | const uint64_t total_us = g_timeout_seconds * 1000000; |
| 111 | uint64_t start = time_now(), now, delta; |
| 112 | unsigned done = 0, iterations_between_time_checks; |
| 113 |
| 114 | if (!func()) { |
| 115 | return false; |
| 116 | } |
| 117 | now = time_now(); |
| 118 | delta = now - start; |
| 119 | if (delta == 0) { |
| 120 | iterations_between_time_checks = 250; |
| 121 | } else { |
| 122 | // Aim for about 100ms between time checks. |
| 123 | iterations_between_time_checks = |
| 124 | static_cast<double>(100000) / static_cast<double>(delta); |
| 125 | if (iterations_between_time_checks > 1000) { |
| 126 | iterations_between_time_checks = 1000; |
| 127 | } else if (iterations_between_time_checks < 1) { |
| 128 | iterations_between_time_checks = 1; |
| 129 | } |
| 130 | } |
| 131 |
| 132 | for (;;) { |
| 133 | for (unsigned i = 0; i < iterations_between_time_checks; i++) { |
| 134 | if (!func()) { |
| 135 | return false; |
| 136 | } |
| 137 | done++; |
| 138 | } |
| 139 |
| 140 | now = time_now(); |
| 141 | if (now - start > total_us) { |
| 142 | break; |
| 143 | } |
| 144 | } |
| 145 |
| 146 | results->us = now - start; |
| 147 | results->num_calls = done; |
| 148 | return true; |
| 149 | } |
| 150 |
| 151 | static bool SpeedRSA(const std::string &selected) { |
| 152 | if (!selected.empty() && selected.find("RSA") == std::string::npos) { |
| 153 | return true; |
| 154 | } |
| 155 |
| 156 | static const struct { |
| 157 | const char *name; |
| 158 | const uint8_t *key; |
| 159 | const size_t key_len; |
| 160 | } kRSAKeys[] = { |
| 161 | {"RSA 2048", kDERRSAPrivate2048, kDERRSAPrivate2048Len}, |
| 162 | {"RSA 4096", kDERRSAPrivate4096, kDERRSAPrivate4096Len}, |
| 163 | }; |
| 164 |
| 165 | for (unsigned i = 0; i < OPENSSL_ARRAY_SIZE(kRSAKeys); i++) { |
| 166 | const std::string name = kRSAKeys[i].name; |
| 167 |
| 168 | bssl::UniquePtr<RSA> key( |
| 169 | RSA_private_key_from_bytes(kRSAKeys[i].key, kRSAKeys[i].key_len)); |
| 170 | if (key == nullptr) { |
| 171 | fprintf(stderr, "Failed to parse %s key.\n", name.c_str()); |
| 172 | ERR_print_errors_fp(stderr); |
| 173 | return false; |
| 174 | } |
| 175 |
| 176 | std::unique_ptr<uint8_t[]> sig(new uint8_t[RSA_size(key.get())]); |
| 177 | const uint8_t fake_sha256_hash[32] = {0}; |
| 178 | unsigned sig_len; |
| 179 |
| 180 | TimeResults results; |
| 181 | if (!TimeFunction(&results, |
| 182 | [&key, &sig, &fake_sha256_hash, &sig_len]() -> bool { |
| 183 | // Usually during RSA signing we're using a long-lived |RSA| that has |
| 184 | // already had all of its |BN_MONT_CTX|s constructed, so it makes |
| 185 | // sense to use |key| directly here. |
| 186 | return RSA_sign(NID_sha256, fake_sha256_hash, sizeof(fake_sha256_hash), |
| 187 | sig.get(), &sig_len, key.get()); |
| 188 | })) { |
| 189 | fprintf(stderr, "RSA_sign failed.\n"); |
| 190 | ERR_print_errors_fp(stderr); |
| 191 | return false; |
| 192 | } |
| 193 | results.Print(name + " signing"); |
| 194 |
| 195 | if (!TimeFunction(&results, |
| 196 | [&key, &fake_sha256_hash, &sig, sig_len]() -> bool { |
| 197 | return RSA_verify( |
| 198 | NID_sha256, fake_sha256_hash, sizeof(fake_sha256_hash), |
| 199 | sig.get(), sig_len, key.get()); |
| 200 | })) { |
| 201 | fprintf(stderr, "RSA_verify failed.\n"); |
| 202 | ERR_print_errors_fp(stderr); |
| 203 | return false; |
| 204 | } |
| 205 | results.Print(name + " verify (same key)"); |
| 206 |
| 207 | if (!TimeFunction(&results, |
| 208 | [&key, &fake_sha256_hash, &sig, sig_len]() -> bool { |
| 209 | // Usually during RSA verification we have to parse an RSA key from a |
| 210 | // certificate or similar, in which case we'd need to construct a new |
| 211 | // RSA key, with a new |BN_MONT_CTX| for the public modulus. If we |
| 212 | // were to use |key| directly instead, then these costs wouldn't be |
| 213 | // accounted for. |
| 214 | bssl::UniquePtr<RSA> verify_key(RSA_new()); |
| 215 | if (!verify_key) { |
| 216 | return false; |
| 217 | } |
| 218 | verify_key->n = BN_dup(key->n); |
| 219 | verify_key->e = BN_dup(key->e); |
| 220 | if (!verify_key->n || |
| 221 | !verify_key->e) { |
| 222 | return false; |
| 223 | } |
| 224 | return RSA_verify(NID_sha256, fake_sha256_hash, |
| 225 | sizeof(fake_sha256_hash), sig.get(), sig_len, |
| 226 | verify_key.get()); |
| 227 | })) { |
| 228 | fprintf(stderr, "RSA_verify failed.\n"); |
| 229 | ERR_print_errors_fp(stderr); |
| 230 | return false; |
| 231 | } |
| 232 | results.Print(name + " verify (fresh key)"); |
| 233 | } |
| 234 |
| 235 | return true; |
| 236 | } |
| 237 |
| 238 | static bool SpeedRSAKeyGen(const std::string &selected) { |
| 239 | // Don't run this by default because it's so slow. |
| 240 | if (selected != "RSAKeyGen") { |
| 241 | return true; |
| 242 | } |
| 243 |
| 244 | bssl::UniquePtr<BIGNUM> e(BN_new()); |
| 245 | if (!BN_set_word(e.get(), 65537)) { |
| 246 | return false; |
| 247 | } |
| 248 |
| 249 | const std::vector<int> kSizes = {2048, 3072, 4096}; |
| 250 | for (int size : kSizes) { |
| 251 | const uint64_t start = time_now(); |
| 252 | unsigned num_calls = 0; |
| 253 | unsigned us; |
| 254 | std::vector<unsigned> durations; |
| 255 |
| 256 | for (;;) { |
| 257 | bssl::UniquePtr<RSA> rsa(RSA_new()); |
| 258 |
| 259 | const uint64_t iteration_start = time_now(); |
| 260 | if (!RSA_generate_key_ex(rsa.get(), size, e.get(), nullptr)) { |
| 261 | fprintf(stderr, "RSA_generate_key_ex failed.\n"); |
| 262 | ERR_print_errors_fp(stderr); |
| 263 | return false; |
| 264 | } |
| 265 | const uint64_t iteration_end = time_now(); |
| 266 |
| 267 | num_calls++; |
| 268 | durations.push_back(iteration_end - iteration_start); |
| 269 |
| 270 | us = iteration_end - start; |
| 271 | if (us > 30 * 1000000 /* 30 secs */) { |
| 272 | break; |
| 273 | } |
| 274 | } |
| 275 |
| 276 | std::sort(durations.begin(), durations.end()); |
| 277 | printf("Did %u RSA %d key-gen operations in %uus (%.1f ops/sec)\n", |
| 278 | num_calls, size, us, |
| 279 | (static_cast<double>(num_calls) / us) * 1000000); |
| 280 | const size_t n = durations.size(); |
| 281 | assert(n > 0); |
| 282 |
| 283 | // |min| and |max| must be stored in temporary variables to avoid an MSVC |
| 284 | // bug on x86. There, size_t is a typedef for unsigned, but MSVC's printf |
| 285 | // warning tries to retain the distinction and suggest %zu for size_t |
| 286 | // instead of %u. It gets confused if std::vector<unsigned> and |
| 287 | // std::vector<size_t> are both instantiated. Being typedefs, the two |
| 288 | // instantiations are identical, which somehow breaks the size_t vs unsigned |
| 289 | // metadata. |
| 290 | unsigned min = durations[0]; |
| 291 | unsigned median = n & 1 ? durations[n / 2] |
| 292 | : (durations[n / 2 - 1] + durations[n / 2]) / 2; |
| 293 | unsigned max = durations[n - 1]; |
| 294 | printf(" min: %uus, median: %uus, max: %uus\n", min, median, max); |
| 295 | } |
| 296 |
| 297 | return true; |
| 298 | } |
| 299 |
| 300 | static bool SpeedSIKEP434(const std::string &selected) { |
| 301 | if (!selected.empty() && selected.find("SIKE") == std::string::npos) { |
| 302 | return true; |
| 303 | } |
| 304 | // speed generation |
| 305 | uint8_t public_SIKE[SIKE_PUB_BYTESZ]; |
| 306 | uint8_t private_SIKE[SIKE_PRV_BYTESZ]; |
| 307 | uint8_t ct[SIKE_CT_BYTESZ]; |
| 308 | bool res; |
| 309 |
| 310 | { |
| 311 | TimeResults results; |
| 312 | res = TimeFunction(&results, |
| 313 | [&private_SIKE, &public_SIKE]() -> bool { |
| 314 | return (SIKE_keypair(private_SIKE, public_SIKE) == 1); |
| 315 | }); |
| 316 | results.Print("SIKE/P434 generate"); |
| 317 | } |
| 318 |
| 319 | if (!res) { |
| 320 | fprintf(stderr, "Failed to time SIKE_keypair.\n"); |
| 321 | return false; |
| 322 | } |
| 323 |
| 324 | { |
| 325 | TimeResults results; |
| 326 | TimeFunction(&results, |
| 327 | [&ct, &public_SIKE]() -> bool { |
| 328 | uint8_t ss[SIKE_SS_BYTESZ]; |
| 329 | SIKE_encaps(ss, ct, public_SIKE); |
| 330 | return true; |
| 331 | }); |
| 332 | results.Print("SIKE/P434 encap"); |
| 333 | } |
| 334 |
| 335 | if (!res) { |
| 336 | fprintf(stderr, "Failed to time SIKE_encaps.\n"); |
| 337 | return false; |
| 338 | } |
| 339 |
| 340 | { |
| 341 | TimeResults results; |
| 342 | TimeFunction(&results, |
| 343 | [&ct, &public_SIKE, &private_SIKE]() -> bool { |
| 344 | uint8_t ss[SIKE_SS_BYTESZ]; |
| 345 | SIKE_decaps(ss, ct, public_SIKE, private_SIKE); |
| 346 | return true; |
| 347 | }); |
| 348 | results.Print("SIKE/P434 decap"); |
| 349 | } |
| 350 |
| 351 | if (!res) { |
| 352 | fprintf(stderr, "Failed to time SIKE_decaps.\n"); |
| 353 | return false; |
| 354 | } |
| 355 | return true; |
| 356 | } |
| 357 |
| 358 | static uint8_t *align(uint8_t *in, unsigned alignment) { |
| 359 | return reinterpret_cast<uint8_t *>( |
| 360 | (reinterpret_cast<uintptr_t>(in) + alignment) & |
| 361 | ~static_cast<size_t>(alignment - 1)); |
| 362 | } |
| 363 |
| 364 | static std::string ChunkLenSuffix(size_t chunk_len) { |
| 365 | char buf[32]; |
| 366 | snprintf(buf, sizeof(buf), " (%zu byte%s)", chunk_len, |
| 367 | chunk_len != 1 ? "s" : ""); |
| 368 | return buf; |
| 369 | } |
| 370 |
| 371 | static bool SpeedAEADChunk(const EVP_AEAD *aead, std::string name, |
| 372 | size_t chunk_len, size_t ad_len, |
| 373 | evp_aead_direction_t direction) { |
| 374 | static const unsigned kAlignment = 16; |
| 375 |
| 376 | name += ChunkLenSuffix(chunk_len); |
| 377 | bssl::ScopedEVP_AEAD_CTX ctx; |
| 378 | const size_t key_len = EVP_AEAD_key_length(aead); |
| 379 | const size_t nonce_len = EVP_AEAD_nonce_length(aead); |
| 380 | const size_t overhead_len = EVP_AEAD_max_overhead(aead); |
| 381 |
| 382 | std::unique_ptr<uint8_t[]> key(new uint8_t[key_len]); |
| 383 | OPENSSL_memset(key.get(), 0, key_len); |
| 384 | std::unique_ptr<uint8_t[]> nonce(new uint8_t[nonce_len]); |
| 385 | OPENSSL_memset(nonce.get(), 0, nonce_len); |
| 386 | std::unique_ptr<uint8_t[]> in_storage(new uint8_t[chunk_len + kAlignment]); |
| 387 | // N.B. for EVP_AEAD_CTX_seal_scatter the input and output buffers may be the |
| 388 | // same size. However, in the direction == evp_aead_open case we still use |
| 389 | // non-scattering seal, hence we add overhead_len to the size of this buffer. |
| 390 | std::unique_ptr<uint8_t[]> out_storage( |
| 391 | new uint8_t[chunk_len + overhead_len + kAlignment]); |
| 392 | std::unique_ptr<uint8_t[]> in2_storage( |
| 393 | new uint8_t[chunk_len + overhead_len + kAlignment]); |
| 394 | std::unique_ptr<uint8_t[]> ad(new uint8_t[ad_len]); |
| 395 | OPENSSL_memset(ad.get(), 0, ad_len); |
| 396 | std::unique_ptr<uint8_t[]> tag_storage( |
| 397 | new uint8_t[overhead_len + kAlignment]); |
| 398 |
| 399 |
| 400 | uint8_t *const in = align(in_storage.get(), kAlignment); |
| 401 | OPENSSL_memset(in, 0, chunk_len); |
| 402 | uint8_t *const out = align(out_storage.get(), kAlignment); |
| 403 | OPENSSL_memset(out, 0, chunk_len + overhead_len); |
| 404 | uint8_t *const tag = align(tag_storage.get(), kAlignment); |
| 405 | OPENSSL_memset(tag, 0, overhead_len); |
| 406 | uint8_t *const in2 = align(in2_storage.get(), kAlignment); |
| 407 |
| 408 | if (!EVP_AEAD_CTX_init_with_direction(ctx.get(), aead, key.get(), key_len, |
| 409 | EVP_AEAD_DEFAULT_TAG_LENGTH, |
| 410 | evp_aead_seal)) { |
| 411 | fprintf(stderr, "Failed to create EVP_AEAD_CTX.\n"); |
| 412 | ERR_print_errors_fp(stderr); |
| 413 | return false; |
| 414 | } |
| 415 |
| 416 | TimeResults results; |
| 417 | if (direction == evp_aead_seal) { |
| 418 | if (!TimeFunction(&results, |
| 419 | [chunk_len, nonce_len, ad_len, overhead_len, in, out, tag, |
| 420 | &ctx, &nonce, &ad]() -> bool { |
| 421 | size_t tag_len; |
| 422 | return EVP_AEAD_CTX_seal_scatter( |
| 423 | ctx.get(), out, tag, &tag_len, overhead_len, |
| 424 | nonce.get(), nonce_len, in, chunk_len, nullptr, 0, |
| 425 | ad.get(), ad_len); |
| 426 | })) { |
| 427 | fprintf(stderr, "EVP_AEAD_CTX_seal failed.\n"); |
| 428 | ERR_print_errors_fp(stderr); |
| 429 | return false; |
| 430 | } |
| 431 | } else { |
| 432 | size_t out_len; |
| 433 | EVP_AEAD_CTX_seal(ctx.get(), out, &out_len, chunk_len + overhead_len, |
| 434 | nonce.get(), nonce_len, in, chunk_len, ad.get(), ad_len); |
| 435 |
| 436 | ctx.Reset(); |
| 437 | if (!EVP_AEAD_CTX_init_with_direction(ctx.get(), aead, key.get(), key_len, |
| 438 | EVP_AEAD_DEFAULT_TAG_LENGTH, |
| 439 | evp_aead_open)) { |
| 440 | fprintf(stderr, "Failed to create EVP_AEAD_CTX.\n"); |
| 441 | ERR_print_errors_fp(stderr); |
| 442 | return false; |
| 443 | } |
| 444 |
| 445 | if (!TimeFunction(&results, |
| 446 | [chunk_len, overhead_len, nonce_len, ad_len, in2, out, |
| 447 | out_len, &ctx, &nonce, &ad]() -> bool { |
| 448 | size_t in2_len; |
| 449 | // N.B. EVP_AEAD_CTX_open_gather is not implemented for |
| 450 | // all AEADs. |
| 451 | return EVP_AEAD_CTX_open(ctx.get(), in2, &in2_len, |
| 452 | chunk_len + overhead_len, |
| 453 | nonce.get(), nonce_len, out, |
| 454 | out_len, ad.get(), ad_len); |
| 455 | })) { |
| 456 | fprintf(stderr, "EVP_AEAD_CTX_open failed.\n"); |
| 457 | ERR_print_errors_fp(stderr); |
| 458 | return false; |
| 459 | } |
| 460 | } |
| 461 |
| 462 | results.PrintWithBytes( |
| 463 | name + (direction == evp_aead_seal ? " seal" : " open"), chunk_len); |
| 464 | return true; |
| 465 | } |
| 466 |
| 467 | static bool SpeedAEAD(const EVP_AEAD *aead, const std::string &name, |
| 468 | size_t ad_len, const std::string &selected) { |
| 469 | if (!selected.empty() && name.find(selected) == std::string::npos) { |
| 470 | return true; |
| 471 | } |
| 472 |
| 473 | for (size_t chunk_len : g_chunk_lengths) { |
| 474 | if (!SpeedAEADChunk(aead, name, chunk_len, ad_len, evp_aead_seal)) { |
| 475 | return false; |
| 476 | } |
| 477 | } |
| 478 | return true; |
| 479 | } |
| 480 |
| 481 | static bool SpeedAEADOpen(const EVP_AEAD *aead, const std::string &name, |
| 482 | size_t ad_len, const std::string &selected) { |
| 483 | if (!selected.empty() && name.find(selected) == std::string::npos) { |
| 484 | return true; |
| 485 | } |
| 486 |
| 487 | for (size_t chunk_len : g_chunk_lengths) { |
| 488 | if (!SpeedAEADChunk(aead, name, chunk_len, ad_len, evp_aead_open)) { |
| 489 | return false; |
| 490 | } |
| 491 | } |
| 492 |
| 493 | return true; |
| 494 | } |
| 495 |
| 496 | static bool SpeedAESBlock(const std::string &name, unsigned bits, |
| 497 | const std::string &selected) { |
| 498 | if (!selected.empty() && name.find(selected) == std::string::npos) { |
| 499 | return true; |
| 500 | } |
| 501 |
| 502 | static const uint8_t kZero[32] = {0}; |
| 503 |
| 504 | { |
| 505 | TimeResults results; |
| 506 | if (!TimeFunction(&results, [&]() -> bool { |
| 507 | AES_KEY key; |
| 508 | return AES_set_encrypt_key(kZero, bits, &key) == 0; |
| 509 | })) { |
| 510 | fprintf(stderr, "AES_set_encrypt_key failed.\n"); |
| 511 | return false; |
| 512 | } |
| 513 | results.Print(name + " encrypt setup"); |
| 514 | } |
| 515 |
| 516 | { |
| 517 | AES_KEY key; |
| 518 | if (AES_set_encrypt_key(kZero, bits, &key) != 0) { |
| 519 | return false; |
| 520 | } |
| 521 | uint8_t block[16] = {0}; |
| 522 | TimeResults results; |
| 523 | if (!TimeFunction(&results, [&]() -> bool { |
| 524 | AES_encrypt(block, block, &key); |
| 525 | return true; |
| 526 | })) { |
| 527 | fprintf(stderr, "AES_encrypt failed.\n"); |
| 528 | return false; |
| 529 | } |
| 530 | results.Print(name + " encrypt"); |
| 531 | } |
| 532 |
| 533 | { |
| 534 | TimeResults results; |
| 535 | if (!TimeFunction(&results, [&]() -> bool { |
| 536 | AES_KEY key; |
| 537 | return AES_set_decrypt_key(kZero, bits, &key) == 0; |
| 538 | })) { |
| 539 | fprintf(stderr, "AES_set_decrypt_key failed.\n"); |
| 540 | return false; |
| 541 | } |
| 542 | results.Print(name + " decrypt setup"); |
| 543 | } |
| 544 |
| 545 | { |
| 546 | AES_KEY key; |
| 547 | if (AES_set_decrypt_key(kZero, bits, &key) != 0) { |
| 548 | return false; |
| 549 | } |
| 550 | uint8_t block[16] = {0}; |
| 551 | TimeResults results; |
| 552 | if (!TimeFunction(&results, [&]() -> bool { |
| 553 | AES_decrypt(block, block, &key); |
| 554 | return true; |
| 555 | })) { |
| 556 | fprintf(stderr, "AES_decrypt failed.\n"); |
| 557 | return false; |
| 558 | } |
| 559 | results.Print(name + " decrypt"); |
| 560 | } |
| 561 |
| 562 | return true; |
| 563 | } |
| 564 |
| 565 | static bool SpeedHashChunk(const EVP_MD *md, std::string name, |
| 566 | size_t chunk_len) { |
| 567 | bssl::ScopedEVP_MD_CTX ctx; |
| 568 | uint8_t scratch[16384]; |
| 569 |
| 570 | if (chunk_len > sizeof(scratch)) { |
| 571 | return false; |
| 572 | } |
| 573 |
| 574 | name += ChunkLenSuffix(chunk_len); |
| 575 | TimeResults results; |
| 576 | if (!TimeFunction(&results, [&ctx, md, chunk_len, &scratch]() -> bool { |
| 577 | uint8_t digest[EVP_MAX_MD_SIZE]; |
| 578 | unsigned int md_len; |
| 579 |
| 580 | return EVP_DigestInit_ex(ctx.get(), md, NULL /* ENGINE */) && |
| 581 | EVP_DigestUpdate(ctx.get(), scratch, chunk_len) && |
| 582 | EVP_DigestFinal_ex(ctx.get(), digest, &md_len); |
| 583 | })) { |
| 584 | fprintf(stderr, "EVP_DigestInit_ex failed.\n"); |
| 585 | ERR_print_errors_fp(stderr); |
| 586 | return false; |
| 587 | } |
| 588 |
| 589 | results.PrintWithBytes(name, chunk_len); |
| 590 | return true; |
| 591 | } |
| 592 |
| 593 | static bool SpeedHash(const EVP_MD *md, const std::string &name, |
| 594 | const std::string &selected) { |
| 595 | if (!selected.empty() && name.find(selected) == std::string::npos) { |
| 596 | return true; |
| 597 | } |
| 598 |
| 599 | for (size_t chunk_len : g_chunk_lengths) { |
| 600 | if (!SpeedHashChunk(md, name, chunk_len)) { |
| 601 | return false; |
| 602 | } |
| 603 | } |
| 604 |
| 605 | return true; |
| 606 | } |
| 607 |
| 608 | static bool SpeedRandomChunk(std::string name, size_t chunk_len) { |
| 609 | uint8_t scratch[16384]; |
| 610 |
| 611 | if (chunk_len > sizeof(scratch)) { |
| 612 | return false; |
| 613 | } |
| 614 |
| 615 | name += ChunkLenSuffix(chunk_len); |
| 616 | TimeResults results; |
| 617 | if (!TimeFunction(&results, [chunk_len, &scratch]() -> bool { |
| 618 | RAND_bytes(scratch, chunk_len); |
| 619 | return true; |
| 620 | })) { |
| 621 | return false; |
| 622 | } |
| 623 |
| 624 | results.PrintWithBytes(name, chunk_len); |
| 625 | return true; |
| 626 | } |
| 627 |
| 628 | static bool SpeedRandom(const std::string &selected) { |
| 629 | if (!selected.empty() && selected != "RNG") { |
| 630 | return true; |
| 631 | } |
| 632 |
| 633 | for (size_t chunk_len : g_chunk_lengths) { |
| 634 | if (!SpeedRandomChunk("RNG", chunk_len)) { |
| 635 | return false; |
| 636 | } |
| 637 | } |
| 638 |
| 639 | return true; |
| 640 | } |
| 641 |
| 642 | static bool SpeedECDHCurve(const std::string &name, int nid, |
| 643 | const std::string &selected) { |
| 644 | if (!selected.empty() && name.find(selected) == std::string::npos) { |
| 645 | return true; |
| 646 | } |
| 647 |
| 648 | bssl::UniquePtr<EC_KEY> peer_key(EC_KEY_new_by_curve_name(nid)); |
| 649 | if (!peer_key || |
| 650 | !EC_KEY_generate_key(peer_key.get())) { |
| 651 | return false; |
| 652 | } |
| 653 |
| 654 | size_t peer_value_len = EC_POINT_point2oct( |
| 655 | EC_KEY_get0_group(peer_key.get()), EC_KEY_get0_public_key(peer_key.get()), |
| 656 | POINT_CONVERSION_UNCOMPRESSED, nullptr, 0, nullptr); |
| 657 | if (peer_value_len == 0) { |
| 658 | return false; |
| 659 | } |
| 660 | std::unique_ptr<uint8_t[]> peer_value(new uint8_t[peer_value_len]); |
| 661 | peer_value_len = EC_POINT_point2oct( |
| 662 | EC_KEY_get0_group(peer_key.get()), EC_KEY_get0_public_key(peer_key.get()), |
| 663 | POINT_CONVERSION_UNCOMPRESSED, peer_value.get(), peer_value_len, nullptr); |
| 664 | if (peer_value_len == 0) { |
| 665 | return false; |
| 666 | } |
| 667 |
| 668 | TimeResults results; |
| 669 | if (!TimeFunction(&results, [nid, peer_value_len, &peer_value]() -> bool { |
| 670 | bssl::UniquePtr<EC_KEY> key(EC_KEY_new_by_curve_name(nid)); |
| 671 | if (!key || |
| 672 | !EC_KEY_generate_key(key.get())) { |
| 673 | return false; |
| 674 | } |
| 675 | const EC_GROUP *const group = EC_KEY_get0_group(key.get()); |
| 676 | bssl::UniquePtr<EC_POINT> point(EC_POINT_new(group)); |
| 677 | bssl::UniquePtr<EC_POINT> peer_point(EC_POINT_new(group)); |
| 678 | bssl::UniquePtr<BN_CTX> ctx(BN_CTX_new()); |
| 679 |
| 680 | bssl::UniquePtr<BIGNUM> x(BN_new()); |
| 681 | bssl::UniquePtr<BIGNUM> y(BN_new()); |
| 682 |
| 683 | if (!point || !peer_point || !ctx || !x || !y || |
| 684 | !EC_POINT_oct2point(group, peer_point.get(), peer_value.get(), |
| 685 | peer_value_len, ctx.get()) || |
| 686 | !EC_POINT_mul(group, point.get(), NULL, peer_point.get(), |
| 687 | EC_KEY_get0_private_key(key.get()), ctx.get()) || |
| 688 | !EC_POINT_get_affine_coordinates_GFp(group, point.get(), x.get(), |
| 689 | y.get(), ctx.get())) { |
| 690 | return false; |
| 691 | } |
| 692 |
| 693 | return true; |
| 694 | })) { |
| 695 | return false; |
| 696 | } |
| 697 |
| 698 | results.Print(name); |
| 699 | return true; |
| 700 | } |
| 701 |
| 702 | static bool SpeedECDSACurve(const std::string &name, int nid, |
| 703 | const std::string &selected) { |
| 704 | if (!selected.empty() && name.find(selected) == std::string::npos) { |
| 705 | return true; |
| 706 | } |
| 707 |
| 708 | bssl::UniquePtr<EC_KEY> key(EC_KEY_new_by_curve_name(nid)); |
| 709 | if (!key || |
| 710 | !EC_KEY_generate_key(key.get())) { |
| 711 | return false; |
| 712 | } |
| 713 |
| 714 | uint8_t signature[256]; |
| 715 | if (ECDSA_size(key.get()) > sizeof(signature)) { |
| 716 | return false; |
| 717 | } |
| 718 | uint8_t digest[20]; |
| 719 | OPENSSL_memset(digest, 42, sizeof(digest)); |
| 720 | unsigned sig_len; |
| 721 |
| 722 | TimeResults results; |
| 723 | if (!TimeFunction(&results, [&key, &signature, &digest, &sig_len]() -> bool { |
| 724 | return ECDSA_sign(0, digest, sizeof(digest), signature, &sig_len, |
| 725 | key.get()) == 1; |
| 726 | })) { |
| 727 | return false; |
| 728 | } |
| 729 |
| 730 | results.Print(name + " signing"); |
| 731 |
| 732 | if (!TimeFunction(&results, [&key, &signature, &digest, sig_len]() -> bool { |
| 733 | return ECDSA_verify(0, digest, sizeof(digest), signature, sig_len, |
| 734 | key.get()) == 1; |
| 735 | })) { |
| 736 | return false; |
| 737 | } |
| 738 |
| 739 | results.Print(name + " verify"); |
| 740 |
| 741 | return true; |
| 742 | } |
| 743 |
| 744 | static bool SpeedECDH(const std::string &selected) { |
| 745 | return SpeedECDHCurve("ECDH P-224", NID_secp224r1, selected) && |
| 746 | SpeedECDHCurve("ECDH P-256", NID_X9_62_prime256v1, selected) && |
| 747 | SpeedECDHCurve("ECDH P-384", NID_secp384r1, selected) && |
| 748 | SpeedECDHCurve("ECDH P-521", NID_secp521r1, selected); |
| 749 | } |
| 750 |
| 751 | static bool SpeedECDSA(const std::string &selected) { |
| 752 | return SpeedECDSACurve("ECDSA P-224", NID_secp224r1, selected) && |
| 753 | SpeedECDSACurve("ECDSA P-256", NID_X9_62_prime256v1, selected) && |
| 754 | SpeedECDSACurve("ECDSA P-384", NID_secp384r1, selected) && |
| 755 | SpeedECDSACurve("ECDSA P-521", NID_secp521r1, selected); |
| 756 | } |
| 757 |
| 758 | static bool Speed25519(const std::string &selected) { |
| 759 | if (!selected.empty() && selected.find("25519") == std::string::npos) { |
| 760 | return true; |
| 761 | } |
| 762 |
| 763 | TimeResults results; |
| 764 |
| 765 | uint8_t public_key[32], private_key[64]; |
| 766 |
| 767 | if (!TimeFunction(&results, [&public_key, &private_key]() -> bool { |
| 768 | ED25519_keypair(public_key, private_key); |
| 769 | return true; |
| 770 | })) { |
| 771 | return false; |
| 772 | } |
| 773 |
| 774 | results.Print("Ed25519 key generation"); |
| 775 |
| 776 | static const uint8_t kMessage[] = {0, 1, 2, 3, 4, 5}; |
| 777 | uint8_t signature[64]; |
| 778 |
| 779 | if (!TimeFunction(&results, [&private_key, &signature]() -> bool { |
| 780 | return ED25519_sign(signature, kMessage, sizeof(kMessage), |
| 781 | private_key) == 1; |
| 782 | })) { |
| 783 | return false; |
| 784 | } |
| 785 |
| 786 | results.Print("Ed25519 signing"); |
| 787 |
| 788 | if (!TimeFunction(&results, [&public_key, &signature]() -> bool { |
| 789 | return ED25519_verify(kMessage, sizeof(kMessage), signature, |
| 790 | public_key) == 1; |
| 791 | })) { |
| 792 | fprintf(stderr, "Ed25519 verify failed.\n"); |
| 793 | return false; |
| 794 | } |
| 795 |
| 796 | results.Print("Ed25519 verify"); |
| 797 |
| 798 | if (!TimeFunction(&results, []() -> bool { |
| 799 | uint8_t out[32], in[32]; |
| 800 | OPENSSL_memset(in, 0, sizeof(in)); |
| 801 | X25519_public_from_private(out, in); |
| 802 | return true; |
| 803 | })) { |
| 804 | fprintf(stderr, "Curve25519 base-point multiplication failed.\n"); |
| 805 | return false; |
| 806 | } |
| 807 |
| 808 | results.Print("Curve25519 base-point multiplication"); |
| 809 |
| 810 | if (!TimeFunction(&results, []() -> bool { |
| 811 | uint8_t out[32], in1[32], in2[32]; |
| 812 | OPENSSL_memset(in1, 0, sizeof(in1)); |
| 813 | OPENSSL_memset(in2, 0, sizeof(in2)); |
| 814 | in1[0] = 1; |
| 815 | in2[0] = 9; |
| 816 | return X25519(out, in1, in2) == 1; |
| 817 | })) { |
| 818 | fprintf(stderr, "Curve25519 arbitrary point multiplication failed.\n"); |
| 819 | return false; |
| 820 | } |
| 821 |
| 822 | results.Print("Curve25519 arbitrary point multiplication"); |
| 823 |
| 824 | return true; |
| 825 | } |
| 826 |
| 827 | static bool SpeedSPAKE2(const std::string &selected) { |
| 828 | if (!selected.empty() && selected.find("SPAKE2") == std::string::npos) { |
| 829 | return true; |
| 830 | } |
| 831 |
| 832 | TimeResults results; |
| 833 |
| 834 | static const uint8_t kAliceName[] = {'A'}; |
| 835 | static const uint8_t kBobName[] = {'B'}; |
| 836 | static const uint8_t kPassword[] = "password"; |
| 837 | bssl::UniquePtr<SPAKE2_CTX> alice(SPAKE2_CTX_new(spake2_role_alice, |
| 838 | kAliceName, sizeof(kAliceName), kBobName, |
| 839 | sizeof(kBobName))); |
| 840 | uint8_t alice_msg[SPAKE2_MAX_MSG_SIZE]; |
| 841 | size_t alice_msg_len; |
| 842 |
| 843 | if (!SPAKE2_generate_msg(alice.get(), alice_msg, &alice_msg_len, |
| 844 | sizeof(alice_msg), |
| 845 | kPassword, sizeof(kPassword))) { |
| 846 | fprintf(stderr, "SPAKE2_generate_msg failed.\n"); |
| 847 | return false; |
| 848 | } |
| 849 |
| 850 | if (!TimeFunction(&results, [&alice_msg, alice_msg_len]() -> bool { |
| 851 | bssl::UniquePtr<SPAKE2_CTX> bob(SPAKE2_CTX_new(spake2_role_bob, |
| 852 | kBobName, sizeof(kBobName), kAliceName, |
| 853 | sizeof(kAliceName))); |
| 854 | uint8_t bob_msg[SPAKE2_MAX_MSG_SIZE], bob_key[64]; |
| 855 | size_t bob_msg_len, bob_key_len; |
| 856 | if (!SPAKE2_generate_msg(bob.get(), bob_msg, &bob_msg_len, |
| 857 | sizeof(bob_msg), kPassword, |
| 858 | sizeof(kPassword)) || |
| 859 | !SPAKE2_process_msg(bob.get(), bob_key, &bob_key_len, |
| 860 | sizeof(bob_key), alice_msg, alice_msg_len)) { |
| 861 | return false; |
| 862 | } |
| 863 |
| 864 | return true; |
| 865 | })) { |
| 866 | fprintf(stderr, "SPAKE2 failed.\n"); |
| 867 | } |
| 868 |
| 869 | results.Print("SPAKE2 over Ed25519"); |
| 870 |
| 871 | return true; |
| 872 | } |
| 873 |
| 874 | static bool SpeedScrypt(const std::string &selected) { |
| 875 | if (!selected.empty() && selected.find("scrypt") == std::string::npos) { |
| 876 | return true; |
| 877 | } |
| 878 |
| 879 | TimeResults results; |
| 880 |
| 881 | static const char kPassword[] = "password"; |
| 882 | static const uint8_t kSalt[] = "NaCl"; |
| 883 |
| 884 | if (!TimeFunction(&results, [&]() -> bool { |
| 885 | uint8_t out[64]; |
| 886 | return !!EVP_PBE_scrypt(kPassword, sizeof(kPassword) - 1, kSalt, |
| 887 | sizeof(kSalt) - 1, 1024, 8, 16, 0 /* max_mem */, |
| 888 | out, sizeof(out)); |
| 889 | })) { |
| 890 | fprintf(stderr, "scrypt failed.\n"); |
| 891 | return false; |
| 892 | } |
| 893 | results.Print("scrypt (N = 1024, r = 8, p = 16)"); |
| 894 |
| 895 | if (!TimeFunction(&results, [&]() -> bool { |
| 896 | uint8_t out[64]; |
| 897 | return !!EVP_PBE_scrypt(kPassword, sizeof(kPassword) - 1, kSalt, |
| 898 | sizeof(kSalt) - 1, 16384, 8, 1, 0 /* max_mem */, |
| 899 | out, sizeof(out)); |
| 900 | })) { |
| 901 | fprintf(stderr, "scrypt failed.\n"); |
| 902 | return false; |
| 903 | } |
| 904 | results.Print("scrypt (N = 16384, r = 8, p = 1)"); |
| 905 |
| 906 | return true; |
| 907 | } |
| 908 |
| 909 | static bool SpeedHRSS(const std::string &selected) { |
| 910 | if (!selected.empty() && selected != "HRSS") { |
| 911 | return true; |
| 912 | } |
| 913 |
| 914 | TimeResults results; |
| 915 |
| 916 | if (!TimeFunction(&results, []() -> bool { |
| 917 | struct HRSS_public_key pub; |
| 918 | struct HRSS_private_key priv; |
| 919 | uint8_t entropy[HRSS_GENERATE_KEY_BYTES]; |
| 920 | RAND_bytes(entropy, sizeof(entropy)); |
| 921 | HRSS_generate_key(&pub, &priv, entropy); |
| 922 | return true; |
| 923 | })) { |
| 924 | fprintf(stderr, "Failed to time HRSS_generate_key.\n"); |
| 925 | return false; |
| 926 | } |
| 927 |
| 928 | results.Print("HRSS generate"); |
| 929 |
| 930 | struct HRSS_public_key pub; |
| 931 | struct HRSS_private_key priv; |
| 932 | uint8_t key_entropy[HRSS_GENERATE_KEY_BYTES]; |
| 933 | RAND_bytes(key_entropy, sizeof(key_entropy)); |
| 934 | HRSS_generate_key(&pub, &priv, key_entropy); |
| 935 |
| 936 | uint8_t ciphertext[HRSS_CIPHERTEXT_BYTES]; |
| 937 | if (!TimeFunction(&results, [&pub, &ciphertext]() -> bool { |
| 938 | uint8_t entropy[HRSS_ENCAP_BYTES]; |
| 939 | uint8_t shared_key[HRSS_KEY_BYTES]; |
| 940 | RAND_bytes(entropy, sizeof(entropy)); |
| 941 | HRSS_encap(ciphertext, shared_key, &pub, entropy); |
| 942 | return true; |
| 943 | })) { |
| 944 | fprintf(stderr, "Failed to time HRSS_encap.\n"); |
| 945 | return false; |
| 946 | } |
| 947 |
| 948 | results.Print("HRSS encap"); |
| 949 |
| 950 | if (!TimeFunction(&results, [&priv, &ciphertext]() -> bool { |
| 951 | uint8_t shared_key[HRSS_KEY_BYTES]; |
| 952 | HRSS_decap(shared_key, &priv, ciphertext, sizeof(ciphertext)); |
| 953 | return true; |
| 954 | })) { |
| 955 | fprintf(stderr, "Failed to time HRSS_encap.\n"); |
| 956 | return false; |
| 957 | } |
| 958 |
| 959 | results.Print("HRSS decap"); |
| 960 |
| 961 | return true; |
| 962 | } |
| 963 |
| 964 | static const struct argument kArguments[] = { |
| 965 | { |
| 966 | "-filter", |
| 967 | kOptionalArgument, |
| 968 | "A filter on the speed tests to run", |
| 969 | }, |
| 970 | { |
| 971 | "-timeout", |
| 972 | kOptionalArgument, |
| 973 | "The number of seconds to run each test for (default is 1)", |
| 974 | }, |
| 975 | { |
| 976 | "-chunks", |
| 977 | kOptionalArgument, |
| 978 | "A comma-separated list of input sizes to run tests at (default is " |
| 979 | "16,256,1350,8192,16384)", |
| 980 | }, |
| 981 | { |
| 982 | "", |
| 983 | kOptionalArgument, |
| 984 | "", |
| 985 | }, |
| 986 | }; |
| 987 |
| 988 | bool Speed(const std::vector<std::string> &args) { |
| 989 | std::map<std::string, std::string> args_map; |
| 990 | if (!ParseKeyValueArguments(&args_map, args, kArguments)) { |
| 991 | PrintUsage(kArguments); |
| 992 | return false; |
| 993 | } |
| 994 |
| 995 | std::string selected; |
| 996 | if (args_map.count("-filter") != 0) { |
| 997 | selected = args_map["-filter"]; |
| 998 | } |
| 999 |
| 1000 | if (args_map.count("-timeout") != 0) { |
| 1001 | g_timeout_seconds = atoi(args_map["-timeout"].c_str()); |
| 1002 | } |
| 1003 |
| 1004 | if (args_map.count("-chunks") != 0) { |
| 1005 | g_chunk_lengths.clear(); |
| 1006 | const char *start = args_map["-chunks"].data(); |
| 1007 | const char *end = start + args_map["-chunks"].size(); |
| 1008 | while (start != end) { |
| 1009 | errno = 0; |
| 1010 | char *ptr; |
| 1011 | unsigned long long val = strtoull(start, &ptr, 10); |
| 1012 | if (ptr == start /* no numeric characters found */ || |
| 1013 | errno == ERANGE /* overflow */ || |
| 1014 | static_cast<size_t>(val) != val) { |
| 1015 | fprintf(stderr, "Error parsing -chunks argument\n"); |
| 1016 | return false; |
| 1017 | } |
| 1018 | g_chunk_lengths.push_back(static_cast<size_t>(val)); |
| 1019 | start = ptr; |
| 1020 | if (start != end) { |
| 1021 | if (*start != ',') { |
| 1022 | fprintf(stderr, "Error parsing -chunks argument\n"); |
| 1023 | return false; |
| 1024 | } |
| 1025 | start++; |
| 1026 | } |
| 1027 | } |
| 1028 | } |
| 1029 |
| 1030 | // kTLSADLen is the number of bytes of additional data that TLS passes to |
| 1031 | // AEADs. |
| 1032 | static const size_t kTLSADLen = 13; |
| 1033 | // kLegacyADLen is the number of bytes that TLS passes to the "legacy" AEADs. |
| 1034 | // These are AEADs that weren't originally defined as AEADs, but which we use |
| 1035 | // via the AEAD interface. In order for that to work, they have some TLS |
| 1036 | // knowledge in them and construct a couple of the AD bytes internally. |
| 1037 | static const size_t kLegacyADLen = kTLSADLen - 2; |
| 1038 |
| 1039 | if (!SpeedRSA(selected) || |
| 1040 | !SpeedAEAD(EVP_aead_aes_128_gcm(), "AES-128-GCM", kTLSADLen, selected) || |
| 1041 | !SpeedAEAD(EVP_aead_aes_256_gcm(), "AES-256-GCM", kTLSADLen, selected) || |
| 1042 | !SpeedAEAD(EVP_aead_chacha20_poly1305(), "ChaCha20-Poly1305", kTLSADLen, |
| 1043 | selected) || |
| 1044 | !SpeedAEAD(EVP_aead_des_ede3_cbc_sha1_tls(), "DES-EDE3-CBC-SHA1", |
| 1045 | kLegacyADLen, selected) || |
| 1046 | !SpeedAEAD(EVP_aead_aes_128_cbc_sha1_tls(), "AES-128-CBC-SHA1", |
| 1047 | kLegacyADLen, selected) || |
| 1048 | !SpeedAEAD(EVP_aead_aes_256_cbc_sha1_tls(), "AES-256-CBC-SHA1", |
| 1049 | kLegacyADLen, selected) || |
| 1050 | !SpeedAEADOpen(EVP_aead_aes_128_cbc_sha1_tls(), "AES-128-CBC-SHA1", |
| 1051 | kLegacyADLen, selected) || |
| 1052 | !SpeedAEADOpen(EVP_aead_aes_256_cbc_sha1_tls(), "AES-256-CBC-SHA1", |
| 1053 | kLegacyADLen, selected) || |
| 1054 | !SpeedAEAD(EVP_aead_aes_128_gcm_siv(), "AES-128-GCM-SIV", kTLSADLen, |
| 1055 | selected) || |
| 1056 | !SpeedAEAD(EVP_aead_aes_256_gcm_siv(), "AES-256-GCM-SIV", kTLSADLen, |
| 1057 | selected) || |
| 1058 | !SpeedAEADOpen(EVP_aead_aes_128_gcm_siv(), "AES-128-GCM-SIV", kTLSADLen, |
| 1059 | selected) || |
| 1060 | !SpeedAEADOpen(EVP_aead_aes_256_gcm_siv(), "AES-256-GCM-SIV", kTLSADLen, |
| 1061 | selected) || |
| 1062 | !SpeedAEAD(EVP_aead_aes_128_ccm_bluetooth(), "AES-128-CCM-Bluetooth", |
| 1063 | kTLSADLen, selected) || |
| 1064 | !SpeedAESBlock("AES-128", 128, selected) || |
| 1065 | !SpeedAESBlock("AES-256", 256, selected) || |
| 1066 | !SpeedHash(EVP_sha1(), "SHA-1", selected) || |
| 1067 | !SpeedHash(EVP_sha256(), "SHA-256", selected) || |
| 1068 | !SpeedHash(EVP_sha512(), "SHA-512", selected) || |
| 1069 | !SpeedRandom(selected) || |
| 1070 | !SpeedECDH(selected) || |
| 1071 | !SpeedECDSA(selected) || |
| 1072 | !Speed25519(selected) || |
| 1073 | !SpeedSIKEP434(selected) || |
| 1074 | !SpeedSPAKE2(selected) || |
| 1075 | !SpeedScrypt(selected) || |
| 1076 | !SpeedRSAKeyGen(selected) || |
| 1077 | !SpeedHRSS(selected)) { |
| 1078 | return false; |
| 1079 | } |
| 1080 |
| 1081 | return true; |
| 1082 | } |
| 1083 |