libcrux_core.h (17922B)
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 #ifndef internal_libcrux_core_H 15 #define internal_libcrux_core_H 16 17 #include "eurydice_glue.h" 18 19 #if defined(__cplusplus) 20 extern "C" { 21 #endif 22 23 #include "../libcrux_core.h" 24 25 /** 26 A monomorphic instance of core.ops.range.Range 27 with types size_t 28 29 */ 30 typedef struct core_ops_range_Range_08_s { 31 size_t start; 32 size_t end; 33 } core_ops_range_Range_08; 34 35 static inline uint64_t core_num__u64__from_le_bytes(uint8_t x0[8U]); 36 37 static inline uint64_t core_num__u64__rotate_left(uint64_t x0, uint32_t x1); 38 39 static inline void core_num__u64__to_le_bytes(uint64_t x0, uint8_t x1[8U]); 40 41 #define LIBCRUX_ML_KEM_CONSTANTS_SHARED_SECRET_SIZE ((size_t)32U) 42 43 void libcrux_ml_kem_constant_time_ops_compare_ciphertexts_select_shared_secret_in_constant_time( 44 Eurydice_slice lhs_c, Eurydice_slice rhs_c, Eurydice_slice lhs_s, 45 Eurydice_slice rhs_s, uint8_t ret[32U]); 46 47 #define LIBCRUX_ML_KEM_CONSTANTS_BITS_PER_COEFFICIENT ((size_t)12U) 48 49 #define LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT ((size_t)256U) 50 51 #define LIBCRUX_ML_KEM_CONSTANTS_BITS_PER_RING_ELEMENT \ 52 (LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT * (size_t)12U) 53 54 #define LIBCRUX_ML_KEM_CONSTANTS_BYTES_PER_RING_ELEMENT \ 55 (LIBCRUX_ML_KEM_CONSTANTS_BITS_PER_RING_ELEMENT / (size_t)8U) 56 57 #define LIBCRUX_ML_KEM_CONSTANTS_CPA_PKE_KEY_GENERATION_SEED_SIZE ((size_t)32U) 58 59 #define LIBCRUX_ML_KEM_CONSTANTS_H_DIGEST_SIZE ((size_t)32U) 60 61 /** 62 K * BITS_PER_RING_ELEMENT / 8 63 64 [eurydice] Note that we can't use const generics here because that breaks 65 C extraction with eurydice. 66 */ 67 size_t libcrux_ml_kem_constants_ranked_bytes_per_ring_element(size_t rank); 68 69 int16_t libcrux_secrets_int_I16(int16_t v); 70 71 /** 72 This function found in impl {libcrux_secrets::traits::Classify<T> for T} 73 */ 74 /** 75 A monomorphic instance of libcrux_secrets.int.public_integers.classify_27 76 with types int16_t 77 78 */ 79 int16_t libcrux_secrets_int_public_integers_classify_27_39(int16_t self); 80 81 /** 82 This function found in impl {libcrux_secrets::int::CastOps for u8} 83 */ 84 int16_t libcrux_secrets_int_as_i16_59(uint8_t self); 85 86 /** 87 This function found in impl {libcrux_secrets::traits::Declassify<T> for T} 88 */ 89 /** 90 A monomorphic instance of libcrux_secrets.int.public_integers.declassify_d8 91 with types int16_t 92 93 */ 94 int16_t libcrux_secrets_int_public_integers_declassify_d8_39(int16_t self); 95 96 /** 97 This function found in impl {libcrux_secrets::int::CastOps for i16} 98 */ 99 uint8_t libcrux_secrets_int_as_u8_f5(int16_t self); 100 101 /** 102 This function found in impl {libcrux_secrets::int::CastOps for i16} 103 */ 104 int32_t libcrux_secrets_int_as_i32_f5(int16_t self); 105 106 /** 107 This function found in impl {libcrux_secrets::int::CastOps for i32} 108 */ 109 int16_t libcrux_secrets_int_as_i16_36(int32_t self); 110 111 /** 112 This function found in impl {libcrux_secrets::int::CastOps for u32} 113 */ 114 int32_t libcrux_secrets_int_as_i32_b8(uint32_t self); 115 116 /** 117 This function found in impl {libcrux_secrets::int::CastOps for i16} 118 */ 119 uint16_t libcrux_secrets_int_as_u16_f5(int16_t self); 120 121 /** 122 This function found in impl {libcrux_secrets::int::CastOps for u16} 123 */ 124 int16_t libcrux_secrets_int_as_i16_ca(uint16_t self); 125 126 /** 127 This function found in impl {libcrux_secrets::int::CastOps for u16} 128 */ 129 uint64_t libcrux_secrets_int_as_u64_ca(uint16_t self); 130 131 /** 132 This function found in impl {libcrux_secrets::traits::Classify<T> for T} 133 */ 134 /** 135 A monomorphic instance of libcrux_secrets.int.public_integers.classify_27 136 with types uint32_t 137 138 */ 139 uint32_t libcrux_secrets_int_public_integers_classify_27_df(uint32_t self); 140 141 /** 142 This function found in impl {libcrux_secrets::int::CastOps for u64} 143 */ 144 uint32_t libcrux_secrets_int_as_u32_a3(uint64_t self); 145 146 /** 147 This function found in impl {libcrux_secrets::int::CastOps for u32} 148 */ 149 int16_t libcrux_secrets_int_as_i16_b8(uint32_t self); 150 151 /** 152 This function found in impl {libcrux_secrets::int::CastOps for i16} 153 */ 154 int16_t libcrux_secrets_int_as_i16_f5(int16_t self); 155 156 typedef struct libcrux_ml_kem_utils_extraction_helper_Keypair1024_s { 157 uint8_t fst[1536U]; 158 uint8_t snd[1568U]; 159 } libcrux_ml_kem_utils_extraction_helper_Keypair1024; 160 161 typedef struct libcrux_ml_kem_utils_extraction_helper_Keypair768_s { 162 uint8_t fst[1152U]; 163 uint8_t snd[1184U]; 164 } libcrux_ml_kem_utils_extraction_helper_Keypair768; 165 166 /** 167 This function found in impl 168 {libcrux_ml_kem::types::MlKemKeyPair<PRIVATE_KEY_SIZE, PUBLIC_KEY_SIZE>} 169 */ 170 /** 171 A monomorphic instance of libcrux_ml_kem.types.from_17 172 with const generics 173 - PRIVATE_KEY_SIZE= 3168 174 - PUBLIC_KEY_SIZE= 1568 175 */ 176 libcrux_ml_kem_mlkem1024_MlKem1024KeyPair libcrux_ml_kem_types_from_17_94( 177 libcrux_ml_kem_types_MlKemPrivateKey_83 sk, 178 libcrux_ml_kem_types_MlKemPublicKey_64 pk); 179 180 /** 181 This function found in impl {core::convert::From<@Array<u8, SIZE>> for 182 libcrux_ml_kem::types::MlKemPrivateKey<SIZE>} 183 */ 184 /** 185 A monomorphic instance of libcrux_ml_kem.types.from_77 186 with const generics 187 - SIZE= 3168 188 */ 189 libcrux_ml_kem_types_MlKemPrivateKey_83 libcrux_ml_kem_types_from_77_39( 190 uint8_t value[3168U]); 191 192 /** 193 This function found in impl {libcrux_ml_kem::types::MlKemCiphertext<SIZE>} 194 */ 195 /** 196 A monomorphic instance of libcrux_ml_kem.types.as_slice_a9 197 with const generics 198 - SIZE= 1568 199 */ 200 uint8_t *libcrux_ml_kem_types_as_slice_a9_af( 201 libcrux_ml_kem_types_MlKemCiphertext_64 *self); 202 203 /** 204 This function found in impl 205 {libcrux_ml_kem::types::MlKemKeyPair<PRIVATE_KEY_SIZE, PUBLIC_KEY_SIZE>} 206 */ 207 /** 208 A monomorphic instance of libcrux_ml_kem.types.from_17 209 with const generics 210 - PRIVATE_KEY_SIZE= 2400 211 - PUBLIC_KEY_SIZE= 1184 212 */ 213 libcrux_ml_kem_mlkem768_MlKem768KeyPair libcrux_ml_kem_types_from_17_74( 214 libcrux_ml_kem_types_MlKemPrivateKey_d9 sk, 215 libcrux_ml_kem_types_MlKemPublicKey_30 pk); 216 217 /** 218 This function found in impl {core::convert::From<@Array<u8, SIZE>> for 219 libcrux_ml_kem::types::MlKemPrivateKey<SIZE>} 220 */ 221 /** 222 A monomorphic instance of libcrux_ml_kem.types.from_77 223 with const generics 224 - SIZE= 2400 225 */ 226 libcrux_ml_kem_types_MlKemPrivateKey_d9 libcrux_ml_kem_types_from_77_28( 227 uint8_t value[2400U]); 228 229 /** 230 This function found in impl {libcrux_ml_kem::types::MlKemCiphertext<SIZE>} 231 */ 232 /** 233 A monomorphic instance of libcrux_ml_kem.types.as_slice_a9 234 with const generics 235 - SIZE= 1088 236 */ 237 uint8_t *libcrux_ml_kem_types_as_slice_a9_80( 238 libcrux_ml_kem_mlkem768_MlKem768Ciphertext *self); 239 240 /** 241 This function found in impl {libcrux_ml_kem::types::MlKemPublicKey<SIZE>} 242 */ 243 /** 244 A monomorphic instance of libcrux_ml_kem.types.as_slice_e6 245 with const generics 246 - SIZE= 1184 247 */ 248 uint8_t *libcrux_ml_kem_types_as_slice_e6_d0( 249 libcrux_ml_kem_types_MlKemPublicKey_30 *self); 250 251 /** 252 This function found in impl {core::convert::From<@Array<u8, SIZE>> for 253 libcrux_ml_kem::types::MlKemPublicKey<SIZE>} 254 */ 255 /** 256 A monomorphic instance of libcrux_ml_kem.types.from_fd 257 with const generics 258 - SIZE= 1184 259 */ 260 libcrux_ml_kem_types_MlKemPublicKey_30 libcrux_ml_kem_types_from_fd_d0( 261 uint8_t value[1184U]); 262 263 typedef struct Eurydice_slice_uint8_t_x4_s { 264 Eurydice_slice fst; 265 Eurydice_slice snd; 266 Eurydice_slice thd; 267 Eurydice_slice f3; 268 } Eurydice_slice_uint8_t_x4; 269 270 typedef struct Eurydice_slice_uint8_t_x2_s { 271 Eurydice_slice fst; 272 Eurydice_slice snd; 273 } Eurydice_slice_uint8_t_x2; 274 275 /** 276 Unpack an incoming private key into it's different parts. 277 278 We have this here in types to extract into a common core for C. 279 */ 280 /** 281 A monomorphic instance of libcrux_ml_kem.types.unpack_private_key 282 with const generics 283 - CPA_SECRET_KEY_SIZE= 1152 284 - PUBLIC_KEY_SIZE= 1184 285 */ 286 Eurydice_slice_uint8_t_x4 libcrux_ml_kem_types_unpack_private_key_b4( 287 Eurydice_slice private_key); 288 289 /** 290 This function found in impl {core::convert::From<@Array<u8, SIZE>> for 291 libcrux_ml_kem::types::MlKemCiphertext<SIZE>} 292 */ 293 /** 294 A monomorphic instance of libcrux_ml_kem.types.from_e0 295 with const generics 296 - SIZE= 1088 297 */ 298 libcrux_ml_kem_mlkem768_MlKem768Ciphertext libcrux_ml_kem_types_from_e0_80( 299 uint8_t value[1088U]); 300 301 /** 302 A monomorphic instance of libcrux_ml_kem.utils.prf_input_inc 303 with const generics 304 - K= 3 305 */ 306 uint8_t libcrux_ml_kem_utils_prf_input_inc_e0(uint8_t (*prf_inputs)[33U], 307 uint8_t domain_separator); 308 309 /** 310 This function found in impl {core::convert::AsRef<@Slice<u8>> for 311 libcrux_ml_kem::types::MlKemCiphertext<SIZE>} 312 */ 313 /** 314 A monomorphic instance of libcrux_ml_kem.types.as_ref_d3 315 with const generics 316 - SIZE= 1088 317 */ 318 Eurydice_slice libcrux_ml_kem_types_as_ref_d3_80( 319 libcrux_ml_kem_mlkem768_MlKem768Ciphertext *self); 320 321 /** 322 Pad the `slice` with `0`s at the end. 323 */ 324 /** 325 A monomorphic instance of libcrux_ml_kem.utils.into_padded_array 326 with const generics 327 - LEN= 1120 328 */ 329 void libcrux_ml_kem_utils_into_padded_array_15(Eurydice_slice slice, 330 uint8_t ret[1120U]); 331 332 /** 333 This function found in impl {libcrux_ml_kem::types::MlKemPublicKey<SIZE>} 334 */ 335 /** 336 A monomorphic instance of libcrux_ml_kem.types.as_slice_e6 337 with const generics 338 - SIZE= 1568 339 */ 340 uint8_t *libcrux_ml_kem_types_as_slice_e6_af( 341 libcrux_ml_kem_types_MlKemPublicKey_64 *self); 342 343 /** 344 This function found in impl {core::convert::From<@Array<u8, SIZE>> for 345 libcrux_ml_kem::types::MlKemPublicKey<SIZE>} 346 */ 347 /** 348 A monomorphic instance of libcrux_ml_kem.types.from_fd 349 with const generics 350 - SIZE= 1568 351 */ 352 libcrux_ml_kem_types_MlKemPublicKey_64 libcrux_ml_kem_types_from_fd_af( 353 uint8_t value[1568U]); 354 355 /** 356 Unpack an incoming private key into it's different parts. 357 358 We have this here in types to extract into a common core for C. 359 */ 360 /** 361 A monomorphic instance of libcrux_ml_kem.types.unpack_private_key 362 with const generics 363 - CPA_SECRET_KEY_SIZE= 1536 364 - PUBLIC_KEY_SIZE= 1568 365 */ 366 Eurydice_slice_uint8_t_x4 libcrux_ml_kem_types_unpack_private_key_1f( 367 Eurydice_slice private_key); 368 369 #define core_result_Ok 0 370 #define core_result_Err 1 371 372 typedef uint8_t core_result_Result_fb_tags; 373 374 /** 375 A monomorphic instance of core.result.Result 376 with types uint8_t[32size_t], core_array_TryFromSliceError 377 378 */ 379 typedef struct core_result_Result_fb_s { 380 core_result_Result_fb_tags tag; 381 union { 382 uint8_t case_Ok[32U]; 383 core_array_TryFromSliceError case_Err; 384 } val; 385 } core_result_Result_fb; 386 387 /** 388 This function found in impl {core::result::Result<T, E>[TraitClause@0, 389 TraitClause@1]} 390 */ 391 /** 392 A monomorphic instance of core.result.unwrap_26 393 with types uint8_t[32size_t], core_array_TryFromSliceError 394 395 */ 396 void core_result_unwrap_26_b3(core_result_Result_fb self, uint8_t ret[32U]); 397 398 /** 399 Pad the `slice` with `0`s at the end. 400 */ 401 /** 402 A monomorphic instance of libcrux_ml_kem.utils.into_padded_array 403 with const generics 404 - LEN= 34 405 */ 406 void libcrux_ml_kem_utils_into_padded_array_b6(Eurydice_slice slice, 407 uint8_t ret[34U]); 408 409 /** 410 This function found in impl {core::convert::From<@Array<u8, SIZE>> for 411 libcrux_ml_kem::types::MlKemCiphertext<SIZE>} 412 */ 413 /** 414 A monomorphic instance of libcrux_ml_kem.types.from_e0 415 with const generics 416 - SIZE= 1568 417 */ 418 libcrux_ml_kem_types_MlKemCiphertext_64 libcrux_ml_kem_types_from_e0_af( 419 uint8_t value[1568U]); 420 421 /** 422 A monomorphic instance of libcrux_ml_kem.utils.prf_input_inc 423 with const generics 424 - K= 4 425 */ 426 uint8_t libcrux_ml_kem_utils_prf_input_inc_ac(uint8_t (*prf_inputs)[33U], 427 uint8_t domain_separator); 428 429 /** 430 Pad the `slice` with `0`s at the end. 431 */ 432 /** 433 A monomorphic instance of libcrux_ml_kem.utils.into_padded_array 434 with const generics 435 - LEN= 33 436 */ 437 void libcrux_ml_kem_utils_into_padded_array_c8(Eurydice_slice slice, 438 uint8_t ret[33U]); 439 440 /** 441 This function found in impl {core::convert::AsRef<@Slice<u8>> for 442 libcrux_ml_kem::types::MlKemCiphertext<SIZE>} 443 */ 444 /** 445 A monomorphic instance of libcrux_ml_kem.types.as_ref_d3 446 with const generics 447 - SIZE= 1568 448 */ 449 Eurydice_slice libcrux_ml_kem_types_as_ref_d3_af( 450 libcrux_ml_kem_types_MlKemCiphertext_64 *self); 451 452 /** 453 Pad the `slice` with `0`s at the end. 454 */ 455 /** 456 A monomorphic instance of libcrux_ml_kem.utils.into_padded_array 457 with const generics 458 - LEN= 1600 459 */ 460 void libcrux_ml_kem_utils_into_padded_array_7f(Eurydice_slice slice, 461 uint8_t ret[1600U]); 462 463 /** 464 Pad the `slice` with `0`s at the end. 465 */ 466 /** 467 A monomorphic instance of libcrux_ml_kem.utils.into_padded_array 468 with const generics 469 - LEN= 64 470 */ 471 void libcrux_ml_kem_utils_into_padded_array_24(Eurydice_slice slice, 472 uint8_t ret[64U]); 473 474 /** 475 This function found in impl {libcrux_secrets::traits::Declassify<T> for T} 476 */ 477 /** 478 A monomorphic instance of libcrux_secrets.int.public_integers.declassify_d8 479 with types uint8_t[24size_t] 480 481 */ 482 void libcrux_secrets_int_public_integers_declassify_d8_d2(uint8_t self[24U], 483 uint8_t ret[24U]); 484 485 /** 486 This function found in impl {libcrux_secrets::traits::Declassify<T> for T} 487 */ 488 /** 489 A monomorphic instance of libcrux_secrets.int.public_integers.declassify_d8 490 with types uint8_t[22size_t] 491 492 */ 493 void libcrux_secrets_int_public_integers_declassify_d8_fa(uint8_t self[22U], 494 uint8_t ret[22U]); 495 496 /** 497 This function found in impl {libcrux_secrets::traits::Declassify<T> for T} 498 */ 499 /** 500 A monomorphic instance of libcrux_secrets.int.public_integers.declassify_d8 501 with types uint8_t[20size_t] 502 503 */ 504 void libcrux_secrets_int_public_integers_declassify_d8_57(uint8_t self[20U], 505 uint8_t ret[20U]); 506 507 /** 508 This function found in impl {libcrux_secrets::traits::Declassify<T> for T} 509 */ 510 /** 511 A monomorphic instance of libcrux_secrets.int.public_integers.declassify_d8 512 with types uint8_t[10size_t] 513 514 */ 515 void libcrux_secrets_int_public_integers_declassify_d8_cc(uint8_t self[10U], 516 uint8_t ret[10U]); 517 518 /** 519 This function found in impl {libcrux_secrets::traits::Declassify<T> for T} 520 */ 521 /** 522 A monomorphic instance of libcrux_secrets.int.public_integers.declassify_d8 523 with types uint8_t[8size_t] 524 525 */ 526 void libcrux_secrets_int_public_integers_declassify_d8_76(uint8_t self[8U], 527 uint8_t ret[8U]); 528 529 /** 530 This function found in impl {libcrux_secrets::traits::Declassify<T> for T} 531 */ 532 /** 533 A monomorphic instance of libcrux_secrets.int.public_integers.declassify_d8 534 with types uint8_t[2size_t] 535 536 */ 537 void libcrux_secrets_int_public_integers_declassify_d8_d4(uint8_t self[2U], 538 uint8_t ret[2U]); 539 540 /** 541 Classify a mutable slice (identity) 542 We define a separate function for this because hax has limited support for 543 &mut-returning functions 544 */ 545 /** 546 A monomorphic instance of libcrux_secrets.int.public_integers.classify_mut_slice 547 with types Eurydice_slice uint8_t 548 549 */ 550 Eurydice_slice libcrux_secrets_int_public_integers_classify_mut_slice_ba( 551 Eurydice_slice x); 552 553 /** 554 This function found in impl {libcrux_secrets::traits::ClassifyRef<&'a 555 (@Slice<T>)> for &'a (@Slice<T>)} 556 */ 557 /** 558 A monomorphic instance of libcrux_secrets.int.classify_public.classify_ref_9b 559 with types uint8_t 560 561 */ 562 Eurydice_slice libcrux_secrets_int_classify_public_classify_ref_9b_90( 563 Eurydice_slice self); 564 565 /** 566 This function found in impl {libcrux_secrets::traits::Declassify<T> for T} 567 */ 568 /** 569 A monomorphic instance of libcrux_secrets.int.public_integers.declassify_d8 570 with types int16_t[16size_t] 571 572 */ 573 void libcrux_secrets_int_public_integers_declassify_d8_46(int16_t self[16U], 574 int16_t ret[16U]); 575 576 /** 577 This function found in impl {libcrux_secrets::traits::ClassifyRef<&'a 578 (@Slice<T>)> for &'a (@Slice<T>)} 579 */ 580 /** 581 A monomorphic instance of libcrux_secrets.int.classify_public.classify_ref_9b 582 with types int16_t 583 584 */ 585 Eurydice_slice libcrux_secrets_int_classify_public_classify_ref_9b_39( 586 Eurydice_slice self); 587 588 /** 589 A monomorphic instance of core.result.Result 590 with types int16_t[16size_t], core_array_TryFromSliceError 591 592 */ 593 typedef struct core_result_Result_0a_s { 594 core_result_Result_fb_tags tag; 595 union { 596 int16_t case_Ok[16U]; 597 core_array_TryFromSliceError case_Err; 598 } val; 599 } core_result_Result_0a; 600 601 /** 602 This function found in impl {core::result::Result<T, E>[TraitClause@0, 603 TraitClause@1]} 604 */ 605 /** 606 A monomorphic instance of core.result.unwrap_26 607 with types int16_t[16size_t], core_array_TryFromSliceError 608 609 */ 610 void core_result_unwrap_26_00(core_result_Result_0a self, int16_t ret[16U]); 611 612 /** 613 This function found in impl {libcrux_secrets::traits::Classify<T> for T} 614 */ 615 /** 616 A monomorphic instance of libcrux_secrets.int.public_integers.classify_27 617 with types int16_t[16size_t] 618 619 */ 620 void libcrux_secrets_int_public_integers_classify_27_46(int16_t self[16U], 621 int16_t ret[16U]); 622 623 /** 624 A monomorphic instance of core.result.Result 625 with types uint8_t[8size_t], core_array_TryFromSliceError 626 627 */ 628 typedef struct core_result_Result_15_s { 629 core_result_Result_fb_tags tag; 630 union { 631 uint8_t case_Ok[8U]; 632 core_array_TryFromSliceError case_Err; 633 } val; 634 } core_result_Result_15; 635 636 /** 637 This function found in impl {core::result::Result<T, E>[TraitClause@0, 638 TraitClause@1]} 639 */ 640 /** 641 A monomorphic instance of core.result.unwrap_26 642 with types uint8_t[8size_t], core_array_TryFromSliceError 643 644 */ 645 void core_result_unwrap_26_68(core_result_Result_15 self, uint8_t ret[8U]); 646 647 #if defined(__cplusplus) 648 } 649 #endif 650 651 #define internal_libcrux_core_H_DEFINED 652 #endif /* internal_libcrux_core_H */