You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

64 lines
2.1 KiB

  1. #ifndef GF2X_ARITH_H
  2. #define GF2X_ARITH_H
  3. #include <inttypes.h>
  4. #include <stddef.h>
  5. /*
  6. * Elements of GF(2)[x] are stored in compact dense binary form.
  7. *
  8. * Each bit in a byte is assumed to be the coefficient of a binary
  9. * polynomial f(x), in Big-Endian format (i.e., reading everything from
  10. * left to right, the most significant element is met first):
  11. *
  12. * byte:(0000 0000) == 0x00 ... f(x) == 0
  13. * byte:(0000 0001) == 0x01 ... f(x) == 1
  14. * byte:(0000 0010) == 0x02 ... f(x) == x
  15. * byte:(0000 0011) == 0x03 ... f(x) == x+1
  16. * ... ... ...
  17. * byte:(0000 1111) == 0x0F ... f(x) == x^{3}+x^{2}+x+1
  18. * ... ... ...
  19. * byte:(1111 1111) == 0xFF ... f(x) == x^{7}+x^{6}+x^{5}+x^{4}+x^{3}+x^{2}+x+1
  20. *
  21. *
  22. * A "machine word" (A_i) is considered as a DIGIT.
  23. * Bytes in a DIGIT are assumed in Big-Endian format:
  24. * E.g., if sizeof(DIGIT) == 4:
  25. * A_i: A_{i,3} A_{i,2} A_{i,1} A_{i,0}.
  26. * A_{i,3} denotes the most significant byte, A_{i,0} the least significant one.
  27. * f(x) == x^{31} + ... + x^{24} +
  28. * + x^{23} + ... + x^{16} +
  29. * + x^{15} + ... + x^{8} +
  30. * + x^{7} + ... + x^{0}
  31. *
  32. *
  33. * Multi-precision elements (i.e., with multiple DIGITs) are stored in
  34. * Big-endian format:
  35. * A = A_{n-1} A_{n-2} ... A_1 A_0
  36. *
  37. * position[A_{n-1}] == 0
  38. * position[A_{n-2}] == 1
  39. * ...
  40. * position[A_{1}] == n-2
  41. * position[A_{0}] == n-1
  42. */
  43. typedef uint64_t DIGIT;
  44. #define DIGIT_SIZE_B (8)
  45. #define DIGIT_SIZE_b (DIGIT_SIZE_B << 3)
  46. #define POSITION_T uint32_t
  47. #define MIN_KAR_DIGITS 10
  48. #define MIN_TOOM_DIGITS 42
  49. #define STACK_KAR_ONLY 2433
  50. #define STACK_WORDS 2892
  51. void PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_add(DIGIT Res[], const DIGIT A[], const DIGIT B[], size_t n);
  52. void PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_cmov(DIGIT *r, const DIGIT *a, size_t len, int c);
  53. void PQCLEAN_LEDAKEMLT12_LEAKTIME_right_bit_shift_n(size_t length, DIGIT in[], size_t amount);
  54. void PQCLEAN_LEDAKEMLT12_LEAKTIME_left_bit_shift_n(size_t length, DIGIT in[], size_t amount);
  55. void PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_mul(DIGIT *R, const DIGIT *A, const DIGIT *B, size_t n);
  56. #endif