| 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 "ec.h" |
| 39 |
#include "modexp_utils.h" |
| 40 |
|
| 41 |
#include <sys/time.h> |
| 42 |
|
| 43 |
#include "ec_ws.c" |
| 44 |
|
| 45 |
int main(void) |
| 46 |
{ |
| 47 |
const uint8_t p256_mod[32] = "\xff\xff\xff\xff\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"; |
| 48 |
const uint8_t b[32] = "\x5a\xc6\x35\xd8\xaa\x3a\x93\xe7\xb3\xeb\xbd\x55\x76\x98\x86\xbc\x65\x1d\x06\xb0\xcc\x53\xb0\xf6\x3b\xce\x3c\x3e\x27\xd2\x60\x4b"; |
| 49 |
const uint8_t order[32] = "\xff\xff\xff\xff\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xbc\xe6\xfa\xad\xa7\x17\x9e\x84\xf3\xb9\xca\xc2\xfc\x63\x25\x51"; |
| 50 |
const uint8_t p256_Gx[32] = "\x6b\x17\xd1\xf2\xe1\x2c\x42\x47\xf8\xbc\xe6\xe5\x63\xa4\x40\xf2\x77\x03\x7d\x81\x2d\xeb\x33\xa0\xf4\xa1\x39\x45\xd8\x98\xc2\x96"; |
| 51 |
const uint8_t p256_Gy[32] = "\x4f\xe3\x42\xe2\xfe\x1a\x7f\x9b\x8e\xe7\xeb\x4a\x7c\x0f\x9e\x16\x2b\xce\x33\x57\x6b\x31\x5e\xce\xcb\xb6\x40\x68\x37\xbf\x51\xf5"; |
| 52 |
uint8_t x[32], y[32]; |
| 53 |
uint8_t exp[32]; |
| 54 |
EcContext *ec_ctx; |
| 55 |
EcPoint *ecp = NULL; |
| 56 |
EcPoint *gp = NULL; |
| 57 |
unsigned i; |
| 58 |
struct timeval start, stop; |
| 59 |
double duration_ms, rate; |
| 60 |
|
| 61 |
#define ITERATIONS 1000U |
| 62 |
|
| 63 |
|
| 64 |
for (i=0; i<32; i++) { |
| 65 |
exp[i] = (uint8_t)(0xFF - i); |
| 66 |
} |
| 67 |
|
| 68 |
ec_ws_new_context(&ec_ctx, p256_mod, b, order, 32, 4); |
| 69 |
|
| 70 |
ec_ws_new_point(&gp, p256_Gx, p256_Gy, 32, ec_ctx); |
| 71 |
ec_ws_clone(&ecp, gp); |
| 72 |
|
| 73 |
|
| 74 |
gettimeofday(&start, NULL); |
| 75 |
for (i=0; i<ITERATIONS; i++) { |
| 76 |
ec_ws_copy(ecp, gp); |
| 77 |
ec_ws_scalar(ecp, exp, 32, 0xFFF); |
| 78 |
ec_ws_get_xy(x, y, 32, ecp); |
| 79 |
} |
| 80 |
gettimeofday(&stop, NULL); |
| 81 |
duration_ms = (double)(stop.tv_sec - start.tv_sec) * 1000 + (double)(stop.tv_usec - start.tv_usec) / 1000; |
| 82 |
rate = ITERATIONS / (duration_ms/1000); |
| 83 |
printf("Speed (scalar mult by G) = %.0f op/s\n", rate); |
| 84 |
|
| 85 |
ec_ws_get_xy(x, y, 32, ecp); |
| 86 |
printf("X: "); |
| 87 |
for (i=0; i<32; i++) |
| 88 |
printf("%02X", x[i]); |
| 89 |
printf("\n"); |
| 90 |
printf("Y: "); |
| 91 |
for (i=0; i<32; i++) |
| 92 |
printf("%02X", y[i]); |
| 93 |
printf("\n"); |
| 94 |
|
| 95 |
#if 1 |
| 96 |
|
| 97 |
ec_ws_double(ecp); |
| 98 |
gettimeofday(&start, NULL); |
| 99 |
for (i=0; i<ITERATIONS; i++) { |
| 100 |
ec_ws_scalar(ecp, exp, 32, 0xFFF); |
| 101 |
ec_ws_get_xy(x, y, 32, ecp); |
| 102 |
} |
| 103 |
gettimeofday(&stop, NULL); |
| 104 |
duration_ms = (double)(stop.tv_sec - start.tv_sec) * 1000 + (double)(stop.tv_usec - start.tv_usec) / 1000; |
| 105 |
rate = ITERATIONS / (duration_ms/1000); |
| 106 |
printf("Speed (scalar mult by P) = %.0f op/s\n", rate); |
| 107 |
|
| 108 |
ec_ws_get_xy(x, y, 32, ecp); |
| 109 |
printf("X: "); |
| 110 |
for (i=0; i<32; i++) |
| 111 |
printf("%02X", x[i]); |
| 112 |
printf("\n"); |
| 113 |
printf("Y: "); |
| 114 |
for (i=0; i<32; i++) |
| 115 |
printf("%02X", y[i]); |
| 116 |
printf("\n"); |
| 117 |
#endif |
| 118 |
|
| 119 |
ec_ws_free_point(gp); |
| 120 |
ec_ws_free_point(ecp); |
| 121 |
ec_free_context(ec_ctx); |
| 122 |
|
| 123 |
return 0; |
| 124 |
} |