/* * File: dclxvi-20130329/speedtest.c * Author: Ruben Niederhagen, Peter Schwabe * Public Domain */ #include #include #include "curvepoint_fp.h" #include "twistpoint_fp2.h" #include "fp12e.h" #include "optate.h" #include "linefunction.h" #define NTESTS 20 #define REP 50 #ifdef __x86_64__ #define mycpucycles(RES) \ __asm__ volatile("rdtsc;shlq $32,%%rdx;orq %%rdx,%%rax" : "=a" (RES) :: "%rdx"); #else #define mycpucycles(RES) \ __asm__ volatile(".byte 15;.byte 49" : "=A" (RES)); #endif extern const curvepoint_fp_t bn_curvegen; extern const twistpoint_fp2_t bn_twistgen; extern const scalar_t bn_n; /* static int cmp_llu(const void *a, const void*b) { if(*(unsigned long long *)a < *(unsigned long long *)b) return -1; if(*(unsigned long long *)a > *(unsigned long long *)b) return 1; return 0; } static unsigned long long median(unsigned long long *l, size_t llen) { qsort(l,llen,sizeof(unsigned long long),cmp_llu); if(llen%2) return l[llen/2]; else return (l[llen/2-1]+l[llen/2])/2; } */ static void print_bench(unsigned long long *l, size_t llen) { size_t i; for(i=0;i= 2) choose = atoi(argv[1]); else choose = 0; scalar_setrandom(s1, bn_n); scalar_setrandom(s2, bn_n); scalar_setrandom(s3, bn_n); curvepoint_fp_scalarmult_vartime(p1, bn_curvegen, s1); curvepoint_fp_makeaffine(p1); twistpoint_fp2_scalarmult_vartime(p2, bn_twistgen, s2); twistpoint_fp2_makeaffine(p2); twistpoint_fp2_scalarmult_vartime(p3, bn_twistgen, s3); twistpoint_fp2_makeaffine(p3); fp2e_setone(rop11); fp2e_setone(rop12); fp2e_setone(rop13); fp2e_setone(r2); fpe_setone(fpe1); fp12e_setone(e1); if(!choose || choose == 1) { printf("Fp2 multiplication: "); for(i=0;i