|
127 | 127 | #ifdef WOLFSSL_SIPHASH |
128 | 128 | #include <wolfssl/wolfcrypt/siphash.h> |
129 | 129 | #endif |
| 130 | + #include <wolfssl/wolfcrypt/kdf.h> |
130 | 131 | #ifndef NO_PWDBASED |
131 | 132 | #include <wolfssl/wolfcrypt/pwdbased.h> |
132 | 133 | #endif |
|
534 | 535 | #define BENCH_PBKDF2 0x00000100 |
535 | 536 | #define BENCH_SIPHASH 0x00000200 |
536 | 537 |
|
| 538 | +/* KDF algorithms */ |
| 539 | +#define BENCH_SRTP_KDF 0x00000001 |
| 540 | + |
537 | 541 | /* Asymmetric algorithms. */ |
538 | 542 | #define BENCH_RSA_KEYGEN 0x00000001 |
539 | 543 | #define BENCH_RSA 0x00000002 |
@@ -619,6 +623,8 @@ static word32 bench_cipher_algs = 0; |
619 | 623 | static word32 bench_digest_algs = 0; |
620 | 624 | /* MAC algorithms to benchmark. */ |
621 | 625 | static word32 bench_mac_algs = 0; |
| 626 | +/* KDF algorithms to benchmark. */ |
| 627 | +static word32 bench_kdf_algs = 0; |
622 | 628 | /* Asymmetric algorithms to benchmark. */ |
623 | 629 | static word32 bench_asym_algs = 0; |
624 | 630 | /* Post-Quantum Asymmetric algorithms to benchmark. */ |
@@ -797,9 +803,18 @@ static const bench_alg bench_mac_opt[] = { |
797 | 803 | #ifndef NO_PWDBASED |
798 | 804 | { "-pbkdf2", BENCH_PBKDF2 }, |
799 | 805 | #endif |
| 806 | +#endif |
800 | 807 | #ifdef WOLFSSL_SIPHASH |
801 | 808 | { "-siphash", BENCH_SIPHASH }, |
802 | 809 | #endif |
| 810 | + { NULL, 0 } |
| 811 | +}; |
| 812 | + |
| 813 | +/* All recognized KDF algorithm choosing command line options. */ |
| 814 | +static const bench_alg bench_kdf_opt[] = { |
| 815 | + { "-kdf", 0xffffffff }, |
| 816 | +#ifdef WC_SRTP_KDF |
| 817 | + { "-srtp-kdf", BENCH_SRTP_KDF }, |
803 | 818 | #endif |
804 | 819 | { NULL, 0 } |
805 | 820 | }; |
@@ -1646,6 +1661,7 @@ static void benchmark_static_init(int force) |
1646 | 1661 | bench_cipher_algs = 0; |
1647 | 1662 | bench_digest_algs = 0; |
1648 | 1663 | bench_mac_algs = 0; |
| 1664 | + bench_kdf_algs = 0; |
1649 | 1665 | bench_asym_algs = 0; |
1650 | 1666 | bench_pq_asym_algs = 0; |
1651 | 1667 | bench_other_algs = 0; |
@@ -2785,12 +2801,18 @@ static void* benchmarks_do(void* args) |
2785 | 2801 | bench_pbkdf2(); |
2786 | 2802 | } |
2787 | 2803 | #endif |
2788 | | - #ifdef WOLFSSL_SIPHASH |
2789 | | - if (bench_all || (bench_mac_algs & BENCH_SIPHASH)) { |
2790 | | - bench_siphash(); |
2791 | | - } |
2792 | | - #endif |
2793 | 2804 | #endif /* NO_HMAC */ |
| 2805 | +#ifdef WOLFSSL_SIPHASH |
| 2806 | + if (bench_all || (bench_mac_algs & BENCH_SIPHASH)) { |
| 2807 | + bench_siphash(); |
| 2808 | + } |
| 2809 | +#endif |
| 2810 | + |
| 2811 | +#ifdef WC_SRTP_KDF |
| 2812 | + if (bench_all || (bench_kdf_algs & BENCH_SRTP_KDF)) { |
| 2813 | + bench_srtpkdf(); |
| 2814 | + } |
| 2815 | +#endif |
2794 | 2816 |
|
2795 | 2817 | #ifdef HAVE_SCRYPT |
2796 | 2818 | if (bench_all || (bench_other_algs & BENCH_SCRYPT)) |
@@ -6721,6 +6743,68 @@ void bench_siphash(void) |
6721 | 6743 | } |
6722 | 6744 | #endif |
6723 | 6745 |
|
| 6746 | +#ifdef WC_SRTP_KDF |
| 6747 | +void bench_srtpkdf(void) |
| 6748 | +{ |
| 6749 | + double start; |
| 6750 | + int count; |
| 6751 | + int ret = 0; |
| 6752 | + byte keyE[32]; |
| 6753 | + byte keyA[20]; |
| 6754 | + byte keyS[14]; |
| 6755 | + const byte *key = bench_key_buf; |
| 6756 | + const byte salt[14] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, |
| 6757 | + 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e }; |
| 6758 | + const byte index[6] = { 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA }; |
| 6759 | + int kdrIdx = 0; |
| 6760 | + int i; |
| 6761 | + |
| 6762 | + bench_stats_start(&count, &start); |
| 6763 | + do { |
| 6764 | + for (i = 0; i < numBlocks; i++) { |
| 6765 | + ret = wc_SRTP_KDF(key, AES_128_KEY_SIZE, salt, sizeof(salt), |
| 6766 | + kdrIdx, index, keyE, AES_128_KEY_SIZE, keyA, sizeof(keyA), |
| 6767 | + keyS, sizeof(keyS)); |
| 6768 | + } |
| 6769 | + count += i; |
| 6770 | + } while (bench_stats_check(start)); |
| 6771 | + bench_stats_asym_finish("KDF", 128, "SRTP", 0, count, start, ret); |
| 6772 | + |
| 6773 | + bench_stats_start(&count, &start); |
| 6774 | + do { |
| 6775 | + for (i = 0; i < numBlocks; i++) { |
| 6776 | + ret = wc_SRTP_KDF(key, AES_256_KEY_SIZE, salt, sizeof(salt), |
| 6777 | + kdrIdx, index, keyE, AES_256_KEY_SIZE, keyA, sizeof(keyA), |
| 6778 | + keyS, sizeof(keyS)); |
| 6779 | + } |
| 6780 | + count += i; |
| 6781 | + } while (bench_stats_check(start)); |
| 6782 | + bench_stats_asym_finish("KDF", 256, "SRTP", 0, count, start, ret); |
| 6783 | + |
| 6784 | + bench_stats_start(&count, &start); |
| 6785 | + do { |
| 6786 | + for (i = 0; i < numBlocks; i++) { |
| 6787 | + ret = wc_SRTCP_KDF(key, AES_128_KEY_SIZE, salt, sizeof(salt), |
| 6788 | + kdrIdx, index, keyE, AES_128_KEY_SIZE, keyA, sizeof(keyA), |
| 6789 | + keyS, sizeof(keyS)); |
| 6790 | + } |
| 6791 | + count += i; |
| 6792 | + } while (bench_stats_check(start)); |
| 6793 | + bench_stats_asym_finish("KDF", 128, "SRTCP", 0, count, start, ret); |
| 6794 | + |
| 6795 | + bench_stats_start(&count, &start); |
| 6796 | + do { |
| 6797 | + for (i = 0; i < numBlocks; i++) { |
| 6798 | + ret = wc_SRTCP_KDF(key, AES_256_KEY_SIZE, salt, sizeof(salt), |
| 6799 | + kdrIdx, index, keyE, AES_256_KEY_SIZE, keyA, sizeof(keyA), |
| 6800 | + keyS, sizeof(keyS)); |
| 6801 | + } |
| 6802 | + count += i; |
| 6803 | + } while (bench_stats_check(start)); |
| 6804 | + bench_stats_asym_finish("KDF", 256, "SRTCP", 0, count, start, ret); |
| 6805 | +} |
| 6806 | +#endif |
| 6807 | + |
6724 | 6808 | #ifndef NO_RSA |
6725 | 6809 |
|
6726 | 6810 | #if defined(WOLFSSL_KEY_GEN) |
@@ -10661,6 +10745,8 @@ static void Usage(void) |
10661 | 10745 | print_alg(bench_digest_opt[i].str, &line); |
10662 | 10746 | for (i=0; bench_mac_opt[i].str != NULL; i++) |
10663 | 10747 | print_alg(bench_mac_opt[i].str, &line); |
| 10748 | + for (i=0; bench_kdf_opt[i].str != NULL; i++) |
| 10749 | + print_alg(bench_kdf_opt[i].str, &line); |
10664 | 10750 | for (i=0; bench_asym_opt[i].str != NULL; i++) |
10665 | 10751 | print_alg(bench_asym_opt[i].str, &line); |
10666 | 10752 | for (i=0; bench_other_opt[i].str != NULL; i++) |
@@ -10895,6 +10981,14 @@ int wolfcrypt_benchmark_main(int argc, char** argv) |
10895 | 10981 | optMatched = 1; |
10896 | 10982 | } |
10897 | 10983 | } |
| 10984 | + /* Known KDF algorithms */ |
| 10985 | + for (i=0; !optMatched && bench_kdf_opt[i].str != NULL; i++) { |
| 10986 | + if (string_matches(argv[1], bench_kdf_opt[i].str)) { |
| 10987 | + bench_kdf_algs |= bench_kdf_opt[i].val; |
| 10988 | + bench_all = 0; |
| 10989 | + optMatched = 1; |
| 10990 | + } |
| 10991 | + } |
10898 | 10992 | /* Known asymmetric algorithms */ |
10899 | 10993 | for (i=0; !optMatched && bench_asym_opt[i].str != NULL; i++) { |
10900 | 10994 | if (string_matches(argv[1], bench_asym_opt[i].str)) { |
|
0 commit comments