datatest.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include <string.h>
  2. #include <stdlib.h>
  3. #include "ssl.h"
  4. int main(int argc, char *argv[])
  5. {
  6. bigint *m1, *m2, *d;
  7. BI_CTX *ctx = bi_initialize();
  8. char cmp1[1024], cmp2[1024];
  9. const char *plaintext = /* 128 byte number */
  10. "01aaaaaaaaaabbbbbbbbbbbbbbbccccccccccccccdddddddddddddeeeeeeeeee"
  11. "01aaaaaaaaaabbbbbbbbbbbbbbbccccccccccccccdddddddddddddeeeeeeeeee";
  12. d = bi_import(ctx, (uint8_t *)plaintext, strlen(plaintext));
  13. memset(cmp1, 0, sizeof(cmp1));
  14. while (1)
  15. {
  16. bi_set_mod(ctx, bi_clone(ctx, d), 0);
  17. m1 = bi_square(ctx, bi_copy(d));
  18. m2 = bi_residue(ctx, m1);
  19. bi_free_mod(ctx, 0);
  20. //bi_export(ctx, bi_copy(d), cmp1, sizeof(cmp1));
  21. bi_export(ctx, m2, cmp2, sizeof(cmp2));
  22. if (memcmp(cmp1, cmp2, sizeof(cmp1)) != 0)
  23. {
  24. printf("Error!\n"); TTY_FLUSH();
  25. break;
  26. }
  27. d = bi_add(ctx, d, int_to_bi(ctx, 1));
  28. }
  29. bi_free(ctx, d);
  30. bi_terminate(ctx);
  31. printf("all good\n"); TTY_FLUSH();
  32. return 0;
  33. }