pq_crypto 0.6.7 → 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 (214) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +20 -0
  3. data/README.md +1 -3
  4. data/ext/pqcrypto/pqcrypto_ruby_secure.c +41 -11
  5. data/ext/pqcrypto/pqcrypto_secure.c +501 -296
  6. data/ext/pqcrypto/pqcrypto_version.h +1 -1
  7. data/ext/pqcrypto/vendor/.vendored +7 -7
  8. data/ext/pqcrypto/vendor/mldsa-native/BUILDING.md +71 -0
  9. data/ext/pqcrypto/vendor/mldsa-native/README.md +26 -11
  10. data/ext/pqcrypto/vendor/mldsa-native/RELEASE.md +77 -150
  11. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.c +93 -40
  12. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.h +74 -59
  13. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_asm.S +106 -40
  14. data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_config.h +94 -92
  15. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/capability.h +31 -0
  16. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/cbmc.h +55 -4
  17. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/common.h +30 -0
  18. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/context.h +1 -0
  19. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/debug.c +1 -0
  20. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202.h +1 -0
  21. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_aarch64_asm.S +5 -2
  22. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_aarch64_asm.S +4 -4
  23. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_aarch64_asm.S +4 -4
  24. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm.S +8 -3
  25. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm.S +8 -4
  26. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/mve.h +12 -0
  27. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +4 -2
  28. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_state_extract_bytes_mve.S +37 -19
  29. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_state_xor_bytes_mve.S +37 -19
  30. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/auto.h +3 -8
  31. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/auto.h +53 -0
  32. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/keccak_f1600_x1_avx512.h +38 -0
  33. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/keccak_f1600_x4_avx512.h +38 -0
  34. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/fips202_native_x86_64.h +24 -0
  35. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccak_f1600_x1_avx512_asm.S +574 -0
  36. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccak_f1600_x4_avx2_asm.S +46 -18
  37. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccak_f1600_x4_avx512_asm.S +679 -0
  38. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccakf1600_constants.c +13 -4
  39. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/meta.h +6 -4
  40. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/arith_native_aarch64.h +5 -6
  41. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_intt_aarch64_asm.S +4 -2
  42. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_ntt_aarch64_asm.S +4 -2
  43. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_pointwise_montgomery_aarch64_asm.S +6 -4
  44. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_caddq_aarch64_asm.S +4 -2
  45. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_chknorm_aarch64_asm.S +6 -4
  46. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_decompose_32_aarch64_asm.S +4 -3
  47. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_decompose_88_aarch64_asm.S +4 -3
  48. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_use_hint_32_aarch64_asm.S +4 -3
  49. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_poly_use_hint_88_aarch64_asm.S +4 -3
  50. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyvecl_pointwise_acc_montgomery_l4_aarch64_asm.S +4 -2
  51. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyvecl_pointwise_acc_montgomery_l5_aarch64_asm.S +4 -2
  52. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyvecl_pointwise_acc_montgomery_l7_aarch64_asm.S +4 -2
  53. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyz_unpack_17_aarch64_asm.S +5 -3
  54. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_polyz_unpack_19_aarch64_asm.S +5 -3
  55. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_rej_uniform_aarch64_asm.S +110 -120
  56. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_rej_uniform_eta2_aarch64_asm.S +109 -101
  57. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mldsa_rej_uniform_eta4_aarch64_asm.S +97 -93
  58. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/api.h +1 -9
  59. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/meta.h +4 -0
  60. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/fastmul.h +74 -0
  61. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/slowmul.h +77 -0
  62. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/src/arith_native_rv32im.h +124 -0
  63. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/src/mldsa_intt_rv32im_asm.S +331 -0
  64. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/src/mldsa_intt_rv32im_slowmul_asm.S +381 -0
  65. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/src/mldsa_ntt_rv32im_asm.S +304 -0
  66. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/src/mldsa_ntt_rv32im_slowmul_asm.S +351 -0
  67. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/src/mldsa_poly_pointwise_montgomery_rv32im_asm.S +139 -0
  68. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/rv32im/src/rv32im_zetas.c +118 -0
  69. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/meta.h +6 -5
  70. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/arith_native_x86_64.h +2 -3
  71. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_intt_avx2_asm.S +5 -3
  72. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_ntt_avx2_asm.S +5 -3
  73. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_nttunpack_avx2_asm.S +5 -3
  74. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_pointwise_acc_l4_avx2_asm.S +6 -3
  75. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_pointwise_acc_l5_avx2_asm.S +6 -3
  76. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_pointwise_acc_l7_avx2_asm.S +6 -3
  77. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_pointwise_avx2_asm.S +5 -3
  78. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_caddq_avx2_asm.S +5 -3
  79. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_chknorm_avx2_asm.S +7 -5
  80. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_decompose_32_avx2_asm.S +69 -67
  81. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_decompose_88_avx2_asm.S +69 -67
  82. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_use_hint_32_avx2_asm.S +12 -16
  83. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_use_hint_88_avx2_asm.S +14 -18
  84. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_polyz_unpack_17_avx2_asm.S +6 -3
  85. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_polyz_unpack_19_avx2_asm.S +6 -3
  86. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_avx2_asm.S +5 -3
  87. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_eta2_avx2_asm.S +5 -3
  88. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_eta4_avx2_asm.S +5 -3
  89. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.c +23 -27
  90. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.h +21 -42
  91. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/params.h +28 -1
  92. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.c +87 -28
  93. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.h +61 -3
  94. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.c +23 -19
  95. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.h +30 -0
  96. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.c +55 -107
  97. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.h +67 -107
  98. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec_lazy.c +16 -24
  99. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec_lazy.h +27 -21
  100. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/reduce.h +8 -8
  101. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.c +191 -119
  102. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.h +6 -3
  103. data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sys.h +16 -42
  104. data/ext/pqcrypto/vendor/mlkem-native/BUILDING.md +72 -0
  105. data/ext/pqcrypto/vendor/mlkem-native/README.md +9 -5
  106. data/ext/pqcrypto/vendor/mlkem-native/RELEASE.md +64 -312
  107. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.c +77 -34
  108. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.h +41 -13
  109. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_asm.S +89 -33
  110. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_config.h +50 -46
  111. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/capability.h +30 -0
  112. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/common.h +30 -0
  113. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.c +1 -0
  114. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.h +4 -5
  115. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/debug.c +1 -0
  116. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202.c +15 -0
  117. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202.h +23 -8
  118. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202x4.c +11 -3
  119. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202x4.h +7 -1
  120. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/keccakf1600.c +8 -0
  121. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/keccakf1600.h +8 -0
  122. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_aarch64_asm.S +5 -2
  123. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_aarch64_asm.S +4 -4
  124. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_aarch64_asm.S +4 -4
  125. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm.S +8 -3
  126. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm.S +8 -4
  127. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +4 -2
  128. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccak_f1600_x4_state_extract_bytes_mve.S +37 -19
  129. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccak_f1600_x4_state_xor_bytes_mve.S +37 -19
  130. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/auto.h +2 -2
  131. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/auto.h +47 -0
  132. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/keccak_f1600_x1_avx512.h +37 -0
  133. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/keccak_f1600_x4_avx512.h +37 -0
  134. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/fips202_native_x86_64.h +24 -0
  135. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccak_f1600_x1_avx512_asm.S +573 -0
  136. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccak_f1600_x4_avx2_asm.S +46 -18
  137. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccak_f1600_x4_avx512_asm.S +678 -0
  138. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccakf1600_constants.c +13 -4
  139. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/indcpa.c +1 -2
  140. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.c +7 -5
  141. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.h +29 -5
  142. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/meta.h +156 -0
  143. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/arith_native_aarch64.h +137 -3
  144. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/compress_d5_table.c +43 -0
  145. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/decompress_d10_table.c +50 -0
  146. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/decompress_d11_table.c +53 -0
  147. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/decompress_d4_table.c +44 -0
  148. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/decompress_d5_table.c +53 -0
  149. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_intt_aarch64_asm.S +5 -3
  150. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_ntt_aarch64_asm.S +4 -2
  151. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_compress_d10_aarch64_asm.S +439 -0
  152. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_compress_d11_aarch64_asm.S +452 -0
  153. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_compress_d4_aarch64_asm.S +106 -0
  154. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_compress_d5_aarch64_asm.S +124 -0
  155. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_decompress_d10_aarch64_asm.S +108 -0
  156. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_decompress_d11_aarch64_asm.S +116 -0
  157. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_decompress_d4_aarch64_asm.S +93 -0
  158. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_decompress_d5_aarch64_asm.S +104 -0
  159. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_frombytes_aarch64_asm.S +84 -0
  160. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_mulcache_compute_aarch64_asm.S +4 -2
  161. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_reduce_aarch64_asm.S +4 -2
  162. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_tobytes_aarch64_asm.S +5 -3
  163. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_poly_tomont_aarch64_asm.S +4 -3
  164. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_polyvec_basemul_acc_montgomery_cached_k2_aarch64_asm.S +4 -2
  165. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_polyvec_basemul_acc_montgomery_cached_k3_aarch64_asm.S +4 -2
  166. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_polyvec_basemul_acc_montgomery_cached_k4_aarch64_asm.S +4 -2
  167. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/mlkem_rej_uniform_aarch64_asm.S +112 -104
  168. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/api.h +0 -1
  169. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/meta.h +2 -2
  170. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/README.md +2 -2
  171. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/meta.h +16 -21
  172. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/arith_native_ppc64le.h +1 -0
  173. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/consts.c +2 -2
  174. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/mlkem_intt_ppc_asm.S +6 -5
  175. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/mlkem_ntt_ppc_asm.S +6 -5
  176. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/mlkem_poly_tomont_ppc_asm.S +6 -5
  177. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/mlkem_reduce_ppc_asm.S +6 -5
  178. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_debug.c +5 -4
  179. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_debug.h +2 -2
  180. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_poly.c +1 -1
  181. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/arith_native_x86_64.h +5 -5
  182. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_intt_avx2_asm.S +36 -33
  183. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_ntt_avx2_asm.S +67 -65
  184. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_nttfrombytes_avx2_asm.S +8 -5
  185. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_ntttobytes_avx2_asm.S +6 -3
  186. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_nttunpack_avx2_asm.S +5 -3
  187. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_compress_d10_avx2_asm.S +7 -5
  188. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_compress_d11_avx2_asm.S +7 -4
  189. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_compress_d4_avx2_asm.S +7 -5
  190. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_compress_d5_avx2_asm.S +7 -4
  191. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_decompress_d10_avx2_asm.S +7 -4
  192. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_decompress_d11_avx2_asm.S +6 -4
  193. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_decompress_d4_avx2_asm.S +7 -4
  194. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_decompress_d5_avx2_asm.S +6 -4
  195. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_poly_mulcache_compute_avx2_asm.S +5 -3
  196. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_polyvec_basemul_acc_montgomery_cached_k2_avx2_asm.S +118 -115
  197. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_polyvec_basemul_acc_montgomery_cached_k3_avx2_asm.S +174 -171
  198. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_polyvec_basemul_acc_montgomery_cached_k4_avx2_asm.S +230 -227
  199. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_reduce_avx2_asm.S +17 -15
  200. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_rej_uniform_avx2_asm.S +7 -6
  201. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mlkem_tomont_avx2_asm.S +5 -3
  202. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.c +4 -9
  203. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.h +1 -1
  204. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sys.h +31 -44
  205. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/verify.h +1 -1
  206. data/lib/pq_crypto/internal.rb +10 -0
  207. data/lib/pq_crypto/kem.rb +5 -10
  208. data/lib/pq_crypto/pkcs8/der.rb +26 -11
  209. data/lib/pq_crypto/pkcs8/private_key_choice.rb +21 -25
  210. data/lib/pq_crypto/signature.rb +28 -40
  211. data/lib/pq_crypto/spki.rb +36 -23
  212. data/lib/pq_crypto/version.rb +1 -1
  213. data/script/vendor_libs.rb +6 -6
  214. metadata +36 -1
@@ -7,6 +7,7 @@
7
7
  #define MLD_COMMON_H
8
8
 
9
9
  #ifndef __ASSEMBLER__
10
+ #include <stddef.h>
10
11
  #include <stdint.h>
11
12
  #endif
12
13
 
@@ -19,9 +20,31 @@
19
20
  #include "mldsa_native_config.h"
20
21
  #endif
21
22
 
23
+ #include "capability.h"
22
24
  #include "params.h"
23
25
  #include "sys.h"
24
26
 
27
+ #if !defined(MLD_CONFIG_NO_ASM) && (defined(__GNUC__) || defined(__clang__))
28
+ #define MLD_HAVE_INLINE_ASM
29
+ #endif
30
+
31
+ #if defined(MLD_CONFIG_CT_TESTING_ENABLED) && !defined(__ASSEMBLER__)
32
+ #include <valgrind/memcheck.h>
33
+ #define MLD_CT_TESTING_SECRET(ptr, len) \
34
+ VALGRIND_MAKE_MEM_UNDEFINED((ptr), (len))
35
+ #define MLD_CT_TESTING_DECLASSIFY(ptr, len) \
36
+ VALGRIND_MAKE_MEM_DEFINED((ptr), (len))
37
+ #else /* MLD_CONFIG_CT_TESTING_ENABLED && !__ASSEMBLER__ */
38
+ #define MLD_CT_TESTING_SECRET(ptr, len) \
39
+ do \
40
+ { \
41
+ } while (0)
42
+ #define MLD_CT_TESTING_DECLASSIFY(ptr, len) \
43
+ do \
44
+ { \
45
+ } while (0)
46
+ #endif /* !(MLD_CONFIG_CT_TESTING_ENABLED && !__ASSEMBLER__) */
47
+
25
48
  /* Internal and public API have external linkage by default, but
26
49
  * this can be overwritten by the user, e.g. for single-CU builds. */
27
50
  #if !defined(MLD_CONFIG_INTERNAL_API_QUALIFIER)
@@ -195,11 +218,18 @@
195
218
  /* Allocation macros for large local structures
196
219
  *
197
220
  * MLD_ALLOC(v, T, N) declares T *v and attempts to point it to an T[N]
221
+ * Additionally, if non-NULL, the value of v must respect
222
+ * MLD_DEFAULT_ALIGN alignment
198
223
  * MLD_FREE(v, T, N) zeroizes and frees the allocation
199
224
  *
200
225
  * Default implementation uses stack allocation.
201
226
  * Can be overridden by setting the config option MLD_CONFIG_CUSTOM_ALLOC_FREE
202
227
  * and defining MLD_CUSTOM_ALLOC and MLD_CUSTOM_FREE.
228
+ *
229
+ * Plain malloc() does not guarantee MLD_DEFAULT_ALIGN alignment.
230
+ * For examples of custom allocators that meet this requirement, see
231
+ * test/configs/custom_heap_alloc_config.h or the allocator in
232
+ * test/src/test_alloc.c configured by test/configs/test_alloc_config.h.
203
233
  */
204
234
  #if defined(MLD_CONFIG_CUSTOM_ALLOC_FREE) != \
205
235
  (defined(MLD_CUSTOM_ALLOC) && defined(MLD_CUSTOM_FREE))
@@ -10,6 +10,7 @@
10
10
  #if !defined(__ASSEMBLER__)
11
11
 
12
12
  #include <stdint.h>
13
+
13
14
  #include "cbmc.h"
14
15
  #include "sys.h"
15
16
 
@@ -15,6 +15,7 @@
15
15
  #include <inttypes.h>
16
16
  #include <stdio.h>
17
17
  #include <stdlib.h>
18
+
18
19
  #include "debug.h"
19
20
 
20
21
  #define MLD_DEBUG_ERROR_HEADER "[ERROR:%s:%04d] "
@@ -6,6 +6,7 @@
6
6
  #define MLD_FIPS202_FIPS202_H
7
7
 
8
8
  #include <stddef.h>
9
+
9
10
  #include "../cbmc.h"
10
11
  #include "../common.h"
11
12
 
@@ -34,7 +34,8 @@
34
34
  */
35
35
 
36
36
  #include "../../../../common.h"
37
- #if defined(MLD_FIPS202_AARCH64_NEED_X1_SCALAR) && \
37
+ #if defined(MLD_SYS_AARCH64) && \
38
+ defined(MLD_FIPS202_AARCH64_NEED_X1_SCALAR) && \
38
39
  !defined(MLD_CONFIG_MULTILEVEL_NO_SHARED)
39
40
 
40
41
  /*
@@ -345,6 +346,8 @@ Lmld_keccak_f1600_x1_scalar_loop:
345
346
  stp x5, x10, [x0, #0xa0]
346
347
  stp x15, x20, [x0, #0xb0]
347
348
  str x25, [x0, #0xc0]
349
+ stp xzr, xzr, [sp]
350
+ stp xzr, xzr, [sp, #0x10]
348
351
  ldp x19, x20, [sp, #0x20]
349
352
  .cfi_restore x19
350
353
  .cfi_restore x20
@@ -370,7 +373,7 @@ Lmld_keccak_f1600_x1_scalar_loop:
370
373
 
371
374
  MLD_ASM_FN_SIZE(keccak_f1600_x1_scalar_aarch64_asm)
372
375
 
373
- #endif /* MLD_FIPS202_AARCH64_NEED_X1_SCALAR && \
376
+ #endif /* MLD_SYS_AARCH64 && MLD_FIPS202_AARCH64_NEED_X1_SCALAR && \
374
377
  !MLD_CONFIG_MULTILEVEL_NO_SHARED */
375
378
 
376
379
  #if defined(__ELF__)
@@ -50,10 +50,10 @@
50
50
  //
51
51
 
52
52
  #include "../../../../common.h"
53
- #if defined(MLD_FIPS202_AARCH64_NEED_X1_V84A) && \
53
+ #if defined(MLD_SYS_AARCH64_NEON) && defined(__ARM_FEATURE_SHA3) && \
54
+ defined(MLD_FIPS202_AARCH64_NEED_X1_V84A) && \
54
55
  !defined(MLD_CONFIG_MULTILEVEL_NO_SHARED)
55
56
 
56
- #if defined(__ARM_FEATURE_SHA3)
57
57
 
58
58
  /*
59
59
  * WARNING: This file is auto-derived from the mldsa-native source file
@@ -197,9 +197,9 @@ Lmld_keccak_f1600_x1_v84a_loop:
197
197
 
198
198
  MLD_ASM_FN_SIZE(keccak_f1600_x1_v84a_aarch64_asm)
199
199
 
200
- #endif /* __ARM_FEATURE_SHA3 */
201
200
 
202
- #endif /* MLD_FIPS202_AARCH64_NEED_X1_V84A && !MLD_CONFIG_MULTILEVEL_NO_SHARED \
201
+ #endif /* MLD_SYS_AARCH64_NEON && __ARM_FEATURE_SHA3 && \
202
+ MLD_FIPS202_AARCH64_NEED_X1_V84A && !MLD_CONFIG_MULTILEVEL_NO_SHARED \
203
203
  */
204
204
 
205
205
  #if defined(__ELF__)
@@ -50,10 +50,10 @@
50
50
  //
51
51
 
52
52
  #include "../../../../common.h"
53
- #if defined(MLD_FIPS202_AARCH64_NEED_X2_V84A) && \
53
+ #if defined(MLD_SYS_AARCH64_NEON) && defined(__ARM_FEATURE_SHA3) && \
54
+ defined(MLD_FIPS202_AARCH64_NEED_X2_V84A) && \
54
55
  !defined(MLD_CONFIG_MULTILEVEL_NO_SHARED)
55
56
 
56
- #if defined(__ARM_FEATURE_SHA3)
57
57
 
58
58
  /*
59
59
  * WARNING: This file is auto-derived from the mldsa-native source file
@@ -252,9 +252,9 @@ Lmld_keccak_f1600_x2_v84a_loop:
252
252
 
253
253
  MLD_ASM_FN_SIZE(keccak_f1600_x2_v84a_aarch64_asm)
254
254
 
255
- #endif /* __ARM_FEATURE_SHA3 */
256
255
 
257
- #endif /* MLD_FIPS202_AARCH64_NEED_X2_V84A && !MLD_CONFIG_MULTILEVEL_NO_SHARED \
256
+ #endif /* MLD_SYS_AARCH64_NEON && __ARM_FEATURE_SHA3 && \
257
+ MLD_FIPS202_AARCH64_NEED_X2_V84A && !MLD_CONFIG_MULTILEVEL_NO_SHARED \
258
258
  */
259
259
 
260
260
  #if defined(__ELF__)
@@ -35,7 +35,8 @@
35
35
  */
36
36
 
37
37
  #include "../../../../common.h"
38
- #if defined(MLD_FIPS202_AARCH64_NEED_X4_V8A_SCALAR_HYBRID) && \
38
+ #if defined(MLD_SYS_AARCH64_NEON) && \
39
+ defined(MLD_FIPS202_AARCH64_NEED_X4_V8A_SCALAR_HYBRID) && \
39
40
  !defined(MLD_CONFIG_MULTILEVEL_NO_SHARED)
40
41
 
41
42
  /*
@@ -1035,6 +1036,10 @@ Lmld_keccak_f1600_x4_v8a_scalar_hybrid_done:
1035
1036
  str d24, [x0]
1036
1037
  trn2 v25.2d, v24.2d, v24.2d
1037
1038
  str d25, [x4]
1039
+ stp xzr, xzr, [sp]
1040
+ stp xzr, xzr, [sp, #0x10]
1041
+ str xzr, [sp, #0x20]
1042
+ str xzr, [sp, #0xd0]
1038
1043
  ldp d8, d9, [sp, #0x90]
1039
1044
  .cfi_restore d8
1040
1045
  .cfi_restore d9
@@ -1072,8 +1077,8 @@ Lmld_keccak_f1600_x4_v8a_scalar_hybrid_done:
1072
1077
 
1073
1078
  MLD_ASM_FN_SIZE(keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm)
1074
1079
 
1075
- #endif /* MLD_FIPS202_AARCH64_NEED_X4_V8A_SCALAR_HYBRID && \
1076
- !MLD_CONFIG_MULTILEVEL_NO_SHARED */
1080
+ #endif /* MLD_SYS_AARCH64_NEON && MLD_FIPS202_AARCH64_NEED_X4_V8A_SCALAR_HYBRID \
1081
+ && !MLD_CONFIG_MULTILEVEL_NO_SHARED */
1077
1082
 
1078
1083
  #if defined(__ELF__)
1079
1084
  .section .note.GNU-stack,"",%progbits
@@ -35,10 +35,10 @@
35
35
  */
36
36
 
37
37
  #include "../../../../common.h"
38
- #if defined(MLD_FIPS202_AARCH64_NEED_X4_V8A_V84A_SCALAR_HYBRID) && \
38
+ #if defined(MLD_SYS_AARCH64_NEON) && defined(__ARM_FEATURE_SHA3) && \
39
+ defined(MLD_FIPS202_AARCH64_NEED_X4_V8A_V84A_SCALAR_HYBRID) && \
39
40
  !defined(MLD_CONFIG_MULTILEVEL_NO_SHARED)
40
41
 
41
- #if defined(__ARM_FEATURE_SHA3)
42
42
 
43
43
  /*
44
44
  * WARNING: This file is auto-derived from the mldsa-native source file
@@ -943,6 +943,10 @@ Lmld_keccak_f1600_x4_v8a_v84a_scalar_hybrid_done:
943
943
  str d24, [x0]
944
944
  trn2 v25.2d, v24.2d, v24.2d
945
945
  str d25, [x4]
946
+ stp xzr, xzr, [sp]
947
+ stp xzr, xzr, [sp, #0x10]
948
+ str xzr, [sp, #0x20]
949
+ str xzr, [sp, #0xd0]
946
950
  ldp d8, d9, [sp, #0x90]
947
951
  .cfi_restore d8
948
952
  .cfi_restore d9
@@ -980,9 +984,9 @@ Lmld_keccak_f1600_x4_v8a_v84a_scalar_hybrid_done:
980
984
 
981
985
  MLD_ASM_FN_SIZE(keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm)
982
986
 
983
- #endif /* __ARM_FEATURE_SHA3 */
984
987
 
985
- #endif /* MLD_FIPS202_AARCH64_NEED_X4_V8A_V84A_SCALAR_HYBRID && \
988
+ #endif /* MLD_SYS_AARCH64_NEON && __ARM_FEATURE_SHA3 && \
989
+ MLD_FIPS202_AARCH64_NEED_X4_V8A_V84A_SCALAR_HYBRID && \
986
990
  !MLD_CONFIG_MULTILEVEL_NO_SHARED */
987
991
 
988
992
  #if defined(__ELF__)
@@ -32,6 +32,10 @@ int mld_keccak_f1600_x4_native_impl(uint64_t *state);
32
32
  MLD_MUST_CHECK_RETURN_VALUE
33
33
  static MLD_INLINE int mld_keccak_f1600_x4_native(uint64_t *state)
34
34
  {
35
+ if (!mld_sys_check_capability(MLD_SYS_CAP_ARMV81M_MVE))
36
+ {
37
+ return MLD_NATIVE_FUNC_FALLBACK;
38
+ }
35
39
  return mld_keccak_f1600_x4_native_impl(state);
36
40
  }
37
41
 
@@ -44,6 +48,10 @@ static MLD_INLINE int mld_keccakf1600_xor_bytes_x4_native(
44
48
  const uint8_t *data2, const uint8_t *data3, unsigned offset,
45
49
  unsigned length)
46
50
  {
51
+ if (!mld_sys_check_capability(MLD_SYS_CAP_ARMV81M_MVE))
52
+ {
53
+ return MLD_NATIVE_FUNC_FALLBACK;
54
+ }
47
55
  mld_keccak_f1600_x4_state_xor_bytes_asm(state, data0, data1, data2, data3,
48
56
  offset, length);
49
57
  return MLD_NATIVE_FUNC_SUCCESS;
@@ -57,6 +65,10 @@ static MLD_INLINE int mld_keccakf1600_extract_bytes_x4_native(
57
65
  uint64_t *state, uint8_t *data0, uint8_t *data1, uint8_t *data2,
58
66
  uint8_t *data3, unsigned offset, unsigned length)
59
67
  {
68
+ if (!mld_sys_check_capability(MLD_SYS_CAP_ARMV81M_MVE))
69
+ {
70
+ return MLD_NATIVE_FUNC_FALLBACK;
71
+ }
60
72
  mld_keccak_f1600_x4_state_extract_bytes_asm(state, data0, data1, data2, data3,
61
73
  offset, length);
62
74
  return MLD_NATIVE_FUNC_SUCCESS;
@@ -67,7 +67,8 @@
67
67
  // 784 S[0][24]_odd, S[1][24]_odd, S[2][24]_odd, S[3][24]_odd
68
68
 
69
69
  #include "../../../../common.h"
70
- #if defined(MLD_FIPS202_ARMV81M_NEED_X4) && \
70
+ #if defined(MLD_SYS_ARMV81M_MVE) && \
71
+ defined(MLD_FIPS202_ARMV81M_NEED_X4) && \
71
72
  !defined(MLD_CONFIG_MULTILEVEL_NO_SHARED)
72
73
 
73
74
  /*
@@ -710,7 +711,8 @@ Lmld_keccak_f1600_x4_mve_asm_roundend:
710
711
 
711
712
  MLD_ASM_FN_SIZE(keccak_f1600_x4_mve_asm)
712
713
 
713
- #endif /* MLD_FIPS202_ARMV81M_NEED_X4 && !MLD_CONFIG_MULTILEVEL_NO_SHARED */
714
+ #endif /* MLD_SYS_ARMV81M_MVE && MLD_FIPS202_ARMV81M_NEED_X4 && \
715
+ !MLD_CONFIG_MULTILEVEL_NO_SHARED */
714
716
 
715
717
  #if defined(__ELF__)
716
718
  .section .note.GNU-stack,"",%progbits
@@ -53,11 +53,13 @@
53
53
  // Prologue -- if offset is not 8-byte aligned, extract
54
54
  // min(length, 8-(offset%8)) bytes via predicated byte stores.
55
55
  // Main -- process full 8-byte groups: load even/odd lane pair,
56
- // de-interleave, scatter-store to output buffers.
56
+ // de-interleave, scatter-store to aligned output buffers
57
+ // or use predicated byte stores for unaligned buffers.
57
58
  // Tail -- extract remaining <8 bytes via predicated byte stores.
58
59
 
59
60
  #include "../../../../common.h"
60
- #if defined(MLD_FIPS202_ARMV81M_NEED_X4) && \
61
+ #if defined(MLD_SYS_ARMV81M_MVE) && \
62
+ defined(MLD_FIPS202_ARMV81M_NEED_X4) && \
61
63
  !defined(MLD_CONFIG_MULTILEVEL_NO_SHARED)
62
64
 
63
65
  /*
@@ -99,13 +101,13 @@ MLD_ASM_FN_SYMBOL(keccak_f1600_x4_state_extract_bytes_asm)
99
101
  ldr.w r10, [sp, #0x6c]
100
102
  ldr r6, [sp, #0x70]
101
103
  cmp r6, #0x0
102
- beq.w Lmld_keccak_f1600_x4_state_extract_bytes_asm_exit @ imm = #0x2ea
104
+ beq.w Lmld_keccak_f1600_x4_state_extract_bytes_asm_exit @ imm = #0x308
103
105
  and r5, r10, #0x7
104
106
  bic r9, r10, #0x7
105
107
  add.w r8, r0, r9, lsl #1
106
108
  add.w r7, r8, #0x190
107
109
  cmp r5, #0x0
108
- beq.w Lmld_keccak_f1600_x4_state_extract_bytes_asm_pre_main @ imm = #0x112
110
+ beq.w Lmld_keccak_f1600_x4_state_extract_bytes_asm_pre_main @ imm = #0x108
109
111
  vldrw.u32 q0, [r8], #16
110
112
  vldrw.u32 q1, [r7], #16
111
113
  vrev32.16 q2, q0
@@ -169,18 +171,20 @@ MLD_ASM_FN_SYMBOL(keccak_f1600_x4_state_extract_bytes_asm)
169
171
  subs r3, r3, r5
170
172
  subs r4, r4, r5
171
173
  vpstttt
172
- vstrbt.8 q0, [r1], #4
173
- vstrbt.8 q1, [r2], #4
174
- vstrbt.8 q2, [r3], #4
175
- vstrbt.8 q3, [r4], #4
174
+ vstrbt.8 q0, [r1], #8
175
+ vstrbt.8 q1, [r2], #8
176
+ vstrbt.8 q2, [r3], #8
177
+ vstrbt.8 q3, [r4], #8
176
178
  subs.w r6, r6, lr
177
179
  cmp r6, #0x0
178
- beq.w Lmld_keccak_f1600_x4_state_extract_bytes_asm_exit @ imm = #0x1cc
179
- vmov q7[2], q7[0], r1, r3
180
- vmov q7[3], q7[1], r2, r4
181
- b Lmld_keccak_f1600_x4_state_extract_bytes_asm_main_body @ imm = #0xe
180
+ beq.w Lmld_keccak_f1600_x4_state_extract_bytes_asm_exit @ imm = #0x1ea
182
181
 
183
182
  Lmld_keccak_f1600_x4_state_extract_bytes_asm_pre_main:
183
+ orr.w r12, r1, r2
184
+ orr.w r12, r12, r3
185
+ orr.w r12, r12, r4
186
+ tst.w r12, #0x3
187
+ bne Lmld_keccak_f1600_x4_state_extract_bytes_asm_main_body_byte @ imm = #0xe2
184
188
  vmov q7[2], q7[0], r1, r3
185
189
  vmov q7[3], q7[1], r2, r4
186
190
  mov.w r12, #0x4
@@ -239,11 +243,17 @@ Lmld_keccak_f1600_x4_state_extract_bytes_asm_main_loop_start:
239
243
 
240
244
  Lmld_keccak_f1600_x4_state_extract_bytes_asm_main_loop_end:
241
245
  ands r6, r6, #0x7
242
- beq Lmld_keccak_f1600_x4_state_extract_bytes_asm_exit @ imm = #0xee
246
+ beq.w Lmld_keccak_f1600_x4_state_extract_bytes_asm_exit @ imm = #0x104
243
247
  mov.w r12, #0x4
244
248
  vadd.i32 q7, q7, r12
245
249
  vmov r1, r3, q7[2], q7[0]
246
250
  vmov r2, r4, q7[3], q7[1]
251
+
252
+ Lmld_keccak_f1600_x4_state_extract_bytes_asm_main_body_byte:
253
+ cmp r6, #0x0
254
+ beq Lmld_keccak_f1600_x4_state_extract_bytes_asm_exit @ imm = #0xee
255
+
256
+ Lmld_keccak_f1600_x4_state_extract_bytes_asm_main_loop_byte_start:
247
257
  vldrw.u32 q0, [r8], #16
248
258
  vldrw.u32 q1, [r7], #16
249
259
  vrev32.16 q2, q0
@@ -294,12 +304,18 @@ Lmld_keccak_f1600_x4_state_extract_bytes_asm_main_loop_end:
294
304
  vpsel q1, q2, q1
295
305
  vmov.f64 d4, d1
296
306
  vmov.f64 d6, d3
297
- vctp.8 r6
307
+ mov.w lr, #0x8
308
+ cmp r6, #0x8
309
+ it lo
310
+ movlo lr, r6
311
+ vctp.8 lr
298
312
  vpstttt
299
- vstrbt.8 q0, [r1], #4
300
- vstrbt.8 q1, [r2], #4
301
- vstrbt.8 q2, [r3], #4
302
- vstrbt.8 q3, [r4], #4
313
+ vstrbt.8 q0, [r1], #8
314
+ vstrbt.8 q1, [r2], #8
315
+ vstrbt.8 q2, [r3], #8
316
+ vstrbt.8 q3, [r4], #8
317
+ subs.w r6, r6, lr
318
+ bne Lmld_keccak_f1600_x4_state_extract_bytes_asm_main_loop_byte_start @ imm = #-0xf2
303
319
 
304
320
  Lmld_keccak_f1600_x4_state_extract_bytes_asm_exit:
305
321
  vpop {d8, d9, d10, d11, d12, d13, d14, d15}
@@ -324,10 +340,12 @@ Lmld_keccak_f1600_x4_state_extract_bytes_asm_exit:
324
340
  .cfi_restore lr
325
341
  .cfi_adjust_cfa_offset -0x28
326
342
  .cfi_endproc
343
+ nop
327
344
 
328
345
  MLD_ASM_FN_SIZE(keccak_f1600_x4_state_extract_bytes_asm)
329
346
 
330
- #endif /* MLD_FIPS202_ARMV81M_NEED_X4 && !MLD_CONFIG_MULTILEVEL_NO_SHARED */
347
+ #endif /* MLD_SYS_ARMV81M_MVE && MLD_FIPS202_ARMV81M_NEED_X4 && \
348
+ !MLD_CONFIG_MULTILEVEL_NO_SHARED */
331
349
 
332
350
  #if defined(__ELF__)
333
351
  .section .note.GNU-stack,"",%progbits
@@ -51,12 +51,14 @@
51
51
  // ---------------------------------------------------------------------------
52
52
  // Prologue -- if offset is not 8-byte aligned, absorb
53
53
  // min(length, 8-(offset%8)) bytes via predicated byte loads.
54
- // Main -- process full 8-byte groups via word-level gather loads,
55
- // bit-interleave, then VEOR into even/odd state halves.
54
+ // Main -- process full 8-byte groups via vldrw.u32 gather loads when
55
+ // 32-bit aligned, otherwise byte loads; bit-interleave, then
56
+ // VEOR into even/odd state halves.
56
57
  // Tail -- absorb remaining <8 bytes via predicated byte loads.
57
58
 
58
59
  #include "../../../../common.h"
59
- #if defined(MLD_FIPS202_ARMV81M_NEED_X4) && \
60
+ #if defined(MLD_SYS_ARMV81M_MVE) && \
61
+ defined(MLD_FIPS202_ARMV81M_NEED_X4) && \
60
62
  !defined(MLD_CONFIG_MULTILEVEL_NO_SHARED)
61
63
 
62
64
  /*
@@ -98,13 +100,13 @@ MLD_ASM_FN_SYMBOL(keccak_f1600_x4_state_xor_bytes_asm)
98
100
  ldr.w r10, [sp, #0x6c]
99
101
  ldr r6, [sp, #0x70]
100
102
  cmp r6, #0x0
101
- beq.w Lmld_keccak_f1600_x4_state_xor_bytes_asm_exit @ imm = #0x346
103
+ beq.w Lmld_keccak_f1600_x4_state_xor_bytes_asm_exit @ imm = #0x368
102
104
  and r5, r10, #0x7
103
105
  bic r9, r10, #0x7
104
106
  add.w r8, r0, r9, lsl #1
105
107
  add.w r7, r8, #0x190
106
108
  cmp r5, #0x0
107
- beq.w Lmld_keccak_f1600_x4_state_xor_bytes_asm_pre_main @ imm = #0x12c
109
+ beq.w Lmld_keccak_f1600_x4_state_xor_bytes_asm_pre_main @ imm = #0x122
108
110
  subs r1, r1, r5
109
111
  subs r2, r2, r5
110
112
  subs r3, r3, r5
@@ -119,10 +121,10 @@ MLD_ASM_FN_SYMBOL(keccak_f1600_x4_state_xor_bytes_asm)
119
121
  lsl.w r11, r11, r5
120
122
  vmsr p0, r11
121
123
  vpstttt
122
- vldrbt.u8 q0, [r1], #4
123
- vldrbt.u8 q1, [r2], #4
124
- vldrbt.u8 q2, [r3], #4
125
- vldrbt.u8 q3, [r4], #4
124
+ vldrbt.u8 q0, [r1], #8
125
+ vldrbt.u8 q1, [r2], #8
126
+ vldrbt.u8 q2, [r3], #8
127
+ vldrbt.u8 q3, [r4], #8
126
128
  vmov.f64 d1, d4
127
129
  vmov.f64 d3, d6
128
130
  vrev64.32 q2, q0
@@ -181,11 +183,13 @@ MLD_ASM_FN_SYMBOL(keccak_f1600_x4_state_xor_bytes_asm)
181
183
  veor q5, q5, q1
182
184
  vstrw.32 q4, [r8], #16
183
185
  vstrw.32 q5, [r7], #16
184
- vmov q7[2], q7[0], r1, r3
185
- vmov q7[3], q7[1], r2, r4
186
- b Lmld_keccak_f1600_x4_state_xor_bytes_asm_main_body @ imm = #0xe
187
186
 
188
187
  Lmld_keccak_f1600_x4_state_xor_bytes_asm_pre_main:
188
+ orr.w r0, r1, r2
189
+ orr.w r0, r0, r3
190
+ orr.w r0, r0, r4
191
+ tst.w r0, #0x3
192
+ bne.w Lmld_keccak_f1600_x4_state_xor_bytes_asm_main_body_byte @ imm = #0x104
189
193
  vmov q7[2], q7[0], r1, r3
190
194
  vmov q7[3], q7[1], r2, r4
191
195
  mov.w r0, #0x4
@@ -252,17 +256,27 @@ Lmld_keccak_f1600_x4_state_xor_bytes_asm_main_loop_start:
252
256
 
253
257
  Lmld_keccak_f1600_x4_state_xor_bytes_asm_main_loop_end:
254
258
  ands r6, r6, #0x7
255
- beq.w Lmld_keccak_f1600_x4_state_xor_bytes_asm_exit @ imm = #0x110
259
+ beq.w Lmld_keccak_f1600_x4_state_xor_bytes_asm_exit @ imm = #0x128
256
260
  mov.w r0, #0x4
257
261
  vadd.i32 q7, q7, r0
258
262
  vmov r1, r3, q7[2], q7[0]
259
263
  vmov r2, r4, q7[3], q7[1]
260
- vctp.8 r6
264
+
265
+ Lmld_keccak_f1600_x4_state_xor_bytes_asm_main_body_byte:
266
+ cmp r6, #0x0
267
+ beq.w Lmld_keccak_f1600_x4_state_xor_bytes_asm_exit @ imm = #0x112
268
+
269
+ Lmld_keccak_f1600_x4_state_xor_bytes_asm_main_loop_byte_start:
270
+ mov.w lr, #0x8
271
+ cmp r6, #0x8
272
+ it lo
273
+ movlo lr, r6
274
+ vctp.8 lr
261
275
  vpstttt
262
- vldrbt.u8 q0, [r1]
263
- vldrbt.u8 q1, [r2]
264
- vldrbt.u8 q2, [r3]
265
- vldrbt.u8 q3, [r4]
276
+ vldrbt.u8 q0, [r1], #8
277
+ vldrbt.u8 q1, [r2], #8
278
+ vldrbt.u8 q2, [r3], #8
279
+ vldrbt.u8 q3, [r4], #8
266
280
  vmov.f64 d1, d4
267
281
  vmov.f64 d3, d6
268
282
  vrev64.32 q2, q0
@@ -321,6 +335,8 @@ Lmld_keccak_f1600_x4_state_xor_bytes_asm_main_loop_end:
321
335
  veor q5, q5, q1
322
336
  vstrw.32 q4, [r8], #16
323
337
  vstrw.32 q5, [r7], #16
338
+ subs.w r6, r6, lr
339
+ bne.w Lmld_keccak_f1600_x4_state_xor_bytes_asm_main_loop_byte_start @ imm = #-0x112
324
340
 
325
341
  Lmld_keccak_f1600_x4_state_xor_bytes_asm_exit:
326
342
  vpop {d8, d9, d10, d11, d12, d13, d14, d15}
@@ -345,10 +361,12 @@ Lmld_keccak_f1600_x4_state_xor_bytes_asm_exit:
345
361
  .cfi_restore lr
346
362
  .cfi_adjust_cfa_offset -0x28
347
363
  .cfi_endproc
364
+ nop
348
365
 
349
366
  MLD_ASM_FN_SIZE(keccak_f1600_x4_state_xor_bytes_asm)
350
367
 
351
- #endif /* MLD_FIPS202_ARMV81M_NEED_X4 && !MLD_CONFIG_MULTILEVEL_NO_SHARED */
368
+ #endif /* MLD_SYS_ARMV81M_MVE && MLD_FIPS202_ARMV81M_NEED_X4 && \
369
+ !MLD_CONFIG_MULTILEVEL_NO_SHARED */
352
370
 
353
371
  #if defined(__ELF__)
354
372
  .section .note.GNU-stack,"",%progbits
@@ -17,14 +17,9 @@
17
17
  #endif
18
18
 
19
19
  /* The x86_64 backend requires toolchain support for the SysV ABI */
20
- #if defined(MLD_SYS_X86_64_AVX2) && defined(MLD_SYSV_ABI_SUPPORTED) && \
21
- (!defined(MLD_CONFIG_NO_KEYPAIR_API) || \
22
- !defined(MLD_CONFIG_NO_SIGN_API) || !defined(MLD_CONFIG_REDUCE_RAM)) && \
23
- !defined(MLD_CONFIG_SERIAL_FIPS202_ONLY)
24
- #include "x86_64/keccak_f1600_x4_avx2.h"
25
- #endif /* MLD_SYS_X86_64_AVX2 && MLD_SYSV_ABI_SUPPORTED && \
26
- (!MLD_CONFIG_NO_KEYPAIR_API || !MLD_CONFIG_NO_SIGN_API || \
27
- !MLD_CONFIG_REDUCE_RAM) && !MLD_CONFIG_SERIAL_FIPS202_ONLY */
20
+ #if defined(MLD_SYS_X86_64) && defined(MLD_SYSV_ABI_SUPPORTED)
21
+ #include "x86_64/auto.h"
22
+ #endif
28
23
 
29
24
  /* We do not yet include the FIPS202 backend for Armv8.1-M+MVE by default
30
25
  * as it is still experimental and undergoing review. */
@@ -0,0 +1,53 @@
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_FIPS202_NATIVE_X86_64_AUTO_H
8
+ #define MLD_FIPS202_NATIVE_X86_64_AUTO_H
9
+ /* Default FIPS202 assembly profile for x86_64 systems */
10
+
11
+ /*
12
+ * Default logic to decide which implementation to use.
13
+ *
14
+ * Each function has a single implementation. If its capability check
15
+ * fails at runtime (see MLD_CONFIG_CUSTOM_CAPABILITY_FUNC), the function
16
+ * falls back to the default C code, not to another x86_64
17
+ * implementation. For example, if AVX-512 is enabled at compile time but
18
+ * the AVX-512 check fails, Keccak-f1600x4 is computed by four calls to
19
+ * Keccak-f1600, which runs in C; the AVX2 implementation of
20
+ * Keccak-f1600x4 is not used.
21
+ */
22
+
23
+ /*
24
+ * Keccak-f1600
25
+ *
26
+ * - If AVX-512 (F, VL and DQ) is enabled, we use the AVX-512
27
+ * implementation.
28
+ * - Otherwise, we fall back to the standard C implementation.
29
+ */
30
+ #if defined(MLD_SYS_X86_64_AVX512)
31
+ #include "keccak_f1600_x1_avx512.h"
32
+ #endif
33
+
34
+ /*
35
+ * Keccak-f1600x4
36
+ *
37
+ * - If AVX-512 (F, VL and DQ) is enabled, we use the AVX-512
38
+ * implementation.
39
+ * - Otherwise, if AVX2 is enabled, we use the AVX2 implementation.
40
+ * - Otherwise, Keccak-f1600x4 is computed by four calls to Keccak-f1600.
41
+ */
42
+ #if (!defined(MLD_CONFIG_NO_KEYPAIR_API) || \
43
+ !defined(MLD_CONFIG_NO_SIGN_API) || !defined(MLD_CONFIG_REDUCE_RAM)) && \
44
+ !defined(MLD_CONFIG_SERIAL_FIPS202_ONLY)
45
+ #if defined(MLD_SYS_X86_64_AVX512)
46
+ #include "keccak_f1600_x4_avx512.h"
47
+ #elif defined(MLD_SYS_X86_64_AVX2)
48
+ #include "keccak_f1600_x4_avx2.h"
49
+ #endif
50
+ #endif /* (!MLD_CONFIG_NO_KEYPAIR_API || !MLD_CONFIG_NO_SIGN_API || \
51
+ !MLD_CONFIG_REDUCE_RAM) && !MLD_CONFIG_SERIAL_FIPS202_ONLY */
52
+
53
+ #endif /* !MLD_FIPS202_NATIVE_X86_64_AUTO_H */
@@ -0,0 +1,38 @@
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_FIPS202_NATIVE_X86_64_KECCAK_F1600_X1_AVX512_H
8
+ #define MLD_FIPS202_NATIVE_X86_64_KECCAK_F1600_X1_AVX512_H
9
+
10
+ #include "../../../common.h"
11
+
12
+ #if !defined(MLD_SYS_X86_64_AVX512)
13
+ #error This backend can only be used if AVX-512 (F, VL and DQ) is enabled.
14
+ #endif
15
+
16
+ /* Guard for assembly file */
17
+ #define MLD_FIPS202_X86_64_NEED_X1_AVX512
18
+
19
+ /* Part of backend API */
20
+ #define MLD_USE_NATIVE_FIPS202_X1
21
+
22
+ #if !defined(__ASSEMBLER__)
23
+ #include "../api.h"
24
+ #include "src/fips202_native_x86_64.h"
25
+ MLD_MUST_CHECK_RETURN_VALUE
26
+ static MLD_INLINE int mld_keccak_f1600_x1_native(uint64_t *state)
27
+ {
28
+ if (!mld_sys_check_capability(MLD_SYS_CAP_X86_64_AVX512))
29
+ {
30
+ return MLD_NATIVE_FUNC_FALLBACK;
31
+ }
32
+
33
+ mld_keccak_f1600_x1_avx512_asm(state, mld_keccakf1600_round_constants);
34
+ return MLD_NATIVE_FUNC_SUCCESS;
35
+ }
36
+ #endif /* !__ASSEMBLER__ */
37
+
38
+ #endif /* !MLD_FIPS202_NATIVE_X86_64_KECCAK_F1600_X1_AVX512_H */
@@ -0,0 +1,38 @@
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_FIPS202_NATIVE_X86_64_KECCAK_F1600_X4_AVX512_H
8
+ #define MLD_FIPS202_NATIVE_X86_64_KECCAK_F1600_X4_AVX512_H
9
+
10
+ #include "../../../common.h"
11
+
12
+ #if !defined(MLD_SYS_X86_64_AVX512)
13
+ #error This backend can only be used if AVX-512 (F, VL and DQ) is enabled.
14
+ #endif
15
+
16
+ /* Guard for assembly file */
17
+ #define MLD_FIPS202_X86_64_NEED_X4_AVX512
18
+
19
+ /* Part of backend API */
20
+ #define MLD_USE_NATIVE_FIPS202_X4
21
+
22
+ #if !defined(__ASSEMBLER__)
23
+ #include "../api.h"
24
+ #include "src/fips202_native_x86_64.h"
25
+ MLD_MUST_CHECK_RETURN_VALUE
26
+ static MLD_INLINE int mld_keccak_f1600_x4_native(uint64_t *state)
27
+ {
28
+ if (!mld_sys_check_capability(MLD_SYS_CAP_X86_64_AVX512))
29
+ {
30
+ return MLD_NATIVE_FUNC_FALLBACK;
31
+ }
32
+
33
+ mld_keccak_f1600_x4_avx512_asm(state, mld_keccakf1600_round_constants);
34
+ return MLD_NATIVE_FUNC_SUCCESS;
35
+ }
36
+ #endif /* !__ASSEMBLER__ */
37
+
38
+ #endif /* !MLD_FIPS202_NATIVE_X86_64_KECCAK_F1600_X4_AVX512_H */