/* 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 "p448.h" #include "ec_point.h" #include "scalarmul.h" #include "barrett_field.h" #include "crandom.h" #include "goldilocks.h" #include "sha512.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 p448_randomize( struct crandom_state_t *crand, struct p448_t *a ) { crandom_generate(crand, (unsigned char *)a, sizeof(*a)); p448_strong_reduce(a); } static void q448_randomize( struct crandom_state_t *crand, word_t sk[448/WORD_BITS] ) { crandom_generate(crand, (unsigned char *)sk, 448/8); } static void p448_print( const char *descr, const struct p448_t *a ) { p448_t b; p448_copy(&b, a); p448_strong_reduce(&b); int j; printf("%s = 0x", descr); for (j=sizeof(*a)/sizeof(a->limb[0])-1; j>=0; j--) { printf(PRIxWORD58, b.limb[j]); } printf("\n"); } static void __attribute__((unused)) p448_print_full ( const char *descr, const struct p448_t *a ) { int j; printf("%s = 0x", descr); for (j=15; j>=0; j--) { printf("%02" PRIxWORD "_" PRIxWORD58 " ", a->limb[j]>>28, a->limb[j]&((1<<28)-1)); } printf("\n"); } static void q448_print( const char *descr, const word_t secret[448/WORD_BITS] ) { int j; printf("%s = 0x", descr); for (j=448/WORD_BITS-1; j>=0; j--) { printf(PRIxWORDfull, secret[j]); } 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 p448_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[448/WORD_BITS],tk[448/WORD_BITS]; q448_randomize(&crand, sk); 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); when = now(); for (i=0; i