-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: benchmarks for primes and biguint operations (#34)
* perf: avoid open/close when generating random numbers * chore: fix some warnings in sha lib * perf: make random number always odd in random_prime * feat: primes benchmarks * feat: biguint operation benchmarks * feat: rsa key generation benchmarks * feat: show function args in benchmark * refactor: add custom name to benchmarks
- Loading branch information
1 parent
d9f1790
commit 75fdf7b
Showing
9 changed files
with
139 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include <digital-signature/rsa.h> | ||
#include <math/random.h> | ||
#include <utils/benchmark.h> | ||
|
||
#define DEFINE_KEY_GEN_BENCHMARKS(BIT_SIZE) \ | ||
void benchmark_rsa_key_generation##BIT_SIZE() { \ | ||
RSAKeyPair key_pair = rsa_key_pair_new(BIT_SIZE); \ | ||
rsa_gen_key_pair(&key_pair); \ | ||
} | ||
|
||
DEFINE_KEY_GEN_BENCHMARKS(256) | ||
DEFINE_KEY_GEN_BENCHMARKS(512) | ||
DEFINE_KEY_GEN_BENCHMARKS(1024) | ||
|
||
int main() { | ||
BEGIN_BENCHMARK(); | ||
benchmark("rsa_key_generation 256 bits", benchmark_rsa_key_generation256, 1); | ||
benchmark("rsa_key_generation 512 bits", benchmark_rsa_key_generation512, 1); | ||
benchmark("rsa_key_generation 1024 bits", benchmark_rsa_key_generation1024, 1); | ||
END_BENCHMARK(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include <math/primes.h> | ||
#include <math/random.h> | ||
#include <utils/benchmark.h> | ||
|
||
void benchmark_random_prime(int size) { | ||
BigUint a = biguint_new_heap(size); | ||
biguint_random_prime(&a); | ||
biguint_free(&a); | ||
} | ||
|
||
void benchmark_is_prime_solovay_strassen(int size, char *prime) { | ||
BigUint a = biguint_new_heap(size); | ||
biguint_from_dec_string(prime, &a); | ||
biguint_is_prime_solovay_strassen(a); | ||
biguint_free(&a); | ||
} | ||
|
||
void benchmark_jacobi(int size, char *prime) { | ||
BigUint p = biguint_new_heap(size); | ||
BigUint a = biguint_new_heap(size); | ||
biguint_from_dec_string(prime, &p); | ||
biguint_random(&a); | ||
jacobi(a, p); | ||
biguint_free(&a, &p); | ||
} | ||
|
||
int main() { | ||
BEGIN_BENCHMARK() | ||
benchmark("random_prime 256 bits", benchmark_random_prime, 1, 4); | ||
benchmark("random_prime 512 bits", benchmark_random_prime, 1, 8); | ||
benchmark("random_prime 1024 bits", benchmark_random_prime, 1, 16); | ||
benchmark("is_prime_solovay_strassen 512 bits prime", benchmark_is_prime_solovay_strassen, 1, 8, | ||
"34335733933145862804940350952130198968391666739716830607881089259566479256360992225995345130785490553890" | ||
"25695338868874287109369850868158680127720763571503"); | ||
benchmark("is_prime_solovay_strassen 1024 bits prime", benchmark_is_prime_solovay_strassen, 1, 16, | ||
"24655650060360753080142862709006690867636082763996432687872619014553026794142593984738962973795417850400" | ||
"85414073637172246986341398241070222037495540411160258675361723321157569314242853171336423647307914642357" | ||
"9483846036052104816190148409971239514167619589698929804939809242854000598245576619523371634111874143"); | ||
benchmark("jacobi 512 bits prime", benchmark_jacobi, 1, 8, | ||
"34335733933145862804940350952130198968391666739716830607881089259566479256360992225995345130785490553890" | ||
"25695338868874287109369850868158680127720763571503"); | ||
benchmark("jacobi 1024 bits prime", benchmark_jacobi, 1, 16, | ||
"24655650060360753080142862709006690867636082763996432687872619014553026794142593984738962973795417850400" | ||
"85414073637172246986341398241070222037495540411160258675361723321157569314242853171336423647307914642357" | ||
"9483846036052104816190148409971239514167619589698929804939809242854000598245576619523371634111874143"); | ||
|
||
END_BENCHMARK() | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters