test_curvepoint_multiscalar.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * File: dclxvi-20130329/test_curvepoint_multiscalar.c
  3. * Author: Ruben Niederhagen, Peter Schwabe
  4. * Public Domain
  5. */
  6. #include <stdio.h>
  7. #include "curvepoint_fp.h"
  8. #include "curvepoint_fp_multiscalar.h"
  9. #include "parameters.h"
  10. extern const scalar_t bn_n;
  11. extern const curvepoint_fp_t bn_curvegen;
  12. #define MAXBATCH 500
  13. int main()
  14. {
  15. struct curvepoint_fp_struct p[MAXBATCH];
  16. curvepoint_fp_t r1, r2, t;
  17. scalar_t s[MAXBATCH];
  18. int i,batch;
  19. for(batch=1;batch<MAXBATCH;batch++)
  20. {
  21. printf("batch: %d\n",batch);
  22. for(i=0;i<batch;i++)
  23. {
  24. scalar_setrandom(s[i],bn_n);
  25. curvepoint_fp_set(&p[i],bn_curvegen);
  26. fpe_isreduced(p[i].m_x);
  27. fpe_isreduced(p[i].m_y);
  28. curvepoint_fp_scalarmult_vartime(&p[i],&p[i],s[i]);
  29. }
  30. curvepoint_fp_setneutral(r2);
  31. for(i=0;i<batch;i++)
  32. {
  33. scalar_setrandom(s[i],bn_n);
  34. curvepoint_fp_scalarmult_vartime(t,&p[i],s[i]);
  35. curvepoint_fp_add_vartime(r2,r2,t);
  36. }
  37. curvepoint_fp_multiscalarmult_vartime(r1,p,s,batch);
  38. curvepoint_fp_makeaffine(r1);
  39. curvepoint_fp_makeaffine(r2);
  40. if(!fpe_iseq(r1->m_x, r2->m_x) || !fpe_iseq(r1->m_y, r2->m_y))
  41. {
  42. printf("error\n");
  43. return -1;
  44. }
  45. }
  46. return 0;
  47. }