#include double powers[12] = { 1.0 /* 2^0 */ , 4194304.0 /* 2^22 */ , 8796093022208.0 /* 2^43 */ , 18446744073709551616.0 /* 2^64 */ , 38685626227668133590597632.0 /* 2^85 */ , 162259276829213363391578010288128.0 /* 2^107 */ , 340282366920938463463374607431768211456.0 /* 2^128 */ , 713623846352979940529142984724747568191373312.0 /* 2^149 */ , 1496577676626844588240573268701473812127674924007424.0 /* 2^170 */ , 6277101735386680763835789423207666416102355444464034512896.0 /* 2^192 */ , 13164036458569648337239753460458804039861886925068638906788872192.0 /* 2^213 */ , 27606985387162255149739023449108101809804435888681546220650096895197184.0 /* 2^234 */ } ; double f[2][24]; double g[2][24]; extern void curve25519_select(double [24],double [24],const double [24],const double[24],long long); int main(int argc,char **argv) { int i; int j; int loop; long long b; for (loop = 0;loop < 100;++loop) { for (j = 0;j < 2;++j) { for (i = 0;i < 12;++i) f[j][i] = (random() & 1048575) * powers[i]; printf("f%d=0",j); for (i = 0;i < 12;++i) printf("%+.0f",f[j][i]); printf(";\n"); } b = random() & 1; printf("b=%lld;\n",b); curve25519_select(g[0],g[1],f[0],f[1],b); for (j = 0;j < 2;++j) { printf("g%d=0",j); for (i = 0;i < 12;++i) printf("%+.0f",g[j][i]); printf(";\n"); } printf("g0-(b*f1+(1-b)*f0)\n"); printf("g1-(b*f0+(1-b)*f1)\n"); } return 0; }