pq_crypto 0.6.8 → 0.6.9

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 (206) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -0
  3. data/README.md +1 -3
  4. data/ext/pqcrypto/pqcrypto_version.h +1 -1
  5. data/ext/pqcrypto/vendor/.vendored +7 -7
  6. data/ext/pqcrypto/vendor/mldsa-native/BUILDING.md +71 -0
  7. data/ext/pqcrypto/vendor/mldsa-native/README.md +26 -11
  8. data/ext/pqcrypto/vendor/mldsa-native/RELEASE.md +77 -150
  9. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.c +93 -40
  10. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.h +74 -59
  11. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_asm.S +106 -40
  12. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_config.h +94 -92
  13. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/capability.h +31 -0
  14. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/cbmc.h +55 -4
  15. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/common.h +30 -0
  16. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/context.h +1 -0
  17. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/debug.c +1 -0
  18. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202.h +1 -0
  19. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_aarch64_asm.S +5 -2
  20. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_aarch64_asm.S +4 -4
  21. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_aarch64_asm.S +4 -4
  22. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm.S +8 -3
  23. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm.S +8 -4
  24. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/mve.h +12 -0
  25. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +4 -2
  26. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_state_extract_bytes_mve.S +37 -19
  27. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_state_xor_bytes_mve.S +37 -19
  28. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/auto.h +3 -8
  29. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/auto.h +53 -0
  30. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/keccak_f1600_x1_avx512.h +38 -0
  31. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/keccak_f1600_x4_avx512.h +38 -0
  32. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/fips202_native_x86_64.h +24 -0
  33. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccak_f1600_x1_avx512_asm.S +574 -0
  34. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccak_f1600_x4_avx2_asm.S +46 -18
  35. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccak_f1600_x4_avx512_asm.S +679 -0
  36. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccakf1600_constants.c +13 -4
  37. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/meta.h +6 -4
  38. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/arith_native_aarch64.h +5 -6
  39. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_intt_aarch64_asm.S +4 -2
  40. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_ntt_aarch64_asm.S +4 -2
  41. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_pointwise_montgomery_aarch64_asm.S +6 -4
  42. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_caddq_aarch64_asm.S +4 -2
  43. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_chknorm_aarch64_asm.S +6 -4
  44. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_decompose_32_aarch64_asm.S +4 -3
  45. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_decompose_88_aarch64_asm.S +4 -3
  46. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_use_hint_32_aarch64_asm.S +4 -3
  47. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_use_hint_88_aarch64_asm.S +4 -3
  48. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyvecl_pointwise_acc_montgomery_l4_aarch64_asm.S +4 -2
  49. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyvecl_pointwise_acc_montgomery_l5_aarch64_asm.S +4 -2
  50. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyvecl_pointwise_acc_montgomery_l7_aarch64_asm.S +4 -2
  51. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyz_unpack_17_aarch64_asm.S +5 -3
  52. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyz_unpack_19_aarch64_asm.S +5 -3
  53. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_rej_uniform_aarch64_asm.S +110 -120
  54. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_rej_uniform_eta2_aarch64_asm.S +109 -101
  55. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_rej_uniform_eta4_aarch64_asm.S +97 -93
  56. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/api.h +1 -9
  57. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/meta.h +4 -0
  58. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/fastmul.h +74 -0
  59. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/slowmul.h +77 -0
  60. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/src/arith_native_rv32im.h +124 -0
  61. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/src/mldsa_intt_rv32im_asm.S +331 -0
  62. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/src/mldsa_intt_rv32im_slowmul_asm.S +381 -0
  63. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/src/mldsa_ntt_rv32im_asm.S +304 -0
  64. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/src/mldsa_ntt_rv32im_slowmul_asm.S +351 -0
  65. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/src/mldsa_poly_pointwise_montgomery_rv32im_asm.S +139 -0
  66. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/src/rv32im_zetas.c +118 -0
  67. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/meta.h +6 -5
  68. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/arith_native_x86_64.h +2 -3
  69. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_intt_avx2_asm.S +5 -3
  70. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_ntt_avx2_asm.S +5 -3
  71. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_nttunpack_avx2_asm.S +5 -3
  72. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_pointwise_acc_l4_avx2_asm.S +6 -3
  73. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_pointwise_acc_l5_avx2_asm.S +6 -3
  74. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_pointwise_acc_l7_avx2_asm.S +6 -3
  75. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_pointwise_avx2_asm.S +5 -3
  76. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_caddq_avx2_asm.S +5 -3
  77. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_chknorm_avx2_asm.S +7 -5
  78. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_decompose_32_avx2_asm.S +69 -67
  79. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_decompose_88_avx2_asm.S +69 -67
  80. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_use_hint_32_avx2_asm.S +12 -16
  81. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_use_hint_88_avx2_asm.S +14 -18
  82. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_polyz_unpack_17_avx2_asm.S +6 -3
  83. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_polyz_unpack_19_avx2_asm.S +6 -3
  84. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_avx2_asm.S +5 -3
  85. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_eta2_avx2_asm.S +5 -3
  86. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_eta4_avx2_asm.S +5 -3
  87. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.c +23 -27
  88. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.h +21 -42
  89. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/params.h +28 -1
  90. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.c +87 -28
  91. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.h +61 -3
  92. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.c +23 -19
  93. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.h +30 -0
  94. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.c +55 -107
  95. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.h +67 -107
  96. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec_lazy.c +16 -24
  97. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec_lazy.h +27 -21
  98. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/reduce.h +8 -8
  99. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.c +191 -119
  100. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.h +6 -3
  101. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sys.h +16 -42
  102. data/ext/pqcrypto/vendor/mlkem-native/BUILDING.md +72 -0
  103. data/ext/pqcrypto/vendor/mlkem-native/README.md +9 -5
  104. data/ext/pqcrypto/vendor/mlkem-native/RELEASE.md +64 -312
  105. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.c +77 -34
  106. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.h +41 -13
  107. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_asm.S +89 -33
  108. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_config.h +50 -46
  109. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/capability.h +30 -0
  110. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/common.h +30 -0
  111. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.c +1 -0
  112. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.h +4 -5
  113. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/debug.c +1 -0
  114. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202.c +15 -0
  115. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202.h +23 -8
  116. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202x4.c +11 -3
  117. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202x4.h +7 -1
  118. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/keccakf1600.c +8 -0
  119. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/keccakf1600.h +8 -0
  120. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_aarch64_asm.S +5 -2
  121. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_aarch64_asm.S +4 -4
  122. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_aarch64_asm.S +4 -4
  123. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm.S +8 -3
  124. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm.S +8 -4
  125. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +4 -2
  126. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccak_f1600_x4_state_extract_bytes_mve.S +37 -19
  127. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccak_f1600_x4_state_xor_bytes_mve.S +37 -19
  128. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/auto.h +2 -2
  129. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/auto.h +47 -0
  130. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/keccak_f1600_x1_avx512.h +37 -0
  131. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/keccak_f1600_x4_avx512.h +37 -0
  132. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/fips202_native_x86_64.h +24 -0
  133. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccak_f1600_x1_avx512_asm.S +573 -0
  134. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccak_f1600_x4_avx2_asm.S +46 -18
  135. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccak_f1600_x4_avx512_asm.S +678 -0
  136. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccakf1600_constants.c +13 -4
  137. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/indcpa.c +1 -2
  138. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.c +7 -5
  139. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.h +29 -5
  140. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/meta.h +156 -0
  141. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/arith_native_aarch64.h +137 -3
  142. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/compress_d5_table.c +43 -0
  143. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/decompress_d10_table.c +50 -0
  144. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/decompress_d11_table.c +53 -0
  145. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/decompress_d4_table.c +44 -0
  146. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/decompress_d5_table.c +53 -0
  147. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_intt_aarch64_asm.S +5 -3
  148. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_ntt_aarch64_asm.S +4 -2
  149. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_compress_d10_aarch64_asm.S +439 -0
  150. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_compress_d11_aarch64_asm.S +452 -0
  151. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_compress_d4_aarch64_asm.S +106 -0
  152. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_compress_d5_aarch64_asm.S +124 -0
  153. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_decompress_d10_aarch64_asm.S +108 -0
  154. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_decompress_d11_aarch64_asm.S +116 -0
  155. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_decompress_d4_aarch64_asm.S +93 -0
  156. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_decompress_d5_aarch64_asm.S +104 -0
  157. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_frombytes_aarch64_asm.S +84 -0
  158. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_mulcache_compute_aarch64_asm.S +4 -2
  159. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_reduce_aarch64_asm.S +4 -2
  160. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_tobytes_aarch64_asm.S +5 -3
  161. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_tomont_aarch64_asm.S +4 -3
  162. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_polyvec_basemul_acc_montgomery_cached_k2_aarch64_asm.S +4 -2
  163. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_polyvec_basemul_acc_montgomery_cached_k3_aarch64_asm.S +4 -2
  164. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_polyvec_basemul_acc_montgomery_cached_k4_aarch64_asm.S +4 -2
  165. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_rej_uniform_aarch64_asm.S +112 -104
  166. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/api.h +0 -1
  167. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/meta.h +2 -2
  168. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/README.md +2 -2
  169. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/meta.h +16 -21
  170. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/arith_native_ppc64le.h +1 -0
  171. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/consts.c +2 -2
  172. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/mlkem_intt_ppc_asm.S +6 -5
  173. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/mlkem_ntt_ppc_asm.S +6 -5
  174. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/mlkem_poly_tomont_ppc_asm.S +6 -5
  175. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/mlkem_reduce_ppc_asm.S +6 -5
  176. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_debug.c +5 -4
  177. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_debug.h +2 -2
  178. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_poly.c +1 -1
  179. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/arith_native_x86_64.h +5 -5
  180. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_intt_avx2_asm.S +36 -33
  181. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_ntt_avx2_asm.S +67 -65
  182. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_nttfrombytes_avx2_asm.S +8 -5
  183. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_ntttobytes_avx2_asm.S +6 -3
  184. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_nttunpack_avx2_asm.S +5 -3
  185. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_compress_d10_avx2_asm.S +7 -5
  186. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_compress_d11_avx2_asm.S +7 -4
  187. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_compress_d4_avx2_asm.S +7 -5
  188. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_compress_d5_avx2_asm.S +7 -4
  189. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_decompress_d10_avx2_asm.S +7 -4
  190. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_decompress_d11_avx2_asm.S +6 -4
  191. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_decompress_d4_avx2_asm.S +7 -4
  192. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_decompress_d5_avx2_asm.S +6 -4
  193. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_mulcache_compute_avx2_asm.S +5 -3
  194. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_polyvec_basemul_acc_montgomery_cached_k2_avx2_asm.S +118 -115
  195. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_polyvec_basemul_acc_montgomery_cached_k3_avx2_asm.S +174 -171
  196. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_polyvec_basemul_acc_montgomery_cached_k4_avx2_asm.S +230 -227
  197. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_reduce_avx2_asm.S +17 -15
  198. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_rej_uniform_avx2_asm.S +7 -6
  199. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_tomont_avx2_asm.S +5 -3
  200. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.c +4 -9
  201. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.h +1 -1
  202. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sys.h +31 -44
  203. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/verify.h +1 -1
  204. data/lib/pq_crypto/version.rb +1 -1
  205. data/script/vendor_libs.rb +6 -6
  206. metadata +36 -1
@@ -7,7 +7,7 @@
7
7
  /*yaml
8
8
  Name: rej_uniform_eta4_aarch64_asm
9
9
  Description: AArch64 rejection sampling of eta=4 secret coefficients
10
- Signature: uint64_t mld_rej_uniform_eta4_aarch64_asm(int32_t r[256], const uint8_t *buf, unsigned buflen, const uint8_t table[4096])
10
+ Signature: uint64_t mld_rej_uniform_eta4_aarch64_asm(int32_t r[256], const uint8_t *buf, uint64_t buflen, const uint8_t table[4096])
11
11
  ABI:
12
12
  Architecture: aarch64
13
13
  CallingConvention: AAPCS64
@@ -17,7 +17,7 @@
17
17
  size_bytes: 1024
18
18
  permissions: write-only
19
19
  c_parameter: int32_t r[256]
20
- description: Output buffer (256 x int32_t)
20
+ description: Output buffer, disjoint from buf and table. The return value is its valid prefix length.
21
21
  x1:
22
22
  type: buffer
23
23
  size_bytes: x2
@@ -26,8 +26,8 @@
26
26
  description: Input buffer
27
27
  x2:
28
28
  type: scalar
29
- c_parameter: unsigned buflen
30
- description: Length of input buffer (must be a multiple of 8)
29
+ c_parameter: uint64_t buflen
30
+ description: Length of input buffer (must be a positive multiple of 8)
31
31
  test_with: 272 # MLD_AARCH64_REJ_UNIFORM_ETA4_BUFLEN
32
32
  x3:
33
33
  type: buffer
@@ -38,7 +38,8 @@
38
38
  */
39
39
 
40
40
  #include "../../../common.h"
41
- #if defined(MLD_ARITH_BACKEND_AARCH64) && \
41
+ #if defined(MLD_SYS_AARCH64_NEON) && \
42
+ defined(MLD_ARITH_BACKEND_AARCH64) && \
42
43
  !defined(MLD_CONFIG_NO_KEYPAIR_API) && \
43
44
  !defined(MLD_CONFIG_MULTILEVEL_NO_SHARED) && \
44
45
  (defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || MLDSA_ETA == 4)
@@ -54,108 +55,111 @@
54
55
  MLD_ASM_FN_SYMBOL(rej_uniform_eta4_aarch64_asm)
55
56
 
56
57
  .cfi_startproc
57
- sub sp, sp, #0x240
58
- .cfi_adjust_cfa_offset 0x240
59
- mov x7, #0x1 // =1
60
- movk x7, #0x2, lsl #16
61
- movk x7, #0x4, lsl #32
62
- movk x7, #0x8, lsl #48
63
- mov v31.d[0], x7
64
- mov x7, #0x10 // =16
65
- movk x7, #0x20, lsl #16
66
- movk x7, #0x40, lsl #32
67
- movk x7, #0x80, lsl #48
68
- mov v31.d[1], x7
69
- movi v30.8h, #0x9
58
+ mov x5, #0x101 // =257
59
+ movk x5, #0x102, lsl #16
60
+ movk x5, #0x104, lsl #32
61
+ movk x5, #0x108, lsl #48
62
+ mov v31.d[0], x5
63
+ mov x5, #0x110 // =272
64
+ movk x5, #0x120, lsl #16
65
+ movk x5, #0x140, lsl #32
66
+ movk x5, #0x180, lsl #48
67
+ mov v31.d[1], x5
68
+ movi v30.16b, #0x9
70
69
  movi v7.8h, #0x4
71
- mov x8, sp
72
- mov x7, x8
73
- mov x11, #0x0 // =0
74
- eor v16.16b, v16.16b, v16.16b
75
-
76
- Lmld_rej_uniform_eta4_initial_zero:
77
- str q16, [x7], #0x40
78
- stur q16, [x7, #-0x30]
79
- stur q16, [x7, #-0x20]
80
- stur q16, [x7, #-0x10]
81
- add x11, x11, #0x20
82
- cmp x11, #0x100
83
- b.lt Lmld_rej_uniform_eta4_initial_zero
84
- mov x7, x8
85
- mov x9, #0x0 // =0
70
+ movi v29.8b, #0xf
86
71
  mov x4, #0x100 // =256
87
72
 
88
- Lmld_rej_uniform_eta4_loop8:
89
- cmp x9, x4
90
- b.hs Lmld_rej_uniform_eta4_memory_copy
91
- sub x2, x2, #0x8
73
+ Lmld_rej_uniform_eta4_loop:
92
74
  ld1 { v0.8b }, [x1], #8
93
- movi v26.8b, #0xf
94
- and v27.8b, v0.8b, v26.8b
95
- ushr v28.8b, v0.8b, #0x4
96
- zip1 v26.8b, v27.8b, v28.8b
97
- zip2 v29.8b, v27.8b, v28.8b
98
- ushll v16.8h, v26.8b, #0x0
99
- ushll v17.8h, v29.8b, #0x0
100
- cmhi v4.8h, v30.8h, v16.8h
101
- cmhi v5.8h, v30.8h, v17.8h
75
+ and v2.8b, v0.8b, v29.8b
76
+ ushr v3.8b, v0.8b, #0x4
77
+ zip1 v6.16b, v2.16b, v3.16b
78
+ cmhi v4.16b, v30.16b, v6.16b
79
+ sshll2 v5.8h, v4.16b, #0x0
80
+ sshll v4.8h, v4.8b, #0x0
102
81
  and v4.16b, v4.16b, v31.16b
103
82
  and v5.16b, v5.16b, v31.16b
104
83
  uaddlv s20, v4.8h
105
84
  uaddlv s21, v5.8h
106
- fmov w12, s20
107
- fmov w13, s21
108
- ldr q24, [x3, x12, lsl #4]
109
- ldr q25, [x3, x13, lsl #4]
110
- cnt v4.16b, v4.16b
111
- cnt v5.16b, v5.16b
112
- uaddlv s20, v4.8h
113
- uaddlv s21, v5.8h
114
- fmov w12, s20
115
- fmov w13, s21
85
+ fmov x12, d20
86
+ fmov x13, d21
87
+ and x14, x12, #0xff
88
+ and x15, x13, #0xff
89
+ lsr x12, x12, #8
90
+ lsr x13, x13, #8
91
+ ldr q24, [x3, x14, lsl #4]
92
+ ldr q25, [x3, x15, lsl #4]
93
+ ushll v16.8h, v6.8b, #0x0
94
+ ushll2 v18.8h, v6.16b, #0x0
116
95
  tbl v16.16b, { v16.16b }, v24.16b
117
- tbl v17.16b, { v17.16b }, v25.16b
118
- st1 { v16.8h }, [x7]
119
- add x7, x7, x12, lsl #1
120
- st1 { v17.8h }, [x7]
121
- add x7, x7, x13, lsl #1
122
- add x12, x12, x13
123
- add x9, x9, x12
124
- cmp x2, #0x8
125
- b.hs Lmld_rej_uniform_eta4_loop8
126
-
127
- Lmld_rej_uniform_eta4_memory_copy:
128
- cmp x9, x4
129
- csel x9, x9, x4, lo
130
- mov x11, #0x0 // =0
131
- mov x7, x8
132
-
133
- Lmld_rej_uniform_eta4_final_copy:
134
- ldr q16, [x7], #0x20
135
- ldur q18, [x7, #-0x10]
136
- sub v16.8h, v7.8h, v16.8h
137
- sub v18.8h, v7.8h, v18.8h
138
- sshll2 v17.4s, v16.8h, #0x0
139
- sshll v16.4s, v16.4h, #0x0
140
- sshll2 v19.4s, v18.8h, #0x0
141
- sshll v18.4s, v18.4h, #0x0
142
- str q16, [x0], #0x40
143
- stur q17, [x0, #-0x30]
144
- stur q18, [x0, #-0x20]
145
- stur q19, [x0, #-0x10]
146
- add x11, x11, #0x10
147
- cmp x11, #0x100
148
- b.lt Lmld_rej_uniform_eta4_final_copy
149
- mov x0, x9
150
- add sp, sp, #0x240
151
- .cfi_adjust_cfa_offset -0x240
96
+ tbl v18.16b, { v18.16b }, v25.16b
97
+ usubl2 v17.4s, v7.8h, v16.8h
98
+ usubl v16.4s, v7.4h, v16.4h
99
+ usubl2 v19.4s, v7.8h, v18.8h
100
+ usubl v18.4s, v7.4h, v18.4h
101
+ cmp x4, #0x10
102
+ b.ls Lmld_rej_uniform_eta4_tail
103
+ st1 { v16.4s, v17.4s }, [x0]
104
+ add x0, x0, x12, lsl #2
105
+ st1 { v18.4s, v19.4s }, [x0]
106
+ add x0, x0, x13, lsl #2
107
+ sub x4, x4, x12
108
+ sub x4, x4, x13
109
+
110
+ Lmld_rej_uniform_eta4_next:
111
+ subs x2, x2, #0x8
112
+ b.ne Lmld_rej_uniform_eta4_loop
113
+ b Lmld_rej_uniform_eta4_return
114
+
115
+ Lmld_rej_uniform_eta4_tail:
116
+ mov x6, #0x2 // =2
117
+
118
+ Lmld_rej_uniform_eta4_store_group:
119
+ cmp x4, #0x8
120
+ b.lo Lmld_rej_uniform_eta4_store_partial
121
+ st1 { v16.4s, v17.4s }, [x0]
122
+ b Lmld_rej_uniform_eta4_stored
123
+
124
+ Lmld_rej_uniform_eta4_store_partial:
125
+ mov x7, x0
126
+ tbz w4, #0x2, Lmld_rej_uniform_eta4_store_two
127
+ st1 { v16.4s }, [x7], #16
128
+ mov v16.16b, v17.16b
129
+
130
+ Lmld_rej_uniform_eta4_store_two:
131
+ tbz w4, #0x1, Lmld_rej_uniform_eta4_store_one
132
+ st1 { v16.2s }, [x7], #8
133
+ ext v16.16b, v16.16b, v16.16b, #0x8
134
+
135
+ Lmld_rej_uniform_eta4_store_one:
136
+ tbz w4, #0x0, Lmld_rej_uniform_eta4_stored
137
+ str s16, [x7]
138
+
139
+ Lmld_rej_uniform_eta4_stored:
140
+ subs x4, x4, x12
141
+ b.ls Lmld_rej_uniform_eta4_full
142
+ add x0, x0, x12, lsl #2
143
+ subs x6, x6, #0x1
144
+ b.eq Lmld_rej_uniform_eta4_next
145
+ mov v16.16b, v18.16b
146
+ mov v17.16b, v19.16b
147
+ mov x12, x13
148
+ b Lmld_rej_uniform_eta4_store_group
149
+
150
+ Lmld_rej_uniform_eta4_full:
151
+ mov x4, #0x0 // =0
152
+
153
+ Lmld_rej_uniform_eta4_return:
154
+ mov x0, #0x100 // =256
155
+ sub x0, x0, x4
152
156
  ret
153
157
  .cfi_endproc
154
158
 
155
159
  MLD_ASM_FN_SIZE(rej_uniform_eta4_aarch64_asm)
156
160
 
157
- #endif /* MLD_ARITH_BACKEND_AARCH64 && !MLD_CONFIG_NO_KEYPAIR_API && \
158
- !MLD_CONFIG_MULTILEVEL_NO_SHARED && \
161
+ #endif /* MLD_SYS_AARCH64_NEON && MLD_ARITH_BACKEND_AARCH64 && \
162
+ !MLD_CONFIG_NO_KEYPAIR_API && !MLD_CONFIG_MULTILEVEL_NO_SHARED && \
159
163
  (MLD_CONFIG_MULTILEVEL_WITH_SHARED || MLDSA_ETA == 4) */
160
164
 
161
165
  #if defined(__ELF__)
@@ -96,7 +96,6 @@ __contract__(
96
96
  assigns(memory_slice(p, sizeof(int32_t) * MLDSA_N))
97
97
  ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || return_value == MLD_NATIVE_FUNC_SUCCESS)
98
98
  ensures((return_value == MLD_NATIVE_FUNC_SUCCESS) ==> array_abs_bound(p, 0, MLDSA_N, MLD_NTT_BOUND))
99
- ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_abs_bound(p, 0, MLDSA_N, MLDSA_Q))
100
99
  ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_unchanged(p, MLDSA_N))
101
100
  );
102
101
  #endif /* MLD_USE_NATIVE_NTT */
@@ -154,7 +153,6 @@ __contract__(
154
153
  assigns(memory_slice(p, sizeof(int32_t) * MLDSA_N))
155
154
  ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || return_value == MLD_NATIVE_FUNC_SUCCESS)
156
155
  ensures((return_value == MLD_NATIVE_FUNC_SUCCESS) ==> array_abs_bound(p, 0, MLDSA_N, MLD_INTT_BOUND))
157
- ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_abs_bound(p, 0, MLDSA_N, MLDSA_Q))
158
156
  ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_unchanged(p, MLDSA_N))
159
157
  );
160
158
  #endif /* MLD_USE_NATIVE_INTT */
@@ -221,7 +219,6 @@ __contract__(
221
219
  requires(memory_no_alias(buf, buflen))
222
220
  assigns(memory_slice(r, sizeof(int32_t) * len))
223
221
  ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || (0 <= return_value && return_value <= len))
224
- /* check-magic: 3 == 2 + 1 (decl gated on MLDSA_ETA == 2) */
225
222
  ensures((return_value != MLD_NATIVE_FUNC_FALLBACK) ==> (array_abs_bound(r, 0, return_value, 3)))
226
223
  );
227
224
  #endif /* MLD_CONFIG_MULTILEVEL_WITH_SHARED || MLDSA_ETA == 2 */
@@ -256,7 +253,6 @@ __contract__(
256
253
  requires(memory_no_alias(buf, buflen))
257
254
  assigns(memory_slice(r, sizeof(int32_t) * len))
258
255
  ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || (0 <= return_value && return_value <= len))
259
- /* check-magic: 5 == 4 + 1 (decl gated on MLDSA_ETA == 4) */
260
256
  ensures((return_value != MLD_NATIVE_FUNC_FALLBACK) ==> (array_abs_bound(r, 0, return_value, 5)))
261
257
  );
262
258
  #endif /* MLD_CONFIG_MULTILEVEL_WITH_SHARED || MLDSA_ETA == 4 */
@@ -290,7 +286,6 @@ __contract__(
290
286
  ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || return_value == MLD_NATIVE_FUNC_SUCCESS)
291
287
  ensures((return_value == MLD_NATIVE_FUNC_SUCCESS) ==> array_bound(a1, 0, MLDSA_N, 0, (MLDSA_Q-1)/(2*MLDSA_GAMMA2)))
292
288
  ensures((return_value == MLD_NATIVE_FUNC_SUCCESS) ==> array_abs_bound(a0, 0, MLDSA_N, MLDSA_GAMMA2+1))
293
- ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_bound(a0, 0, MLDSA_N, 0, MLDSA_Q))
294
289
  ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_unchanged(a0, MLDSA_N))
295
290
  );
296
291
  #endif /* MLD_CONFIG_MULTILEVEL_WITH_SHARED || MLD_CONFIG_PARAMETER_SET == 65 \
@@ -322,7 +317,6 @@ __contract__(
322
317
  ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || return_value == MLD_NATIVE_FUNC_SUCCESS)
323
318
  ensures((return_value == MLD_NATIVE_FUNC_SUCCESS) ==> array_bound(a1, 0, MLDSA_N, 0, (MLDSA_Q-1)/(2*MLDSA_GAMMA2)))
324
319
  ensures((return_value == MLD_NATIVE_FUNC_SUCCESS) ==> array_abs_bound(a0, 0, MLDSA_N, MLDSA_GAMMA2+1))
325
- ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_bound(a0, 0, MLDSA_N, 0, MLDSA_Q))
326
320
  ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_unchanged(a0, MLDSA_N))
327
321
  );
328
322
  #endif /* MLD_CONFIG_MULTILEVEL_WITH_SHARED || MLD_CONFIG_PARAMETER_SET == 44 \
@@ -344,7 +338,6 @@ __contract__(
344
338
  assigns(memory_slice(a, sizeof(int32_t) * MLDSA_N))
345
339
  ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || return_value == MLD_NATIVE_FUNC_SUCCESS)
346
340
  ensures((return_value == MLD_NATIVE_FUNC_SUCCESS) ==> array_bound(a, 0, MLDSA_N, 0, MLDSA_Q))
347
- ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_abs_bound(a, 0, MLDSA_N, MLDSA_Q))
348
341
  ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_unchanged(a, MLDSA_N))
349
342
  );
350
343
  #endif /* MLD_USE_NATIVE_POLY_CADDQ */
@@ -508,8 +501,7 @@ __contract__(
508
501
  assigns(memory_slice(a, sizeof(int32_t) * MLDSA_N))
509
502
  ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || return_value == MLD_NATIVE_FUNC_SUCCESS)
510
503
  ensures((return_value == MLD_NATIVE_FUNC_SUCCESS) ==> array_abs_bound(a, 0, MLDSA_N, MLDSA_Q))
511
- ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_abs_bound(a, 0, MLDSA_N, MLD_NTT_BOUND))
512
- ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_abs_bound(b, 0, MLDSA_N, MLD_NTT_BOUND))
504
+ ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_unchanged(a, MLDSA_N))
513
505
  );
514
506
  #endif /* MLD_USE_NATIVE_POINTWISE_MONTGOMERY */
515
507
  #endif /* !MLD_CONFIG_NO_SIGN_API || !MLD_CONFIG_NO_VERIFY_API || \
@@ -21,4 +21,8 @@
21
21
  #include "x86_64/meta.h"
22
22
  #endif
23
23
 
24
+ #if defined(MLD_SYS_RISCV32_M)
25
+ #include "rv32im/fastmul.h"
26
+ #endif
27
+
24
28
  #endif /* !MLD_NATIVE_META_H */
@@ -0,0 +1,74 @@
1
+ /*
2
+ * Copyright (c) The mlkem-native project authors
3
+ * Copyright (c) The mldsa-native project authors
4
+ * SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
5
+ */
6
+
7
+ #ifndef MLD_NATIVE_RV32IM_FASTMUL_H
8
+ #define MLD_NATIVE_RV32IM_FASTMUL_H
9
+
10
+ #if !defined(MLD_SYS_RISCV32_M)
11
+ #error This backend can only be used on RV32 targets with the M extension.
12
+ #endif
13
+
14
+ /*
15
+ * Arithmetic backend for the RISC-V RV32-IM ISA and the ILP32, ILP32F, and
16
+ * ILP32D family of ABIs. This is the default arithmetic backend selected by
17
+ * mldsa/src/native/meta.h on RV32IM targets.
18
+ *
19
+ * This profile uses an RV32M low multiply for the Barrett `t*q` step in the
20
+ * forward and inverse NTT wrappers.
21
+ *
22
+ * The assembly has fixed control flow and secret-independent memory
23
+ * addresses. Constant-time use also relies on the target's 32-bit multiplier
24
+ * executing RV32M mul and mulh with data-independent latency. RV32IM does not
25
+ * architecturally guarantee this property; integrators must establish it for
26
+ * the selected core. HOL-Light proves functional correctness, memory safety,
27
+ * and secret-independent execution subject to that multiplier assumption.
28
+ * CBMC proves that these C wrappers satisfy the native arithmetic contracts.
29
+ */
30
+
31
+ /* Set of primitives that this backend replaces. */
32
+ #define MLD_USE_NATIVE_NTT
33
+ #define MLD_USE_NATIVE_INTT
34
+ #define MLD_USE_NATIVE_POINTWISE_MONTGOMERY
35
+
36
+ /* Identifier for this backend so that source and assembly files
37
+ * in the build can be appropriately guarded. */
38
+ #define MLD_ARITH_BACKEND_RV32IM
39
+
40
+ #define MLD_RV32IM_NEED_FASTMUL
41
+
42
+ #if !defined(__ASSEMBLER__)
43
+ #include "../api.h"
44
+ #include "src/arith_native_rv32im.h"
45
+
46
+ MLD_MUST_CHECK_RETURN_VALUE
47
+ static MLD_INLINE int mld_ntt_native(int32_t data[MLDSA_N])
48
+ {
49
+ mld_ntt_rv32im_fastmul_asm(data, mld_rv32im_ntt_zetas);
50
+ return MLD_NATIVE_FUNC_SUCCESS;
51
+ }
52
+
53
+ MLD_MUST_CHECK_RETURN_VALUE
54
+ static MLD_INLINE int mld_intt_native(int32_t data[MLDSA_N])
55
+ {
56
+ mld_intt_rv32im_fastmul_asm(data, mld_rv32im_ntt_zetas);
57
+ return MLD_NATIVE_FUNC_SUCCESS;
58
+ }
59
+
60
+ #if !defined(MLD_CONFIG_NO_SIGN_API) || !defined(MLD_CONFIG_NO_VERIFY_API) || \
61
+ defined(MLD_CONFIG_REDUCE_RAM) || defined(MLD_UNIT_TEST)
62
+ MLD_MUST_CHECK_RETURN_VALUE
63
+ static MLD_INLINE int mld_poly_pointwise_montgomery_native(
64
+ int32_t a[MLDSA_N], const int32_t b[MLDSA_N])
65
+ {
66
+ mld_poly_pointwise_montgomery_rv32im_asm(a, b);
67
+ return MLD_NATIVE_FUNC_SUCCESS;
68
+ }
69
+ #endif /* !MLD_CONFIG_NO_SIGN_API || !MLD_CONFIG_NO_VERIFY_API || \
70
+ MLD_CONFIG_REDUCE_RAM || MLD_UNIT_TEST */
71
+
72
+ #endif /* !__ASSEMBLER__ */
73
+
74
+ #endif /* !MLD_NATIVE_RV32IM_FASTMUL_H */
@@ -0,0 +1,77 @@
1
+ /*
2
+ * Copyright (c) The mlkem-native project authors
3
+ * Copyright (c) The mldsa-native project authors
4
+ * SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
5
+ */
6
+
7
+ #ifndef MLD_NATIVE_RV32IM_SLOWMUL_H
8
+ #define MLD_NATIVE_RV32IM_SLOWMUL_H
9
+
10
+ #if !defined(MLD_SYS_RISCV32_M)
11
+ #error This backend can only be used on RV32 targets with the M extension.
12
+ #endif
13
+
14
+ /*
15
+ * Arithmetic backend for the RISC-V RV32-IM ISA and the ILP32, ILP32F, and
16
+ * ILP32D family of ABIs. Select this profile explicitly through
17
+ * MLD_CONFIG_ARITH_BACKEND_FILE when shift/add multiplication by q is
18
+ * preferable to the default fastmul profile.
19
+ *
20
+ * This profile replaces the Barrett low(t*q) multiply in the forward and
21
+ * inverse NTT wrappers by a shift/add chain exploiting q = 2^23 - 2^13 + 1.
22
+ * It still uses RV32M `mulh`, and constant-time use still relies on the
23
+ * target's RV32M multiplier, including `mul` and `mulh`, having
24
+ * data-independent latency even if it is comparatively slow.
25
+ *
26
+ * The assembly has fixed control flow and secret-independent memory
27
+ * addresses. RV32IM does not architecturally guarantee constant-latency
28
+ * multiplication, so integrators must establish this property for the
29
+ * selected core. HOL-Light proves functional correctness, memory safety, and
30
+ * secret-independent execution subject to that multiplier assumption.
31
+ * CBMC proves that these C wrappers satisfy the native arithmetic contracts.
32
+ */
33
+
34
+ /* Set of primitives that this backend replaces. */
35
+ #define MLD_USE_NATIVE_NTT
36
+ #define MLD_USE_NATIVE_INTT
37
+ #define MLD_USE_NATIVE_POINTWISE_MONTGOMERY
38
+
39
+ /* Identifier for this backend so that source and assembly files
40
+ * in the build can be appropriately guarded. */
41
+ #define MLD_ARITH_BACKEND_RV32IM
42
+
43
+ #define MLD_RV32IM_NEED_SLOWMUL
44
+
45
+ #if !defined(__ASSEMBLER__)
46
+ #include "../api.h"
47
+ #include "src/arith_native_rv32im.h"
48
+
49
+ MLD_MUST_CHECK_RETURN_VALUE
50
+ static MLD_INLINE int mld_ntt_native(int32_t data[MLDSA_N])
51
+ {
52
+ mld_ntt_rv32im_slowmul_asm(data, mld_rv32im_ntt_zetas);
53
+ return MLD_NATIVE_FUNC_SUCCESS;
54
+ }
55
+
56
+ MLD_MUST_CHECK_RETURN_VALUE
57
+ static MLD_INLINE int mld_intt_native(int32_t data[MLDSA_N])
58
+ {
59
+ mld_intt_rv32im_slowmul_asm(data, mld_rv32im_ntt_zetas);
60
+ return MLD_NATIVE_FUNC_SUCCESS;
61
+ }
62
+
63
+ #if !defined(MLD_CONFIG_NO_SIGN_API) || !defined(MLD_CONFIG_NO_VERIFY_API) || \
64
+ defined(MLD_CONFIG_REDUCE_RAM) || defined(MLD_UNIT_TEST)
65
+ MLD_MUST_CHECK_RETURN_VALUE
66
+ static MLD_INLINE int mld_poly_pointwise_montgomery_native(
67
+ int32_t a[MLDSA_N], const int32_t b[MLDSA_N])
68
+ {
69
+ mld_poly_pointwise_montgomery_rv32im_asm(a, b);
70
+ return MLD_NATIVE_FUNC_SUCCESS;
71
+ }
72
+ #endif /* !MLD_CONFIG_NO_SIGN_API || !MLD_CONFIG_NO_VERIFY_API || \
73
+ MLD_CONFIG_REDUCE_RAM || MLD_UNIT_TEST */
74
+
75
+ #endif /* !__ASSEMBLER__ */
76
+
77
+ #endif /* !MLD_NATIVE_RV32IM_SLOWMUL_H */
@@ -0,0 +1,124 @@
1
+ /*
2
+ * Copyright (c) The mldsa-native project authors
3
+ * SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
4
+ */
5
+
6
+ #ifndef MLD_NATIVE_RV32IM_SRC_ARITH_NATIVE_RV32IM_H
7
+ #define MLD_NATIVE_RV32IM_SRC_ARITH_NATIVE_RV32IM_H
8
+
9
+ #include "../../../cbmc.h"
10
+ #include "../../../common.h"
11
+
12
+ #define mld_rv32im_ntt_zetas MLD_NAMESPACE(rv32im_ntt_zetas)
13
+
14
+ /*
15
+ * Forward NTT zeta table for the RV32-IM backend.
16
+ *
17
+ * 255 logical entries, each a (zeta, w) Barrett pair: zeta is the plain
18
+ * centered twiddle w^{bitrev_8(k)} mod q (|zeta| <= q/2) and
19
+ * w = round(zeta * 2^32 / q) is the Barrett multiplier used by the
20
+ * constant-twiddle butterfly. The order matches the consumption order of
21
+ * the 2+2+2+2 forward NTT.
22
+ */
23
+ MLD_INTERNAL_DATA_DECLARATION const int32_t mld_rv32im_ntt_zetas[510];
24
+
25
+ #define mld_ntt_rv32im_fastmul_asm MLD_NAMESPACE(ntt_rv32im_fastmul_asm)
26
+ void mld_ntt_rv32im_fastmul_asm(int32_t r[MLDSA_N], const int32_t zetas[510])
27
+ /* This must be kept in sync with the HOL-Light subroutine specification in
28
+ * proofs/hol_light/riscv32/proofs/mldsa_ntt_rv32im_asm.ml. */
29
+ __contract__(
30
+ requires(memory_no_alias(r, sizeof(int32_t) * MLDSA_N))
31
+ requires(array_abs_bound(r, 0, MLDSA_N, MLDSA_Q))
32
+ requires(zetas == mld_rv32im_ntt_zetas)
33
+ assigns(memory_slice(r, sizeof(int32_t) * MLDSA_N))
34
+ /* The truncating `mulh` Barrett multiply has output bound
35
+ * ceil(5*q/4), so eight CT layers grow the input-q bound to
36
+ * q + 8*ceil(5*q/4) < 9*ceil(5*q/4). */
37
+ /* This is MLD_NTT_BOUND, the exclusive output bound in the generic C and
38
+ * native NTT contracts and the exclusive input bound in the pointwise
39
+ * Montgomery contracts. */
40
+ /* check-magic: 94279698 == 9 * ((5 * MLDSA_Q + 3) / 4) */
41
+ ensures(array_abs_bound(r, 0, MLDSA_N, 94279698))
42
+ );
43
+
44
+ #define mld_ntt_rv32im_slowmul_asm MLD_NAMESPACE(ntt_rv32im_slowmul_asm)
45
+ void mld_ntt_rv32im_slowmul_asm(int32_t r[MLDSA_N], const int32_t zetas[510])
46
+ /* This must be kept in sync with the HOL-Light subroutine specification in
47
+ * proofs/hol_light/riscv32/proofs/mldsa_ntt_rv32im_slowmul_asm.ml. */
48
+ __contract__(
49
+ requires(memory_no_alias(r, sizeof(int32_t) * MLDSA_N))
50
+ requires(array_abs_bound(r, 0, MLDSA_N, MLDSA_Q))
51
+ requires(zetas == mld_rv32im_ntt_zetas)
52
+ assigns(memory_slice(r, sizeof(int32_t) * MLDSA_N))
53
+ /* The truncating `mulh` Barrett multiply has output bound
54
+ * ceil(5*q/4), so eight CT layers grow the input-q bound to
55
+ * q + 8*ceil(5*q/4) < 9*ceil(5*q/4). */
56
+ /* This is MLD_NTT_BOUND, the exclusive output bound in the generic C and
57
+ * native NTT contracts and the exclusive input bound in the pointwise
58
+ * Montgomery contracts. */
59
+ /* check-magic: 94279698 == 9 * ((5 * MLDSA_Q + 3) / 4) */
60
+ ensures(array_abs_bound(r, 0, MLDSA_N, 94279698))
61
+ );
62
+
63
+ #define mld_intt_rv32im_fastmul_asm MLD_NAMESPACE(intt_rv32im_fastmul_asm)
64
+ void mld_intt_rv32im_fastmul_asm(int32_t r[MLDSA_N], const int32_t zetas[510])
65
+ /* This must be kept in sync with the HOL-Light subroutine specification in
66
+ * proofs/hol_light/riscv32/proofs/mldsa_intt_rv32im_asm.ml. */
67
+ __contract__(
68
+ requires(memory_no_alias(r, sizeof(int32_t) * MLDSA_N))
69
+ requires(array_abs_bound(r, 0, MLDSA_N, MLDSA_Q))
70
+ requires(zetas == mld_rv32im_ntt_zetas)
71
+ assigns(memory_slice(r, sizeof(int32_t) * MLDSA_N))
72
+ ensures(array_abs_bound(r, 0, MLDSA_N, MLDSA_Q))
73
+ );
74
+
75
+ #define mld_intt_rv32im_slowmul_asm MLD_NAMESPACE(intt_rv32im_slowmul_asm)
76
+ void mld_intt_rv32im_slowmul_asm(int32_t r[MLDSA_N], const int32_t zetas[510])
77
+ /* This must be kept in sync with the HOL-Light subroutine specification in
78
+ * proofs/hol_light/riscv32/proofs/mldsa_intt_rv32im_slowmul_asm.ml. */
79
+ __contract__(
80
+ requires(memory_no_alias(r, sizeof(int32_t) * MLDSA_N))
81
+ requires(array_abs_bound(r, 0, MLDSA_N, MLDSA_Q))
82
+ requires(zetas == mld_rv32im_ntt_zetas)
83
+ assigns(memory_slice(r, sizeof(int32_t) * MLDSA_N))
84
+ ensures(array_abs_bound(r, 0, MLDSA_N, MLDSA_Q))
85
+ );
86
+
87
+ #define mld_poly_pointwise_montgomery_rv32im_asm \
88
+ MLD_NAMESPACE(poly_pointwise_montgomery_rv32im_asm)
89
+ #if !defined(MLD_CONFIG_NO_SIGN_API) || !defined(MLD_CONFIG_NO_VERIFY_API) || \
90
+ defined(MLD_CONFIG_REDUCE_RAM) || defined(MLD_UNIT_TEST)
91
+ void mld_poly_pointwise_montgomery_rv32im_asm(int32_t a[MLDSA_N],
92
+ const int32_t b[MLDSA_N])
93
+ /* This must be kept in sync with the HOL-Light subroutine specification in
94
+ * proofs/hol_light/riscv32/proofs/
95
+ * mldsa_poly_pointwise_montgomery_rv32im_asm.ml. */
96
+ __contract__(
97
+ requires(memory_no_alias(a, sizeof(int32_t) * MLDSA_N))
98
+ requires(memory_no_alias(b, sizeof(int32_t) * MLDSA_N))
99
+ /* This is MLD_NTT_BOUND, the exclusive output bound in the generic C and
100
+ * native forward-NTT contracts and the exclusive input bound in the
101
+ * pointwise-Montgomery contracts. */
102
+ /* check-magic: 94279698 == 9 * ((5 * MLDSA_Q + 3) / 4) */
103
+ requires(array_abs_bound(a, 0, MLDSA_N, 94279698))
104
+ requires(array_abs_bound(b, 0, MLDSA_N, 94279698))
105
+ assigns(memory_slice(a, sizeof(int32_t) * MLDSA_N))
106
+ /* The q-bound is both the pointwise postcondition and the inverse-NTT
107
+ * input precondition in the generic C and native contracts. */
108
+ ensures(array_abs_bound(a, 0, MLDSA_N, MLDSA_Q))
109
+ );
110
+ #endif /* !MLD_CONFIG_NO_SIGN_API || !MLD_CONFIG_NO_VERIFY_API || \
111
+ MLD_CONFIG_REDUCE_RAM || MLD_UNIT_TEST */
112
+
113
+ /*
114
+ * `array_abs_bound` is exclusive, matching the strict bounds in the forward
115
+ * NTT and pointwise HOL-Light theorems. Its MLDSA_Q form is equivalent to the
116
+ * inclusive `abs <= MLDSA_Q - 1` bound used by the inverse NTT theorems.
117
+ *
118
+ * The assigns clauses give the same caller-visible footprint as HOL-Light:
119
+ * only the 1024-byte output array changes. HOL-Light also tracks the private
120
+ * 16- or 32-byte stack frame used during a call and proves that the stack
121
+ * pointer is restored before return.
122
+ */
123
+
124
+ #endif /* !MLD_NATIVE_RV32IM_SRC_ARITH_NATIVE_RV32IM_H */