diff options
author | Florian Dold <florian.dold@gmail.com> | 2018-08-18 15:10:39 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2018-08-18 15:10:39 +0200 |
commit | af99085b7163fdded4dfad94fd2a98231bc12209 (patch) | |
tree | c055728c186a49be04c4381bf10f890eaba482c6 /src/util/crypto_ecc.c | |
parent | ec8162bdf0db6282fbf507e6da72b056119c7805 (diff) | |
download | gnunet-af99085b7163fdded4dfad94fd2a98231bc12209.tar.gz gnunet-af99085b7163fdded4dfad94fd2a98231bc12209.zip |
benchmark collection awk scripts
Diffstat (limited to 'src/util/crypto_ecc.c')
-rw-r--r-- | src/util/crypto_ecc.c | 59 |
1 files changed, 55 insertions, 4 deletions
diff --git a/src/util/crypto_ecc.c b/src/util/crypto_ecc.c index ca2aa40ad..9902f276d 100644 --- a/src/util/crypto_ecc.c +++ b/src/util/crypto_ecc.c | |||
@@ -226,6 +226,8 @@ GNUNET_CRYPTO_ecdsa_key_get_public (const struct GNUNET_CRYPTO_EcdsaPrivateKey * | |||
226 | gcry_ctx_t ctx; | 226 | gcry_ctx_t ctx; |
227 | gcry_mpi_t q; | 227 | gcry_mpi_t q; |
228 | 228 | ||
229 | BENCHMARK_START (ecdsa_key_get_public); | ||
230 | |||
229 | sexp = decode_private_ecdsa_key (priv); | 231 | sexp = decode_private_ecdsa_key (priv); |
230 | GNUNET_assert (NULL != sexp); | 232 | GNUNET_assert (NULL != sexp); |
231 | GNUNET_assert (0 == gcry_mpi_ec_new (&ctx, sexp, NULL)); | 233 | GNUNET_assert (0 == gcry_mpi_ec_new (&ctx, sexp, NULL)); |
@@ -235,6 +237,8 @@ GNUNET_CRYPTO_ecdsa_key_get_public (const struct GNUNET_CRYPTO_EcdsaPrivateKey * | |||
235 | GNUNET_CRYPTO_mpi_print_unsigned (pub->q_y, sizeof (pub->q_y), q); | 237 | GNUNET_CRYPTO_mpi_print_unsigned (pub->q_y, sizeof (pub->q_y), q); |
236 | gcry_mpi_release (q); | 238 | gcry_mpi_release (q); |
237 | gcry_ctx_release (ctx); | 239 | gcry_ctx_release (ctx); |
240 | |||
241 | BENCHMARK_END (ecdsa_key_get_public); | ||
238 | } | 242 | } |
239 | 243 | ||
240 | 244 | ||
@@ -252,6 +256,8 @@ GNUNET_CRYPTO_eddsa_key_get_public (const struct GNUNET_CRYPTO_EddsaPrivateKey * | |||
252 | gcry_ctx_t ctx; | 256 | gcry_ctx_t ctx; |
253 | gcry_mpi_t q; | 257 | gcry_mpi_t q; |
254 | 258 | ||
259 | BENCHMARK_START (eddsa_key_get_public); | ||
260 | |||
255 | sexp = decode_private_eddsa_key (priv); | 261 | sexp = decode_private_eddsa_key (priv); |
256 | GNUNET_assert (NULL != sexp); | 262 | GNUNET_assert (NULL != sexp); |
257 | GNUNET_assert (0 == gcry_mpi_ec_new (&ctx, sexp, NULL)); | 263 | GNUNET_assert (0 == gcry_mpi_ec_new (&ctx, sexp, NULL)); |
@@ -261,6 +267,8 @@ GNUNET_CRYPTO_eddsa_key_get_public (const struct GNUNET_CRYPTO_EddsaPrivateKey * | |||
261 | GNUNET_CRYPTO_mpi_print_unsigned (pub->q_y, sizeof (pub->q_y), q); | 267 | GNUNET_CRYPTO_mpi_print_unsigned (pub->q_y, sizeof (pub->q_y), q); |
262 | gcry_mpi_release (q); | 268 | gcry_mpi_release (q); |
263 | gcry_ctx_release (ctx); | 269 | gcry_ctx_release (ctx); |
270 | |||
271 | BENCHMARK_END (eddsa_key_get_public); | ||
264 | } | 272 | } |
265 | 273 | ||
266 | 274 | ||
@@ -278,6 +286,8 @@ GNUNET_CRYPTO_ecdhe_key_get_public (const struct GNUNET_CRYPTO_EcdhePrivateKey * | |||
278 | gcry_ctx_t ctx; | 286 | gcry_ctx_t ctx; |
279 | gcry_mpi_t q; | 287 | gcry_mpi_t q; |
280 | 288 | ||
289 | BENCHMARK_START (ecdhe_key_get_public); | ||
290 | |||
281 | sexp = decode_private_ecdhe_key (priv); | 291 | sexp = decode_private_ecdhe_key (priv); |
282 | GNUNET_assert (NULL != sexp); | 292 | GNUNET_assert (NULL != sexp); |
283 | GNUNET_assert (0 == gcry_mpi_ec_new (&ctx, sexp, NULL)); | 293 | GNUNET_assert (0 == gcry_mpi_ec_new (&ctx, sexp, NULL)); |
@@ -287,6 +297,8 @@ GNUNET_CRYPTO_ecdhe_key_get_public (const struct GNUNET_CRYPTO_EcdhePrivateKey * | |||
287 | GNUNET_CRYPTO_mpi_print_unsigned (pub->q_y, sizeof (pub->q_y), q); | 297 | GNUNET_CRYPTO_mpi_print_unsigned (pub->q_y, sizeof (pub->q_y), q); |
288 | gcry_mpi_release (q); | 298 | gcry_mpi_release (q); |
289 | gcry_ctx_release (ctx); | 299 | gcry_ctx_release (ctx); |
300 | |||
301 | BENCHMARK_END (ecdhe_key_get_public); | ||
290 | } | 302 | } |
291 | 303 | ||
292 | 304 | ||
@@ -556,6 +568,8 @@ GNUNET_CRYPTO_ecdhe_key_create2 (struct GNUNET_CRYPTO_EcdhePrivateKey *pk) | |||
556 | gcry_mpi_t d; | 568 | gcry_mpi_t d; |
557 | int rc; | 569 | int rc; |
558 | 570 | ||
571 | BENCHMARK_START (ecdhe_key_create); | ||
572 | |||
559 | /* NOTE: For libgcrypt >= 1.7, we do not need the 'eddsa' flag here, | 573 | /* NOTE: For libgcrypt >= 1.7, we do not need the 'eddsa' flag here, |
560 | but should also be harmless. For libgcrypt < 1.7, using 'eddsa' | 574 | but should also be harmless. For libgcrypt < 1.7, using 'eddsa' |
561 | disables an expensive key testing routine. We do not want to run | 575 | disables an expensive key testing routine. We do not want to run |
@@ -592,6 +606,9 @@ GNUNET_CRYPTO_ecdhe_key_create2 (struct GNUNET_CRYPTO_EcdhePrivateKey *pk) | |||
592 | gcry_sexp_release (priv_sexp); | 606 | gcry_sexp_release (priv_sexp); |
593 | GNUNET_CRYPTO_mpi_print_unsigned (pk->d, sizeof (pk->d), d); | 607 | GNUNET_CRYPTO_mpi_print_unsigned (pk->d, sizeof (pk->d), d); |
594 | gcry_mpi_release (d); | 608 | gcry_mpi_release (d); |
609 | |||
610 | BENCHMARK_END (ecdhe_key_create); | ||
611 | |||
595 | return GNUNET_OK; | 612 | return GNUNET_OK; |
596 | } | 613 | } |
597 | 614 | ||
@@ -610,6 +627,8 @@ GNUNET_CRYPTO_ecdsa_key_create () | |||
610 | gcry_mpi_t d; | 627 | gcry_mpi_t d; |
611 | int rc; | 628 | int rc; |
612 | 629 | ||
630 | BENCHMARK_START (ecdsa_key_create); | ||
631 | |||
613 | if (0 != (rc = gcry_sexp_build (&s_keyparam, NULL, | 632 | if (0 != (rc = gcry_sexp_build (&s_keyparam, NULL, |
614 | "(genkey(ecc(curve \"" CURVE "\")" | 633 | "(genkey(ecc(curve \"" CURVE "\")" |
615 | "(flags)))"))) | 634 | "(flags)))"))) |
@@ -642,6 +661,9 @@ GNUNET_CRYPTO_ecdsa_key_create () | |||
642 | priv = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPrivateKey); | 661 | priv = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPrivateKey); |
643 | GNUNET_CRYPTO_mpi_print_unsigned (priv->d, sizeof (priv->d), d); | 662 | GNUNET_CRYPTO_mpi_print_unsigned (priv->d, sizeof (priv->d), d); |
644 | gcry_mpi_release (d); | 663 | gcry_mpi_release (d); |
664 | |||
665 | BENCHMARK_END (ecdsa_key_create); | ||
666 | |||
645 | return priv; | 667 | return priv; |
646 | } | 668 | } |
647 | 669 | ||
@@ -659,6 +681,8 @@ GNUNET_CRYPTO_eddsa_key_create () | |||
659 | gcry_mpi_t d; | 681 | gcry_mpi_t d; |
660 | int rc; | 682 | int rc; |
661 | 683 | ||
684 | BENCHMARK_START (eddsa_key_create); | ||
685 | |||
662 | #if CRYPTO_BUG | 686 | #if CRYPTO_BUG |
663 | again: | 687 | again: |
664 | #endif | 688 | #endif |
@@ -705,6 +729,8 @@ GNUNET_CRYPTO_eddsa_key_create () | |||
705 | } | 729 | } |
706 | #endif | 730 | #endif |
707 | 731 | ||
732 | BENCHMARK_END (eddsa_key_create); | ||
733 | |||
708 | return priv; | 734 | return priv; |
709 | } | 735 | } |
710 | 736 | ||
@@ -824,6 +850,8 @@ GNUNET_CRYPTO_ecdsa_sign (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, | |||
824 | int rc; | 850 | int rc; |
825 | gcry_mpi_t rs[2]; | 851 | gcry_mpi_t rs[2]; |
826 | 852 | ||
853 | BENCHMARK_START (ecdsa_sign); | ||
854 | |||
827 | priv_sexp = decode_private_ecdsa_key (priv); | 855 | priv_sexp = decode_private_ecdsa_key (priv); |
828 | data = data_to_ecdsa_value (purpose); | 856 | data = data_to_ecdsa_value (purpose); |
829 | if (0 != (rc = gcry_pk_sign (&sig_sexp, data, priv_sexp))) | 857 | if (0 != (rc = gcry_pk_sign (&sig_sexp, data, priv_sexp))) |
@@ -851,6 +879,9 @@ GNUNET_CRYPTO_ecdsa_sign (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, | |||
851 | GNUNET_CRYPTO_mpi_print_unsigned (sig->s, sizeof (sig->s), rs[1]); | 879 | GNUNET_CRYPTO_mpi_print_unsigned (sig->s, sizeof (sig->s), rs[1]); |
852 | gcry_mpi_release (rs[0]); | 880 | gcry_mpi_release (rs[0]); |
853 | gcry_mpi_release (rs[1]); | 881 | gcry_mpi_release (rs[1]); |
882 | |||
883 | BENCHMARK_END (ecdsa_sign); | ||
884 | |||
854 | return GNUNET_OK; | 885 | return GNUNET_OK; |
855 | } | 886 | } |
856 | 887 | ||
@@ -874,10 +905,7 @@ GNUNET_CRYPTO_eddsa_sign (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, | |||
874 | int rc; | 905 | int rc; |
875 | gcry_mpi_t rs[2]; | 906 | gcry_mpi_t rs[2]; |
876 | 907 | ||
877 | #if ENABLE_BENCHMARK | 908 | BENCHMARK_START (eddsa_sign); |
878 | struct BenchmarkData *bd = get_benchmark_data (); | ||
879 | bd->eddsa_sign_count++; | ||
880 | #endif | ||
881 | 909 | ||
882 | priv_sexp = decode_private_eddsa_key (priv); | 910 | priv_sexp = decode_private_eddsa_key (priv); |
883 | data = data_to_eddsa_value (purpose); | 911 | data = data_to_eddsa_value (purpose); |
@@ -906,6 +934,9 @@ GNUNET_CRYPTO_eddsa_sign (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, | |||
906 | GNUNET_CRYPTO_mpi_print_unsigned (sig->s, sizeof (sig->s), rs[1]); | 934 | GNUNET_CRYPTO_mpi_print_unsigned (sig->s, sizeof (sig->s), rs[1]); |
907 | gcry_mpi_release (rs[0]); | 935 | gcry_mpi_release (rs[0]); |
908 | gcry_mpi_release (rs[1]); | 936 | gcry_mpi_release (rs[1]); |
937 | |||
938 | BENCHMARK_END (eddsa_sign); | ||
939 | |||
909 | return GNUNET_OK; | 940 | return GNUNET_OK; |
910 | } | 941 | } |
911 | 942 | ||
@@ -930,6 +961,8 @@ GNUNET_CRYPTO_ecdsa_verify (uint32_t purpose, | |||
930 | gcry_sexp_t pub_sexpr; | 961 | gcry_sexp_t pub_sexpr; |
931 | int rc; | 962 | int rc; |
932 | 963 | ||
964 | BENCHMARK_START (ecdsa_verify); | ||
965 | |||
933 | if (purpose != ntohl (validate->purpose)) | 966 | if (purpose != ntohl (validate->purpose)) |
934 | return GNUNET_SYSERR; /* purpose mismatch */ | 967 | return GNUNET_SYSERR; /* purpose mismatch */ |
935 | 968 | ||
@@ -960,8 +993,10 @@ GNUNET_CRYPTO_ecdsa_verify (uint32_t purpose, | |||
960 | LOG (GNUNET_ERROR_TYPE_INFO, | 993 | LOG (GNUNET_ERROR_TYPE_INFO, |
961 | _("ECDSA signature verification failed at %s:%d: %s\n"), __FILE__, | 994 | _("ECDSA signature verification failed at %s:%d: %s\n"), __FILE__, |
962 | __LINE__, gcry_strerror (rc)); | 995 | __LINE__, gcry_strerror (rc)); |
996 | BENCHMARK_END (ecdsa_verify); | ||
963 | return GNUNET_SYSERR; | 997 | return GNUNET_SYSERR; |
964 | } | 998 | } |
999 | BENCHMARK_END (ecdsa_verify); | ||
965 | return GNUNET_OK; | 1000 | return GNUNET_OK; |
966 | } | 1001 | } |
967 | 1002 | ||
@@ -987,6 +1022,8 @@ GNUNET_CRYPTO_eddsa_verify (uint32_t purpose, | |||
987 | gcry_sexp_t pub_sexpr; | 1022 | gcry_sexp_t pub_sexpr; |
988 | int rc; | 1023 | int rc; |
989 | 1024 | ||
1025 | BENCHMARK_START (eddsa_verify); | ||
1026 | |||
990 | if (purpose != ntohl (validate->purpose)) | 1027 | if (purpose != ntohl (validate->purpose)) |
991 | return GNUNET_SYSERR; /* purpose mismatch */ | 1028 | return GNUNET_SYSERR; /* purpose mismatch */ |
992 | 1029 | ||
@@ -1017,8 +1054,10 @@ GNUNET_CRYPTO_eddsa_verify (uint32_t purpose, | |||
1017 | LOG (GNUNET_ERROR_TYPE_INFO, | 1054 | LOG (GNUNET_ERROR_TYPE_INFO, |
1018 | _("EdDSA signature verification failed at %s:%d: %s\n"), __FILE__, | 1055 | _("EdDSA signature verification failed at %s:%d: %s\n"), __FILE__, |
1019 | __LINE__, gcry_strerror (rc)); | 1056 | __LINE__, gcry_strerror (rc)); |
1057 | BENCHMARK_END (eddsa_verify); | ||
1020 | return GNUNET_SYSERR; | 1058 | return GNUNET_SYSERR; |
1021 | } | 1059 | } |
1060 | BENCHMARK_END (eddsa_verify); | ||
1022 | return GNUNET_OK; | 1061 | return GNUNET_OK; |
1023 | } | 1062 | } |
1024 | 1063 | ||
@@ -1045,6 +1084,8 @@ GNUNET_CRYPTO_ecc_ecdh (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, | |||
1045 | unsigned char xbuf[256 / 8]; | 1084 | unsigned char xbuf[256 / 8]; |
1046 | size_t rsize; | 1085 | size_t rsize; |
1047 | 1086 | ||
1087 | BENCHMARK_START (ecc_ecdh); | ||
1088 | |||
1048 | /* first, extract the q = dP value from the public key */ | 1089 | /* first, extract the q = dP value from the public key */ |
1049 | if (0 != gcry_sexp_build (&pub_sexpr, NULL, | 1090 | if (0 != gcry_sexp_build (&pub_sexpr, NULL, |
1050 | "(public-key(ecc(curve " CURVE ")(q %b)))", | 1091 | "(public-key(ecc(curve " CURVE ")(q %b)))", |
@@ -1088,6 +1129,7 @@ GNUNET_CRYPTO_ecc_ecdh (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, | |||
1088 | rsize, | 1129 | rsize, |
1089 | key_material); | 1130 | key_material); |
1090 | gcry_mpi_release (result_x); | 1131 | gcry_mpi_release (result_x); |
1132 | BENCHMARK_END (ecc_ecdh); | ||
1091 | return GNUNET_OK; | 1133 | return GNUNET_OK; |
1092 | } | 1134 | } |
1093 | 1135 | ||
@@ -1371,6 +1413,8 @@ GNUNET_CRYPTO_eddsa_ecdh (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, | |||
1371 | gcry_sexp_t pub_sexpr; | 1413 | gcry_sexp_t pub_sexpr; |
1372 | int ret; | 1414 | int ret; |
1373 | 1415 | ||
1416 | BENCHMARK_START (eddsa_ecdh); | ||
1417 | |||
1374 | /* first, extract the q = dP value from the public key */ | 1418 | /* first, extract the q = dP value from the public key */ |
1375 | if (0 != gcry_sexp_build (&pub_sexpr, NULL, | 1419 | if (0 != gcry_sexp_build (&pub_sexpr, NULL, |
1376 | "(public-key(ecc(curve " CURVE ")(q %b)))", | 1420 | "(public-key(ecc(curve " CURVE ")(q %b)))", |
@@ -1398,6 +1442,7 @@ GNUNET_CRYPTO_eddsa_ecdh (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, | |||
1398 | key_material); | 1442 | key_material); |
1399 | gcry_mpi_point_release (result); | 1443 | gcry_mpi_point_release (result); |
1400 | gcry_ctx_release (ctx); | 1444 | gcry_ctx_release (ctx); |
1445 | BENCHMARK_END (eddsa_ecdh); | ||
1401 | return ret; | 1446 | return ret; |
1402 | } | 1447 | } |
1403 | 1448 | ||
@@ -1424,6 +1469,8 @@ GNUNET_CRYPTO_ecdsa_ecdh (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, | |||
1424 | gcry_sexp_t pub_sexpr; | 1469 | gcry_sexp_t pub_sexpr; |
1425 | int ret; | 1470 | int ret; |
1426 | 1471 | ||
1472 | BENCHMARK_START (ecdsa_ecdh); | ||
1473 | |||
1427 | /* first, extract the q = dP value from the public key */ | 1474 | /* first, extract the q = dP value from the public key */ |
1428 | if (0 != gcry_sexp_build (&pub_sexpr, NULL, | 1475 | if (0 != gcry_sexp_build (&pub_sexpr, NULL, |
1429 | "(public-key(ecc(curve " CURVE ")(q %b)))", | 1476 | "(public-key(ecc(curve " CURVE ")(q %b)))", |
@@ -1448,6 +1495,7 @@ GNUNET_CRYPTO_ecdsa_ecdh (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, | |||
1448 | key_material); | 1495 | key_material); |
1449 | gcry_mpi_point_release (result); | 1496 | gcry_mpi_point_release (result); |
1450 | gcry_ctx_release (ctx); | 1497 | gcry_ctx_release (ctx); |
1498 | BENCHMARK_END (ecdsa_ecdh); | ||
1451 | return ret; | 1499 | return ret; |
1452 | } | 1500 | } |
1453 | 1501 | ||
@@ -1475,6 +1523,8 @@ GNUNET_CRYPTO_ecdh_eddsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, | |||
1475 | gcry_sexp_t pub_sexpr; | 1523 | gcry_sexp_t pub_sexpr; |
1476 | int ret; | 1524 | int ret; |
1477 | 1525 | ||
1526 | BENCHMARK_START (ecdh_eddsa); | ||
1527 | |||
1478 | /* first, extract the q = dP value from the public key */ | 1528 | /* first, extract the q = dP value from the public key */ |
1479 | if (0 != gcry_sexp_build (&pub_sexpr, NULL, | 1529 | if (0 != gcry_sexp_build (&pub_sexpr, NULL, |
1480 | "(public-key(ecc(curve " CURVE ")(q %b)))", | 1530 | "(public-key(ecc(curve " CURVE ")(q %b)))", |
@@ -1499,6 +1549,7 @@ GNUNET_CRYPTO_ecdh_eddsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, | |||
1499 | key_material); | 1549 | key_material); |
1500 | gcry_mpi_point_release (result); | 1550 | gcry_mpi_point_release (result); |
1501 | gcry_ctx_release (ctx); | 1551 | gcry_ctx_release (ctx); |
1552 | BENCHMARK_END (ecdh_eddsa); | ||
1502 | return ret; | 1553 | return ret; |
1503 | } | 1554 | } |
1504 | 1555 | ||