You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bench_recover.c 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /**********************************************************************
  2. * Copyright (c) 2014 Pieter Wuille *
  3. * Distributed under the MIT software license, see the accompanying *
  4. * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
  5. **********************************************************************/
  6. #include "include/secp256k1.h"
  7. #include "util.h"
  8. #include "bench.h"
  9. typedef struct {
  10. unsigned char msg[32];
  11. unsigned char sig[64];
  12. } bench_recover_t;
  13. void bench_recover(void* arg) {
  14. bench_recover_t *data = (bench_recover_t*)arg;
  15. unsigned char pubkey[33];
  16. for (int i=0; i<20000; i++) {
  17. int pubkeylen = 33;
  18. CHECK(secp256k1_ecdsa_recover_compact(data->msg, 32, data->sig, pubkey, &pubkeylen, 1, i % 2));
  19. for (int j = 0; j < 32; j++) {
  20. data->sig[j + 32] = data->msg[j]; /* Move former message to S. */
  21. data->msg[j] = data->sig[j]; /* Move former R to message. */
  22. data->sig[j] = pubkey[j + 1]; /* Move recovered pubkey X coordinate to R (which must be a valid X coordinate). */
  23. }
  24. }
  25. }
  26. void bench_recover_setup(void* arg) {
  27. bench_recover_t *data = (bench_recover_t*)arg;
  28. for (int i = 0; i < 32; i++) data->msg[i] = 1 + i;
  29. for (int i = 0; i < 64; i++) data->sig[i] = 65 + i;
  30. }
  31. int main(void) {
  32. secp256k1_start(SECP256K1_START_VERIFY);
  33. bench_recover_t data;
  34. run_benchmark(bench_recover, bench_recover_setup, NULL, &data, 10, 20000);
  35. secp256k1_stop();
  36. return 0;
  37. }