void newhope_sharedb(unsigned char *sharedkey, unsigned char *send, const unsigned char *received) { poly sp, ep, v, a, pka, c, epp, bp; unsigned char seed[NEWHOPE_SEEDBYTES]; unsigned char noiseseed[32]; randombytes(noiseseed, 32); decode_a(&pka, seed, received); gen_a(&a, seed); poly_getnoise(&sp,noiseseed,0); poly_ntt(&sp); poly_getnoise(&ep,noiseseed,1); poly_ntt(&ep); poly_pointwise(&bp, &a, &sp); poly_add(&bp, &bp, &ep); poly_pointwise(&v, &pka, &sp); poly_bitrev(&v); poly_invntt(&v); poly_getnoise(&epp,noiseseed,2); poly_add(&v, &v, &epp); helprec(&c, &v, noiseseed, 3); encode_b(send, &bp, &c); rec(sharedkey, &v, &c); sha3256(sharedkey, sharedkey, 32); }
void newhope_keygen(unsigned char *send, poly *sk) { poly a, e, r, pk; unsigned char seed[NEWHOPE_SEEDBYTES]; unsigned char noiseseed[32]; randombytes(seed, NEWHOPE_SEEDBYTES); randombytes(noiseseed, 32); gen_a(&a, seed); //unsigned poly_getnoise(sk,noiseseed,0); poly_ntt(sk); //unsigned poly_getnoise(&e,noiseseed,1); poly_ntt(&e); //unsigned poly_pointwise(&r,sk,&a); //unsigned poly_add(&pk,&e,&r); //unsigned encode_a(send, &pk, seed); }
int main(void) { poly sk_a; unsigned char key_a[32], key_b[32]; unsigned char senda[NTESTS*NEWHOPE_SENDABYTES]; unsigned char sendb[NTESTS*NEWHOPE_SENDBBYTES]; unsigned char seed[NEWHOPE_SEEDBYTES]; int i; for(i=0; i<NTESTS; i++) { t[i] = cpucycles(); randombytes(seed, NEWHOPE_SEEDBYTES); poly_uniform(&sk_a, seed); } print_results("poly_uniform: ", t, NTESTS); for(i=0; i<NTESTS; i++) { t[i] = cpucycles(); poly_ntt(&sk_a); } print_results("poly_ntt: ", t, NTESTS); for(i=0; i<NTESTS; i++) { t[i] = cpucycles(); poly_invntt(&sk_a); } print_results("poly_invntt: ", t, NTESTS); for(i=0; i<NTESTS; i++) { t[i] = cpucycles(); poly_getnoise(&sk_a,seed,0); } print_results("poly_getnoise: ", t, NTESTS); for(i=0; i<NTESTS; i++) { t[i] = cpucycles(); helprec(&sk_a, &sk_a, seed, 0); } print_results("helprec: ", t, NTESTS); for(i=0; i<NTESTS; i++) { t[i] = cpucycles(); rec(key_a, &sk_a, &sk_a); } print_results("rec: ", t, NTESTS); for(i=0; i<NTESTS; i++) { t[i] = cpucycles(); newhope_keygen(senda+i*NEWHOPE_SENDABYTES, &sk_a); } print_results("newhope_keygen: ", t, NTESTS); for(i=0; i<NTESTS; i++) { t[i] = cpucycles(); newhope_sharedb(key_b, sendb+i*NEWHOPE_SENDBBYTES, senda+i*NEWHOPE_SENDABYTES); } print_results("newhope_sharedb: ", t, NTESTS); for(i=0; i<NTESTS; i++) { t[i] = cpucycles(); newhope_shareda(key_a, &sk_a, sendb+i*NEWHOPE_SENDBBYTES); } print_results("newhope_shareda: ", t, NTESTS); return 0; }