| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
#include <assert.h> |
| 33 |
|
| 34 |
#include "common.h" |
| 35 |
#include "endianess.h" |
| 36 |
#include "multiply.h" |
| 37 |
#include "mont.h" |
| 38 |
#include "modexp_utils.h" |
| 39 |
|
| 40 |
#include <sys/time.h> |
| 41 |
|
| 42 |
#include "ed448.c" |
| 43 |
|
| 44 |
#define COORD_LEN 56 |
| 45 |
|
| 46 |
int main(void) |
| 47 |
{ |
| 48 |
uint8_t x[COORD_LEN], y[COORD_LEN]; |
| 49 |
uint8_t exp[56]; |
| 50 |
PointEd448 *gp = NULL; |
| 51 |
unsigned i; |
| 52 |
int res; |
| 53 |
EcContext *ec_ctx; |
| 54 |
struct timeval start, stop; |
| 55 |
double duration_ms, rate; |
| 56 |
const uint8_t Gx[COORD_LEN] = "\x4f\x19\x70\xc6\x6b\xed\x0d\xed\x22\x1d\x15\xa6\x22\xbf\x36\xda\x9e\x14\x65\x70\x47\x0f\x17\x67\xea\x6d\xe3\x24\xa3\xd3\xa4\x64\x12\xae\x1a\xf7\x2a\xb6\x65\x11\x43\x3b\x80\xe1\x8b\x00\x93\x8e\x26\x26\xa8\x2b\xc7\x0c\xc0\x5e"; |
| 57 |
const uint8_t Gy[COORD_LEN] = "\x69\x3f\x46\x71\x6e\xb6\xbc\x24\x88\x76\x20\x37\x56\xc9\xc7\x62\x4b\xea\x73\x73\x6c\xa3\x98\x40\x87\x78\x9c\x1e\x05\xa0\xc2\xd7\x3a\xd3\xff\x1c\xe6\x7c\x39\xc4\xfd\xbd\x13\x2c\x4e\xd7\xc8\xad\x98\x08\x79\x5b\xf2\x30\xfa\x14"; |
| 58 |
|
| 59 |
#define ITERATIONS 5000U |
| 60 |
|
| 61 |
|
| 62 |
for (i=0; i<sizeof(exp); i++) { |
| 63 |
exp[i] = (uint8_t)(0xFF - i); |
| 64 |
} |
| 65 |
|
| 66 |
res = ed448_new_context(&ec_ctx); |
| 67 |
assert(res == 0); |
| 68 |
res = ed448_new_point(&gp, Gx, Gy, COORD_LEN, ec_ctx); |
| 69 |
assert(res == 0); |
| 70 |
|
| 71 |
|
| 72 |
gettimeofday(&start, NULL); |
| 73 |
for (i=0; i<ITERATIONS; i++) { |
| 74 |
ed448_scalar(gp, exp, sizeof(exp), 0xFFF); |
| 75 |
} |
| 76 |
gettimeofday(&stop, NULL); |
| 77 |
duration_ms = (double)(stop.tv_sec - start.tv_sec) * 1000 + (double)(stop.tv_usec - start.tv_usec) / 1000; |
| 78 |
rate = ITERATIONS / (duration_ms/1000); |
| 79 |
printf("Speed (scalar mult by P) = %.0f op/s\n", rate); |
| 80 |
|
| 81 |
ed448_get_xy(x, y, sizeof(x), gp); |
| 82 |
printf("X: "); |
| 83 |
for (i=0; i<sizeof(x); i++) |
| 84 |
printf("%02X", x[i]); |
| 85 |
printf("\n"); |
| 86 |
printf("Y: "); |
| 87 |
for (i=0; i<sizeof(y); i++) |
| 88 |
printf("%02X", y[i]); |
| 89 |
printf("\n"); |
| 90 |
|
| 91 |
ed448_free_point(gp); |
| 92 |
ed448_free_context(ec_ctx); |
| 93 |
|
| 94 |
return 0; |
| 95 |
} |