pq_crypto 0.6.2 → 0.6.3

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 (113) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/ext/pqcrypto/pqcrypto_version.h +1 -1
  4. data/ext/pqcrypto/vendor/.vendored +4 -4
  5. data/ext/pqcrypto/vendor/mlkem-native/README.md +6 -3
  6. data/ext/pqcrypto/vendor/mlkem-native/RELEASE.md +22 -0
  7. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.c +77 -36
  8. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.h +135 -146
  9. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_asm.S +116 -72
  10. data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_config.h +351 -415
  11. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/cbmc.h +43 -20
  12. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/common.h +16 -8
  13. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.c +57 -31
  14. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.h +260 -349
  15. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/debug.h +17 -24
  16. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202.c +35 -37
  17. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202.h +43 -57
  18. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202x4.c +14 -15
  19. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202x4.h +5 -4
  20. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/keccakf1600.c +42 -6
  21. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/fips202_native_aarch64.h +31 -20
  22. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/{keccak_f1600_x1_scalar_asm.S → keccak_f1600_x1_scalar_aarch64_asm.S} +10 -10
  23. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/{keccak_f1600_x1_v84a_asm.S → keccak_f1600_x1_v84a_aarch64_asm.S} +10 -10
  24. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/{keccak_f1600_x2_v84a_asm.S → keccak_f1600_x2_v84a_aarch64_asm.S} +10 -10
  25. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/{keccak_f1600_x4_v8a_scalar_hybrid_asm.S → keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm.S} +10 -10
  26. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/{keccak_f1600_x4_v8a_v84a_scalar_hybrid_asm.S → keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm.S} +10 -10
  27. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccakf1600_round_constants.c +10 -9
  28. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x1_scalar.h +2 -1
  29. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x1_v84a.h +1 -1
  30. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x2_v84a.h +4 -2
  31. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x4_v8a_scalar.h +2 -2
  32. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +1 -1
  33. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/fips202_native_armv81m.h +2 -1
  34. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +55 -9
  35. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccakf1600_round_constants.c +26 -25
  36. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/state_extract_bytes_x4_mve.S +58 -14
  37. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/state_xor_bytes_x4_mve.S +57 -16
  38. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/auto.h +2 -1
  39. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/keccak_f1600_x4_avx2.h +2 -2
  40. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/fips202_native_x86_64.h +10 -7
  41. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/{keccak_f1600_x4_avx2.S → keccak_f1600_x4_avx2_asm.S} +13 -11
  42. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccakf1600_constants.c +12 -11
  43. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/indcpa.c +167 -136
  44. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/indcpa.h +75 -68
  45. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.h +135 -157
  46. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/meta.h +15 -13
  47. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/aarch64_zetas.c +143 -135
  48. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/arith_native_aarch64.h +52 -46
  49. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{intt.S → intt_aarch64_asm.S} +10 -10
  50. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{ntt.S → ntt_aarch64_asm.S} +10 -10
  51. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{poly_mulcache_compute_asm.S → poly_mulcache_compute_aarch64_asm.S} +10 -10
  52. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{poly_reduce_asm.S → poly_reduce_aarch64_asm.S} +10 -10
  53. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{poly_tobytes_asm.S → poly_tobytes_aarch64_asm.S} +10 -10
  54. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{poly_tomont_asm.S → poly_tomont_aarch64_asm.S} +10 -12
  55. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{polyvec_basemul_acc_montgomery_cached_asm_k2.S → polyvec_basemul_acc_montgomery_cached_k2_aarch64_asm.S} +10 -10
  56. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{polyvec_basemul_acc_montgomery_cached_asm_k3.S → polyvec_basemul_acc_montgomery_cached_k3_aarch64_asm.S} +10 -10
  57. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{polyvec_basemul_acc_montgomery_cached_asm_k4.S → polyvec_basemul_acc_montgomery_cached_k4_aarch64_asm.S} +10 -10
  58. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/{rej_uniform_asm.S → rej_uniform_aarch64_asm.S} +12 -12
  59. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/rej_uniform_table.c +514 -513
  60. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/api.h +254 -253
  61. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/meta.h +6 -1
  62. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/README.md +6 -0
  63. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/meta.h +77 -0
  64. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/arith_native_ppc64le.h +24 -0
  65. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/consts.c +299 -0
  66. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/consts.h +34 -0
  67. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/intt_ppc_asm.S +3222 -0
  68. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/ntt_ppc_asm.S +1651 -0
  69. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/poly_tomont_ppc_asm.S +294 -0
  70. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/ppc64le/src/reduce_ppc_asm.S +710 -0
  71. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/meta.h +5 -0
  72. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_debug.c +18 -16
  73. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_debug.h +19 -24
  74. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_poly.c +53 -65
  75. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/meta.h +20 -20
  76. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/arith_native_x86_64.h +106 -88
  77. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/compress_consts.c +45 -35
  78. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/compress_consts.h +8 -8
  79. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/consts.c +1 -1
  80. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/consts.h +1 -1
  81. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{intt.S → intt_avx2_asm.S} +8 -8
  82. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{ntt.S → ntt_avx2_asm.S} +8 -8
  83. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{nttfrombytes.S → nttfrombytes_avx2_asm.S} +8 -8
  84. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{ntttobytes.S → ntttobytes_avx2_asm.S} +8 -8
  85. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{nttunpack.S → nttunpack_avx2_asm.S} +8 -8
  86. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_compress_d10.S → poly_compress_d10_avx2_asm.S} +9 -9
  87. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_compress_d11.S → poly_compress_d11_avx2_asm.S} +9 -9
  88. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_compress_d4.S → poly_compress_d4_avx2_asm.S} +9 -9
  89. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_compress_d5.S → poly_compress_d5_avx2_asm.S} +9 -9
  90. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_decompress_d10.S → poly_decompress_d10_avx2_asm.S} +9 -9
  91. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_decompress_d11.S → poly_decompress_d11_avx2_asm.S} +9 -9
  92. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_decompress_d4.S → poly_decompress_d4_avx2_asm.S} +9 -9
  93. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{poly_decompress_d5.S → poly_decompress_d5_avx2_asm.S} +9 -9
  94. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{mulcache_compute.S → poly_mulcache_compute_avx2_asm.S} +8 -8
  95. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{polyvec_basemul_acc_montgomery_cached_asm_k2.S → polyvec_basemul_acc_montgomery_cached_k2_avx2_asm.S} +8 -8
  96. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{polyvec_basemul_acc_montgomery_cached_asm_k3.S → polyvec_basemul_acc_montgomery_cached_k3_avx2_asm.S} +8 -8
  97. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{polyvec_basemul_acc_montgomery_cached_asm_k4.S → polyvec_basemul_acc_montgomery_cached_k4_avx2_asm.S} +8 -8
  98. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{reduce.S → reduce_avx2_asm.S} +8 -8
  99. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{rej_uniform_asm.S → rej_uniform_avx2_asm.S} +9 -9
  100. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/rej_uniform_table.c +514 -513
  101. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/{tomont.S → tomont_avx2_asm.S} +8 -8
  102. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly.c +61 -57
  103. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly.h +89 -116
  104. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.c +31 -32
  105. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.h +226 -301
  106. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/randombytes.h +21 -29
  107. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sampling.c +68 -63
  108. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sampling.h +37 -48
  109. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sys.h +44 -2
  110. data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/verify.h +141 -159
  111. data/lib/pq_crypto/version.rb +1 -1
  112. data/script/vendor_libs.rb +3 -3
  113. metadata +47 -38
@@ -55,26 +55,25 @@
55
55
  #define mlk_kem_check_pk MLK_NAMESPACE_K(check_pk) MLK_CONTEXT_PARAMETERS_1
56
56
  #define mlk_kem_check_sk MLK_NAMESPACE_K(check_sk) MLK_CONTEXT_PARAMETERS_1
57
57
 
58
- /*************************************************
59
- * Name: mlk_kem_check_pk
58
+ /**
59
+ * Implements modulus check mandated by FIPS 203, i.e., ensures that
60
+ * coefficients are in [0,q-1].
60
61
  *
61
- * Description: Implements modulus check mandated by FIPS 203,
62
- * i.e., ensures that coefficients are in [0,q-1].
62
+ * @spec{Implements @[FIPS203, Section 7.2, 'modulus check'].}
63
63
  *
64
- * Arguments: - const uint8_t *pk: pointer to input public key
65
- * (an already allocated array of MLKEM_INDCCA_PUBLICKEYBYTES
66
- * bytes)
64
+ * @reference{Not implemented in the reference implementation @[REF].}
67
65
  *
68
- * Returns: - 0 on success
69
- * - MLK_ERR_FAIL: If the modulus check failed.
70
- * - MLK_ERR_OUT_OF_MEMORY: If MLK_CONFIG_CUSTOM_ALLOC_FREE is
71
- * used and an allocation via MLK_CUSTOM_ALLOC returned NULL.
66
+ * @param[in] pk Input public key (an already allocated array of
67
+ * MLKEM_INDCCA_PUBLICKEYBYTES bytes).
68
+ * @param context Application context. Only present when
69
+ * MLK_CONFIG_CONTEXT_PARAMETER is defined; type set by
70
+ * MLK_CONFIG_CONTEXT_PARAMETER_TYPE.
72
71
  *
73
- * Specification: Implements @[FIPS203, Section 7.2, 'modulus check']
74
- *
75
- **************************************************/
76
-
77
- /* Reference: Not implemented in the reference implementation @[REF]. */
72
+ * @retval 0 Success.
73
+ * @retval MLK_ERR_FAIL Modulus check failed.
74
+ * @retval MLK_ERR_OUT_OF_MEMORY MLK_CONFIG_CUSTOM_ALLOC_FREE was used and
75
+ * MLK_CUSTOM_ALLOC returned NULL.
76
+ */
78
77
  MLK_EXTERNAL_API
79
78
  MLK_MUST_CHECK_RETURN_VALUE
80
79
  int mlk_kem_check_pk(const uint8_t pk[MLKEM_INDCCA_PUBLICKEYBYTES],
@@ -86,27 +85,25 @@ __contract__(
86
85
  );
87
86
 
88
87
 
89
- /*************************************************
90
- * Name: mlk_kem_check_sk
88
+ /**
89
+ * Implements public key hash check mandated by FIPS 203, i.e., ensures that
90
+ * sk[768𝑘+32 ∶ 768𝑘+64] = H(pk) = H(sk[384𝑘 : 768𝑘+32]).
91
91
  *
92
- * Description: Implements public key hash check mandated by FIPS 203,
93
- * i.e., ensures that
94
- * sk[768𝑘+32 ∶ 768𝑘+64] = H(pk)= H(sk[384𝑘 : 768𝑘+32])
92
+ * @spec{Implements @[FIPS203, Section 7.3, 'hash check'].}
95
93
  *
96
- * Arguments: - const uint8_t *sk: pointer to input private key
97
- * (an already allocated array of MLKEM_INDCCA_SECRETKEYBYTES
98
- * bytes)
94
+ * @reference{Not implemented in the reference implementation @[REF].}
99
95
  *
100
- * Returns: - 0 on success
101
- * - MLK_ERR_FAIL: If the public key hash check failed.
102
- * - MLK_ERR_OUT_OF_MEMORY: If MLK_CONFIG_CUSTOM_ALLOC_FREE is
103
- * used and an allocation via MLK_CUSTOM_ALLOC returned NULL.
96
+ * @param[in] sk Input private key (an already allocated array of
97
+ * MLKEM_INDCCA_SECRETKEYBYTES bytes).
98
+ * @param context Application context. Only present when
99
+ * MLK_CONFIG_CONTEXT_PARAMETER is defined; type set by
100
+ * MLK_CONFIG_CONTEXT_PARAMETER_TYPE.
104
101
  *
105
- * Specification: Implements @[FIPS203, Section 7.3, 'hash check']
106
- *
107
- **************************************************/
108
-
109
- /* Reference: Not implemented in the reference implementation @[REF]. */
102
+ * @retval 0 Success.
103
+ * @retval MLK_ERR_FAIL Public key hash check failed.
104
+ * @retval MLK_ERR_OUT_OF_MEMORY MLK_CONFIG_CUSTOM_ALLOC_FREE was used and
105
+ * MLK_CUSTOM_ALLOC returned NULL.
106
+ */
110
107
  MLK_EXTERNAL_API
111
108
  MLK_MUST_CHECK_RETURN_VALUE
112
109
  int mlk_kem_check_sk(const uint8_t sk[MLKEM_INDCCA_SECRETKEYBYTES],
@@ -117,31 +114,26 @@ __contract__(
117
114
  return_value == MLK_ERR_OUT_OF_MEMORY)
118
115
  );
119
116
 
120
- /*************************************************
121
- * Name: mlk_kem_keypair_derand
122
- *
123
- * Description: Generates public and private key
124
- * for CCA-secure ML-KEM key encapsulation mechanism
125
- *
126
- * Arguments: - uint8_t *pk: pointer to output public key
127
- * (an already allocated array of MLKEM_INDCCA_PUBLICKEYBYTES
128
- * bytes)
129
- * - uint8_t *sk: pointer to output private key
130
- * (an already allocated array of MLKEM_INDCCA_SECRETKEYBYTES
131
- * bytes)
132
- * - uint8_t *coins: pointer to input randomness
133
- * (an already allocated array filled with 2*MLKEM_SYMBYTES
134
- * random bytes)
135
- *
136
- * Returns: - 0: On success
137
- * - MLK_ERR_FAIL: If MLK_CONFIG_KEYGEN_PCT is enabled and the
138
- * PCT failed.
139
- * - MLK_ERR_OUT_OF_MEMORY: If MLK_CONFIG_CUSTOM_ALLOC_FREE is
140
- * used and an allocation via MLK_CUSTOM_ALLOC returned NULL.
141
- *
142
- * Specification: Implements @[FIPS203, Algorithm 16, ML-KEM.KeyGen_Internal]
143
- *
144
- **************************************************/
117
+ /**
118
+ * Generate a public/private keypair for the ML-KEM key encapsulation mechanism.
119
+ *
120
+ * @spec{Implements @[FIPS203, Algorithm 16, ML-KEM.KeyGen_Internal].}
121
+ *
122
+ * @param[out] pk Output public key (an already allocated array of
123
+ * MLKEM_INDCCA_PUBLICKEYBYTES bytes).
124
+ * @param[out] sk Output private key (an already allocated array of
125
+ * MLKEM_INDCCA_SECRETKEYBYTES bytes).
126
+ * @param[in] coins Input randomness (an already allocated array filled
127
+ * with 2*MLKEM_SYMBYTES random bytes).
128
+ * @param context Application context. Only present when
129
+ * MLK_CONFIG_CONTEXT_PARAMETER is defined; type set by
130
+ * MLK_CONFIG_CONTEXT_PARAMETER_TYPE.
131
+ *
132
+ * @retval 0 Success.
133
+ * @retval MLK_ERR_FAIL MLK_CONFIG_KEYGEN_PCT enabled and PCT failed.
134
+ * @retval MLK_ERR_OUT_OF_MEMORY MLK_CONFIG_CUSTOM_ALLOC_FREE was used and
135
+ * MLK_CUSTOM_ALLOC returned NULL.
136
+ */
145
137
  MLK_EXTERNAL_API
146
138
  MLK_MUST_CHECK_RETURN_VALUE
147
139
  int mlk_kem_keypair_derand(uint8_t pk[MLKEM_INDCCA_PUBLICKEYBYTES],
@@ -159,29 +151,25 @@ __contract__(
159
151
  return_value == MLK_ERR_RNG_FAIL)
160
152
  );
161
153
 
162
- /*************************************************
163
- * Name: mlk_kem_keypair
164
- *
165
- * Description: Generates public and private key
166
- * for CCA-secure ML-KEM key encapsulation mechanism
167
- *
168
- * Arguments: - uint8_t *pk: pointer to output public key
169
- * (an already allocated array of MLKEM_INDCCA_PUBLICKEYBYTES
170
- * bytes)
171
- * - uint8_t *sk: pointer to output private key
172
- * (an already allocated array of MLKEM_INDCCA_SECRETKEYBYTES
173
- * bytes)
174
- *
175
- * Returns: - 0: On success
176
- * - MLK_ERR_OUT_OF_MEMORY: If MLK_CONFIG_CUSTOM_ALLOC_FREE is
177
- * used and an allocation via MLK_CUSTOM_ALLOC returned NULL.
178
- * - MLK_ERR_RNG_FAIL: Random number generation failed.
179
- * - MLK_ERR_FAIL: If MLK_CONFIG_KEYGEN_PCT is enabled and the
180
- * PCT failed.
181
- *
182
- * Specification: Implements @[FIPS203, Algorithm 19, ML-KEM.KeyGen]
183
- *
184
- **************************************************/
154
+ /**
155
+ * Generate a public/private keypair for the ML-KEM key encapsulation mechanism.
156
+ *
157
+ * @spec{Implements @[FIPS203, Algorithm 19, ML-KEM.KeyGen].}
158
+ *
159
+ * @param[out] pk Output public key (an already allocated array of
160
+ * MLKEM_INDCCA_PUBLICKEYBYTES bytes).
161
+ * @param[out] sk Output private key (an already allocated array of
162
+ * MLKEM_INDCCA_SECRETKEYBYTES bytes).
163
+ * @param context Application context. Only present when
164
+ * MLK_CONFIG_CONTEXT_PARAMETER is defined; type set by
165
+ * MLK_CONFIG_CONTEXT_PARAMETER_TYPE.
166
+ *
167
+ * @retval 0 Success.
168
+ * @retval MLK_ERR_OUT_OF_MEMORY MLK_CONFIG_CUSTOM_ALLOC_FREE was used and
169
+ * MLK_CUSTOM_ALLOC returned NULL.
170
+ * @retval MLK_ERR_RNG_FAIL Random number generation failed.
171
+ * @retval MLK_ERR_FAIL MLK_CONFIG_KEYGEN_PCT enabled and PCT failed.
172
+ */
185
173
  MLK_EXTERNAL_API
186
174
  MLK_MUST_CHECK_RETURN_VALUE
187
175
  int mlk_kem_keypair(uint8_t pk[MLKEM_INDCCA_PUBLICKEYBYTES],
@@ -197,33 +185,29 @@ __contract__(
197
185
  return_value == MLK_ERR_RNG_FAIL)
198
186
  );
199
187
 
200
- /*************************************************
201
- * Name: mlk_kem_enc_derand
202
- *
203
- * Description: Generates cipher text and shared
204
- * secret for given public key
205
- *
206
- * Arguments: - uint8_t *ct: pointer to output cipher text
207
- * (an already allocated array of MLKEM_INDCCA_CIPHERTEXTBYTES
208
- * bytes)
209
- * - uint8_t *ss: pointer to output shared secret
210
- * (an already allocated array of MLKEM_SSBYTES bytes)
211
- * - const uint8_t *pk: pointer to input public key
212
- * (an already allocated array of MLKEM_INDCCA_PUBLICKEYBYTES
213
- * bytes)
214
- * - const uint8_t *coins: pointer to input randomness
215
- * (an already allocated array filled with MLKEM_SYMBYTES random
216
- * bytes)
217
- *
218
- * Returns: - 0 on success
219
- * - MLK_ERR_FAIL: If the 'modulus check' @[FIPS203, Section 7.2]
220
- * for the public key fails.
221
- * - MLK_ERR_OUT_OF_MEMORY: If MLK_CONFIG_CUSTOM_ALLOC_FREE is
222
- * used and an allocation via MLK_CUSTOM_ALLOC returned NULL.
223
- *
224
- * Specification: Implements @[FIPS203, Algorithm 17, ML-KEM.Encaps_Internal]
225
- *
226
- **************************************************/
188
+ /**
189
+ * Generate ciphertext and shared secret for a given public key.
190
+ *
191
+ * @spec{Implements @[FIPS203, Algorithm 17, ML-KEM.Encaps_Internal].}
192
+ *
193
+ * @param[out] ct Output ciphertext (an already allocated array of
194
+ * MLKEM_INDCCA_CIPHERTEXTBYTES bytes).
195
+ * @param[out] ss Output shared secret (an already allocated array of
196
+ * MLKEM_SSBYTES bytes).
197
+ * @param[in] pk Input public key (an already allocated array of
198
+ * MLKEM_INDCCA_PUBLICKEYBYTES bytes).
199
+ * @param[in] coins Input randomness (an already allocated array filled
200
+ * with MLKEM_SYMBYTES random bytes).
201
+ * @param context Application context. Only present when
202
+ * MLK_CONFIG_CONTEXT_PARAMETER is defined; type set by
203
+ * MLK_CONFIG_CONTEXT_PARAMETER_TYPE.
204
+ *
205
+ * @retval 0 Success.
206
+ * @retval MLK_ERR_FAIL The 'modulus check' @[FIPS203, Section 7.2]
207
+ * for the public key failed.
208
+ * @retval MLK_ERR_OUT_OF_MEMORY MLK_CONFIG_CUSTOM_ALLOC_FREE was used and
209
+ * MLK_CUSTOM_ALLOC returned NULL.
210
+ */
227
211
  MLK_EXTERNAL_API
228
212
  MLK_MUST_CHECK_RETURN_VALUE
229
213
  int mlk_kem_enc_derand(uint8_t ct[MLKEM_INDCCA_CIPHERTEXTBYTES],
@@ -242,31 +226,28 @@ __contract__(
242
226
  return_value == MLK_ERR_OUT_OF_MEMORY)
243
227
  );
244
228
 
245
- /*************************************************
246
- * Name: mlk_kem_enc
247
- *
248
- * Description: Generates cipher text and shared
249
- * secret for given public key
250
- *
251
- * Arguments: - uint8_t *ct: pointer to output cipher text
252
- * (an already allocated array of MLKEM_INDCCA_CIPHERTEXTBYTES
253
- * bytes)
254
- * - uint8_t *ss: pointer to output shared secret
255
- * (an already allocated array of MLKEM_SSBYTES bytes)
256
- * - const uint8_t *pk: pointer to input public key
257
- * (an already allocated array of MLKEM_INDCCA_PUBLICKEYBYTES
258
- * bytes)
259
- *
260
- * Returns: - 0 on success
261
- * - MLK_ERR_OUT_OF_MEMORY: If MLK_CONFIG_CUSTOM_ALLOC_FREE is
262
- * used and an allocation via MLK_CUSTOM_ALLOC returned NULL.
263
- * - MLK_ERR_RNG_FAIL: Random number generation failed.
264
- * - MLK_ERR_FAIL: If the 'modulus check' @[FIPS203, Section 7.2]
265
- * for the public key fails.
266
- *
267
- * Specification: Implements @[FIPS203, Algorithm 20, ML-KEM.Encaps]
268
- *
269
- **************************************************/
229
+ /**
230
+ * Generate ciphertext and shared secret for a given public key.
231
+ *
232
+ * @spec{Implements @[FIPS203, Algorithm 20, ML-KEM.Encaps].}
233
+ *
234
+ * @param[out] ct Output ciphertext (an already allocated array of
235
+ * MLKEM_INDCCA_CIPHERTEXTBYTES bytes).
236
+ * @param[out] ss Output shared secret (an already allocated array of
237
+ * MLKEM_SSBYTES bytes).
238
+ * @param[in] pk Input public key (an already allocated array of
239
+ * MLKEM_INDCCA_PUBLICKEYBYTES bytes).
240
+ * @param context Application context. Only present when
241
+ * MLK_CONFIG_CONTEXT_PARAMETER is defined; type set by
242
+ * MLK_CONFIG_CONTEXT_PARAMETER_TYPE.
243
+ *
244
+ * @retval 0 Success.
245
+ * @retval MLK_ERR_OUT_OF_MEMORY MLK_CONFIG_CUSTOM_ALLOC_FREE was used and
246
+ * MLK_CUSTOM_ALLOC returned NULL.
247
+ * @retval MLK_ERR_RNG_FAIL Random number generation failed.
248
+ * @retval MLK_ERR_FAIL The 'modulus check' @[FIPS203, Section 7.2]
249
+ * for the public key failed.
250
+ */
270
251
  MLK_EXTERNAL_API
271
252
  MLK_MUST_CHECK_RETURN_VALUE
272
253
  int mlk_kem_enc(uint8_t ct[MLKEM_INDCCA_CIPHERTEXTBYTES],
@@ -284,30 +265,27 @@ __contract__(
284
265
  return_value == MLK_ERR_RNG_FAIL)
285
266
  );
286
267
 
287
- /*************************************************
288
- * Name: mlk_kem_dec
289
- *
290
- * Description: Generates shared secret for given
291
- * cipher text and private key
292
- *
293
- * Arguments: - uint8_t *ss: pointer to output shared secret
294
- * (an already allocated array of MLKEM_SSBYTES bytes)
295
- * - const uint8_t *ct: pointer to input cipher text
296
- * (an already allocated array of MLKEM_INDCCA_CIPHERTEXTBYTES
297
- * bytes)
298
- * - const uint8_t *sk: pointer to input private key
299
- * (an already allocated array of MLKEM_INDCCA_SECRETKEYBYTES
300
- * bytes)
301
- *
302
- * Returns: - 0 on success
303
- * - MLK_ERR_FAIL: If the 'hash check' @[FIPS203, Section 7.3]
304
- * for the secret key fails.
305
- * - MLK_ERR_OUT_OF_MEMORY: If MLK_CONFIG_CUSTOM_ALLOC_FREE is
306
- * used and an allocation via MLK_CUSTOM_ALLOC returned NULL.
307
- *
308
- * Specification: Implements @[FIPS203, Algorithm 21, ML-KEM.Decaps]
309
- *
310
- **************************************************/
268
+ /**
269
+ * Generate shared secret for a given ciphertext and private key.
270
+ *
271
+ * @spec{Implements @[FIPS203, Algorithm 21, ML-KEM.Decaps].}
272
+ *
273
+ * @param[out] ss Output shared secret (an already allocated array of
274
+ * MLKEM_SSBYTES bytes).
275
+ * @param[in] ct Input ciphertext (an already allocated array of
276
+ * MLKEM_INDCCA_CIPHERTEXTBYTES bytes).
277
+ * @param[in] sk Input private key (an already allocated array of
278
+ * MLKEM_INDCCA_SECRETKEYBYTES bytes).
279
+ * @param context Application context. Only present when
280
+ * MLK_CONFIG_CONTEXT_PARAMETER is defined; type set by
281
+ * MLK_CONFIG_CONTEXT_PARAMETER_TYPE.
282
+ *
283
+ * @retval 0 Success.
284
+ * @retval MLK_ERR_FAIL The 'hash check' @[FIPS203, Section 7.3]
285
+ * for the secret key failed.
286
+ * @retval MLK_ERR_OUT_OF_MEMORY MLK_CONFIG_CUSTOM_ALLOC_FREE was used and
287
+ * MLK_CUSTOM_ALLOC returned NULL.
288
+ */
311
289
  MLK_EXTERNAL_API
312
290
  MLK_MUST_CHECK_RETURN_VALUE
313
291
  int mlk_kem_dec(uint8_t ss[MLKEM_SSBYTES],
@@ -28,30 +28,30 @@
28
28
  MLK_MUST_CHECK_RETURN_VALUE
29
29
  static MLK_INLINE int mlk_ntt_native(int16_t data[MLKEM_N])
30
30
  {
31
- mlk_ntt_asm(data, mlk_aarch64_ntt_zetas_layer12345,
32
- mlk_aarch64_ntt_zetas_layer67);
31
+ mlk_ntt_aarch64_asm(data, mlk_aarch64_ntt_zetas_layer12345,
32
+ mlk_aarch64_ntt_zetas_layer67);
33
33
  return MLK_NATIVE_FUNC_SUCCESS;
34
34
  }
35
35
 
36
36
  MLK_MUST_CHECK_RETURN_VALUE
37
37
  static MLK_INLINE int mlk_intt_native(int16_t data[MLKEM_N])
38
38
  {
39
- mlk_intt_asm(data, mlk_aarch64_invntt_zetas_layer12345,
40
- mlk_aarch64_invntt_zetas_layer67);
39
+ mlk_intt_aarch64_asm(data, mlk_aarch64_invntt_zetas_layer12345,
40
+ mlk_aarch64_invntt_zetas_layer67);
41
41
  return MLK_NATIVE_FUNC_SUCCESS;
42
42
  }
43
43
 
44
44
  MLK_MUST_CHECK_RETURN_VALUE
45
45
  static MLK_INLINE int mlk_poly_reduce_native(int16_t data[MLKEM_N])
46
46
  {
47
- mlk_poly_reduce_asm(data);
47
+ mlk_poly_reduce_aarch64_asm(data);
48
48
  return MLK_NATIVE_FUNC_SUCCESS;
49
49
  }
50
50
 
51
51
  MLK_MUST_CHECK_RETURN_VALUE
52
52
  static MLK_INLINE int mlk_poly_tomont_native(int16_t data[MLKEM_N])
53
53
  {
54
- mlk_poly_tomont_asm(data);
54
+ mlk_poly_tomont_aarch64_asm(data);
55
55
  return MLK_NATIVE_FUNC_SUCCESS;
56
56
  }
57
57
 
@@ -59,8 +59,9 @@ MLK_MUST_CHECK_RETURN_VALUE
59
59
  static MLK_INLINE int mlk_poly_mulcache_compute_native(int16_t x[MLKEM_N / 2],
60
60
  const int16_t y[MLKEM_N])
61
61
  {
62
- mlk_poly_mulcache_compute_asm(x, y, mlk_aarch64_zetas_mulcache_native,
63
- mlk_aarch64_zetas_mulcache_twisted_native);
62
+ mlk_poly_mulcache_compute_aarch64_asm(
63
+ x, y, mlk_aarch64_zetas_mulcache_native,
64
+ mlk_aarch64_zetas_mulcache_twisted_native);
64
65
  return MLK_NATIVE_FUNC_SUCCESS;
65
66
  }
66
67
 
@@ -70,7 +71,7 @@ static MLK_INLINE int mlk_polyvec_basemul_acc_montgomery_cached_k2_native(
70
71
  int16_t r[MLKEM_N], const int16_t a[2 * MLKEM_N],
71
72
  const int16_t b[2 * MLKEM_N], const int16_t b_cache[2 * (MLKEM_N / 2)])
72
73
  {
73
- mlk_polyvec_basemul_acc_montgomery_cached_asm_k2(r, a, b, b_cache);
74
+ mlk_polyvec_basemul_acc_montgomery_cached_k2_aarch64_asm(r, a, b, b_cache);
74
75
  return MLK_NATIVE_FUNC_SUCCESS;
75
76
  }
76
77
  #endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 2 */
@@ -81,7 +82,7 @@ static MLK_INLINE int mlk_polyvec_basemul_acc_montgomery_cached_k3_native(
81
82
  int16_t r[MLKEM_N], const int16_t a[3 * MLKEM_N],
82
83
  const int16_t b[3 * MLKEM_N], const int16_t b_cache[3 * (MLKEM_N / 2)])
83
84
  {
84
- mlk_polyvec_basemul_acc_montgomery_cached_asm_k3(r, a, b, b_cache);
85
+ mlk_polyvec_basemul_acc_montgomery_cached_k3_aarch64_asm(r, a, b, b_cache);
85
86
  return MLK_NATIVE_FUNC_SUCCESS;
86
87
  }
87
88
  #endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 3 */
@@ -92,7 +93,7 @@ static MLK_INLINE int mlk_polyvec_basemul_acc_montgomery_cached_k4_native(
92
93
  int16_t r[MLKEM_N], const int16_t a[4 * MLKEM_N],
93
94
  const int16_t b[4 * MLKEM_N], const int16_t b_cache[4 * (MLKEM_N / 2)])
94
95
  {
95
- mlk_polyvec_basemul_acc_montgomery_cached_asm_k4(r, a, b, b_cache);
96
+ mlk_polyvec_basemul_acc_montgomery_cached_k4_aarch64_asm(r, a, b, b_cache);
96
97
  return MLK_NATIVE_FUNC_SUCCESS;
97
98
  }
98
99
  #endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 4 */
@@ -101,7 +102,7 @@ MLK_MUST_CHECK_RETURN_VALUE
101
102
  static MLK_INLINE int mlk_poly_tobytes_native(uint8_t r[MLKEM_POLYBYTES],
102
103
  const int16_t a[MLKEM_N])
103
104
  {
104
- mlk_poly_tobytes_asm(r, a);
105
+ mlk_poly_tobytes_aarch64_asm(r, a);
105
106
  return MLK_NATIVE_FUNC_SUCCESS;
106
107
  }
107
108
 
@@ -115,7 +116,8 @@ static MLK_INLINE int mlk_rej_uniform_native(int16_t *r, unsigned len,
115
116
  {
116
117
  return MLK_NATIVE_FUNC_FALLBACK;
117
118
  }
118
- return (int)mlk_rej_uniform_asm(r, buf, buflen, mlk_rej_uniform_table);
119
+ return (int)mlk_rej_uniform_aarch64_asm(r, buf, buflen,
120
+ mlk_rej_uniform_table);
119
121
  }
120
122
  #endif /* !__ASSEMBLER__ */
121
123