pq_crypto 0.6.1 → 0.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (247) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +10 -0
  3. data/SECURITY.md +7 -0
  4. data/ext/pqcrypto/pqcrypto_version.h +1 -1
  5. data/ext/pqcrypto/vendor/.vendored +7 -7
  6. data/ext/pqcrypto/vendor/mldsa-native/README.md +23 -10
  7. data/ext/pqcrypto/vendor/mldsa-native/mldsa/README.md +23 -0
  8. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.c +114 -58
  9. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.h +498 -461
  10. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_asm.S +145 -85
  11. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_config.h +456 -422
  12. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/cbmc.h +47 -25
  13. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/common.h +26 -14
  14. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/ct.h +56 -81
  15. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/debug.h +17 -24
  16. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202.c +33 -40
  17. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202.h +67 -87
  18. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202x4.c +19 -14
  19. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202x4.h +13 -5
  20. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.c +84 -10
  21. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.h +10 -5
  22. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/auto.h +6 -0
  23. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/fips202_native_aarch64.h +22 -15
  24. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_aarch64_asm.S +376 -0
  25. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_aarch64_asm.S +204 -0
  26. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_aarch64_asm.S +259 -0
  27. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm.S +1077 -0
  28. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm.S +987 -0
  29. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccakf1600_round_constants.c +16 -10
  30. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_scalar.h +2 -1
  31. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_v84a.h +1 -1
  32. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x2_v84a.h +4 -2
  33. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_scalar.h +2 -2
  34. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +1 -1
  35. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/api.h +60 -0
  36. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/mve.h +48 -0
  37. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/fips202_native_armv81m.h +18 -1
  38. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +658 -582
  39. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.c +5 -100
  40. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccakf1600_round_constants.c +26 -25
  41. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/state_extract_bytes_x4_mve.S +334 -0
  42. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/state_xor_bytes_x4_mve.S +355 -0
  43. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/auto.h +8 -3
  44. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/{xkcp.h → keccak_f1600_x4_avx2.h} +11 -8
  45. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/fips202_native_x86_64.h +44 -0
  46. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccak_f1600_x4_avx2_asm.S +454 -0
  47. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccakf1600_constants.c +52 -0
  48. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/meta.h +37 -28
  49. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/aarch64_zetas.c +213 -196
  50. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/arith_native_aarch64.h +248 -64
  51. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/intt_aarch64_asm.S +753 -0
  52. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l4_aarch64_asm.S +129 -0
  53. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l5_aarch64_asm.S +145 -0
  54. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l7_aarch64_asm.S +177 -0
  55. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/ntt_aarch64_asm.S +653 -0
  56. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/pointwise_montgomery_aarch64_asm.S +84 -0
  57. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_caddq_aarch64_asm.S +53 -0
  58. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_chknorm_aarch64_asm.S +55 -0
  59. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_32_aarch64_asm.S +86 -0
  60. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_88_aarch64_asm.S +86 -0
  61. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_32_aarch64_asm.S +103 -0
  62. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_88_aarch64_asm.S +111 -0
  63. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_17_aarch64_asm.S +75 -0
  64. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_19_aarch64_asm.S +72 -0
  65. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_table.c +23 -11
  66. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_aarch64_asm.S +189 -0
  67. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta2_aarch64_asm.S +137 -0
  68. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta4_aarch64_asm.S +130 -0
  69. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta_table.c +520 -516
  70. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_table.c +34 -33
  71. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/api.h +202 -242
  72. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/meta.h +25 -17
  73. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/arith_native_x86_64.h +112 -28
  74. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.c +1 -1
  75. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.h +1 -1
  76. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/intt_avx2_asm.S +2311 -0
  77. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/ntt_avx2_asm.S +2383 -0
  78. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/nttunpack_avx2_asm.S +238 -0
  79. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l4_avx2_asm.S +139 -0
  80. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l5_avx2_asm.S +155 -0
  81. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l7_avx2_asm.S +187 -0
  82. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_avx2_asm.S +130 -0
  83. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_caddq_avx2_asm.S +190 -0
  84. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_32_avx2.c +6 -4
  85. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_88_avx2.c +6 -4
  86. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_32_avx2.c +9 -8
  87. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_88_avx2.c +10 -9
  88. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_17_avx2.c +8 -5
  89. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_19_avx2.c +8 -5
  90. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta2_avx2.c +6 -4
  91. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta4_avx2.c +6 -4
  92. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_table.c +130 -129
  93. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.c +109 -180
  94. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.h +169 -150
  95. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.c +56 -40
  96. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.h +149 -164
  97. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.c +52 -57
  98. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.h +132 -167
  99. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.c +57 -424
  100. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.h +167 -474
  101. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec_lazy.c +308 -0
  102. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec_lazy.h +653 -0
  103. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/reduce.h +22 -29
  104. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/rounding.h +37 -43
  105. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.c +511 -367
  106. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.h +456 -417
  107. data/ext/pqcrypto/vendor/mlkem-native/README.md +6 -3
  108. data/ext/pqcrypto/vendor/mlkem-native/RELEASE.md +22 -0
  109. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.c +77 -36
  110. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.h +135 -146
  111. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_asm.S +116 -72
  112. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_config.h +351 -415
  113. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/cbmc.h +43 -20
  114. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/common.h +16 -8
  115. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.c +57 -31
  116. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.h +260 -349
  117. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/debug.h +17 -24
  118. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202.c +35 -37
  119. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202.h +43 -57
  120. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202x4.c +14 -15
  121. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202x4.h +5 -4
  122. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/keccakf1600.c +42 -6
  123. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/fips202_native_aarch64.h +31 -20
  124. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/{keccak_f1600_x1_scalar_asm.S → keccak_f1600_x1_scalar_aarch64_asm.S} +10 -10
  125. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/{keccak_f1600_x1_v84a_asm.S → keccak_f1600_x1_v84a_aarch64_asm.S} +10 -10
  126. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/{keccak_f1600_x2_v84a_asm.S → keccak_f1600_x2_v84a_aarch64_asm.S} +10 -10
  127. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/{keccak_f1600_x4_v8a_scalar_hybrid_asm.S → keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm.S} +10 -10
  128. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/{keccak_f1600_x4_v8a_v84a_scalar_hybrid_asm.S → keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm.S} +10 -10
  129. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccakf1600_round_constants.c +10 -9
  130. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x1_scalar.h +2 -1
  131. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x1_v84a.h +1 -1
  132. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x2_v84a.h +4 -2
  133. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x4_v8a_scalar.h +2 -2
  134. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +1 -1
  135. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/fips202_native_armv81m.h +2 -1
  136. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +55 -9
  137. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccakf1600_round_constants.c +26 -25
  138. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/state_extract_bytes_x4_mve.S +58 -14
  139. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/state_xor_bytes_x4_mve.S +57 -16
  140. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/auto.h +2 -1
  141. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/keccak_f1600_x4_avx2.h +2 -2
  142. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/fips202_native_x86_64.h +10 -7
  143. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/{keccak_f1600_x4_avx2.S → keccak_f1600_x4_avx2_asm.S} +13 -11
  144. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccakf1600_constants.c +12 -11
  145. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/indcpa.c +167 -136
  146. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/indcpa.h +75 -68
  147. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.h +135 -157
  148. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/meta.h +15 -13
  149. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/aarch64_zetas.c +143 -135
  150. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/arith_native_aarch64.h +52 -46
  151. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{intt.S → intt_aarch64_asm.S} +10 -10
  152. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{ntt.S → ntt_aarch64_asm.S} +10 -10
  153. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{poly_mulcache_compute_asm.S → poly_mulcache_compute_aarch64_asm.S} +10 -10
  154. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{poly_reduce_asm.S → poly_reduce_aarch64_asm.S} +10 -10
  155. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{poly_tobytes_asm.S → poly_tobytes_aarch64_asm.S} +10 -10
  156. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{poly_tomont_asm.S → poly_tomont_aarch64_asm.S} +10 -12
  157. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{polyvec_basemul_acc_montgomery_cached_asm_k2.S → polyvec_basemul_acc_montgomery_cached_k2_aarch64_asm.S} +10 -10
  158. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{polyvec_basemul_acc_montgomery_cached_asm_k3.S → polyvec_basemul_acc_montgomery_cached_k3_aarch64_asm.S} +10 -10
  159. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{polyvec_basemul_acc_montgomery_cached_asm_k4.S → polyvec_basemul_acc_montgomery_cached_k4_aarch64_asm.S} +10 -10
  160. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{rej_uniform_asm.S → rej_uniform_aarch64_asm.S} +12 -12
  161. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/rej_uniform_table.c +514 -513
  162. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/api.h +254 -253
  163. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/meta.h +6 -1
  164. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/README.md +6 -0
  165. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/meta.h +77 -0
  166. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/arith_native_ppc64le.h +24 -0
  167. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/consts.c +299 -0
  168. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/consts.h +34 -0
  169. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/intt_ppc_asm.S +3222 -0
  170. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/ntt_ppc_asm.S +1651 -0
  171. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/poly_tomont_ppc_asm.S +294 -0
  172. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/reduce_ppc_asm.S +710 -0
  173. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/meta.h +5 -0
  174. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_debug.c +18 -16
  175. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_debug.h +19 -24
  176. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_poly.c +53 -65
  177. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/meta.h +20 -20
  178. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/arith_native_x86_64.h +106 -88
  179. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/compress_consts.c +45 -35
  180. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/compress_consts.h +8 -8
  181. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/consts.c +1 -1
  182. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/consts.h +1 -1
  183. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{intt.S → intt_avx2_asm.S} +8 -8
  184. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{ntt.S → ntt_avx2_asm.S} +8 -8
  185. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{nttfrombytes.S → nttfrombytes_avx2_asm.S} +8 -8
  186. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{ntttobytes.S → ntttobytes_avx2_asm.S} +8 -8
  187. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{nttunpack.S → nttunpack_avx2_asm.S} +8 -8
  188. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_compress_d10.S → poly_compress_d10_avx2_asm.S} +9 -9
  189. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_compress_d11.S → poly_compress_d11_avx2_asm.S} +9 -9
  190. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_compress_d4.S → poly_compress_d4_avx2_asm.S} +9 -9
  191. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_compress_d5.S → poly_compress_d5_avx2_asm.S} +9 -9
  192. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_decompress_d10.S → poly_decompress_d10_avx2_asm.S} +9 -9
  193. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_decompress_d11.S → poly_decompress_d11_avx2_asm.S} +9 -9
  194. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_decompress_d4.S → poly_decompress_d4_avx2_asm.S} +9 -9
  195. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_decompress_d5.S → poly_decompress_d5_avx2_asm.S} +9 -9
  196. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{mulcache_compute.S → poly_mulcache_compute_avx2_asm.S} +8 -8
  197. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{polyvec_basemul_acc_montgomery_cached_asm_k2.S → polyvec_basemul_acc_montgomery_cached_k2_avx2_asm.S} +8 -8
  198. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{polyvec_basemul_acc_montgomery_cached_asm_k3.S → polyvec_basemul_acc_montgomery_cached_k3_avx2_asm.S} +8 -8
  199. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{polyvec_basemul_acc_montgomery_cached_asm_k4.S → polyvec_basemul_acc_montgomery_cached_k4_avx2_asm.S} +8 -8
  200. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{reduce.S → reduce_avx2_asm.S} +8 -8
  201. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{rej_uniform_asm.S → rej_uniform_avx2_asm.S} +9 -9
  202. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/rej_uniform_table.c +514 -513
  203. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{tomont.S → tomont_avx2_asm.S} +8 -8
  204. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly.c +61 -57
  205. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly.h +89 -116
  206. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.c +31 -32
  207. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.h +226 -301
  208. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/randombytes.h +21 -29
  209. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sampling.c +68 -63
  210. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sampling.h +37 -48
  211. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sys.h +44 -2
  212. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/verify.h +141 -159
  213. data/lib/pq_crypto/version.rb +1 -1
  214. data/script/vendor_libs.rb +6 -6
  215. metadata +86 -71
  216. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_asm.S +0 -376
  217. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_asm.S +0 -204
  218. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_asm.S +0 -259
  219. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_asm.S +0 -1077
  220. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_asm.S +0 -987
  221. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/KeccakP_1600_times4_SIMD256.c +0 -488
  222. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/KeccakP_1600_times4_SIMD256.h +0 -16
  223. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/intt.S +0 -753
  224. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l4.S +0 -129
  225. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l5.S +0 -145
  226. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l7.S +0 -177
  227. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/ntt.S +0 -653
  228. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/pointwise_montgomery.S +0 -79
  229. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_caddq_asm.S +0 -53
  230. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_chknorm_asm.S +0 -55
  231. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_32_asm.S +0 -85
  232. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_88_asm.S +0 -85
  233. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_32_asm.S +0 -102
  234. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_88_asm.S +0 -110
  235. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_17_asm.S +0 -72
  236. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_19_asm.S +0 -69
  237. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_asm.S +0 -189
  238. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta2_asm.S +0 -135
  239. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta4_asm.S +0 -128
  240. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/intt.S +0 -2311
  241. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/ntt.S +0 -2383
  242. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/nttunpack.S +0 -239
  243. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise.S +0 -131
  244. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l4.S +0 -139
  245. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l5.S +0 -155
  246. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l7.S +0 -187
  247. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_caddq_avx2.c +0 -61
@@ -23,6 +23,7 @@
23
23
  #include "randombytes.h"
24
24
  #include "sampling.h"
25
25
  #include "symmetric.h"
26
+ #include "verify.h"
26
27
 
27
28
  /* Parameter set namespacing
28
29
  * This is to facilitate building multiple instances
@@ -39,24 +40,21 @@
39
40
  MLK_ADD_PARAM_SET(mlk_polyvec_permute_bitrev_to_custom)
40
41
  #define mlk_polymat_permute_bitrev_to_custom \
41
42
  MLK_ADD_PARAM_SET(mlk_polymat_permute_bitrev_to_custom)
43
+ #define mlk_keypair_getnoise_eta1 MLK_ADD_PARAM_SET(mlk_keypair_getnoise_eta1)
44
+ #define mlk_enc_getnoise_eta1_eta2 MLK_ADD_PARAM_SET(mlk_enc_getnoise_eta1_eta2)
42
45
  /* End of parameter set namespacing */
43
46
 
44
- /*************************************************
45
- * Name: mlk_pack_pk
47
+ /**
48
+ * Serialize the public key as the concatenation of the serialized vector of
49
+ * polynomials pk and the public seed used to generate the matrix A.
46
50
  *
47
- * Description: Serialize the public key as concatenation of the
48
- * serialized vector of polynomials pk
49
- * and the public seed used to generate the matrix A.
51
+ * @spec{Implements @[FIPS203, Algorithm 13 (K-PKE.KeyGen), L19].}
50
52
  *
51
- * Arguments: uint8_t *r: pointer to the output serialized public key
52
- * mlk_polyvec pk: pointer to the input public-key mlk_polyvec.
53
- * Must have coefficients within [0,..,q-1].
54
- * const uint8_t *seed: pointer to the input public seed
55
- *
56
- * Specification:
57
- * Implements @[FIPS203, Algorithm 13 (K-PKE.KeyGen), L19]
58
- *
59
- **************************************************/
53
+ * @param[out] r Output serialized public key.
54
+ * @param[in] pk Input public-key polyvec. Must have coefficients within
55
+ * [0,..,MLKEM_Q-1].
56
+ * @param[in] seed Input public seed.
57
+ */
60
58
  static void mlk_pack_pk(uint8_t r[MLKEM_INDCPA_PUBLICKEYBYTES],
61
59
  const mlk_polyvec *pk,
62
60
  const uint8_t seed[MLKEM_SYMBYTES])
@@ -66,22 +64,17 @@ static void mlk_pack_pk(uint8_t r[MLKEM_INDCPA_PUBLICKEYBYTES],
66
64
  mlk_memcpy(r + MLKEM_POLYVECBYTES, seed, MLKEM_SYMBYTES);
67
65
  }
68
66
 
69
- /*************************************************
70
- * Name: mlk_unpack_pk
67
+ /**
68
+ * De-serialize public key from a byte array; approximate inverse of
69
+ * mlk_pack_pk.
71
70
  *
72
- * Description: De-serialize public key from a byte array;
73
- * approximate inverse of mlk_pack_pk
71
+ * @spec{Implements @[FIPS203, Algorithm 14 (K-PKE.Encrypt), L2-3].}
74
72
  *
75
- * Arguments: - mlk_polyvec pk: pointer to output public-key polynomial
76
- * vector Coefficients will be normalized to [0,..,q-1].
77
- * - uint8_t *seed: pointer to output seed to generate matrix A
78
- * - const uint8_t *packedpk: pointer to input serialized public
79
- * key.
80
- *
81
- * Specification:
82
- * Implements @[FIPS203, Algorithm 14 (K-PKE.Encrypt), L2-3]
83
- *
84
- **************************************************/
73
+ * @param[out] pk Output public-key polynomial vector. Coefficients
74
+ * will be normalized to [0,1,..,MLKEM_Q-1].
75
+ * @param[out] seed Output seed to generate matrix A.
76
+ * @param[in] packedpk Input serialized public key.
77
+ */
85
78
  static void mlk_unpack_pk(mlk_polyvec *pk, uint8_t seed[MLKEM_SYMBYTES],
86
79
  const uint8_t packedpk[MLKEM_INDCPA_PUBLICKEYBYTES])
87
80
  {
@@ -94,19 +87,14 @@ static void mlk_unpack_pk(mlk_polyvec *pk, uint8_t seed[MLKEM_SYMBYTES],
94
87
  * work with the easily provable bound by MLKEM_UINT12_LIMIT. */
95
88
  }
96
89
 
97
- /*************************************************
98
- * Name: mlk_pack_sk
90
+ /**
91
+ * Serialize the secret key.
99
92
  *
100
- * Description: Serialize the secret key
93
+ * @spec{Implements @[FIPS203, Algorithm 13 (K-PKE.KeyGen), L20].}
101
94
  *
102
- * Arguments: - uint8_t *r: pointer to output serialized secret key
103
- * - mlk_polyvec sk: pointer to input vector of polynomials
104
- * (secret key)
105
- *
106
- * Specification:
107
- * Implements @[FIPS203, Algorithm 13 (K-PKE.KeyGen), L20]
108
- *
109
- **************************************************/
95
+ * @param[out] r Output serialized secret key.
96
+ * @param[in] sk Input vector of polynomials (secret key).
97
+ */
110
98
  static void mlk_pack_sk(uint8_t r[MLKEM_INDCPA_SECRETKEYBYTES],
111
99
  const mlk_polyvec *sk)
112
100
  {
@@ -114,41 +102,31 @@ static void mlk_pack_sk(uint8_t r[MLKEM_INDCPA_SECRETKEYBYTES],
114
102
  mlk_polyvec_tobytes(r, sk);
115
103
  }
116
104
 
117
- /*************************************************
118
- * Name: mlk_unpack_sk
105
+ /**
106
+ * De-serialize the secret key; inverse of mlk_pack_sk.
119
107
  *
120
- * Description: De-serialize the secret key; inverse of mlk_pack_sk
108
+ * @spec{Implements @[FIPS203, Algorithm 15 (K-PKE.Decrypt), L5].}
121
109
  *
122
- * Arguments: - mlk_polyvec sk: pointer to output vector of polynomials
123
- * (secret key)
124
- * - const uint8_t *packedsk: pointer to input serialized secret
125
- * key
126
- *
127
- * Specification:
128
- * Implements @[FIPS203, Algorithm 15 (K-PKE.Decrypt), L5]
129
- *
130
- **************************************************/
110
+ * @param[out] sk Output vector of polynomials (secret key).
111
+ * @param[in] packedsk Input serialized secret key.
112
+ */
131
113
  static void mlk_unpack_sk(mlk_polyvec *sk,
132
114
  const uint8_t packedsk[MLKEM_INDCPA_SECRETKEYBYTES])
133
115
  {
134
116
  mlk_polyvec_frombytes(sk, packedsk);
135
117
  }
136
118
 
137
- /*************************************************
138
- * Name: mlk_pack_ciphertext
119
+ /**
120
+ * Serialize the ciphertext as the concatenation of the compressed and
121
+ * serialized vector of polynomials b and the compressed and serialized
122
+ * polynomial v.
139
123
  *
140
- * Description: Serialize the ciphertext as concatenation of the
141
- * compressed and serialized vector of polynomials b
142
- * and the compressed and serialized polynomial v
124
+ * @spec{Implements @[FIPS203, Algorithm 14 (K-PKE.Encrypt), L22-23].}
143
125
  *
144
- * Arguments: uint8_t *r: pointer to the output serialized ciphertext
145
- * mlk_poly *pk: pointer to the input vector of polynomials b
146
- * mlk_poly *v: pointer to the input polynomial v
147
- *
148
- * Specification:
149
- * Implements @[FIPS203, Algorithm 14 (K-PKE.Encrypt), L22-23]
150
- *
151
- **************************************************/
126
+ * @param[out] r Output serialized ciphertext.
127
+ * @param[in] b Input vector of polynomials b.
128
+ * @param[in] v Input polynomial v.
129
+ */
152
130
  static void mlk_pack_ciphertext(uint8_t r[MLKEM_INDCPA_BYTES],
153
131
  const mlk_polyvec *b, mlk_poly *v)
154
132
  {
@@ -156,20 +134,16 @@ static void mlk_pack_ciphertext(uint8_t r[MLKEM_INDCPA_BYTES],
156
134
  mlk_poly_compress_dv(r + MLKEM_POLYVECCOMPRESSEDBYTES_DU, v);
157
135
  }
158
136
 
159
- /*************************************************
160
- * Name: mlk_unpack_ciphertext
137
+ /**
138
+ * De-serialize and decompress ciphertext from a byte array; approximate
139
+ * inverse of mlk_pack_ciphertext.
161
140
  *
162
- * Description: De-serialize and decompress ciphertext from a byte array;
163
- * approximate inverse of mlk_pack_ciphertext
141
+ * @spec{Implements @[FIPS203, Algorithm 15 (K-PKE.Decrypt), L1-4].}
164
142
  *
165
- * Arguments: - mlk_polyvec b: pointer to the output vector of polynomials b
166
- * - mlk_poly *v: pointer to the output polynomial v
167
- * - const uint8_t *c: pointer to the input serialized ciphertext
168
- *
169
- * Specification:
170
- * Implements @[FIPS203, Algorithm 15 (K-PKE.Decrypt), L1-4]
171
- *
172
- **************************************************/
143
+ * @param[out] b Output vector of polynomials b.
144
+ * @param[out] v Output polynomial v.
145
+ * @param[in] c Input serialized ciphertext.
146
+ */
173
147
  static void mlk_unpack_ciphertext(mlk_polyvec *b, mlk_poly *v,
174
148
  const uint8_t c[MLKEM_INDCPA_BYTES])
175
149
  {
@@ -201,7 +175,8 @@ __contract__(
201
175
  assigns(i, memory_slice(v, sizeof(mlk_polyvec)))
202
176
  invariant(i <= MLKEM_K)
203
177
  invariant(forall(x, 0, MLKEM_K,
204
- array_bound(v->vec[x].coeffs, 0, MLKEM_N, 0, MLKEM_Q))))
178
+ array_bound(v->vec[x].coeffs, 0, MLKEM_N, 0, MLKEM_Q)))
179
+ decreases(MLKEM_K - i))
205
180
  {
206
181
  mlk_poly_permute_bitrev_to_custom(v->vec[i].coeffs);
207
182
  }
@@ -228,7 +203,8 @@ __contract__(
228
203
  assigns(i, memory_slice(a, sizeof(mlk_polymat)))
229
204
  invariant(i <= MLKEM_K)
230
205
  invariant(forall(x, 0, MLKEM_K, forall(y, 0, MLKEM_K,
231
- array_bound(a->vec[x].vec[y].coeffs, 0, MLKEM_N, 0, MLKEM_Q)))))
206
+ array_bound(a->vec[x].vec[y].coeffs, 0, MLKEM_N, 0, MLKEM_Q))))
207
+ decreases(MLKEM_K - i))
232
208
  {
233
209
  mlk_polyvec_permute_bitrev_to_custom(&a->vec[i]);
234
210
  }
@@ -323,23 +299,18 @@ void mlk_gen_matrix(mlk_polymat *a, const uint8_t seed[MLKEM_SYMBYTES],
323
299
  mlk_zeroize(seed_ext, sizeof(seed_ext));
324
300
  }
325
301
 
326
- /*************************************************
327
- * Name: mlk_matvec_mul
302
+ /**
303
+ * Compute matrix-vector product in NTT domain, via Montgomery multiplication.
328
304
  *
329
- * Description: Computes matrix-vector product in NTT domain,
330
- * via Montgomery multiplication.
305
+ * @spec{Implements @[FIPS203, Section 2.4.7, Eq (2.12), (2.13)].}
331
306
  *
332
- * Arguments: - mlk_polyvec out: Pointer to output polynomial vector
333
- * - mlk_polymat a: Input matrix. Must be in NTT domain
334
- * and have coefficients of absolute value < 4096.
335
- * - mlk_polyvec v: Input polynomial vector. Must be in NTT
336
- * domain.
337
- * - mlk_polyvec vc: Mulcache for v, computed via
338
- * mlk_polyvec_mulcache_compute().
339
- *
340
- * Specification: Implements @[FIPS203, Section 2.4.7, Eq (2.12), (2.13)]
341
- *
342
- **************************************************/
307
+ * @param[out] out Output polynomial vector.
308
+ * @param[in] a Input matrix. Must be in NTT domain and have coefficients
309
+ * of absolute value < 4096.
310
+ * @param[in] v Input polynomial vector. Must be in NTT domain.
311
+ * @param[in] vc Mulcache for @p v, computed via
312
+ * mlk_polyvec_mulcache_compute().
313
+ */
343
314
  static void mlk_matvec_mul(mlk_polyvec *out, const mlk_polymat *a,
344
315
  const mlk_polyvec *v, const mlk_polyvec_mulcache *vc)
345
316
  __contract__(
@@ -356,15 +327,111 @@ __contract__(
356
327
  for (i = 0; i < MLKEM_K; i++)
357
328
  __loop__(
358
329
  assigns(i, memory_slice(out, sizeof(mlk_polyvec)))
359
- invariant(i <= MLKEM_K))
330
+ invariant(i <= MLKEM_K)
331
+ decreases(MLKEM_K - i))
360
332
  {
361
333
  mlk_polyvec_basemul_acc_montgomery_cached(&out->vec[i], &a->vec[i], v, vc);
362
334
  }
363
335
  }
364
336
 
337
+ /**
338
+ * Compute and fill the pv and e polyvec structures needed by
339
+ * mlk_keypair_derand(). Uses x4-batched versions of `poly_getnoise` to
340
+ * leverage batched Keccak-f1600.
341
+ *
342
+ * @spec{Implements @[FIPS203, Algorithm 13 (K-PKE.KeyGen)] steps 8-15.}
343
+ *
344
+ * @param[out] pv Output polynomial vector.
345
+ * @param[out] e Output polynomial vector.
346
+ * @param[in] seed Seed bytes for sampling.
347
+ */
348
+ static void mlk_keypair_getnoise_eta1(mlk_polyvec *pv, mlk_polyvec *e,
349
+ const uint8_t seed[MLKEM_SYMBYTES])
350
+ __contract__(
351
+ requires(memory_no_alias(pv, sizeof(mlk_polyvec)))
352
+ requires(memory_no_alias(e, sizeof(mlk_polyvec)))
353
+ requires(memory_no_alias(seed, MLKEM_SYMBYTES))
354
+ assigns(memory_slice(pv, sizeof(mlk_polyvec)))
355
+ assigns(memory_slice(e, sizeof(mlk_polyvec)))
356
+ ensures(forall(k0, 0, MLKEM_K, array_abs_bound(pv->vec[k0].coeffs, 0, MLKEM_N, MLKEM_ETA1 + 1)))
357
+ ensures(forall(k1, 0, MLKEM_K, array_abs_bound(e->vec[k1].coeffs, 0, MLKEM_N, MLKEM_ETA1 + 1)))
358
+ )
359
+ {
360
+ #if MLKEM_K == 2
361
+ mlk_poly_getnoise_eta1_4x(&pv->vec[0], &pv->vec[1], /* Fill elements of pv */
362
+ &e->vec[0], &e->vec[1], /* and two elements of e */
363
+ seed, 0, 1, 2, 3);
364
+ #elif MLKEM_K == 3
365
+ /*
366
+ * Only the first three output buffers are needed, so we pass NULL as
367
+ * the fourth parameter, and 0xFF as its dummy nonce.
368
+ */
369
+ mlk_poly_getnoise_eta1_4x(&pv->vec[0], &pv->vec[1], &pv->vec[2], NULL, seed,
370
+ 0, 1, 2, 0xFF);
371
+ /* Same here */
372
+ mlk_poly_getnoise_eta1_4x(&e->vec[0], &e->vec[1], &e->vec[2], NULL, seed, 3,
373
+ 4, 5, 0xFF);
374
+ #elif MLKEM_K == 4
375
+ mlk_poly_getnoise_eta1_4x(&pv->vec[0], &pv->vec[1], &pv->vec[2], &pv->vec[3],
376
+ seed, 0, 1, 2, 3);
377
+ mlk_poly_getnoise_eta1_4x(&e->vec[0], &e->vec[1], &e->vec[2], &e->vec[3],
378
+ seed, 4, 5, 6, 7);
379
+ #endif /* MLKEM_K == 4 */
380
+ }
381
+
382
+ /**
383
+ * Compute and fill the sp, ep, and epp polynomial structures needed by
384
+ * mlk_indcpa_enc(). Uses x4-batched versions of `poly_getnoise` to leverage
385
+ * batched Keccak-f1600.
386
+ *
387
+ * @spec{Implements @[FIPS203, Algorithm 14 (K-PKE.Encrypt)] steps 9-16.}
388
+ *
389
+ * @param[out] sp Output polynomial vector.
390
+ * @param[out] ep Output polynomial vector.
391
+ * @param[out] epp Output polynomial.
392
+ * @param[in] coins Seed bytes for sampling.
393
+ */
394
+ static void mlk_enc_getnoise_eta1_eta2(mlk_polyvec *sp, mlk_polyvec *ep,
395
+ mlk_poly *epp,
396
+ const uint8_t coins[MLKEM_SYMBYTES])
397
+ __contract__(
398
+ requires(memory_no_alias(sp, sizeof(mlk_polyvec)))
399
+ requires(memory_no_alias(ep, sizeof(mlk_polyvec)))
400
+ requires(memory_no_alias(epp, sizeof(mlk_poly)))
401
+ requires(memory_no_alias(coins, MLKEM_SYMBYTES))
402
+ assigns(memory_slice(sp, sizeof(mlk_polyvec)))
403
+ assigns(memory_slice(ep, sizeof(mlk_polyvec)))
404
+ assigns(memory_slice(epp, sizeof(mlk_poly)))
405
+ ensures(forall(k0, 0, MLKEM_K, array_abs_bound(sp->vec[k0].coeffs, 0, MLKEM_N, MLKEM_ETA1 + 1)))
406
+ ensures(forall(k1, 0, MLKEM_K, array_abs_bound(ep->vec[k1].coeffs, 0, MLKEM_N, MLKEM_ETA2 + 1)))
407
+ ensures(array_abs_bound(epp->coeffs, 0, MLKEM_N, MLKEM_ETA2 + 1))
408
+ )
409
+ {
410
+ #if MLKEM_K == 2
411
+ mlk_poly_getnoise_eta1122_4x(&sp->vec[0], &sp->vec[1], &ep->vec[0],
412
+ &ep->vec[1], coins, 0, 1, 2, 3);
413
+ mlk_poly_getnoise_eta2(epp, coins, 4);
414
+ #elif MLKEM_K == 3
415
+ /*
416
+ * In this call, only the first three output buffers are needed,
417
+ * so we pass NULL as the fourth parameter, and 0xFF as its dummy nonce.
418
+ */
419
+ mlk_poly_getnoise_eta1_4x(&sp->vec[0], &sp->vec[1], &sp->vec[2], NULL, coins,
420
+ 0, 1, 2, 0xFF /* irrelevant */);
421
+ /* The fourth output buffer in this call _is_ used. */
422
+ mlk_poly_getnoise_eta2_4x(&ep->vec[0], &ep->vec[1], &ep->vec[2], epp, coins,
423
+ 3, 4, 5, 6);
424
+ #elif MLKEM_K == 4
425
+ mlk_poly_getnoise_eta1_4x(&sp->vec[0], &sp->vec[1], &sp->vec[2], &sp->vec[3],
426
+ coins, 0, 1, 2, 3);
427
+ mlk_poly_getnoise_eta2_4x(&ep->vec[0], &ep->vec[1], &ep->vec[2], &ep->vec[3],
428
+ coins, 4, 5, 6, 7);
429
+ mlk_poly_getnoise_eta2(epp, coins, 8);
430
+ #endif /* MLKEM_K == 4 */
431
+ }
432
+
433
+
365
434
  /* Reference: `indcpa_keypair_derand()` in the reference implementation @[REF].
366
- * - We use x4-batched versions of `poly_getnoise` to leverage
367
- * batched x4-batched Keccak-f1600.
368
435
  * - We use a different implementation of `gen_matrix()` which
369
436
  * uses x4-batched Keccak-f1600 (see `mlk_gen_matrix()` above).
370
437
  * - We use a mulcache to speed up matrix-vector multiplication.
@@ -413,25 +480,7 @@ int mlk_indcpa_keypair_derand(uint8_t pk[MLKEM_INDCPA_PUBLICKEYBYTES],
413
480
 
414
481
  mlk_gen_matrix(a, publicseed, 0 /* no transpose */);
415
482
 
416
- #if MLKEM_K == 2
417
- mlk_poly_getnoise_eta1_4x(&skpv->vec[0], &skpv->vec[1], &e->vec[0],
418
- &e->vec[1], noiseseed, 0, 1, 2, 3);
419
- #elif MLKEM_K == 3
420
- /*
421
- * Only the first three output buffers are needed.
422
- * The laster parameter is a dummy that's overwritten later.
423
- */
424
- mlk_poly_getnoise_eta1_4x(&skpv->vec[0], &skpv->vec[1], &skpv->vec[2], NULL,
425
- noiseseed, 0, 1, 2, 0xFF /* irrelevant */);
426
- /* Same here */
427
- mlk_poly_getnoise_eta1_4x(&e->vec[0], &e->vec[1], &e->vec[2], NULL, noiseseed,
428
- 3, 4, 5, 0xFF /* irrelevant */);
429
- #elif MLKEM_K == 4
430
- mlk_poly_getnoise_eta1_4x(&skpv->vec[0], &skpv->vec[1], &skpv->vec[2],
431
- &skpv->vec[3], noiseseed, 0, 1, 2, 3);
432
- mlk_poly_getnoise_eta1_4x(&e->vec[0], &e->vec[1], &e->vec[2], &e->vec[3],
433
- noiseseed, 4, 5, 6, 7);
434
- #endif /* MLKEM_K == 4 */
483
+ mlk_keypair_getnoise_eta1(skpv, e, noiseseed);
435
484
 
436
485
  mlk_polyvec_ntt(skpv);
437
486
  mlk_polyvec_ntt(e);
@@ -507,27 +556,7 @@ int mlk_indcpa_enc(uint8_t c[MLKEM_INDCPA_BYTES],
507
556
 
508
557
  mlk_gen_matrix(at, seed, 1 /* transpose */);
509
558
 
510
- #if MLKEM_K == 2
511
- mlk_poly_getnoise_eta1122_4x(&sp->vec[0], &sp->vec[1], &ep->vec[0],
512
- &ep->vec[1], coins, 0, 1, 2, 3);
513
- mlk_poly_getnoise_eta2(epp, coins, 4);
514
- #elif MLKEM_K == 3
515
- /*
516
- * In this call, only the first three output buffers are needed.
517
- * The last parameter is a dummy that's overwritten later.
518
- */
519
- mlk_poly_getnoise_eta1_4x(&sp->vec[0], &sp->vec[1], &sp->vec[2], NULL, coins,
520
- 0, 1, 2, 0xFF /* irrelevant */);
521
- /* The fourth output buffer in this call _is_ used. */
522
- mlk_poly_getnoise_eta2_4x(&ep->vec[0], &ep->vec[1], &ep->vec[2], epp, coins,
523
- 3, 4, 5, 6);
524
- #elif MLKEM_K == 4
525
- mlk_poly_getnoise_eta1_4x(&sp->vec[0], &sp->vec[1], &sp->vec[2], &sp->vec[3],
526
- coins, 0, 1, 2, 3);
527
- mlk_poly_getnoise_eta2_4x(&ep->vec[0], &ep->vec[1], &ep->vec[2], &ep->vec[3],
528
- coins, 4, 5, 6, 7);
529
- mlk_poly_getnoise_eta2(epp, coins, 8);
530
- #endif /* MLKEM_K == 4 */
559
+ mlk_enc_getnoise_eta1_eta2(sp, ep, epp, coins);
531
560
 
532
561
  mlk_polyvec_ntt(sp);
533
562
 
@@ -620,3 +649,5 @@ cleanup:
620
649
  #undef mlk_matvec_mul
621
650
  #undef mlk_polyvec_permute_bitrev_to_custom
622
651
  #undef mlk_polymat_permute_bitrev_to_custom
652
+ #undef mlk_keypair_getnoise_eta1
653
+ #undef mlk_enc_getnoise_eta1_eta2
@@ -20,23 +20,19 @@
20
20
  #include "poly_k.h"
21
21
 
22
22
  #define mlk_gen_matrix MLK_NAMESPACE_K(gen_matrix)
23
- /*************************************************
24
- * Name: mlk_gen_matrix
25
- *
26
- * Description: Deterministically generate matrix A (or the transpose of A)
27
- * from a seed. Entries of the matrix are polynomials that look
28
- * uniformly random. Performs rejection sampling on output of
29
- * a XOF
30
- *
31
- * Arguments: - mlk_polymat a: pointer to output matrix A
32
- * - const uint8_t *seed: pointer to input seed
33
- * - int transposed: boolean deciding whether A or A^T is generated
34
- *
35
- * Specification: Implements @[FIPS203, Algorithm 13 (K-PKE.KeyGen), L3-7]
36
- * and @[FIPS203, Algorithm 14 (K-PKE.Encrypt), L4-8].
37
- * The `transposed` parameter only affects internal presentation.
38
- *
39
- **************************************************/
23
+ /**
24
+ * Deterministically generate matrix A (or the transpose of A) from a seed.
25
+ * Entries of the matrix are polynomials that look uniformly random.
26
+ * Performs rejection sampling on the output of an XOF.
27
+ *
28
+ * @spec{Implements @[FIPS203, Algorithm 13 (K-PKE.KeyGen), L3-7] and
29
+ * @[FIPS203, Algorithm 14 (K-PKE.Encrypt), L4-8]. The @p transposed
30
+ * parameter only affects internal presentation.}
31
+ *
32
+ * @param[out] a Output matrix A.
33
+ * @param[in] seed Input seed.
34
+ * @param transposed Boolean deciding whether A or A^T is generated.
35
+ */
40
36
  MLK_INTERNAL_API
41
37
  void mlk_gen_matrix(mlk_polymat *a, const uint8_t seed[MLKEM_SYMBYTES],
42
38
  int transposed)
@@ -51,22 +47,27 @@ __contract__(
51
47
 
52
48
  #define mlk_indcpa_keypair_derand \
53
49
  MLK_NAMESPACE_K(indcpa_keypair_derand) MLK_CONTEXT_PARAMETERS_3
54
- /*************************************************
55
- * Name: mlk_indcpa_keypair_derand
56
- *
57
- * Description: Generates public and private key for the CPA-secure
58
- * public-key encryption scheme underlying ML-KEM
59
- *
60
- * Arguments: - uint8_t *pk: pointer to output public key
61
- * (of length MLKEM_INDCPA_PUBLICKEYBYTES bytes)
62
- * - uint8_t *sk: pointer to output private key
63
- * (of length MLKEM_INDCPA_SECRETKEYBYTES bytes)
64
- * - const uint8_t *coins: pointer to input randomness
65
- * (of length MLKEM_SYMBYTES bytes)
66
- *
67
- * Specification: Implements @[FIPS203, Algorithm 13 (K-PKE.KeyGen)].
68
- *
69
- **************************************************/
50
+ /**
51
+ * Generate public and private key for the CPA-secure public-key encryption
52
+ * scheme underlying ML-KEM.
53
+ *
54
+ * @spec{Implements @[FIPS203, Algorithm 13 (K-PKE.KeyGen)].}
55
+ *
56
+ * @param[out] pk Output public key
57
+ * (length MLKEM_INDCPA_PUBLICKEYBYTES bytes).
58
+ * @param[out] sk Output private key
59
+ * (length MLKEM_INDCPA_SECRETKEYBYTES bytes).
60
+ * @param[in] coins Input randomness (length MLKEM_SYMBYTES bytes).
61
+ * @param context Application context. Only present when
62
+ * MLK_CONFIG_CONTEXT_PARAMETER is defined; type set by
63
+ * MLK_CONFIG_CONTEXT_PARAMETER_TYPE.
64
+ *
65
+ * @retval 0 Success.
66
+ * @retval MLK_ERR_FAIL MLK_CONFIG_KEYGEN_PCT enabled and PCT failed.
67
+ * @retval MLK_ERR_OUT_OF_MEMORY MLK_CONFIG_CUSTOM_ALLOC_FREE was used and
68
+ * MLK_CUSTOM_ALLOC returned NULL.
69
+ * @retval MLK_ERR_RNG_FAIL Random number generation failed.
70
+ */
70
71
  MLK_INTERNAL_API
71
72
  MLK_MUST_CHECK_RETURN_VALUE
72
73
  int mlk_indcpa_keypair_derand(uint8_t pk[MLKEM_INDCPA_PUBLICKEYBYTES],
@@ -85,25 +86,27 @@ __contract__(
85
86
  );
86
87
 
87
88
  #define mlk_indcpa_enc MLK_NAMESPACE_K(indcpa_enc) MLK_CONTEXT_PARAMETERS_4
88
- /*************************************************
89
- * Name: mlk_indcpa_enc
90
- *
91
- * Description: Encryption function of the CPA-secure
92
- * public-key encryption scheme underlying Kyber.
93
- *
94
- * Arguments: - uint8_t *c: pointer to output ciphertext
95
- * (of length MLKEM_INDCPA_BYTES bytes)
96
- * - const uint8_t *m: pointer to input message
97
- * (of length MLKEM_INDCPA_MSGBYTES bytes)
98
- * - const uint8_t *pk: pointer to input public key
99
- * (of length MLKEM_INDCPA_PUBLICKEYBYTES)
100
- * - const uint8_t *coins: pointer to input random coins used as
101
- * seed (of length MLKEM_SYMBYTES) to deterministically generate
102
- * all randomness
103
- *
104
- * Specification: Implements @[FIPS203, Algorithm 14 (K-PKE.Encrypt)].
105
- *
106
- **************************************************/
89
+ /**
90
+ * Encryption function of the CPA-secure public-key encryption scheme
91
+ * underlying ML-KEM.
92
+ *
93
+ * @spec{Implements @[FIPS203, Algorithm 14 (K-PKE.Encrypt)].}
94
+ *
95
+ * @param[out] c Output ciphertext (length MLKEM_INDCPA_BYTES bytes).
96
+ * @param[in] m Input message (length MLKEM_INDCPA_MSGBYTES bytes).
97
+ * @param[in] pk Input public key
98
+ * (length MLKEM_INDCPA_PUBLICKEYBYTES bytes).
99
+ * @param[in] coins Input random coins used as seed (length MLKEM_SYMBYTES
100
+ * bytes) to deterministically generate all randomness.
101
+ * @param context Application context. Only present when
102
+ * MLK_CONFIG_CONTEXT_PARAMETER is defined; type set by
103
+ * MLK_CONFIG_CONTEXT_PARAMETER_TYPE.
104
+ *
105
+ * @retval 0 Success.
106
+ * @retval MLK_ERR_FAIL Operation failed.
107
+ * @retval MLK_ERR_OUT_OF_MEMORY MLK_CONFIG_CUSTOM_ALLOC_FREE was used and
108
+ * MLK_CUSTOM_ALLOC returned NULL.
109
+ */
107
110
  MLK_INTERNAL_API
108
111
  MLK_MUST_CHECK_RETURN_VALUE
109
112
  int mlk_indcpa_enc(uint8_t c[MLKEM_INDCPA_BYTES],
@@ -122,22 +125,26 @@ __contract__(
122
125
  );
123
126
 
124
127
  #define mlk_indcpa_dec MLK_NAMESPACE_K(indcpa_dec) MLK_CONTEXT_PARAMETERS_3
125
- /*************************************************
126
- * Name: mlk_indcpa_dec
127
- *
128
- * Description: Decryption function of the CPA-secure
129
- * public-key encryption scheme underlying Kyber.
130
- *
131
- * Arguments: - uint8_t *m: pointer to output decrypted message
132
- * (of length MLKEM_INDCPA_MSGBYTES)
133
- * - const uint8_t *c: pointer to input ciphertext
134
- * (of length MLKEM_INDCPA_BYTES)
135
- * - const uint8_t *sk: pointer to input secret key
136
- * (of length MLKEM_INDCPA_SECRETKEYBYTES)
137
- *
138
- * Specification: Implements @[FIPS203, Algorithm 15 (K-PKE.Decrypt)].
139
- *
140
- **************************************************/
128
+ /**
129
+ * Decryption function of the CPA-secure public-key encryption scheme
130
+ * underlying ML-KEM.
131
+ *
132
+ * @spec{Implements @[FIPS203, Algorithm 15 (K-PKE.Decrypt)].}
133
+ *
134
+ * @param[out] m Output decrypted message
135
+ * (length MLKEM_INDCPA_MSGBYTES bytes).
136
+ * @param[in] c Input ciphertext (length MLKEM_INDCPA_BYTES bytes).
137
+ * @param[in] sk Input secret key
138
+ * (length MLKEM_INDCPA_SECRETKEYBYTES bytes).
139
+ * @param context Application context. Only present when
140
+ * MLK_CONFIG_CONTEXT_PARAMETER is defined; type set by
141
+ * MLK_CONFIG_CONTEXT_PARAMETER_TYPE.
142
+ *
143
+ * @retval 0 Success.
144
+ * @retval MLK_ERR_FAIL Operation failed.
145
+ * @retval MLK_ERR_OUT_OF_MEMORY MLK_CONFIG_CUSTOM_ALLOC_FREE was used and
146
+ * MLK_CUSTOM_ALLOC returned NULL.
147
+ */
141
148
  MLK_INTERNAL_API
142
149
  MLK_MUST_CHECK_RETURN_VALUE
143
150
  int mlk_indcpa_dec(uint8_t m[MLKEM_INDCPA_MSGBYTES],