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
@@ -61,7 +61,7 @@
61
61
 
62
62
  /*
63
63
  * WARNING: This file is auto-derived from the mlkem-native source file
64
- * dev/fips202/armv81m/src/state_xor_bytes_x4_mve.S using scripts/simpasm. Do not modify it directly.
64
+ * dev/fips202/armv81m/src/keccak_f1600_x4_state_xor_bytes_mve.S using scripts/simpasm. Do not modify it directly.
65
65
  */
66
66
 
67
67
  .thumb
@@ -98,13 +98,13 @@ MLK_ASM_FN_SYMBOL(keccak_f1600_x4_state_xor_bytes_asm)
98
98
  ldr.w r10, [sp, #0x6c]
99
99
  ldr r6, [sp, #0x70]
100
100
  cmp r6, #0x0
101
- beq.w Lkeccak_f1600_x4_state_xor_bytes_asm_exit @ imm = #0x346
101
+ beq.w Lmlk_keccak_f1600_x4_state_xor_bytes_asm_exit @ imm = #0x346
102
102
  and r5, r10, #0x7
103
103
  bic r9, r10, #0x7
104
104
  add.w r8, r0, r9, lsl #1
105
105
  add.w r7, r8, #0x190
106
106
  cmp r5, #0x0
107
- beq.w Lkeccak_f1600_x4_state_xor_bytes_asm_pre_main @ imm = #0x12c
107
+ beq.w Lmlk_keccak_f1600_x4_state_xor_bytes_asm_pre_main @ imm = #0x12c
108
108
  subs r1, r1, r5
109
109
  subs r2, r2, r5
110
110
  subs r3, r3, r5
@@ -183,19 +183,19 @@ MLK_ASM_FN_SYMBOL(keccak_f1600_x4_state_xor_bytes_asm)
183
183
  vstrw.32 q5, [r7], #16
184
184
  vmov q7[2], q7[0], r1, r3
185
185
  vmov q7[3], q7[1], r2, r4
186
- b Lkeccak_f1600_x4_state_xor_bytes_asm_main_body @ imm = #0xe
186
+ b Lmlk_keccak_f1600_x4_state_xor_bytes_asm_main_body @ imm = #0xe
187
187
 
188
- Lkeccak_f1600_x4_state_xor_bytes_asm_pre_main:
188
+ Lmlk_keccak_f1600_x4_state_xor_bytes_asm_pre_main:
189
189
  vmov q7[2], q7[0], r1, r3
190
190
  vmov q7[3], q7[1], r2, r4
191
191
  mov.w r0, #0x4
192
192
  vsub.i32 q7, q7, r0
193
193
 
194
- Lkeccak_f1600_x4_state_xor_bytes_asm_main_body:
194
+ Lmlk_keccak_f1600_x4_state_xor_bytes_asm_main_body:
195
195
  lsr.w lr, r6, #0x3
196
- wls lr, lr, Lkeccak_f1600_x4_state_xor_bytes_asm_main_loop_end @ imm = #0xd4
196
+ wls lr, lr, Lmlk_keccak_f1600_x4_state_xor_bytes_asm_main_loop_end @ imm = #0xd4
197
197
 
198
- Lkeccak_f1600_x4_state_xor_bytes_asm_main_loop_start:
198
+ Lmlk_keccak_f1600_x4_state_xor_bytes_asm_main_loop_start:
199
199
  vldrw.u32 q0, [q7, #4]!
200
200
  vldrw.u32 q1, [q7, #4]!
201
201
  vmov q2, q0
@@ -248,11 +248,11 @@ Lkeccak_f1600_x4_state_xor_bytes_asm_main_loop_start:
248
248
  veor q5, q5, q1
249
249
  vstrw.32 q4, [r8], #16
250
250
  vstrw.32 q5, [r7], #16
251
- le lr, Lkeccak_f1600_x4_state_xor_bytes_asm_main_loop_start @ imm = #-0xd4
251
+ le lr, Lmlk_keccak_f1600_x4_state_xor_bytes_asm_main_loop_start @ imm = #-0xd4
252
252
 
253
- Lkeccak_f1600_x4_state_xor_bytes_asm_main_loop_end:
253
+ Lmlk_keccak_f1600_x4_state_xor_bytes_asm_main_loop_end:
254
254
  ands r6, r6, #0x7
255
- beq.w Lkeccak_f1600_x4_state_xor_bytes_asm_exit @ imm = #0x110
255
+ beq.w Lmlk_keccak_f1600_x4_state_xor_bytes_asm_exit @ imm = #0x110
256
256
  mov.w r0, #0x4
257
257
  vadd.i32 q7, q7, r0
258
258
  vmov r1, r3, q7[2], q7[0]
@@ -322,7 +322,7 @@ Lkeccak_f1600_x4_state_xor_bytes_asm_main_loop_end:
322
322
  vstrw.32 q4, [r8], #16
323
323
  vstrw.32 q5, [r7], #16
324
324
 
325
- Lkeccak_f1600_x4_state_xor_bytes_asm_exit:
325
+ Lmlk_keccak_f1600_x4_state_xor_bytes_asm_exit:
326
326
  vpop {d8, d9, d10, d11, d12, d13, d14, d15}
327
327
  .cfi_restore d8
328
328
  .cfi_restore d9
@@ -11,7 +11,7 @@
11
11
  #define MLK_FIPS202_X86_64_NEED_X4_AVX2
12
12
 
13
13
  /* Part of backend API */
14
- #define MLK_USE_FIPS202_X4_NATIVE
14
+ #define MLK_USE_NATIVE_FIPS202_X4
15
15
 
16
16
  #if !defined(__ASSEMBLER__)
17
17
  #include "../api.h"
@@ -19,7 +19,7 @@
19
19
  MLK_MUST_CHECK_RETURN_VALUE
20
20
  static MLK_INLINE int mlk_keccak_f1600_x4_native(uint64_t *state)
21
21
  {
22
- if (!mlk_sys_check_capability(MLK_SYS_CAP_AVX2))
22
+ if (!mlk_sys_check_capability(MLK_SYS_CAP_X86_64_AVX2))
23
23
  {
24
24
  return MLK_NATIVE_FUNC_FALLBACK;
25
25
  }
@@ -6,6 +6,40 @@
6
6
 
7
7
  #if defined(MLK_FIPS202_X86_64_NEED_X4_AVX2) && \
8
8
  !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED)
9
+ /*yaml
10
+ Name: keccak_f1600_x4_avx2_asm
11
+ Description: x86_64 AVX2 Keccak-f[1600] permutation for four sequential states
12
+ Signature: void mlk_keccak_f1600_x4_avx2_asm(uint64_t states[100], const uint64_t rc[24], const uint64_t rho8[4], const uint64_t rho56[4])
13
+ ABI:
14
+ Architecture: x86_64
15
+ CallingConvention: SysV
16
+ Features: [AVX2]
17
+ rdi:
18
+ type: buffer
19
+ size_bytes: 800
20
+ permissions: read/write
21
+ c_parameter: uint64_t states[100]
22
+ description: Four sequential Keccak states (4 x 25 x uint64_t)
23
+ rsi:
24
+ type: buffer
25
+ size_bytes: 192
26
+ permissions: read-only
27
+ c_parameter: const uint64_t rc[24]
28
+ description: Round constants (24 x uint64_t)
29
+ rdx:
30
+ type: buffer
31
+ size_bytes: 32
32
+ permissions: read-only
33
+ c_parameter: const uint64_t rho8[4]
34
+ description: Rotation constant rho8 (4 x uint64_t)
35
+ rcx:
36
+ type: buffer
37
+ size_bytes: 32
38
+ permissions: read-only
39
+ c_parameter: const uint64_t rho56[4]
40
+ description: Rotation constant rho56 (4 x uint64_t)
41
+ */
42
+
9
43
 
10
44
  /*
11
45
  * WARNING: This file is auto-derived from the mlkem-native source file
@@ -119,7 +153,7 @@ MLK_ASM_FN_SYMBOL(keccak_f1600_x4_avx2_asm)
119
153
  vinserti128 $0x1, %xmm0, %ymm1, %ymm2
120
154
  movq $0x0, %r10
121
155
 
122
- LLkeccak_f1600_x4_avx2:
156
+ LLmlk_keccak_f1600_x4_avx2:
123
157
  vmovdqu 0xa0(%rsp), %ymm4
124
158
  vpxor 0x1c0(%rsp), %ymm9, %ymm0
125
159
  vmovdqu %ymm9, 0x200(%rsp)
@@ -343,7 +377,7 @@ LLkeccak_f1600_x4_avx2:
343
377
  addq $0x8, %rsi
344
378
  addq $0x1, %r10
345
379
  cmpq $0x18, %r10
346
- jne LLkeccak_f1600_x4_avx2
380
+ jne LLmlk_keccak_f1600_x4_avx2
347
381
  vmovdqu (%rsp), %ymm4
348
382
  vmovdqu 0x40(%rsp), %ymm5
349
383
  vmovdqu 0x20(%rsp), %ymm0
@@ -55,6 +55,7 @@
55
55
  * [0,..,MLKEM_Q-1].
56
56
  * @param[in] seed Input public seed.
57
57
  */
58
+ #if !defined(MLK_CONFIG_NO_KEYPAIR_API)
58
59
  static void mlk_pack_pk(uint8_t r[MLKEM_INDCPA_PUBLICKEYBYTES],
59
60
  const mlk_polyvec *pk,
60
61
  const uint8_t seed[MLKEM_SYMBYTES])
@@ -63,6 +64,7 @@ static void mlk_pack_pk(uint8_t r[MLKEM_INDCPA_PUBLICKEYBYTES],
63
64
  mlk_polyvec_tobytes(r, pk);
64
65
  mlk_memcpy(r + MLKEM_POLYVECBYTES, seed, MLKEM_SYMBYTES);
65
66
  }
67
+ #endif /* !MLK_CONFIG_NO_KEYPAIR_API */
66
68
 
67
69
  /**
68
70
  * De-serialize public key from a byte array; approximate inverse of
@@ -75,6 +77,7 @@ static void mlk_pack_pk(uint8_t r[MLKEM_INDCPA_PUBLICKEYBYTES],
75
77
  * @param[out] seed Output seed to generate matrix A.
76
78
  * @param[in] packedpk Input serialized public key.
77
79
  */
80
+ #if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)
78
81
  static void mlk_unpack_pk(mlk_polyvec *pk, uint8_t seed[MLKEM_SYMBYTES],
79
82
  const uint8_t packedpk[MLKEM_INDCPA_PUBLICKEYBYTES])
80
83
  {
@@ -86,6 +89,7 @@ static void mlk_unpack_pk(mlk_polyvec *pk, uint8_t seed[MLKEM_SYMBYTES],
86
89
  * specifications and proofs, however, do _not_ assume this, and instead
87
90
  * work with the easily provable bound by MLKEM_UINT12_LIMIT. */
88
91
  }
92
+ #endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */
89
93
 
90
94
  /**
91
95
  * Serialize the secret key.
@@ -95,12 +99,14 @@ static void mlk_unpack_pk(mlk_polyvec *pk, uint8_t seed[MLKEM_SYMBYTES],
95
99
  * @param[out] r Output serialized secret key.
96
100
  * @param[in] sk Input vector of polynomials (secret key).
97
101
  */
102
+ #if !defined(MLK_CONFIG_NO_KEYPAIR_API)
98
103
  static void mlk_pack_sk(uint8_t r[MLKEM_INDCPA_SECRETKEYBYTES],
99
104
  const mlk_polyvec *sk)
100
105
  {
101
106
  mlk_assert_bound_2d(sk->vec, MLKEM_K, MLKEM_N, 0, MLKEM_Q);
102
107
  mlk_polyvec_tobytes(r, sk);
103
108
  }
109
+ #endif /* !MLK_CONFIG_NO_KEYPAIR_API */
104
110
 
105
111
  /**
106
112
  * De-serialize the secret key; inverse of mlk_pack_sk.
@@ -110,11 +116,13 @@ static void mlk_pack_sk(uint8_t r[MLKEM_INDCPA_SECRETKEYBYTES],
110
116
  * @param[out] sk Output vector of polynomials (secret key).
111
117
  * @param[in] packedsk Input serialized secret key.
112
118
  */
119
+ #if !defined(MLK_CONFIG_NO_DECAPS_API)
113
120
  static void mlk_unpack_sk(mlk_polyvec *sk,
114
121
  const uint8_t packedsk[MLKEM_INDCPA_SECRETKEYBYTES])
115
122
  {
116
123
  mlk_polyvec_frombytes(sk, packedsk);
117
124
  }
125
+ #endif /* !MLK_CONFIG_NO_DECAPS_API */
118
126
 
119
127
  /**
120
128
  * Serialize the ciphertext as the concatenation of the compressed and
@@ -127,12 +135,14 @@ static void mlk_unpack_sk(mlk_polyvec *sk,
127
135
  * @param[in] b Input vector of polynomials b.
128
136
  * @param[in] v Input polynomial v.
129
137
  */
138
+ #if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)
130
139
  static void mlk_pack_ciphertext(uint8_t r[MLKEM_INDCPA_BYTES],
131
140
  const mlk_polyvec *b, mlk_poly *v)
132
141
  {
133
142
  mlk_polyvec_compress_du(r, b);
134
143
  mlk_poly_compress_dv(r + MLKEM_POLYVECCOMPRESSEDBYTES_DU, v);
135
144
  }
145
+ #endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */
136
146
 
137
147
  /**
138
148
  * De-serialize and decompress ciphertext from a byte array; approximate
@@ -144,12 +154,14 @@ static void mlk_pack_ciphertext(uint8_t r[MLKEM_INDCPA_BYTES],
144
154
  * @param[out] v Output polynomial v.
145
155
  * @param[in] c Input serialized ciphertext.
146
156
  */
157
+ #if !defined(MLK_CONFIG_NO_DECAPS_API)
147
158
  static void mlk_unpack_ciphertext(mlk_polyvec *b, mlk_poly *v,
148
159
  const uint8_t c[MLKEM_INDCPA_BYTES])
149
160
  {
150
161
  mlk_polyvec_decompress_du(b, c);
151
162
  mlk_poly_decompress_dv(v, c + MLKEM_POLYVECCOMPRESSEDBYTES_DU);
152
163
  }
164
+ #endif /* !MLK_CONFIG_NO_DECAPS_API */
153
165
 
154
166
  /* Helper function to ensure that the polynomial entries in the output
155
167
  * of gen_matrix use the standard (bitreversed) ordering of coefficients.
@@ -345,6 +357,7 @@ __contract__(
345
357
  * @param[out] e Output polynomial vector.
346
358
  * @param[in] seed Seed bytes for sampling.
347
359
  */
360
+ #if !defined(MLK_CONFIG_NO_KEYPAIR_API)
348
361
  static void mlk_keypair_getnoise_eta1(mlk_polyvec *pv, mlk_polyvec *e,
349
362
  const uint8_t seed[MLKEM_SYMBYTES])
350
363
  __contract__(
@@ -378,6 +391,7 @@ __contract__(
378
391
  seed, 4, 5, 6, 7);
379
392
  #endif /* MLKEM_K == 4 */
380
393
  }
394
+ #endif /* !MLK_CONFIG_NO_KEYPAIR_API */
381
395
 
382
396
  /**
383
397
  * Compute and fill the sp, ep, and epp polynomial structures needed by
@@ -391,6 +405,7 @@ __contract__(
391
405
  * @param[out] epp Output polynomial.
392
406
  * @param[in] coins Seed bytes for sampling.
393
407
  */
408
+ #if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)
394
409
  static void mlk_enc_getnoise_eta1_eta2(mlk_polyvec *sp, mlk_polyvec *ep,
395
410
  mlk_poly *epp,
396
411
  const uint8_t coins[MLKEM_SYMBYTES])
@@ -429,6 +444,7 @@ __contract__(
429
444
  mlk_poly_getnoise_eta2(epp, coins, 8);
430
445
  #endif /* MLKEM_K == 4 */
431
446
  }
447
+ #endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */
432
448
 
433
449
 
434
450
  /* Reference: `indcpa_keypair_derand()` in the reference implementation @[REF].
@@ -437,6 +453,7 @@ __contract__(
437
453
  * - We use a mulcache to speed up matrix-vector multiplication.
438
454
  * - We include buffer zeroization.
439
455
  */
456
+ #if !defined(MLK_CONFIG_NO_KEYPAIR_API)
440
457
  MLK_INTERNAL_API
441
458
  int mlk_indcpa_keypair_derand(uint8_t pk[MLKEM_INDCPA_PUBLICKEYBYTES],
442
459
  uint8_t sk[MLKEM_INDCPA_SECRETKEYBYTES],
@@ -508,6 +525,7 @@ cleanup:
508
525
  MLK_FREE(buf, uint8_t, 2 * MLKEM_SYMBYTES, context);
509
526
  return ret;
510
527
  }
528
+ #endif /* !MLK_CONFIG_NO_KEYPAIR_API */
511
529
 
512
530
  /* Reference: `indcpa_enc()` in the reference implementation @[REF].
513
531
  * - We use x4-batched versions of `poly_getnoise` to leverage
@@ -517,6 +535,7 @@ cleanup:
517
535
  * - We use a mulcache to speed up matrix-vector multiplication.
518
536
  * - We include buffer zeroization.
519
537
  */
538
+ #if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)
520
539
  MLK_INTERNAL_API
521
540
  int mlk_indcpa_enc(uint8_t c[MLKEM_INDCPA_BYTES],
522
541
  const uint8_t m[MLKEM_INDCPA_MSGBYTES],
@@ -591,10 +610,12 @@ cleanup:
591
610
  MLK_FREE(seed, uint8_t, MLKEM_SYMBYTES, context);
592
611
  return ret;
593
612
  }
613
+ #endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */
594
614
 
595
615
  /* Reference: `indcpa_dec()` in the reference implementation @[REF].
596
616
  * - We use a mulcache for the scalar product.
597
617
  * - We include buffer zeroization. */
618
+ #if !defined(MLK_CONFIG_NO_DECAPS_API)
598
619
  MLK_INTERNAL_API
599
620
  int mlk_indcpa_dec(uint8_t m[MLKEM_INDCPA_MSGBYTES],
600
621
  const uint8_t c[MLKEM_INDCPA_BYTES],
@@ -637,6 +658,7 @@ cleanup:
637
658
  MLK_FREE(b, mlk_polyvec, 1, context);
638
659
  return ret;
639
660
  }
661
+ #endif /* !MLK_CONFIG_NO_DECAPS_API */
640
662
 
641
663
  /* To facilitate single-compilation-unit (SCU) builds, undefine all macros.
642
664
  * Don't modify by hand -- this is auto-generated by scripts/autogen. */
@@ -45,6 +45,7 @@ __contract__(
45
45
  array_bound(a->vec[x].vec[y].coeffs, 0, MLKEM_N, 0, MLKEM_Q))))
46
46
  );
47
47
 
48
+ #if !defined(MLK_CONFIG_NO_KEYPAIR_API)
48
49
  #define mlk_indcpa_keypair_derand \
49
50
  MLK_NAMESPACE_K(indcpa_keypair_derand) MLK_CONTEXT_PARAMETERS_3
50
51
  /**
@@ -63,10 +64,8 @@ __contract__(
63
64
  * MLK_CONFIG_CONTEXT_PARAMETER_TYPE.
64
65
  *
65
66
  * @retval 0 Success.
66
- * @retval MLK_ERR_FAIL MLK_CONFIG_KEYGEN_PCT enabled and PCT failed.
67
67
  * @retval MLK_ERR_OUT_OF_MEMORY MLK_CONFIG_CUSTOM_ALLOC_FREE was used and
68
68
  * MLK_CUSTOM_ALLOC returned NULL.
69
- * @retval MLK_ERR_RNG_FAIL Random number generation failed.
70
69
  */
71
70
  MLK_INTERNAL_API
72
71
  MLK_MUST_CHECK_RETURN_VALUE
@@ -80,11 +79,16 @@ __contract__(
80
79
  requires(memory_no_alias(coins, MLKEM_SYMBYTES))
81
80
  assigns(memory_slice(pk, MLKEM_INDCPA_PUBLICKEYBYTES))
82
81
  assigns(memory_slice(sk, MLKEM_INDCPA_SECRETKEYBYTES))
83
- ensures(return_value == 0 || return_value == MLK_ERR_FAIL ||
84
- return_value == MLK_ERR_OUT_OF_MEMORY ||
85
- return_value == MLK_ERR_RNG_FAIL)
82
+ ensures(return_value == 0 || return_value == MLK_ERR_OUT_OF_MEMORY)
83
+ /* Output buffers on error, per API-CONVENTIONS.md */
84
+ ensures(return_value != 0 ==>
85
+ array_unchanged_or_zeroized_u8(pk, MLKEM_INDCPA_PUBLICKEYBYTES))
86
+ ensures(return_value != 0 ==>
87
+ array_unchanged_or_zeroized_u8(sk, MLKEM_INDCPA_SECRETKEYBYTES))
86
88
  );
89
+ #endif /* !MLK_CONFIG_NO_KEYPAIR_API */
87
90
 
91
+ #if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)
88
92
  #define mlk_indcpa_enc MLK_NAMESPACE_K(indcpa_enc) MLK_CONTEXT_PARAMETERS_4
89
93
  /**
90
94
  * Encryption function of the CPA-secure public-key encryption scheme
@@ -103,7 +107,6 @@ __contract__(
103
107
  * MLK_CONFIG_CONTEXT_PARAMETER_TYPE.
104
108
  *
105
109
  * @retval 0 Success.
106
- * @retval MLK_ERR_FAIL Operation failed.
107
110
  * @retval MLK_ERR_OUT_OF_MEMORY MLK_CONFIG_CUSTOM_ALLOC_FREE was used and
108
111
  * MLK_CUSTOM_ALLOC returned NULL.
109
112
  */
@@ -120,10 +123,14 @@ __contract__(
120
123
  requires(memory_no_alias(pk, MLKEM_INDCPA_PUBLICKEYBYTES))
121
124
  requires(memory_no_alias(coins, MLKEM_SYMBYTES))
122
125
  assigns(memory_slice(c, MLKEM_INDCPA_BYTES))
123
- ensures(return_value == 0 || return_value == MLK_ERR_FAIL ||
124
- return_value == MLK_ERR_OUT_OF_MEMORY)
126
+ ensures(return_value == 0 || return_value == MLK_ERR_OUT_OF_MEMORY)
127
+ /* Output buffers on error, per API-CONVENTIONS.md */
128
+ ensures(return_value != 0 ==>
129
+ array_unchanged_or_zeroized_u8(c, MLKEM_INDCPA_BYTES))
125
130
  );
131
+ #endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */
126
132
 
133
+ #if !defined(MLK_CONFIG_NO_DECAPS_API)
127
134
  #define mlk_indcpa_dec MLK_NAMESPACE_K(indcpa_dec) MLK_CONTEXT_PARAMETERS_3
128
135
  /**
129
136
  * Decryption function of the CPA-secure public-key encryption scheme
@@ -141,7 +148,6 @@ __contract__(
141
148
  * MLK_CONFIG_CONTEXT_PARAMETER_TYPE.
142
149
  *
143
150
  * @retval 0 Success.
144
- * @retval MLK_ERR_FAIL Operation failed.
145
151
  * @retval MLK_ERR_OUT_OF_MEMORY MLK_CONFIG_CUSTOM_ALLOC_FREE was used and
146
152
  * MLK_CUSTOM_ALLOC returned NULL.
147
153
  */
@@ -156,8 +162,11 @@ __contract__(
156
162
  requires(memory_no_alias(m, MLKEM_INDCPA_MSGBYTES))
157
163
  requires(memory_no_alias(sk, MLKEM_INDCPA_SECRETKEYBYTES))
158
164
  assigns(memory_slice(m, MLKEM_INDCPA_MSGBYTES))
159
- ensures(return_value == 0 || return_value == MLK_ERR_FAIL ||
160
- return_value == MLK_ERR_OUT_OF_MEMORY)
165
+ ensures(return_value == 0 || return_value == MLK_ERR_OUT_OF_MEMORY)
166
+ /* Output buffers on error, per API-CONVENTIONS.md */
167
+ ensures(return_value != 0 ==>
168
+ array_unchanged_or_zeroized_u8(m, MLKEM_INDCPA_MSGBYTES))
161
169
  );
170
+ #endif /* !MLK_CONFIG_NO_DECAPS_API */
162
171
 
163
172
  #endif /* !MLK_INDCPA_H */
@@ -37,6 +37,7 @@
37
37
  #define mlk_check_pct MLK_ADD_PARAM_SET(mlk_check_pct) MLK_CONTEXT_PARAMETERS_2
38
38
  /* End of parameter set namespacing */
39
39
 
40
+ #if !defined(MLK_CONFIG_NO_ENCAPS_API)
40
41
  /* Reference: Not implemented in the reference implementation @[REF]. */
41
42
  MLK_EXTERNAL_API
42
43
  MLK_MUST_CHECK_RETURN_VALUE
@@ -59,7 +60,8 @@ int mlk_kem_check_pk(const uint8_t pk[MLKEM_INDCCA_PUBLICKEYBYTES],
59
60
 
60
61
  /* We use a constant-time memcmp here to avoid having to
61
62
  * declassify the PK before the PCT has succeeded. */
62
- ret = mlk_ct_memcmp(pk, p_reencoded, MLKEM_POLYVECBYTES) ? MLK_ERR_FAIL : 0;
63
+ ret = mlk_ct_memcmp(pk, p_reencoded, MLKEM_POLYVECBYTES) ? MLK_ERR_INVALID_PK
64
+ : 0;
63
65
 
64
66
  cleanup:
65
67
  /* Specification: Partially implements
@@ -68,8 +70,10 @@ cleanup:
68
70
  MLK_FREE(p, mlk_polyvec, 1, context);
69
71
  return ret;
70
72
  }
73
+ #endif /* !MLK_CONFIG_NO_ENCAPS_API */
71
74
 
72
75
 
76
+ #if !defined(MLK_CONFIG_NO_DECAPS_API)
73
77
  /* Reference: Not implemented in the reference implementation @[REF]. */
74
78
  MLK_EXTERNAL_API
75
79
  MLK_MUST_CHECK_RETURN_VALUE
@@ -104,7 +108,7 @@ int mlk_kem_check_sk(const uint8_t sk[MLKEM_INDCCA_SECRETKEYBYTES],
104
108
  * of minimizing stdlib dependency, we use our constant-time one anyway. */
105
109
  ret = mlk_ct_memcmp(sk + MLKEM_INDCCA_SECRETKEYBYTES - 2 * MLKEM_SYMBYTES,
106
110
  test, MLKEM_SYMBYTES)
107
- ? MLK_ERR_FAIL
111
+ ? MLK_ERR_INVALID_SK
108
112
  : 0;
109
113
 
110
114
  cleanup:
@@ -113,7 +117,9 @@ cleanup:
113
117
  MLK_FREE(test, uint8_t, MLKEM_SYMBYTES, context);
114
118
  return ret;
115
119
  }
120
+ #endif /* !MLK_CONFIG_NO_DECAPS_API */
116
121
 
122
+ #if !defined(MLK_CONFIG_NO_KEYPAIR_API)
117
123
  MLK_MUST_CHECK_RETURN_VALUE
118
124
  static int mlk_check_pct(uint8_t const pk[MLKEM_INDCCA_PUBLICKEYBYTES],
119
125
  uint8_t const sk[MLKEM_INDCCA_SECRETKEYBYTES],
@@ -121,9 +127,9 @@ static int mlk_check_pct(uint8_t const pk[MLKEM_INDCCA_PUBLICKEYBYTES],
121
127
  __contract__(
122
128
  requires(memory_no_alias(pk, MLKEM_INDCCA_PUBLICKEYBYTES))
123
129
  requires(memory_no_alias(sk, MLKEM_INDCCA_SECRETKEYBYTES))
124
- ensures(return_value == 0 || return_value == MLK_ERR_FAIL ||
125
- return_value == MLK_ERR_OUT_OF_MEMORY ||
126
- return_value == MLK_ERR_RNG_FAIL)
130
+ ensures(return_value == 0 || return_value == MLK_ERR_OUT_OF_MEMORY ||
131
+ return_value == MLK_ERR_RNG_FAIL ||
132
+ return_value == MLK_ERR_PCT_FAIL)
127
133
  );
128
134
 
129
135
  #if defined(MLK_CONFIG_KEYGEN_PCT)
@@ -131,7 +137,13 @@ __contract__(
131
137
  * Partially implements 'Pairwise Consistency Test' @[FIPS140_3_IG, p.87] and
132
138
  * @[FIPS203, Section 7.1, Pairwise Consistency]. */
133
139
 
134
- /* Reference: Not implemented in the reference implementation @[REF]. */
140
+ /* Reference: Not implemented in the reference implementation @[REF].
141
+ *
142
+ * @retval 0 Success.
143
+ * @retval MLK_ERR_OUT_OF_MEMORY MLK_CONFIG_CUSTOM_ALLOC_FREE was used and
144
+ * MLK_CUSTOM_ALLOC returned NULL.
145
+ * @retval MLK_ERR_RNG_FAIL Random number generation failed.
146
+ * @retval MLK_ERR_PCT_FAIL The consistency check failed. */
135
147
  MLK_MUST_CHECK_RETURN_VALUE
136
148
  static int mlk_check_pct(uint8_t const pk[MLKEM_INDCCA_PUBLICKEYBYTES],
137
149
  uint8_t const sk[MLKEM_INDCCA_SECRETKEYBYTES],
@@ -174,7 +186,7 @@ static int mlk_check_pct(uint8_t const pk[MLKEM_INDCCA_PUBLICKEYBYTES],
174
186
 
175
187
  if (ret != 0)
176
188
  {
177
- ret = MLK_ERR_FAIL;
189
+ ret = MLK_ERR_PCT_FAIL;
178
190
  }
179
191
 
180
192
  cleanup:
@@ -184,9 +196,21 @@ cleanup:
184
196
  MLK_FREE(ss_dec, uint8_t, MLKEM_SSBYTES, context);
185
197
  MLK_FREE(ss_enc, uint8_t, MLKEM_SSBYTES, context);
186
198
  MLK_FREE(ct, uint8_t, MLKEM_INDCCA_CIPHERTEXTBYTES, context);
199
+
200
+ /* The key pair being tested was just generated by this library, so a key
201
+ * check rejecting it hints at a faulty implementation rather than at bad
202
+ * input. Report it as a PCT failure. */
203
+ if (ret == MLK_ERR_INVALID_PK || ret == MLK_ERR_INVALID_SK)
204
+ {
205
+ ret = MLK_ERR_PCT_FAIL;
206
+ }
207
+
208
+ /* Other error codes, e.g. platform failures like out of memory or
209
+ * randomness failure, are passed on unmodified. */
210
+
187
211
  return ret;
188
212
  }
189
- #else /* MLK_CONFIG_KEYGEN_PCT */
213
+ #else /* MLK_CONFIG_KEYGEN_PCT */
190
214
  MLK_MUST_CHECK_RETURN_VALUE
191
215
  static int mlk_check_pct(uint8_t const pk[MLKEM_INDCCA_PUBLICKEYBYTES],
192
216
  uint8_t const sk[MLKEM_INDCCA_SECRETKEYBYTES],
@@ -195,9 +219,7 @@ static int mlk_check_pct(uint8_t const pk[MLKEM_INDCCA_PUBLICKEYBYTES],
195
219
  /* Skip PCT */
196
220
  ((void)pk);
197
221
  ((void)sk);
198
- #if defined(MLK_CONFIG_CONTEXT_PARAMETER)
199
- ((void)context);
200
- #endif
222
+ MLK_CONTEXT_UNUSED(context);
201
223
  return 0;
202
224
  }
203
225
  #endif /* !MLK_CONFIG_KEYGEN_PCT */
@@ -207,6 +229,7 @@ static int mlk_check_pct(uint8_t const pk[MLKEM_INDCCA_PUBLICKEYBYTES],
207
229
  * - We optionally include PCT which is not present in
208
230
  * the reference code. */
209
231
  MLK_EXTERNAL_API
232
+ MLK_MUST_CHECK_RETURN_VALUE
210
233
  int mlk_kem_keypair_derand(uint8_t pk[MLKEM_INDCCA_PUBLICKEYBYTES],
211
234
  uint8_t sk[MLKEM_INDCCA_SECRETKEYBYTES],
212
235
  const uint8_t coins[2 * MLKEM_SYMBYTES],
@@ -282,7 +305,9 @@ cleanup:
282
305
  return ret;
283
306
  }
284
307
  #endif /* !MLK_CONFIG_NO_RANDOMIZED_API */
308
+ #endif /* !MLK_CONFIG_NO_KEYPAIR_API */
285
309
 
310
+ #if !defined(MLK_CONFIG_NO_ENCAPS_API)
286
311
  /* Reference: `crypto_kem_enc_derand()` in the reference implementation @[REF]
287
312
  * - We include public key check
288
313
  * - We include stack buffer zeroization */
@@ -368,7 +393,9 @@ cleanup:
368
393
  return ret;
369
394
  }
370
395
  #endif /* !MLK_CONFIG_NO_RANDOMIZED_API */
396
+ #endif /* !MLK_CONFIG_NO_ENCAPS_API */
371
397
 
398
+ #if !defined(MLK_CONFIG_NO_DECAPS_API)
372
399
  /* Reference: `crypto_kem_dec()` in the reference implementation @[REF]
373
400
  * - We include secret key check
374
401
  * - We include stack buffer zeroization */
@@ -440,6 +467,7 @@ cleanup:
440
467
 
441
468
  return ret;
442
469
  }
470
+ #endif /* !MLK_CONFIG_NO_DECAPS_API */
443
471
 
444
472
  /* To facilitate single-compilation-unit (SCU) builds, undefine all macros.
445
473
  * Don't modify by hand -- this is auto-generated by scripts/autogen. */