exp.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* unused */
  2. #include <stdio.h>
  3. #include <openssl/tmdiff.h>
  4. #include "bn_lcl.h"
  5. #define SIZE 256
  6. #define NUM (8*8*8)
  7. #define MOD (8*8*8*8*8)
  8. main(argc, argv)
  9. int argc;
  10. char *argv[];
  11. {
  12. BN_CTX ctx;
  13. BIGNUM a, b, c, r, rr, t, l;
  14. int j, i, size = SIZE, num = NUM, mod = MOD;
  15. char *start, *end;
  16. BN_MONT_CTX mont;
  17. double d, md;
  18. BN_MONT_CTX_init(&mont);
  19. BN_CTX_init(&ctx);
  20. BN_init(&a);
  21. BN_init(&b);
  22. BN_init(&c);
  23. BN_init(&r);
  24. start = ms_time_new();
  25. end = ms_time_new();
  26. while (size <= 1024 * 8) {
  27. BN_rand(&a, size, 0, 0);
  28. BN_rand(&b, size, 1, 0);
  29. BN_rand(&c, size, 0, 1);
  30. BN_mod(&a, &a, &c, &ctx);
  31. ms_time_get(start);
  32. for (i = 0; i < 10; i++)
  33. BN_MONT_CTX_set(&mont, &c, &ctx);
  34. ms_time_get(end);
  35. md = ms_time_diff(start, end);
  36. ms_time_get(start);
  37. for (i = 0; i < num; i++) {
  38. /* bn_mull(&r,&a,&b,&ctx); */
  39. /* BN_sqr(&r,&a,&ctx); */
  40. BN_mod_exp_mont(&r, &a, &b, &c, &ctx, &mont);
  41. }
  42. ms_time_get(end);
  43. d = ms_time_diff(start, end) /* *50/33 */ ;
  44. printf("%5d bit:%6.2f %6d %6.4f %4d m_set(%5.4f)\n", size,
  45. d, num, d / num, (int)((d / num) * mod), md / 10.0);
  46. num /= 8;
  47. mod /= 8;
  48. if (num <= 0)
  49. num = 1;
  50. size *= 2;
  51. }
  52. }