1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- /*
- *******************************************************************************
- \file ecp_bench.c
- \brief Benchmarks for elliptic curves over prime fields
- \project bee2/test
- \created 2013.10.17
- \version 2023.09.22
- \copyright The Bee2 authors
- \license Licensed under the Apache License, Version 2.0 (see LICENSE.txt).
- *******************************************************************************
- */
- #include <stdio.h>
- #include <bee2/core/mem.h>
- #include <bee2/core/prng.h>
- #include <bee2/core/stack.h>
- #include <bee2/core/tm.h>
- #include <bee2/core/util.h>
- #include <crypto/bign/bign_lcl.h>
- #include <bee2/math/ecp.h>
- #include <bee2/math/gfp.h>
- /*
- *******************************************************************************
- Потребности в стеке
- *******************************************************************************
- */
- static size_t _ecpBench_deep(size_t n, size_t f_deep, size_t ec_d,
- size_t ec_deep)
- {
- return O_OF_W(3 * n) + prngCOMBO_keep() +
- ecMulA_deep(n, ec_d, ec_deep, n);
- }
- bool_t ecpBench()
- {
- // описание кривой
- bign_params params[1];
- // состояние
- octet state[6000];
- ec_o* ec;
- octet* combo_state;
- word* pt;
- word* d;
- void* stack;
- // подготовить память
- if (sizeof(state) < bignStart_keep(128, _ecpBench_deep))
- return FALSE;
- // загрузить параметры и создать описание кривой
- if (bignParamsStd(params, "1.2.112.0.2.0.34.101.45.3.1") != ERR_OK ||
- bignStart(state, params) != ERR_OK)
- return FALSE;
- // раскладка состояния
- ec = (ec_o*)state;
- ec->tpl = 0;
- combo_state = objEnd(ec, octet);
- pt = (word*)(combo_state + prngCOMBO_keep());
- d = pt + 2 * ec->f->n;
- stack = d + ec->f->n;
- // создать генератор COMBO
- prngCOMBOStart(combo_state, utilNonce32());
- // оценить число кратных точек в секунду
- {
- const size_t reps = 1000;
- size_t i;
- tm_ticks_t ticks;
- // эксперимент
- for (i = 0, ticks = tmTicks(); i < reps; ++i)
- {
- prngCOMBOStepR(d, ec->f->no, combo_state);
- ecMulA(pt, ec->base, ec, d, ec->f->n, stack);
- }
- ticks = tmTicks() - ticks;
- // печать результатов
- printf("ecpBench: %u cycles/mulpoint [%u mulpoints/sec]\n",
- (unsigned)(ticks / reps),
- (unsigned)tmSpeed(reps, ticks));
- }
- // все нормально
- return TRUE;
- }
|