void test_ckdh_hec_fp_2e127m1_g2i(char *s) { unsigned char pk1[PUBLICKEY_BYTES], pk2[PUBLICKEY_BYTES]; unsigned char sk1[SECRETKEY_BYTES], sk2[SECRETKEY_BYTES]; unsigned char ss1[SHAREDSECRET_BYTES], ss2[SHAREDSECRET_BYTES]; long count, i; printf("\n//%s\n", s); fflush(stdout); for(count = 0; count < 1000000000UL; count++){ crypto_dh_keypair(pk1, sk1); crypto_dh_keypair(pk2, sk2); crypto_dh(ss1, pk1, sk2); crypto_dh(ss2, pk2, sk1); for(i = 0; i < SHAREDSECRET_BYTES; i++){ if(ss1[i] != ss2[i]){ printf("Error! Secret does not match. (@ %lu)\n", count); exit(1); } } if((count%10000) == 0){ printf("%lu\n", count); fflush(stdout); } } copyrightclaims(); timingattacks(); patentclaims(); }
void test_try_ec_fp_smulbase_256q() { unsigned char pk1[PUBLICKEY_BYTES], sk1[SECRETKEY_BYTES]; unsigned char pk2[PUBLICKEY_BYTES], sk2[SECRETKEY_BYTES]; unsigned char ss1[PUBLICKEY_BYTES], ss2[SECRETKEY_BYTES]; long count, i; printf("\nJacobi Quartic (a=-1/2) Q^e with Q (fixedbase)\n"); for(count = 0; count < 1000000000UL; count++){ crypto_dh_keypair(pk1, sk1); crypto_dh_keypair(pk2, sk2); crypto_dh(ss1, pk1, sk2); crypto_dh(ss2, pk2, sk1); for(i = 0; i < 32; i++){ if(ss1[i] != ss2[i]){ printf("Error! Secret does not match. (@ %lu)\n", count); exit(1); } } if((count%10000) == 0){ printf("%lu\n", count); } } copyrightclaims(); timingattacks(); patentclaims(); }
int main() { int i,j; unsigned char ska[32],pka[64],ssa[32]; unsigned char skb[32],pkb[64],ssb[32]; unsigned long long skl,pkl; for (j=0;j<10;j++) { crypto_dh_keypair(pka,ska); printf("Alice private= "); for (i=0;i<32;i++) printf("%02x",ska[i]); printf("\n"); printf("Alice's public= "); for (i=0;i<32;i++) printf("%02x",pka[i]); printf("\n"); if (crypto_dh_keypair(pkb,skb)<0) { printf("problem\n"); break; } printf("Bob private= "); for (i=0;i<32;i++) printf("%02x",skb[i]); printf("\n"); printf("Bob's public= "); for (i=0;i<32;i++) printf("%02x",pkb[i]); printf("\n"); if (crypto_dh(ssa,pka,skb)<0) { printf("problem\n"); break; } printf("Alice's secret= "); for (i=0;i<32;i++) printf("%02x",ssa[i]); printf("\n"); crypto_dh(ssb,pkb,ska); printf("Bob's secret= "); for (i=0;i<32;i++) printf("%02x",ssb[i]); printf("\n\n"); } return 0; }
void test_perf_hec_fp_2e127m1_g2i(char *s) { unsigned char pk[PUBLICKEY_BYTES], sk[SECRETKEY_BYTES], ss[SHAREDSECRET_BYTES]; struct timeval t_start, t_end, t_diff; long long st, fn, count; printf("\n//%s\n", s); fflush(stdout); gettimeofday(&t_start, NULL); st = cpucycles(); for(count = 0; count < TRIAL; count++){ crypto_dh_keypair(pk, sk); } fn = cpucycles(); gettimeofday(&t_end, NULL); timersub(&t_end, &t_start, &t_diff); printf("Key pair generation cycles: %lld\n", (fn - st)/TRIAL); printf("Key pair generation time: %.3f msec\n", get_msec(t_diff, TRIAL, 1)); fflush(stdout); gettimeofday(&t_start, NULL); st = cpucycles(); for(count = 0; count < TRIAL; count++){ crypto_dh(ss, pk, sk); } fn = cpucycles(); gettimeofday(&t_end, NULL); timersub(&t_end, &t_start, &t_diff); printf("Secret sharing cycles: %lld\n", (fn - st)/TRIAL); printf("Secret sharing time: %.3f msec\n", get_msec(t_diff, TRIAL, 1)); fflush(stdout); }
int main(void) { unsigned int i; unsigned long long t[NRUNS]; pk = calloc(crypto_dh_PUBLICKEYBYTES,1); if(!pk) fail("allocation of pk failed"); sk = calloc(crypto_dh_SECRETKEYBYTES,1); if(!sk) fail("allocation of sk failed"); s = calloc(crypto_dh_BYTES,1); if(!s) fail("allocation of s failed"); for(i=0;i<NRUNS;i++) { t[i] = cpucycles(); crypto_dh_keypair(pk,sk); } print_speed(XSTR(crypto_dh_keypair),-1,t,NRUNS); for(i=0;i<NRUNS;i++) { t[i] = cpucycles(); crypto_dh(s,pk,sk); } print_speed(XSTR(crypto_dh),-1,t,NRUNS); free(pk); free(sk); free(s); avr_end(); return 0; }