kyber512r3_consts_avx2.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #include "kyber512r3_align_avx2.h"
  2. #include "kyber512r3_consts_avx2.h"
  3. #if defined(S2N_KYBER512R3_AVX2_BMI2)
  4. #define Q S2N_KYBER_512_R3_Q
  5. #define MONT -1044 // 2^16 mod q
  6. #define QINV -3327 // q^-1 mod 2^16
  7. #define V 20159 // floor(2^26/q + 0.5)
  8. #define FHI 1441 // mont^2/128
  9. #define FLO -10079 // qinv*FHI
  10. #define MONTSQHI 1353 // mont^2
  11. #define MONTSQLO 20553 // qinv*MONTSQHI
  12. #define MASK 4095
  13. #define SHIFT 32
  14. const qdata_t qdata = {{
  15. #define _16XQ 0
  16. Q, Q, Q, Q, Q, Q, Q, Q, Q, Q, Q, Q, Q, Q, Q, Q,
  17. #define _16XQINV 16
  18. QINV, QINV, QINV, QINV, QINV, QINV, QINV, QINV,
  19. QINV, QINV, QINV, QINV, QINV, QINV, QINV, QINV,
  20. #define _16XV 32
  21. V, V, V, V, V, V, V, V, V, V, V, V, V, V, V, V,
  22. #define _16XFLO 48
  23. FLO, FLO, FLO, FLO, FLO, FLO, FLO, FLO,
  24. FLO, FLO, FLO, FLO, FLO, FLO, FLO, FLO,
  25. #define _16XFHI 64
  26. FHI, FHI, FHI, FHI, FHI, FHI, FHI, FHI,
  27. FHI, FHI, FHI, FHI, FHI, FHI, FHI, FHI,
  28. #define _16XMONTSQLO 80
  29. MONTSQLO, MONTSQLO, MONTSQLO, MONTSQLO,
  30. MONTSQLO, MONTSQLO, MONTSQLO, MONTSQLO,
  31. MONTSQLO, MONTSQLO, MONTSQLO, MONTSQLO,
  32. MONTSQLO, MONTSQLO, MONTSQLO, MONTSQLO,
  33. #define _16XMONTSQHI 96
  34. MONTSQHI, MONTSQHI, MONTSQHI, MONTSQHI,
  35. MONTSQHI, MONTSQHI, MONTSQHI, MONTSQHI,
  36. MONTSQHI, MONTSQHI, MONTSQHI, MONTSQHI,
  37. MONTSQHI, MONTSQHI, MONTSQHI, MONTSQHI,
  38. #define _16XMASK 112
  39. MASK, MASK, MASK, MASK, MASK, MASK, MASK, MASK,
  40. MASK, MASK, MASK, MASK, MASK, MASK, MASK, MASK,
  41. #define _REVIDXB 128
  42. 3854, 3340, 2826, 2312, 1798, 1284, 770, 256,
  43. 3854, 3340, 2826, 2312, 1798, 1284, 770, 256,
  44. #define _REVIDXD 144
  45. 7, 0, 6, 0, 5, 0, 4, 0, 3, 0, 2, 0, 1, 0, 0, 0,
  46. #define _ZETAS_EXP 160
  47. 31498, 31498, 31498, 31498, -758, -758, -758, -758,
  48. 5237, 5237, 5237, 5237, 1397, 1397, 1397, 1397,
  49. 14745, 14745, 14745, 14745, 14745, 14745, 14745, 14745,
  50. 14745, 14745, 14745, 14745, 14745, 14745, 14745, 14745,
  51. -359, -359, -359, -359, -359, -359, -359, -359,
  52. -359, -359, -359, -359, -359, -359, -359, -359,
  53. 13525, 13525, 13525, 13525, 13525, 13525, 13525, 13525,
  54. -12402, -12402, -12402, -12402, -12402, -12402, -12402, -12402,
  55. 1493, 1493, 1493, 1493, 1493, 1493, 1493, 1493,
  56. 1422, 1422, 1422, 1422, 1422, 1422, 1422, 1422,
  57. -20907, -20907, -20907, -20907, 27758, 27758, 27758, 27758,
  58. -3799, -3799, -3799, -3799, -15690, -15690, -15690, -15690,
  59. -171, -171, -171, -171, 622, 622, 622, 622,
  60. 1577, 1577, 1577, 1577, 182, 182, 182, 182,
  61. -5827, -5827, 17363, 17363, -26360, -26360, -29057, -29057,
  62. 5571, 5571, -1102, -1102, 21438, 21438, -26242, -26242,
  63. 573, 573, -1325, -1325, 264, 264, 383, 383,
  64. -829, -829, 1458, 1458, -1602, -1602, -130, -130,
  65. -5689, -6516, 1496, 30967, -23565, 20179, 20710, 25080,
  66. -12796, 26616, 16064, -12442, 9134, -650, -25986, 27837,
  67. 1223, 652, -552, 1015, -1293, 1491, -282, -1544,
  68. 516, -8, -320, -666, -1618, -1162, 126, 1469,
  69. -335, -11477, -32227, 20494, -27738, 945, -14883, 6182,
  70. 32010, 10631, 29175, -28762, -18486, 17560, -14430, -5276,
  71. -1103, 555, -1251, 1550, 422, 177, -291, 1574,
  72. -246, 1159, -777, -602, -1590, -872, 418, -156,
  73. 11182, 13387, -14233, -21655, 13131, -4587, 23092, 5493,
  74. -32502, 30317, -18741, 12639, 20100, 18525, 19529, -12619,
  75. 430, 843, 871, 105, 587, -235, -460, 1653,
  76. 778, -147, 1483, 1119, 644, 349, 329, -75,
  77. 787, 787, 787, 787, 787, 787, 787, 787,
  78. 787, 787, 787, 787, 787, 787, 787, 787,
  79. -1517, -1517, -1517, -1517, -1517, -1517, -1517, -1517,
  80. -1517, -1517, -1517, -1517, -1517, -1517, -1517, -1517,
  81. 28191, 28191, 28191, 28191, 28191, 28191, 28191, 28191,
  82. -16694, -16694, -16694, -16694, -16694, -16694, -16694, -16694,
  83. 287, 287, 287, 287, 287, 287, 287, 287,
  84. 202, 202, 202, 202, 202, 202, 202, 202,
  85. 10690, 10690, 10690, 10690, 1358, 1358, 1358, 1358,
  86. -11202, -11202, -11202, -11202, 31164, 31164, 31164, 31164,
  87. 962, 962, 962, 962, -1202, -1202, -1202, -1202,
  88. -1474, -1474, -1474, -1474, 1468, 1468, 1468, 1468,
  89. -28073, -28073, 24313, 24313, -10532, -10532, 8800, 8800,
  90. 18426, 18426, 8859, 8859, 26675, 26675, -16163, -16163,
  91. -681, -681, 1017, 1017, 732, 732, 608, 608,
  92. -1542, -1542, 411, 411, -205, -205, -1571, -1571,
  93. 19883, -28250, -15887, -8898, -28309, 9075, -30199, 18249,
  94. 13426, 14017, -29156, -12757, 16832, 4311, -24155, -17915,
  95. -853, -90, -271, 830, 107, -1421, -247, -951,
  96. -398, 961, -1508, -725, 448, -1065, 677, -1275,
  97. -31183, 25435, -7382, 24391, -20927, 10946, 24214, 16989,
  98. 10335, -7934, -22502, 10906, 31636, 28644, 23998, -17422,
  99. 817, 603, 1322, -1465, -1215, 1218, -874, -1187,
  100. -1185, -1278, -1510, -870, -108, 996, 958, 1522,
  101. 20297, 2146, 15355, -32384, -6280, -14903, -11044, 14469,
  102. -21498, -20198, 23210, -17442, -23860, -20257, 7756, 23132,
  103. 1097, 610, -1285, 384, -136, -1335, 220, -1659,
  104. -1530, 794, -854, 478, -308, 991, -1460, 1628,
  105. #define _16XSHIFT 624
  106. SHIFT, SHIFT, SHIFT, SHIFT, SHIFT, SHIFT, SHIFT, SHIFT,
  107. SHIFT, SHIFT, SHIFT, SHIFT, SHIFT, SHIFT, SHIFT, SHIFT
  108. }};
  109. #endif