pq_crypto 0.6.4 → 0.6.6

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 (213) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +180 -0
  3. data/README.md +7 -0
  4. data/ext/pqcrypto/extconf.rb +4 -1
  5. data/ext/pqcrypto/pq_externalmu.c +35 -0
  6. data/ext/pqcrypto/pqcrypto_native_api.h +85 -75
  7. data/ext/pqcrypto/pqcrypto_ruby_secure.c +16 -9
  8. data/ext/pqcrypto/pqcrypto_secure.c +43 -33
  9. data/ext/pqcrypto/pqcrypto_secure.h +52 -47
  10. data/ext/pqcrypto/pqcrypto_version.h +1 -1
  11. data/ext/pqcrypto/vendor/.vendored +7 -7
  12. data/ext/pqcrypto/vendor/mldsa-native/BUILDING.md +5 -2
  13. data/ext/pqcrypto/vendor/mldsa-native/LICENSE +21 -2
  14. data/ext/pqcrypto/vendor/mldsa-native/README.md +20 -7
  15. data/ext/pqcrypto/vendor/mldsa-native/RELEASE.md +160 -0
  16. data/ext/pqcrypto/vendor/mldsa-native/SECURITY.md +1 -1
  17. data/ext/pqcrypto/vendor/mldsa-native/mldsa/README.md +2 -2
  18. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.c +85 -59
  19. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.h +292 -348
  20. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_asm.S +122 -76
  21. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_config.h +184 -86
  22. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/cbmc.h +49 -4
  23. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/common.h +49 -81
  24. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/context.h +152 -0
  25. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/ct.h +25 -12
  26. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/debug.c +2 -0
  27. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/debug.h +2 -0
  28. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202x4.c +2 -2
  29. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.c +9 -11
  30. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/auto.h +19 -11
  31. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_aarch64_asm.S +6 -4
  32. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_aarch64_asm.S +7 -4
  33. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_aarch64_asm.S +7 -4
  34. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm.S +12 -9
  35. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm.S +12 -9
  36. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_scalar.h +1 -1
  37. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_v84a.h +3 -2
  38. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x2_v84a.h +3 -2
  39. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_scalar.h +6 -1
  40. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +3 -2
  41. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/api.h +11 -11
  42. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/mve.h +9 -22
  43. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +8 -5
  44. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.c +1 -0
  45. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/{state_extract_bytes_x4_mve.S → keccak_f1600_x4_state_extract_bytes_mve.S} +14 -14
  46. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/{state_xor_bytes_x4_mve.S → keccak_f1600_x4_state_xor_bytes_mve.S} +12 -12
  47. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/auto.h +5 -4
  48. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/keccak_f1600_x4_avx2.h +2 -2
  49. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/fips202_native_x86_64.h +1 -0
  50. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccak_f1600_x4_avx2_asm.S +36 -2
  51. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/meta.h +62 -4
  52. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/arith_native_aarch64.h +87 -54
  53. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{intt_aarch64_asm.S → mldsa_intt_aarch64_asm.S} +39 -6
  54. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{ntt_aarch64_asm.S → mldsa_ntt_aarch64_asm.S} +39 -6
  55. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{pointwise_montgomery_aarch64_asm.S → mldsa_pointwise_montgomery_aarch64_asm.S} +25 -3
  56. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{poly_caddq_aarch64_asm.S → mldsa_poly_caddq_aarch64_asm.S} +19 -3
  57. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{poly_chknorm_aarch64_asm.S → mldsa_poly_chknorm_aarch64_asm.S} +24 -3
  58. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{poly_decompose_32_aarch64_asm.S → mldsa_poly_decompose_32_aarch64_asm.S} +25 -3
  59. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{poly_decompose_88_aarch64_asm.S → mldsa_poly_decompose_88_aarch64_asm.S} +25 -3
  60. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{poly_use_hint_32_aarch64_asm.S → mldsa_poly_use_hint_32_aarch64_asm.S} +25 -3
  61. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{poly_use_hint_88_aarch64_asm.S → mldsa_poly_use_hint_88_aarch64_asm.S} +25 -3
  62. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{mld_polyvecl_pointwise_acc_montgomery_l4_aarch64_asm.S → mldsa_polyvecl_pointwise_acc_montgomery_l4_aarch64_asm.S} +31 -3
  63. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{mld_polyvecl_pointwise_acc_montgomery_l5_aarch64_asm.S → mldsa_polyvecl_pointwise_acc_montgomery_l5_aarch64_asm.S} +31 -3
  64. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{mld_polyvecl_pointwise_acc_montgomery_l7_aarch64_asm.S → mldsa_polyvecl_pointwise_acc_montgomery_l7_aarch64_asm.S} +31 -3
  65. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{polyz_unpack_17_aarch64_asm.S → mldsa_polyz_unpack_17_aarch64_asm.S} +31 -3
  66. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{polyz_unpack_19_aarch64_asm.S → mldsa_polyz_unpack_19_aarch64_asm.S} +31 -3
  67. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{rej_uniform_aarch64_asm.S → mldsa_rej_uniform_aarch64_asm.S} +48 -15
  68. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{rej_uniform_eta2_aarch64_asm.S → mldsa_rej_uniform_eta2_aarch64_asm.S} +42 -9
  69. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{rej_uniform_eta4_aarch64_asm.S → mldsa_rej_uniform_eta4_aarch64_asm.S} +42 -9
  70. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/api.h +11 -3
  71. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/meta.h +3 -2
  72. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/meta.h +28 -28
  73. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/arith_native_x86_64.h +171 -49
  74. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/{intt_avx2_asm.S → mldsa_intt_avx2_asm.S} +23 -1
  75. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/{ntt_avx2_asm.S → mldsa_ntt_avx2_asm.S} +23 -1
  76. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/{nttunpack_avx2_asm.S → mldsa_nttunpack_avx2_asm.S} +17 -1
  77. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/{pointwise_acc_l4_avx2_asm.S → mldsa_pointwise_acc_l4_avx2_asm.S} +37 -3
  78. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/{pointwise_acc_l5_avx2_asm.S → mldsa_pointwise_acc_l5_avx2_asm.S} +37 -3
  79. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/{pointwise_acc_l7_avx2_asm.S → mldsa_pointwise_acc_l7_avx2_asm.S} +37 -3
  80. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/{pointwise_avx2_asm.S → mldsa_pointwise_avx2_asm.S} +31 -3
  81. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/{poly_caddq_avx2_asm.S → mldsa_poly_caddq_avx2_asm.S} +18 -9
  82. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_chknorm_avx2_asm.S +176 -0
  83. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_decompose_32_avx2_asm.S +490 -0
  84. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_decompose_88_avx2_asm.S +489 -0
  85. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_use_hint_32_avx2_asm.S +123 -0
  86. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_use_hint_88_avx2_asm.S +125 -0
  87. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_polyz_unpack_17_avx2_asm.S +355 -0
  88. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_polyz_unpack_19_avx2_asm.S +355 -0
  89. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_avx2_asm.S +132 -0
  90. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_eta2_avx2_asm.S +205 -0
  91. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_eta4_avx2_asm.S +176 -0
  92. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.c +27 -36
  93. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.h +42 -8
  94. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/params.h +93 -17
  95. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.c +74 -15
  96. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.h +97 -11
  97. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.c +7 -38
  98. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.h +49 -7
  99. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.c +16 -17
  100. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.h +26 -9
  101. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec_lazy.c +3 -0
  102. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec_lazy.h +18 -19
  103. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/reduce.h +15 -3
  104. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/rounding.h +28 -6
  105. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.c +311 -246
  106. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.h +245 -240
  107. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sys.h +64 -5
  108. data/ext/pqcrypto/vendor/mlkem-native/BUILDING.md +5 -2
  109. data/ext/pqcrypto/vendor/mlkem-native/LICENSE +21 -3
  110. data/ext/pqcrypto/vendor/mlkem-native/README.md +4 -6
  111. data/ext/pqcrypto/vendor/mlkem-native/RELEASE.md +211 -0
  112. data/ext/pqcrypto/vendor/mlkem-native/mlkem/README.md +2 -2
  113. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.c +25 -34
  114. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.h +79 -142
  115. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_asm.S +62 -71
  116. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_config.h +77 -39
  117. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/cbmc.h +25 -0
  118. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/common.h +48 -34
  119. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.c +25 -5
  120. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.h +14 -0
  121. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/context.h +51 -0
  122. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202.h +2 -2
  123. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/keccakf1600.c +8 -8
  124. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/auto.h +20 -12
  125. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_aarch64_asm.S +5 -3
  126. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_aarch64_asm.S +5 -2
  127. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_aarch64_asm.S +5 -2
  128. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm.S +10 -7
  129. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm.S +10 -7
  130. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x1_scalar.h +1 -1
  131. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x1_v84a.h +3 -2
  132. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x2_v84a.h +3 -2
  133. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x4_v8a_scalar.h +6 -1
  134. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +3 -2
  135. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/api.h +11 -11
  136. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/mve.h +8 -22
  137. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +8 -5
  138. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/{state_extract_bytes_x4_mve.S → keccak_f1600_x4_state_extract_bytes_mve.S} +14 -14
  139. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/{state_xor_bytes_x4_mve.S → keccak_f1600_x4_state_xor_bytes_mve.S} +12 -12
  140. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/keccak_f1600_x4_avx2.h +2 -2
  141. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccak_f1600_x4_avx2_asm.S +36 -2
  142. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/indcpa.c +22 -0
  143. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/indcpa.h +20 -11
  144. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.c +39 -11
  145. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.h +64 -15
  146. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/meta.h +44 -2
  147. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/aarch64_zetas.c +2 -0
  148. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/arith_native_aarch64.h +11 -10
  149. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{intt_aarch64_asm.S → mlkem_intt_aarch64_asm.S} +16 -9
  150. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{ntt_aarch64_asm.S → mlkem_ntt_aarch64_asm.S} +10 -7
  151. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{poly_mulcache_compute_aarch64_asm.S → mlkem_poly_mulcache_compute_aarch64_asm.S} +6 -3
  152. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{poly_reduce_aarch64_asm.S → mlkem_poly_reduce_aarch64_asm.S} +6 -3
  153. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{poly_tobytes_aarch64_asm.S → mlkem_poly_tobytes_aarch64_asm.S} +12 -5
  154. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{poly_tomont_aarch64_asm.S → mlkem_poly_tomont_aarch64_asm.S} +11 -5
  155. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{polyvec_basemul_acc_montgomery_cached_k2_aarch64_asm.S → mlkem_polyvec_basemul_acc_montgomery_cached_k2_aarch64_asm.S} +6 -3
  156. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{polyvec_basemul_acc_montgomery_cached_k3_aarch64_asm.S → mlkem_polyvec_basemul_acc_montgomery_cached_k3_aarch64_asm.S} +6 -3
  157. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{polyvec_basemul_acc_montgomery_cached_k4_aarch64_asm.S → mlkem_polyvec_basemul_acc_montgomery_cached_k4_aarch64_asm.S} +6 -3
  158. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{rej_uniform_aarch64_asm.S → mlkem_rej_uniform_aarch64_asm.S} +17 -17
  159. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/api.h +21 -8
  160. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/meta.h +1 -1
  161. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/meta.h +4 -0
  162. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/{intt_ppc_asm.S → mlkem_intt_ppc_asm.S} +29 -5
  163. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/{ntt_ppc_asm.S → mlkem_ntt_ppc_asm.S} +22 -1
  164. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/{poly_tomont_ppc_asm.S → mlkem_poly_tomont_ppc_asm.S} +25 -3
  165. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/{reduce_ppc_asm.S → mlkem_reduce_ppc_asm.S} +22 -1
  166. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/meta.h +4 -0
  167. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/arith_native_riscv64.h +4 -0
  168. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_poly.c +6 -2
  169. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/meta.h +45 -25
  170. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/arith_native_x86_64.h +20 -20
  171. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/compress_consts.c +14 -3
  172. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/compress_consts.h +8 -0
  173. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{intt_avx2_asm.S → mlkem_intt_avx2_asm.S} +27 -3
  174. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{ntt_avx2_asm.S → mlkem_ntt_avx2_asm.S} +23 -1
  175. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{nttfrombytes_avx2_asm.S → mlkem_nttfrombytes_avx2_asm.S} +27 -3
  176. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{ntttobytes_avx2_asm.S → mlkem_ntttobytes_avx2_asm.S} +27 -3
  177. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{nttunpack_avx2_asm.S → mlkem_nttunpack_avx2_asm.S} +17 -1
  178. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_compress_d10_avx2_asm.S → mlkem_poly_compress_d10_avx2_asm.S} +34 -3
  179. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_compress_d11_avx2_asm.S → mlkem_poly_compress_d11_avx2_asm.S} +33 -2
  180. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_compress_d4_avx2_asm.S → mlkem_poly_compress_d4_avx2_asm.S} +34 -3
  181. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_compress_d5_avx2_asm.S → mlkem_poly_compress_d5_avx2_asm.S} +33 -2
  182. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_decompress_d10_avx2_asm.S → mlkem_poly_decompress_d10_avx2_asm.S} +32 -3
  183. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_decompress_d11_avx2_asm.S → mlkem_poly_decompress_d11_avx2_asm.S} +32 -2
  184. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_decompress_d4_avx2_asm.S → mlkem_poly_decompress_d4_avx2_asm.S} +32 -3
  185. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_decompress_d5_avx2_asm.S → mlkem_poly_decompress_d5_avx2_asm.S} +32 -2
  186. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_mulcache_compute_avx2_asm.S → mlkem_poly_mulcache_compute_avx2_asm.S} +29 -1
  187. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{polyvec_basemul_acc_montgomery_cached_k2_avx2_asm.S → mlkem_polyvec_basemul_acc_montgomery_cached_k2_avx2_asm.S} +35 -1
  188. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{polyvec_basemul_acc_montgomery_cached_k3_avx2_asm.S → mlkem_polyvec_basemul_acc_montgomery_cached_k3_avx2_asm.S} +35 -1
  189. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{polyvec_basemul_acc_montgomery_cached_k4_avx2_asm.S → mlkem_polyvec_basemul_acc_montgomery_cached_k4_avx2_asm.S} +35 -1
  190. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{reduce_avx2_asm.S → mlkem_reduce_avx2_asm.S} +17 -1
  191. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{rej_uniform_avx2_asm.S → mlkem_rej_uniform_avx2_asm.S} +40 -7
  192. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{tomont_avx2_asm.S → mlkem_tomont_avx2_asm.S} +20 -3
  193. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly.c +7 -2
  194. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly.h +6 -0
  195. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.c +25 -4
  196. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.h +33 -4
  197. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sampling.c +4 -0
  198. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sampling.h +4 -0
  199. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sys.h +21 -3
  200. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/verify.h +11 -10
  201. data/lib/pq_crypto/version.rb +1 -1
  202. data/script/vendor_libs.rb +6 -6
  203. metadata +79 -79
  204. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_chknorm_avx2.c +0 -52
  205. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_32_avx2.c +0 -157
  206. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_88_avx2.c +0 -157
  207. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_32_avx2.c +0 -103
  208. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_88_avx2.c +0 -105
  209. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_17_avx2.c +0 -94
  210. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_19_avx2.c +0 -96
  211. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_avx2.c +0 -126
  212. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta2_avx2.c +0 -157
  213. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta4_avx2.c +0 -141
@@ -7,10 +7,44 @@
7
7
  #if defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) && \
8
8
  !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \
9
9
  (defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 3)
10
+ /*yaml
11
+ Name: polyvec_basemul_acc_montgomery_cached_k3_avx2_asm
12
+ Description: x86_64 AVX2 base multiplication with accumulation (k=3)
13
+ Signature: void mlk_polyvec_basemul_acc_montgomery_cached_k3_avx2_asm(int16_t *r, const int16_t *a, const int16_t *b, const int16_t *b_cache)
14
+ ABI:
15
+ Architecture: x86_64
16
+ CallingConvention: SysV
17
+ Features: [AVX2]
18
+ rdi:
19
+ type: buffer
20
+ size_bytes: 512
21
+ permissions: read/write
22
+ c_parameter: int16_t *r
23
+ description: Output polynomial (256 x int16_t)
24
+ rsi:
25
+ type: buffer
26
+ size_bytes: 1536
27
+ permissions: read-only
28
+ c_parameter: const int16_t *a
29
+ description: Input polyvec a (3 x 256 x int16_t)
30
+ rdx:
31
+ type: buffer
32
+ size_bytes: 1536
33
+ permissions: read-only
34
+ c_parameter: const int16_t *b
35
+ description: Input polyvec b (3 x 256 x int16_t)
36
+ rcx:
37
+ type: buffer
38
+ size_bytes: 768
39
+ permissions: read-only
40
+ c_parameter: const int16_t *b_cache
41
+ description: Mulcache for b (3 x 128 x int16_t)
42
+ */
43
+
10
44
 
11
45
  /*
12
46
  * WARNING: This file is auto-derived from the mlkem-native source file
13
- * dev/x86_64/src/polyvec_basemul_acc_montgomery_cached_k3_avx2_asm.S using scripts/simpasm. Do not modify it directly.
47
+ * dev/x86_64/src/mlkem_polyvec_basemul_acc_montgomery_cached_k3_avx2_asm.S using scripts/simpasm. Do not modify it directly.
14
48
  */
15
49
 
16
50
  .text
@@ -7,10 +7,44 @@
7
7
  #if defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) && \
8
8
  !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \
9
9
  (defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 4)
10
+ /*yaml
11
+ Name: polyvec_basemul_acc_montgomery_cached_k4_avx2_asm
12
+ Description: x86_64 AVX2 base multiplication with accumulation (k=4)
13
+ Signature: void mlk_polyvec_basemul_acc_montgomery_cached_k4_avx2_asm(int16_t *r, const int16_t *a, const int16_t *b, const int16_t *b_cache)
14
+ ABI:
15
+ Architecture: x86_64
16
+ CallingConvention: SysV
17
+ Features: [AVX2]
18
+ rdi:
19
+ type: buffer
20
+ size_bytes: 512
21
+ permissions: read/write
22
+ c_parameter: int16_t *r
23
+ description: Output polynomial (256 x int16_t)
24
+ rsi:
25
+ type: buffer
26
+ size_bytes: 2048
27
+ permissions: read-only
28
+ c_parameter: const int16_t *a
29
+ description: Input polyvec a (4 x 256 x int16_t)
30
+ rdx:
31
+ type: buffer
32
+ size_bytes: 2048
33
+ permissions: read-only
34
+ c_parameter: const int16_t *b
35
+ description: Input polyvec b (4 x 256 x int16_t)
36
+ rcx:
37
+ type: buffer
38
+ size_bytes: 1024
39
+ permissions: read-only
40
+ c_parameter: const int16_t *b_cache
41
+ description: Mulcache for b (4 x 128 x int16_t)
42
+ */
43
+
10
44
 
11
45
  /*
12
46
  * WARNING: This file is auto-derived from the mlkem-native source file
13
- * dev/x86_64/src/polyvec_basemul_acc_montgomery_cached_k4_avx2_asm.S using scripts/simpasm. Do not modify it directly.
47
+ * dev/x86_64/src/mlkem_polyvec_basemul_acc_montgomery_cached_k4_avx2_asm.S using scripts/simpasm. Do not modify it directly.
14
48
  */
15
49
 
16
50
  .text
@@ -27,10 +27,26 @@
27
27
 
28
28
  #if defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) && \
29
29
  !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED)
30
+ /*yaml
31
+ Name: reduce_avx2_asm
32
+ Description: x86_64 AVX2 modular reduction
33
+ Signature: void mlk_reduce_avx2_asm(int16_t *r)
34
+ ABI:
35
+ Architecture: x86_64
36
+ CallingConvention: SysV
37
+ Features: [AVX2]
38
+ rdi:
39
+ type: buffer
40
+ size_bytes: 512
41
+ permissions: read/write
42
+ c_parameter: int16_t *r
43
+ description: Input/output polynomial (256 x int16_t)
44
+ */
45
+
30
46
 
31
47
  /*
32
48
  * WARNING: This file is auto-derived from the mlkem-native source file
33
- * dev/x86_64/src/reduce_avx2_asm.S using scripts/simpasm. Do not modify it directly.
49
+ * dev/x86_64/src/mlkem_reduce_avx2_asm.S using scripts/simpasm. Do not modify it directly.
34
50
  */
35
51
 
36
52
  .text
@@ -22,10 +22,43 @@
22
22
 
23
23
  #if defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) && \
24
24
  !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED)
25
+ /*yaml
26
+ Name: rej_uniform_avx2_asm
27
+ Description: x86_64 AVX2 rejection sampling
28
+ Signature: uint64_t mlk_rej_uniform_avx2_asm(int16_t *r, const uint8_t *buf, unsigned buflen, const uint8_t *table)
29
+ ABI:
30
+ Architecture: x86_64
31
+ CallingConvention: SysV
32
+ Features: [AVX2]
33
+ rdi:
34
+ type: buffer
35
+ size_bytes: 512
36
+ permissions: write-only
37
+ c_parameter: int16_t *r
38
+ description: Output buffer (256 x int16_t)
39
+ rsi:
40
+ type: buffer
41
+ size_bytes: rdx
42
+ permissions: read-only
43
+ c_parameter: const uint8_t *buf
44
+ description: Input buffer
45
+ rdx:
46
+ type: scalar
47
+ c_parameter: unsigned buflen
48
+ description: Length of input buffer (must be multiple of 12)
49
+ test_with: 504 # MLKEM_GEN_MATRIX_NBLOCKS * MLK_XOF_RATE
50
+ rcx:
51
+ type: buffer
52
+ size_bytes: 4096
53
+ permissions: read-only
54
+ c_parameter: const uint8_t *table
55
+ description: Lookup table
56
+ */
57
+
25
58
 
26
59
  /*
27
60
  * WARNING: This file is auto-derived from the mlkem-native source file
28
- * dev/x86_64/src/rej_uniform_avx2_asm.S using scripts/simpasm. Do not modify it directly.
61
+ * dev/x86_64/src/mlkem_rej_uniform_avx2_asm.S using scripts/simpasm. Do not modify it directly.
29
62
  */
30
63
 
31
64
  .text
@@ -38,7 +71,7 @@ MLK_ASM_FN_SYMBOL(rej_uniform_avx2_asm)
38
71
  .cfi_adjust_cfa_offset 0x210
39
72
  xorl %eax, %eax
40
73
  testq %rdx, %rdx
41
- je Lrej_uniform_asm_end
74
+ je Lmlk_rej_uniform_asm_end
42
75
  movabsq $0xd010d010d010d01, %rax # imm = 0xD010D010D010D01
43
76
  movq %rax, %xmm0
44
77
  pinsrq $0x1, %rax, %xmm0
@@ -53,7 +86,7 @@ MLK_ASM_FN_SYMBOL(rej_uniform_avx2_asm)
53
86
  movq $0x0, %r8
54
87
  movq $0x5555, %r9 # imm = 0x5555
55
88
 
56
- Lrej_uniform_asm_loop_start:
89
+ Lmlk_rej_uniform_asm_loop_start:
57
90
  movq (%rsi,%r8), %xmm2
58
91
  pinsrd $0x2, 0x8(%rsi,%r8), %xmm2
59
92
  pshufb %xmm4, %xmm2
@@ -73,12 +106,12 @@ Lrej_uniform_asm_loop_start:
73
106
  popcntq %r11, %r11
74
107
  addq %r11, %rax
75
108
  cmpq $0x100, %rax # imm = 0x100
76
- jae Lrej_uniform_asm_final_copy
109
+ jae Lmlk_rej_uniform_asm_final_copy
77
110
  addq $0xc, %r8
78
111
  cmpq %r8, %rdx
79
- ja Lrej_uniform_asm_loop_start
112
+ ja Lmlk_rej_uniform_asm_loop_start
80
113
 
81
- Lrej_uniform_asm_final_copy:
114
+ Lmlk_rej_uniform_asm_final_copy:
82
115
  movq $0x100, %rcx # imm = 0x100
83
116
  cmpq $0x100, %rax # imm = 0x100
84
117
  cmovaq %rcx, %rax
@@ -87,7 +120,7 @@ Lrej_uniform_asm_final_copy:
87
120
  shlq %rcx
88
121
  rep movsb (%rsi), %es:(%rdi)
89
122
 
90
- Lrej_uniform_asm_end:
123
+ Lmlk_rej_uniform_asm_end:
91
124
  addq $0x210, %rsp # imm = 0x210
92
125
  .cfi_adjust_cfa_offset -0x210
93
126
  retq
@@ -24,11 +24,28 @@
24
24
 
25
25
  #include "../../../common.h"
26
26
  #if defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) && \
27
- !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED)
27
+ !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \
28
+ !defined(MLK_CONFIG_NO_KEYPAIR_API)
29
+ /*yaml
30
+ Name: tomont_avx2_asm
31
+ Description: x86_64 AVX2 Montgomery conversion
32
+ Signature: void mlk_tomont_avx2_asm(int16_t *r)
33
+ ABI:
34
+ Architecture: x86_64
35
+ CallingConvention: SysV
36
+ Features: [AVX2]
37
+ rdi:
38
+ type: buffer
39
+ size_bytes: 512
40
+ permissions: read/write
41
+ c_parameter: int16_t *r
42
+ description: Input/output polynomial (256 x int16_t)
43
+ */
44
+
28
45
 
29
46
  /*
30
47
  * WARNING: This file is auto-derived from the mlkem-native source file
31
- * dev/x86_64/src/tomont_avx2_asm.S using scripts/simpasm. Do not modify it directly.
48
+ * dev/x86_64/src/mlkem_tomont_avx2_asm.S using scripts/simpasm. Do not modify it directly.
32
49
  */
33
50
 
34
51
  .text
@@ -148,7 +165,7 @@ MLK_ASM_FN_SYMBOL(tomont_avx2_asm)
148
165
  MLK_ASM_FN_SIZE(tomont_avx2_asm)
149
166
 
150
167
  #endif /* MLK_ARITH_BACKEND_X86_64_DEFAULT && !MLK_CONFIG_MULTILEVEL_NO_SHARED \
151
- */
168
+ && !MLK_CONFIG_NO_KEYPAIR_API */
152
169
 
153
170
  #if defined(__ELF__)
154
171
  .section .note.GNU-stack,"",%progbits
@@ -105,6 +105,7 @@ __contract__(
105
105
  return res;
106
106
  }
107
107
 
108
+ #if !defined(MLK_CONFIG_NO_KEYPAIR_API)
108
109
  /* Reference: `poly_tomont()` in the reference implementation @[REF]. */
109
110
  MLK_STATIC_TESTABLE void mlk_poly_tomont_c(mlk_poly *r)
110
111
  __contract__(
@@ -142,6 +143,7 @@ void mlk_poly_tomont(mlk_poly *r)
142
143
 
143
144
  mlk_poly_tomont_c(r);
144
145
  }
146
+ #endif /* !MLK_CONFIG_NO_KEYPAIR_API */
145
147
 
146
148
  /**
147
149
  * Constant-time conversion of signed representatives modulo MLKEM_Q within
@@ -241,6 +243,7 @@ void mlk_poly_add(mlk_poly *r, const mlk_poly *b)
241
243
  }
242
244
  }
243
245
 
246
+ #if !defined(MLK_CONFIG_NO_DECAPS_API)
244
247
  /* Reference: `poly_sub()` in the reference implementation @[REF].
245
248
  * - We use destructive version (output=first input) to avoid
246
249
  * reasoning about aliasing in the CBMC specification */
@@ -259,6 +262,7 @@ void mlk_poly_sub(mlk_poly *r, const mlk_poly *b)
259
262
  r->coeffs[i] = (int16_t)(r->coeffs[i] - b->coeffs[i]);
260
263
  }
261
264
  }
265
+ #endif /* !MLK_CONFIG_NO_DECAPS_API */
262
266
 
263
267
  #include "zetas.inc"
264
268
 
@@ -470,6 +474,7 @@ void mlk_poly_ntt(mlk_poly *r)
470
474
  }
471
475
 
472
476
 
477
+ #if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)
473
478
  /* Compute one layer of inverse NTT */
474
479
 
475
480
  /* Reference: Embedded into `invntt()` in the reference implementation @[REF] */
@@ -568,8 +573,8 @@ void mlk_poly_invntt_tomont(mlk_poly *r)
568
573
 
569
574
  mlk_poly_invntt_tomont_c(r);
570
575
  }
571
-
572
- #else /* !MLK_CONFIG_MULTILEVEL_NO_SHARED */
576
+ #endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */
577
+ #else /* !MLK_CONFIG_MULTILEVEL_NO_SHARED */
573
578
 
574
579
  MLK_EMPTY_CU(mlk_poly)
575
580
 
@@ -99,6 +99,7 @@ __contract__(
99
99
  return (int16_t)r;
100
100
  }
101
101
 
102
+ #if !defined(MLK_CONFIG_NO_KEYPAIR_API)
102
103
  #define mlk_poly_tomont MLK_NAMESPACE(poly_tomont)
103
104
  /**
104
105
  * In-place conversion of all coefficients of a polynomial from the normal
@@ -119,6 +120,7 @@ __contract__(
119
120
  assigns(memory_slice(r, sizeof(mlk_poly)))
120
121
  ensures(array_abs_bound(r->coeffs, 0, MLKEM_N, MLKEM_Q))
121
122
  );
123
+ #endif /* !MLK_CONFIG_NO_KEYPAIR_API */
122
124
 
123
125
  #define mlk_poly_mulcache_compute MLK_NAMESPACE(poly_mulcache_compute)
124
126
  /**
@@ -207,6 +209,7 @@ __contract__(
207
209
  assigns(memory_slice(r, sizeof(mlk_poly)))
208
210
  );
209
211
 
212
+ #if !defined(MLK_CONFIG_NO_DECAPS_API)
210
213
  #define mlk_poly_sub MLK_NAMESPACE(poly_sub)
211
214
  /**
212
215
  * Subtract two polynomials; no modular reduction is performed.
@@ -231,6 +234,7 @@ __contract__(
231
234
  ensures(forall(k, 0, MLKEM_N, r->coeffs[k] == old(*r).coeffs[k] - b->coeffs[k]))
232
235
  assigns(memory_slice(r, sizeof(mlk_poly)))
233
236
  );
237
+ #endif /* !MLK_CONFIG_NO_DECAPS_API */
234
238
 
235
239
  #define mlk_poly_ntt MLK_NAMESPACE(poly_ntt)
236
240
  /**
@@ -260,6 +264,7 @@ __contract__(
260
264
  ensures(array_abs_bound(r->coeffs, 0, MLKEM_N, MLK_NTT_BOUND))
261
265
  );
262
266
 
267
+ #if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)
263
268
  #define mlk_poly_invntt_tomont MLK_NAMESPACE(poly_invntt_tomont)
264
269
  /**
265
270
  * Compute the inverse negacyclic number-theoretic transform (NTT) of a
@@ -286,5 +291,6 @@ __contract__(
286
291
  assigns(memory_slice(r, sizeof(mlk_poly)))
287
292
  ensures(array_abs_bound(r->coeffs, 0, MLKEM_N, MLK_INVNTT_BOUND))
288
293
  );
294
+ #endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */
289
295
 
290
296
  #endif /* !MLK_POLY_H */
@@ -39,6 +39,7 @@
39
39
  MLK_ADD_PARAM_SET(mlk_polyvec_basemul_acc_montgomery_cached_c)
40
40
  /* End of parameter set namespacing */
41
41
 
42
+ #if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)
42
43
  /* Reference: `polyvec_compress()` in the reference implementation @[REF]
43
44
  * - In contrast to the reference implementation, we assume
44
45
  * unsigned canonical coefficients here.
@@ -56,7 +57,9 @@ void mlk_polyvec_compress_du(uint8_t r[MLKEM_POLYVECCOMPRESSEDBYTES_DU],
56
57
  mlk_poly_compress_du(r + i * MLKEM_POLYCOMPRESSEDBYTES_DU, &a->vec[i]);
57
58
  }
58
59
  }
60
+ #endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */
59
61
 
62
+ #if !defined(MLK_CONFIG_NO_DECAPS_API)
60
63
  /* Reference: `polyvec_decompress()` in the reference implementation @[REF]. */
61
64
  MLK_INTERNAL_API
62
65
  void mlk_polyvec_decompress_du(mlk_polyvec *r,
@@ -70,7 +73,9 @@ void mlk_polyvec_decompress_du(mlk_polyvec *r,
70
73
 
71
74
  mlk_assert_bound_2d(r->vec, MLKEM_K, MLKEM_N, 0, MLKEM_Q);
72
75
  }
76
+ #endif /* !MLK_CONFIG_NO_DECAPS_API */
73
77
 
78
+ #if !defined(MLK_CONFIG_NO_KEYPAIR_API) || !defined(MLK_CONFIG_NO_ENCAPS_API)
74
79
  /* Reference: `polyvec_tobytes()` in the reference implementation @[REF].
75
80
  * - In contrast to the reference implementation, we assume
76
81
  * unsigned canonical coefficients here.
@@ -92,7 +97,9 @@ void mlk_polyvec_tobytes(uint8_t r[MLKEM_POLYVECBYTES], const mlk_polyvec *a)
92
97
  mlk_poly_tobytes(&r[i * MLKEM_POLYBYTES], &a->vec[i]);
93
98
  }
94
99
  }
100
+ #endif /* !MLK_CONFIG_NO_KEYPAIR_API || !MLK_CONFIG_NO_ENCAPS_API */
95
101
 
102
+ #if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)
96
103
  /* Reference: `polyvec_frombytes()` in the reference implementation @[REF]. */
97
104
  MLK_INTERNAL_API
98
105
  void mlk_polyvec_frombytes(mlk_polyvec *r, const uint8_t a[MLKEM_POLYVECBYTES])
@@ -105,6 +112,7 @@ void mlk_polyvec_frombytes(mlk_polyvec *r, const uint8_t a[MLKEM_POLYVECBYTES])
105
112
 
106
113
  mlk_assert_bound_2d(r->vec, MLKEM_K, MLKEM_N, 0, MLKEM_UINT12_LIMIT);
107
114
  }
115
+ #endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */
108
116
 
109
117
  /* Reference: `polyvec_ntt()` in the reference implementation @[REF]. */
110
118
  MLK_INTERNAL_API
@@ -124,6 +132,7 @@ void mlk_polyvec_ntt(mlk_polyvec *r)
124
132
  * while the reference implementation normalizes at
125
133
  * the end. This allows us to drop a call to `poly_reduce()`
126
134
  * from the base multiplication. */
135
+ #if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)
127
136
  MLK_INTERNAL_API
128
137
  void mlk_polyvec_invntt_tomont(mlk_polyvec *r)
129
138
  {
@@ -135,6 +144,7 @@ void mlk_polyvec_invntt_tomont(mlk_polyvec *r)
135
144
 
136
145
  mlk_assert_abs_bound_2d(r->vec, MLKEM_K, MLKEM_N, MLK_INVNTT_BOUND);
137
146
  }
147
+ #endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */
138
148
 
139
149
  /* Reference: `polyvec_basemul_acc_montgomery()` in the
140
150
  * reference implementation @[REF].
@@ -279,6 +289,7 @@ void mlk_polyvec_add(mlk_polyvec *r, const mlk_polyvec *b)
279
289
  }
280
290
  }
281
291
 
292
+ #if !defined(MLK_CONFIG_NO_KEYPAIR_API)
282
293
  /* Reference: `polyvec_tomont()` in the reference implementation @[REF]. */
283
294
  MLK_INTERNAL_API
284
295
  void mlk_polyvec_tomont(mlk_polyvec *r)
@@ -291,6 +302,7 @@ void mlk_polyvec_tomont(mlk_polyvec *r)
291
302
 
292
303
  mlk_assert_abs_bound_2d(r->vec, MLKEM_K, MLKEM_N, MLKEM_Q);
293
304
  }
305
+ #endif /* !MLK_CONFIG_NO_KEYPAIR_API */
294
306
 
295
307
 
296
308
  /**
@@ -325,6 +337,9 @@ __contract__(
325
337
  #endif
326
338
  }
327
339
 
340
+ #if !defined(MLK_CONFIG_NO_KEYPAIR_API) || \
341
+ (MLKEM_ETA1 == MLKEM_ETA2 && (!defined(MLK_CONFIG_NO_ENCAPS_API) || \
342
+ !defined(MLK_CONFIG_NO_DECAPS_API)))
328
343
  /* Reference: Does not exist in the reference implementation @[REF].
329
344
  * - This implements a x4-batched version of `poly_getnoise_eta1()`
330
345
  * from the reference implementation, to leverage
@@ -378,8 +393,11 @@ void mlk_poly_getnoise_eta1_4x(mlk_poly *r0, mlk_poly *r1, mlk_poly *r2,
378
393
  mlk_zeroize(buf, sizeof(buf));
379
394
  mlk_zeroize(extkey, sizeof(extkey));
380
395
  }
396
+ #endif /* !MLK_CONFIG_NO_KEYPAIR_API || (MLKEM_ETA1 == MLKEM_ETA2 && \
397
+ (!MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API)) */
381
398
 
382
- #if MLKEM_K == 2 || MLKEM_K == 4
399
+ #if (MLKEM_K == 2 || MLKEM_K == 4) && \
400
+ (!defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API))
383
401
  /**
384
402
  * Given an array of uniformly random bytes, compute a polynomial with
385
403
  * coefficients distributed according to a centered binomial distribution
@@ -431,9 +449,11 @@ void mlk_poly_getnoise_eta2(mlk_poly *r, const uint8_t seed[MLKEM_SYMBYTES],
431
449
  mlk_zeroize(buf, sizeof(buf));
432
450
  mlk_zeroize(extkey, sizeof(extkey));
433
451
  }
434
- #endif /* MLKEM_K == 2 || MLKEM_K == 4 */
452
+ #endif /* (MLKEM_K == 2 || MLKEM_K == 4) && (!MLK_CONFIG_NO_ENCAPS_API || \
453
+ !MLK_CONFIG_NO_DECAPS_API) */
435
454
 
436
- #if MLKEM_K == 2
455
+ #if MLKEM_K == 2 && \
456
+ (!defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API))
437
457
  /* Reference: Does not exist in the reference implementation @[REF].
438
458
  * - This implements a x4-batched version of `poly_getnoise_eta1()`
439
459
  * and `poly_getnoise_eta2()` from the reference implementation,
@@ -492,7 +512,8 @@ void mlk_poly_getnoise_eta1122_4x(mlk_poly *r0, mlk_poly *r1, mlk_poly *r2,
492
512
  mlk_zeroize(buf, sizeof(buf));
493
513
  mlk_zeroize(extkey, sizeof(extkey));
494
514
  }
495
- #endif /* MLKEM_K == 2 */
515
+ #endif /* MLKEM_K == 2 && (!MLK_CONFIG_NO_ENCAPS_API || \
516
+ !MLK_CONFIG_NO_DECAPS_API) */
496
517
 
497
518
  /* To facilitate single-compilation-unit (SCU) builds, undefine all macros.
498
519
  * Don't modify by hand -- this is auto-generated by scripts/autogen. */
@@ -46,6 +46,7 @@ typedef struct
46
46
  mlk_poly_mulcache vec[MLKEM_K]; /**< Per-component caches. */
47
47
  } MLK_ALIGN mlk_polyvec_mulcache;
48
48
 
49
+ #if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)
49
50
  #define mlk_poly_compress_du MLK_NAMESPACE_K(poly_compress_du)
50
51
  /**
51
52
  * Compression (du bits) and subsequent serialization of a polynomial.
@@ -75,7 +76,9 @@ __contract__(
75
76
  #error "Invalid value of MLKEM_DU"
76
77
  #endif
77
78
  }
79
+ #endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */
78
80
 
81
+ #if !defined(MLK_CONFIG_NO_DECAPS_API)
79
82
  #define mlk_poly_decompress_du MLK_NAMESPACE_K(poly_decompress_du)
80
83
  /**
81
84
  * De-serialization and subsequent decompression (du bits) of a polynomial;
@@ -108,7 +111,9 @@ __contract__(
108
111
  #error "Invalid value of MLKEM_DU"
109
112
  #endif
110
113
  }
114
+ #endif /* !MLK_CONFIG_NO_DECAPS_API */
111
115
 
116
+ #if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)
112
117
  #define mlk_poly_compress_dv MLK_NAMESPACE_K(poly_compress_dv)
113
118
  /**
114
119
  * Compression (dv bits) and subsequent serialization of a polynomial.
@@ -138,8 +143,10 @@ __contract__(
138
143
  #error "Invalid value of MLKEM_DV"
139
144
  #endif
140
145
  }
146
+ #endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */
141
147
 
142
148
 
149
+ #if !defined(MLK_CONFIG_NO_DECAPS_API)
143
150
  #define mlk_poly_decompress_dv MLK_NAMESPACE_K(poly_decompress_dv)
144
151
  /**
145
152
  * De-serialization and subsequent decompression (dv bits) of a polynomial;
@@ -172,7 +179,9 @@ __contract__(
172
179
  #error "Invalid value of MLKEM_DV"
173
180
  #endif
174
181
  }
182
+ #endif /* !MLK_CONFIG_NO_DECAPS_API */
175
183
 
184
+ #if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)
176
185
  #define mlk_polyvec_compress_du MLK_NAMESPACE_K(polyvec_compress_du)
177
186
  /**
178
187
  * Compress and serialize a vector of polynomials.
@@ -196,7 +205,9 @@ __contract__(
196
205
  array_bound(a->vec[k0].coeffs, 0, MLKEM_N, 0, MLKEM_Q)))
197
206
  assigns(memory_slice(r, MLKEM_POLYVECCOMPRESSEDBYTES_DU))
198
207
  );
208
+ #endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */
199
209
 
210
+ #if !defined(MLK_CONFIG_NO_DECAPS_API)
200
211
  #define mlk_polyvec_decompress_du MLK_NAMESPACE_K(polyvec_decompress_du)
201
212
  /**
202
213
  * De-serialize and decompress a vector of polynomials; approximate inverse
@@ -221,7 +232,9 @@ __contract__(
221
232
  ensures(forall(k0, 0, MLKEM_K,
222
233
  array_bound(r->vec[k0].coeffs, 0, MLKEM_N, 0, MLKEM_Q)))
223
234
  );
235
+ #endif /* !MLK_CONFIG_NO_DECAPS_API */
224
236
 
237
+ #if !defined(MLK_CONFIG_NO_KEYPAIR_API) || !defined(MLK_CONFIG_NO_ENCAPS_API)
225
238
  #define mlk_polyvec_tobytes MLK_NAMESPACE_K(polyvec_tobytes)
226
239
  /**
227
240
  * Serialize a vector of polynomials.
@@ -243,7 +256,9 @@ __contract__(
243
256
  array_bound(a->vec[k0].coeffs, 0, MLKEM_N, 0, MLKEM_Q)))
244
257
  assigns(memory_slice(r, MLKEM_POLYVECBYTES))
245
258
  );
259
+ #endif /* !MLK_CONFIG_NO_KEYPAIR_API || !MLK_CONFIG_NO_ENCAPS_API */
246
260
 
261
+ #if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)
247
262
  #define mlk_polyvec_frombytes MLK_NAMESPACE_K(polyvec_frombytes)
248
263
  /**
249
264
  * De-serialize a vector of polynomials; inverse of mlk_polyvec_tobytes.
@@ -265,6 +280,7 @@ __contract__(
265
280
  ensures(forall(k0, 0, MLKEM_K,
266
281
  array_bound(r->vec[k0].coeffs, 0, MLKEM_N, 0, MLKEM_UINT12_LIMIT)))
267
282
  );
283
+ #endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */
268
284
 
269
285
  #define mlk_polyvec_ntt MLK_NAMESPACE_K(polyvec_ntt)
270
286
  /**
@@ -292,6 +308,7 @@ __contract__(
292
308
  array_abs_bound(r->vec[j].coeffs, 0, MLKEM_N, MLK_NTT_BOUND)))
293
309
  );
294
310
 
311
+ #if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)
295
312
  #define mlk_polyvec_invntt_tomont MLK_NAMESPACE_K(polyvec_invntt_tomont)
296
313
  /**
297
314
  * Apply inverse NTT to all elements of a vector of polynomials and multiply
@@ -316,6 +333,7 @@ __contract__(
316
333
  ensures(forall(j, 0, MLKEM_K,
317
334
  array_abs_bound(r->vec[j].coeffs, 0, MLKEM_N, MLK_INVNTT_BOUND)))
318
335
  );
336
+ #endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */
319
337
 
320
338
  #define mlk_polyvec_basemul_acc_montgomery_cached \
321
339
  MLK_NAMESPACE_K(polyvec_basemul_acc_montgomery_cached)
@@ -442,6 +460,7 @@ __contract__(
442
460
  assigns(memory_slice(r, sizeof(mlk_polyvec)))
443
461
  );
444
462
 
463
+ #if !defined(MLK_CONFIG_NO_KEYPAIR_API)
445
464
  #define mlk_polyvec_tomont MLK_NAMESPACE_K(polyvec_tomont)
446
465
  /**
447
466
  * In-place conversion of all coefficients of a polynomial vector from the
@@ -463,7 +482,11 @@ __contract__(
463
482
  ensures(forall(j, 0, MLKEM_K,
464
483
  array_abs_bound(r->vec[j].coeffs, 0, MLKEM_N, MLKEM_Q)))
465
484
  );
485
+ #endif /* !MLK_CONFIG_NO_KEYPAIR_API */
466
486
 
487
+ #if !defined(MLK_CONFIG_NO_KEYPAIR_API) || \
488
+ (MLKEM_ETA1 == MLKEM_ETA2 && (!defined(MLK_CONFIG_NO_ENCAPS_API) || \
489
+ !defined(MLK_CONFIG_NO_DECAPS_API)))
467
490
  #define mlk_poly_getnoise_eta1_4x MLK_NAMESPACE_K(poly_getnoise_eta1_4x)
468
491
  /**
469
492
  * Batch sample four polynomials deterministically from a seed and nonces,
@@ -515,8 +538,11 @@ __contract__(
515
538
  */
516
539
  #define mlk_poly_getnoise_eta2_4x mlk_poly_getnoise_eta1_4x
517
540
  #endif /* MLKEM_ETA1 == MLKEM_ETA2 */
541
+ #endif /* !MLK_CONFIG_NO_KEYPAIR_API || (MLKEM_ETA1 == MLKEM_ETA2 && \
542
+ (!MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API)) */
518
543
 
519
- #if MLKEM_K == 2 || MLKEM_K == 4
544
+ #if (MLKEM_K == 2 || MLKEM_K == 4) && \
545
+ (!defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API))
520
546
  #define mlk_poly_getnoise_eta2 MLK_NAMESPACE_K(poly_getnoise_eta2)
521
547
  /**
522
548
  * Sample a polynomial deterministically from a seed and a nonce, with
@@ -541,9 +567,11 @@ __contract__(
541
567
  assigns(memory_slice(r, sizeof(mlk_poly)))
542
568
  ensures(array_abs_bound(r->coeffs, 0, MLKEM_N, MLKEM_ETA2 + 1))
543
569
  );
544
- #endif /* MLKEM_K == 2 || MLKEM_K == 4 */
570
+ #endif /* (MLKEM_K == 2 || MLKEM_K == 4) && (!MLK_CONFIG_NO_ENCAPS_API || \
571
+ !MLK_CONFIG_NO_DECAPS_API) */
545
572
 
546
- #if MLKEM_K == 2
573
+ #if MLKEM_K == 2 && \
574
+ (!defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API))
547
575
  #define mlk_poly_getnoise_eta1122_4x MLK_NAMESPACE_K(poly_getnoise_eta1122_4x)
548
576
  /**
549
577
  * Batch sample four polynomials deterministically from a seed and nonces,
@@ -588,6 +616,7 @@ __contract__(
588
616
  && array_abs_bound(r2->coeffs,0, MLKEM_N, MLKEM_ETA2 + 1)
589
617
  && array_abs_bound(r3->coeffs,0, MLKEM_N, MLKEM_ETA2 + 1))
590
618
  );
591
- #endif /* MLKEM_K == 2 */
619
+ #endif /* MLKEM_K == 2 && (!MLK_CONFIG_NO_ENCAPS_API || \
620
+ !MLK_CONFIG_NO_DECAPS_API) */
592
621
 
593
622
  #endif /* !MLK_POLY_K_H */
@@ -251,6 +251,8 @@ void mlk_poly_rej_uniform(mlk_poly *entry, uint8_t seed[MLKEM_SYMBYTES + 2])
251
251
  mlk_zeroize(buf, sizeof(buf));
252
252
  }
253
253
 
254
+ #if defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_ETA1 == 2 || \
255
+ !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)
254
256
  /**
255
257
  * Load 4 bytes into a 32-bit integer in little-endian order.
256
258
  *
@@ -300,6 +302,8 @@ void mlk_poly_cbd2(mlk_poly *r, const uint8_t buf[2 * MLKEM_N / 4])
300
302
  }
301
303
  }
302
304
  }
305
+ #endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_ETA1 == 2 || \
306
+ !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */
303
307
 
304
308
  #if defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_ETA1 == 3
305
309
  /**
@@ -19,6 +19,8 @@
19
19
  #include "common.h"
20
20
  #include "poly.h"
21
21
 
22
+ #if defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_ETA1 == 2 || \
23
+ !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)
22
24
  #define mlk_poly_cbd2 MLK_NAMESPACE(poly_cbd2)
23
25
  /**
24
26
  * Given an array of uniformly random bytes, compute a polynomial with
@@ -32,6 +34,8 @@
32
34
  */
33
35
  MLK_INTERNAL_API
34
36
  void mlk_poly_cbd2(mlk_poly *r, const uint8_t buf[2 * MLKEM_N / 4]);
37
+ #endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_ETA1 == 2 || \
38
+ !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */
35
39
 
36
40
  #if defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_ETA1 == 3
37
41
  #define mlk_poly_cbd3 MLK_NAMESPACE(poly_cbd3)