libcrux_core.c (29186B)
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 "internal/libcrux_core.h" 15 16 /** 17 Return 1 if `value` is not zero and 0 otherwise. 18 */ 19 static KRML_NOINLINE uint8_t 20 inz(uint8_t value) 21 { 22 uint16_t value0 = (uint16_t)value; 23 uint8_t result = 24 (uint8_t)((uint32_t)core_num__u16__wrapping_add(~value0, 1U) >> 8U); 25 return (uint32_t)result & 1U; 26 } 27 28 static KRML_NOINLINE uint8_t 29 is_non_zero(uint8_t value) 30 { 31 return inz(value); 32 } 33 34 /** 35 Return 1 if the bytes of `lhs` and `rhs` do not exactly 36 match and 0 otherwise. 37 */ 38 static KRML_NOINLINE uint8_t 39 compare(Eurydice_slice lhs, Eurydice_slice rhs) 40 { 41 uint8_t r = 0U; 42 for (size_t i = (size_t)0U; i < Eurydice_slice_len(lhs, uint8_t); i++) { 43 size_t i0 = i; 44 uint8_t nr = (uint32_t)r | 45 ((uint32_t)Eurydice_slice_index(lhs, i0, uint8_t, uint8_t *) ^ 46 (uint32_t)Eurydice_slice_index(rhs, i0, uint8_t, uint8_t *)); 47 r = nr; 48 } 49 return is_non_zero(r); 50 } 51 52 static KRML_NOINLINE uint8_t 53 compare_ciphertexts_in_constant_time(Eurydice_slice lhs, Eurydice_slice rhs) 54 { 55 return compare(lhs, rhs); 56 } 57 58 /** 59 If `selector` is not zero, return the bytes in `rhs`; return the bytes in 60 `lhs` otherwise. 61 */ 62 static KRML_NOINLINE void 63 select_ct(Eurydice_slice lhs, Eurydice_slice rhs, 64 uint8_t selector, uint8_t ret[32U]) 65 { 66 uint8_t mask = core_num__u8__wrapping_sub(is_non_zero(selector), 1U); 67 uint8_t out[32U] = { 0U }; 68 for (size_t i = (size_t)0U; i < LIBCRUX_ML_KEM_CONSTANTS_SHARED_SECRET_SIZE; 69 i++) { 70 size_t i0 = i; 71 uint8_t outi = 72 ((uint32_t)Eurydice_slice_index(lhs, i0, uint8_t, uint8_t *) & 73 (uint32_t)mask) | 74 ((uint32_t)Eurydice_slice_index(rhs, i0, uint8_t, uint8_t *) & 75 (uint32_t)~mask); 76 out[i0] = outi; 77 } 78 memcpy(ret, out, (size_t)32U * sizeof(uint8_t)); 79 } 80 81 static KRML_NOINLINE void 82 select_shared_secret_in_constant_time( 83 Eurydice_slice lhs, Eurydice_slice rhs, uint8_t selector, 84 uint8_t ret[32U]) 85 { 86 select_ct(lhs, rhs, selector, ret); 87 } 88 89 KRML_NOINLINE void 90 libcrux_ml_kem_constant_time_ops_compare_ciphertexts_select_shared_secret_in_constant_time( 91 Eurydice_slice lhs_c, Eurydice_slice rhs_c, Eurydice_slice lhs_s, 92 Eurydice_slice rhs_s, uint8_t ret[32U]) 93 { 94 uint8_t selector = compare_ciphertexts_in_constant_time(lhs_c, rhs_c); 95 uint8_t ret0[32U]; 96 select_shared_secret_in_constant_time(lhs_s, rhs_s, selector, ret0); 97 memcpy(ret, ret0, (size_t)32U * sizeof(uint8_t)); 98 } 99 100 /** 101 K * BITS_PER_RING_ELEMENT / 8 102 103 [eurydice] Note that we can't use const generics here because that breaks 104 C extraction with eurydice. 105 */ 106 size_t 107 libcrux_ml_kem_constants_ranked_bytes_per_ring_element(size_t rank) 108 { 109 return rank * LIBCRUX_ML_KEM_CONSTANTS_BITS_PER_RING_ELEMENT / (size_t)8U; 110 } 111 112 /** 113 Construct a public integer (identity) 114 */ 115 /** 116 A monomorphic instance of libcrux_secrets.int.public_integers.secret 117 with types int16_t 118 119 */ 120 static KRML_MUSTINLINE int16_t 121 secret_39(int16_t x) 122 { 123 return x; 124 } 125 126 int16_t 127 libcrux_secrets_int_I16(int16_t v) 128 { 129 return secret_39(v); 130 } 131 132 /** 133 This function found in impl {libcrux_secrets::traits::Classify<T> for T} 134 */ 135 /** 136 A monomorphic instance of libcrux_secrets.int.public_integers.classify_27 137 with types int16_t 138 139 */ 140 int16_t 141 libcrux_secrets_int_public_integers_classify_27_39(int16_t self) 142 { 143 return self; 144 } 145 146 /** 147 This function found in impl {libcrux_secrets::traits::Declassify<T> for T} 148 */ 149 /** 150 A monomorphic instance of libcrux_secrets.int.public_integers.declassify_d8 151 with types uint8_t 152 153 */ 154 static KRML_MUSTINLINE uint8_t 155 declassify_d8_90(uint8_t self) 156 { 157 return self; 158 } 159 160 /** 161 This function found in impl {libcrux_secrets::int::CastOps for u8} 162 */ 163 int16_t 164 libcrux_secrets_int_as_i16_59(uint8_t self) 165 { 166 return libcrux_secrets_int_public_integers_classify_27_39( 167 (int16_t)declassify_d8_90(self)); 168 } 169 170 /** 171 This function found in impl {libcrux_secrets::traits::Classify<T> for T} 172 */ 173 /** 174 A monomorphic instance of libcrux_secrets.int.public_integers.classify_27 175 with types uint8_t 176 177 */ 178 static KRML_MUSTINLINE uint8_t 179 classify_27_90(uint8_t self) 180 { 181 return self; 182 } 183 184 /** 185 This function found in impl {libcrux_secrets::traits::Declassify<T> for T} 186 */ 187 /** 188 A monomorphic instance of libcrux_secrets.int.public_integers.declassify_d8 189 with types int16_t 190 191 */ 192 int16_t 193 libcrux_secrets_int_public_integers_declassify_d8_39(int16_t self) 194 { 195 return self; 196 } 197 198 /** 199 This function found in impl {libcrux_secrets::int::CastOps for i16} 200 */ 201 uint8_t 202 libcrux_secrets_int_as_u8_f5(int16_t self) 203 { 204 return classify_27_90( 205 (uint8_t)libcrux_secrets_int_public_integers_declassify_d8_39(self)); 206 } 207 208 /** 209 This function found in impl {libcrux_secrets::traits::Classify<T> for T} 210 */ 211 /** 212 A monomorphic instance of libcrux_secrets.int.public_integers.classify_27 213 with types int32_t 214 215 */ 216 static KRML_MUSTINLINE int32_t 217 classify_27_a8(int32_t self) 218 { 219 return self; 220 } 221 222 /** 223 This function found in impl {libcrux_secrets::int::CastOps for i16} 224 */ 225 int32_t 226 libcrux_secrets_int_as_i32_f5(int16_t self) 227 { 228 return classify_27_a8( 229 (int32_t)libcrux_secrets_int_public_integers_declassify_d8_39(self)); 230 } 231 232 /** 233 This function found in impl {libcrux_secrets::traits::Declassify<T> for T} 234 */ 235 /** 236 A monomorphic instance of libcrux_secrets.int.public_integers.declassify_d8 237 with types int32_t 238 239 */ 240 static KRML_MUSTINLINE int32_t 241 declassify_d8_a8(int32_t self) 242 { 243 return self; 244 } 245 246 /** 247 This function found in impl {libcrux_secrets::int::CastOps for i32} 248 */ 249 int16_t 250 libcrux_secrets_int_as_i16_36(int32_t self) 251 { 252 return libcrux_secrets_int_public_integers_classify_27_39( 253 (int16_t)declassify_d8_a8(self)); 254 } 255 256 /** 257 This function found in impl {libcrux_secrets::traits::Declassify<T> for T} 258 */ 259 /** 260 A monomorphic instance of libcrux_secrets.int.public_integers.declassify_d8 261 with types uint32_t 262 263 */ 264 static KRML_MUSTINLINE uint32_t 265 declassify_d8_df(uint32_t self) 266 { 267 return self; 268 } 269 270 /** 271 This function found in impl {libcrux_secrets::int::CastOps for u32} 272 */ 273 int32_t 274 libcrux_secrets_int_as_i32_b8(uint32_t self) 275 { 276 return classify_27_a8((int32_t)declassify_d8_df(self)); 277 } 278 279 /** 280 This function found in impl {libcrux_secrets::traits::Classify<T> for T} 281 */ 282 /** 283 A monomorphic instance of libcrux_secrets.int.public_integers.classify_27 284 with types uint16_t 285 286 */ 287 static KRML_MUSTINLINE uint16_t 288 classify_27_de(uint16_t self) 289 { 290 return self; 291 } 292 293 /** 294 This function found in impl {libcrux_secrets::int::CastOps for i16} 295 */ 296 uint16_t 297 libcrux_secrets_int_as_u16_f5(int16_t self) 298 { 299 return classify_27_de( 300 (uint16_t)libcrux_secrets_int_public_integers_declassify_d8_39(self)); 301 } 302 303 /** 304 This function found in impl {libcrux_secrets::traits::Declassify<T> for T} 305 */ 306 /** 307 A monomorphic instance of libcrux_secrets.int.public_integers.declassify_d8 308 with types uint16_t 309 310 */ 311 static KRML_MUSTINLINE uint16_t 312 declassify_d8_de(uint16_t self) 313 { 314 return self; 315 } 316 317 /** 318 This function found in impl {libcrux_secrets::int::CastOps for u16} 319 */ 320 int16_t 321 libcrux_secrets_int_as_i16_ca(uint16_t self) 322 { 323 return libcrux_secrets_int_public_integers_classify_27_39( 324 (int16_t)declassify_d8_de(self)); 325 } 326 327 /** 328 This function found in impl {libcrux_secrets::traits::Classify<T> for T} 329 */ 330 /** 331 A monomorphic instance of libcrux_secrets.int.public_integers.classify_27 332 with types uint64_t 333 334 */ 335 static KRML_MUSTINLINE uint64_t 336 classify_27_49(uint64_t self) 337 { 338 return self; 339 } 340 341 /** 342 This function found in impl {libcrux_secrets::int::CastOps for u16} 343 */ 344 uint64_t 345 libcrux_secrets_int_as_u64_ca(uint16_t self) 346 { 347 return classify_27_49((uint64_t)declassify_d8_de(self)); 348 } 349 350 /** 351 This function found in impl {libcrux_secrets::traits::Classify<T> for T} 352 */ 353 /** 354 A monomorphic instance of libcrux_secrets.int.public_integers.classify_27 355 with types uint32_t 356 357 */ 358 uint32_t 359 libcrux_secrets_int_public_integers_classify_27_df(uint32_t self) 360 { 361 return self; 362 } 363 364 /** 365 This function found in impl {libcrux_secrets::traits::Declassify<T> for T} 366 */ 367 /** 368 A monomorphic instance of libcrux_secrets.int.public_integers.declassify_d8 369 with types uint64_t 370 371 */ 372 static KRML_MUSTINLINE uint64_t 373 declassify_d8_49(uint64_t self) 374 { 375 return self; 376 } 377 378 /** 379 This function found in impl {libcrux_secrets::int::CastOps for u64} 380 */ 381 uint32_t 382 libcrux_secrets_int_as_u32_a3(uint64_t self) 383 { 384 return libcrux_secrets_int_public_integers_classify_27_df( 385 (uint32_t)declassify_d8_49(self)); 386 } 387 388 /** 389 This function found in impl {libcrux_secrets::int::CastOps for u32} 390 */ 391 int16_t 392 libcrux_secrets_int_as_i16_b8(uint32_t self) 393 { 394 return libcrux_secrets_int_public_integers_classify_27_39( 395 (int16_t)declassify_d8_df(self)); 396 } 397 398 /** 399 This function found in impl {libcrux_secrets::int::CastOps for i16} 400 */ 401 int16_t 402 libcrux_secrets_int_as_i16_f5(int16_t self) 403 { 404 return libcrux_secrets_int_public_integers_classify_27_39( 405 libcrux_secrets_int_public_integers_declassify_d8_39(self)); 406 } 407 408 /** 409 This function found in impl 410 {libcrux_ml_kem::types::MlKemKeyPair<PRIVATE_KEY_SIZE, PUBLIC_KEY_SIZE>} 411 */ 412 /** 413 A monomorphic instance of libcrux_ml_kem.types.from_17 414 with const generics 415 - PRIVATE_KEY_SIZE= 3168 416 - PUBLIC_KEY_SIZE= 1568 417 */ 418 libcrux_ml_kem_mlkem1024_MlKem1024KeyPair 419 libcrux_ml_kem_types_from_17_94( 420 libcrux_ml_kem_types_MlKemPrivateKey_83 sk, 421 libcrux_ml_kem_types_MlKemPublicKey_64 pk) 422 { 423 return (KRML_CLITERAL(libcrux_ml_kem_mlkem1024_MlKem1024KeyPair){ .sk = sk, 424 .pk = pk }); 425 } 426 427 /** 428 This function found in impl {core::convert::From<@Array<u8, SIZE>> for 429 libcrux_ml_kem::types::MlKemPrivateKey<SIZE>} 430 */ 431 /** 432 A monomorphic instance of libcrux_ml_kem.types.from_77 433 with const generics 434 - SIZE= 3168 435 */ 436 libcrux_ml_kem_types_MlKemPrivateKey_83 437 libcrux_ml_kem_types_from_77_39( 438 uint8_t value[3168U]) 439 { 440 /* Passing arrays by value in Rust generates a copy in C */ 441 uint8_t copy_of_value[3168U]; 442 memcpy(copy_of_value, value, (size_t)3168U * sizeof(uint8_t)); 443 libcrux_ml_kem_types_MlKemPrivateKey_83 lit; 444 memcpy(lit.value, copy_of_value, (size_t)3168U * sizeof(uint8_t)); 445 return lit; 446 } 447 448 /** 449 This function found in impl {libcrux_ml_kem::types::MlKemCiphertext<SIZE>} 450 */ 451 /** 452 A monomorphic instance of libcrux_ml_kem.types.as_slice_a9 453 with const generics 454 - SIZE= 1568 455 */ 456 uint8_t * 457 libcrux_ml_kem_types_as_slice_a9_af( 458 libcrux_ml_kem_types_MlKemCiphertext_64 *self) 459 { 460 return self->value; 461 } 462 463 /** 464 This function found in impl 465 {libcrux_ml_kem::types::MlKemKeyPair<PRIVATE_KEY_SIZE, PUBLIC_KEY_SIZE>} 466 */ 467 /** 468 A monomorphic instance of libcrux_ml_kem.types.from_17 469 with const generics 470 - PRIVATE_KEY_SIZE= 2400 471 - PUBLIC_KEY_SIZE= 1184 472 */ 473 libcrux_ml_kem_mlkem768_MlKem768KeyPair 474 libcrux_ml_kem_types_from_17_74( 475 libcrux_ml_kem_types_MlKemPrivateKey_d9 sk, 476 libcrux_ml_kem_types_MlKemPublicKey_30 pk) 477 { 478 return (KRML_CLITERAL(libcrux_ml_kem_mlkem768_MlKem768KeyPair){ .sk = sk, 479 .pk = pk }); 480 } 481 482 /** 483 This function found in impl {core::convert::From<@Array<u8, SIZE>> for 484 libcrux_ml_kem::types::MlKemPrivateKey<SIZE>} 485 */ 486 /** 487 A monomorphic instance of libcrux_ml_kem.types.from_77 488 with const generics 489 - SIZE= 2400 490 */ 491 libcrux_ml_kem_types_MlKemPrivateKey_d9 492 libcrux_ml_kem_types_from_77_28( 493 uint8_t value[2400U]) 494 { 495 /* Passing arrays by value in Rust generates a copy in C */ 496 uint8_t copy_of_value[2400U]; 497 memcpy(copy_of_value, value, (size_t)2400U * sizeof(uint8_t)); 498 libcrux_ml_kem_types_MlKemPrivateKey_d9 lit; 499 memcpy(lit.value, copy_of_value, (size_t)2400U * sizeof(uint8_t)); 500 return lit; 501 } 502 503 /** 504 This function found in impl {libcrux_ml_kem::types::MlKemCiphertext<SIZE>} 505 */ 506 /** 507 A monomorphic instance of libcrux_ml_kem.types.as_slice_a9 508 with const generics 509 - SIZE= 1088 510 */ 511 uint8_t * 512 libcrux_ml_kem_types_as_slice_a9_80( 513 libcrux_ml_kem_mlkem768_MlKem768Ciphertext *self) 514 { 515 return self->value; 516 } 517 518 /** 519 This function found in impl {libcrux_ml_kem::types::MlKemPublicKey<SIZE>} 520 */ 521 /** 522 A monomorphic instance of libcrux_ml_kem.types.as_slice_e6 523 with const generics 524 - SIZE= 1184 525 */ 526 uint8_t * 527 libcrux_ml_kem_types_as_slice_e6_d0( 528 libcrux_ml_kem_types_MlKemPublicKey_30 *self) 529 { 530 return self->value; 531 } 532 533 /** 534 This function found in impl {core::convert::From<@Array<u8, SIZE>> for 535 libcrux_ml_kem::types::MlKemPublicKey<SIZE>} 536 */ 537 /** 538 A monomorphic instance of libcrux_ml_kem.types.from_fd 539 with const generics 540 - SIZE= 1184 541 */ 542 libcrux_ml_kem_types_MlKemPublicKey_30 543 libcrux_ml_kem_types_from_fd_d0( 544 uint8_t value[1184U]) 545 { 546 /* Passing arrays by value in Rust generates a copy in C */ 547 uint8_t copy_of_value[1184U]; 548 memcpy(copy_of_value, value, (size_t)1184U * sizeof(uint8_t)); 549 libcrux_ml_kem_types_MlKemPublicKey_30 lit; 550 memcpy(lit.value, copy_of_value, (size_t)1184U * sizeof(uint8_t)); 551 return lit; 552 } 553 554 /** 555 Unpack an incoming private key into it's different parts. 556 557 We have this here in types to extract into a common core for C. 558 */ 559 /** 560 A monomorphic instance of libcrux_ml_kem.types.unpack_private_key 561 with const generics 562 - CPA_SECRET_KEY_SIZE= 1152 563 - PUBLIC_KEY_SIZE= 1184 564 */ 565 Eurydice_slice_uint8_t_x4 566 libcrux_ml_kem_types_unpack_private_key_b4( 567 Eurydice_slice private_key) 568 { 569 Eurydice_slice_uint8_t_x2 uu____0 = Eurydice_slice_split_at( 570 private_key, (size_t)1152U, uint8_t, Eurydice_slice_uint8_t_x2); 571 Eurydice_slice ind_cpa_secret_key = uu____0.fst; 572 Eurydice_slice secret_key0 = uu____0.snd; 573 Eurydice_slice_uint8_t_x2 uu____1 = Eurydice_slice_split_at( 574 secret_key0, (size_t)1184U, uint8_t, Eurydice_slice_uint8_t_x2); 575 Eurydice_slice ind_cpa_public_key = uu____1.fst; 576 Eurydice_slice secret_key = uu____1.snd; 577 Eurydice_slice_uint8_t_x2 uu____2 = Eurydice_slice_split_at( 578 secret_key, LIBCRUX_ML_KEM_CONSTANTS_H_DIGEST_SIZE, uint8_t, 579 Eurydice_slice_uint8_t_x2); 580 Eurydice_slice ind_cpa_public_key_hash = uu____2.fst; 581 Eurydice_slice implicit_rejection_value = uu____2.snd; 582 return ( 583 KRML_CLITERAL(Eurydice_slice_uint8_t_x4){ .fst = ind_cpa_secret_key, 584 .snd = ind_cpa_public_key, 585 .thd = ind_cpa_public_key_hash, 586 .f3 = implicit_rejection_value }); 587 } 588 589 /** 590 This function found in impl {core::convert::From<@Array<u8, SIZE>> for 591 libcrux_ml_kem::types::MlKemCiphertext<SIZE>} 592 */ 593 /** 594 A monomorphic instance of libcrux_ml_kem.types.from_e0 595 with const generics 596 - SIZE= 1088 597 */ 598 libcrux_ml_kem_mlkem768_MlKem768Ciphertext 599 libcrux_ml_kem_types_from_e0_80( 600 uint8_t value[1088U]) 601 { 602 /* Passing arrays by value in Rust generates a copy in C */ 603 uint8_t copy_of_value[1088U]; 604 memcpy(copy_of_value, value, (size_t)1088U * sizeof(uint8_t)); 605 libcrux_ml_kem_mlkem768_MlKem768Ciphertext lit; 606 memcpy(lit.value, copy_of_value, (size_t)1088U * sizeof(uint8_t)); 607 return lit; 608 } 609 610 /** 611 A monomorphic instance of libcrux_ml_kem.utils.prf_input_inc 612 with const generics 613 - K= 3 614 */ 615 uint8_t 616 libcrux_ml_kem_utils_prf_input_inc_e0(uint8_t (*prf_inputs)[33U], 617 uint8_t domain_separator) 618 { 619 KRML_MAYBE_FOR3(i, (size_t)0U, (size_t)3U, (size_t)1U, size_t i0 = i; 620 prf_inputs[i0][32U] = domain_separator; 621 domain_separator = (uint32_t)domain_separator + 1U;); 622 return domain_separator; 623 } 624 625 /** 626 This function found in impl {core::convert::AsRef<@Slice<u8>> for 627 libcrux_ml_kem::types::MlKemCiphertext<SIZE>} 628 */ 629 /** 630 A monomorphic instance of libcrux_ml_kem.types.as_ref_d3 631 with const generics 632 - SIZE= 1088 633 */ 634 Eurydice_slice 635 libcrux_ml_kem_types_as_ref_d3_80( 636 libcrux_ml_kem_mlkem768_MlKem768Ciphertext *self) 637 { 638 return Eurydice_array_to_slice((size_t)1088U, self->value, uint8_t); 639 } 640 641 /** 642 Pad the `slice` with `0`s at the end. 643 */ 644 /** 645 A monomorphic instance of libcrux_ml_kem.utils.into_padded_array 646 with const generics 647 - LEN= 1120 648 */ 649 void 650 libcrux_ml_kem_utils_into_padded_array_15(Eurydice_slice slice, 651 uint8_t ret[1120U]) 652 { 653 uint8_t out[1120U] = { 0U }; 654 uint8_t *uu____0 = out; 655 Eurydice_slice_copy( 656 Eurydice_array_to_subslice3( 657 uu____0, (size_t)0U, Eurydice_slice_len(slice, uint8_t), uint8_t *), 658 slice, uint8_t); 659 memcpy(ret, out, (size_t)1120U * sizeof(uint8_t)); 660 } 661 662 /** 663 This function found in impl {libcrux_ml_kem::types::MlKemPublicKey<SIZE>} 664 */ 665 /** 666 A monomorphic instance of libcrux_ml_kem.types.as_slice_e6 667 with const generics 668 - SIZE= 1568 669 */ 670 uint8_t * 671 libcrux_ml_kem_types_as_slice_e6_af( 672 libcrux_ml_kem_types_MlKemPublicKey_64 *self) 673 { 674 return self->value; 675 } 676 677 /** 678 This function found in impl {core::convert::From<@Array<u8, SIZE>> for 679 libcrux_ml_kem::types::MlKemPublicKey<SIZE>} 680 */ 681 /** 682 A monomorphic instance of libcrux_ml_kem.types.from_fd 683 with const generics 684 - SIZE= 1568 685 */ 686 libcrux_ml_kem_types_MlKemPublicKey_64 687 libcrux_ml_kem_types_from_fd_af( 688 uint8_t value[1568U]) 689 { 690 /* Passing arrays by value in Rust generates a copy in C */ 691 uint8_t copy_of_value[1568U]; 692 memcpy(copy_of_value, value, (size_t)1568U * sizeof(uint8_t)); 693 libcrux_ml_kem_types_MlKemPublicKey_64 lit; 694 memcpy(lit.value, copy_of_value, (size_t)1568U * sizeof(uint8_t)); 695 return lit; 696 } 697 698 /** 699 Unpack an incoming private key into it's different parts. 700 701 We have this here in types to extract into a common core for C. 702 */ 703 /** 704 A monomorphic instance of libcrux_ml_kem.types.unpack_private_key 705 with const generics 706 - CPA_SECRET_KEY_SIZE= 1536 707 - PUBLIC_KEY_SIZE= 1568 708 */ 709 Eurydice_slice_uint8_t_x4 710 libcrux_ml_kem_types_unpack_private_key_1f( 711 Eurydice_slice private_key) 712 { 713 Eurydice_slice_uint8_t_x2 uu____0 = Eurydice_slice_split_at( 714 private_key, (size_t)1536U, uint8_t, Eurydice_slice_uint8_t_x2); 715 Eurydice_slice ind_cpa_secret_key = uu____0.fst; 716 Eurydice_slice secret_key0 = uu____0.snd; 717 Eurydice_slice_uint8_t_x2 uu____1 = Eurydice_slice_split_at( 718 secret_key0, (size_t)1568U, uint8_t, Eurydice_slice_uint8_t_x2); 719 Eurydice_slice ind_cpa_public_key = uu____1.fst; 720 Eurydice_slice secret_key = uu____1.snd; 721 Eurydice_slice_uint8_t_x2 uu____2 = Eurydice_slice_split_at( 722 secret_key, LIBCRUX_ML_KEM_CONSTANTS_H_DIGEST_SIZE, uint8_t, 723 Eurydice_slice_uint8_t_x2); 724 Eurydice_slice ind_cpa_public_key_hash = uu____2.fst; 725 Eurydice_slice implicit_rejection_value = uu____2.snd; 726 return ( 727 KRML_CLITERAL(Eurydice_slice_uint8_t_x4){ .fst = ind_cpa_secret_key, 728 .snd = ind_cpa_public_key, 729 .thd = ind_cpa_public_key_hash, 730 .f3 = implicit_rejection_value }); 731 } 732 733 /** 734 This function found in impl {core::result::Result<T, E>[TraitClause@0, 735 TraitClause@1]} 736 */ 737 /** 738 A monomorphic instance of core.result.unwrap_26 739 with types uint8_t[32size_t], core_array_TryFromSliceError 740 741 */ 742 void 743 core_result_unwrap_26_b3(core_result_Result_fb self, uint8_t ret[32U]) 744 { 745 if (self.tag == core_result_Ok) { 746 uint8_t f0[32U]; 747 memcpy(f0, self.val.case_Ok, (size_t)32U * sizeof(uint8_t)); 748 memcpy(ret, f0, (size_t)32U * sizeof(uint8_t)); 749 } else { 750 KRML_HOST_EPRINTF("KaRaMeL abort at %s:%d\n%s\n", __FILE__, __LINE__, 751 "unwrap not Ok"); 752 KRML_HOST_EXIT(255U); 753 } 754 } 755 756 /** 757 Pad the `slice` with `0`s at the end. 758 */ 759 /** 760 A monomorphic instance of libcrux_ml_kem.utils.into_padded_array 761 with const generics 762 - LEN= 34 763 */ 764 void 765 libcrux_ml_kem_utils_into_padded_array_b6(Eurydice_slice slice, 766 uint8_t ret[34U]) 767 { 768 uint8_t out[34U] = { 0U }; 769 uint8_t *uu____0 = out; 770 Eurydice_slice_copy( 771 Eurydice_array_to_subslice3( 772 uu____0, (size_t)0U, Eurydice_slice_len(slice, uint8_t), uint8_t *), 773 slice, uint8_t); 774 memcpy(ret, out, (size_t)34U * sizeof(uint8_t)); 775 } 776 777 /** 778 This function found in impl {core::convert::From<@Array<u8, SIZE>> for 779 libcrux_ml_kem::types::MlKemCiphertext<SIZE>} 780 */ 781 /** 782 A monomorphic instance of libcrux_ml_kem.types.from_e0 783 with const generics 784 - SIZE= 1568 785 */ 786 libcrux_ml_kem_types_MlKemCiphertext_64 787 libcrux_ml_kem_types_from_e0_af( 788 uint8_t value[1568U]) 789 { 790 /* Passing arrays by value in Rust generates a copy in C */ 791 uint8_t copy_of_value[1568U]; 792 memcpy(copy_of_value, value, (size_t)1568U * sizeof(uint8_t)); 793 libcrux_ml_kem_types_MlKemCiphertext_64 lit; 794 memcpy(lit.value, copy_of_value, (size_t)1568U * sizeof(uint8_t)); 795 return lit; 796 } 797 798 /** 799 A monomorphic instance of libcrux_ml_kem.utils.prf_input_inc 800 with const generics 801 - K= 4 802 */ 803 uint8_t 804 libcrux_ml_kem_utils_prf_input_inc_ac(uint8_t (*prf_inputs)[33U], 805 uint8_t domain_separator) 806 { 807 KRML_MAYBE_FOR4(i, (size_t)0U, (size_t)4U, (size_t)1U, size_t i0 = i; 808 prf_inputs[i0][32U] = domain_separator; 809 domain_separator = (uint32_t)domain_separator + 1U;); 810 return domain_separator; 811 } 812 813 /** 814 Pad the `slice` with `0`s at the end. 815 */ 816 /** 817 A monomorphic instance of libcrux_ml_kem.utils.into_padded_array 818 with const generics 819 - LEN= 33 820 */ 821 void 822 libcrux_ml_kem_utils_into_padded_array_c8(Eurydice_slice slice, 823 uint8_t ret[33U]) 824 { 825 uint8_t out[33U] = { 0U }; 826 uint8_t *uu____0 = out; 827 Eurydice_slice_copy( 828 Eurydice_array_to_subslice3( 829 uu____0, (size_t)0U, Eurydice_slice_len(slice, uint8_t), uint8_t *), 830 slice, uint8_t); 831 memcpy(ret, out, (size_t)33U * sizeof(uint8_t)); 832 } 833 834 /** 835 This function found in impl {core::convert::AsRef<@Slice<u8>> for 836 libcrux_ml_kem::types::MlKemCiphertext<SIZE>} 837 */ 838 /** 839 A monomorphic instance of libcrux_ml_kem.types.as_ref_d3 840 with const generics 841 - SIZE= 1568 842 */ 843 Eurydice_slice 844 libcrux_ml_kem_types_as_ref_d3_af( 845 libcrux_ml_kem_types_MlKemCiphertext_64 *self) 846 { 847 return Eurydice_array_to_slice((size_t)1568U, self->value, uint8_t); 848 } 849 850 /** 851 Pad the `slice` with `0`s at the end. 852 */ 853 /** 854 A monomorphic instance of libcrux_ml_kem.utils.into_padded_array 855 with const generics 856 - LEN= 1600 857 */ 858 void 859 libcrux_ml_kem_utils_into_padded_array_7f(Eurydice_slice slice, 860 uint8_t ret[1600U]) 861 { 862 uint8_t out[1600U] = { 0U }; 863 uint8_t *uu____0 = out; 864 Eurydice_slice_copy( 865 Eurydice_array_to_subslice3( 866 uu____0, (size_t)0U, Eurydice_slice_len(slice, uint8_t), uint8_t *), 867 slice, uint8_t); 868 memcpy(ret, out, (size_t)1600U * sizeof(uint8_t)); 869 } 870 871 /** 872 Pad the `slice` with `0`s at the end. 873 */ 874 /** 875 A monomorphic instance of libcrux_ml_kem.utils.into_padded_array 876 with const generics 877 - LEN= 64 878 */ 879 void 880 libcrux_ml_kem_utils_into_padded_array_24(Eurydice_slice slice, 881 uint8_t ret[64U]) 882 { 883 uint8_t out[64U] = { 0U }; 884 uint8_t *uu____0 = out; 885 Eurydice_slice_copy( 886 Eurydice_array_to_subslice3( 887 uu____0, (size_t)0U, Eurydice_slice_len(slice, uint8_t), uint8_t *), 888 slice, uint8_t); 889 memcpy(ret, out, (size_t)64U * sizeof(uint8_t)); 890 } 891 892 /** 893 This function found in impl {libcrux_secrets::traits::Declassify<T> for T} 894 */ 895 /** 896 A monomorphic instance of libcrux_secrets.int.public_integers.declassify_d8 897 with types uint8_t[24size_t] 898 899 */ 900 void 901 libcrux_secrets_int_public_integers_declassify_d8_d2(uint8_t self[24U], 902 uint8_t ret[24U]) 903 { 904 memcpy(ret, self, (size_t)24U * sizeof(uint8_t)); 905 } 906 907 /** 908 This function found in impl {libcrux_secrets::traits::Declassify<T> for T} 909 */ 910 /** 911 A monomorphic instance of libcrux_secrets.int.public_integers.declassify_d8 912 with types uint8_t[22size_t] 913 914 */ 915 void 916 libcrux_secrets_int_public_integers_declassify_d8_fa(uint8_t self[22U], 917 uint8_t ret[22U]) 918 { 919 memcpy(ret, self, (size_t)22U * sizeof(uint8_t)); 920 } 921 922 /** 923 This function found in impl {libcrux_secrets::traits::Declassify<T> for T} 924 */ 925 /** 926 A monomorphic instance of libcrux_secrets.int.public_integers.declassify_d8 927 with types uint8_t[20size_t] 928 929 */ 930 void 931 libcrux_secrets_int_public_integers_declassify_d8_57(uint8_t self[20U], 932 uint8_t ret[20U]) 933 { 934 memcpy(ret, self, (size_t)20U * sizeof(uint8_t)); 935 } 936 937 /** 938 This function found in impl {libcrux_secrets::traits::Declassify<T> for T} 939 */ 940 /** 941 A monomorphic instance of libcrux_secrets.int.public_integers.declassify_d8 942 with types uint8_t[10size_t] 943 944 */ 945 void 946 libcrux_secrets_int_public_integers_declassify_d8_cc(uint8_t self[10U], 947 uint8_t ret[10U]) 948 { 949 memcpy(ret, self, (size_t)10U * sizeof(uint8_t)); 950 } 951 952 /** 953 This function found in impl {libcrux_secrets::traits::Declassify<T> for T} 954 */ 955 /** 956 A monomorphic instance of libcrux_secrets.int.public_integers.declassify_d8 957 with types uint8_t[8size_t] 958 959 */ 960 void 961 libcrux_secrets_int_public_integers_declassify_d8_76(uint8_t self[8U], 962 uint8_t ret[8U]) 963 { 964 memcpy(ret, self, (size_t)8U * sizeof(uint8_t)); 965 } 966 967 /** 968 This function found in impl {libcrux_secrets::traits::Declassify<T> for T} 969 */ 970 /** 971 A monomorphic instance of libcrux_secrets.int.public_integers.declassify_d8 972 with types uint8_t[2size_t] 973 974 */ 975 void 976 libcrux_secrets_int_public_integers_declassify_d8_d4(uint8_t self[2U], 977 uint8_t ret[2U]) 978 { 979 memcpy(ret, self, (size_t)2U * sizeof(uint8_t)); 980 } 981 982 /** 983 Classify a mutable slice (identity) 984 We define a separate function for this because hax has limited support for 985 &mut-returning functions 986 */ 987 /** 988 A monomorphic instance of libcrux_secrets.int.public_integers.classify_mut_slice 989 with types Eurydice_slice uint8_t 990 991 */ 992 Eurydice_slice 993 libcrux_secrets_int_public_integers_classify_mut_slice_ba( 994 Eurydice_slice x) 995 { 996 return x; 997 } 998 999 /** 1000 This function found in impl {libcrux_secrets::traits::ClassifyRef<&'a 1001 (@Slice<T>)> for &'a (@Slice<T>)} 1002 */ 1003 /** 1004 A monomorphic instance of libcrux_secrets.int.classify_public.classify_ref_9b 1005 with types uint8_t 1006 1007 */ 1008 Eurydice_slice 1009 libcrux_secrets_int_classify_public_classify_ref_9b_90( 1010 Eurydice_slice self) 1011 { 1012 return self; 1013 } 1014 1015 /** 1016 This function found in impl {libcrux_secrets::traits::Declassify<T> for T} 1017 */ 1018 /** 1019 A monomorphic instance of libcrux_secrets.int.public_integers.declassify_d8 1020 with types int16_t[16size_t] 1021 1022 */ 1023 void 1024 libcrux_secrets_int_public_integers_declassify_d8_46(int16_t self[16U], 1025 int16_t ret[16U]) 1026 { 1027 memcpy(ret, self, (size_t)16U * sizeof(int16_t)); 1028 } 1029 1030 /** 1031 This function found in impl {libcrux_secrets::traits::ClassifyRef<&'a 1032 (@Slice<T>)> for &'a (@Slice<T>)} 1033 */ 1034 /** 1035 A monomorphic instance of libcrux_secrets.int.classify_public.classify_ref_9b 1036 with types int16_t 1037 1038 */ 1039 Eurydice_slice 1040 libcrux_secrets_int_classify_public_classify_ref_9b_39( 1041 Eurydice_slice self) 1042 { 1043 return self; 1044 } 1045 1046 /** 1047 This function found in impl {core::result::Result<T, E>[TraitClause@0, 1048 TraitClause@1]} 1049 */ 1050 /** 1051 A monomorphic instance of core.result.unwrap_26 1052 with types int16_t[16size_t], core_array_TryFromSliceError 1053 1054 */ 1055 void 1056 core_result_unwrap_26_00(core_result_Result_0a self, int16_t ret[16U]) 1057 { 1058 if (self.tag == core_result_Ok) { 1059 int16_t f0[16U]; 1060 memcpy(f0, self.val.case_Ok, (size_t)16U * sizeof(int16_t)); 1061 memcpy(ret, f0, (size_t)16U * sizeof(int16_t)); 1062 } else { 1063 KRML_HOST_EPRINTF("KaRaMeL abort at %s:%d\n%s\n", __FILE__, __LINE__, 1064 "unwrap not Ok"); 1065 KRML_HOST_EXIT(255U); 1066 } 1067 } 1068 1069 /** 1070 This function found in impl {libcrux_secrets::traits::Classify<T> for T} 1071 */ 1072 /** 1073 A monomorphic instance of libcrux_secrets.int.public_integers.classify_27 1074 with types int16_t[16size_t] 1075 1076 */ 1077 void 1078 libcrux_secrets_int_public_integers_classify_27_46(int16_t self[16U], 1079 int16_t ret[16U]) 1080 { 1081 memcpy(ret, self, (size_t)16U * sizeof(int16_t)); 1082 } 1083 1084 /** 1085 This function found in impl {core::result::Result<T, E>[TraitClause@0, 1086 TraitClause@1]} 1087 */ 1088 /** 1089 A monomorphic instance of core.result.unwrap_26 1090 with types uint8_t[8size_t], core_array_TryFromSliceError 1091 1092 */ 1093 void 1094 core_result_unwrap_26_68(core_result_Result_15 self, uint8_t ret[8U]) 1095 { 1096 if (self.tag == core_result_Ok) { 1097 uint8_t f0[8U]; 1098 memcpy(f0, self.val.case_Ok, (size_t)8U * sizeof(uint8_t)); 1099 memcpy(ret, f0, (size_t)8U * sizeof(uint8_t)); 1100 } else { 1101 KRML_HOST_EPRINTF("KaRaMeL abort at %s:%d\n%s\n", __FILE__, __LINE__, 1102 "unwrap not Ok"); 1103 KRML_HOST_EXIT(255U); 1104 } 1105 }