/* Copyright (c) 2014 Cryptography Research, Inc. * Released under the MIT License. See LICENSE.txt for license information. */ #include "word.h" #include #include #include #include #include "field.h" #include "ec_point.h" #include "scalarmul.h" #include "barrett_field.h" #include "crandom.h" #include "goldilocks.h" #include "sha512.h" #include "decaf.h" #include "decaf_crypto.h" #include "shake.h" static __inline__ void ignore_result ( int result ) { (void)result; } static double now(void) { struct timeval tv; gettimeofday(&tv, NULL); return tv.tv_sec + tv.tv_usec/1000000.0; } static void field_randomize( struct crandom_state_t *crand, field_a_t a ) { crandom_generate(crand, (unsigned char *)a, sizeof(*a)); field_strong_reduce(a); } static void q448_randomize( struct crandom_state_t *crand, word_t sk[SCALAR_WORDS] ) { crandom_generate(crand, (unsigned char *)sk, SCALAR_BYTES); } static void field_print( const char *descr, const field_a_t a ) { int j; unsigned char ser[FIELD_BYTES]; field_serialize(ser,a); printf("%s = 0x", descr); for (j=FIELD_BYTES - 1; j>=0; j--) { printf("%02x", ser[j]); } printf("\n"); } static void __attribute__((unused)) field_print_full ( const char *descr, const field_a_t a ) { int j; printf("%s = 0x", descr); for (j=15; j>=0; j--) { printf("%02" PRIxWORD "_" PRIxWORD56 " ", a->limb[j]>>28, a->limb[j]&((1<<28)-1)); } printf("\n"); } #ifndef N_TESTS_BASE #define N_TESTS_BASE 10000 #endif int main(int argc, char **argv) { (void)argc; (void)argv; struct tw_extensible_t ext; struct extensible_t exta; struct tw_niels_t niels; struct tw_pniels_t pniels; struct affine_t affine; struct montgomery_t mb; struct montgomery_aux_t mba; field_a_t a,b,c,d; double when; int i; int nbase = N_TESTS_BASE; /* Bad randomness so we can debug. */ char initial_seed[32]; for (i=0; i<32; i++) initial_seed[i] = i; struct crandom_state_t crand; crandom_init_from_buffer(&crand, initial_seed); /* For testing the performance drop from the crandom debuffering change. ignore_result(crandom_init_from_file(&crand, "/dev/urandom", 10000, 1)); */ word_t sk[SCALAR_WORDS],tk[SCALAR_WORDS]; q448_randomize(&crand, sk); memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); memset(c,0,sizeof(c)); memset(d,0,sizeof(d)); when = now(); for (i=0; ia isog: %5.1fns\n", when * 1e9 / i); when = now(); for (i=0; ii isog: %5.1fns\n", when * 1e9 / i); memset(&mb,0,sizeof(mb)); when = now(); for (i=0; i