libcrux_mlkem1024_portable.c (5454B)
1 /* 2 * SPDX-FileCopyrightText: 2025 Cryspen Sarl <info@cryspen.com> 3 * 4 * SPDX-License-Identifier: MIT or Apache-2.0 5 * 6 * This code was generated with the following revisions: 7 * Charon: 667d2fc98984ff7f3df989c2367e6c1fa4a000e7 8 * Eurydice: 2381cbc416ef2ad0b561c362c500bc84f36b6785 9 * Karamel: 80f5435f2fc505973c469a4afcc8d875cddd0d8b 10 * F*: 71d8221589d4d438af3706d89cb653cf53e18aab 11 * Libcrux: 68dfed5a4a9e40277f62828471c029afed1ecdcc 12 */ 13 14 #include "libcrux_mlkem1024_portable.h" 15 16 #include "internal/libcrux_mlkem_portable.h" 17 #include "libcrux_core.h" 18 19 /** 20 Portable decapsulate 21 */ 22 /** 23 A monomorphic instance of 24 libcrux_ml_kem.ind_cca.instantiations.portable.decapsulate with const generics 25 - K= 4 26 - SECRET_KEY_SIZE= 3168 27 - CPA_SECRET_KEY_SIZE= 1536 28 - PUBLIC_KEY_SIZE= 1568 29 - CIPHERTEXT_SIZE= 1568 30 - T_AS_NTT_ENCODED_SIZE= 1536 31 - C1_SIZE= 1408 32 - C2_SIZE= 160 33 - VECTOR_U_COMPRESSION_FACTOR= 11 34 - VECTOR_V_COMPRESSION_FACTOR= 5 35 - C1_BLOCK_SIZE= 352 36 - ETA1= 2 37 - ETA1_RANDOMNESS_SIZE= 128 38 - ETA2= 2 39 - ETA2_RANDOMNESS_SIZE= 128 40 - IMPLICIT_REJECTION_HASH_INPUT_SIZE= 1600 41 */ 42 static void 43 decapsulate_e0(libcrux_ml_kem_types_MlKemPrivateKey_83 *private_key, 44 libcrux_ml_kem_types_MlKemCiphertext_64 *ciphertext, 45 uint8_t ret[32U]) 46 { 47 libcrux_ml_kem_ind_cca_decapsulate_620(private_key, ciphertext, ret); 48 } 49 50 /** 51 Decapsulate ML-KEM 1024 52 53 Generates an [`MlKemSharedSecret`]. 54 The input is a reference to an [`MlKem1024PrivateKey`] and an 55 [`MlKem1024Ciphertext`]. 56 */ 57 void 58 libcrux_ml_kem_mlkem1024_portable_decapsulate( 59 libcrux_ml_kem_types_MlKemPrivateKey_83 *private_key, 60 libcrux_ml_kem_types_MlKemCiphertext_64 *ciphertext, uint8_t ret[32U]) 61 { 62 decapsulate_e0(private_key, ciphertext, ret); 63 } 64 65 /** 66 A monomorphic instance of 67 libcrux_ml_kem.ind_cca.instantiations.portable.encapsulate with const generics 68 - K= 4 69 - CIPHERTEXT_SIZE= 1568 70 - PUBLIC_KEY_SIZE= 1568 71 - T_AS_NTT_ENCODED_SIZE= 1536 72 - C1_SIZE= 1408 73 - C2_SIZE= 160 74 - VECTOR_U_COMPRESSION_FACTOR= 11 75 - VECTOR_V_COMPRESSION_FACTOR= 5 76 - C1_BLOCK_SIZE= 352 77 - ETA1= 2 78 - ETA1_RANDOMNESS_SIZE= 128 79 - ETA2= 2 80 - ETA2_RANDOMNESS_SIZE= 128 81 */ 82 static tuple_fa 83 encapsulate_8f( 84 libcrux_ml_kem_types_MlKemPublicKey_64 *public_key, uint8_t *randomness) 85 { 86 return libcrux_ml_kem_ind_cca_encapsulate_ca0(public_key, randomness); 87 } 88 89 /** 90 Encapsulate ML-KEM 1024 91 92 Generates an ([`MlKem1024Ciphertext`], [`MlKemSharedSecret`]) tuple. 93 The input is a reference to an [`MlKem1024PublicKey`] and 94 [`SHARED_SECRET_SIZE`] bytes of `randomness`. 95 */ 96 tuple_fa 97 libcrux_ml_kem_mlkem1024_portable_encapsulate( 98 libcrux_ml_kem_types_MlKemPublicKey_64 *public_key, 99 uint8_t randomness[32U]) 100 { 101 return encapsulate_8f(public_key, randomness); 102 } 103 104 /** 105 Portable generate key pair. 106 */ 107 /** 108 A monomorphic instance of 109 libcrux_ml_kem.ind_cca.instantiations.portable.generate_keypair with const 110 generics 111 - K= 4 112 - CPA_PRIVATE_KEY_SIZE= 1536 113 - PRIVATE_KEY_SIZE= 3168 114 - PUBLIC_KEY_SIZE= 1568 115 - ETA1= 2 116 - ETA1_RANDOMNESS_SIZE= 128 117 */ 118 static libcrux_ml_kem_mlkem1024_MlKem1024KeyPair 119 generate_keypair_b4( 120 uint8_t *randomness) 121 { 122 return libcrux_ml_kem_ind_cca_generate_keypair_150(randomness); 123 } 124 125 /** 126 Generate ML-KEM 1024 Key Pair 127 */ 128 libcrux_ml_kem_mlkem1024_MlKem1024KeyPair 129 libcrux_ml_kem_mlkem1024_portable_generate_key_pair(uint8_t randomness[64U]) 130 { 131 return generate_keypair_b4(randomness); 132 } 133 134 /** 135 Private key validation 136 */ 137 /** 138 A monomorphic instance of 139 libcrux_ml_kem.ind_cca.instantiations.portable.validate_private_key with const 140 generics 141 - K= 4 142 - SECRET_KEY_SIZE= 3168 143 - CIPHERTEXT_SIZE= 1568 144 */ 145 static KRML_MUSTINLINE bool 146 validate_private_key_6b( 147 libcrux_ml_kem_types_MlKemPrivateKey_83 *private_key, 148 libcrux_ml_kem_types_MlKemCiphertext_64 *ciphertext) 149 { 150 return libcrux_ml_kem_ind_cca_validate_private_key_b5(private_key, 151 ciphertext); 152 } 153 154 /** 155 Validate a private key. 156 157 Returns `true` if valid, and `false` otherwise. 158 */ 159 bool 160 libcrux_ml_kem_mlkem1024_portable_validate_private_key( 161 libcrux_ml_kem_types_MlKemPrivateKey_83 *private_key, 162 libcrux_ml_kem_types_MlKemCiphertext_64 *ciphertext) 163 { 164 return validate_private_key_6b(private_key, ciphertext); 165 } 166 167 /** 168 Private key validation 169 */ 170 /** 171 A monomorphic instance of 172 libcrux_ml_kem.ind_cca.instantiations.portable.validate_private_key_only with 173 const generics 174 - K= 4 175 - SECRET_KEY_SIZE= 3168 176 */ 177 static KRML_MUSTINLINE bool 178 validate_private_key_only_44( 179 libcrux_ml_kem_types_MlKemPrivateKey_83 *private_key) 180 { 181 return libcrux_ml_kem_ind_cca_validate_private_key_only_60(private_key); 182 } 183 184 /** 185 Validate the private key only. 186 187 Returns `true` if valid, and `false` otherwise. 188 */ 189 bool 190 libcrux_ml_kem_mlkem1024_portable_validate_private_key_only( 191 libcrux_ml_kem_types_MlKemPrivateKey_83 *private_key) 192 { 193 return validate_private_key_only_44(private_key); 194 } 195 196 /** 197 Public key validation 198 */ 199 /** 200 A monomorphic instance of 201 libcrux_ml_kem.ind_cca.instantiations.portable.validate_public_key with const 202 generics 203 - K= 4 204 - PUBLIC_KEY_SIZE= 1568 205 */ 206 static KRML_MUSTINLINE bool 207 validate_public_key_44(uint8_t *public_key) 208 { 209 return libcrux_ml_kem_ind_cca_validate_public_key_ff(public_key); 210 } 211 212 /** 213 Validate a public key. 214 215 Returns `true` if valid, and `false` otherwise. 216 */ 217 bool 218 libcrux_ml_kem_mlkem1024_portable_validate_public_key( 219 libcrux_ml_kem_types_MlKemPublicKey_64 *public_key) 220 { 221 return validate_public_key_44(public_key->value); 222 }