#include "common.h" #include "ec.h" #include "endianess.h" #define BITS 256 #define BYTES BITS/8 #define WORDS BITS/64 static void print_64bit_array(uint64_t *x, unsigned len) { unsigned i, j; for (i=0; i> ((7-j)*8))); } printf("ULL"); if (i!=(len-1)) printf(","); } } int main(void) { 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"; 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"; 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"; 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"; 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"; uint8_t xz[32] = { 0 }, yz[32] = { 0 }; EcContext *ec_ctx; EcPoint *g = NULL; EcPoint **window = NULL; int i, j; unsigned n_tables, points_per_table, window_size; ec_ws_new_context(&ec_ctx, p256_mod, b, order, 32, 0); ec_ws_new_point(&g, p256_Gx, p256_Gy, 32, ec_ctx); /** TODO: accept this as input **/ window_size = 5; points_per_table = 1U << window_size; n_tables = (256+window_size-1)/window_size; /** Create table with points 0, G, 2G, 3G, .. (2**window_size-1)G **/ window = (EcPoint**)calloc(points_per_table, sizeof(EcPoint*)); ec_ws_new_point(&window[0], xz, yz, 32, ec_ctx); for (i=1; ix, sizeof xw); memcpy(yw, window[j]->y, sizeof yw); } printf(" { /* Point #%d */\n", j); printf(" { "); print_64bit_array(xw, 4); printf(" },\n"); printf(" { "); print_64bit_array(yw, 4); printf(" }\n"); printf(" }%s\n", j==points_per_table-1 ? "" : ","); } printf(" }%s\n", i==n_tables-1 ? "" : ","); /* Move from G to G*2^{w} */ for (j=0; j