pq_crypto 0.6.3 → 0.6.5

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 (94) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +149 -17
  3. data/CHANGELOG.md +73 -0
  4. data/GET_STARTED.md +1 -1
  5. data/README.md +7 -2
  6. data/ext/pqcrypto/extconf.rb +264 -24
  7. data/ext/pqcrypto/pqcrypto_version.h +1 -1
  8. data/ext/pqcrypto/vendor/.vendored +4 -4
  9. data/ext/pqcrypto/vendor/mlkem-native/README.md +2 -4
  10. data/ext/pqcrypto/vendor/mlkem-native/RELEASE.md +98 -0
  11. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.c +8 -7
  12. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.h +21 -1
  13. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_asm.S +45 -44
  14. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_config.h +36 -0
  15. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/common.h +13 -30
  16. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.c +25 -5
  17. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.h +14 -0
  18. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/context.h +42 -0
  19. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/auto.h +20 -12
  20. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_aarch64_asm.S +5 -3
  21. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_aarch64_asm.S +5 -2
  22. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_aarch64_asm.S +5 -2
  23. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm.S +10 -7
  24. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm.S +10 -7
  25. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x1_v84a.h +2 -1
  26. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x2_v84a.h +2 -1
  27. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x4_v8a_scalar.h +5 -0
  28. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +2 -1
  29. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/mve.h +5 -19
  30. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +8 -5
  31. 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
  32. 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
  33. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccak_f1600_x4_avx2_asm.S +36 -2
  34. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/indcpa.c +22 -0
  35. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/indcpa.h +6 -0
  36. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.c +11 -0
  37. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.h +25 -1
  38. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/meta.h +44 -2
  39. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/aarch64_zetas.c +2 -0
  40. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/arith_native_aarch64.h +11 -10
  41. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{intt_aarch64_asm.S → mlkem_intt_aarch64_asm.S} +16 -9
  42. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{ntt_aarch64_asm.S → mlkem_ntt_aarch64_asm.S} +10 -7
  43. 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
  44. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{poly_reduce_aarch64_asm.S → mlkem_poly_reduce_aarch64_asm.S} +6 -3
  45. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{poly_tobytes_aarch64_asm.S → mlkem_poly_tobytes_aarch64_asm.S} +12 -5
  46. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{poly_tomont_aarch64_asm.S → mlkem_poly_tomont_aarch64_asm.S} +11 -5
  47. 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
  48. 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
  49. 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
  50. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{rej_uniform_aarch64_asm.S → mlkem_rej_uniform_aarch64_asm.S} +17 -17
  51. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/api.h +21 -8
  52. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/meta.h +1 -1
  53. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/meta.h +4 -0
  54. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/{intt_ppc_asm.S → mlkem_intt_ppc_asm.S} +29 -5
  55. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/{ntt_ppc_asm.S → mlkem_ntt_ppc_asm.S} +22 -1
  56. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/{poly_tomont_ppc_asm.S → mlkem_poly_tomont_ppc_asm.S} +25 -3
  57. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/{reduce_ppc_asm.S → mlkem_reduce_ppc_asm.S} +22 -1
  58. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/meta.h +4 -0
  59. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/arith_native_riscv64.h +4 -0
  60. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_poly.c +6 -2
  61. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/meta.h +25 -5
  62. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/arith_native_x86_64.h +20 -20
  63. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/compress_consts.c +14 -3
  64. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/compress_consts.h +8 -0
  65. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{intt_avx2_asm.S → mlkem_intt_avx2_asm.S} +27 -3
  66. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{ntt_avx2_asm.S → mlkem_ntt_avx2_asm.S} +23 -1
  67. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{nttfrombytes_avx2_asm.S → mlkem_nttfrombytes_avx2_asm.S} +27 -3
  68. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{ntttobytes_avx2_asm.S → mlkem_ntttobytes_avx2_asm.S} +27 -3
  69. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{nttunpack_avx2_asm.S → mlkem_nttunpack_avx2_asm.S} +17 -1
  70. 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
  71. 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
  72. 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
  73. 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
  74. 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
  75. 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
  76. 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
  77. 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
  78. 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
  79. 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
  80. 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
  81. 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
  82. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{reduce_avx2_asm.S → mlkem_reduce_avx2_asm.S} +17 -1
  83. 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
  84. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{tomont_avx2_asm.S → mlkem_tomont_avx2_asm.S} +20 -3
  85. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly.c +7 -2
  86. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly.h +6 -0
  87. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.c +25 -4
  88. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.h +33 -4
  89. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sampling.c +4 -0
  90. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sampling.h +4 -0
  91. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sys.h +19 -1
  92. data/lib/pq_crypto/version.rb +1 -1
  93. data/script/vendor_libs.rb +3 -3
  94. metadata +41 -43
@@ -13,6 +13,9 @@
13
13
  Description: AArch64 hybrid scalar/vector implementation of Keccak-f[1600] permutation for four sequential states
14
14
  Signature: void mlk_keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm(uint64_t state[100], const uint64_t rc[24])
15
15
  ABI:
16
+ Architecture: aarch64
17
+ CallingConvention: AAPCS64
18
+ Features: [NEON]
16
19
  x0:
17
20
  type: buffer
18
21
  size_bytes: 800
@@ -140,7 +143,7 @@ MLK_ASM_FN_SYMBOL(keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm)
140
143
  ldr x25, [x0, #0xc0]
141
144
  sub x0, x0, #0x190
142
145
 
143
- Lkeccak_f1600_x4_v8a_scalar_hybrid_initial:
146
+ Lmlk_keccak_f1600_x4_v8a_scalar_hybrid_initial:
144
147
  eor x30, x24, x25
145
148
  eor x27, x9, x10
146
149
  eor v30.16b, v0.16b, v5.16b
@@ -523,7 +526,7 @@ Lkeccak_f1600_x4_v8a_scalar_hybrid_initial:
523
526
  str x30, [sp, #0x10]
524
527
  eor v0.16b, v0.16b, v28.16b
525
528
 
526
- Lkeccak_f1600_x4_v8a_scalar_hybrid_loop:
529
+ Lmlk_keccak_f1600_x4_v8a_scalar_hybrid_loop:
527
530
  eor x0, x15, x11, ror #52
528
531
  eor x0, x0, x13, ror #48
529
532
  eor v30.16b, v0.16b, v5.16b
@@ -911,8 +914,8 @@ Lkeccak_f1600_x4_v8a_scalar_hybrid_loop:
911
914
  str x30, [sp, #0x10]
912
915
  eor v0.16b, v0.16b, v28.16b
913
916
 
914
- Lkeccak_f1600_x4_v8a_scalar_hybrid_loop_end:
915
- b.le Lkeccak_f1600_x4_v8a_scalar_hybrid_loop
917
+ Lmlk_keccak_f1600_x4_v8a_scalar_hybrid_loop_end:
918
+ b.le Lmlk_keccak_f1600_x4_v8a_scalar_hybrid_loop
916
919
  ror x2, x2, #0x3d
917
920
  ror x3, x3, #0x27
918
921
  ror x4, x4, #0x36
@@ -938,7 +941,7 @@ Lkeccak_f1600_x4_v8a_scalar_hybrid_loop_end:
938
941
  ror x25, x25, #0x9
939
942
  ldr x30, [sp, #0x20]
940
943
  cmp x30, #0x1
941
- b.eq Lkeccak_f1600_x4_v8a_scalar_hybrid_done
944
+ b.eq Lmlk_keccak_f1600_x4_v8a_scalar_hybrid_done
942
945
  mov x30, #0x1 // =1
943
946
  str x30, [sp, #0x20]
944
947
  ldr x0, [sp]
@@ -972,9 +975,9 @@ Lkeccak_f1600_x4_v8a_scalar_hybrid_loop_end:
972
975
  ldp x15, x20, [x0, #0xb0]
973
976
  ldr x25, [x0, #0xc0]
974
977
  sub x0, x0, #0x258
975
- b Lkeccak_f1600_x4_v8a_scalar_hybrid_initial
978
+ b Lmlk_keccak_f1600_x4_v8a_scalar_hybrid_initial
976
979
 
977
- Lkeccak_f1600_x4_v8a_scalar_hybrid_done:
980
+ Lmlk_keccak_f1600_x4_v8a_scalar_hybrid_done:
978
981
  ldr x0, [sp]
979
982
  add x0, x0, #0x258
980
983
  stp x1, x6, [x0]
@@ -13,6 +13,9 @@
13
13
  Description: AArch64 hybrid scalar/vector implementation of Keccak-f[1600] permutation for four sequential states with ARMv8.4-A optimizations
14
14
  Signature: void mlk_keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm(uint64_t state[100], const uint64_t rc[24])
15
15
  ABI:
16
+ Architecture: aarch64
17
+ CallingConvention: AAPCS64
18
+ Features: [NEON, SHA3]
16
19
  x0:
17
20
  type: buffer
18
21
  size_bytes: 800
@@ -142,7 +145,7 @@ MLK_ASM_FN_SYMBOL(keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm)
142
145
  ldr x25, [x0, #0xc0]
143
146
  sub x0, x0, #0x190
144
147
 
145
- Lkeccak_f1600_x4_v8a_v84a_scalar_hybrid_initial:
148
+ Lmlk_keccak_f1600_x4_v8a_v84a_scalar_hybrid_initial:
146
149
  eor x30, x24, x25
147
150
  eor x27, x9, x10
148
151
  eor3 v30.16b, v0.16b, v5.16b, v10.16b
@@ -478,7 +481,7 @@ Lkeccak_f1600_x4_v8a_v84a_scalar_hybrid_initial:
478
481
  str x30, [sp, #0x10]
479
482
  eor v0.16b, v0.16b, v28.16b
480
483
 
481
- Lkeccak_f1600_x4_v8a_v84a_scalar_hybrid_loop:
484
+ Lmlk_keccak_f1600_x4_v8a_v84a_scalar_hybrid_loop:
482
485
  eor x0, x15, x11, ror #52
483
486
  eor x0, x0, x13, ror #48
484
487
  eor3 v30.16b, v0.16b, v5.16b, v10.16b
@@ -819,8 +822,8 @@ Lkeccak_f1600_x4_v8a_v84a_scalar_hybrid_loop:
819
822
  str x30, [sp, #0x10]
820
823
  eor v0.16b, v0.16b, v28.16b
821
824
 
822
- Lkeccak_f1600_x4_v8a_v84a_scalar_hybrid_loop_end:
823
- b.le Lkeccak_f1600_x4_v8a_v84a_scalar_hybrid_loop
825
+ Lmlk_keccak_f1600_x4_v8a_v84a_scalar_hybrid_loop_end:
826
+ b.le Lmlk_keccak_f1600_x4_v8a_v84a_scalar_hybrid_loop
824
827
  ror x2, x2, #0x3d
825
828
  ror x3, x3, #0x27
826
829
  ror x4, x4, #0x36
@@ -846,7 +849,7 @@ Lkeccak_f1600_x4_v8a_v84a_scalar_hybrid_loop_end:
846
849
  ror x25, x25, #0x9
847
850
  ldr x30, [sp, #0x20]
848
851
  cmp x30, #0x1
849
- b.eq Lkeccak_f1600_x4_v8a_v84a_scalar_hybrid_done
852
+ b.eq Lmlk_keccak_f1600_x4_v8a_v84a_scalar_hybrid_done
850
853
  mov x30, #0x1 // =1
851
854
  str x30, [sp, #0x20]
852
855
  ldr x0, [sp]
@@ -880,9 +883,9 @@ Lkeccak_f1600_x4_v8a_v84a_scalar_hybrid_loop_end:
880
883
  ldp x15, x20, [x0, #0xb0]
881
884
  ldr x25, [x0, #0xc0]
882
885
  sub x0, x0, #0x258
883
- b Lkeccak_f1600_x4_v8a_v84a_scalar_hybrid_initial
886
+ b Lmlk_keccak_f1600_x4_v8a_v84a_scalar_hybrid_initial
884
887
 
885
- Lkeccak_f1600_x4_v8a_v84a_scalar_hybrid_done:
888
+ Lmlk_keccak_f1600_x4_v8a_v84a_scalar_hybrid_done:
886
889
  ldr x0, [sp]
887
890
  add x0, x0, #0x258
888
891
  stp x1, x6, [x0]
@@ -21,7 +21,8 @@
21
21
  MLK_MUST_CHECK_RETURN_VALUE
22
22
  static MLK_INLINE int mlk_keccak_f1600_x1_native(uint64_t *state)
23
23
  {
24
- if (!mlk_sys_check_capability(MLK_SYS_CAP_SHA3))
24
+ if (!mlk_sys_check_capability(MLK_SYS_CAP_NEON) ||
25
+ !mlk_sys_check_capability(MLK_SYS_CAP_SHA3))
25
26
  {
26
27
  return MLK_NATIVE_FUNC_FALLBACK;
27
28
  }
@@ -21,7 +21,8 @@
21
21
  MLK_MUST_CHECK_RETURN_VALUE
22
22
  static MLK_INLINE int mlk_keccak_f1600_x4_native(uint64_t *state)
23
23
  {
24
- if (!mlk_sys_check_capability(MLK_SYS_CAP_SHA3))
24
+ if (!mlk_sys_check_capability(MLK_SYS_CAP_NEON) ||
25
+ !mlk_sys_check_capability(MLK_SYS_CAP_SHA3))
25
26
  {
26
27
  return MLK_NATIVE_FUNC_FALLBACK;
27
28
  }
@@ -17,6 +17,11 @@
17
17
  MLK_MUST_CHECK_RETURN_VALUE
18
18
  static MLK_INLINE int mlk_keccak_f1600_x4_native(uint64_t *state)
19
19
  {
20
+ if (!mlk_sys_check_capability(MLK_SYS_CAP_NEON))
21
+ {
22
+ return MLK_NATIVE_FUNC_FALLBACK;
23
+ }
24
+
20
25
  mlk_keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm(
21
26
  state, mlk_keccakf1600_round_constants);
22
27
  return MLK_NATIVE_FUNC_SUCCESS;
@@ -21,7 +21,8 @@
21
21
  MLK_MUST_CHECK_RETURN_VALUE
22
22
  static MLK_INLINE int mlk_keccak_f1600_x4_native(uint64_t *state)
23
23
  {
24
- if (!mlk_sys_check_capability(MLK_SYS_CAP_SHA3))
24
+ if (!mlk_sys_check_capability(MLK_SYS_CAP_NEON) ||
25
+ !mlk_sys_check_capability(MLK_SYS_CAP_SHA3))
25
26
  {
26
27
  return MLK_NATIVE_FUNC_FALLBACK;
27
28
  }
@@ -17,6 +17,7 @@
17
17
 
18
18
  #if !defined(__ASSEMBLER__)
19
19
  #include "../api.h"
20
+ #include "src/fips202_native_armv81m.h"
20
21
 
21
22
  /*
22
23
  * Native x4 permutation
@@ -35,42 +36,27 @@ static MLK_INLINE int mlk_keccak_f1600_x4_native(uint64_t *state)
35
36
  /*
36
37
  * Native x4 XOR bytes (with on-the-fly bit interleaving)
37
38
  */
38
- #define mlk_keccak_f1600_x4_state_xor_bytes \
39
- MLK_NAMESPACE(keccak_f1600_x4_state_xor_bytes_asm)
40
- void mlk_keccak_f1600_x4_state_xor_bytes(void *state, const uint8_t *data0,
41
- const uint8_t *data1,
42
- const uint8_t *data2,
43
- const uint8_t *data3, unsigned offset,
44
- unsigned length);
45
-
46
39
  MLK_MUST_CHECK_RETURN_VALUE
47
40
  static MLK_INLINE int mlk_keccakf1600_xor_bytes_x4_native(
48
41
  uint64_t *state, const uint8_t *data0, const uint8_t *data1,
49
42
  const uint8_t *data2, const uint8_t *data3, unsigned offset,
50
43
  unsigned length)
51
44
  {
52
- mlk_keccak_f1600_x4_state_xor_bytes(state, data0, data1, data2, data3, offset,
53
- length);
45
+ mlk_keccak_f1600_x4_state_xor_bytes_asm(state, data0, data1, data2, data3,
46
+ offset, length);
54
47
  return MLK_NATIVE_FUNC_SUCCESS;
55
48
  }
56
49
 
57
50
  /*
58
51
  * Native x4 extract bytes (with on-the-fly bit de-interleaving)
59
52
  */
60
- #define mlk_keccak_f1600_x4_state_extract_bytes \
61
- MLK_NAMESPACE(keccak_f1600_x4_state_extract_bytes_asm)
62
- void mlk_keccak_f1600_x4_state_extract_bytes(void *state, uint8_t *data0,
63
- uint8_t *data1, uint8_t *data2,
64
- uint8_t *data3, unsigned offset,
65
- unsigned length);
66
-
67
53
  MLK_MUST_CHECK_RETURN_VALUE
68
54
  static MLK_INLINE int mlk_keccakf1600_extract_bytes_x4_native(
69
55
  uint64_t *state, uint8_t *data0, uint8_t *data1, uint8_t *data2,
70
56
  uint8_t *data3, unsigned offset, unsigned length)
71
57
  {
72
- mlk_keccak_f1600_x4_state_extract_bytes(state, data0, data1, data2, data3,
73
- offset, length);
58
+ mlk_keccak_f1600_x4_state_extract_bytes_asm(state, data0, data1, data2, data3,
59
+ offset, length);
74
60
  return MLK_NATIVE_FUNC_SUCCESS;
75
61
  }
76
62
 
@@ -9,6 +9,9 @@
9
9
  Description: Armv8.1-M MVE implementation of batched (x4) Keccak-f[1600] permutation using bit-interleaved state
10
10
  Signature: void mlk_keccak_f1600_x4_mve_asm(void *state, void *tmpstate, const uint32_t *rc)
11
11
  ABI:
12
+ Architecture: armv81m
13
+ CallingConvention: AAPCS32
14
+ Features: [MVE]
12
15
  r0:
13
16
  type: buffer
14
17
  size_bytes: 800
@@ -111,9 +114,9 @@ MLK_ASM_FN_SYMBOL(keccak_f1600_x4_mve_asm)
111
114
  vldrw.u32 q0, [r3]
112
115
  vldrw.u32 q1, [r2]
113
116
  vldrw.u32 q2, [r2, #32]
114
- wls lr, lr, Lkeccak_f1600_x4_mve_asm_roundend @ imm = #0x8c0
117
+ wls lr, lr, Lmlk_keccak_f1600_x4_mve_asm_roundend @ imm = #0x8c0
115
118
 
116
- Lkeccak_f1600_x4_mve_asm_roundstart:
119
+ Lmlk_keccak_f1600_x4_mve_asm_roundstart:
117
120
  vldrw.u32 q6, [r2, #112]
118
121
  veor q7, q6, q2
119
122
  vldrw.u32 q2, [r2, #80]
@@ -674,10 +677,10 @@ Lkeccak_f1600_x4_mve_asm_roundstart:
674
677
  veor q0, q4, q6
675
678
  vstrw.32 q0, [r5]
676
679
 
677
- Lkeccak_f1600_x4_mve_asm_roundend_pre:
678
- le lr, Lkeccak_f1600_x4_mve_asm_roundstart @ imm = #-0x8c0
680
+ Lmlk_keccak_f1600_x4_mve_asm_roundend_pre:
681
+ le lr, Lmlk_keccak_f1600_x4_mve_asm_roundstart @ imm = #-0x8c0
679
682
 
680
- Lkeccak_f1600_x4_mve_asm_roundend:
683
+ Lmlk_keccak_f1600_x4_mve_asm_roundend:
681
684
  add sp, #0x80
682
685
  .cfi_adjust_cfa_offset -0x80
683
686
  vpop {d8, d9, d10, d11, d12, d13, d14, d15}
@@ -9,7 +9,7 @@
9
9
  // Overview
10
10
  // ---------------------------------------------------------------------------
11
11
  // MVE/Helium implementation of KeccakF1600x4_StateExtractBytes
12
- // (inverse of state_xor_bytes_x4_mve.S).
12
+ // (inverse of keccak_f1600_x4_state_xor_bytes_mve.S).
13
13
  //
14
14
  // void KeccakF1600x4_StateExtractBytes(state, d0, d1, d2, d3, offset, length)
15
15
  //
@@ -62,7 +62,7 @@
62
62
 
63
63
  /*
64
64
  * WARNING: This file is auto-derived from the mlkem-native source file
65
- * dev/fips202/armv81m/src/state_extract_bytes_x4_mve.S using scripts/simpasm. Do not modify it directly.
65
+ * dev/fips202/armv81m/src/keccak_f1600_x4_state_extract_bytes_mve.S using scripts/simpasm. Do not modify it directly.
66
66
  */
67
67
 
68
68
  .thumb
@@ -99,13 +99,13 @@ MLK_ASM_FN_SYMBOL(keccak_f1600_x4_state_extract_bytes_asm)
99
99
  ldr.w r10, [sp, #0x6c]
100
100
  ldr r6, [sp, #0x70]
101
101
  cmp r6, #0x0
102
- beq.w Lkeccak_f1600_x4_state_extract_bytes_asm_exit @ imm = #0x2ea
102
+ beq.w Lmlk_keccak_f1600_x4_state_extract_bytes_asm_exit @ imm = #0x2ea
103
103
  and r5, r10, #0x7
104
104
  bic r9, r10, #0x7
105
105
  add.w r8, r0, r9, lsl #1
106
106
  add.w r7, r8, #0x190
107
107
  cmp r5, #0x0
108
- beq.w Lkeccak_f1600_x4_state_extract_bytes_asm_pre_main @ imm = #0x112
108
+ beq.w Lmlk_keccak_f1600_x4_state_extract_bytes_asm_pre_main @ imm = #0x112
109
109
  vldrw.u32 q0, [r8], #16
110
110
  vldrw.u32 q1, [r7], #16
111
111
  vrev32.16 q2, q0
@@ -175,22 +175,22 @@ MLK_ASM_FN_SYMBOL(keccak_f1600_x4_state_extract_bytes_asm)
175
175
  vstrbt.8 q3, [r4], #4
176
176
  subs.w r6, r6, lr
177
177
  cmp r6, #0x0
178
- beq.w Lkeccak_f1600_x4_state_extract_bytes_asm_exit @ imm = #0x1cc
178
+ beq.w Lmlk_keccak_f1600_x4_state_extract_bytes_asm_exit @ imm = #0x1cc
179
179
  vmov q7[2], q7[0], r1, r3
180
180
  vmov q7[3], q7[1], r2, r4
181
- b Lkeccak_f1600_x4_state_extract_bytes_asm_main_body @ imm = #0xe
181
+ b Lmlk_keccak_f1600_x4_state_extract_bytes_asm_main_body @ imm = #0xe
182
182
 
183
- Lkeccak_f1600_x4_state_extract_bytes_asm_pre_main:
183
+ Lmlk_keccak_f1600_x4_state_extract_bytes_asm_pre_main:
184
184
  vmov q7[2], q7[0], r1, r3
185
185
  vmov q7[3], q7[1], r2, r4
186
186
  mov.w r12, #0x4
187
187
  vsub.i32 q7, q7, r12
188
188
 
189
- Lkeccak_f1600_x4_state_extract_bytes_asm_main_body:
189
+ Lmlk_keccak_f1600_x4_state_extract_bytes_asm_main_body:
190
190
  lsr.w lr, r6, #0x3
191
- wls lr, lr, Lkeccak_f1600_x4_state_extract_bytes_asm_main_loop_end @ imm = #0xb4
191
+ wls lr, lr, Lmlk_keccak_f1600_x4_state_extract_bytes_asm_main_loop_end @ imm = #0xb4
192
192
 
193
- Lkeccak_f1600_x4_state_extract_bytes_asm_main_loop_start:
193
+ Lmlk_keccak_f1600_x4_state_extract_bytes_asm_main_loop_start:
194
194
  vldrw.u32 q0, [r8], #16
195
195
  vldrw.u32 q1, [r7], #16
196
196
  vrev32.16 q2, q0
@@ -235,11 +235,11 @@ Lkeccak_f1600_x4_state_extract_bytes_asm_main_loop_start:
235
235
  vorr q1, q1, q3
236
236
  vstrw.32 q0, [q7, #4]!
237
237
  vstrw.32 q1, [q7, #4]!
238
- le lr, Lkeccak_f1600_x4_state_extract_bytes_asm_main_loop_start @ imm = #-0xb4
238
+ le lr, Lmlk_keccak_f1600_x4_state_extract_bytes_asm_main_loop_start @ imm = #-0xb4
239
239
 
240
- Lkeccak_f1600_x4_state_extract_bytes_asm_main_loop_end:
240
+ Lmlk_keccak_f1600_x4_state_extract_bytes_asm_main_loop_end:
241
241
  ands r6, r6, #0x7
242
- beq Lkeccak_f1600_x4_state_extract_bytes_asm_exit @ imm = #0xee
242
+ beq Lmlk_keccak_f1600_x4_state_extract_bytes_asm_exit @ imm = #0xee
243
243
  mov.w r12, #0x4
244
244
  vadd.i32 q7, q7, r12
245
245
  vmov r1, r3, q7[2], q7[0]
@@ -301,7 +301,7 @@ Lkeccak_f1600_x4_state_extract_bytes_asm_main_loop_end:
301
301
  vstrbt.8 q2, [r3], #4
302
302
  vstrbt.8 q3, [r4], #4
303
303
 
304
- Lkeccak_f1600_x4_state_extract_bytes_asm_exit:
304
+ Lmlk_keccak_f1600_x4_state_extract_bytes_asm_exit:
305
305
  vpop {d8, d9, d10, d11, d12, d13, d14, d15}
306
306
  .cfi_restore d8
307
307
  .cfi_restore d9
@@ -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
@@ -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
  /**
@@ -84,7 +85,9 @@ __contract__(
84
85
  return_value == MLK_ERR_OUT_OF_MEMORY ||
85
86
  return_value == MLK_ERR_RNG_FAIL)
86
87
  );
88
+ #endif /* !MLK_CONFIG_NO_KEYPAIR_API */
87
89
 
90
+ #if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)
88
91
  #define mlk_indcpa_enc MLK_NAMESPACE_K(indcpa_enc) MLK_CONTEXT_PARAMETERS_4
89
92
  /**
90
93
  * Encryption function of the CPA-secure public-key encryption scheme
@@ -123,7 +126,9 @@ __contract__(
123
126
  ensures(return_value == 0 || return_value == MLK_ERR_FAIL ||
124
127
  return_value == MLK_ERR_OUT_OF_MEMORY)
125
128
  );
129
+ #endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */
126
130
 
131
+ #if !defined(MLK_CONFIG_NO_DECAPS_API)
127
132
  #define mlk_indcpa_dec MLK_NAMESPACE_K(indcpa_dec) MLK_CONTEXT_PARAMETERS_3
128
133
  /**
129
134
  * Decryption function of the CPA-secure public-key encryption scheme
@@ -159,5 +164,6 @@ __contract__(
159
164
  ensures(return_value == 0 || return_value == MLK_ERR_FAIL ||
160
165
  return_value == MLK_ERR_OUT_OF_MEMORY)
161
166
  );
167
+ #endif /* !MLK_CONFIG_NO_DECAPS_API */
162
168
 
163
169
  #endif /* !MLK_INDCPA_H */