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_verify.c 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 <stdio.h>
  7. #include <string.h>
  8. #include "include/secp256k1.h"
  9. #include "util.h"
  10. #include "bench.h"
  11. typedef struct {
  12. unsigned char msg[32];
  13. unsigned char key[32];
  14. unsigned char nonce[32];
  15. unsigned char sig[72];
  16. int siglen;
  17. unsigned char pubkey[33];
  18. int pubkeylen;
  19. } benchmark_verify_t;
  20. static void benchmark_verify(void* arg) {
  21. benchmark_verify_t* data = (benchmark_verify_t*)arg;
  22. for (int i=0; i<20000; i++) {
  23. data->sig[data->siglen - 1] ^= (i & 0xFF);
  24. data->sig[data->siglen - 2] ^= ((i >> 8) & 0xFF);
  25. data->sig[data->siglen - 3] ^= ((i >> 16) & 0xFF);
  26. CHECK(secp256k1_ecdsa_verify(data->msg, 32, data->sig, data->siglen, data->pubkey, data->pubkeylen) == (i == 0));
  27. data->sig[data->siglen - 1] ^= (i & 0xFF);
  28. data->sig[data->siglen - 2] ^= ((i >> 8) & 0xFF);
  29. data->sig[data->siglen - 3] ^= ((i >> 16) & 0xFF);
  30. }
  31. }
  32. int main(void) {
  33. secp256k1_start(SECP256K1_START_VERIFY | SECP256K1_START_SIGN);
  34. benchmark_verify_t data;
  35. for (int i = 0; i < 32; i++) data.msg[i] = 1 + i;
  36. for (int i = 0; i < 32; i++) data.key[i] = 33 + i;
  37. for (int i = 0; i < 32; i++) data.nonce[i] = 65 + i;
  38. data.siglen = 72;
  39. CHECK(secp256k1_ecdsa_sign(data.msg, 32, data.sig, &data.siglen, data.key, data.nonce));
  40. data.pubkeylen = 33;
  41. CHECK(secp256k1_ec_pubkey_create(data.pubkey, &data.pubkeylen, data.key, 1));
  42. run_benchmark(benchmark_verify, NULL, NULL, &data, 10, 20000);
  43. secp256k1_stop();
  44. return 0;
  45. }