ecp_bench.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. *******************************************************************************
  3. \file ecp_bench.c
  4. \brief Benchmarks for elliptic curves over prime fields
  5. \project bee2/test
  6. \author (C) Sergey Agievich [agievich@{bsu.by|gmail.com}]
  7. \created 2013.10.17
  8. \version 2020.02.05
  9. \license This program is released under the GNU General Public License
  10. version 3. See Copyright Notices in bee2/info.h.
  11. *******************************************************************************
  12. */
  13. #include <stdio.h>
  14. #include <bee2/core/mem.h>
  15. #include <bee2/core/prng.h>
  16. #include <bee2/core/stack.h>
  17. #include <bee2/core/tm.h>
  18. #include <bee2/core/util.h>
  19. #include <crypto/bign_lcl.h>
  20. #include <bee2/math/ecp.h>
  21. #include <bee2/math/gfp.h>
  22. /*
  23. *******************************************************************************
  24. Потребности в стеке
  25. *******************************************************************************
  26. */
  27. static size_t _ecpBench_deep(size_t n, size_t f_deep, size_t ec_d,
  28. size_t ec_deep)
  29. {
  30. return O_OF_W(3 * n) + prngCOMBO_keep() +
  31. ecMulA_deep(n, ec_d, ec_deep, n);
  32. }
  33. bool_t ecpBench()
  34. {
  35. // описание кривой
  36. bign_params params[1];
  37. // состояние
  38. octet state[6000];
  39. ec_o* ec;
  40. octet* combo_state;
  41. word* pt;
  42. word* d;
  43. void* stack;
  44. // загрузить параметры и создать описание кривой
  45. ASSERT(bignStart_keep(128, _ecpBench_deep) <= sizeof(state));
  46. if (bignStdParams(params, "1.2.112.0.2.0.34.101.45.3.1") != ERR_OK ||
  47. bignStart(state, params) != ERR_OK)
  48. return FALSE;
  49. // раскладка состояния
  50. ec = (ec_o*)state;
  51. ec->tpl = 0;
  52. combo_state = objEnd(ec, octet);
  53. pt = (word*)(combo_state + prngCOMBO_keep());
  54. d = pt + 2 * ec->f->n;
  55. stack = d + ec->f->n;
  56. // создать генератор COMBO
  57. prngCOMBOStart(combo_state, utilNonce32());
  58. // оценить число кратных точек в секунду
  59. {
  60. const size_t reps = 1000;
  61. size_t i;
  62. tm_ticks_t ticks;
  63. // эксперимент
  64. for (i = 0, ticks = tmTicks(); i < reps; ++i)
  65. {
  66. prngCOMBOStepR(d, ec->f->no, combo_state);
  67. ecMulA(pt, ec->base, ec, d, ec->f->n, stack);
  68. }
  69. ticks = tmTicks() - ticks;
  70. // печать результатов
  71. printf("ecpBench: %u cycles/mulpoint [%u mulpoints/sec]\n",
  72. (unsigned)(ticks / reps),
  73. (unsigned)tmSpeed(reps, ticks));
  74. }
  75. // все нормально
  76. return TRUE;
  77. }