| 282 | } |
| 283 | |
| 284 | void benchmark_crypto_ops(size_t count, std::ostream &out) { |
| 285 | std::vector<Scalar> scalars(count); |
| 286 | std::vector<PublicKey> public_keys(count); |
| 287 | std::vector<KeyDerivation> derivations(count); |
| 288 | std::vector<Point> points(count); |
| 289 | std::vector<ge_dsmp> precomp(count); |
| 290 | std::vector<crypto::EllipticCurvePoint> bytes(count); |
| 291 | std::vector<std::pair<Scalar, Point>> merged_sp(count); |
| 292 | auto merged_double_points = |
| 293 | std::make_unique<std::tuple<Scalar, Scalar, Point, Point>[]>(count); // Also ok in C++14 |
| 294 | |
| 295 | // initialize random values for tests |
| 296 | for (size_t i = 0; i < count; ++i) { |
| 297 | KeyPair k = random_keypair(); |
| 298 | bytes[i] = k.public_key; |
| 299 | auto s = k.secret_key; |
| 300 | auto p = crypto::P3(k.public_key).p3; |
| 301 | scalars[i] = s; |
| 302 | points[i] = p; |
| 303 | public_keys[i] = to_bytes(p); |
| 304 | memcpy(derivations[i].data, public_keys[i].data, sizeof(EllipticCurvePoint)); |
| 305 | merged_sp[i] = std::make_pair(s, p); |
| 306 | |
| 307 | k = random_keypair(); |
| 308 | auto s2 = k.secret_key; |
| 309 | auto p2 = crypto::P3(k.public_key).p3; |
| 310 | merged_double_points.get()[i] = std::make_tuple(s, s2, p, p2); |
| 311 | |
| 312 | ge_dsm_precomp(&precomp[i], &p); |
| 313 | } |
| 314 | |
| 315 | std::map<std::string, BenchmarkResult> benchmark_results; |
| 316 | |
| 317 | // run the benchmarks |
| 318 | benchmark_results["frombytes"] = benchmark(count * 10, test_frombytes, bytes); |
| 319 | benchmark_results["fromfe_frombytes"] = benchmark(count * 10, test_fromfe_frombytes, bytes); |
| 320 | benchmark_results["check_subgroup"] = benchmark(count, test_check_subgroup, points); |
| 321 | benchmark_results["derive_output_secret_key"] = |
| 322 | benchmark(count * 10, test_derive_output_secret_key, mk_vec(derivations, scalars)); |
| 323 | benchmark_results["double_scalarmult_base"] = |
| 324 | benchmark(count, test_double_scalarmult_base, mk_vec(scalars, points)); |
| 325 | benchmark_results["double_scalarmult_badprecomp"] = |
| 326 | benchmark(count, test_double_scalarmult_badprecomp, mk_vec(scalars, points)); |
| 327 | benchmark_results["double_scalarmult_simple"] = |
| 328 | benchmark(count, test_double_scalarmult_simple, mk_vec(scalars, points)); |
| 329 | benchmark_results["double_scalarmult_simple_opt"] = |
| 330 | benchmark(count, test_double_scalarmult_simple_opt, mk_vec(scalars, points)); |
| 331 | benchmark_results["double_scalarmult_simple_aligned"] = |
| 332 | benchmark(count, test_double_scalarmult_simple_aligned, mk_vec(scalars, scalars, points, points)); |
| 333 | benchmark_results["generate_key_derivation"] = |
| 334 | benchmark(count, test_generate_key_derivation, mk_vec(scalars, public_keys)); |
| 335 | benchmark_results["generate_signature"] = benchmark(count, test_generate_signature, mk_vec(public_keys, scalars)); |
| 336 | benchmark_results["scalarmult_base"] = benchmark(count, test_scalarmult_base, scalars); |
| 337 | benchmark_results["scalarmult"] = benchmark(count, test_scalarmult, mk_vec(scalars, points)); |
| 338 | benchmark_results["scalarmult_via_phantom_point"] = |
| 339 | benchmark(count, test_scalarmult_via_phantom_point, mk_vec(scalars, points)); |
| 340 | benchmark_results["double_scalarmult"] = benchmark(count, test_double_scalarmult, mk_vec(scalars, points)); |
| 341 | benchmark_results["sc_mul"] = benchmark(count * 1000, test_sc_mul, mk_vec(scalars, scalars)); |
nothing calls this directly
no test coverage detected