/*
 * SPDX-FileCopyrightText: 2026 CE Labs
 *
 * SPDX-License-Identifier: MIT or Apache-2.0
 *
 * This code was generated with the following revisions:
 * Charon: e656e17bff6ca5efac8ab6919b9b74cb9a8dd8ad
 * Eurydice: aaa9fa657fb6f09802edb890252040d94cd93982
 * Karamel: 8c19d41458ce5cbfea029ebc03334ba96d149039
 * F*: 70671ffb81fa30aba09b9d6e2af275dfbccaa8f8
 * Libcrux: 10066f256cec8d50d6111a4cf33ab920cfdb96cb
 */


#include "internal/libcrux_mlkem_portable.h"

#include "libcrux_sha3_portable.h"
#include "libcrux_mlkem_core.h"
#include "libcrux_ct_ops.h"
#include "combined_core.h"
#include "internal/libcrux_sha3_portable.h"
#include "internal/libcrux_mlkem_core.h"
#include "internal/combined_core.h"

inline Eurydice_arr_c7 libcrux_ml_kem_hash_functions_portable_G(Eurydice_borrow_slice_u8 input)
{
  Eurydice_arr_c7 digest = { .data = { 0U } };
  libcrux_sha3_portable_sha512(Eurydice_array_to_slice_mut_17(&digest), input);
  return digest;
}

inline Eurydice_arr_ec libcrux_ml_kem_hash_functions_portable_H(Eurydice_borrow_slice_u8 input)
{
  Eurydice_arr_ec digest = { .data = { 0U } };
  libcrux_sha3_portable_sha256(Eurydice_array_to_slice_mut_01(&digest), input);
  return digest;
}

#define ZETAS_TIMES_MONTGOMERY_R ((KRML_CLITERAL(Eurydice_arr_34){ .data = { -1044, -758, -359, -1517, 1493, 1422, 287, 202, -171, 622, 1577, 182, 962, -1202, -1474, 1468, 573, -1325, 264, 383, -829, 1458, -1602, -130, -681, 1017, 732, 608, -1542, 411, -205, -1571, 1223, 652, -552, 1015, -1293, 1491, -282, -1544, 516, -8, -320, -666, -1618, -1162, 126, 1469, -853, -90, -271, 830, 107, -1421, -247, -951, -398, 961, -1508, -725, 448, -1065, 677, -1275, -1103, 430, 555, 843, -1251, 871, 1550, 105, 422, 587, 177, -235, -291, -460, 1574, 1653, -246, 778, 1159, -147, -777, 1483, -602, 1119, -1590, 644, -872, 349, 418, 329, -156, -75, 817, 1097, 603, 610, 1322, -1285, -1465, 384, -1215, -136, 1218, -1335, -874, 220, -1187, -1659, -1185, -1530, -1278, 794, -1510, -854, -870, 478, -108, -308, 996, 991, 958, -1460, 1522, 1628 } }))

int16_t libcrux_ml_kem_polynomial_zeta(size_t i)
{
  return ZETAS_TIMES_MONTGOMERY_R.data[i];
}

KRML_MUSTINLINE Eurydice_arr_d6
libcrux_ml_kem_vector_portable_vector_type_from_i16_array(Eurydice_borrow_slice_i16 array)
{
  Eurydice_arr_d6 arr;
  memcpy(arr.data,
    Eurydice_slice_subslice_shared_a6(array,
      (KRML_CLITERAL(core_ops_range_Range_87){ .start = (size_t)0U, .end = (size_t)16U })).ptr,
    (size_t)16U * sizeof (int16_t));
  return
    core_result_unwrap_26_d3((
        KRML_CLITERAL(core_result_Result_ec){ .tag = core_result_Ok, .val = { .case_Ok = arr } }
      ));
}

/**
This function found in impl {libcrux_ml_kem::vector::traits::Operations for libcrux_ml_kem::vector::portable::vector_type::PortableVector}
*/
Eurydice_arr_d6
libcrux_ml_kem_vector_portable_from_i16_array_b8(Eurydice_borrow_slice_i16 array)
{
  return
    libcrux_ml_kem_vector_portable_vector_type_from_i16_array(libcrux_secrets_int_classify_public_classify_ref_6d_39(array));
}

KRML_MUSTINLINE uint8_t_x11
libcrux_ml_kem_vector_portable_serialize_serialize_11_int(Eurydice_borrow_slice_i16 v)
{
  uint8_t r0 = libcrux_secrets_int_as_u8_f5(v.ptr[0U]);
  uint8_t
  r1 =
    (uint32_t)libcrux_secrets_int_as_u8_f5(v.ptr[1U] & 31) << 3U |
      (uint32_t)libcrux_secrets_int_as_u8_f5(v.ptr[0U] >> 8U);
  uint8_t
  r2 =
    (uint32_t)libcrux_secrets_int_as_u8_f5(v.ptr[2U] & 3) << 6U |
      (uint32_t)libcrux_secrets_int_as_u8_f5(v.ptr[1U] >> 5U);
  uint8_t r3 = libcrux_secrets_int_as_u8_f5(v.ptr[2U] >> 2U & 255);
  uint8_t
  r4 =
    (uint32_t)libcrux_secrets_int_as_u8_f5(v.ptr[3U] & 127) << 1U |
      (uint32_t)libcrux_secrets_int_as_u8_f5(v.ptr[2U] >> 10U);
  uint8_t
  r5 =
    (uint32_t)libcrux_secrets_int_as_u8_f5(v.ptr[4U] & 15) << 4U |
      (uint32_t)libcrux_secrets_int_as_u8_f5(v.ptr[3U] >> 7U);
  uint8_t
  r6 =
    (uint32_t)libcrux_secrets_int_as_u8_f5(v.ptr[5U] & 1) << 7U |
      (uint32_t)libcrux_secrets_int_as_u8_f5(v.ptr[4U] >> 4U);
  uint8_t r7 = libcrux_secrets_int_as_u8_f5(v.ptr[5U] >> 1U & 255);
  uint8_t
  r8 =
    (uint32_t)libcrux_secrets_int_as_u8_f5(v.ptr[6U] & 63) << 2U |
      (uint32_t)libcrux_secrets_int_as_u8_f5(v.ptr[5U] >> 9U);
  uint8_t
  r9 =
    (uint32_t)libcrux_secrets_int_as_u8_f5(v.ptr[7U] & 7) << 5U |
      (uint32_t)libcrux_secrets_int_as_u8_f5(v.ptr[6U] >> 6U);
  uint8_t r10 = libcrux_secrets_int_as_u8_f5(v.ptr[7U] >> 3U);
  return
    (
      KRML_CLITERAL(uint8_t_x11){
        .fst = r0,
        .snd = r1,
        .thd = r2,
        .f3 = r3,
        .f4 = r4,
        .f5 = r5,
        .f6 = r6,
        .f7 = r7,
        .f8 = r8,
        .f9 = r9,
        .f10 = r10
      }
    );
}

KRML_MUSTINLINE Eurydice_arr_80
libcrux_ml_kem_vector_portable_serialize_serialize_11(Eurydice_arr_d6 v)
{
  uint8_t_x11
  r0_10 =
    libcrux_ml_kem_vector_portable_serialize_serialize_11_int(Eurydice_array_to_subslice_shared_e7(&v,
        (KRML_CLITERAL(core_ops_range_Range_87){ .start = (size_t)0U, .end = (size_t)8U })));
  uint8_t_x11
  r11_21 =
    libcrux_ml_kem_vector_portable_serialize_serialize_11_int(Eurydice_array_to_subslice_shared_e7(&v,
        (KRML_CLITERAL(core_ops_range_Range_87){ .start = (size_t)8U, .end = (size_t)16U })));
  return
    (
      KRML_CLITERAL(Eurydice_arr_80){
        .data = {
          r0_10.fst, r0_10.snd, r0_10.thd, r0_10.f3, r0_10.f4, r0_10.f5, r0_10.f6, r0_10.f7,
          r0_10.f8, r0_10.f9, r0_10.f10, r11_21.fst, r11_21.snd, r11_21.thd, r11_21.f3, r11_21.f4,
          r11_21.f5, r11_21.f6, r11_21.f7, r11_21.f8, r11_21.f9, r11_21.f10
        }
      }
    );
}

Eurydice_arr_80 libcrux_ml_kem_vector_portable_serialize_11(Eurydice_arr_d6 a)
{
  return
    libcrux_secrets_int_classify_public_declassify_91_98(libcrux_ml_kem_vector_portable_serialize_serialize_11(a));
}

/**
This function found in impl {libcrux_ml_kem::vector::traits::Operations for libcrux_ml_kem::vector::portable::vector_type::PortableVector}
*/
Eurydice_arr_80 libcrux_ml_kem_vector_portable_serialize_11_b8(Eurydice_arr_d6 a)
{
  return libcrux_ml_kem_vector_portable_serialize_11(a);
}

KRML_MUSTINLINE int16_t_x8
libcrux_ml_kem_vector_portable_serialize_deserialize_11_int(Eurydice_borrow_slice_u8 bytes)
{
  int16_t
  r0 =
    (int16_t)((uint32_t)(libcrux_secrets_int_as_i16_59(bytes.ptr[1U]) & 7) << 8U) |
      libcrux_secrets_int_as_i16_59(bytes.ptr[0U]);
  int16_t
  r1 =
    (int16_t)((uint32_t)(libcrux_secrets_int_as_i16_59(bytes.ptr[2U]) & 63) << 5U) |
      libcrux_secrets_int_as_i16_59(bytes.ptr[1U]) >> 3U;
  int16_t
  r2 =
    ((int16_t)((uint32_t)(libcrux_secrets_int_as_i16_59(bytes.ptr[4U]) & 1) << 10U) |
      (int16_t)((uint32_t)libcrux_secrets_int_as_i16_59(bytes.ptr[3U]) << 2U))
    | libcrux_secrets_int_as_i16_59(bytes.ptr[2U]) >> 6U;
  int16_t
  r3 =
    (int16_t)((uint32_t)(libcrux_secrets_int_as_i16_59(bytes.ptr[5U]) & 15) << 7U) |
      libcrux_secrets_int_as_i16_59(bytes.ptr[4U]) >> 1U;
  int16_t
  r4 =
    (int16_t)((uint32_t)(libcrux_secrets_int_as_i16_59(bytes.ptr[6U]) & 127) << 4U) |
      libcrux_secrets_int_as_i16_59(bytes.ptr[5U]) >> 4U;
  int16_t
  r5 =
    ((int16_t)((uint32_t)(libcrux_secrets_int_as_i16_59(bytes.ptr[8U]) & 3) << 9U) |
      (int16_t)((uint32_t)libcrux_secrets_int_as_i16_59(bytes.ptr[7U]) << 1U))
    | libcrux_secrets_int_as_i16_59(bytes.ptr[6U]) >> 7U;
  int16_t
  r6 =
    (int16_t)((uint32_t)(libcrux_secrets_int_as_i16_59(bytes.ptr[9U]) & 31) << 6U) |
      libcrux_secrets_int_as_i16_59(bytes.ptr[8U]) >> 2U;
  int16_t
  r7 =
    (int16_t)((uint32_t)libcrux_secrets_int_as_i16_59(bytes.ptr[10U]) << 3U) |
      libcrux_secrets_int_as_i16_59(bytes.ptr[9U]) >> 5U;
  return
    (
      KRML_CLITERAL(int16_t_x8){
        .fst = r0,
        .snd = r1,
        .thd = r2,
        .f3 = r3,
        .f4 = r4,
        .f5 = r5,
        .f6 = r6,
        .f7 = r7
      }
    );
}

KRML_MUSTINLINE Eurydice_arr_d6
libcrux_ml_kem_vector_portable_serialize_deserialize_11(Eurydice_borrow_slice_u8 bytes)
{
  int16_t_x8
  v0_7 =
    libcrux_ml_kem_vector_portable_serialize_deserialize_11_int(Eurydice_slice_subslice_shared_c8(bytes,
        (KRML_CLITERAL(core_ops_range_Range_87){ .start = (size_t)0U, .end = (size_t)11U })));
  int16_t_x8
  v8_15 =
    libcrux_ml_kem_vector_portable_serialize_deserialize_11_int(Eurydice_slice_subslice_shared_c8(bytes,
        (KRML_CLITERAL(core_ops_range_Range_87){ .start = (size_t)11U, .end = (size_t)22U })));
  return
    (
      KRML_CLITERAL(Eurydice_arr_d6){
        .data = {
          v0_7.fst, v0_7.snd, v0_7.thd, v0_7.f3, v0_7.f4, v0_7.f5, v0_7.f6, v0_7.f7, v8_15.fst,
          v8_15.snd, v8_15.thd, v8_15.f3, v8_15.f4, v8_15.f5, v8_15.f6, v8_15.f7
        }
      }
    );
}

Eurydice_arr_d6 libcrux_ml_kem_vector_portable_deserialize_11(Eurydice_borrow_slice_u8 a)
{
  return
    libcrux_ml_kem_vector_portable_serialize_deserialize_11(libcrux_secrets_int_classify_public_classify_ref_6d_90(a));
}

/**
This function found in impl {libcrux_ml_kem::vector::traits::Operations for libcrux_ml_kem::vector::portable::vector_type::PortableVector}
*/
Eurydice_arr_d6 libcrux_ml_kem_vector_portable_deserialize_11_b8(Eurydice_borrow_slice_u8 a)
{
  return libcrux_ml_kem_vector_portable_deserialize_11(a);
}

KRML_MUSTINLINE Eurydice_arr_d6
libcrux_ml_kem_vector_portable_vector_type_to_i16_array(Eurydice_arr_d6 x)
{
  return x;
}

/**
This function found in impl {libcrux_ml_kem::vector::traits::Operations for libcrux_ml_kem::vector::portable::vector_type::PortableVector}
*/
Eurydice_arr_d6 libcrux_ml_kem_vector_portable_to_i16_array_b8(Eurydice_arr_d6 x)
{
  return
    libcrux_secrets_int_classify_public_declassify_91_8a(libcrux_ml_kem_vector_portable_vector_type_to_i16_array(x));
}

KRML_MUSTINLINE Eurydice_arr_d6 libcrux_ml_kem_vector_portable_vector_type_zero(void)
{
  return
    libcrux_secrets_int_classify_public_classify_fa_8a((
        KRML_CLITERAL(Eurydice_arr_d6){ .data = { 0U } }
      ));
}

/**
This function found in impl {libcrux_ml_kem::vector::traits::Operations for libcrux_ml_kem::vector::portable::vector_type::PortableVector}
*/
Eurydice_arr_d6 libcrux_ml_kem_vector_portable_ZERO_b8(void)
{
  return libcrux_ml_kem_vector_portable_vector_type_zero();
}

KRML_MUSTINLINE Eurydice_arr_d6
libcrux_ml_kem_vector_portable_vector_type_from_bytes(Eurydice_borrow_slice_u8 array)
{
  Eurydice_arr_d6 elements;
  int16_t repeat_expression[16U];
  KRML_MAYBE_FOR16(i,
    (size_t)0U,
    (size_t)16U,
    (size_t)1U,
    repeat_expression[i] = libcrux_secrets_int_I16(0););
  memcpy(elements.data, repeat_expression, (size_t)16U * sizeof (int16_t));
  for (size_t i = (size_t)0U; i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++)
  {
    size_t i0 = i;
    elements.data[i0] =
      (int16_t)((uint32_t)libcrux_secrets_int_as_i16_59(array.ptr[(size_t)2U * i0 + (size_t)1U]) <<
        8U)
      | libcrux_secrets_int_as_i16_59(array.ptr[(size_t)2U * i0]);
  }
  return elements;
}

/**
This function found in impl {libcrux_ml_kem::vector::traits::Operations for libcrux_ml_kem::vector::portable::vector_type::PortableVector}
*/
Eurydice_arr_d6 libcrux_ml_kem_vector_portable_from_bytes_b8(Eurydice_borrow_slice_u8 array)
{
  return
    libcrux_ml_kem_vector_portable_vector_type_from_bytes(libcrux_secrets_int_classify_public_classify_ref_6d_90(array));
}

KRML_MUSTINLINE void
libcrux_ml_kem_vector_portable_vector_type_to_bytes(
  Eurydice_arr_d6 x,
  Eurydice_mut_borrow_slice_u8 bytes
)
{
  for (size_t i = (size_t)0U; i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++)
  {
    size_t i0 = i;
    bytes.ptr[(size_t)2U * i0 + (size_t)1U] = libcrux_secrets_int_as_u8_f5(x.data[i0] >> 8U);
    bytes.ptr[(size_t)2U * i0] = libcrux_secrets_int_as_u8_f5(x.data[i0]);
  }
}

/**
This function found in impl {libcrux_ml_kem::vector::traits::Operations for libcrux_ml_kem::vector::portable::vector_type::PortableVector}
*/
void
libcrux_ml_kem_vector_portable_to_bytes_b8(
  Eurydice_arr_d6 x,
  Eurydice_mut_borrow_slice_u8 bytes
)
{
  libcrux_ml_kem_vector_portable_vector_type_to_bytes(x,
    libcrux_secrets_int_classify_public_classify_mut_slice_75(bytes));
}

KRML_MUSTINLINE Eurydice_arr_d6
libcrux_ml_kem_vector_portable_arithmetic_add(Eurydice_arr_d6 lhs, const Eurydice_arr_d6 *rhs)
{
  for (size_t i = (size_t)0U; i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++)
  {
    size_t i0 = i;
    size_t uu____0 = i0;
    lhs.data[uu____0] += rhs->data[i0];
  }
  return lhs;
}

/**
This function found in impl {libcrux_ml_kem::vector::traits::Operations for libcrux_ml_kem::vector::portable::vector_type::PortableVector}
*/
Eurydice_arr_d6
libcrux_ml_kem_vector_portable_add_b8(Eurydice_arr_d6 lhs, const Eurydice_arr_d6 *rhs)
{
  return libcrux_ml_kem_vector_portable_arithmetic_add(lhs, rhs);
}

KRML_MUSTINLINE Eurydice_arr_d6
libcrux_ml_kem_vector_portable_arithmetic_sub(Eurydice_arr_d6 lhs, const Eurydice_arr_d6 *rhs)
{
  for (size_t i = (size_t)0U; i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++)
  {
    size_t i0 = i;
    size_t uu____0 = i0;
    lhs.data[uu____0] -= rhs->data[i0];
  }
  return lhs;
}

/**
This function found in impl {libcrux_ml_kem::vector::traits::Operations for libcrux_ml_kem::vector::portable::vector_type::PortableVector}
*/
Eurydice_arr_d6
libcrux_ml_kem_vector_portable_sub_b8(Eurydice_arr_d6 lhs, const Eurydice_arr_d6 *rhs)
{
  return libcrux_ml_kem_vector_portable_arithmetic_sub(lhs, rhs);
}

KRML_MUSTINLINE Eurydice_arr_d6
libcrux_ml_kem_vector_portable_arithmetic_multiply_by_constant(Eurydice_arr_d6 vec, int16_t c)
{
  for (size_t i = (size_t)0U; i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++)
  {
    size_t i0 = i;
    size_t uu____0 = i0;
    vec.data[uu____0] *= c;
  }
  return vec;
}

/**
This function found in impl {libcrux_ml_kem::vector::traits::Operations for libcrux_ml_kem::vector::portable::vector_type::PortableVector}
*/
Eurydice_arr_d6
libcrux_ml_kem_vector_portable_multiply_by_constant_b8(Eurydice_arr_d6 vec, int16_t c)
{
  return libcrux_ml_kem_vector_portable_arithmetic_multiply_by_constant(vec, c);
}

/**
 Note: This function is not secret independent
 Only use with public values.
*/
KRML_MUSTINLINE Eurydice_arr_d6
libcrux_ml_kem_vector_portable_arithmetic_cond_subtract_3329(Eurydice_arr_d6 vec)
{
  for (size_t i = (size_t)0U; i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++)
  {
    size_t i0 = i;
    if (libcrux_secrets_int_classify_public_declassify_d8_39(vec.data[i0]) >= 3329)
    {
      size_t uu____0 = i0;
      vec.data[uu____0] -= 3329;
    }
  }
  return vec;
}

/**
This function found in impl {libcrux_ml_kem::vector::traits::Operations for libcrux_ml_kem::vector::portable::vector_type::PortableVector}
*/
Eurydice_arr_d6 libcrux_ml_kem_vector_portable_cond_subtract_3329_b8(Eurydice_arr_d6 v)
{
  return libcrux_ml_kem_vector_portable_arithmetic_cond_subtract_3329(v);
}

/**
 Signed Barrett Reduction

 Given an input `value`, `barrett_reduce` outputs a representative `result`
 such that:

 - result ≡ value (mod FIELD_MODULUS)
 - the absolute value of `result` is bound as follows:

 `|result| ≤ FIELD_MODULUS / 2 · (|value|/BARRETT_R + 1)

 Note: The input bound is 28296 to prevent overflow in the multiplication of quotient by FIELD_MODULUS

*/
int16_t libcrux_ml_kem_vector_portable_arithmetic_barrett_reduce_element(int16_t value)
{
  int32_t
  t =
    libcrux_secrets_int_as_i32_f5(value) *
      LIBCRUX_ML_KEM_VECTOR_PORTABLE_ARITHMETIC_BARRETT_MULTIPLIER
    + (LIBCRUX_ML_KEM_VECTOR_TRAITS_BARRETT_R >> 1U);
  int16_t
  quotient =
    libcrux_secrets_int_as_i16_36(t >> (uint32_t)LIBCRUX_ML_KEM_VECTOR_TRAITS_BARRETT_SHIFT);
  return value - quotient * LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS;
}

KRML_MUSTINLINE Eurydice_arr_d6
libcrux_ml_kem_vector_portable_arithmetic_barrett_reduce(Eurydice_arr_d6 vec)
{
  for (size_t i = (size_t)0U; i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++)
  {
    size_t i0 = i;
    int16_t vi = libcrux_ml_kem_vector_portable_arithmetic_barrett_reduce_element(vec.data[i0]);
    vec.data[i0] = vi;
  }
  return vec;
}

/**
This function found in impl {libcrux_ml_kem::vector::traits::Operations for libcrux_ml_kem::vector::portable::vector_type::PortableVector}
*/
Eurydice_arr_d6 libcrux_ml_kem_vector_portable_barrett_reduce_b8(Eurydice_arr_d6 vector)
{
  return libcrux_ml_kem_vector_portable_arithmetic_barrett_reduce(vector);
}

/**
 Signed Montgomery Reduction

 Given an input `value`, `montgomery_reduce` outputs a representative `o`
 such that:

 - o ≡ value · MONTGOMERY_R^(-1) (mod FIELD_MODULUS)
 - the absolute value of `o` is bound as follows:

 `|result| ≤ ceil(|value| / MONTGOMERY_R) + 1665

 In particular, if `|value| ≤ FIELD_MODULUS-1 * FIELD_MODULUS-1`, then `|o| <= FIELD_MODULUS-1`.
 And, if `|value| ≤ pow2 16 * FIELD_MODULUS-1`, then `|o| <= FIELD_MODULUS + 1664

*/
int16_t libcrux_ml_kem_vector_portable_arithmetic_montgomery_reduce_element(int32_t value)
{
  int32_t
  k =
    libcrux_secrets_int_as_i32_f5(libcrux_secrets_int_as_i16_36(value)) *
      libcrux_secrets_int_as_i32_b8(libcrux_secrets_int_classify_public_classify_27_df(LIBCRUX_ML_KEM_VECTOR_TRAITS_INVERSE_OF_MODULUS_MOD_MONTGOMERY_R));
  int32_t
  k_times_modulus =
    libcrux_secrets_int_as_i32_f5(libcrux_secrets_int_as_i16_36(k)) *
      libcrux_secrets_int_as_i32_f5(libcrux_secrets_int_classify_public_classify_27_39(LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS));
  int16_t
  c =
    libcrux_secrets_int_as_i16_36(k_times_modulus >>
        (uint32_t)LIBCRUX_ML_KEM_VECTOR_PORTABLE_ARITHMETIC_MONTGOMERY_SHIFT);
  int16_t
  value_high =
    libcrux_secrets_int_as_i16_36(value >>
        (uint32_t)LIBCRUX_ML_KEM_VECTOR_PORTABLE_ARITHMETIC_MONTGOMERY_SHIFT);
  return value_high - c;
}

/**
 If `fe` is some field element 'x' of the Kyber field and `fer` is congruent to
 `y · MONTGOMERY_R`, this procedure outputs a value that is congruent to
 `x · y`, as follows:

    `fe · fer ≡ x · y · MONTGOMERY_R (mod FIELD_MODULUS)`

 `montgomery_reduce` takes the value `x · y · MONTGOMERY_R` and outputs a representative
 `x · y · MONTGOMERY_R * MONTGOMERY_R^{-1} ≡ x · y (mod FIELD_MODULUS)`.
*/
KRML_MUSTINLINE int16_t
libcrux_ml_kem_vector_portable_arithmetic_montgomery_multiply_fe_by_fer(
  int16_t fe,
  int16_t fer
)
{
  int32_t product = libcrux_secrets_int_as_i32_f5(fe) * libcrux_secrets_int_as_i32_f5(fer);
  return libcrux_ml_kem_vector_portable_arithmetic_montgomery_reduce_element(product);
}

KRML_MUSTINLINE Eurydice_arr_d6
libcrux_ml_kem_vector_portable_arithmetic_montgomery_multiply_by_constant(
  Eurydice_arr_d6 vec,
  int16_t c
)
{
  for (size_t i = (size_t)0U; i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++)
  {
    size_t i0 = i;
    vec.data[i0] =
      libcrux_ml_kem_vector_portable_arithmetic_montgomery_multiply_fe_by_fer(vec.data[i0],
        c);
  }
  return vec;
}

/**
This function found in impl {libcrux_ml_kem::vector::traits::Operations for libcrux_ml_kem::vector::portable::vector_type::PortableVector}
*/
Eurydice_arr_d6
libcrux_ml_kem_vector_portable_montgomery_multiply_by_constant_b8(
  Eurydice_arr_d6 vector,
  int16_t constant
)
{
  return
    libcrux_ml_kem_vector_portable_arithmetic_montgomery_multiply_by_constant(vector,
      libcrux_secrets_int_classify_public_classify_27_39(constant));
}

KRML_MUSTINLINE Eurydice_arr_d6
libcrux_ml_kem_vector_portable_arithmetic_bitwise_and_with_constant(
  Eurydice_arr_d6 vec,
  int16_t c
)
{
  for (size_t i = (size_t)0U; i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++)
  {
    size_t i0 = i;
    size_t uu____0 = i0;
    vec.data[uu____0] &= c;
  }
  return vec;
}

/**
A monomorphic instance of libcrux_ml_kem.vector.portable.arithmetic.shift_right
with const generics
- SHIFT_BY= 15
*/
static KRML_MUSTINLINE Eurydice_arr_d6 shift_right_ef(Eurydice_arr_d6 vec)
{
  for (size_t i = (size_t)0U; i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++)
  {
    size_t i0 = i;
    vec.data[i0] >>= (uint32_t)15;
  }
  return vec;
}

KRML_MUSTINLINE Eurydice_arr_d6
libcrux_ml_kem_vector_portable_arithmetic_to_unsigned_representative(Eurydice_arr_d6 a)
{
  Eurydice_arr_d6 t = shift_right_ef(a);
  Eurydice_arr_d6
  fm =
    libcrux_ml_kem_vector_portable_arithmetic_bitwise_and_with_constant(t,
      LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS);
  return libcrux_ml_kem_vector_portable_arithmetic_add(a, &fm);
}

/**
This function found in impl {libcrux_ml_kem::vector::traits::Operations for libcrux_ml_kem::vector::portable::vector_type::PortableVector}
*/
Eurydice_arr_d6 libcrux_ml_kem_vector_portable_to_unsigned_representative_b8(Eurydice_arr_d6 a)
{
  return libcrux_ml_kem_vector_portable_arithmetic_to_unsigned_representative(a);
}

/**
 The `compress_*` functions implement the `Compress` function specified in the NIST FIPS
 203 standard (Page 18, Expression 4.5), which is defined as:

 ```plaintext
 Compress_d: ℤq -> ℤ_{2ᵈ}
 Compress_d(x) = ⌈(2ᵈ/q)·x⌋
 ```

 Since `⌈x⌋ = ⌊x + 1/2⌋` we have:

 ```plaintext
 Compress_d(x) = ⌊(2ᵈ/q)·x + 1/2⌋
               = ⌊(2^{d+1}·x + q) / 2q⌋
 ```

 For further information about the function implementations, consult the
 `implementation_notes.pdf` document in this directory.

 The NIST FIPS 203 standard can be found at
 <https://csrc.nist.gov/pubs/fips/203/ipd>.
*/
uint8_t libcrux_ml_kem_vector_portable_compress_compress_message_coefficient(uint16_t fe)
{
  int16_t
  shifted =
    libcrux_secrets_int_classify_public_classify_27_39(1664) - libcrux_secrets_int_as_i16_ca(fe);
  int16_t mask = shifted >> 15U;
  int16_t shifted_to_positive = mask ^ shifted;
  int16_t shifted_positive_in_range = shifted_to_positive - 832;
  int16_t r0 = shifted_positive_in_range >> 15U;
  int16_t r1 = r0 & 1;
  return libcrux_secrets_int_as_u8_f5(r1);
}

KRML_MUSTINLINE Eurydice_arr_d6
libcrux_ml_kem_vector_portable_compress_compress_1(Eurydice_arr_d6 a)
{
  for (size_t i = (size_t)0U; i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++)
  {
    size_t i0 = i;
    a.data[i0] =
      libcrux_secrets_int_as_i16_59(libcrux_ml_kem_vector_portable_compress_compress_message_coefficient(libcrux_secrets_int_as_u16_f5(a.data[i0])));
  }
  return a;
}

/**
This function found in impl {libcrux_ml_kem::vector::traits::Operations for libcrux_ml_kem::vector::portable::vector_type::PortableVector}
*/
Eurydice_arr_d6 libcrux_ml_kem_vector_portable_compress_1_b8(Eurydice_arr_d6 a)
{
  return libcrux_ml_kem_vector_portable_compress_compress_1(a);
}

KRML_MUSTINLINE uint32_t
libcrux_ml_kem_vector_portable_arithmetic_get_n_least_significant_bits(
  uint8_t n,
  uint32_t value
)
{
  return value & ((1U << (uint32_t)n) - 1U);
}

int16_t
libcrux_ml_kem_vector_portable_compress_compress_ciphertext_coefficient(
  uint8_t coefficient_bits,
  uint16_t fe
)
{
  uint64_t compressed = libcrux_secrets_int_as_u64_ca(fe) << (uint32_t)coefficient_bits;
  compressed += 1664ULL;
  compressed *= 10321340ULL;
  compressed >>= 35U;
  return
    libcrux_secrets_int_as_i16_b8(libcrux_ml_kem_vector_portable_arithmetic_get_n_least_significant_bits(coefficient_bits,
        libcrux_secrets_int_as_u32_a3(compressed)));
}

KRML_MUSTINLINE Eurydice_arr_d6
libcrux_ml_kem_vector_portable_compress_decompress_1(Eurydice_arr_d6 a)
{
  Eurydice_arr_d6 z = libcrux_ml_kem_vector_portable_vector_type_zero();
  Eurydice_arr_d6 s = libcrux_ml_kem_vector_portable_arithmetic_sub(z, &a);
  Eurydice_arr_d6
  res = libcrux_ml_kem_vector_portable_arithmetic_bitwise_and_with_constant(s, 1665);
  return res;
}

/**
This function found in impl {libcrux_ml_kem::vector::traits::Operations for libcrux_ml_kem::vector::portable::vector_type::PortableVector}
*/
Eurydice_arr_d6 libcrux_ml_kem_vector_portable_decompress_1_b8(Eurydice_arr_d6 a)
{
  return libcrux_ml_kem_vector_portable_compress_decompress_1(a);
}

KRML_MUSTINLINE void
libcrux_ml_kem_vector_portable_ntt_ntt_step(
  Eurydice_arr_d6 *vec,
  int16_t zeta,
  size_t i,
  size_t j
)
{
  int16_t
  t =
    libcrux_ml_kem_vector_portable_arithmetic_montgomery_multiply_fe_by_fer(vec->data[j],
      libcrux_secrets_int_classify_public_classify_27_39(zeta));
  int16_t a_minus_t = vec->data[i] - t;
  int16_t a_plus_t = vec->data[i] + t;
  vec->data[j] = a_minus_t;
  vec->data[i] = a_plus_t;
}

KRML_MUSTINLINE Eurydice_arr_d6
libcrux_ml_kem_vector_portable_ntt_ntt_layer_1_step(
  Eurydice_arr_d6 vec,
  int16_t zeta0,
  int16_t zeta1,
  int16_t zeta2,
  int16_t zeta3
)
{
  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta0, (size_t)0U, (size_t)2U);
  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta0, (size_t)1U, (size_t)3U);
  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta1, (size_t)4U, (size_t)6U);
  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta1, (size_t)5U, (size_t)7U);
  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta2, (size_t)8U, (size_t)10U);
  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta2, (size_t)9U, (size_t)11U);
  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta3, (size_t)12U, (size_t)14U);
  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta3, (size_t)13U, (size_t)15U);
  return vec;
}

/**
This function found in impl {libcrux_ml_kem::vector::traits::Operations for libcrux_ml_kem::vector::portable::vector_type::PortableVector}
*/
Eurydice_arr_d6
libcrux_ml_kem_vector_portable_ntt_layer_1_step_b8(
  Eurydice_arr_d6 a,
  int16_t zeta0,
  int16_t zeta1,
  int16_t zeta2,
  int16_t zeta3
)
{
  return libcrux_ml_kem_vector_portable_ntt_ntt_layer_1_step(a, zeta0, zeta1, zeta2, zeta3);
}

KRML_MUSTINLINE Eurydice_arr_d6
libcrux_ml_kem_vector_portable_ntt_ntt_layer_2_step(
  Eurydice_arr_d6 vec,
  int16_t zeta0,
  int16_t zeta1
)
{
  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta0, (size_t)0U, (size_t)4U);
  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta0, (size_t)1U, (size_t)5U);
  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta0, (size_t)2U, (size_t)6U);
  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta0, (size_t)3U, (size_t)7U);
  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta1, (size_t)8U, (size_t)12U);
  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta1, (size_t)9U, (size_t)13U);
  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta1, (size_t)10U, (size_t)14U);
  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta1, (size_t)11U, (size_t)15U);
  return vec;
}

/**
This function found in impl {libcrux_ml_kem::vector::traits::Operations for libcrux_ml_kem::vector::portable::vector_type::PortableVector}
*/
Eurydice_arr_d6
libcrux_ml_kem_vector_portable_ntt_layer_2_step_b8(
  Eurydice_arr_d6 a,
  int16_t zeta0,
  int16_t zeta1
)
{
  return libcrux_ml_kem_vector_portable_ntt_ntt_layer_2_step(a, zeta0, zeta1);
}

KRML_MUSTINLINE Eurydice_arr_d6
libcrux_ml_kem_vector_portable_ntt_ntt_layer_3_step(Eurydice_arr_d6 vec, int16_t zeta)
{
  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta, (size_t)0U, (size_t)8U);
  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta, (size_t)1U, (size_t)9U);
  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta, (size_t)2U, (size_t)10U);
  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta, (size_t)3U, (size_t)11U);
  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta, (size_t)4U, (size_t)12U);
  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta, (size_t)5U, (size_t)13U);
  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta, (size_t)6U, (size_t)14U);
  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta, (size_t)7U, (size_t)15U);
  return vec;
}

/**
This function found in impl {libcrux_ml_kem::vector::traits::Operations for libcrux_ml_kem::vector::portable::vector_type::PortableVector}
*/
Eurydice_arr_d6
libcrux_ml_kem_vector_portable_ntt_layer_3_step_b8(Eurydice_arr_d6 a, int16_t zeta)
{
  return libcrux_ml_kem_vector_portable_ntt_ntt_layer_3_step(a, zeta);
}

KRML_MUSTINLINE void
libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(
  Eurydice_arr_d6 *vec,
  int16_t zeta,
  size_t i,
  size_t j
)
{
  int16_t a_minus_b = vec->data[j] - vec->data[i];
  int16_t a_plus_b = vec->data[j] + vec->data[i];
  int16_t o0 = libcrux_ml_kem_vector_portable_arithmetic_barrett_reduce_element(a_plus_b);
  int16_t
  o1 =
    libcrux_ml_kem_vector_portable_arithmetic_montgomery_multiply_fe_by_fer(a_minus_b,
      libcrux_secrets_int_classify_public_classify_27_39(zeta));
  vec->data[i] = o0;
  vec->data[j] = o1;
}

KRML_MUSTINLINE Eurydice_arr_d6
libcrux_ml_kem_vector_portable_ntt_inv_ntt_layer_1_step(
  Eurydice_arr_d6 vec,
  int16_t zeta0,
  int16_t zeta1,
  int16_t zeta2,
  int16_t zeta3
)
{
  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta0, (size_t)0U, (size_t)2U);
  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta0, (size_t)1U, (size_t)3U);
  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta1, (size_t)4U, (size_t)6U);
  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta1, (size_t)5U, (size_t)7U);
  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta2, (size_t)8U, (size_t)10U);
  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta2, (size_t)9U, (size_t)11U);
  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta3, (size_t)12U, (size_t)14U);
  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta3, (size_t)13U, (size_t)15U);
  return vec;
}

/**
This function found in impl {libcrux_ml_kem::vector::traits::Operations for libcrux_ml_kem::vector::portable::vector_type::PortableVector}
*/
Eurydice_arr_d6
libcrux_ml_kem_vector_portable_inv_ntt_layer_1_step_b8(
  Eurydice_arr_d6 a,
  int16_t zeta0,
  int16_t zeta1,
  int16_t zeta2,
  int16_t zeta3
)
{
  return libcrux_ml_kem_vector_portable_ntt_inv_ntt_layer_1_step(a, zeta0, zeta1, zeta2, zeta3);
}

KRML_MUSTINLINE Eurydice_arr_d6
libcrux_ml_kem_vector_portable_ntt_inv_ntt_layer_2_step(
  Eurydice_arr_d6 vec,
  int16_t zeta0,
  int16_t zeta1
)
{
  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta0, (size_t)0U, (size_t)4U);
  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta0, (size_t)1U, (size_t)5U);
  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta0, (size_t)2U, (size_t)6U);
  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta0, (size_t)3U, (size_t)7U);
  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta1, (size_t)8U, (size_t)12U);
  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta1, (size_t)9U, (size_t)13U);
  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta1, (size_t)10U, (size_t)14U);
  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta1, (size_t)11U, (size_t)15U);
  return vec;
}

/**
This function found in impl {libcrux_ml_kem::vector::traits::Operations for libcrux_ml_kem::vector::portable::vector_type::PortableVector}
*/
Eurydice_arr_d6
libcrux_ml_kem_vector_portable_inv_ntt_layer_2_step_b8(
  Eurydice_arr_d6 a,
  int16_t zeta0,
  int16_t zeta1
)
{
  return libcrux_ml_kem_vector_portable_ntt_inv_ntt_layer_2_step(a, zeta0, zeta1);
}

KRML_MUSTINLINE Eurydice_arr_d6
libcrux_ml_kem_vector_portable_ntt_inv_ntt_layer_3_step(Eurydice_arr_d6 vec, int16_t zeta)
{
  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta, (size_t)0U, (size_t)8U);
  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta, (size_t)1U, (size_t)9U);
  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta, (size_t)2U, (size_t)10U);
  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta, (size_t)3U, (size_t)11U);
  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta, (size_t)4U, (size_t)12U);
  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta, (size_t)5U, (size_t)13U);
  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta, (size_t)6U, (size_t)14U);
  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta, (size_t)7U, (size_t)15U);
  return vec;
}

/**
This function found in impl {libcrux_ml_kem::vector::traits::Operations for libcrux_ml_kem::vector::portable::vector_type::PortableVector}
*/
Eurydice_arr_d6
libcrux_ml_kem_vector_portable_inv_ntt_layer_3_step_b8(Eurydice_arr_d6 a, int16_t zeta)
{
  return libcrux_ml_kem_vector_portable_ntt_inv_ntt_layer_3_step(a, zeta);
}

/**
 Compute the product of two Kyber binomials with respect to the
 modulus `X² - zeta`.

 This function almost implements <strong>Algorithm 11</strong> of the
 NIST FIPS 203 standard, which is reproduced below:

 ```plaintext
 Input:  a₀, a₁, b₀, b₁ ∈ ℤq.
 Input: γ ∈ ℤq.
 Output: c₀, c₁ ∈ ℤq.

 c₀ ← a₀·b₀ + a₁·b₁·γ
 c₁ ← a₀·b₁ + a₁·b₀
 return c₀, c₁
 ```
 We say "almost" because the coefficients output by this function are in
 the Montgomery domain (unlike in the specification).

 The NIST FIPS 203 standard can be found at
 <https://csrc.nist.gov/pubs/fips/203/ipd>.
*/
KRML_MUSTINLINE void
libcrux_ml_kem_vector_portable_ntt_ntt_multiply_binomials(
  const Eurydice_arr_d6 *a,
  const Eurydice_arr_d6 *b,
  int16_t zeta,
  size_t i,
  Eurydice_arr_d6 *out
)
{
  int16_t ai = a->data[(size_t)2U * i];
  int16_t bi = b->data[(size_t)2U * i];
  int16_t aj = a->data[(size_t)2U * i + (size_t)1U];
  int16_t bj = b->data[(size_t)2U * i + (size_t)1U];
  int32_t ai_bi = libcrux_secrets_int_as_i32_f5(ai) * libcrux_secrets_int_as_i32_f5(bi);
  int32_t aj_bj_ = libcrux_secrets_int_as_i32_f5(aj) * libcrux_secrets_int_as_i32_f5(bj);
  int16_t aj_bj = libcrux_ml_kem_vector_portable_arithmetic_montgomery_reduce_element(aj_bj_);
  int32_t
  aj_bj_zeta = libcrux_secrets_int_as_i32_f5(aj_bj) * libcrux_secrets_int_as_i32_f5(zeta);
  int32_t ai_bi_aj_bj = ai_bi + aj_bj_zeta;
  int16_t o0 = libcrux_ml_kem_vector_portable_arithmetic_montgomery_reduce_element(ai_bi_aj_bj);
  int32_t ai_bj = libcrux_secrets_int_as_i32_f5(ai) * libcrux_secrets_int_as_i32_f5(bj);
  int32_t aj_bi = libcrux_secrets_int_as_i32_f5(aj) * libcrux_secrets_int_as_i32_f5(bi);
  int32_t ai_bj_aj_bi = ai_bj + aj_bi;
  int16_t o1 = libcrux_ml_kem_vector_portable_arithmetic_montgomery_reduce_element(ai_bj_aj_bi);
  out->data[(size_t)2U * i] = o0;
  out->data[(size_t)2U * i + (size_t)1U] = o1;
}

KRML_MUSTINLINE Eurydice_arr_d6
libcrux_ml_kem_vector_portable_ntt_ntt_multiply(
  const Eurydice_arr_d6 *lhs,
  const Eurydice_arr_d6 *rhs,
  int16_t zeta0,
  int16_t zeta1,
  int16_t zeta2,
  int16_t zeta3
)
{
  int16_t nzeta0 = -zeta0;
  int16_t nzeta1 = -zeta1;
  int16_t nzeta2 = -zeta2;
  int16_t nzeta3 = -zeta3;
  Eurydice_arr_d6 out = libcrux_ml_kem_vector_portable_vector_type_zero();
  libcrux_ml_kem_vector_portable_ntt_ntt_multiply_binomials(lhs,
    rhs,
    libcrux_secrets_int_classify_public_classify_27_39(zeta0),
    (size_t)0U,
    &out);
  libcrux_ml_kem_vector_portable_ntt_ntt_multiply_binomials(lhs,
    rhs,
    libcrux_secrets_int_classify_public_classify_27_39(nzeta0),
    (size_t)1U,
    &out);
  libcrux_ml_kem_vector_portable_ntt_ntt_multiply_binomials(lhs,
    rhs,
    libcrux_secrets_int_classify_public_classify_27_39(zeta1),
    (size_t)2U,
    &out);
  libcrux_ml_kem_vector_portable_ntt_ntt_multiply_binomials(lhs,
    rhs,
    libcrux_secrets_int_classify_public_classify_27_39(nzeta1),
    (size_t)3U,
    &out);
  libcrux_ml_kem_vector_portable_ntt_ntt_multiply_binomials(lhs,
    rhs,
    libcrux_secrets_int_classify_public_classify_27_39(zeta2),
    (size_t)4U,
    &out);
  libcrux_ml_kem_vector_portable_ntt_ntt_multiply_binomials(lhs,
    rhs,
    libcrux_secrets_int_classify_public_classify_27_39(nzeta2),
    (size_t)5U,
    &out);
  libcrux_ml_kem_vector_portable_ntt_ntt_multiply_binomials(lhs,
    rhs,
    libcrux_secrets_int_classify_public_classify_27_39(zeta3),
    (size_t)6U,
    &out);
  libcrux_ml_kem_vector_portable_ntt_ntt_multiply_binomials(lhs,
    rhs,
    libcrux_secrets_int_classify_public_classify_27_39(nzeta3),
    (size_t)7U,
    &out);
  return out;
}

/**
This function found in impl {libcrux_ml_kem::vector::traits::Operations for libcrux_ml_kem::vector::portable::vector_type::PortableVector}
*/
Eurydice_arr_d6
libcrux_ml_kem_vector_portable_ntt_multiply_b8(
  const Eurydice_arr_d6 *lhs,
  const Eurydice_arr_d6 *rhs,
  int16_t zeta0,
  int16_t zeta1,
  int16_t zeta2,
  int16_t zeta3
)
{
  return libcrux_ml_kem_vector_portable_ntt_ntt_multiply(lhs, rhs, zeta0, zeta1, zeta2, zeta3);
}

KRML_MUSTINLINE Eurydice_array_u8x2
libcrux_ml_kem_vector_portable_serialize_serialize_1(Eurydice_arr_d6 v)
{
  uint8_t
  result0 =
    (((((((uint32_t)libcrux_secrets_int_as_u8_f5(v.data[0U]) |
      (uint32_t)libcrux_secrets_int_as_u8_f5(v.data[1U]) << 1U)
    | (uint32_t)libcrux_secrets_int_as_u8_f5(v.data[2U]) << 2U)
    | (uint32_t)libcrux_secrets_int_as_u8_f5(v.data[3U]) << 3U)
    | (uint32_t)libcrux_secrets_int_as_u8_f5(v.data[4U]) << 4U)
    | (uint32_t)libcrux_secrets_int_as_u8_f5(v.data[5U]) << 5U)
    | (uint32_t)libcrux_secrets_int_as_u8_f5(v.data[6U]) << 6U)
    | (uint32_t)libcrux_secrets_int_as_u8_f5(v.data[7U]) << 7U;
  uint8_t
  result1 =
    (((((((uint32_t)libcrux_secrets_int_as_u8_f5(v.data[8U]) |
      (uint32_t)libcrux_secrets_int_as_u8_f5(v.data[9U]) << 1U)
    | (uint32_t)libcrux_secrets_int_as_u8_f5(v.data[10U]) << 2U)
    | (uint32_t)libcrux_secrets_int_as_u8_f5(v.data[11U]) << 3U)
    | (uint32_t)libcrux_secrets_int_as_u8_f5(v.data[12U]) << 4U)
    | (uint32_t)libcrux_secrets_int_as_u8_f5(v.data[13U]) << 5U)
    | (uint32_t)libcrux_secrets_int_as_u8_f5(v.data[14U]) << 6U)
    | (uint32_t)libcrux_secrets_int_as_u8_f5(v.data[15U]) << 7U;
  return (KRML_CLITERAL(Eurydice_array_u8x2){ .data = { result0, result1 } });
}

Eurydice_array_u8x2 libcrux_ml_kem_vector_portable_serialize_1(Eurydice_arr_d6 a)
{
  return
    libcrux_secrets_int_classify_public_declassify_91_82(libcrux_ml_kem_vector_portable_serialize_serialize_1(a));
}

/**
This function found in impl {libcrux_ml_kem::vector::traits::Operations for libcrux_ml_kem::vector::portable::vector_type::PortableVector}
*/
Eurydice_array_u8x2 libcrux_ml_kem_vector_portable_serialize_1_b8(Eurydice_arr_d6 a)
{
  return libcrux_ml_kem_vector_portable_serialize_1(a);
}

KRML_MUSTINLINE Eurydice_arr_d6
libcrux_ml_kem_vector_portable_serialize_deserialize_1(Eurydice_borrow_slice_u8 v)
{
  int16_t result0 = libcrux_secrets_int_as_i16_59((uint32_t)v.ptr[0U] & 1U);
  int16_t result1 = libcrux_secrets_int_as_i16_59((uint32_t)v.ptr[0U] >> 1U & 1U);
  int16_t result2 = libcrux_secrets_int_as_i16_59((uint32_t)v.ptr[0U] >> 2U & 1U);
  int16_t result3 = libcrux_secrets_int_as_i16_59((uint32_t)v.ptr[0U] >> 3U & 1U);
  int16_t result4 = libcrux_secrets_int_as_i16_59((uint32_t)v.ptr[0U] >> 4U & 1U);
  int16_t result5 = libcrux_secrets_int_as_i16_59((uint32_t)v.ptr[0U] >> 5U & 1U);
  int16_t result6 = libcrux_secrets_int_as_i16_59((uint32_t)v.ptr[0U] >> 6U & 1U);
  int16_t result7 = libcrux_secrets_int_as_i16_59((uint32_t)v.ptr[0U] >> 7U & 1U);
  int16_t result8 = libcrux_secrets_int_as_i16_59((uint32_t)v.ptr[1U] & 1U);
  int16_t result9 = libcrux_secrets_int_as_i16_59((uint32_t)v.ptr[1U] >> 1U & 1U);
  int16_t result10 = libcrux_secrets_int_as_i16_59((uint32_t)v.ptr[1U] >> 2U & 1U);
  int16_t result11 = libcrux_secrets_int_as_i16_59((uint32_t)v.ptr[1U] >> 3U & 1U);
  int16_t result12 = libcrux_secrets_int_as_i16_59((uint32_t)v.ptr[1U] >> 4U & 1U);
  int16_t result13 = libcrux_secrets_int_as_i16_59((uint32_t)v.ptr[1U] >> 5U & 1U);
  int16_t result14 = libcrux_secrets_int_as_i16_59((uint32_t)v.ptr[1U] >> 6U & 1U);
  int16_t result15 = libcrux_secrets_int_as_i16_59((uint32_t)v.ptr[1U] >> 7U & 1U);
  return
    (
      KRML_CLITERAL(Eurydice_arr_d6){
        .data = {
          result0, result1, result2, result3, result4, result5, result6, result7, result8, result9,
          result10, result11, result12, result13, result14, result15
        }
      }
    );
}

Eurydice_arr_d6 libcrux_ml_kem_vector_portable_deserialize_1(Eurydice_borrow_slice_u8 a)
{
  return
    libcrux_ml_kem_vector_portable_serialize_deserialize_1(libcrux_secrets_int_classify_public_classify_ref_6d_90(a));
}

/**
This function found in impl {libcrux_ml_kem::vector::traits::Operations for libcrux_ml_kem::vector::portable::vector_type::PortableVector}
*/
Eurydice_arr_d6 libcrux_ml_kem_vector_portable_deserialize_1_b8(Eurydice_borrow_slice_u8 a)
{
  return libcrux_ml_kem_vector_portable_deserialize_1(a);
}

KRML_MUSTINLINE uint8_t_x4
libcrux_ml_kem_vector_portable_serialize_serialize_4_int(Eurydice_borrow_slice_i16 v)
{
  uint8_t
  result0 =
    (uint32_t)libcrux_secrets_int_as_u8_f5(v.ptr[1U]) << 4U |
      (uint32_t)libcrux_secrets_int_as_u8_f5(v.ptr[0U]);
  uint8_t
  result1 =
    (uint32_t)libcrux_secrets_int_as_u8_f5(v.ptr[3U]) << 4U |
      (uint32_t)libcrux_secrets_int_as_u8_f5(v.ptr[2U]);
  uint8_t
  result2 =
    (uint32_t)libcrux_secrets_int_as_u8_f5(v.ptr[5U]) << 4U |
      (uint32_t)libcrux_secrets_int_as_u8_f5(v.ptr[4U]);
  uint8_t
  result3 =
    (uint32_t)libcrux_secrets_int_as_u8_f5(v.ptr[7U]) << 4U |
      (uint32_t)libcrux_secrets_int_as_u8_f5(v.ptr[6U]);
  return
    (KRML_CLITERAL(uint8_t_x4){ .fst = result0, .snd = result1, .thd = result2, .f3 = result3 });
}

KRML_MUSTINLINE Eurydice_array_u8x8
libcrux_ml_kem_vector_portable_serialize_serialize_4(Eurydice_arr_d6 v)
{
  uint8_t_x4
  result0_3 =
    libcrux_ml_kem_vector_portable_serialize_serialize_4_int(Eurydice_array_to_subslice_shared_e7(&v,
        (KRML_CLITERAL(core_ops_range_Range_87){ .start = (size_t)0U, .end = (size_t)8U })));
  uint8_t_x4
  result4_7 =
    libcrux_ml_kem_vector_portable_serialize_serialize_4_int(Eurydice_array_to_subslice_shared_e7(&v,
        (KRML_CLITERAL(core_ops_range_Range_87){ .start = (size_t)8U, .end = (size_t)16U })));
  return
    (
      KRML_CLITERAL(Eurydice_array_u8x8){
        .data = {
          result0_3.fst, result0_3.snd, result0_3.thd, result0_3.f3, result4_7.fst, result4_7.snd,
          result4_7.thd, result4_7.f3
        }
      }
    );
}

Eurydice_array_u8x8 libcrux_ml_kem_vector_portable_serialize_4(Eurydice_arr_d6 a)
{
  return
    libcrux_secrets_int_classify_public_declassify_91_6e(libcrux_ml_kem_vector_portable_serialize_serialize_4(a));
}

/**
This function found in impl {libcrux_ml_kem::vector::traits::Operations for libcrux_ml_kem::vector::portable::vector_type::PortableVector}
*/
Eurydice_array_u8x8 libcrux_ml_kem_vector_portable_serialize_4_b8(Eurydice_arr_d6 a)
{
  return libcrux_ml_kem_vector_portable_serialize_4(a);
}

KRML_MUSTINLINE int16_t_x8
libcrux_ml_kem_vector_portable_serialize_deserialize_4_int(Eurydice_borrow_slice_u8 bytes)
{
  int16_t v0 = libcrux_secrets_int_as_i16_59((uint32_t)bytes.ptr[0U] & 15U);
  int16_t v1 = libcrux_secrets_int_as_i16_59((uint32_t)bytes.ptr[0U] >> 4U & 15U);
  int16_t v2 = libcrux_secrets_int_as_i16_59((uint32_t)bytes.ptr[1U] & 15U);
  int16_t v3 = libcrux_secrets_int_as_i16_59((uint32_t)bytes.ptr[1U] >> 4U & 15U);
  int16_t v4 = libcrux_secrets_int_as_i16_59((uint32_t)bytes.ptr[2U] & 15U);
  int16_t v5 = libcrux_secrets_int_as_i16_59((uint32_t)bytes.ptr[2U] >> 4U & 15U);
  int16_t v6 = libcrux_secrets_int_as_i16_59((uint32_t)bytes.ptr[3U] & 15U);
  int16_t v7 = libcrux_secrets_int_as_i16_59((uint32_t)bytes.ptr[3U] >> 4U & 15U);
  return
    (
      KRML_CLITERAL(int16_t_x8){
        .fst = v0,
        .snd = v1,
        .thd = v2,
        .f3 = v3,
        .f4 = v4,
        .f5 = v5,
        .f6 = v6,
        .f7 = v7
      }
    );
}

KRML_MUSTINLINE Eurydice_arr_d6
libcrux_ml_kem_vector_portable_serialize_deserialize_4(Eurydice_borrow_slice_u8 bytes)
{
  int16_t_x8
  v0_7 =
    libcrux_ml_kem_vector_portable_serialize_deserialize_4_int(Eurydice_slice_subslice_shared_c8(bytes,
        (KRML_CLITERAL(core_ops_range_Range_87){ .start = (size_t)0U, .end = (size_t)4U })));
  int16_t_x8
  v8_15 =
    libcrux_ml_kem_vector_portable_serialize_deserialize_4_int(Eurydice_slice_subslice_shared_c8(bytes,
        (KRML_CLITERAL(core_ops_range_Range_87){ .start = (size_t)4U, .end = (size_t)8U })));
  return
    (
      KRML_CLITERAL(Eurydice_arr_d6){
        .data = {
          v0_7.fst, v0_7.snd, v0_7.thd, v0_7.f3, v0_7.f4, v0_7.f5, v0_7.f6, v0_7.f7, v8_15.fst,
          v8_15.snd, v8_15.thd, v8_15.f3, v8_15.f4, v8_15.f5, v8_15.f6, v8_15.f7
        }
      }
    );
}

Eurydice_arr_d6 libcrux_ml_kem_vector_portable_deserialize_4(Eurydice_borrow_slice_u8 a)
{
  return
    libcrux_ml_kem_vector_portable_serialize_deserialize_4(libcrux_secrets_int_classify_public_classify_ref_6d_90(a));
}

/**
This function found in impl {libcrux_ml_kem::vector::traits::Operations for libcrux_ml_kem::vector::portable::vector_type::PortableVector}
*/
Eurydice_arr_d6 libcrux_ml_kem_vector_portable_deserialize_4_b8(Eurydice_borrow_slice_u8 a)
{
  return libcrux_ml_kem_vector_portable_deserialize_4(a);
}

KRML_MUSTINLINE uint8_t_x5
libcrux_ml_kem_vector_portable_serialize_serialize_5_int(Eurydice_borrow_slice_i16 v)
{
  uint8_t r0 = libcrux_secrets_int_as_u8_f5(v.ptr[0U] | (int16_t)((uint32_t)v.ptr[1U] << 5U));
  uint8_t
  r1 =
    libcrux_secrets_int_as_u8_f5((v.ptr[1U] >> 3U | (int16_t)((uint32_t)v.ptr[2U] << 2U)) |
        (int16_t)((uint32_t)v.ptr[3U] << 7U));
  uint8_t
  r2 = libcrux_secrets_int_as_u8_f5(v.ptr[3U] >> 1U | (int16_t)((uint32_t)v.ptr[4U] << 4U));
  uint8_t
  r3 =
    libcrux_secrets_int_as_u8_f5((v.ptr[4U] >> 4U | (int16_t)((uint32_t)v.ptr[5U] << 1U)) |
        (int16_t)((uint32_t)v.ptr[6U] << 6U));
  uint8_t
  r4 = libcrux_secrets_int_as_u8_f5(v.ptr[6U] >> 2U | (int16_t)((uint32_t)v.ptr[7U] << 3U));
  return (KRML_CLITERAL(uint8_t_x5){ .fst = r0, .snd = r1, .thd = r2, .f3 = r3, .f4 = r4 });
}

KRML_MUSTINLINE Eurydice_arr_6d
libcrux_ml_kem_vector_portable_serialize_serialize_5(Eurydice_arr_d6 v)
{
  uint8_t_x5
  r0_4 =
    libcrux_ml_kem_vector_portable_serialize_serialize_5_int(Eurydice_array_to_subslice_shared_e7(&v,
        (KRML_CLITERAL(core_ops_range_Range_87){ .start = (size_t)0U, .end = (size_t)8U })));
  uint8_t_x5
  r5_9 =
    libcrux_ml_kem_vector_portable_serialize_serialize_5_int(Eurydice_array_to_subslice_shared_e7(&v,
        (KRML_CLITERAL(core_ops_range_Range_87){ .start = (size_t)8U, .end = (size_t)16U })));
  return
    (
      KRML_CLITERAL(Eurydice_arr_6d){
        .data = {
          r0_4.fst, r0_4.snd, r0_4.thd, r0_4.f3, r0_4.f4, r5_9.fst, r5_9.snd, r5_9.thd, r5_9.f3,
          r5_9.f4
        }
      }
    );
}

Eurydice_arr_6d libcrux_ml_kem_vector_portable_serialize_5(Eurydice_arr_d6 a)
{
  return
    libcrux_secrets_int_classify_public_declassify_91_30(libcrux_ml_kem_vector_portable_serialize_serialize_5(a));
}

/**
This function found in impl {libcrux_ml_kem::vector::traits::Operations for libcrux_ml_kem::vector::portable::vector_type::PortableVector}
*/
Eurydice_arr_6d libcrux_ml_kem_vector_portable_serialize_5_b8(Eurydice_arr_d6 a)
{
  return libcrux_ml_kem_vector_portable_serialize_5(a);
}

KRML_MUSTINLINE int16_t_x8
libcrux_ml_kem_vector_portable_serialize_deserialize_5_int(Eurydice_borrow_slice_u8 bytes)
{
  int16_t v0 = libcrux_secrets_int_as_i16_59((uint32_t)bytes.ptr[0U] & 31U);
  int16_t
  v1 =
    libcrux_secrets_int_as_i16_59(((uint32_t)bytes.ptr[1U] & 3U) << 3U |
        (uint32_t)bytes.ptr[0U] >> 5U);
  int16_t v2 = libcrux_secrets_int_as_i16_59((uint32_t)bytes.ptr[1U] >> 2U & 31U);
  int16_t
  v3 =
    libcrux_secrets_int_as_i16_59(((uint32_t)bytes.ptr[2U] & 15U) << 1U |
        (uint32_t)bytes.ptr[1U] >> 7U);
  int16_t
  v4 =
    libcrux_secrets_int_as_i16_59(((uint32_t)bytes.ptr[3U] & 1U) << 4U |
        (uint32_t)bytes.ptr[2U] >> 4U);
  int16_t v5 = libcrux_secrets_int_as_i16_59((uint32_t)bytes.ptr[3U] >> 1U & 31U);
  int16_t
  v6 =
    libcrux_secrets_int_as_i16_59(((uint32_t)bytes.ptr[4U] & 7U) << 2U |
        (uint32_t)bytes.ptr[3U] >> 6U);
  int16_t v7 = libcrux_secrets_int_as_i16_59((uint32_t)bytes.ptr[4U] >> 3U);
  return
    (
      KRML_CLITERAL(int16_t_x8){
        .fst = v0,
        .snd = v1,
        .thd = v2,
        .f3 = v3,
        .f4 = v4,
        .f5 = v5,
        .f6 = v6,
        .f7 = v7
      }
    );
}

KRML_MUSTINLINE Eurydice_arr_d6
libcrux_ml_kem_vector_portable_serialize_deserialize_5(Eurydice_borrow_slice_u8 bytes)
{
  int16_t_x8
  v0_7 =
    libcrux_ml_kem_vector_portable_serialize_deserialize_5_int(Eurydice_slice_subslice_shared_c8(bytes,
        (KRML_CLITERAL(core_ops_range_Range_87){ .start = (size_t)0U, .end = (size_t)5U })));
  int16_t_x8
  v8_15 =
    libcrux_ml_kem_vector_portable_serialize_deserialize_5_int(Eurydice_slice_subslice_shared_c8(bytes,
        (KRML_CLITERAL(core_ops_range_Range_87){ .start = (size_t)5U, .end = (size_t)10U })));
  return
    (
      KRML_CLITERAL(Eurydice_arr_d6){
        .data = {
          v0_7.fst, v0_7.snd, v0_7.thd, v0_7.f3, v0_7.f4, v0_7.f5, v0_7.f6, v0_7.f7, v8_15.fst,
          v8_15.snd, v8_15.thd, v8_15.f3, v8_15.f4, v8_15.f5, v8_15.f6, v8_15.f7
        }
      }
    );
}

Eurydice_arr_d6 libcrux_ml_kem_vector_portable_deserialize_5(Eurydice_borrow_slice_u8 a)
{
  return
    libcrux_ml_kem_vector_portable_serialize_deserialize_5(libcrux_secrets_int_classify_public_classify_ref_6d_90(a));
}

/**
This function found in impl {libcrux_ml_kem::vector::traits::Operations for libcrux_ml_kem::vector::portable::vector_type::PortableVector}
*/
Eurydice_arr_d6 libcrux_ml_kem_vector_portable_deserialize_5_b8(Eurydice_borrow_slice_u8 a)
{
  return libcrux_ml_kem_vector_portable_deserialize_5(a);
}

KRML_MUSTINLINE uint8_t_x5
libcrux_ml_kem_vector_portable_serialize_serialize_10_int(Eurydice_borrow_slice_i16 v)
{
  uint8_t r0 = libcrux_secrets_int_as_u8_f5(v.ptr[0U] & 255);
  uint8_t
  r1 =
    (uint32_t)libcrux_secrets_int_as_u8_f5(v.ptr[1U] & 63) << 2U |
      (uint32_t)libcrux_secrets_int_as_u8_f5(v.ptr[0U] >> 8U & 3);
  uint8_t
  r2 =
    (uint32_t)libcrux_secrets_int_as_u8_f5(v.ptr[2U] & 15) << 4U |
      (uint32_t)libcrux_secrets_int_as_u8_f5(v.ptr[1U] >> 6U & 15);
  uint8_t
  r3 =
    (uint32_t)libcrux_secrets_int_as_u8_f5(v.ptr[3U] & 3) << 6U |
      (uint32_t)libcrux_secrets_int_as_u8_f5(v.ptr[2U] >> 4U & 63);
  uint8_t r4 = libcrux_secrets_int_as_u8_f5(v.ptr[3U] >> 2U & 255);
  return (KRML_CLITERAL(uint8_t_x5){ .fst = r0, .snd = r1, .thd = r2, .f3 = r3, .f4 = r4 });
}

KRML_MUSTINLINE Eurydice_arr_fc
libcrux_ml_kem_vector_portable_serialize_serialize_10(Eurydice_arr_d6 v)
{
  uint8_t_x5
  r0_4 =
    libcrux_ml_kem_vector_portable_serialize_serialize_10_int(Eurydice_array_to_subslice_shared_e7(&v,
        (KRML_CLITERAL(core_ops_range_Range_87){ .start = (size_t)0U, .end = (size_t)4U })));
  uint8_t_x5
  r5_9 =
    libcrux_ml_kem_vector_portable_serialize_serialize_10_int(Eurydice_array_to_subslice_shared_e7(&v,
        (KRML_CLITERAL(core_ops_range_Range_87){ .start = (size_t)4U, .end = (size_t)8U })));
  uint8_t_x5
  r10_14 =
    libcrux_ml_kem_vector_portable_serialize_serialize_10_int(Eurydice_array_to_subslice_shared_e7(&v,
        (KRML_CLITERAL(core_ops_range_Range_87){ .start = (size_t)8U, .end = (size_t)12U })));
  uint8_t_x5
  r15_19 =
    libcrux_ml_kem_vector_portable_serialize_serialize_10_int(Eurydice_array_to_subslice_shared_e7(&v,
        (KRML_CLITERAL(core_ops_range_Range_87){ .start = (size_t)12U, .end = (size_t)16U })));
  return
    (
      KRML_CLITERAL(Eurydice_arr_fc){
        .data = {
          r0_4.fst, r0_4.snd, r0_4.thd, r0_4.f3, r0_4.f4, r5_9.fst, r5_9.snd, r5_9.thd, r5_9.f3,
          r5_9.f4, r10_14.fst, r10_14.snd, r10_14.thd, r10_14.f3, r10_14.f4, r15_19.fst, r15_19.snd,
          r15_19.thd, r15_19.f3, r15_19.f4
        }
      }
    );
}

Eurydice_arr_fc libcrux_ml_kem_vector_portable_serialize_10(Eurydice_arr_d6 a)
{
  return
    libcrux_secrets_int_classify_public_declassify_91_8f(libcrux_ml_kem_vector_portable_serialize_serialize_10(a));
}

/**
This function found in impl {libcrux_ml_kem::vector::traits::Operations for libcrux_ml_kem::vector::portable::vector_type::PortableVector}
*/
Eurydice_arr_fc libcrux_ml_kem_vector_portable_serialize_10_b8(Eurydice_arr_d6 a)
{
  return libcrux_ml_kem_vector_portable_serialize_10(a);
}

KRML_MUSTINLINE int16_t_x8
libcrux_ml_kem_vector_portable_serialize_deserialize_10_int(Eurydice_borrow_slice_u8 bytes)
{
  int16_t
  r0 =
    libcrux_secrets_int_as_i16_f5((int16_t)((uint32_t)(libcrux_secrets_int_as_i16_59(bytes.ptr[1U])
      & 3)
      << 8U)
      | (libcrux_secrets_int_as_i16_59(bytes.ptr[0U]) & 255));
  int16_t
  r1 =
    libcrux_secrets_int_as_i16_f5((int16_t)((uint32_t)(libcrux_secrets_int_as_i16_59(bytes.ptr[2U])
      & 15)
      << 6U)
      | libcrux_secrets_int_as_i16_59(bytes.ptr[1U]) >> 2U);
  int16_t
  r2 =
    libcrux_secrets_int_as_i16_f5((int16_t)((uint32_t)(libcrux_secrets_int_as_i16_59(bytes.ptr[3U])
      & 63)
      << 4U)
      | libcrux_secrets_int_as_i16_59(bytes.ptr[2U]) >> 4U);
  int16_t
  r3 =
    libcrux_secrets_int_as_i16_f5((int16_t)((uint32_t)libcrux_secrets_int_as_i16_59(bytes.ptr[4U])
      << 2U)
      | libcrux_secrets_int_as_i16_59(bytes.ptr[3U]) >> 6U);
  int16_t
  r4 =
    libcrux_secrets_int_as_i16_f5((int16_t)((uint32_t)(libcrux_secrets_int_as_i16_59(bytes.ptr[6U])
      & 3)
      << 8U)
      | (libcrux_secrets_int_as_i16_59(bytes.ptr[5U]) & 255));
  int16_t
  r5 =
    libcrux_secrets_int_as_i16_f5((int16_t)((uint32_t)(libcrux_secrets_int_as_i16_59(bytes.ptr[7U])
      & 15)
      << 6U)
      | libcrux_secrets_int_as_i16_59(bytes.ptr[6U]) >> 2U);
  int16_t
  r6 =
    libcrux_secrets_int_as_i16_f5((int16_t)((uint32_t)(libcrux_secrets_int_as_i16_59(bytes.ptr[8U])
      & 63)
      << 4U)
      | libcrux_secrets_int_as_i16_59(bytes.ptr[7U]) >> 4U);
  int16_t
  r7 =
    libcrux_secrets_int_as_i16_f5((int16_t)((uint32_t)libcrux_secrets_int_as_i16_59(bytes.ptr[9U])
      << 2U)
      | libcrux_secrets_int_as_i16_59(bytes.ptr[8U]) >> 6U);
  return
    (
      KRML_CLITERAL(int16_t_x8){
        .fst = r0,
        .snd = r1,
        .thd = r2,
        .f3 = r3,
        .f4 = r4,
        .f5 = r5,
        .f6 = r6,
        .f7 = r7
      }
    );
}

KRML_MUSTINLINE Eurydice_arr_d6
libcrux_ml_kem_vector_portable_serialize_deserialize_10(Eurydice_borrow_slice_u8 bytes)
{
  int16_t_x8
  v0_7 =
    libcrux_ml_kem_vector_portable_serialize_deserialize_10_int(Eurydice_slice_subslice_shared_c8(bytes,
        (KRML_CLITERAL(core_ops_range_Range_87){ .start = (size_t)0U, .end = (size_t)10U })));
  int16_t_x8
  v8_15 =
    libcrux_ml_kem_vector_portable_serialize_deserialize_10_int(Eurydice_slice_subslice_shared_c8(bytes,
        (KRML_CLITERAL(core_ops_range_Range_87){ .start = (size_t)10U, .end = (size_t)20U })));
  return
    (
      KRML_CLITERAL(Eurydice_arr_d6){
        .data = {
          v0_7.fst, v0_7.snd, v0_7.thd, v0_7.f3, v0_7.f4, v0_7.f5, v0_7.f6, v0_7.f7, v8_15.fst,
          v8_15.snd, v8_15.thd, v8_15.f3, v8_15.f4, v8_15.f5, v8_15.f6, v8_15.f7
        }
      }
    );
}

Eurydice_arr_d6 libcrux_ml_kem_vector_portable_deserialize_10(Eurydice_borrow_slice_u8 a)
{
  return
    libcrux_ml_kem_vector_portable_serialize_deserialize_10(libcrux_secrets_int_classify_public_classify_ref_6d_90(a));
}

/**
This function found in impl {libcrux_ml_kem::vector::traits::Operations for libcrux_ml_kem::vector::portable::vector_type::PortableVector}
*/
Eurydice_arr_d6 libcrux_ml_kem_vector_portable_deserialize_10_b8(Eurydice_borrow_slice_u8 a)
{
  return libcrux_ml_kem_vector_portable_deserialize_10(a);
}

KRML_MUSTINLINE uint8_t_x3
libcrux_ml_kem_vector_portable_serialize_serialize_12_int(Eurydice_borrow_slice_i16 v)
{
  uint8_t r0 = libcrux_secrets_int_as_u8_f5(v.ptr[0U] & 255);
  uint8_t
  r1 =
    libcrux_secrets_int_as_u8_f5(v.ptr[0U] >> 8U | (int16_t)((uint32_t)(v.ptr[1U] & 15) << 4U));
  uint8_t r2 = libcrux_secrets_int_as_u8_f5(v.ptr[1U] >> 4U & 255);
  return (KRML_CLITERAL(uint8_t_x3){ .fst = r0, .snd = r1, .thd = r2 });
}

KRML_MUSTINLINE Eurydice_arr_94
libcrux_ml_kem_vector_portable_serialize_serialize_12(Eurydice_arr_d6 v)
{
  uint8_t_x3
  r0_2 =
    libcrux_ml_kem_vector_portable_serialize_serialize_12_int(Eurydice_array_to_subslice_shared_e7(&v,
        (KRML_CLITERAL(core_ops_range_Range_87){ .start = (size_t)0U, .end = (size_t)2U })));
  uint8_t_x3
  r3_5 =
    libcrux_ml_kem_vector_portable_serialize_serialize_12_int(Eurydice_array_to_subslice_shared_e7(&v,
        (KRML_CLITERAL(core_ops_range_Range_87){ .start = (size_t)2U, .end = (size_t)4U })));
  uint8_t_x3
  r6_8 =
    libcrux_ml_kem_vector_portable_serialize_serialize_12_int(Eurydice_array_to_subslice_shared_e7(&v,
        (KRML_CLITERAL(core_ops_range_Range_87){ .start = (size_t)4U, .end = (size_t)6U })));
  uint8_t_x3
  r9_11 =
    libcrux_ml_kem_vector_portable_serialize_serialize_12_int(Eurydice_array_to_subslice_shared_e7(&v,
        (KRML_CLITERAL(core_ops_range_Range_87){ .start = (size_t)6U, .end = (size_t)8U })));
  uint8_t_x3
  r12_14 =
    libcrux_ml_kem_vector_portable_serialize_serialize_12_int(Eurydice_array_to_subslice_shared_e7(&v,
        (KRML_CLITERAL(core_ops_range_Range_87){ .start = (size_t)8U, .end = (size_t)10U })));
  uint8_t_x3
  r15_17 =
    libcrux_ml_kem_vector_portable_serialize_serialize_12_int(Eurydice_array_to_subslice_shared_e7(&v,
        (KRML_CLITERAL(core_ops_range_Range_87){ .start = (size_t)10U, .end = (size_t)12U })));
  uint8_t_x3
  r18_20 =
    libcrux_ml_kem_vector_portable_serialize_serialize_12_int(Eurydice_array_to_subslice_shared_e7(&v,
        (KRML_CLITERAL(core_ops_range_Range_87){ .start = (size_t)12U, .end = (size_t)14U })));
  uint8_t_x3
  r21_23 =
    libcrux_ml_kem_vector_portable_serialize_serialize_12_int(Eurydice_array_to_subslice_shared_e7(&v,
        (KRML_CLITERAL(core_ops_range_Range_87){ .start = (size_t)14U, .end = (size_t)16U })));
  return
    (
      KRML_CLITERAL(Eurydice_arr_94){
        .data = {
          r0_2.fst, r0_2.snd, r0_2.thd, r3_5.fst, r3_5.snd, r3_5.thd, r6_8.fst, r6_8.snd, r6_8.thd,
          r9_11.fst, r9_11.snd, r9_11.thd, r12_14.fst, r12_14.snd, r12_14.thd, r15_17.fst,
          r15_17.snd, r15_17.thd, r18_20.fst, r18_20.snd, r18_20.thd, r21_23.fst, r21_23.snd,
          r21_23.thd
        }
      }
    );
}

Eurydice_arr_94 libcrux_ml_kem_vector_portable_serialize_12(Eurydice_arr_d6 a)
{
  return
    libcrux_secrets_int_classify_public_declassify_91_ed(libcrux_ml_kem_vector_portable_serialize_serialize_12(a));
}

/**
This function found in impl {libcrux_ml_kem::vector::traits::Operations for libcrux_ml_kem::vector::portable::vector_type::PortableVector}
*/
Eurydice_arr_94 libcrux_ml_kem_vector_portable_serialize_12_b8(Eurydice_arr_d6 a)
{
  return libcrux_ml_kem_vector_portable_serialize_12(a);
}

KRML_MUSTINLINE int16_t_x2
libcrux_ml_kem_vector_portable_serialize_deserialize_12_int(Eurydice_borrow_slice_u8 bytes)
{
  int16_t byte0 = libcrux_secrets_int_as_i16_59(bytes.ptr[0U]);
  int16_t byte1 = libcrux_secrets_int_as_i16_59(bytes.ptr[1U]);
  int16_t byte2 = libcrux_secrets_int_as_i16_59(bytes.ptr[2U]);
  int16_t r0 = (int16_t)((uint32_t)(byte1 & 15) << 8U) | (byte0 & 255);
  int16_t r1 = (int16_t)((uint32_t)byte2 << 4U) | (byte1 >> 4U & 15);
  return (KRML_CLITERAL(int16_t_x2){ .fst = r0, .snd = r1 });
}

KRML_MUSTINLINE Eurydice_arr_d6
libcrux_ml_kem_vector_portable_serialize_deserialize_12(Eurydice_borrow_slice_u8 bytes)
{
  int16_t_x2
  v0_1 =
    libcrux_ml_kem_vector_portable_serialize_deserialize_12_int(Eurydice_slice_subslice_shared_c8(bytes,
        (KRML_CLITERAL(core_ops_range_Range_87){ .start = (size_t)0U, .end = (size_t)3U })));
  int16_t_x2
  v2_3 =
    libcrux_ml_kem_vector_portable_serialize_deserialize_12_int(Eurydice_slice_subslice_shared_c8(bytes,
        (KRML_CLITERAL(core_ops_range_Range_87){ .start = (size_t)3U, .end = (size_t)6U })));
  int16_t_x2
  v4_5 =
    libcrux_ml_kem_vector_portable_serialize_deserialize_12_int(Eurydice_slice_subslice_shared_c8(bytes,
        (KRML_CLITERAL(core_ops_range_Range_87){ .start = (size_t)6U, .end = (size_t)9U })));
  int16_t_x2
  v6_7 =
    libcrux_ml_kem_vector_portable_serialize_deserialize_12_int(Eurydice_slice_subslice_shared_c8(bytes,
        (KRML_CLITERAL(core_ops_range_Range_87){ .start = (size_t)9U, .end = (size_t)12U })));
  int16_t_x2
  v8_9 =
    libcrux_ml_kem_vector_portable_serialize_deserialize_12_int(Eurydice_slice_subslice_shared_c8(bytes,
        (KRML_CLITERAL(core_ops_range_Range_87){ .start = (size_t)12U, .end = (size_t)15U })));
  int16_t_x2
  v10_11 =
    libcrux_ml_kem_vector_portable_serialize_deserialize_12_int(Eurydice_slice_subslice_shared_c8(bytes,
        (KRML_CLITERAL(core_ops_range_Range_87){ .start = (size_t)15U, .end = (size_t)18U })));
  int16_t_x2
  v12_13 =
    libcrux_ml_kem_vector_portable_serialize_deserialize_12_int(Eurydice_slice_subslice_shared_c8(bytes,
        (KRML_CLITERAL(core_ops_range_Range_87){ .start = (size_t)18U, .end = (size_t)21U })));
  int16_t_x2
  v14_15 =
    libcrux_ml_kem_vector_portable_serialize_deserialize_12_int(Eurydice_slice_subslice_shared_c8(bytes,
        (KRML_CLITERAL(core_ops_range_Range_87){ .start = (size_t)21U, .end = (size_t)24U })));
  return
    (
      KRML_CLITERAL(Eurydice_arr_d6){
        .data = {
          v0_1.fst, v0_1.snd, v2_3.fst, v2_3.snd, v4_5.fst, v4_5.snd, v6_7.fst, v6_7.snd, v8_9.fst,
          v8_9.snd, v10_11.fst, v10_11.snd, v12_13.fst, v12_13.snd, v14_15.fst, v14_15.snd
        }
      }
    );
}

Eurydice_arr_d6 libcrux_ml_kem_vector_portable_deserialize_12(Eurydice_borrow_slice_u8 a)
{
  return
    libcrux_ml_kem_vector_portable_serialize_deserialize_12(libcrux_secrets_int_classify_public_classify_ref_6d_90(a));
}

/**
This function found in impl {libcrux_ml_kem::vector::traits::Operations for libcrux_ml_kem::vector::portable::vector_type::PortableVector}
*/
Eurydice_arr_d6 libcrux_ml_kem_vector_portable_deserialize_12_b8(Eurydice_borrow_slice_u8 a)
{
  return libcrux_ml_kem_vector_portable_deserialize_12(a);
}

KRML_MUSTINLINE size_t
libcrux_ml_kem_vector_portable_sampling_rej_sample(
  Eurydice_borrow_slice_u8 a,
  Eurydice_mut_borrow_slice_i16 result
)
{
  size_t sampled = (size_t)0U;
  for (size_t i = (size_t)0U; i < a.meta / (size_t)3U; i++)
  {
    size_t i0 = i;
    int16_t b1 = (int16_t)(uint32_t)a.ptr[i0 * (size_t)3U + (size_t)0U];
    int16_t b2 = (int16_t)(uint32_t)a.ptr[i0 * (size_t)3U + (size_t)1U];
    int16_t b3 = (int16_t)(uint32_t)a.ptr[i0 * (size_t)3U + (size_t)2U];
    int16_t d1 = (int16_t)((uint32_t)(b2 & 15) << 8U) | b1;
    int16_t d2 = (int16_t)((uint32_t)b3 << 4U) | b2 >> 4U;
    if (d1 < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS)
    {
      if (sampled < (size_t)16U)
      {
        result.ptr[sampled] = d1;
        sampled++;
      }
    }
    if (d2 < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS)
    {
      if (sampled < (size_t)16U)
      {
        result.ptr[sampled] = d2;
        sampled++;
      }
    }
  }
  return sampled;
}

/**
This function found in impl {libcrux_ml_kem::vector::traits::Operations for libcrux_ml_kem::vector::portable::vector_type::PortableVector}
*/
size_t
libcrux_ml_kem_vector_portable_rej_sample_b8(
  Eurydice_borrow_slice_u8 a,
  Eurydice_mut_borrow_slice_i16 out
)
{
  return libcrux_ml_kem_vector_portable_sampling_rej_sample(a, out);
}

/**
This function found in impl {core::clone::Clone for libcrux_ml_kem::vector::portable::vector_type::PortableVector}
*/
inline Eurydice_arr_d6
libcrux_ml_kem_vector_portable_vector_type_clone_9c(const Eurydice_arr_d6 *self)
{
  return self[0U];
}

/**
This function found in impl {libcrux_ml_kem::polynomial::PolynomialRingElement<Vector>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.polynomial.ZERO_d6
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static Eurydice_arr_9e ZERO_d6_ea(void)
{
  Eurydice_arr_9e lit;
  Eurydice_arr_d6 repeat_expression[16U];
  KRML_MAYBE_FOR16(i,
    (size_t)0U,
    (size_t)16U,
    (size_t)1U,
    repeat_expression[i] = libcrux_ml_kem_vector_portable_ZERO_b8(););
  memcpy(lit.data, repeat_expression, (size_t)16U * sizeof (Eurydice_arr_d6));
  return lit;
}

/**
 Only use with public values.

 This MUST NOT be used with secret inputs, like its caller `deserialize_ring_elements_reduced`.
*/
/**
A monomorphic instance of libcrux_ml_kem.serialize.deserialize_to_reduced_ring_element
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static KRML_MUSTINLINE Eurydice_arr_9e
deserialize_to_reduced_ring_element_ea(Eurydice_borrow_slice_u8 serialized)
{
  Eurydice_arr_9e re = ZERO_d6_ea();
  for (size_t i = (size_t)0U; i < serialized.meta / (size_t)24U; i++)
  {
    size_t i0 = i;
    Eurydice_borrow_slice_u8
    bytes =
      Eurydice_slice_subslice_shared_c8(serialized,
        (
          KRML_CLITERAL(core_ops_range_Range_87){
            .start = i0 * (size_t)24U,
            .end = i0 * (size_t)24U + (size_t)24U
          }
        ));
    Eurydice_arr_d6 coefficient = libcrux_ml_kem_vector_portable_deserialize_12_b8(bytes);
    Eurydice_arr_d6 uu____0 = libcrux_ml_kem_vector_portable_cond_subtract_3329_b8(coefficient);
    re.data[i0] = uu____0;
  }
  return re;
}

/**
 See [deserialize_ring_elements_reduced_out].
*/
/**
A monomorphic instance of libcrux_ml_kem.serialize.deserialize_ring_elements_reduced
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 4
*/
static KRML_MUSTINLINE void
deserialize_ring_elements_reduced_ee(
  Eurydice_borrow_slice_u8 public_key,
  Eurydice_arr_d20 *deserialized_pk
)
{
  for
  (size_t
    i = (size_t)0U;
    i < public_key.meta / LIBCRUX_ML_KEM_CONSTANTS_BYTES_PER_RING_ELEMENT;
    i++)
  {
    size_t i0 = i;
    Eurydice_borrow_slice_u8
    ring_element =
      Eurydice_slice_subslice_shared_c8(public_key,
        (
          KRML_CLITERAL(core_ops_range_Range_87){
            .start = i0 * LIBCRUX_ML_KEM_CONSTANTS_BYTES_PER_RING_ELEMENT,
            .end = i0 * LIBCRUX_ML_KEM_CONSTANTS_BYTES_PER_RING_ELEMENT +
              LIBCRUX_ML_KEM_CONSTANTS_BYTES_PER_RING_ELEMENT
          }
        ));
    Eurydice_arr_9e uu____0 = deserialize_to_reduced_ring_element_ea(ring_element);
    deserialized_pk->data[i0] = uu____0;
  }
}

/**
A monomorphic instance of libcrux_ml_kem.hash_functions.portable.shake128_init_absorb_final
with const generics
- K= 4
*/
static inline Eurydice_arr_4a shake128_init_absorb_final_23(const Eurydice_arr_56 *input)
{
  Eurydice_arr_4a shake128_state;
  Eurydice_arr_7c repeat_expression[4U];
  KRML_MAYBE_FOR4(i,
    (size_t)0U,
    (size_t)4U,
    (size_t)1U,
    repeat_expression[i] = libcrux_sha3_portable_incremental_shake128_init(););
  memcpy(shake128_state.data, repeat_expression, (size_t)4U * sizeof (Eurydice_arr_7c));
  KRML_MAYBE_FOR4(i,
    (size_t)0U,
    (size_t)4U,
    (size_t)1U,
    size_t i0 = i;
    libcrux_sha3_portable_incremental_shake128_absorb_final(&shake128_state.data[i0],
      Eurydice_array_to_slice_shared_e9(&input->data[i0])););
  return shake128_state;
}

/**
This function found in impl {libcrux_ml_kem::hash_functions::Hash<K> for libcrux_ml_kem::hash_functions::portable::PortableHash<K>}
*/
/**
A monomorphic instance of libcrux_ml_kem.hash_functions.portable.shake128_init_absorb_final_4a
with const generics
- K= 4
*/
Eurydice_arr_4a
libcrux_ml_kem_hash_functions_portable_shake128_init_absorb_final_4a_23(
  const Eurydice_arr_56 *input
)
{
  return shake128_init_absorb_final_23(input);
}

/**
A monomorphic instance of libcrux_ml_kem.hash_functions.portable.shake128_squeeze_first_three_blocks
with const generics
- K= 4
*/
static inline Eurydice_arr_7c0 shake128_squeeze_first_three_blocks_23(Eurydice_arr_4a *st)
{
  Eurydice_arr_7c0
  out =
    { .data = { { .data = { 0U } }, { .data = { 0U } }, { .data = { 0U } }, { .data = { 0U } } } };
  KRML_MAYBE_FOR4(i,
    (size_t)0U,
    (size_t)4U,
    (size_t)1U,
    size_t i0 = i;
    libcrux_sha3_portable_incremental_shake128_squeeze_first_three_blocks(&st->data[i0],
      Eurydice_array_to_slice_mut_48(&out.data[i0])););
  return out;
}

/**
This function found in impl {libcrux_ml_kem::hash_functions::Hash<K> for libcrux_ml_kem::hash_functions::portable::PortableHash<K>}
*/
/**
A monomorphic instance of libcrux_ml_kem.hash_functions.portable.shake128_squeeze_first_three_blocks_4a
with const generics
- K= 4
*/
Eurydice_arr_7c0
libcrux_ml_kem_hash_functions_portable_shake128_squeeze_first_three_blocks_4a_23(
  Eurydice_arr_4a *self
)
{
  return shake128_squeeze_first_three_blocks_23(self);
}

/**
 If `bytes` contains a set of uniformly random bytes, this function
 uniformly samples a ring element `â` that is treated as being the NTT representation
 of the corresponding polynomial `a`.

 Since rejection sampling is used, it is possible the supplied bytes are
 not enough to sample the element, in which case an `Err` is returned and the
 caller must try again with a fresh set of bytes.

 This function <strong>partially</strong> implements <strong>Algorithm 6</strong> of the NIST FIPS 203 standard,
 We say "partially" because this implementation only accepts a finite set of
 bytes as input and returns an error if the set is not enough; Algorithm 6 of
 the FIPS 203 standard on the other hand samples from an infinite stream of bytes
 until the ring element is filled. Algorithm 6 is reproduced below:

 ```plaintext
 Input: byte stream B ∈ 𝔹*.
 Output: array â ∈ ℤ₂₅₆.

 i ← 0
 j ← 0
 while j < 256 do
     d₁ ← B[i] + 256·(B[i+1] mod 16)
     d₂ ← ⌊B[i+1]/16⌋ + 16·B[i+2]
     if d₁ < q then
         â[j] ← d₁
         j ← j + 1
     end if
     if d₂ < q and j < 256 then
         â[j] ← d₂
         j ← j + 1
     end if
     i ← i + 3
 end while
 return â
 ```

 The NIST FIPS 203 standard can be found at
 <https://csrc.nist.gov/pubs/fips/203/ipd>.
*/
/**
A monomorphic instance of libcrux_ml_kem.sampling.sample_from_uniform_distribution_next
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 4
- N= 504
*/
static KRML_MUSTINLINE bool
sample_from_uniform_distribution_next_1c(
  const Eurydice_arr_7c0 *randomness,
  Eurydice_arr_cc *sampled_coefficients,
  Eurydice_arr_240 *out
)
{
  KRML_MAYBE_FOR4(i0,
    (size_t)0U,
    (size_t)4U,
    (size_t)1U,
    size_t i1 = i0;
    for (size_t i = (size_t)0U; i < (size_t)504U / (size_t)24U; i++)
    {
      size_t r = i;
      if (sampled_coefficients->data[i1] < LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT)
      {
        size_t
        sampled =
          libcrux_ml_kem_vector_portable_rej_sample_b8(Eurydice_array_to_subslice_shared_d46(&randomness->data[i1],
              (
                KRML_CLITERAL(core_ops_range_Range_87){
                  .start = r * (size_t)24U,
                  .end = r * (size_t)24U + (size_t)24U
                }
              )),
            Eurydice_array_to_subslice_mut_e7(&out->data[i1],
              (
                KRML_CLITERAL(core_ops_range_Range_87){
                  .start = sampled_coefficients->data[i1],
                  .end = sampled_coefficients->data[i1] + (size_t)16U
                }
              )));
        size_t uu____0 = i1;
        sampled_coefficients->data[uu____0] += sampled;
      }
    });
  bool done = true;
  KRML_MAYBE_FOR4(i,
    (size_t)0U,
    (size_t)4U,
    (size_t)1U,
    size_t i0 = i;
    if (sampled_coefficients->data[i0] >= LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT)
    {
      sampled_coefficients->data[i0] = LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT;
    }
    else
    {
      done = false;
    });
  return done;
}

/**
A monomorphic instance of libcrux_ml_kem.hash_functions.portable.shake128_squeeze_next_block
with const generics
- K= 4
*/
static inline Eurydice_arr_9c shake128_squeeze_next_block_23(Eurydice_arr_4a *st)
{
  Eurydice_arr_9c
  out =
    { .data = { { .data = { 0U } }, { .data = { 0U } }, { .data = { 0U } }, { .data = { 0U } } } };
  KRML_MAYBE_FOR4(i,
    (size_t)0U,
    (size_t)4U,
    (size_t)1U,
    size_t i0 = i;
    libcrux_sha3_portable_incremental_shake128_squeeze_next_block(&st->data[i0],
      Eurydice_array_to_slice_mut_2c(&out.data[i0])););
  return out;
}

/**
This function found in impl {libcrux_ml_kem::hash_functions::Hash<K> for libcrux_ml_kem::hash_functions::portable::PortableHash<K>}
*/
/**
A monomorphic instance of libcrux_ml_kem.hash_functions.portable.shake128_squeeze_next_block_4a
with const generics
- K= 4
*/
Eurydice_arr_9c
libcrux_ml_kem_hash_functions_portable_shake128_squeeze_next_block_4a_23(Eurydice_arr_4a *self)
{
  return shake128_squeeze_next_block_23(self);
}

/**
 If `bytes` contains a set of uniformly random bytes, this function
 uniformly samples a ring element `â` that is treated as being the NTT representation
 of the corresponding polynomial `a`.

 Since rejection sampling is used, it is possible the supplied bytes are
 not enough to sample the element, in which case an `Err` is returned and the
 caller must try again with a fresh set of bytes.

 This function <strong>partially</strong> implements <strong>Algorithm 6</strong> of the NIST FIPS 203 standard,
 We say "partially" because this implementation only accepts a finite set of
 bytes as input and returns an error if the set is not enough; Algorithm 6 of
 the FIPS 203 standard on the other hand samples from an infinite stream of bytes
 until the ring element is filled. Algorithm 6 is reproduced below:

 ```plaintext
 Input: byte stream B ∈ 𝔹*.
 Output: array â ∈ ℤ₂₅₆.

 i ← 0
 j ← 0
 while j < 256 do
     d₁ ← B[i] + 256·(B[i+1] mod 16)
     d₂ ← ⌊B[i+1]/16⌋ + 16·B[i+2]
     if d₁ < q then
         â[j] ← d₁
         j ← j + 1
     end if
     if d₂ < q and j < 256 then
         â[j] ← d₂
         j ← j + 1
     end if
     i ← i + 3
 end while
 return â
 ```

 The NIST FIPS 203 standard can be found at
 <https://csrc.nist.gov/pubs/fips/203/ipd>.
*/
/**
A monomorphic instance of libcrux_ml_kem.sampling.sample_from_uniform_distribution_next
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 4
- N= 168
*/
static KRML_MUSTINLINE bool
sample_from_uniform_distribution_next_1c0(
  const Eurydice_arr_9c *randomness,
  Eurydice_arr_cc *sampled_coefficients,
  Eurydice_arr_240 *out
)
{
  KRML_MAYBE_FOR4(i0,
    (size_t)0U,
    (size_t)4U,
    (size_t)1U,
    size_t i1 = i0;
    for (size_t i = (size_t)0U; i < (size_t)168U / (size_t)24U; i++)
    {
      size_t r = i;
      if (sampled_coefficients->data[i1] < LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT)
      {
        size_t
        sampled =
          libcrux_ml_kem_vector_portable_rej_sample_b8(Eurydice_array_to_subslice_shared_d40(&randomness->data[i1],
              (
                KRML_CLITERAL(core_ops_range_Range_87){
                  .start = r * (size_t)24U,
                  .end = r * (size_t)24U + (size_t)24U
                }
              )),
            Eurydice_array_to_subslice_mut_e7(&out->data[i1],
              (
                KRML_CLITERAL(core_ops_range_Range_87){
                  .start = sampled_coefficients->data[i1],
                  .end = sampled_coefficients->data[i1] + (size_t)16U
                }
              )));
        size_t uu____0 = i1;
        sampled_coefficients->data[uu____0] += sampled;
      }
    });
  bool done = true;
  KRML_MAYBE_FOR4(i,
    (size_t)0U,
    (size_t)4U,
    (size_t)1U,
    size_t i0 = i;
    if (sampled_coefficients->data[i0] >= LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT)
    {
      sampled_coefficients->data[i0] = LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT;
    }
    else
    {
      done = false;
    });
  return done;
}

/**
A monomorphic instance of libcrux_ml_kem.polynomial.ZERO
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static Eurydice_arr_9e ZERO_ea(void)
{
  Eurydice_arr_9e lit;
  Eurydice_arr_d6 repeat_expression[16U];
  KRML_MAYBE_FOR16(i,
    (size_t)0U,
    (size_t)16U,
    (size_t)1U,
    repeat_expression[i] = libcrux_ml_kem_vector_portable_ZERO_b8(););
  memcpy(lit.data, repeat_expression, (size_t)16U * sizeof (Eurydice_arr_d6));
  return lit;
}

/**
A monomorphic instance of libcrux_ml_kem.polynomial.from_i16_array
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static KRML_MUSTINLINE Eurydice_arr_9e from_i16_array_ea(Eurydice_borrow_slice_i16 a)
{
  Eurydice_arr_9e result = ZERO_ea();
  for (size_t i = (size_t)0U; i < LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT; i++)
  {
    size_t i0 = i;
    Eurydice_arr_d6
    uu____0 =
      libcrux_ml_kem_vector_portable_from_i16_array_b8(Eurydice_slice_subslice_shared_a6(a,
          (
            KRML_CLITERAL(core_ops_range_Range_87){
              .start = i0 * (size_t)16U,
              .end = (i0 + (size_t)1U) * (size_t)16U
            }
          )));
    result.data[i0] = uu____0;
  }
  return result;
}

/**
This function found in impl {libcrux_ml_kem::polynomial::PolynomialRingElement<Vector>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.polynomial.from_i16_array_d6
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static KRML_MUSTINLINE Eurydice_arr_9e from_i16_array_d6_ea(Eurydice_borrow_slice_i16 a)
{
  return from_i16_array_ea(a);
}

/**
This function found in impl {core::ops::function::FnMut<([i16; 272usize]), libcrux_ml_kem::polynomial::PolynomialRingElement<Vector>[TraitClause@0, TraitClause@2]> for libcrux_ml_kem::sampling::sample_from_xof::closure<Vector, Hasher, K>[TraitClause@0, TraitClause@1, TraitClause@2, TraitClause@3]}
*/
/**
A monomorphic instance of libcrux_ml_kem.sampling.sample_from_xof.call_mut_0a
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$4size_t]]
with const generics
- K= 4
*/
static Eurydice_arr_9e call_mut_0a_911(Eurydice_arr_5b tupled_args)
{
  Eurydice_arr_5b s = tupled_args;
  return
    from_i16_array_d6_ea(Eurydice_array_to_subslice_shared_e70(&s,
        (KRML_CLITERAL(core_ops_range_Range_87){ .start = (size_t)0U, .end = (size_t)256U })));
}

/**
A monomorphic instance of libcrux_ml_kem.sampling.sample_from_xof
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$4size_t]]
with const generics
- K= 4
*/
static KRML_MUSTINLINE Eurydice_arr_d20 sample_from_xof_911(const Eurydice_arr_56 *seeds)
{
  Eurydice_arr_cc sampled_coefficients = { .data = { 0U } };
  Eurydice_arr_240
  out =
    { .data = { { .data = { 0U } }, { .data = { 0U } }, { .data = { 0U } }, { .data = { 0U } } } };
  Eurydice_arr_4a
  xof_state = libcrux_ml_kem_hash_functions_portable_shake128_init_absorb_final_4a_23(seeds);
  Eurydice_arr_7c0
  randomness0 =
    libcrux_ml_kem_hash_functions_portable_shake128_squeeze_first_three_blocks_4a_23(&xof_state);
  bool
  done = sample_from_uniform_distribution_next_1c(&randomness0, &sampled_coefficients, &out);
  while (true)
  {
    if (done)
    {
      break;
    }
    else
    {
      Eurydice_arr_9c
      randomness =
        libcrux_ml_kem_hash_functions_portable_shake128_squeeze_next_block_4a_23(&xof_state);
      done = sample_from_uniform_distribution_next_1c0(&randomness, &sampled_coefficients, &out);
    }
  }
  Eurydice_arr_d20 arr_mapped_str;
  KRML_MAYBE_FOR4(i,
    (size_t)0U,
    (size_t)4U,
    (size_t)1U,
    arr_mapped_str.data[i] = call_mut_0a_911(out.data[i]););
  return arr_mapped_str;
}

/**
A monomorphic instance of libcrux_ml_kem.matrix.sample_matrix_A
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$4size_t]]
with const generics
- K= 4
*/
static KRML_MUSTINLINE void
sample_matrix_A_911(Eurydice_arr_602 *A_transpose, const Eurydice_arr_31 *seed, bool transpose)
{
  KRML_MAYBE_FOR4(i0,
    (size_t)0U,
    (size_t)4U,
    (size_t)1U,
    size_t i1 = i0;
    Eurydice_arr_56 seeds;
    Eurydice_arr_31 repeat_expression[4U];
    KRML_MAYBE_FOR4(i,
      (size_t)0U,
      (size_t)4U,
      (size_t)1U,
      repeat_expression[i] =
        core_array__core__clone__Clone_for__T__N___clone((size_t)34U,
          seed,
          uint8_t,
          Eurydice_arr_31););
    memcpy(seeds.data, repeat_expression, (size_t)4U * sizeof (Eurydice_arr_31));
    KRML_MAYBE_FOR4(i,
      (size_t)0U,
      (size_t)4U,
      (size_t)1U,
      size_t j = i;
      seeds.data[j].data[32U] = (uint8_t)i1;
      seeds.data[j].data[33U] = (uint8_t)j;);
    Eurydice_arr_d20 sampled = sample_from_xof_911(&seeds);
    KRML_MAYBE_FOR4(i,
      (size_t)0U,
      (size_t)4U,
      (size_t)1U,
      size_t j = i;
      Eurydice_arr_9e sample = sampled.data[j];
      if (transpose)
      {
        A_transpose->data[j].data[i1] = sample;
      }
      else
      {
        A_transpose->data[i1].data[j] = sample;
      }););
}

/**
This function found in impl {libcrux_ml_kem::hash_functions::Hash<K> for libcrux_ml_kem::hash_functions::portable::PortableHash<K>}
*/
/**
A monomorphic instance of libcrux_ml_kem.hash_functions.portable.H_4a
with const generics
- K= 4
*/
static inline Eurydice_arr_ec H_4a_23(Eurydice_borrow_slice_u8 input)
{
  return libcrux_ml_kem_hash_functions_portable_H(input);
}

/**
 Generate an unpacked key from a serialized key.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.unpack_public_key
with types libcrux_ml_kem_hash_functions_portable_PortableHash[[$4size_t]], libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 4
- T_AS_NTT_ENCODED_SIZE= 1536
- PUBLIC_KEY_SIZE= 1568
*/
void
libcrux_ml_kem_ind_cca_unpacked_unpack_public_key_29(
  const Eurydice_arr_d1 *public_key,
  libcrux_ml_kem_ind_cca_unpacked_MlKemPublicKeyUnpacked_94 *unpacked_public_key
)
{
  Eurydice_borrow_slice_u8
  uu____0 = Eurydice_array_to_subslice_to_shared_214(public_key, (size_t)1536U);
  deserialize_ring_elements_reduced_ee(uu____0,
    &unpacked_public_key->ind_cpa_public_key.t_as_ntt);
  unpacked_public_key->ind_cpa_public_key.seed_for_A =
    libcrux_ml_kem_utils_into_padded_array_ce(Eurydice_array_to_subslice_from_shared_5f5(public_key,
        (size_t)1536U));
  Eurydice_arr_602 *uu____2 = &unpacked_public_key->ind_cpa_public_key.A;
  /* original Rust expression is not an lvalue in C */
  Eurydice_arr_31
  lvalue =
    libcrux_ml_kem_utils_into_padded_array_de(Eurydice_array_to_subslice_from_shared_5f5(public_key,
        (size_t)1536U));
  sample_matrix_A_911(uu____2, &lvalue, false);
  Eurydice_arr_ec
  uu____3 =
    H_4a_23(Eurydice_array_to_slice_shared_b50(libcrux_ml_kem_types_as_slice_e6_d9(public_key)));
  unpacked_public_key->public_key_hash = uu____3;
}

/**
A monomorphic instance of libcrux_ml_kem.serialize.to_unsigned_field_modulus
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static KRML_MUSTINLINE Eurydice_arr_d6 to_unsigned_field_modulus_ea(Eurydice_arr_d6 a)
{
  return libcrux_ml_kem_vector_portable_to_unsigned_representative_b8(a);
}

/**
A monomorphic instance of libcrux_ml_kem.serialize.serialize_uncompressed_ring_element
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static KRML_MUSTINLINE Eurydice_arr_b20
serialize_uncompressed_ring_element_ea(const Eurydice_arr_9e *re)
{
  Eurydice_arr_b20 serialized = { .data = { 0U } };
  for (size_t i = (size_t)0U; i < LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT; i++)
  {
    size_t i0 = i;
    Eurydice_arr_d6 coefficient = to_unsigned_field_modulus_ea(re->data[i0]);
    Eurydice_arr_94 bytes = libcrux_ml_kem_vector_portable_serialize_12_b8(coefficient);
    Eurydice_slice_copy(Eurydice_array_to_subslice_mut_d415(&serialized,
        (
          KRML_CLITERAL(core_ops_range_Range_87){
            .start = (size_t)24U * i0,
            .end = (size_t)24U * i0 + (size_t)24U
          }
        )),
      Eurydice_array_to_slice_shared_ed(&bytes),
      uint8_t);
  }
  return serialized;
}

/**
 Call [`serialize_uncompressed_ring_element`] for each ring element.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.serialize_vector
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 4
*/
static KRML_MUSTINLINE void
serialize_vector_ee(const Eurydice_arr_d20 *key, Eurydice_mut_borrow_slice_u8 out)
{
  KRML_MAYBE_FOR4(i,
    (size_t)0U,
    (size_t)4U,
    (size_t)1U,
    size_t i0 = i;
    Eurydice_arr_9e re = key->data[i0];
    Eurydice_mut_borrow_slice_u8
    uu____0 =
      Eurydice_slice_subslice_mut_c8(out,
        (
          KRML_CLITERAL(core_ops_range_Range_87){
            .start = i0 * LIBCRUX_ML_KEM_CONSTANTS_BYTES_PER_RING_ELEMENT,
            .end = (i0 + (size_t)1U) * LIBCRUX_ML_KEM_CONSTANTS_BYTES_PER_RING_ELEMENT
          }
        ));
    /* original Rust expression is not an lvalue in C */
    Eurydice_arr_b20 lvalue = serialize_uncompressed_ring_element_ea(&re);
    Eurydice_slice_copy(uu____0, Eurydice_array_to_slice_shared_a9(&lvalue), uint8_t););
}

/**
 Concatenate `t` and `ρ` into the public key.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.serialize_public_key_mut
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 4
- PUBLIC_KEY_SIZE= 1568
*/
static KRML_MUSTINLINE void
serialize_public_key_mut_1c(
  const Eurydice_arr_d20 *t_as_ntt,
  Eurydice_borrow_slice_u8 seed_for_a,
  Eurydice_arr_d1 *serialized
)
{
  serialize_vector_ee(t_as_ntt,
    Eurydice_array_to_subslice_mut_d423(serialized,
      (
        KRML_CLITERAL(core_ops_range_Range_87){
          .start = (size_t)0U,
          .end = libcrux_ml_kem_constants_ranked_bytes_per_ring_element((size_t)4U)
        }
      )));
  Eurydice_slice_copy(Eurydice_array_to_subslice_from_mut_5f8(serialized,
      libcrux_ml_kem_constants_ranked_bytes_per_ring_element((size_t)4U)),
    seed_for_a,
    uint8_t);
}

/**
 Get the serialized public key.
*/
/**
This function found in impl {libcrux_ml_kem::ind_cca::unpacked::MlKemPublicKeyUnpacked<Vector, K>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.serialized_mut_dd
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 4
- PUBLIC_KEY_SIZE= 1568
*/
void
libcrux_ml_kem_ind_cca_unpacked_serialized_mut_dd_1c(
  const libcrux_ml_kem_ind_cca_unpacked_MlKemPublicKeyUnpacked_94 *self,
  Eurydice_arr_d1 *serialized
)
{
  serialize_public_key_mut_1c(&self->ind_cpa_public_key.t_as_ntt,
    Eurydice_array_to_slice_shared_01(&self->ind_cpa_public_key.seed_for_A),
    serialized);
}

/**
 Get the serialized public key.
*/
/**
This function found in impl {libcrux_ml_kem::ind_cca::unpacked::MlKemKeyPairUnpacked<Vector, K>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.serialized_public_key_mut_11
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 4
- PUBLIC_KEY_SIZE= 1568
*/
void
libcrux_ml_kem_ind_cca_unpacked_serialized_public_key_mut_11_1c(
  const libcrux_ml_kem_mlkem1024_portable_unpacked_MlKem1024KeyPairUnpacked *self,
  Eurydice_arr_d1 *serialized
)
{
  libcrux_ml_kem_ind_cca_unpacked_serialized_mut_dd_1c(&self->public_key, serialized);
}

/**
 Concatenate `t` and `ρ` into the public key.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.serialize_public_key
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 4
- PUBLIC_KEY_SIZE= 1568
*/
static KRML_MUSTINLINE Eurydice_arr_d1
serialize_public_key_1c(const Eurydice_arr_d20 *t_as_ntt, Eurydice_borrow_slice_u8 seed_for_a)
{
  Eurydice_arr_d1 public_key_serialized = { .data = { 0U } };
  serialize_public_key_mut_1c(t_as_ntt, seed_for_a, &public_key_serialized);
  return public_key_serialized;
}

/**
 Get the serialized public key.
*/
/**
This function found in impl {libcrux_ml_kem::ind_cca::unpacked::MlKemPublicKeyUnpacked<Vector, K>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.serialized_dd
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 4
- PUBLIC_KEY_SIZE= 1568
*/
static KRML_MUSTINLINE Eurydice_arr_d1
serialized_dd_1c(const libcrux_ml_kem_ind_cca_unpacked_MlKemPublicKeyUnpacked_94 *self)
{
  return
    libcrux_ml_kem_types_from_51_d9(serialize_public_key_1c(&self->ind_cpa_public_key.t_as_ntt,
        Eurydice_array_to_slice_shared_01(&self->ind_cpa_public_key.seed_for_A)));
}

/**
 Get the serialized public key.
*/
/**
This function found in impl {libcrux_ml_kem::ind_cca::unpacked::MlKemKeyPairUnpacked<Vector, K>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.serialized_public_key_11
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 4
- PUBLIC_KEY_SIZE= 1568
*/
Eurydice_arr_d1
libcrux_ml_kem_ind_cca_unpacked_serialized_public_key_11_1c(
  const libcrux_ml_kem_mlkem1024_portable_unpacked_MlKem1024KeyPairUnpacked *self
)
{
  return serialized_dd_1c(&self->public_key);
}

/**
 Serialize the secret key from the unpacked key pair generation.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.serialize_unpacked_secret_key
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 4
- PRIVATE_KEY_SIZE= 1536
- PUBLIC_KEY_SIZE= 1568
*/
static libcrux_ml_kem_utils_extraction_helper_Keypair1024
serialize_unpacked_secret_key_1c(
  const libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_94 *public_key,
  const Eurydice_arr_d20 *private_key
)
{
  Eurydice_arr_d1
  public_key_serialized =
    serialize_public_key_1c(&public_key->t_as_ntt,
      Eurydice_array_to_slice_shared_01(&public_key->seed_for_A));
  Eurydice_arr_df secret_key_serialized = { .data = { 0U } };
  serialize_vector_ee(private_key, Eurydice_array_to_slice_mut_2f(&secret_key_serialized));
  return
    (
      KRML_CLITERAL(libcrux_ml_kem_utils_extraction_helper_Keypair1024){
        .fst = secret_key_serialized,
        .snd = public_key_serialized
      }
    );
}

/**
 Serialize the secret key.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.serialize_kem_secret_key_mut
with types libcrux_ml_kem_hash_functions_portable_PortableHash[[$4size_t]]
with const generics
- K= 4
- SERIALIZED_KEY_LEN= 3168
*/
void
libcrux_ml_kem_ind_cca_serialize_kem_secret_key_mut_4c(
  Eurydice_borrow_slice_u8 private_key,
  Eurydice_borrow_slice_u8 public_key,
  Eurydice_borrow_slice_u8 implicit_rejection_value,
  Eurydice_arr_a8 *serialized
)
{
  size_t pointer = (size_t)0U;
  Eurydice_slice_copy(Eurydice_array_to_subslice_mut_d424(serialized,
      (
        KRML_CLITERAL(core_ops_range_Range_87){
          .start = pointer,
          .end = pointer + private_key.meta
        }
      )),
    private_key,
    uint8_t);
  pointer += private_key.meta;
  Eurydice_slice_copy(Eurydice_array_to_subslice_mut_d424(serialized,
      (KRML_CLITERAL(core_ops_range_Range_87){ .start = pointer, .end = pointer + public_key.meta })),
    public_key,
    uint8_t);
  pointer += public_key.meta;
  Eurydice_mut_borrow_slice_u8
  uu____0 =
    Eurydice_array_to_subslice_mut_d424(serialized,
      (
        KRML_CLITERAL(core_ops_range_Range_87){
          .start = pointer,
          .end = pointer + LIBCRUX_ML_KEM_CONSTANTS_H_DIGEST_SIZE
        }
      ));
  /* original Rust expression is not an lvalue in C */
  Eurydice_arr_ec lvalue = H_4a_23(public_key);
  Eurydice_slice_copy(uu____0, Eurydice_array_to_slice_shared_01(&lvalue), uint8_t);
  pointer += LIBCRUX_ML_KEM_CONSTANTS_H_DIGEST_SIZE;
  Eurydice_slice_copy(Eurydice_array_to_subslice_mut_d424(serialized,
      (
        KRML_CLITERAL(core_ops_range_Range_87){
          .start = pointer,
          .end = pointer + implicit_rejection_value.meta
        }
      )),
    implicit_rejection_value,
    uint8_t);
}

/**
 Get the serialized private key.
*/
/**
This function found in impl {libcrux_ml_kem::ind_cca::unpacked::MlKemKeyPairUnpacked<Vector, K>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.serialized_private_key_mut_11
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 4
- CPA_PRIVATE_KEY_SIZE= 1536
- PRIVATE_KEY_SIZE= 3168
- PUBLIC_KEY_SIZE= 1568
*/
void
libcrux_ml_kem_ind_cca_unpacked_serialized_private_key_mut_11_2e(
  const libcrux_ml_kem_mlkem1024_portable_unpacked_MlKem1024KeyPairUnpacked *self,
  Eurydice_arr_a8 *serialized
)
{
  libcrux_ml_kem_utils_extraction_helper_Keypair1024
  uu____0 =
    serialize_unpacked_secret_key_1c(&self->public_key.ind_cpa_public_key,
      &self->private_key.ind_cpa_private_key);
  Eurydice_arr_df ind_cpa_private_key = uu____0.fst;
  Eurydice_arr_d1 ind_cpa_public_key = uu____0.snd;
  libcrux_ml_kem_ind_cca_serialize_kem_secret_key_mut_4c(Eurydice_array_to_slice_shared_2f0(&ind_cpa_private_key),
    Eurydice_array_to_slice_shared_b50(&ind_cpa_public_key),
    Eurydice_array_to_slice_shared_01(&self->private_key.implicit_rejection_value),
    serialized);
}

/**
 Get the serialized private key.
*/
/**
This function found in impl {libcrux_ml_kem::ind_cca::unpacked::MlKemKeyPairUnpacked<Vector, K>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.serialized_private_key_11
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 4
- CPA_PRIVATE_KEY_SIZE= 1536
- PRIVATE_KEY_SIZE= 3168
- PUBLIC_KEY_SIZE= 1568
*/
Eurydice_arr_a8
libcrux_ml_kem_ind_cca_unpacked_serialized_private_key_11_2e(
  const libcrux_ml_kem_mlkem1024_portable_unpacked_MlKem1024KeyPairUnpacked *self
)
{
  Eurydice_arr_a8 sk = libcrux_ml_kem_types_default_d3_0e();
  libcrux_ml_kem_ind_cca_unpacked_serialized_private_key_mut_11_2e(self, &sk);
  return sk;
}

/**
A monomorphic instance of libcrux_ml_kem.serialize.deserialize_to_uncompressed_ring_element
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static KRML_MUSTINLINE Eurydice_arr_9e
deserialize_to_uncompressed_ring_element_ea(Eurydice_borrow_slice_u8 serialized)
{
  Eurydice_arr_9e re = ZERO_d6_ea();
  for (size_t i = (size_t)0U; i < serialized.meta / (size_t)24U; i++)
  {
    size_t i0 = i;
    Eurydice_borrow_slice_u8
    bytes =
      Eurydice_slice_subslice_shared_c8(serialized,
        (
          KRML_CLITERAL(core_ops_range_Range_87){
            .start = i0 * (size_t)24U,
            .end = i0 * (size_t)24U + (size_t)24U
          }
        ));
    Eurydice_arr_d6 uu____0 = libcrux_ml_kem_vector_portable_deserialize_12_b8(bytes);
    re.data[i0] = uu____0;
  }
  return re;
}

/**
 Call [`deserialize_to_uncompressed_ring_element`] for each ring element.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.deserialize_vector
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 4
*/
static KRML_MUSTINLINE void
deserialize_vector_ee(Eurydice_borrow_slice_u8 secret_key, Eurydice_arr_d20 *secret_as_ntt)
{
  KRML_MAYBE_FOR4(i,
    (size_t)0U,
    (size_t)4U,
    (size_t)1U,
    size_t i0 = i;
    Eurydice_arr_9e
    uu____0 =
      deserialize_to_uncompressed_ring_element_ea(Eurydice_slice_subslice_shared_c8(secret_key,
          (
            KRML_CLITERAL(core_ops_range_Range_87){
              .start = i0 * LIBCRUX_ML_KEM_CONSTANTS_BYTES_PER_RING_ELEMENT,
              .end = (i0 + (size_t)1U) * LIBCRUX_ML_KEM_CONSTANTS_BYTES_PER_RING_ELEMENT
            }
          )));
    secret_as_ntt->data[i0] = uu____0;);
}

/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.build_unpacked_public_key_mut
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$4size_t]]
with const generics
- K= 4
- T_AS_NTT_ENCODED_SIZE= 1536
*/
static KRML_MUSTINLINE void
build_unpacked_public_key_mut_051(
  Eurydice_borrow_slice_u8 public_key,
  libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_94 *unpacked_public_key
)
{
  deserialize_ring_elements_reduced_ee(Eurydice_slice_subslice_to_shared_72(public_key,
      (size_t)1536U),
    &unpacked_public_key->t_as_ntt);
  Eurydice_borrow_slice_u8
  seed = Eurydice_slice_subslice_from_shared_6d(public_key, (size_t)1536U);
  Eurydice_arr_602 *uu____0 = &unpacked_public_key->A;
  /* original Rust expression is not an lvalue in C */
  Eurydice_arr_31 lvalue = libcrux_ml_kem_utils_into_padded_array_de(seed);
  sample_matrix_A_911(uu____0, &lvalue, false);
}

/**
 Take a serialized private key and generate an unpacked key pair from it.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.keys_from_private_key
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 4
- SECRET_KEY_SIZE= 3168
- CPA_SECRET_KEY_SIZE= 1536
- PUBLIC_KEY_SIZE= 1568
- T_AS_NTT_ENCODED_SIZE= 1536
*/
void
libcrux_ml_kem_ind_cca_unpacked_keys_from_private_key_38(
  const Eurydice_arr_a8 *private_key,
  libcrux_ml_kem_mlkem1024_portable_unpacked_MlKem1024KeyPairUnpacked *key_pair
)
{
  Eurydice_borrow_slice_u8_x4
  uu____0 =
    libcrux_ml_kem_types_unpack_private_key_e3(Eurydice_array_to_slice_shared_680(private_key));
  Eurydice_borrow_slice_u8 ind_cpa_secret_key = uu____0.fst;
  Eurydice_borrow_slice_u8 ind_cpa_public_key = uu____0.snd;
  Eurydice_borrow_slice_u8 ind_cpa_public_key_hash = uu____0.thd;
  Eurydice_borrow_slice_u8 implicit_rejection_value = uu____0.f3;
  deserialize_vector_ee(ind_cpa_secret_key, &key_pair->private_key.ind_cpa_private_key);
  build_unpacked_public_key_mut_051(ind_cpa_public_key,
    &key_pair->public_key.ind_cpa_public_key);
  Eurydice_slice_copy(Eurydice_array_to_slice_mut_01(&key_pair->public_key.public_key_hash),
    ind_cpa_public_key_hash,
    uint8_t);
  Eurydice_slice_copy(Eurydice_array_to_slice_mut_01(&key_pair->private_key.implicit_rejection_value),
    implicit_rejection_value,
    uint8_t);
  Eurydice_slice_copy(Eurydice_array_to_slice_mut_01(&key_pair->public_key.ind_cpa_public_key.seed_for_A),
    Eurydice_slice_subslice_from_shared_6d(ind_cpa_public_key, (size_t)1536U),
    uint8_t);
}

/**
This function found in impl {core::default::Default for libcrux_ml_kem::ind_cpa::unpacked::IndCpaPrivateKeyUnpacked<Vector, K>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.unpacked.default_70
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 4
*/
static Eurydice_arr_d20 default_70_ee(void)
{
  Eurydice_arr_d20 lit;
  Eurydice_arr_9e repeat_expression[4U];
  KRML_MAYBE_FOR4(i, (size_t)0U, (size_t)4U, (size_t)1U, repeat_expression[i] = ZERO_d6_ea(););
  memcpy(lit.data, repeat_expression, (size_t)4U * sizeof (Eurydice_arr_9e));
  return lit;
}

/**
This function found in impl {core::default::Default for libcrux_ml_kem::ind_cpa::unpacked::IndCpaPublicKeyUnpacked<Vector, K>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.unpacked.default_8b
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 4
*/
static libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_94 default_8b_ee(void)
{
  Eurydice_arr_d20 uu____0;
  Eurydice_arr_9e repeat_expression0[4U];
  KRML_MAYBE_FOR4(i, (size_t)0U, (size_t)4U, (size_t)1U, repeat_expression0[i] = ZERO_d6_ea(););
  memcpy(uu____0.data, repeat_expression0, (size_t)4U * sizeof (Eurydice_arr_9e));
  Eurydice_arr_ec uu____1 = { .data = { 0U } };
  libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_94 lit0;
  lit0.t_as_ntt = uu____0;
  lit0.seed_for_A = uu____1;
  Eurydice_arr_d20 repeat_expression1[4U];
  KRML_MAYBE_FOR4(i0,
    (size_t)0U,
    (size_t)4U,
    (size_t)1U,
    Eurydice_arr_d20 lit;
    Eurydice_arr_9e repeat_expression[4U];
    KRML_MAYBE_FOR4(i, (size_t)0U, (size_t)4U, (size_t)1U, repeat_expression[i] = ZERO_d6_ea(););
    memcpy(lit.data, repeat_expression, (size_t)4U * sizeof (Eurydice_arr_9e));
    repeat_expression1[i0] = lit;);
  memcpy(lit0.A.data, repeat_expression1, (size_t)4U * sizeof (Eurydice_arr_d20));
  return lit0;
}

/**
This function found in impl {core::default::Default for libcrux_ml_kem::ind_cca::unpacked::MlKemPublicKeyUnpacked<Vector, K>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.default_30
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 4
*/
libcrux_ml_kem_ind_cca_unpacked_MlKemPublicKeyUnpacked_94
libcrux_ml_kem_ind_cca_unpacked_default_30_ee(void)
{
  return
    (
      KRML_CLITERAL(libcrux_ml_kem_ind_cca_unpacked_MlKemPublicKeyUnpacked_94){
        .ind_cpa_public_key = default_8b_ee(),
        .public_key_hash = { .data = { 0U } }
      }
    );
}

/**
This function found in impl {core::default::Default for libcrux_ml_kem::ind_cca::unpacked::MlKemKeyPairUnpacked<Vector, K>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.default_7b
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 4
*/
libcrux_ml_kem_mlkem1024_portable_unpacked_MlKem1024KeyPairUnpacked
libcrux_ml_kem_ind_cca_unpacked_default_7b_ee(void)
{
  libcrux_ml_kem_ind_cca_unpacked_MlKemPrivateKeyUnpacked_94
  uu____0 =
    { .ind_cpa_private_key = default_70_ee(), .implicit_rejection_value = { .data = { 0U } } };
  return
    (
      KRML_CLITERAL(libcrux_ml_kem_mlkem1024_portable_unpacked_MlKem1024KeyPairUnpacked){
        .private_key = uu____0,
        .public_key = libcrux_ml_kem_ind_cca_unpacked_default_30_ee()
      }
    );
}

/**
This function found in impl {libcrux_ml_kem::hash_functions::Hash<K> for libcrux_ml_kem::hash_functions::portable::PortableHash<K>}
*/
/**
A monomorphic instance of libcrux_ml_kem.hash_functions.portable.G_4a
with const generics
- K= 4
*/
static inline Eurydice_arr_c7 G_4a_23(Eurydice_borrow_slice_u8 input)
{
  return libcrux_ml_kem_hash_functions_portable_G(input);
}

/**
This function found in impl {libcrux_ml_kem::variant::Variant for libcrux_ml_kem::variant::MlKem}
*/
/**
A monomorphic instance of libcrux_ml_kem.variant.cpa_keygen_seed_39
with types libcrux_ml_kem_hash_functions_portable_PortableHash[[$4size_t]]
with const generics
- K= 4
*/
static KRML_MUSTINLINE Eurydice_arr_c7
cpa_keygen_seed_39_fe(Eurydice_borrow_slice_u8 key_generation_seed)
{
  Eurydice_arr_fa seed = { .data = { 0U } };
  Eurydice_slice_copy(Eurydice_array_to_subslice_mut_d412(&seed,
      (
        KRML_CLITERAL(core_ops_range_Range_87){
          .start = (size_t)0U,
          .end = LIBCRUX_ML_KEM_CONSTANTS_CPA_PKE_KEY_GENERATION_SEED_SIZE
        }
      )),
    key_generation_seed,
    uint8_t);
  seed.data[LIBCRUX_ML_KEM_CONSTANTS_CPA_PKE_KEY_GENERATION_SEED_SIZE] = (uint8_t)(size_t)4U;
  return G_4a_23(Eurydice_array_to_slice_shared_b5(&seed));
}

/**
A monomorphic instance of libcrux_ml_kem.hash_functions.portable.PRFxN
with const generics
- K= 4
- LEN= 128
*/
static inline Eurydice_arr_3b0 PRFxN_f5(const Eurydice_arr_890 *input)
{
  Eurydice_arr_3b0
  out =
    { .data = { { .data = { 0U } }, { .data = { 0U } }, { .data = { 0U } }, { .data = { 0U } } } };
  KRML_MAYBE_FOR4(i,
    (size_t)0U,
    (size_t)4U,
    (size_t)1U,
    size_t i0 = i;
    libcrux_sha3_portable_shake256(Eurydice_array_to_slice_mut_78(&out.data[i0]),
      Eurydice_array_to_slice_shared_b5(&input->data[i0])););
  return out;
}

/**
This function found in impl {libcrux_ml_kem::hash_functions::Hash<K> for libcrux_ml_kem::hash_functions::portable::PortableHash<K>}
*/
/**
A monomorphic instance of libcrux_ml_kem.hash_functions.portable.PRFxN_4a
with const generics
- K= 4
- LEN= 128
*/
static inline Eurydice_arr_3b0 PRFxN_4a_f5(const Eurydice_arr_890 *input)
{
  return PRFxN_f5(input);
}

/**
 Given a series of uniformly random bytes in `randomness`, for some number `eta`,
 the `sample_from_binomial_distribution_{eta}` functions sample
 a ring element from a binomial distribution centered at 0 that uses two sets
 of `eta` coin flips. If, for example,
 `eta = ETA`, each ring coefficient is a value `v` such
 such that `v ∈ {-ETA, -ETA + 1, ..., 0, ..., ETA + 1, ETA}` and:

 ```plaintext
 - If v < 0, Pr[v] = Pr[-v]
 - If v >= 0, Pr[v] = BINOMIAL_COEFFICIENT(2 * ETA; ETA - v) / 2 ^ (2 * ETA)
 ```

 The values `v < 0` are mapped to the appropriate `KyberFieldElement`.

 The expected value is:

 ```plaintext
 E[X] = (-ETA)Pr[-ETA] + (-(ETA - 1))Pr[-(ETA - 1)] + ... + (ETA - 1)Pr[ETA - 1] + (ETA)Pr[ETA]
      = 0 since Pr[-v] = Pr[v] when v < 0.
 ```

 And the variance is:

 ```plaintext
 Var(X) = E[(X - E[X])^2]
        = E[X^2]
        = sum_(v=-ETA to ETA)v^2 * (BINOMIAL_COEFFICIENT(2 * ETA; ETA - v) / 2^(2 * ETA))
        = ETA / 2
 ```

 This function implements <strong>Algorithm 7</strong> of the NIST FIPS 203 standard, which is
 reproduced below:

 ```plaintext
 Input: byte array B ∈ 𝔹^{64η}.
 Output: array f ∈ ℤ₂₅₆.

 b ← BytesToBits(B)
 for (i ← 0; i < 256; i++)
     x ← ∑(j=0 to η - 1) b[2iη + j]
     y ← ∑(j=0 to η - 1) b[2iη + η + j]
     f[i] ← x−y mod q
 end for
 return f
 ```

 The NIST FIPS 203 standard can be found at
 <https://csrc.nist.gov/pubs/fips/203/ipd>.
*/
/**
A monomorphic instance of libcrux_ml_kem.sampling.sample_from_binomial_distribution_2
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static KRML_MUSTINLINE Eurydice_arr_9e
sample_from_binomial_distribution_2_ea(Eurydice_borrow_slice_u8 randomness)
{
  Eurydice_arr_04 sampled_i16s = { .data = { 0U } };
  for (size_t i0 = (size_t)0U; i0 < randomness.meta / (size_t)4U; i0++)
  {
    size_t chunk_number = i0;
    Eurydice_borrow_slice_u8
    byte_chunk =
      Eurydice_slice_subslice_shared_c8(randomness,
        (
          KRML_CLITERAL(core_ops_range_Range_87){
            .start = chunk_number * (size_t)4U,
            .end = chunk_number * (size_t)4U + (size_t)4U
          }
        ));
    uint32_t
    random_bits_as_u32 =
      (((uint32_t)byte_chunk.ptr[0U] | (uint32_t)byte_chunk.ptr[1U] << 8U) |
        (uint32_t)byte_chunk.ptr[2U] << 16U)
      | (uint32_t)byte_chunk.ptr[3U] << 24U;
    uint32_t even_bits = random_bits_as_u32 & 1431655765U;
    uint32_t odd_bits = random_bits_as_u32 >> 1U & 1431655765U;
    uint32_t coin_toss_outcomes = even_bits + odd_bits;
    for (uint32_t i = 0U; i < 32U / 4U; i++)
    {
      uint32_t outcome_set = i;
      uint32_t outcome_set0 = outcome_set * 4U;
      int16_t outcome_1 = (int16_t)(coin_toss_outcomes >> (uint32_t)outcome_set0 & 3U);
      int16_t outcome_2 = (int16_t)(coin_toss_outcomes >> (uint32_t)(outcome_set0 + 2U) & 3U);
      size_t offset = (size_t)(outcome_set0 >> 2U);
      sampled_i16s.data[(size_t)8U * chunk_number + offset] = outcome_1 - outcome_2;
    }
  }
  return from_i16_array_d6_ea(Eurydice_array_to_slice_shared_990(&sampled_i16s));
}

/**
A monomorphic instance of libcrux_ml_kem.sampling.sample_from_binomial_distribution_3
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static KRML_MUSTINLINE Eurydice_arr_9e
sample_from_binomial_distribution_3_ea(Eurydice_borrow_slice_u8 randomness)
{
  Eurydice_arr_04 sampled_i16s = { .data = { 0U } };
  for (size_t i0 = (size_t)0U; i0 < randomness.meta / (size_t)3U; i0++)
  {
    size_t chunk_number = i0;
    Eurydice_borrow_slice_u8
    byte_chunk =
      Eurydice_slice_subslice_shared_c8(randomness,
        (
          KRML_CLITERAL(core_ops_range_Range_87){
            .start = chunk_number * (size_t)3U,
            .end = chunk_number * (size_t)3U + (size_t)3U
          }
        ));
    uint32_t
    random_bits_as_u24 =
      ((uint32_t)byte_chunk.ptr[0U] | (uint32_t)byte_chunk.ptr[1U] << 8U) |
        (uint32_t)byte_chunk.ptr[2U] << 16U;
    uint32_t first_bits = random_bits_as_u24 & 2396745U;
    uint32_t second_bits = random_bits_as_u24 >> 1U & 2396745U;
    uint32_t third_bits = random_bits_as_u24 >> 2U & 2396745U;
    uint32_t coin_toss_outcomes = first_bits + second_bits + third_bits;
    for (int32_t i = 0; i < 24 / 6; i++)
    {
      int32_t outcome_set = i;
      int32_t outcome_set0 = outcome_set * 6;
      int16_t outcome_1 = (int16_t)(coin_toss_outcomes >> (uint32_t)outcome_set0 & 7U);
      int16_t outcome_2 = (int16_t)(coin_toss_outcomes >> (uint32_t)(outcome_set0 + 3) & 7U);
      size_t offset = (size_t)(outcome_set0 / 6);
      sampled_i16s.data[(size_t)4U * chunk_number + offset] = outcome_1 - outcome_2;
    }
  }
  return from_i16_array_d6_ea(Eurydice_array_to_slice_shared_990(&sampled_i16s));
}

/**
A monomorphic instance of libcrux_ml_kem.sampling.sample_from_binomial_distribution
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- ETA= 2
*/
static KRML_MUSTINLINE Eurydice_arr_9e
sample_from_binomial_distribution_66(Eurydice_borrow_slice_u8 randomness)
{
  return sample_from_binomial_distribution_2_ea(randomness);
}

/**
A monomorphic instance of libcrux_ml_kem.ntt.ntt_at_layer_7
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static KRML_MUSTINLINE void ntt_at_layer_7_ea(Eurydice_arr_9e *re)
{
  size_t step = LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT / (size_t)2U;
  for (size_t i = (size_t)0U; i < step; i++)
  {
    size_t j = i;
    Eurydice_arr_d6
    t = libcrux_ml_kem_vector_portable_multiply_by_constant_b8(re->data[j + step], -1600);
    re->data[j + step] = libcrux_ml_kem_vector_portable_sub_b8(re->data[j], &t);
    Eurydice_arr_d6 uu____1 = libcrux_ml_kem_vector_portable_add_b8(re->data[j], &t);
    re->data[j] = uu____1;
  }
}

typedef struct libcrux_ml_kem_vector_portable_vector_type_PortableVector_x2_s
{
  Eurydice_arr_d6 fst;
  Eurydice_arr_d6 snd;
}
libcrux_ml_kem_vector_portable_vector_type_PortableVector_x2;

/**
A monomorphic instance of libcrux_ml_kem.ntt.ntt_layer_int_vec_step
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static KRML_MUSTINLINE libcrux_ml_kem_vector_portable_vector_type_PortableVector_x2
ntt_layer_int_vec_step_ea(Eurydice_arr_d6 a, Eurydice_arr_d6 b, int16_t zeta_r)
{
  Eurydice_arr_d6
  t = libcrux_ml_kem_vector_portable_montgomery_multiply_by_constant_b8(b, zeta_r);
  b = libcrux_ml_kem_vector_portable_sub_b8(a, &t);
  a = libcrux_ml_kem_vector_portable_add_b8(a, &t);
  return
    (
      KRML_CLITERAL(libcrux_ml_kem_vector_portable_vector_type_PortableVector_x2){
        .fst = a,
        .snd = b
      }
    );
}

/**
A monomorphic instance of libcrux_ml_kem.ntt.ntt_at_layer_4_plus
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static KRML_MUSTINLINE void
ntt_at_layer_4_plus_ea(size_t *zeta_i, Eurydice_arr_9e *re, size_t layer)
{
  size_t step = (size_t)1U << (uint32_t)layer;
  for (size_t i0 = (size_t)0U; i0 < (size_t)128U >> (uint32_t)layer; i0++)
  {
    size_t round = i0;
    zeta_i[0U]++;
    size_t offset = round * step * (size_t)2U;
    size_t offset_vec = offset / (size_t)16U;
    size_t step_vec = step / (size_t)16U;
    for (size_t i = offset_vec; i < offset_vec + step_vec; i++)
    {
      size_t j = i;
      libcrux_ml_kem_vector_portable_vector_type_PortableVector_x2
      uu____0 =
        ntt_layer_int_vec_step_ea(re->data[j],
          re->data[j + step_vec],
          libcrux_ml_kem_polynomial_zeta(zeta_i[0U]));
      Eurydice_arr_d6 x = uu____0.fst;
      Eurydice_arr_d6 y = uu____0.snd;
      re->data[j] = x;
      re->data[j + step_vec] = y;
    }
  }
}

/**
A monomorphic instance of libcrux_ml_kem.ntt.ntt_at_layer_3
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static KRML_MUSTINLINE void ntt_at_layer_3_ea(size_t *zeta_i, Eurydice_arr_9e *re)
{
  KRML_MAYBE_FOR16(i,
    (size_t)0U,
    (size_t)16U,
    (size_t)1U,
    size_t round = i;
    zeta_i[0U]++;
    Eurydice_arr_d6
    uu____0 =
      libcrux_ml_kem_vector_portable_ntt_layer_3_step_b8(re->data[round],
        libcrux_ml_kem_polynomial_zeta(zeta_i[0U]));
    re->data[round] = uu____0;);
}

/**
A monomorphic instance of libcrux_ml_kem.ntt.ntt_at_layer_2
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static KRML_MUSTINLINE void ntt_at_layer_2_ea(size_t *zeta_i, Eurydice_arr_9e *re)
{
  KRML_MAYBE_FOR16(i,
    (size_t)0U,
    (size_t)16U,
    (size_t)1U,
    size_t round = i;
    zeta_i[0U]++;
    re->data[round] =
      libcrux_ml_kem_vector_portable_ntt_layer_2_step_b8(re->data[round],
        libcrux_ml_kem_polynomial_zeta(zeta_i[0U]),
        libcrux_ml_kem_polynomial_zeta(zeta_i[0U] + (size_t)1U));
    zeta_i[0U]++;);
}

/**
A monomorphic instance of libcrux_ml_kem.ntt.ntt_at_layer_1
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static KRML_MUSTINLINE void ntt_at_layer_1_ea(size_t *zeta_i, Eurydice_arr_9e *re)
{
  KRML_MAYBE_FOR16(i,
    (size_t)0U,
    (size_t)16U,
    (size_t)1U,
    size_t round = i;
    zeta_i[0U]++;
    re->data[round] =
      libcrux_ml_kem_vector_portable_ntt_layer_1_step_b8(re->data[round],
        libcrux_ml_kem_polynomial_zeta(zeta_i[0U]),
        libcrux_ml_kem_polynomial_zeta(zeta_i[0U] + (size_t)1U),
        libcrux_ml_kem_polynomial_zeta(zeta_i[0U] + (size_t)2U),
        libcrux_ml_kem_polynomial_zeta(zeta_i[0U] + (size_t)3U));
    zeta_i[0U] += (size_t)3U;);
}

/**
A monomorphic instance of libcrux_ml_kem.polynomial.poly_barrett_reduce
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static KRML_MUSTINLINE void poly_barrett_reduce_ea(Eurydice_arr_9e *myself)
{
  for (size_t i = (size_t)0U; i < LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT; i++)
  {
    size_t i0 = i;
    Eurydice_arr_d6 uu____0 = libcrux_ml_kem_vector_portable_barrett_reduce_b8(myself->data[i0]);
    myself->data[i0] = uu____0;
  }
}

/**
This function found in impl {libcrux_ml_kem::polynomial::PolynomialRingElement<Vector>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.polynomial.poly_barrett_reduce_d6
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static KRML_MUSTINLINE void poly_barrett_reduce_d6_ea(Eurydice_arr_9e *self)
{
  poly_barrett_reduce_ea(self);
}

/**
A monomorphic instance of libcrux_ml_kem.ntt.ntt_binomially_sampled_ring_element
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static KRML_MUSTINLINE void ntt_binomially_sampled_ring_element_ea(Eurydice_arr_9e *re)
{
  ntt_at_layer_7_ea(re);
  size_t zeta_i = (size_t)1U;
  ntt_at_layer_4_plus_ea(&zeta_i, re, (size_t)6U);
  ntt_at_layer_4_plus_ea(&zeta_i, re, (size_t)5U);
  ntt_at_layer_4_plus_ea(&zeta_i, re, (size_t)4U);
  ntt_at_layer_3_ea(&zeta_i, re);
  ntt_at_layer_2_ea(&zeta_i, re);
  ntt_at_layer_1_ea(&zeta_i, re);
  poly_barrett_reduce_d6_ea(re);
}

/**
 Sample a vector of ring elements from a centered binomial distribution and
 convert them into their NTT representations.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.sample_vector_cbd_then_ntt
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$4size_t]]
with const generics
- K= 4
- ETA= 2
- ETA_RANDOMNESS_SIZE= 128
*/
static KRML_MUSTINLINE uint8_t
sample_vector_cbd_then_ntt_bf1(
  Eurydice_arr_d20 *re_as_ntt,
  const Eurydice_arr_fa *prf_input,
  uint8_t domain_separator
)
{
  Eurydice_arr_890 prf_inputs;
  Eurydice_arr_fa repeat_expression[4U];
  KRML_MAYBE_FOR4(i,
    (size_t)0U,
    (size_t)4U,
    (size_t)1U,
    repeat_expression[i] =
      core_array__core__clone__Clone_for__T__N___clone((size_t)33U,
        prf_input,
        uint8_t,
        Eurydice_arr_fa););
  memcpy(prf_inputs.data, repeat_expression, (size_t)4U * sizeof (Eurydice_arr_fa));
  domain_separator = libcrux_ml_kem_utils_prf_input_inc_23(&prf_inputs, domain_separator);
  Eurydice_arr_3b0 prf_outputs = PRFxN_4a_f5(&prf_inputs);
  KRML_MAYBE_FOR4(i,
    (size_t)0U,
    (size_t)4U,
    (size_t)1U,
    size_t i0 = i;
    Eurydice_arr_9e
    uu____0 =
      sample_from_binomial_distribution_66(Eurydice_array_to_slice_shared_78(&prf_outputs.data[i0]));
    re_as_ntt->data[i0] = uu____0;
    ntt_binomially_sampled_ring_element_ea(&re_as_ntt->data[i0]););
  return domain_separator;
}

/**
This function found in impl {core::ops::function::FnMut<(usize), libcrux_ml_kem::polynomial::PolynomialRingElement<Vector>[TraitClause@0, TraitClause@3]> for libcrux_ml_kem::ind_cpa::generate_keypair_unpacked::closure<Vector, Hasher, Scheme, K, ETA1, ETA1_RANDOMNESS_SIZE>[TraitClause@0, TraitClause@1, TraitClause@2, TraitClause@3, TraitClause@4, TraitClause@5]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.generate_keypair_unpacked.call_mut_73
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$4size_t]], libcrux_ml_kem_variant_MlKem
with const generics
- K= 4
- ETA1= 2
- ETA1_RANDOMNESS_SIZE= 128
*/
static Eurydice_arr_9e call_mut_73_391(void **_)
{
  return ZERO_d6_ea();
}

/**
 Given two `KyberPolynomialRingElement`s in their NTT representations,
 compute their product. Given two polynomials in the NTT domain `f^` and `ĵ`,
 the `iᵗʰ` coefficient of the product `k̂` is determined by the calculation:

 ```plaintext
 ĥ[2·i] + ĥ[2·i + 1]X = (f^[2·i] + f^[2·i + 1]X)·(ĝ[2·i] + ĝ[2·i + 1]X) mod (X² - ζ^(2·BitRev₇(i) + 1))
 ```

 This function almost implements <strong>Algorithm 10</strong> of the
 NIST FIPS 203 standard, which is reproduced below:

 ```plaintext
 Input: Two arrays fˆ ∈ ℤ₂₅₆ and ĝ ∈ ℤ₂₅₆.
 Output: An array ĥ ∈ ℤq.

 for(i ← 0; i < 128; i++)
     (ĥ[2i], ĥ[2i+1]) ← BaseCaseMultiply(fˆ[2i], fˆ[2i+1], ĝ[2i], ĝ[2i+1], ζ^(2·BitRev₇(i) + 1))
 end for
 return ĥ
 ```
 We say "almost" because the coefficients of the ring element output by
 this function are in the Montgomery domain.

 The NIST FIPS 203 standard can be found at
 <https://csrc.nist.gov/pubs/fips/203/ipd>.
*/
/**
A monomorphic instance of libcrux_ml_kem.polynomial.ntt_multiply
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static KRML_MUSTINLINE Eurydice_arr_9e
ntt_multiply_ea(const Eurydice_arr_9e *myself, const Eurydice_arr_9e *rhs)
{
  Eurydice_arr_9e out = ZERO_ea();
  for (size_t i = (size_t)0U; i < LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT; i++)
  {
    size_t i0 = i;
    Eurydice_arr_d6
    uu____0 =
      libcrux_ml_kem_vector_portable_ntt_multiply_b8(&myself->data[i0],
        &rhs->data[i0],
        libcrux_ml_kem_polynomial_zeta((size_t)64U + (size_t)4U * i0),
        libcrux_ml_kem_polynomial_zeta((size_t)64U + (size_t)4U * i0 + (size_t)1U),
        libcrux_ml_kem_polynomial_zeta((size_t)64U + (size_t)4U * i0 + (size_t)2U),
        libcrux_ml_kem_polynomial_zeta((size_t)64U + (size_t)4U * i0 + (size_t)3U));
    out.data[i0] = uu____0;
  }
  return out;
}

/**
This function found in impl {libcrux_ml_kem::polynomial::PolynomialRingElement<Vector>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.polynomial.ntt_multiply_d6
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static KRML_MUSTINLINE Eurydice_arr_9e
ntt_multiply_d6_ea(const Eurydice_arr_9e *self, const Eurydice_arr_9e *rhs)
{
  return ntt_multiply_ea(self, rhs);
}

/**
 Given two polynomial ring elements `lhs` and `rhs`, compute the pointwise
 sum of their constituent coefficients.
*/
/**
A monomorphic instance of libcrux_ml_kem.polynomial.add_to_ring_element
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 4
*/
static KRML_MUSTINLINE void
add_to_ring_element_ee(Eurydice_arr_9e *myself, const Eurydice_arr_9e *rhs)
{
  KRML_MAYBE_FOR16(i,
    (size_t)0U,
    (size_t)16U,
    (size_t)1U,
    size_t i0 = i;
    Eurydice_arr_d6
    uu____0 = libcrux_ml_kem_vector_portable_add_b8(myself->data[i0], &rhs->data[i0]);
    myself->data[i0] = uu____0;);
}

/**
 Given two polynomial ring elements `lhs` and `rhs`, compute the pointwise
 sum of their constituent coefficients.
*/
/**
This function found in impl {libcrux_ml_kem::polynomial::PolynomialRingElement<Vector>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.polynomial.add_to_ring_element_d6
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 4
*/
static KRML_MUSTINLINE void
add_to_ring_element_d6_ee(Eurydice_arr_9e *self, const Eurydice_arr_9e *rhs)
{
  add_to_ring_element_ee(self, rhs);
}

/**
A monomorphic instance of libcrux_ml_kem.polynomial.to_standard_domain
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static KRML_MUSTINLINE Eurydice_arr_d6 to_standard_domain_ea(Eurydice_arr_d6 vector)
{
  return
    libcrux_ml_kem_vector_portable_montgomery_multiply_by_constant_b8(vector,
      LIBCRUX_ML_KEM_VECTOR_TRAITS_MONTGOMERY_R_SQUARED_MOD_FIELD_MODULUS);
}

/**
A monomorphic instance of libcrux_ml_kem.polynomial.add_standard_error_reduce
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static KRML_MUSTINLINE void
add_standard_error_reduce_ea(Eurydice_arr_9e *myself, const Eurydice_arr_9e *error)
{
  for (size_t i = (size_t)0U; i < LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT; i++)
  {
    size_t j = i;
    Eurydice_arr_d6 coefficient_normal_form = to_standard_domain_ea(myself->data[j]);
    Eurydice_arr_d6
    sum = libcrux_ml_kem_vector_portable_add_b8(coefficient_normal_form, &error->data[j]);
    Eurydice_arr_d6 red = libcrux_ml_kem_vector_portable_barrett_reduce_b8(sum);
    myself->data[j] = red;
  }
}

/**
This function found in impl {libcrux_ml_kem::polynomial::PolynomialRingElement<Vector>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.polynomial.add_standard_error_reduce_d6
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static KRML_MUSTINLINE void
add_standard_error_reduce_d6_ea(Eurydice_arr_9e *self, const Eurydice_arr_9e *error)
{
  add_standard_error_reduce_ea(self, error);
}

/**
 Compute Â ◦ ŝ + ê
*/
/**
A monomorphic instance of libcrux_ml_kem.matrix.compute_As_plus_e
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 4
*/
static KRML_MUSTINLINE void
compute_As_plus_e_ee(
  Eurydice_arr_d20 *t_as_ntt,
  const Eurydice_arr_602 *matrix_A,
  const Eurydice_arr_d20 *s_as_ntt,
  const Eurydice_arr_d20 *error_as_ntt
)
{
  KRML_MAYBE_FOR4(i,
    (size_t)0U,
    (size_t)4U,
    (size_t)1U,
    size_t i0 = i;
    const Eurydice_arr_d20 *row = &matrix_A->data[i0];
    Eurydice_arr_9e uu____0 = ZERO_d6_ea();
    t_as_ntt->data[i0] = uu____0;
    KRML_MAYBE_FOR4(i1,
      (size_t)0U,
      (size_t)4U,
      (size_t)1U,
      size_t j = i1;
      const Eurydice_arr_9e *matrix_element = &row->data[j];
      Eurydice_arr_9e product = ntt_multiply_d6_ea(matrix_element, &s_as_ntt->data[j]);
      add_to_ring_element_d6_ee(&t_as_ntt->data[i0], &product););
    add_standard_error_reduce_d6_ea(&t_as_ntt->data[i0], &error_as_ntt->data[i0]););
}

/**
 This function implements most of <strong>Algorithm 12</strong> of the
 NIST FIPS 203 specification; this is the Kyber CPA-PKE key generation algorithm.

 We say "most of" since Algorithm 12 samples the required randomness within
 the function itself, whereas this implementation expects it to be provided
 through the `key_generation_seed` parameter.

 Algorithm 12 is reproduced below:

 ```plaintext
 Output: encryption key ekₚₖₑ ∈ 𝔹^{384k+32}.
 Output: decryption key dkₚₖₑ ∈ 𝔹^{384k}.

 d ←$ B
 (ρ,σ) ← G(d)
 N ← 0
 for (i ← 0; i < k; i++)
     for(j ← 0; j < k; j++)
         Â[i,j] ← SampleNTT(XOF(ρ, i, j))
     end for
 end for
 for(i ← 0; i < k; i++)
     s[i] ← SamplePolyCBD_{η₁}(PRF_{η₁}(σ,N))
     N ← N + 1
 end for
 for(i ← 0; i < k; i++)
     e[i] ← SamplePolyCBD_{η₂}(PRF_{η₂}(σ,N))
     N ← N + 1
 end for
 ŝ ← NTT(s)
 ê ← NTT(e)
 t̂ ← Â◦ŝ + ê
 ekₚₖₑ ← ByteEncode₁₂(t̂) ‖ ρ
 dkₚₖₑ ← ByteEncode₁₂(ŝ)
 ```

 The NIST FIPS 203 standard can be found at
 <https://csrc.nist.gov/pubs/fips/203/ipd>.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.generate_keypair_unpacked
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$4size_t]], libcrux_ml_kem_variant_MlKem
with const generics
- K= 4
- ETA1= 2
- ETA1_RANDOMNESS_SIZE= 128
*/
static KRML_MUSTINLINE void
generate_keypair_unpacked_391(
  Eurydice_borrow_slice_u8 key_generation_seed,
  Eurydice_arr_d20 *private_key,
  libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_94 *public_key
)
{
  Eurydice_arr_c7 hashed = cpa_keygen_seed_39_fe(key_generation_seed);
  Eurydice_borrow_slice_u8_x2
  uu____0 =
    Eurydice_slice_split_at(Eurydice_array_to_slice_shared_17(&hashed),
      (size_t)32U,
      uint8_t,
      Eurydice_borrow_slice_u8_x2);
  Eurydice_borrow_slice_u8 seed_for_A = uu____0.fst;
  Eurydice_borrow_slice_u8 seed_for_secret_and_error = uu____0.snd;
  Eurydice_arr_602 *uu____1 = &public_key->A;
  /* original Rust expression is not an lvalue in C */
  Eurydice_arr_31 lvalue0 = libcrux_ml_kem_utils_into_padded_array_de(seed_for_A);
  sample_matrix_A_911(uu____1, &lvalue0, true);
  Eurydice_arr_fa
  prf_input = libcrux_ml_kem_utils_into_padded_array_29(seed_for_secret_and_error);
  uint8_t domain_separator = sample_vector_cbd_then_ntt_bf1(private_key, &prf_input, 0U);
  Eurydice_arr_d20 arr_struct;
  KRML_MAYBE_FOR4(i,
    (size_t)0U,
    (size_t)4U,
    (size_t)1U,
    /* original Rust expression is not an lvalue in C */
    void *lvalue = (void *)0U;
    arr_struct.data[i] = call_mut_73_391(&lvalue););
  Eurydice_arr_d20 error_as_ntt = arr_struct;
  sample_vector_cbd_then_ntt_bf1(&error_as_ntt, &prf_input, domain_separator);
  compute_As_plus_e_ee(&public_key->t_as_ntt, &public_key->A, &private_key[0U], &error_as_ntt);
  Eurydice_arr_ec arr;
  memcpy(arr.data, seed_for_A.ptr, (size_t)32U * sizeof (uint8_t));
  Eurydice_arr_ec
  uu____2 =
    core_result_unwrap_26_39((
        KRML_CLITERAL(core_result_Result_07){ .tag = core_result_Ok, .val = { .case_Ok = arr } }
      ));
  public_key->seed_for_A = uu____2;
}

/**
This function found in impl {core::ops::function::FnMut<(usize), libcrux_ml_kem::polynomial::PolynomialRingElement<Vector>[TraitClause@0, TraitClause@1]> for libcrux_ml_kem::ind_cca::unpacked::transpose_a::closure::closure<Vector, K>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.transpose_a.closure.call_mut_b4
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 4
*/
static Eurydice_arr_9e call_mut_b4_ee(void **_)
{
  return ZERO_d6_ea();
}

/**
This function found in impl {core::ops::function::FnMut<(usize), [libcrux_ml_kem::polynomial::PolynomialRingElement<Vector>[TraitClause@0, TraitClause@1]; K]> for libcrux_ml_kem::ind_cca::unpacked::transpose_a::closure<Vector, K>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.transpose_a.call_mut_22
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 4
*/
static Eurydice_arr_d20 call_mut_22_ee(void **_)
{
  Eurydice_arr_d20 arr_struct;
  KRML_MAYBE_FOR4(i,
    (size_t)0U,
    (size_t)4U,
    (size_t)1U,
    /* original Rust expression is not an lvalue in C */
    void *lvalue = (void *)0U;
    arr_struct.data[i] = call_mut_b4_ee(&lvalue););
  return arr_struct;
}

/**
This function found in impl {core::clone::Clone for libcrux_ml_kem::polynomial::PolynomialRingElement<Vector>[TraitClause@0, TraitClause@2]}
*/
/**
A monomorphic instance of libcrux_ml_kem.polynomial.clone_c1
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static inline Eurydice_arr_9e clone_c1_ea(const Eurydice_arr_9e *self)
{
  return
    core_array__core__clone__Clone_for__T__N___clone((size_t)16U,
      self,
      Eurydice_arr_d6,
      Eurydice_arr_9e);
}

/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.transpose_a
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 4
*/
static Eurydice_arr_602 transpose_a_ee(Eurydice_arr_602 ind_cpa_a)
{
  Eurydice_arr_602 arr_struct;
  KRML_MAYBE_FOR4(i,
    (size_t)0U,
    (size_t)4U,
    (size_t)1U,
    /* original Rust expression is not an lvalue in C */
    void *lvalue = (void *)0U;
    arr_struct.data[i] = call_mut_22_ee(&lvalue););
  Eurydice_arr_602 A = arr_struct;
  KRML_MAYBE_FOR4(i0,
    (size_t)0U,
    (size_t)4U,
    (size_t)1U,
    size_t i1 = i0;
    KRML_MAYBE_FOR4(i,
      (size_t)0U,
      (size_t)4U,
      (size_t)1U,
      size_t j = i;
      Eurydice_arr_9e uu____0 = clone_c1_ea(&ind_cpa_a.data[j].data[i1]);
      A.data[i1].data[j] = uu____0;););
  return A;
}

/**
 Generate Unpacked Keys
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.generate_keypair
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$4size_t]], libcrux_ml_kem_variant_MlKem
with const generics
- K= 4
- CPA_PRIVATE_KEY_SIZE= 1536
- PRIVATE_KEY_SIZE= 3168
- PUBLIC_KEY_SIZE= 1568
- ETA1= 2
- ETA1_RANDOMNESS_SIZE= 128
*/
void
libcrux_ml_kem_ind_cca_unpacked_generate_keypair_b81(
  Eurydice_arr_c7 randomness,
  libcrux_ml_kem_mlkem1024_portable_unpacked_MlKem1024KeyPairUnpacked *out
)
{
  Eurydice_borrow_slice_u8
  ind_cpa_keypair_randomness =
    Eurydice_array_to_subslice_shared_d47(&randomness,
      (
        KRML_CLITERAL(core_ops_range_Range_87){
          .start = (size_t)0U,
          .end = LIBCRUX_ML_KEM_CONSTANTS_CPA_PKE_KEY_GENERATION_SEED_SIZE
        }
      ));
  Eurydice_borrow_slice_u8
  implicit_rejection_value =
    Eurydice_array_to_subslice_from_shared_5f1(&randomness,
      LIBCRUX_ML_KEM_CONSTANTS_CPA_PKE_KEY_GENERATION_SEED_SIZE);
  generate_keypair_unpacked_391(ind_cpa_keypair_randomness,
    &out->private_key.ind_cpa_private_key,
    &out->public_key.ind_cpa_public_key);
  Eurydice_arr_602 A = transpose_a_ee(out->public_key.ind_cpa_public_key.A);
  out->public_key.ind_cpa_public_key.A = A;
  Eurydice_arr_d1
  pk_serialized =
    serialize_public_key_1c(&out->public_key.ind_cpa_public_key.t_as_ntt,
      Eurydice_array_to_slice_shared_01(&out->public_key.ind_cpa_public_key.seed_for_A));
  Eurydice_arr_ec uu____0 = H_4a_23(Eurydice_array_to_slice_shared_b50(&pk_serialized));
  out->public_key.public_key_hash = uu____0;
  Eurydice_arr_ec arr;
  memcpy(arr.data, implicit_rejection_value.ptr, (size_t)32U * sizeof (uint8_t));
  Eurydice_arr_ec
  uu____1 =
    core_result_unwrap_26_39((
        KRML_CLITERAL(core_result_Result_07){ .tag = core_result_Ok, .val = { .case_Ok = arr } }
      ));
  out->private_key.implicit_rejection_value = uu____1;
}

/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.encaps_prepare
with types libcrux_ml_kem_hash_functions_portable_PortableHash[[$4size_t]]
with const generics
- K= 4
*/
static Eurydice_arr_c7
encaps_prepare_fe(Eurydice_borrow_slice_u8 randomness, Eurydice_borrow_slice_u8 pk_hash)
{
  Eurydice_arr_c7 to_hash = libcrux_ml_kem_utils_into_padded_array_c9(randomness);
  Eurydice_slice_copy(Eurydice_array_to_subslice_from_mut_5f1(&to_hash,
      LIBCRUX_ML_KEM_CONSTANTS_H_DIGEST_SIZE),
    pk_hash,
    uint8_t);
  return G_4a_23(Eurydice_array_to_slice_shared_17(&to_hash));
}

/**
A monomorphic instance of n-tuple
with types Eurydice_arr_d20, libcrux_ml_kem_polynomial_PolynomialRingElement_1d

*/
typedef struct tuple_12_s
{
  Eurydice_arr_d20 fst;
  Eurydice_arr_9e snd;
}
tuple_12;

/**
This function found in impl {core::ops::function::FnMut<(usize), libcrux_ml_kem::polynomial::PolynomialRingElement<Vector>[TraitClause@0, TraitClause@2]> for libcrux_ml_kem::ind_cpa::encrypt_c1::closure<Vector, Hasher, K, C1_LEN, U_COMPRESSION_FACTOR, BLOCK_LEN, ETA1, ETA1_RANDOMNESS_SIZE, ETA2, ETA2_RANDOMNESS_SIZE>[TraitClause@0, TraitClause@1, TraitClause@2, TraitClause@3]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.encrypt_c1.call_mut_f1
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$4size_t]]
with const generics
- K= 4
- C1_LEN= 1408
- U_COMPRESSION_FACTOR= 11
- BLOCK_LEN= 352
- ETA1= 2
- ETA1_RANDOMNESS_SIZE= 128
- ETA2= 2
- ETA2_RANDOMNESS_SIZE= 128
*/
static Eurydice_arr_9e call_mut_f1_871(void **_)
{
  return ZERO_d6_ea();
}

/**
This function found in impl {core::ops::function::FnMut<(usize), libcrux_ml_kem::polynomial::PolynomialRingElement<Vector>[TraitClause@0, TraitClause@2]> for libcrux_ml_kem::ind_cpa::encrypt_c1::closure#1<Vector, Hasher, K, C1_LEN, U_COMPRESSION_FACTOR, BLOCK_LEN, ETA1, ETA1_RANDOMNESS_SIZE, ETA2, ETA2_RANDOMNESS_SIZE>[TraitClause@0, TraitClause@1, TraitClause@2, TraitClause@3]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.encrypt_c1.call_mut_dd
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$4size_t]]
with const generics
- K= 4
- C1_LEN= 1408
- U_COMPRESSION_FACTOR= 11
- BLOCK_LEN= 352
- ETA1= 2
- ETA1_RANDOMNESS_SIZE= 128
- ETA2= 2
- ETA2_RANDOMNESS_SIZE= 128
*/
static Eurydice_arr_9e call_mut_dd_871(void **_)
{
  return ZERO_d6_ea();
}

/**
 Sample a vector of ring elements from a centered binomial distribution.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.sample_ring_element_cbd
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$4size_t]]
with const generics
- K= 4
- ETA2_RANDOMNESS_SIZE= 128
- ETA2= 2
*/
static KRML_MUSTINLINE uint8_t
sample_ring_element_cbd_bf1(
  const Eurydice_arr_fa *prf_input,
  uint8_t domain_separator,
  Eurydice_arr_d20 *error_1
)
{
  Eurydice_arr_890 prf_inputs;
  Eurydice_arr_fa repeat_expression[4U];
  KRML_MAYBE_FOR4(i,
    (size_t)0U,
    (size_t)4U,
    (size_t)1U,
    repeat_expression[i] =
      core_array__core__clone__Clone_for__T__N___clone((size_t)33U,
        prf_input,
        uint8_t,
        Eurydice_arr_fa););
  memcpy(prf_inputs.data, repeat_expression, (size_t)4U * sizeof (Eurydice_arr_fa));
  domain_separator = libcrux_ml_kem_utils_prf_input_inc_23(&prf_inputs, domain_separator);
  Eurydice_arr_3b0 prf_outputs = PRFxN_4a_f5(&prf_inputs);
  KRML_MAYBE_FOR4(i,
    (size_t)0U,
    (size_t)4U,
    (size_t)1U,
    size_t i0 = i;
    Eurydice_arr_9e
    uu____0 =
      sample_from_binomial_distribution_66(Eurydice_array_to_slice_shared_78(&prf_outputs.data[i0]));
    error_1->data[i0] = uu____0;);
  return domain_separator;
}

/**
A monomorphic instance of libcrux_ml_kem.hash_functions.portable.PRF
with const generics
- LEN= 128
*/
static inline Eurydice_arr_89 PRF_ec(Eurydice_borrow_slice_u8 input)
{
  Eurydice_arr_89 digest = { .data = { 0U } };
  libcrux_sha3_portable_shake256(Eurydice_array_to_slice_mut_78(&digest), input);
  return digest;
}

/**
This function found in impl {libcrux_ml_kem::hash_functions::Hash<K> for libcrux_ml_kem::hash_functions::portable::PortableHash<K>}
*/
/**
A monomorphic instance of libcrux_ml_kem.hash_functions.portable.PRF_4a
with const generics
- K= 4
- LEN= 128
*/
static inline Eurydice_arr_89 PRF_4a_f50(Eurydice_borrow_slice_u8 input)
{
  return PRF_ec(input);
}

/**
This function found in impl {core::ops::function::FnMut<(usize), libcrux_ml_kem::polynomial::PolynomialRingElement<Vector>[TraitClause@0, TraitClause@1]> for libcrux_ml_kem::matrix::compute_vector_u::closure<Vector, K>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.matrix.compute_vector_u.call_mut_a8
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 4
*/
static Eurydice_arr_9e call_mut_a8_ee(void **_)
{
  return ZERO_d6_ea();
}

/**
A monomorphic instance of libcrux_ml_kem.invert_ntt.invert_ntt_at_layer_1
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static KRML_MUSTINLINE void invert_ntt_at_layer_1_ea(size_t *zeta_i, Eurydice_arr_9e *re)
{
  KRML_MAYBE_FOR16(i,
    (size_t)0U,
    (size_t)16U,
    (size_t)1U,
    size_t round = i;
    zeta_i[0U]--;
    re->data[round] =
      libcrux_ml_kem_vector_portable_inv_ntt_layer_1_step_b8(re->data[round],
        libcrux_ml_kem_polynomial_zeta(zeta_i[0U]),
        libcrux_ml_kem_polynomial_zeta(zeta_i[0U] - (size_t)1U),
        libcrux_ml_kem_polynomial_zeta(zeta_i[0U] - (size_t)2U),
        libcrux_ml_kem_polynomial_zeta(zeta_i[0U] - (size_t)3U));
    zeta_i[0U] -= (size_t)3U;);
}

/**
A monomorphic instance of libcrux_ml_kem.invert_ntt.invert_ntt_at_layer_2
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static KRML_MUSTINLINE void invert_ntt_at_layer_2_ea(size_t *zeta_i, Eurydice_arr_9e *re)
{
  KRML_MAYBE_FOR16(i,
    (size_t)0U,
    (size_t)16U,
    (size_t)1U,
    size_t round = i;
    zeta_i[0U]--;
    re->data[round] =
      libcrux_ml_kem_vector_portable_inv_ntt_layer_2_step_b8(re->data[round],
        libcrux_ml_kem_polynomial_zeta(zeta_i[0U]),
        libcrux_ml_kem_polynomial_zeta(zeta_i[0U] - (size_t)1U));
    zeta_i[0U]--;);
}

/**
A monomorphic instance of libcrux_ml_kem.invert_ntt.invert_ntt_at_layer_3
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static KRML_MUSTINLINE void invert_ntt_at_layer_3_ea(size_t *zeta_i, Eurydice_arr_9e *re)
{
  KRML_MAYBE_FOR16(i,
    (size_t)0U,
    (size_t)16U,
    (size_t)1U,
    size_t round = i;
    zeta_i[0U]--;
    Eurydice_arr_d6
    uu____0 =
      libcrux_ml_kem_vector_portable_inv_ntt_layer_3_step_b8(re->data[round],
        libcrux_ml_kem_polynomial_zeta(zeta_i[0U]));
    re->data[round] = uu____0;);
}

/**
A monomorphic instance of libcrux_ml_kem.invert_ntt.inv_ntt_layer_int_vec_step_reduce
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static KRML_MUSTINLINE libcrux_ml_kem_vector_portable_vector_type_PortableVector_x2
inv_ntt_layer_int_vec_step_reduce_ea(Eurydice_arr_d6 a, Eurydice_arr_d6 b, int16_t zeta_r)
{
  Eurydice_arr_d6 a_minus_b = libcrux_ml_kem_vector_portable_sub_b8(b, &a);
  a =
    libcrux_ml_kem_vector_portable_barrett_reduce_b8(libcrux_ml_kem_vector_portable_add_b8(a, &b));
  b = libcrux_ml_kem_vector_portable_montgomery_multiply_by_constant_b8(a_minus_b, zeta_r);
  return
    (
      KRML_CLITERAL(libcrux_ml_kem_vector_portable_vector_type_PortableVector_x2){
        .fst = a,
        .snd = b
      }
    );
}

/**
A monomorphic instance of libcrux_ml_kem.invert_ntt.invert_ntt_at_layer_4_plus
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static KRML_MUSTINLINE void
invert_ntt_at_layer_4_plus_ea(size_t *zeta_i, Eurydice_arr_9e *re, size_t layer)
{
  size_t step = (size_t)1U << (uint32_t)layer;
  for (size_t i0 = (size_t)0U; i0 < (size_t)128U >> (uint32_t)layer; i0++)
  {
    size_t round = i0;
    zeta_i[0U]--;
    size_t offset = round * step * (size_t)2U;
    size_t offset_vec = offset / LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR;
    size_t step_vec = step / LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR;
    for (size_t i = offset_vec; i < offset_vec + step_vec; i++)
    {
      size_t j = i;
      libcrux_ml_kem_vector_portable_vector_type_PortableVector_x2
      uu____0 =
        inv_ntt_layer_int_vec_step_reduce_ea(re->data[j],
          re->data[j + step_vec],
          libcrux_ml_kem_polynomial_zeta(zeta_i[0U]));
      Eurydice_arr_d6 x = uu____0.fst;
      Eurydice_arr_d6 y = uu____0.snd;
      re->data[j] = x;
      re->data[j + step_vec] = y;
    }
  }
}

/**
A monomorphic instance of libcrux_ml_kem.invert_ntt.invert_ntt_montgomery
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 4
*/
static KRML_MUSTINLINE void invert_ntt_montgomery_ee(Eurydice_arr_9e *re)
{
  size_t zeta_i = LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT / (size_t)2U;
  invert_ntt_at_layer_1_ea(&zeta_i, re);
  invert_ntt_at_layer_2_ea(&zeta_i, re);
  invert_ntt_at_layer_3_ea(&zeta_i, re);
  invert_ntt_at_layer_4_plus_ea(&zeta_i, re, (size_t)4U);
  invert_ntt_at_layer_4_plus_ea(&zeta_i, re, (size_t)5U);
  invert_ntt_at_layer_4_plus_ea(&zeta_i, re, (size_t)6U);
  invert_ntt_at_layer_4_plus_ea(&zeta_i, re, (size_t)7U);
  poly_barrett_reduce_d6_ea(re);
}

/**
A monomorphic instance of libcrux_ml_kem.polynomial.add_error_reduce
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static KRML_MUSTINLINE void
add_error_reduce_ea(Eurydice_arr_9e *myself, const Eurydice_arr_9e *error)
{
  for (size_t i = (size_t)0U; i < LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT; i++)
  {
    size_t j = i;
    Eurydice_arr_d6
    coefficient_normal_form =
      libcrux_ml_kem_vector_portable_montgomery_multiply_by_constant_b8(myself->data[j],
        1441);
    Eurydice_arr_d6
    sum = libcrux_ml_kem_vector_portable_add_b8(coefficient_normal_form, &error->data[j]);
    Eurydice_arr_d6 red = libcrux_ml_kem_vector_portable_barrett_reduce_b8(sum);
    myself->data[j] = red;
  }
}

/**
This function found in impl {libcrux_ml_kem::polynomial::PolynomialRingElement<Vector>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.polynomial.add_error_reduce_d6
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static KRML_MUSTINLINE void
add_error_reduce_d6_ea(Eurydice_arr_9e *self, const Eurydice_arr_9e *error)
{
  add_error_reduce_ea(self, error);
}

/**
 Compute u := InvertNTT(Aᵀ ◦ r̂) + e₁
*/
/**
A monomorphic instance of libcrux_ml_kem.matrix.compute_vector_u
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 4
*/
static KRML_MUSTINLINE Eurydice_arr_d20
compute_vector_u_ee(
  const Eurydice_arr_602 *a_as_ntt,
  const Eurydice_arr_d20 *r_as_ntt,
  const Eurydice_arr_d20 *error_1
)
{
  Eurydice_arr_d20 arr_struct;
  KRML_MAYBE_FOR4(i,
    (size_t)0U,
    (size_t)4U,
    (size_t)1U,
    /* original Rust expression is not an lvalue in C */
    void *lvalue = (void *)0U;
    arr_struct.data[i] = call_mut_a8_ee(&lvalue););
  Eurydice_arr_d20 result = arr_struct;
  KRML_MAYBE_FOR4(i0,
    (size_t)0U,
    (size_t)4U,
    (size_t)1U,
    size_t i1 = i0;
    const Eurydice_arr_d20 *row = &a_as_ntt->data[i1];
    KRML_MAYBE_FOR4(i,
      (size_t)0U,
      (size_t)4U,
      (size_t)1U,
      size_t j = i;
      const Eurydice_arr_9e *a_element = &row->data[j];
      Eurydice_arr_9e product = ntt_multiply_d6_ea(a_element, &r_as_ntt->data[j]);
      add_to_ring_element_d6_ee(&result.data[i1], &product););
    invert_ntt_montgomery_ee(&result.data[i1]);
    add_error_reduce_d6_ea(&result.data[i1], &error_1->data[i1]););
  return result;
}

/**
A monomorphic instance of libcrux_ml_kem.vector.portable.compress.compress
with const generics
- COEFFICIENT_BITS= 10
*/
static KRML_MUSTINLINE Eurydice_arr_d6 compress_ef(Eurydice_arr_d6 a)
{
  for (size_t i = (size_t)0U; i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++)
  {
    size_t i0 = i;
    int16_t
    uu____0 =
      libcrux_secrets_int_as_i16_f5(libcrux_ml_kem_vector_portable_compress_compress_ciphertext_coefficient((uint8_t)10,
          libcrux_secrets_int_as_u16_f5(a.data[i0])));
    a.data[i0] = uu____0;
  }
  return a;
}

/**
This function found in impl {libcrux_ml_kem::vector::traits::Operations for libcrux_ml_kem::vector::portable::vector_type::PortableVector}
*/
/**
A monomorphic instance of libcrux_ml_kem.vector.portable.compress_b8
with const generics
- COEFFICIENT_BITS= 10
*/
static Eurydice_arr_d6 compress_b8_ef(Eurydice_arr_d6 a)
{
  return compress_ef(a);
}

/**
A monomorphic instance of libcrux_ml_kem.vector.portable.compress.compress
with const generics
- COEFFICIENT_BITS= 11
*/
static KRML_MUSTINLINE Eurydice_arr_d6 compress_c4(Eurydice_arr_d6 a)
{
  for (size_t i = (size_t)0U; i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++)
  {
    size_t i0 = i;
    int16_t
    uu____0 =
      libcrux_secrets_int_as_i16_f5(libcrux_ml_kem_vector_portable_compress_compress_ciphertext_coefficient((uint8_t)11,
          libcrux_secrets_int_as_u16_f5(a.data[i0])));
    a.data[i0] = uu____0;
  }
  return a;
}

/**
This function found in impl {libcrux_ml_kem::vector::traits::Operations for libcrux_ml_kem::vector::portable::vector_type::PortableVector}
*/
/**
A monomorphic instance of libcrux_ml_kem.vector.portable.compress_b8
with const generics
- COEFFICIENT_BITS= 11
*/
static Eurydice_arr_d6 compress_b8_c4(Eurydice_arr_d6 a)
{
  return compress_c4(a);
}

/**
A monomorphic instance of libcrux_ml_kem.serialize.compress_then_serialize_11
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- OUT_LEN= 352
*/
static KRML_MUSTINLINE Eurydice_arr_e7 compress_then_serialize_11_bd(const Eurydice_arr_9e *re)
{
  Eurydice_arr_e7 serialized = { .data = { 0U } };
  for (size_t i = (size_t)0U; i < LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT; i++)
  {
    size_t i0 = i;
    Eurydice_arr_d6
    coefficient =
      compress_b8_c4(libcrux_ml_kem_vector_portable_to_unsigned_representative_b8(re->data[i0]));
    Eurydice_arr_80 bytes = libcrux_ml_kem_vector_portable_serialize_11_b8(coefficient);
    Eurydice_slice_copy(Eurydice_array_to_subslice_mut_d422(&serialized,
        (
          KRML_CLITERAL(core_ops_range_Range_87){
            .start = (size_t)22U * i0,
            .end = (size_t)22U * i0 + (size_t)22U
          }
        )),
      Eurydice_array_to_slice_shared_980(&bytes),
      uint8_t);
  }
  return serialized;
}

/**
A monomorphic instance of libcrux_ml_kem.serialize.compress_then_serialize_ring_element_u
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- COMPRESSION_FACTOR= 11
- OUT_LEN= 352
*/
static KRML_MUSTINLINE Eurydice_arr_e7
compress_then_serialize_ring_element_u_86(const Eurydice_arr_9e *re)
{
  return compress_then_serialize_11_bd(re);
}

/**
 Call [`compress_then_serialize_ring_element_u`] on each ring element.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.compress_then_serialize_u
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 4
- OUT_LEN= 1408
- COMPRESSION_FACTOR= 11
- BLOCK_LEN= 352
*/
static KRML_MUSTINLINE void
compress_then_serialize_u_2e(Eurydice_arr_d20 input, Eurydice_mut_borrow_slice_u8 out)
{
  KRML_MAYBE_FOR4(i,
    (size_t)0U,
    (size_t)4U,
    (size_t)1U,
    size_t i0 = i;
    Eurydice_arr_9e re = input.data[i0];
    Eurydice_mut_borrow_slice_u8
    uu____0 =
      Eurydice_slice_subslice_mut_c8(out,
        (
          KRML_CLITERAL(core_ops_range_Range_87){
            .start = i0 * ((size_t)1408U / (size_t)4U),
            .end = (i0 + (size_t)1U) * ((size_t)1408U / (size_t)4U)
          }
        ));
    /* original Rust expression is not an lvalue in C */
    Eurydice_arr_e7 lvalue = compress_then_serialize_ring_element_u_86(&re);
    Eurydice_slice_copy(uu____0, Eurydice_array_to_slice_shared_25(&lvalue), uint8_t););
}

/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.encrypt_c1
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$4size_t]]
with const generics
- K= 4
- C1_LEN= 1408
- U_COMPRESSION_FACTOR= 11
- BLOCK_LEN= 352
- ETA1= 2
- ETA1_RANDOMNESS_SIZE= 128
- ETA2= 2
- ETA2_RANDOMNESS_SIZE= 128
*/
static KRML_MUSTINLINE tuple_12
encrypt_c1_871(
  Eurydice_borrow_slice_u8 randomness,
  const Eurydice_arr_602 *matrix,
  Eurydice_mut_borrow_slice_u8 ciphertext
)
{
  Eurydice_arr_fa prf_input = libcrux_ml_kem_utils_into_padded_array_29(randomness);
  Eurydice_arr_d20 arr_struct0;
  KRML_MAYBE_FOR4(i,
    (size_t)0U,
    (size_t)4U,
    (size_t)1U,
    /* original Rust expression is not an lvalue in C */
    void *lvalue = (void *)0U;
    arr_struct0.data[i] = call_mut_f1_871(&lvalue););
  Eurydice_arr_d20 r_as_ntt = arr_struct0;
  uint8_t domain_separator0 = sample_vector_cbd_then_ntt_bf1(&r_as_ntt, &prf_input, 0U);
  Eurydice_arr_d20 arr_struct;
  KRML_MAYBE_FOR4(i,
    (size_t)0U,
    (size_t)4U,
    (size_t)1U,
    /* original Rust expression is not an lvalue in C */
    void *lvalue = (void *)0U;
    arr_struct.data[i] = call_mut_dd_871(&lvalue););
  Eurydice_arr_d20 error_1 = arr_struct;
  uint8_t
  domain_separator = sample_ring_element_cbd_bf1(&prf_input, domain_separator0, &error_1);
  prf_input.data[32U] = domain_separator;
  Eurydice_arr_89 prf_output = PRF_4a_f50(Eurydice_array_to_slice_shared_b5(&prf_input));
  Eurydice_arr_9e
  error_2 = sample_from_binomial_distribution_66(Eurydice_array_to_slice_shared_78(&prf_output));
  Eurydice_arr_d20 u = compute_vector_u_ee(matrix, &r_as_ntt, &error_1);
  compress_then_serialize_u_2e(u, ciphertext);
  return (KRML_CLITERAL(tuple_12){ .fst = r_as_ntt, .snd = error_2 });
}

/**
A monomorphic instance of libcrux_ml_kem.serialize.deserialize_then_decompress_message
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static KRML_MUSTINLINE Eurydice_arr_9e
deserialize_then_decompress_message_ea(const Eurydice_arr_ec *serialized)
{
  Eurydice_arr_9e re = ZERO_d6_ea();
  KRML_MAYBE_FOR16(i,
    (size_t)0U,
    (size_t)16U,
    (size_t)1U,
    size_t i0 = i;
    Eurydice_arr_d6
    coefficient_compressed =
      libcrux_ml_kem_vector_portable_deserialize_1_b8(Eurydice_array_to_subslice_shared_d41(serialized,
          (
            KRML_CLITERAL(core_ops_range_Range_87){
              .start = (size_t)2U * i0,
              .end = (size_t)2U * i0 + (size_t)2U
            }
          )));
    Eurydice_arr_d6
    uu____0 = libcrux_ml_kem_vector_portable_decompress_1_b8(coefficient_compressed);
    re.data[i0] = uu____0;);
  return re;
}

/**
A monomorphic instance of libcrux_ml_kem.polynomial.add_message_error_reduce
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static KRML_MUSTINLINE Eurydice_arr_9e
add_message_error_reduce_ea(
  const Eurydice_arr_9e *myself,
  const Eurydice_arr_9e *message,
  Eurydice_arr_9e result
)
{
  for (size_t i = (size_t)0U; i < LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT; i++)
  {
    size_t i0 = i;
    Eurydice_arr_d6
    coefficient_normal_form =
      libcrux_ml_kem_vector_portable_montgomery_multiply_by_constant_b8(result.data[i0],
        1441);
    Eurydice_arr_d6
    sum1 = libcrux_ml_kem_vector_portable_add_b8(myself->data[i0], &message->data[i0]);
    Eurydice_arr_d6 sum2 = libcrux_ml_kem_vector_portable_add_b8(coefficient_normal_form, &sum1);
    Eurydice_arr_d6 red = libcrux_ml_kem_vector_portable_barrett_reduce_b8(sum2);
    result.data[i0] = red;
  }
  return result;
}

/**
This function found in impl {libcrux_ml_kem::polynomial::PolynomialRingElement<Vector>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.polynomial.add_message_error_reduce_d6
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static KRML_MUSTINLINE Eurydice_arr_9e
add_message_error_reduce_d6_ea(
  const Eurydice_arr_9e *self,
  const Eurydice_arr_9e *message,
  Eurydice_arr_9e result
)
{
  return add_message_error_reduce_ea(self, message, result);
}

/**
 Compute InverseNTT(tᵀ ◦ r̂) + e₂ + message
*/
/**
A monomorphic instance of libcrux_ml_kem.matrix.compute_ring_element_v
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 4
*/
static KRML_MUSTINLINE Eurydice_arr_9e
compute_ring_element_v_ee(
  const Eurydice_arr_d20 *t_as_ntt,
  const Eurydice_arr_d20 *r_as_ntt,
  const Eurydice_arr_9e *error_2,
  const Eurydice_arr_9e *message
)
{
  Eurydice_arr_9e result = ZERO_d6_ea();
  KRML_MAYBE_FOR4(i,
    (size_t)0U,
    (size_t)4U,
    (size_t)1U,
    size_t i0 = i;
    Eurydice_arr_9e product = ntt_multiply_d6_ea(&t_as_ntt->data[i0], &r_as_ntt->data[i0]);
    add_to_ring_element_d6_ee(&result, &product););
  invert_ntt_montgomery_ee(&result);
  return add_message_error_reduce_d6_ea(error_2, message, result);
}

/**
A monomorphic instance of libcrux_ml_kem.vector.portable.compress.compress
with const generics
- COEFFICIENT_BITS= 4
*/
static KRML_MUSTINLINE Eurydice_arr_d6 compress_d1(Eurydice_arr_d6 a)
{
  for (size_t i = (size_t)0U; i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++)
  {
    size_t i0 = i;
    int16_t
    uu____0 =
      libcrux_secrets_int_as_i16_f5(libcrux_ml_kem_vector_portable_compress_compress_ciphertext_coefficient((uint8_t)4,
          libcrux_secrets_int_as_u16_f5(a.data[i0])));
    a.data[i0] = uu____0;
  }
  return a;
}

/**
This function found in impl {libcrux_ml_kem::vector::traits::Operations for libcrux_ml_kem::vector::portable::vector_type::PortableVector}
*/
/**
A monomorphic instance of libcrux_ml_kem.vector.portable.compress_b8
with const generics
- COEFFICIENT_BITS= 4
*/
static Eurydice_arr_d6 compress_b8_d1(Eurydice_arr_d6 a)
{
  return compress_d1(a);
}

/**
A monomorphic instance of libcrux_ml_kem.serialize.compress_then_serialize_4
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static KRML_MUSTINLINE void
compress_then_serialize_4_ea(Eurydice_arr_9e re, Eurydice_mut_borrow_slice_u8 serialized)
{
  for (size_t i = (size_t)0U; i < LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT; i++)
  {
    size_t i0 = i;
    Eurydice_arr_d6 coefficient = compress_b8_d1(to_unsigned_field_modulus_ea(re.data[i0]));
    Eurydice_array_u8x8 bytes = libcrux_ml_kem_vector_portable_serialize_4_b8(coefficient);
    Eurydice_slice_copy(Eurydice_slice_subslice_mut_c8(serialized,
        (
          KRML_CLITERAL(core_ops_range_Range_87){
            .start = (size_t)8U * i0,
            .end = (size_t)8U * i0 + (size_t)8U
          }
        )),
      Eurydice_array_to_slice_shared_6e(&bytes),
      uint8_t);
  }
}

/**
A monomorphic instance of libcrux_ml_kem.vector.portable.compress.compress
with const generics
- COEFFICIENT_BITS= 5
*/
static KRML_MUSTINLINE Eurydice_arr_d6 compress_f4(Eurydice_arr_d6 a)
{
  for (size_t i = (size_t)0U; i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++)
  {
    size_t i0 = i;
    int16_t
    uu____0 =
      libcrux_secrets_int_as_i16_f5(libcrux_ml_kem_vector_portable_compress_compress_ciphertext_coefficient((uint8_t)5,
          libcrux_secrets_int_as_u16_f5(a.data[i0])));
    a.data[i0] = uu____0;
  }
  return a;
}

/**
This function found in impl {libcrux_ml_kem::vector::traits::Operations for libcrux_ml_kem::vector::portable::vector_type::PortableVector}
*/
/**
A monomorphic instance of libcrux_ml_kem.vector.portable.compress_b8
with const generics
- COEFFICIENT_BITS= 5
*/
static Eurydice_arr_d6 compress_b8_f4(Eurydice_arr_d6 a)
{
  return compress_f4(a);
}

/**
A monomorphic instance of libcrux_ml_kem.serialize.compress_then_serialize_5
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static KRML_MUSTINLINE void
compress_then_serialize_5_ea(Eurydice_arr_9e re, Eurydice_mut_borrow_slice_u8 serialized)
{
  for (size_t i = (size_t)0U; i < LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT; i++)
  {
    size_t i0 = i;
    Eurydice_arr_d6
    coefficients =
      compress_b8_f4(libcrux_ml_kem_vector_portable_to_unsigned_representative_b8(re.data[i0]));
    Eurydice_arr_6d bytes = libcrux_ml_kem_vector_portable_serialize_5_b8(coefficients);
    Eurydice_slice_copy(Eurydice_slice_subslice_mut_c8(serialized,
        (
          KRML_CLITERAL(core_ops_range_Range_87){
            .start = (size_t)10U * i0,
            .end = (size_t)10U * i0 + (size_t)10U
          }
        )),
      Eurydice_array_to_slice_shared_30(&bytes),
      uint8_t);
  }
}

/**
A monomorphic instance of libcrux_ml_kem.serialize.compress_then_serialize_ring_element_v
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 4
- COMPRESSION_FACTOR= 5
- OUT_LEN= 160
*/
static KRML_MUSTINLINE void
compress_then_serialize_ring_element_v_1c(Eurydice_arr_9e re, Eurydice_mut_borrow_slice_u8 out)
{
  compress_then_serialize_5_ea(re, out);
}

/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.encrypt_c2
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 4
- V_COMPRESSION_FACTOR= 5
- C2_LEN= 160
*/
static KRML_MUSTINLINE void
encrypt_c2_1c(
  const Eurydice_arr_d20 *t_as_ntt,
  const Eurydice_arr_d20 *r_as_ntt,
  const Eurydice_arr_9e *error_2,
  const Eurydice_arr_ec *message,
  Eurydice_mut_borrow_slice_u8 ciphertext
)
{
  Eurydice_arr_9e message_as_ring_element = deserialize_then_decompress_message_ea(message);
  Eurydice_arr_9e
  v = compute_ring_element_v_ee(t_as_ntt, r_as_ntt, error_2, &message_as_ring_element);
  compress_then_serialize_ring_element_v_1c(v, ciphertext);
}

/**
 This function implements <strong>Algorithm 13</strong> of the
 NIST FIPS 203 specification; this is the Kyber CPA-PKE encryption algorithm.

 Algorithm 13 is reproduced below:

 ```plaintext
 Input: encryption key ekₚₖₑ ∈ 𝔹^{384k+32}.
 Input: message m ∈ 𝔹^{32}.
 Input: encryption randomness r ∈ 𝔹^{32}.
 Output: ciphertext c ∈ 𝔹^{32(dᵤk + dᵥ)}.

 N ← 0
 t̂ ← ByteDecode₁₂(ekₚₖₑ[0:384k])
 ρ ← ekₚₖₑ[384k: 384k + 32]
 for (i ← 0; i < k; i++)
     for(j ← 0; j < k; j++)
         Â[i,j] ← SampleNTT(XOF(ρ, i, j))
     end for
 end for
 for(i ← 0; i < k; i++)
     r[i] ← SamplePolyCBD_{η₁}(PRF_{η₁}(r,N))
     N ← N + 1
 end for
 for(i ← 0; i < k; i++)
     e₁[i] ← SamplePolyCBD_{η₂}(PRF_{η₂}(r,N))
     N ← N + 1
 end for
 e₂ ← SamplePolyCBD_{η₂}(PRF_{η₂}(r,N))
 r̂ ← NTT(r)
 u ← NTT-¹(Âᵀ ◦ r̂) + e₁
 μ ← Decompress₁(ByteDecode₁(m)))
 v ← NTT-¹(t̂ᵀ ◦ rˆ) + e₂ + μ
 c₁ ← ByteEncode_{dᵤ}(Compress_{dᵤ}(u))
 c₂ ← ByteEncode_{dᵥ}(Compress_{dᵥ}(v))
 return c ← (c₁ ‖ c₂)
 ```

 The NIST FIPS 203 standard can be found at
 <https://csrc.nist.gov/pubs/fips/203/ipd>.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.encrypt_unpacked
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$4size_t]]
with const generics
- K= 4
- CIPHERTEXT_SIZE= 1568
- T_AS_NTT_ENCODED_SIZE= 1536
- C1_LEN= 1408
- C2_LEN= 160
- U_COMPRESSION_FACTOR= 11
- V_COMPRESSION_FACTOR= 5
- BLOCK_LEN= 352
- ETA1= 2
- ETA1_RANDOMNESS_SIZE= 128
- ETA2= 2
- ETA2_RANDOMNESS_SIZE= 128
*/
static KRML_MUSTINLINE Eurydice_arr_d1
encrypt_unpacked_d51(
  const libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_94 *public_key,
  const Eurydice_arr_ec *message,
  Eurydice_borrow_slice_u8 randomness
)
{
  Eurydice_arr_d1 ciphertext = { .data = { 0U } };
  tuple_12
  uu____0 =
    encrypt_c1_871(randomness,
      &public_key->A,
      Eurydice_array_to_subslice_mut_d423(&ciphertext,
        (KRML_CLITERAL(core_ops_range_Range_87){ .start = (size_t)0U, .end = (size_t)1408U })));
  Eurydice_arr_d20 r_as_ntt = uu____0.fst;
  Eurydice_arr_9e error_2 = uu____0.snd;
  encrypt_c2_1c(&public_key->t_as_ntt,
    &r_as_ntt,
    &error_2,
    message,
    Eurydice_array_to_subslice_from_mut_5f8(&ciphertext, (size_t)1408U));
  return ciphertext;
}

/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.encapsulate
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$4size_t]]
with const generics
- K= 4
- CIPHERTEXT_SIZE= 1568
- PUBLIC_KEY_SIZE= 1568
- T_AS_NTT_ENCODED_SIZE= 1536
- C1_SIZE= 1408
- C2_SIZE= 160
- VECTOR_U_COMPRESSION_FACTOR= 11
- VECTOR_V_COMPRESSION_FACTOR= 5
- VECTOR_U_BLOCK_LEN= 352
- ETA1= 2
- ETA1_RANDOMNESS_SIZE= 128
- ETA2= 2
- ETA2_RANDOMNESS_SIZE= 128
*/
tuple_25
libcrux_ml_kem_ind_cca_unpacked_encapsulate_a71(
  const libcrux_ml_kem_ind_cca_unpacked_MlKemPublicKeyUnpacked_94 *public_key,
  const Eurydice_arr_ec *randomness
)
{
  Eurydice_arr_c7
  hashed =
    encaps_prepare_fe(Eurydice_array_to_slice_shared_01(randomness),
      Eurydice_array_to_slice_shared_01(&public_key->public_key_hash));
  Eurydice_borrow_slice_u8_x2
  uu____0 =
    Eurydice_slice_split_at(Eurydice_array_to_slice_shared_17(&hashed),
      LIBCRUX_ML_KEM_CONSTANTS_SHARED_SECRET_SIZE,
      uint8_t,
      Eurydice_borrow_slice_u8_x2);
  Eurydice_borrow_slice_u8 shared_secret = uu____0.fst;
  Eurydice_borrow_slice_u8 pseudorandomness = uu____0.snd;
  Eurydice_arr_d1
  ciphertext =
    encrypt_unpacked_d51(&public_key->ind_cpa_public_key,
      randomness,
      pseudorandomness);
  Eurydice_arr_ec shared_secret_array = { .data = { 0U } };
  Eurydice_slice_copy(Eurydice_array_to_slice_mut_01(&shared_secret_array),
    shared_secret,
    uint8_t);
  return
    (
      KRML_CLITERAL(tuple_25){
        .fst = libcrux_ml_kem_types_from_19_d9(ciphertext),
        .snd = shared_secret_array
      }
    );
}

/**
This function found in impl {core::ops::function::FnMut<(usize), libcrux_ml_kem::polynomial::PolynomialRingElement<Vector>[TraitClause@0, TraitClause@1]> for libcrux_ml_kem::ind_cpa::deserialize_then_decompress_u::closure<Vector, K, CIPHERTEXT_SIZE, U_COMPRESSION_FACTOR>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.deserialize_then_decompress_u.call_mut_35
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 4
- CIPHERTEXT_SIZE= 1568
- U_COMPRESSION_FACTOR= 11
*/
static Eurydice_arr_9e call_mut_35_1c(void **_)
{
  return ZERO_d6_ea();
}

/**
A monomorphic instance of libcrux_ml_kem.vector.portable.compress.decompress_ciphertext_coefficient
with const generics
- COEFFICIENT_BITS= 10
*/
static KRML_MUSTINLINE Eurydice_arr_d6 decompress_ciphertext_coefficient_ef(Eurydice_arr_d6 a)
{
  for (size_t i = (size_t)0U; i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++)
  {
    size_t i0 = i;
    int32_t
    decompressed =
      libcrux_secrets_int_as_i32_f5(a.data[i0]) *
        libcrux_secrets_int_as_i32_f5(libcrux_secrets_int_classify_public_classify_27_39(LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS));
    decompressed = (int32_t)((uint32_t)decompressed << 1U) + (int32_t)((uint32_t)1 << (uint32_t)10);
    decompressed >>= (uint32_t)(10 + 1);
    a.data[i0] = libcrux_secrets_int_as_i16_36(decompressed);
  }
  return a;
}

/**
This function found in impl {libcrux_ml_kem::vector::traits::Operations for libcrux_ml_kem::vector::portable::vector_type::PortableVector}
*/
/**
A monomorphic instance of libcrux_ml_kem.vector.portable.decompress_ciphertext_coefficient_b8
with const generics
- COEFFICIENT_BITS= 10
*/
static Eurydice_arr_d6 decompress_ciphertext_coefficient_b8_ef(Eurydice_arr_d6 a)
{
  return decompress_ciphertext_coefficient_ef(a);
}

/**
A monomorphic instance of libcrux_ml_kem.serialize.deserialize_then_decompress_10
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static KRML_MUSTINLINE Eurydice_arr_9e
deserialize_then_decompress_10_ea(Eurydice_borrow_slice_u8 serialized)
{
  Eurydice_arr_9e re = ZERO_d6_ea();
  for (size_t i = (size_t)0U; i < serialized.meta / (size_t)20U; i++)
  {
    size_t i0 = i;
    Eurydice_borrow_slice_u8
    bytes =
      Eurydice_slice_subslice_shared_c8(serialized,
        (
          KRML_CLITERAL(core_ops_range_Range_87){
            .start = i0 * (size_t)20U,
            .end = i0 * (size_t)20U + (size_t)20U
          }
        ));
    Eurydice_arr_d6 coefficient = libcrux_ml_kem_vector_portable_deserialize_10_b8(bytes);
    Eurydice_arr_d6 uu____0 = decompress_ciphertext_coefficient_b8_ef(coefficient);
    re.data[i0] = uu____0;
  }
  return re;
}

/**
A monomorphic instance of libcrux_ml_kem.vector.portable.compress.decompress_ciphertext_coefficient
with const generics
- COEFFICIENT_BITS= 11
*/
static KRML_MUSTINLINE Eurydice_arr_d6 decompress_ciphertext_coefficient_c4(Eurydice_arr_d6 a)
{
  for (size_t i = (size_t)0U; i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++)
  {
    size_t i0 = i;
    int32_t
    decompressed =
      libcrux_secrets_int_as_i32_f5(a.data[i0]) *
        libcrux_secrets_int_as_i32_f5(libcrux_secrets_int_classify_public_classify_27_39(LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS));
    decompressed = (int32_t)((uint32_t)decompressed << 1U) + (int32_t)((uint32_t)1 << (uint32_t)11);
    decompressed >>= (uint32_t)(11 + 1);
    a.data[i0] = libcrux_secrets_int_as_i16_36(decompressed);
  }
  return a;
}

/**
This function found in impl {libcrux_ml_kem::vector::traits::Operations for libcrux_ml_kem::vector::portable::vector_type::PortableVector}
*/
/**
A monomorphic instance of libcrux_ml_kem.vector.portable.decompress_ciphertext_coefficient_b8
with const generics
- COEFFICIENT_BITS= 11
*/
static Eurydice_arr_d6 decompress_ciphertext_coefficient_b8_c4(Eurydice_arr_d6 a)
{
  return decompress_ciphertext_coefficient_c4(a);
}

/**
A monomorphic instance of libcrux_ml_kem.serialize.deserialize_then_decompress_11
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static KRML_MUSTINLINE Eurydice_arr_9e
deserialize_then_decompress_11_ea(Eurydice_borrow_slice_u8 serialized)
{
  Eurydice_arr_9e re = ZERO_d6_ea();
  for (size_t i = (size_t)0U; i < serialized.meta / (size_t)22U; i++)
  {
    size_t i0 = i;
    Eurydice_borrow_slice_u8
    bytes =
      Eurydice_slice_subslice_shared_c8(serialized,
        (
          KRML_CLITERAL(core_ops_range_Range_87){
            .start = i0 * (size_t)22U,
            .end = i0 * (size_t)22U + (size_t)22U
          }
        ));
    Eurydice_arr_d6 coefficient = libcrux_ml_kem_vector_portable_deserialize_11_b8(bytes);
    Eurydice_arr_d6 uu____0 = decompress_ciphertext_coefficient_b8_c4(coefficient);
    re.data[i0] = uu____0;
  }
  return re;
}

/**
A monomorphic instance of libcrux_ml_kem.serialize.deserialize_then_decompress_ring_element_u
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- COMPRESSION_FACTOR= 11
*/
static KRML_MUSTINLINE Eurydice_arr_9e
deserialize_then_decompress_ring_element_u_ee(Eurydice_borrow_slice_u8 serialized)
{
  return deserialize_then_decompress_11_ea(serialized);
}

/**
A monomorphic instance of libcrux_ml_kem.ntt.ntt_vector_u
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- VECTOR_U_COMPRESSION_FACTOR= 11
*/
static KRML_MUSTINLINE void ntt_vector_u_ee(Eurydice_arr_9e *re)
{
  size_t zeta_i = (size_t)0U;
  ntt_at_layer_4_plus_ea(&zeta_i, re, (size_t)7U);
  ntt_at_layer_4_plus_ea(&zeta_i, re, (size_t)6U);
  ntt_at_layer_4_plus_ea(&zeta_i, re, (size_t)5U);
  ntt_at_layer_4_plus_ea(&zeta_i, re, (size_t)4U);
  ntt_at_layer_3_ea(&zeta_i, re);
  ntt_at_layer_2_ea(&zeta_i, re);
  ntt_at_layer_1_ea(&zeta_i, re);
  poly_barrett_reduce_d6_ea(re);
}

/**
 Call [`deserialize_then_decompress_ring_element_u`] on each ring element
 in the `ciphertext`.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.deserialize_then_decompress_u
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 4
- CIPHERTEXT_SIZE= 1568
- U_COMPRESSION_FACTOR= 11
*/
static KRML_MUSTINLINE Eurydice_arr_d20
deserialize_then_decompress_u_1c(const Eurydice_arr_d1 *ciphertext)
{
  Eurydice_arr_d20 arr_struct;
  KRML_MAYBE_FOR4(i,
    (size_t)0U,
    (size_t)4U,
    (size_t)1U,
    /* original Rust expression is not an lvalue in C */
    void *lvalue = (void *)0U;
    arr_struct.data[i] = call_mut_35_1c(&lvalue););
  Eurydice_arr_d20 u_as_ntt = arr_struct;
  for
  (size_t
    i = (size_t)0U;
    i <
      (size_t)1568U /
        (LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT * (size_t)11U / (size_t)8U);
    i++)
  {
    size_t i0 = i;
    Eurydice_borrow_slice_u8
    u_bytes =
      Eurydice_array_to_subslice_shared_d411(ciphertext,
        (
          KRML_CLITERAL(core_ops_range_Range_87){
            .start = i0 *
              (LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT * (size_t)11U / (size_t)8U),
            .end = i0 *
              (LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT * (size_t)11U / (size_t)8U)
            + LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT * (size_t)11U / (size_t)8U
          }
        ));
    u_as_ntt.data[i0] = deserialize_then_decompress_ring_element_u_ee(u_bytes);
    ntt_vector_u_ee(&u_as_ntt.data[i0]);
  }
  return u_as_ntt;
}

/**
A monomorphic instance of libcrux_ml_kem.vector.portable.compress.decompress_ciphertext_coefficient
with const generics
- COEFFICIENT_BITS= 4
*/
static KRML_MUSTINLINE Eurydice_arr_d6 decompress_ciphertext_coefficient_d1(Eurydice_arr_d6 a)
{
  for (size_t i = (size_t)0U; i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++)
  {
    size_t i0 = i;
    int32_t
    decompressed =
      libcrux_secrets_int_as_i32_f5(a.data[i0]) *
        libcrux_secrets_int_as_i32_f5(libcrux_secrets_int_classify_public_classify_27_39(LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS));
    decompressed = (int32_t)((uint32_t)decompressed << 1U) + (int32_t)((uint32_t)1 << (uint32_t)4);
    decompressed >>= (uint32_t)(4 + 1);
    a.data[i0] = libcrux_secrets_int_as_i16_36(decompressed);
  }
  return a;
}

/**
This function found in impl {libcrux_ml_kem::vector::traits::Operations for libcrux_ml_kem::vector::portable::vector_type::PortableVector}
*/
/**
A monomorphic instance of libcrux_ml_kem.vector.portable.decompress_ciphertext_coefficient_b8
with const generics
- COEFFICIENT_BITS= 4
*/
static Eurydice_arr_d6 decompress_ciphertext_coefficient_b8_d1(Eurydice_arr_d6 a)
{
  return decompress_ciphertext_coefficient_d1(a);
}

/**
A monomorphic instance of libcrux_ml_kem.serialize.deserialize_then_decompress_4
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static KRML_MUSTINLINE Eurydice_arr_9e
deserialize_then_decompress_4_ea(Eurydice_borrow_slice_u8 serialized)
{
  Eurydice_arr_9e re = ZERO_d6_ea();
  for (size_t i = (size_t)0U; i < serialized.meta / (size_t)8U; i++)
  {
    size_t i0 = i;
    Eurydice_borrow_slice_u8
    bytes =
      Eurydice_slice_subslice_shared_c8(serialized,
        (
          KRML_CLITERAL(core_ops_range_Range_87){
            .start = i0 * (size_t)8U,
            .end = i0 * (size_t)8U + (size_t)8U
          }
        ));
    Eurydice_arr_d6 coefficient = libcrux_ml_kem_vector_portable_deserialize_4_b8(bytes);
    Eurydice_arr_d6 uu____0 = decompress_ciphertext_coefficient_b8_d1(coefficient);
    re.data[i0] = uu____0;
  }
  return re;
}

/**
A monomorphic instance of libcrux_ml_kem.vector.portable.compress.decompress_ciphertext_coefficient
with const generics
- COEFFICIENT_BITS= 5
*/
static KRML_MUSTINLINE Eurydice_arr_d6 decompress_ciphertext_coefficient_f4(Eurydice_arr_d6 a)
{
  for (size_t i = (size_t)0U; i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++)
  {
    size_t i0 = i;
    int32_t
    decompressed =
      libcrux_secrets_int_as_i32_f5(a.data[i0]) *
        libcrux_secrets_int_as_i32_f5(libcrux_secrets_int_classify_public_classify_27_39(LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS));
    decompressed = (int32_t)((uint32_t)decompressed << 1U) + (int32_t)((uint32_t)1 << (uint32_t)5);
    decompressed >>= (uint32_t)(5 + 1);
    a.data[i0] = libcrux_secrets_int_as_i16_36(decompressed);
  }
  return a;
}

/**
This function found in impl {libcrux_ml_kem::vector::traits::Operations for libcrux_ml_kem::vector::portable::vector_type::PortableVector}
*/
/**
A monomorphic instance of libcrux_ml_kem.vector.portable.decompress_ciphertext_coefficient_b8
with const generics
- COEFFICIENT_BITS= 5
*/
static Eurydice_arr_d6 decompress_ciphertext_coefficient_b8_f4(Eurydice_arr_d6 a)
{
  return decompress_ciphertext_coefficient_f4(a);
}

/**
A monomorphic instance of libcrux_ml_kem.serialize.deserialize_then_decompress_5
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static KRML_MUSTINLINE Eurydice_arr_9e
deserialize_then_decompress_5_ea(Eurydice_borrow_slice_u8 serialized)
{
  Eurydice_arr_9e re = ZERO_d6_ea();
  for (size_t i = (size_t)0U; i < serialized.meta / (size_t)10U; i++)
  {
    size_t i0 = i;
    Eurydice_borrow_slice_u8
    bytes =
      Eurydice_slice_subslice_shared_c8(serialized,
        (
          KRML_CLITERAL(core_ops_range_Range_87){
            .start = i0 * (size_t)10U,
            .end = i0 * (size_t)10U + (size_t)10U
          }
        ));
    re.data[i0] = libcrux_ml_kem_vector_portable_deserialize_5_b8(bytes);
    Eurydice_arr_d6 uu____1 = decompress_ciphertext_coefficient_b8_f4(re.data[i0]);
    re.data[i0] = uu____1;
  }
  return re;
}

/**
A monomorphic instance of libcrux_ml_kem.serialize.deserialize_then_decompress_ring_element_v
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 4
- COMPRESSION_FACTOR= 5
*/
static KRML_MUSTINLINE Eurydice_arr_9e
deserialize_then_decompress_ring_element_v_1c(Eurydice_borrow_slice_u8 serialized)
{
  return deserialize_then_decompress_5_ea(serialized);
}

/**
A monomorphic instance of libcrux_ml_kem.polynomial.subtract_reduce
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static KRML_MUSTINLINE Eurydice_arr_9e
subtract_reduce_ea(const Eurydice_arr_9e *myself, Eurydice_arr_9e b)
{
  for (size_t i = (size_t)0U; i < LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT; i++)
  {
    size_t i0 = i;
    Eurydice_arr_d6
    coefficient_normal_form =
      libcrux_ml_kem_vector_portable_montgomery_multiply_by_constant_b8(b.data[i0],
        1441);
    Eurydice_arr_d6
    diff = libcrux_ml_kem_vector_portable_sub_b8(myself->data[i0], &coefficient_normal_form);
    Eurydice_arr_d6 red = libcrux_ml_kem_vector_portable_barrett_reduce_b8(diff);
    b.data[i0] = red;
  }
  return b;
}

/**
This function found in impl {libcrux_ml_kem::polynomial::PolynomialRingElement<Vector>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.polynomial.subtract_reduce_d6
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static KRML_MUSTINLINE Eurydice_arr_9e
subtract_reduce_d6_ea(const Eurydice_arr_9e *self, Eurydice_arr_9e b)
{
  return subtract_reduce_ea(self, b);
}

/**
 The following functions compute various expressions involving
 vectors and matrices. The computation of these expressions has been
 abstracted away into these functions in order to save on loop iterations.
 Compute v − InverseNTT(sᵀ ◦ NTT(u))
*/
/**
A monomorphic instance of libcrux_ml_kem.matrix.compute_message
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 4
*/
static KRML_MUSTINLINE Eurydice_arr_9e
compute_message_ee(
  const Eurydice_arr_9e *v,
  const Eurydice_arr_d20 *secret_as_ntt,
  const Eurydice_arr_d20 *u_as_ntt
)
{
  Eurydice_arr_9e result = ZERO_d6_ea();
  KRML_MAYBE_FOR4(i,
    (size_t)0U,
    (size_t)4U,
    (size_t)1U,
    size_t i0 = i;
    Eurydice_arr_9e product = ntt_multiply_d6_ea(&secret_as_ntt->data[i0], &u_as_ntt->data[i0]);
    add_to_ring_element_d6_ee(&result, &product););
  invert_ntt_montgomery_ee(&result);
  return subtract_reduce_d6_ea(v, result);
}

/**
A monomorphic instance of libcrux_ml_kem.serialize.compress_then_serialize_message
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics

*/
static KRML_MUSTINLINE Eurydice_arr_ec compress_then_serialize_message_ea(Eurydice_arr_9e re)
{
  Eurydice_arr_ec serialized = { .data = { 0U } };
  KRML_MAYBE_FOR16(i,
    (size_t)0U,
    (size_t)16U,
    (size_t)1U,
    size_t i0 = i;
    Eurydice_arr_d6 coefficient = to_unsigned_field_modulus_ea(re.data[i0]);
    Eurydice_arr_d6
    coefficient_compressed = libcrux_ml_kem_vector_portable_compress_1_b8(coefficient);
    Eurydice_array_u8x2
    bytes = libcrux_ml_kem_vector_portable_serialize_1_b8(coefficient_compressed);
    Eurydice_slice_copy(Eurydice_array_to_subslice_mut_d44(&serialized,
        (
          KRML_CLITERAL(core_ops_range_Range_87){
            .start = (size_t)2U * i0,
            .end = (size_t)2U * i0 + (size_t)2U
          }
        )),
      Eurydice_array_to_slice_shared_82(&bytes),
      uint8_t););
  return serialized;
}

/**
 This function implements <strong>Algorithm 14</strong> of the
 NIST FIPS 203 specification; this is the Kyber CPA-PKE decryption algorithm.

 Algorithm 14 is reproduced below:

 ```plaintext
 Input: decryption key dkₚₖₑ ∈ 𝔹^{384k}.
 Input: ciphertext c ∈ 𝔹^{32(dᵤk + dᵥ)}.
 Output: message m ∈ 𝔹^{32}.

 c₁ ← c[0 : 32dᵤk]
 c₂ ← c[32dᵤk : 32(dᵤk + dᵥ)]
 u ← Decompress_{dᵤ}(ByteDecode_{dᵤ}(c₁))
 v ← Decompress_{dᵥ}(ByteDecode_{dᵥ}(c₂))
 ŝ ← ByteDecode₁₂(dkₚₖₑ)
 w ← v - NTT-¹(ŝᵀ ◦ NTT(u))
 m ← ByteEncode₁(Compress₁(w))
 return m
 ```

 The NIST FIPS 203 standard can be found at
 <https://csrc.nist.gov/pubs/fips/203/ipd>.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.decrypt_unpacked
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 4
- CIPHERTEXT_SIZE= 1568
- VECTOR_U_ENCODED_SIZE= 1408
- U_COMPRESSION_FACTOR= 11
- V_COMPRESSION_FACTOR= 5
*/
static KRML_MUSTINLINE Eurydice_arr_ec
decrypt_unpacked_38(const Eurydice_arr_d20 *secret_key, const Eurydice_arr_d1 *ciphertext)
{
  Eurydice_arr_d20 u_as_ntt = deserialize_then_decompress_u_1c(ciphertext);
  Eurydice_arr_9e
  v =
    deserialize_then_decompress_ring_element_v_1c(Eurydice_array_to_subslice_from_shared_5f5(ciphertext,
        (size_t)1408U));
  Eurydice_arr_9e message = compute_message_ee(&v, secret_key, &u_as_ntt);
  return compress_then_serialize_message_ea(message);
}

/**
A monomorphic instance of libcrux_ml_kem.hash_functions.portable.PRF
with const generics
- LEN= 32
*/
static inline Eurydice_arr_ec PRF_ce(Eurydice_borrow_slice_u8 input)
{
  Eurydice_arr_ec digest = { .data = { 0U } };
  libcrux_sha3_portable_shake256(Eurydice_array_to_slice_mut_01(&digest), input);
  return digest;
}

/**
This function found in impl {libcrux_ml_kem::hash_functions::Hash<K> for libcrux_ml_kem::hash_functions::portable::PortableHash<K>}
*/
/**
A monomorphic instance of libcrux_ml_kem.hash_functions.portable.PRF_4a
with const generics
- K= 4
- LEN= 32
*/
static inline Eurydice_arr_ec PRF_4a_f5(Eurydice_borrow_slice_u8 input)
{
  return PRF_ce(input);
}

/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.decapsulate
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$4size_t]]
with const generics
- K= 4
- SECRET_KEY_SIZE= 3168
- CPA_SECRET_KEY_SIZE= 1536
- PUBLIC_KEY_SIZE= 1568
- CIPHERTEXT_SIZE= 1568
- T_AS_NTT_ENCODED_SIZE= 1536
- C1_SIZE= 1408
- C2_SIZE= 160
- VECTOR_U_COMPRESSION_FACTOR= 11
- VECTOR_V_COMPRESSION_FACTOR= 5
- C1_BLOCK_SIZE= 352
- ETA1= 2
- ETA1_RANDOMNESS_SIZE= 128
- ETA2= 2
- ETA2_RANDOMNESS_SIZE= 128
- IMPLICIT_REJECTION_HASH_INPUT_SIZE= 1600
*/
Eurydice_arr_ec
libcrux_ml_kem_ind_cca_unpacked_decapsulate_0c1(
  const libcrux_ml_kem_mlkem1024_portable_unpacked_MlKem1024KeyPairUnpacked *key_pair,
  const Eurydice_arr_d1 *ciphertext
)
{
  Eurydice_arr_ec
  decrypted = decrypt_unpacked_38(&key_pair->private_key.ind_cpa_private_key, ciphertext);
  Eurydice_arr_c7
  to_hash0 =
    libcrux_ml_kem_utils_into_padded_array_c9(Eurydice_array_to_slice_shared_01(&decrypted));
  Eurydice_mut_borrow_slice_u8
  uu____0 =
    Eurydice_array_to_subslice_from_mut_5f1(&to_hash0,
      LIBCRUX_ML_KEM_CONSTANTS_SHARED_SECRET_SIZE);
  Eurydice_slice_copy(uu____0,
    Eurydice_array_to_slice_shared_01(&key_pair->public_key.public_key_hash),
    uint8_t);
  Eurydice_arr_c7 hashed = G_4a_23(Eurydice_array_to_slice_shared_17(&to_hash0));
  Eurydice_borrow_slice_u8_x2
  uu____1 =
    Eurydice_slice_split_at(Eurydice_array_to_slice_shared_17(&hashed),
      LIBCRUX_ML_KEM_CONSTANTS_SHARED_SECRET_SIZE,
      uint8_t,
      Eurydice_borrow_slice_u8_x2);
  Eurydice_borrow_slice_u8 shared_secret = uu____1.fst;
  Eurydice_borrow_slice_u8 pseudorandomness = uu____1.snd;
  Eurydice_arr_14
  to_hash =
    libcrux_ml_kem_utils_into_padded_array_49(Eurydice_array_to_slice_shared_01(&key_pair->private_key.implicit_rejection_value));
  Eurydice_mut_borrow_slice_u8
  uu____2 =
    Eurydice_array_to_subslice_from_mut_5f7(&to_hash,
      LIBCRUX_ML_KEM_CONSTANTS_SHARED_SECRET_SIZE);
  Eurydice_slice_copy(uu____2, libcrux_ml_kem_types_as_ref_c1_d9(ciphertext), uint8_t);
  Eurydice_arr_ec
  implicit_rejection_shared_secret = PRF_4a_f5(Eurydice_array_to_slice_shared_720(&to_hash));
  Eurydice_arr_d1
  expected_ciphertext =
    encrypt_unpacked_d51(&key_pair->public_key.ind_cpa_public_key,
      &decrypted,
      pseudorandomness);
  Eurydice_borrow_slice_u8 uu____3 = libcrux_ml_kem_types_as_ref_c1_d9(ciphertext);
  uint8_t
  selector =
    libcrux_ml_kem_constant_time_ops_compare_ciphertexts_in_constant_time(uu____3,
      Eurydice_array_to_slice_shared_b50(&expected_ciphertext));
  return
    libcrux_ml_kem_constant_time_ops_select_shared_secret_in_constant_time(shared_secret,
      Eurydice_array_to_slice_shared_01(&implicit_rejection_shared_secret),
      selector);
}

/**
This function found in impl {core::ops::function::FnMut<(usize), libcrux_ml_kem::polynomial::PolynomialRingElement<Vector>[TraitClause@0, TraitClause@1]> for libcrux_ml_kem::serialize::deserialize_ring_elements_reduced_out::closure<Vector, K>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.serialize.deserialize_ring_elements_reduced_out.call_mut_0b
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 4
*/
static Eurydice_arr_9e call_mut_0b_ee(void **_)
{
  return ZERO_d6_ea();
}

/**
 This function deserializes ring elements and reduces the result by the field
 modulus.

 This function MUST NOT be used on secret inputs.
*/
/**
A monomorphic instance of libcrux_ml_kem.serialize.deserialize_ring_elements_reduced_out
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 4
*/
static KRML_MUSTINLINE Eurydice_arr_d20
deserialize_ring_elements_reduced_out_ee(Eurydice_borrow_slice_u8 public_key)
{
  Eurydice_arr_d20 arr_struct;
  KRML_MAYBE_FOR4(i,
    (size_t)0U,
    (size_t)4U,
    (size_t)1U,
    /* original Rust expression is not an lvalue in C */
    void *lvalue = (void *)0U;
    arr_struct.data[i] = call_mut_0b_ee(&lvalue););
  Eurydice_arr_d20 deserialized_pk = arr_struct;
  deserialize_ring_elements_reduced_ee(public_key, &deserialized_pk);
  return deserialized_pk;
}

/**
 Validate an ML-KEM public key.

 This implements the Modulus check in 7.2 2.
 Note that the size check in 7.2 1 is covered by the `PUBLIC_KEY_SIZE` in the
 `public_key` type.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.validate_public_key
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 4
- PUBLIC_KEY_SIZE= 1568
*/
bool libcrux_ml_kem_ind_cca_validate_public_key_1c(const Eurydice_arr_d1 *public_key)
{
  Eurydice_arr_d20
  deserialized_pk =
    deserialize_ring_elements_reduced_out_ee(Eurydice_array_to_subslice_to_shared_214(public_key,
        libcrux_ml_kem_constants_ranked_bytes_per_ring_element((size_t)4U)));
  Eurydice_arr_d1
  public_key_serialized =
    serialize_public_key_1c(&deserialized_pk,
      Eurydice_array_to_subslice_from_shared_5f5(public_key,
        libcrux_ml_kem_constants_ranked_bytes_per_ring_element((size_t)4U)));
  return Eurydice_array_eq((size_t)1568U, public_key, &public_key_serialized, uint8_t);
}

/**
 Validate an ML-KEM private key.

 This implements the Hash check in 7.3 3.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.validate_private_key_only
with types libcrux_ml_kem_hash_functions_portable_PortableHash[[$4size_t]]
with const generics
- K= 4
- SECRET_KEY_SIZE= 3168
*/
bool libcrux_ml_kem_ind_cca_validate_private_key_only_4c(const Eurydice_arr_a8 *private_key)
{
  Eurydice_arr_ec
  t =
    H_4a_23(Eurydice_array_to_subslice_shared_d412(private_key,
        (
          KRML_CLITERAL(core_ops_range_Range_87){
            .start = (size_t)384U * (size_t)4U,
            .end = (size_t)768U * (size_t)4U + (size_t)32U
          }
        )));
  Eurydice_borrow_slice_u8
  expected =
    Eurydice_array_to_subslice_shared_d412(private_key,
      (
        KRML_CLITERAL(core_ops_range_Range_87){
          .start = (size_t)768U * (size_t)4U + (size_t)32U,
          .end = (size_t)768U * (size_t)4U + (size_t)64U
        }
      ));
  return Eurydice_array_eq_slice_shared((size_t)32U, &t, &expected, uint8_t, bool);
}

/**
 Validate an ML-KEM private key.

 This implements the Hash check in 7.3 3.
 Note that the size checks in 7.2 1 and 2 are covered by the `SECRET_KEY_SIZE`
 and `CIPHERTEXT_SIZE` in the `private_key` and `ciphertext` types.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.validate_private_key
with types libcrux_ml_kem_hash_functions_portable_PortableHash[[$4size_t]]
with const generics
- K= 4
- SECRET_KEY_SIZE= 3168
- CIPHERTEXT_SIZE= 1568
*/
bool
libcrux_ml_kem_ind_cca_validate_private_key_79(
  const Eurydice_arr_a8 *private_key,
  const Eurydice_arr_d1 *_ciphertext
)
{
  return libcrux_ml_kem_ind_cca_validate_private_key_only_4c(private_key);
}

/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.generate_keypair
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$4size_t]], libcrux_ml_kem_variant_MlKem
with const generics
- K= 4
- PRIVATE_KEY_SIZE= 1536
- PUBLIC_KEY_SIZE= 1568
- ETA1= 2
- ETA1_RANDOMNESS_SIZE= 128
*/
static KRML_MUSTINLINE libcrux_ml_kem_utils_extraction_helper_Keypair1024
generate_keypair_301(Eurydice_borrow_slice_u8 key_generation_seed)
{
  Eurydice_arr_d20 private_key = default_70_ee();
  libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_94 public_key = default_8b_ee();
  generate_keypair_unpacked_391(key_generation_seed, &private_key, &public_key);
  return serialize_unpacked_secret_key_1c(&public_key, &private_key);
}

/**
A monomorphic instance of libcrux_ml_kem.ind_cca.serialize_kem_secret_key
with types libcrux_ml_kem_hash_functions_portable_PortableHash[[$4size_t]]
with const generics
- K= 4
- SERIALIZED_KEY_LEN= 3168
*/
static KRML_MUSTINLINE Eurydice_arr_a8
serialize_kem_secret_key_4c(
  Eurydice_borrow_slice_u8 private_key,
  Eurydice_borrow_slice_u8 public_key,
  Eurydice_borrow_slice_u8 implicit_rejection_value
)
{
  Eurydice_arr_a8 out = { .data = { 0U } };
  libcrux_ml_kem_ind_cca_serialize_kem_secret_key_mut_4c(private_key,
    public_key,
    implicit_rejection_value,
    &out);
  return out;
}

/**
 Packed API

 Generate a key pair.

 Depending on the `Vector` and `Hasher` used, this requires different hardware
 features
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.generate_keypair
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$4size_t]], libcrux_ml_kem_variant_MlKem
with const generics
- K= 4
- CPA_PRIVATE_KEY_SIZE= 1536
- PRIVATE_KEY_SIZE= 3168
- PUBLIC_KEY_SIZE= 1568
- ETA1= 2
- ETA1_RANDOMNESS_SIZE= 128
*/
libcrux_ml_kem_mlkem1024_MlKem1024KeyPair
libcrux_ml_kem_ind_cca_generate_keypair_b81(const Eurydice_arr_c7 *randomness)
{
  Eurydice_borrow_slice_u8
  ind_cpa_keypair_randomness =
    Eurydice_array_to_subslice_shared_d47(randomness,
      (
        KRML_CLITERAL(core_ops_range_Range_87){
          .start = (size_t)0U,
          .end = LIBCRUX_ML_KEM_CONSTANTS_CPA_PKE_KEY_GENERATION_SEED_SIZE
        }
      ));
  Eurydice_borrow_slice_u8
  implicit_rejection_value =
    Eurydice_array_to_subslice_from_shared_5f1(randomness,
      LIBCRUX_ML_KEM_CONSTANTS_CPA_PKE_KEY_GENERATION_SEED_SIZE);
  libcrux_ml_kem_utils_extraction_helper_Keypair1024
  uu____0 = generate_keypair_301(ind_cpa_keypair_randomness);
  Eurydice_arr_df ind_cpa_private_key = uu____0.fst;
  Eurydice_arr_d1 public_key = uu____0.snd;
  Eurydice_arr_a8
  secret_key_serialized =
    serialize_kem_secret_key_4c(Eurydice_array_to_slice_shared_2f0(&ind_cpa_private_key),
      Eurydice_array_to_slice_shared_b50(&public_key),
      implicit_rejection_value);
  Eurydice_arr_a8 private_key = libcrux_ml_kem_types_from_b2_0e(secret_key_serialized);
  return
    libcrux_ml_kem_types_from_17_70(private_key,
      libcrux_ml_kem_types_from_51_d9(public_key));
}

/**
This function found in impl {libcrux_ml_kem::variant::Variant for libcrux_ml_kem::variant::MlKem}
*/
/**
A monomorphic instance of libcrux_ml_kem.variant.entropy_preprocess_39
with types libcrux_ml_kem_hash_functions_portable_PortableHash[[$4size_t]]
with const generics
- K= 4
*/
static KRML_MUSTINLINE Eurydice_arr_ec
entropy_preprocess_39_fe(Eurydice_borrow_slice_u8 randomness)
{
  Eurydice_arr_ec out = { .data = { 0U } };
  Eurydice_slice_copy(Eurydice_array_to_slice_mut_01(&out), randomness, uint8_t);
  return out;
}

/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.build_unpacked_public_key
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$4size_t]]
with const generics
- K= 4
- T_AS_NTT_ENCODED_SIZE= 1536
*/
static KRML_MUSTINLINE libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_94
build_unpacked_public_key_051(Eurydice_borrow_slice_u8 public_key)
{
  libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_94
  unpacked_public_key = default_8b_ee();
  build_unpacked_public_key_mut_051(public_key, &unpacked_public_key);
  return unpacked_public_key;
}

/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.encrypt
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$4size_t]]
with const generics
- K= 4
- CIPHERTEXT_SIZE= 1568
- T_AS_NTT_ENCODED_SIZE= 1536
- C1_LEN= 1408
- C2_LEN= 160
- U_COMPRESSION_FACTOR= 11
- V_COMPRESSION_FACTOR= 5
- BLOCK_LEN= 352
- ETA1= 2
- ETA1_RANDOMNESS_SIZE= 128
- ETA2= 2
- ETA2_RANDOMNESS_SIZE= 128
*/
static KRML_MUSTINLINE Eurydice_arr_d1
encrypt_d51(
  Eurydice_borrow_slice_u8 public_key,
  const Eurydice_arr_ec *message,
  Eurydice_borrow_slice_u8 randomness
)
{
  libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_94
  unpacked_public_key = build_unpacked_public_key_051(public_key);
  return encrypt_unpacked_d51(&unpacked_public_key, message, randomness);
}

/**
This function found in impl {libcrux_ml_kem::variant::Variant for libcrux_ml_kem::variant::MlKem}
*/
/**
A monomorphic instance of libcrux_ml_kem.variant.kdf_39
with types libcrux_ml_kem_hash_functions_portable_PortableHash[[$4size_t]]
with const generics
- K= 4
- CIPHERTEXT_SIZE= 1568
*/
static KRML_MUSTINLINE Eurydice_arr_ec kdf_39_4c(Eurydice_borrow_slice_u8 shared_secret)
{
  Eurydice_arr_ec out = { .data = { 0U } };
  Eurydice_slice_copy(Eurydice_array_to_slice_mut_01(&out), shared_secret, uint8_t);
  return out;
}

/**
A monomorphic instance of libcrux_ml_kem.ind_cca.encapsulate
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$4size_t]], libcrux_ml_kem_variant_MlKem
with const generics
- K= 4
- CIPHERTEXT_SIZE= 1568
- PUBLIC_KEY_SIZE= 1568
- T_AS_NTT_ENCODED_SIZE= 1536
- C1_SIZE= 1408
- C2_SIZE= 160
- VECTOR_U_COMPRESSION_FACTOR= 11
- VECTOR_V_COMPRESSION_FACTOR= 5
- C1_BLOCK_SIZE= 352
- ETA1= 2
- ETA1_RANDOMNESS_SIZE= 128
- ETA2= 2
- ETA2_RANDOMNESS_SIZE= 128
*/
tuple_25
libcrux_ml_kem_ind_cca_encapsulate_991(
  const Eurydice_arr_d1 *public_key,
  const Eurydice_arr_ec *randomness
)
{
  Eurydice_arr_ec
  randomness0 = entropy_preprocess_39_fe(Eurydice_array_to_slice_shared_01(randomness));
  Eurydice_arr_c7
  to_hash =
    libcrux_ml_kem_utils_into_padded_array_c9(Eurydice_array_to_slice_shared_01(&randomness0));
  Eurydice_mut_borrow_slice_u8
  uu____0 =
    Eurydice_array_to_subslice_from_mut_5f1(&to_hash,
      LIBCRUX_ML_KEM_CONSTANTS_H_DIGEST_SIZE);
  /* original Rust expression is not an lvalue in C */
  Eurydice_arr_ec
  lvalue =
    H_4a_23(Eurydice_array_to_slice_shared_b50(libcrux_ml_kem_types_as_slice_e6_d9(public_key)));
  Eurydice_slice_copy(uu____0, Eurydice_array_to_slice_shared_01(&lvalue), uint8_t);
  Eurydice_arr_c7 hashed = G_4a_23(Eurydice_array_to_slice_shared_17(&to_hash));
  Eurydice_borrow_slice_u8_x2
  uu____1 =
    Eurydice_slice_split_at(Eurydice_array_to_slice_shared_17(&hashed),
      LIBCRUX_ML_KEM_CONSTANTS_SHARED_SECRET_SIZE,
      uint8_t,
      Eurydice_borrow_slice_u8_x2);
  Eurydice_borrow_slice_u8 shared_secret = uu____1.fst;
  Eurydice_borrow_slice_u8 pseudorandomness = uu____1.snd;
  Eurydice_arr_d1
  ciphertext =
    encrypt_d51(Eurydice_array_to_slice_shared_b50(libcrux_ml_kem_types_as_slice_e6_d9(public_key)),
      &randomness0,
      pseudorandomness);
  Eurydice_arr_d1 uu____2 = libcrux_ml_kem_types_from_19_d9(ciphertext);
  return (KRML_CLITERAL(tuple_25){ .fst = uu____2, .snd = kdf_39_4c(shared_secret) });
}

/**
This function found in impl {core::ops::function::FnMut<(usize), libcrux_ml_kem::polynomial::PolynomialRingElement<Vector>[TraitClause@0, TraitClause@1]> for libcrux_ml_kem::ind_cpa::decrypt::closure<Vector, K, CIPHERTEXT_SIZE, VECTOR_U_ENCODED_SIZE, U_COMPRESSION_FACTOR, V_COMPRESSION_FACTOR>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.decrypt.call_mut_0b
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 4
- CIPHERTEXT_SIZE= 1568
- VECTOR_U_ENCODED_SIZE= 1408
- U_COMPRESSION_FACTOR= 11
- V_COMPRESSION_FACTOR= 5
*/
static Eurydice_arr_9e call_mut_0b_38(void **_)
{
  return ZERO_d6_ea();
}

/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.decrypt
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 4
- CIPHERTEXT_SIZE= 1568
- VECTOR_U_ENCODED_SIZE= 1408
- U_COMPRESSION_FACTOR= 11
- V_COMPRESSION_FACTOR= 5
*/
static KRML_MUSTINLINE Eurydice_arr_ec
decrypt_38(Eurydice_borrow_slice_u8 secret_key, const Eurydice_arr_d1 *ciphertext)
{
  Eurydice_arr_d20 arr_struct;
  KRML_MAYBE_FOR4(i,
    (size_t)0U,
    (size_t)4U,
    (size_t)1U,
    /* original Rust expression is not an lvalue in C */
    void *lvalue = (void *)0U;
    arr_struct.data[i] = call_mut_0b_38(&lvalue););
  Eurydice_arr_d20 secret_key_unpacked = arr_struct;
  deserialize_vector_ee(secret_key, &secret_key_unpacked);
  return decrypt_unpacked_38(&secret_key_unpacked, ciphertext);
}

/**
 This code verifies on some machines, runs out of memory on others
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.decapsulate
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$4size_t]], libcrux_ml_kem_variant_MlKem
with const generics
- K= 4
- SECRET_KEY_SIZE= 3168
- CPA_SECRET_KEY_SIZE= 1536
- PUBLIC_KEY_SIZE= 1568
- CIPHERTEXT_SIZE= 1568
- T_AS_NTT_ENCODED_SIZE= 1536
- C1_SIZE= 1408
- C2_SIZE= 160
- VECTOR_U_COMPRESSION_FACTOR= 11
- VECTOR_V_COMPRESSION_FACTOR= 5
- C1_BLOCK_SIZE= 352
- ETA1= 2
- ETA1_RANDOMNESS_SIZE= 128
- ETA2= 2
- ETA2_RANDOMNESS_SIZE= 128
- IMPLICIT_REJECTION_HASH_INPUT_SIZE= 1600
*/
Eurydice_arr_ec
libcrux_ml_kem_ind_cca_decapsulate_fd1(
  const Eurydice_arr_a8 *private_key,
  const Eurydice_arr_d1 *ciphertext
)
{
  Eurydice_borrow_slice_u8_x4
  uu____0 =
    libcrux_ml_kem_types_unpack_private_key_e3(Eurydice_array_to_slice_shared_680(private_key));
  Eurydice_borrow_slice_u8 ind_cpa_secret_key = uu____0.fst;
  Eurydice_borrow_slice_u8 ind_cpa_public_key = uu____0.snd;
  Eurydice_borrow_slice_u8 ind_cpa_public_key_hash = uu____0.thd;
  Eurydice_borrow_slice_u8 implicit_rejection_value = uu____0.f3;
  Eurydice_arr_ec decrypted = decrypt_38(ind_cpa_secret_key, ciphertext);
  Eurydice_arr_c7
  to_hash0 =
    libcrux_ml_kem_utils_into_padded_array_c9(Eurydice_array_to_slice_shared_01(&decrypted));
  Eurydice_slice_copy(Eurydice_array_to_subslice_from_mut_5f1(&to_hash0,
      LIBCRUX_ML_KEM_CONSTANTS_SHARED_SECRET_SIZE),
    ind_cpa_public_key_hash,
    uint8_t);
  Eurydice_arr_c7 hashed = G_4a_23(Eurydice_array_to_slice_shared_17(&to_hash0));
  Eurydice_borrow_slice_u8_x2
  uu____1 =
    Eurydice_slice_split_at(Eurydice_array_to_slice_shared_17(&hashed),
      LIBCRUX_ML_KEM_CONSTANTS_SHARED_SECRET_SIZE,
      uint8_t,
      Eurydice_borrow_slice_u8_x2);
  Eurydice_borrow_slice_u8 shared_secret0 = uu____1.fst;
  Eurydice_borrow_slice_u8 pseudorandomness = uu____1.snd;
  Eurydice_arr_14 to_hash = libcrux_ml_kem_utils_into_padded_array_49(implicit_rejection_value);
  Eurydice_mut_borrow_slice_u8
  uu____2 =
    Eurydice_array_to_subslice_from_mut_5f7(&to_hash,
      LIBCRUX_ML_KEM_CONSTANTS_SHARED_SECRET_SIZE);
  Eurydice_slice_copy(uu____2, libcrux_ml_kem_types_as_ref_c1_d9(ciphertext), uint8_t);
  Eurydice_arr_ec
  implicit_rejection_shared_secret = PRF_4a_f5(Eurydice_array_to_slice_shared_720(&to_hash));
  Eurydice_arr_d1
  expected_ciphertext = encrypt_d51(ind_cpa_public_key, &decrypted, pseudorandomness);
  Eurydice_borrow_slice_u8
  uu____3 = Eurydice_array_to_slice_shared_01(&implicit_rejection_shared_secret);
  Eurydice_arr_ec implicit_rejection_shared_secret0 = kdf_39_4c(uu____3);
  Eurydice_arr_ec shared_secret = kdf_39_4c(shared_secret0);
  Eurydice_borrow_slice_u8 uu____4 = libcrux_ml_kem_types_as_ref_c1_d9(ciphertext);
  return
    libcrux_ml_kem_constant_time_ops_compare_ciphertexts_select_shared_secret_in_constant_time(uu____4,
      Eurydice_array_to_slice_shared_b50(&expected_ciphertext),
      Eurydice_array_to_slice_shared_01(&shared_secret),
      Eurydice_array_to_slice_shared_01(&implicit_rejection_shared_secret0));
}

/**
 See [deserialize_ring_elements_reduced_out].
*/
/**
A monomorphic instance of libcrux_ml_kem.serialize.deserialize_ring_elements_reduced
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 2
*/
static KRML_MUSTINLINE void
deserialize_ring_elements_reduced_66(
  Eurydice_borrow_slice_u8 public_key,
  Eurydice_arr_1e *deserialized_pk
)
{
  for
  (size_t
    i = (size_t)0U;
    i < public_key.meta / LIBCRUX_ML_KEM_CONSTANTS_BYTES_PER_RING_ELEMENT;
    i++)
  {
    size_t i0 = i;
    Eurydice_borrow_slice_u8
    ring_element =
      Eurydice_slice_subslice_shared_c8(public_key,
        (
          KRML_CLITERAL(core_ops_range_Range_87){
            .start = i0 * LIBCRUX_ML_KEM_CONSTANTS_BYTES_PER_RING_ELEMENT,
            .end = i0 * LIBCRUX_ML_KEM_CONSTANTS_BYTES_PER_RING_ELEMENT +
              LIBCRUX_ML_KEM_CONSTANTS_BYTES_PER_RING_ELEMENT
          }
        ));
    Eurydice_arr_9e uu____0 = deserialize_to_reduced_ring_element_ea(ring_element);
    deserialized_pk->data[i0] = uu____0;
  }
}

/**
A monomorphic instance of libcrux_ml_kem.hash_functions.portable.shake128_init_absorb_final
with const generics
- K= 2
*/
static inline Eurydice_arr_e3 shake128_init_absorb_final_af(const Eurydice_arr_bf *input)
{
  Eurydice_arr_e3 shake128_state;
  Eurydice_arr_7c repeat_expression[2U];
  KRML_MAYBE_FOR2(i,
    (size_t)0U,
    (size_t)2U,
    (size_t)1U,
    repeat_expression[i] = libcrux_sha3_portable_incremental_shake128_init(););
  memcpy(shake128_state.data, repeat_expression, (size_t)2U * sizeof (Eurydice_arr_7c));
  KRML_MAYBE_FOR2(i,
    (size_t)0U,
    (size_t)2U,
    (size_t)1U,
    size_t i0 = i;
    libcrux_sha3_portable_incremental_shake128_absorb_final(&shake128_state.data[i0],
      Eurydice_array_to_slice_shared_e9(&input->data[i0])););
  return shake128_state;
}

/**
This function found in impl {libcrux_ml_kem::hash_functions::Hash<K> for libcrux_ml_kem::hash_functions::portable::PortableHash<K>}
*/
/**
A monomorphic instance of libcrux_ml_kem.hash_functions.portable.shake128_init_absorb_final_4a
with const generics
- K= 2
*/
Eurydice_arr_e3
libcrux_ml_kem_hash_functions_portable_shake128_init_absorb_final_4a_af(
  const Eurydice_arr_bf *input
)
{
  return shake128_init_absorb_final_af(input);
}

/**
A monomorphic instance of libcrux_ml_kem.hash_functions.portable.shake128_squeeze_first_three_blocks
with const generics
- K= 2
*/
static inline Eurydice_arr_b8 shake128_squeeze_first_three_blocks_af(Eurydice_arr_e3 *st)
{
  Eurydice_arr_b8 out = { .data = { { .data = { 0U } }, { .data = { 0U } } } };
  KRML_MAYBE_FOR2(i,
    (size_t)0U,
    (size_t)2U,
    (size_t)1U,
    size_t i0 = i;
    libcrux_sha3_portable_incremental_shake128_squeeze_first_three_blocks(&st->data[i0],
      Eurydice_array_to_slice_mut_48(&out.data[i0])););
  return out;
}

/**
This function found in impl {libcrux_ml_kem::hash_functions::Hash<K> for libcrux_ml_kem::hash_functions::portable::PortableHash<K>}
*/
/**
A monomorphic instance of libcrux_ml_kem.hash_functions.portable.shake128_squeeze_first_three_blocks_4a
with const generics
- K= 2
*/
Eurydice_arr_b8
libcrux_ml_kem_hash_functions_portable_shake128_squeeze_first_three_blocks_4a_af(
  Eurydice_arr_e3 *self
)
{
  return shake128_squeeze_first_three_blocks_af(self);
}

/**
 If `bytes` contains a set of uniformly random bytes, this function
 uniformly samples a ring element `â` that is treated as being the NTT representation
 of the corresponding polynomial `a`.

 Since rejection sampling is used, it is possible the supplied bytes are
 not enough to sample the element, in which case an `Err` is returned and the
 caller must try again with a fresh set of bytes.

 This function <strong>partially</strong> implements <strong>Algorithm 6</strong> of the NIST FIPS 203 standard,
 We say "partially" because this implementation only accepts a finite set of
 bytes as input and returns an error if the set is not enough; Algorithm 6 of
 the FIPS 203 standard on the other hand samples from an infinite stream of bytes
 until the ring element is filled. Algorithm 6 is reproduced below:

 ```plaintext
 Input: byte stream B ∈ 𝔹*.
 Output: array â ∈ ℤ₂₅₆.

 i ← 0
 j ← 0
 while j < 256 do
     d₁ ← B[i] + 256·(B[i+1] mod 16)
     d₂ ← ⌊B[i+1]/16⌋ + 16·B[i+2]
     if d₁ < q then
         â[j] ← d₁
         j ← j + 1
     end if
     if d₂ < q and j < 256 then
         â[j] ← d₂
         j ← j + 1
     end if
     i ← i + 3
 end while
 return â
 ```

 The NIST FIPS 203 standard can be found at
 <https://csrc.nist.gov/pubs/fips/203/ipd>.
*/
/**
A monomorphic instance of libcrux_ml_kem.sampling.sample_from_uniform_distribution_next
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 2
- N= 504
*/
static KRML_MUSTINLINE bool
sample_from_uniform_distribution_next_53(
  const Eurydice_arr_b8 *randomness,
  Eurydice_arr_850 *sampled_coefficients,
  Eurydice_arr_800 *out
)
{
  KRML_MAYBE_FOR2(i0,
    (size_t)0U,
    (size_t)2U,
    (size_t)1U,
    size_t i1 = i0;
    for (size_t i = (size_t)0U; i < (size_t)504U / (size_t)24U; i++)
    {
      size_t r = i;
      if (sampled_coefficients->data[i1] < LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT)
      {
        size_t
        sampled =
          libcrux_ml_kem_vector_portable_rej_sample_b8(Eurydice_array_to_subslice_shared_d46(&randomness->data[i1],
              (
                KRML_CLITERAL(core_ops_range_Range_87){
                  .start = r * (size_t)24U,
                  .end = r * (size_t)24U + (size_t)24U
                }
              )),
            Eurydice_array_to_subslice_mut_e7(&out->data[i1],
              (
                KRML_CLITERAL(core_ops_range_Range_87){
                  .start = sampled_coefficients->data[i1],
                  .end = sampled_coefficients->data[i1] + (size_t)16U
                }
              )));
        size_t uu____0 = i1;
        sampled_coefficients->data[uu____0] += sampled;
      }
    });
  bool done = true;
  KRML_MAYBE_FOR2(i,
    (size_t)0U,
    (size_t)2U,
    (size_t)1U,
    size_t i0 = i;
    if (sampled_coefficients->data[i0] >= LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT)
    {
      sampled_coefficients->data[i0] = LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT;
    }
    else
    {
      done = false;
    });
  return done;
}

/**
A monomorphic instance of libcrux_ml_kem.hash_functions.portable.shake128_squeeze_next_block
with const generics
- K= 2
*/
static inline Eurydice_arr_5b0 shake128_squeeze_next_block_af(Eurydice_arr_e3 *st)
{
  Eurydice_arr_5b0 out = { .data = { { .data = { 0U } }, { .data = { 0U } } } };
  KRML_MAYBE_FOR2(i,
    (size_t)0U,
    (size_t)2U,
    (size_t)1U,
    size_t i0 = i;
    libcrux_sha3_portable_incremental_shake128_squeeze_next_block(&st->data[i0],
      Eurydice_array_to_slice_mut_2c(&out.data[i0])););
  return out;
}

/**
This function found in impl {libcrux_ml_kem::hash_functions::Hash<K> for libcrux_ml_kem::hash_functions::portable::PortableHash<K>}
*/
/**
A monomorphic instance of libcrux_ml_kem.hash_functions.portable.shake128_squeeze_next_block_4a
with const generics
- K= 2
*/
Eurydice_arr_5b0
libcrux_ml_kem_hash_functions_portable_shake128_squeeze_next_block_4a_af(Eurydice_arr_e3 *self)
{
  return shake128_squeeze_next_block_af(self);
}

/**
 If `bytes` contains a set of uniformly random bytes, this function
 uniformly samples a ring element `â` that is treated as being the NTT representation
 of the corresponding polynomial `a`.

 Since rejection sampling is used, it is possible the supplied bytes are
 not enough to sample the element, in which case an `Err` is returned and the
 caller must try again with a fresh set of bytes.

 This function <strong>partially</strong> implements <strong>Algorithm 6</strong> of the NIST FIPS 203 standard,
 We say "partially" because this implementation only accepts a finite set of
 bytes as input and returns an error if the set is not enough; Algorithm 6 of
 the FIPS 203 standard on the other hand samples from an infinite stream of bytes
 until the ring element is filled. Algorithm 6 is reproduced below:

 ```plaintext
 Input: byte stream B ∈ 𝔹*.
 Output: array â ∈ ℤ₂₅₆.

 i ← 0
 j ← 0
 while j < 256 do
     d₁ ← B[i] + 256·(B[i+1] mod 16)
     d₂ ← ⌊B[i+1]/16⌋ + 16·B[i+2]
     if d₁ < q then
         â[j] ← d₁
         j ← j + 1
     end if
     if d₂ < q and j < 256 then
         â[j] ← d₂
         j ← j + 1
     end if
     i ← i + 3
 end while
 return â
 ```

 The NIST FIPS 203 standard can be found at
 <https://csrc.nist.gov/pubs/fips/203/ipd>.
*/
/**
A monomorphic instance of libcrux_ml_kem.sampling.sample_from_uniform_distribution_next
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 2
- N= 168
*/
static KRML_MUSTINLINE bool
sample_from_uniform_distribution_next_530(
  const Eurydice_arr_5b0 *randomness,
  Eurydice_arr_850 *sampled_coefficients,
  Eurydice_arr_800 *out
)
{
  KRML_MAYBE_FOR2(i0,
    (size_t)0U,
    (size_t)2U,
    (size_t)1U,
    size_t i1 = i0;
    for (size_t i = (size_t)0U; i < (size_t)168U / (size_t)24U; i++)
    {
      size_t r = i;
      if (sampled_coefficients->data[i1] < LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT)
      {
        size_t
        sampled =
          libcrux_ml_kem_vector_portable_rej_sample_b8(Eurydice_array_to_subslice_shared_d40(&randomness->data[i1],
              (
                KRML_CLITERAL(core_ops_range_Range_87){
                  .start = r * (size_t)24U,
                  .end = r * (size_t)24U + (size_t)24U
                }
              )),
            Eurydice_array_to_subslice_mut_e7(&out->data[i1],
              (
                KRML_CLITERAL(core_ops_range_Range_87){
                  .start = sampled_coefficients->data[i1],
                  .end = sampled_coefficients->data[i1] + (size_t)16U
                }
              )));
        size_t uu____0 = i1;
        sampled_coefficients->data[uu____0] += sampled;
      }
    });
  bool done = true;
  KRML_MAYBE_FOR2(i,
    (size_t)0U,
    (size_t)2U,
    (size_t)1U,
    size_t i0 = i;
    if (sampled_coefficients->data[i0] >= LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT)
    {
      sampled_coefficients->data[i0] = LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT;
    }
    else
    {
      done = false;
    });
  return done;
}

/**
This function found in impl {core::ops::function::FnMut<([i16; 272usize]), libcrux_ml_kem::polynomial::PolynomialRingElement<Vector>[TraitClause@0, TraitClause@2]> for libcrux_ml_kem::sampling::sample_from_xof::closure<Vector, Hasher, K>[TraitClause@0, TraitClause@1, TraitClause@2, TraitClause@3]}
*/
/**
A monomorphic instance of libcrux_ml_kem.sampling.sample_from_xof.call_mut_0a
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$2size_t]]
with const generics
- K= 2
*/
static Eurydice_arr_9e call_mut_0a_910(Eurydice_arr_5b tupled_args)
{
  Eurydice_arr_5b s = tupled_args;
  return
    from_i16_array_d6_ea(Eurydice_array_to_subslice_shared_e70(&s,
        (KRML_CLITERAL(core_ops_range_Range_87){ .start = (size_t)0U, .end = (size_t)256U })));
}

/**
A monomorphic instance of libcrux_ml_kem.sampling.sample_from_xof
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$2size_t]]
with const generics
- K= 2
*/
static KRML_MUSTINLINE Eurydice_arr_1e sample_from_xof_910(const Eurydice_arr_bf *seeds)
{
  Eurydice_arr_850 sampled_coefficients = { .data = { 0U } };
  Eurydice_arr_800 out = { .data = { { .data = { 0U } }, { .data = { 0U } } } };
  Eurydice_arr_e3
  xof_state = libcrux_ml_kem_hash_functions_portable_shake128_init_absorb_final_4a_af(seeds);
  Eurydice_arr_b8
  randomness0 =
    libcrux_ml_kem_hash_functions_portable_shake128_squeeze_first_three_blocks_4a_af(&xof_state);
  bool
  done = sample_from_uniform_distribution_next_53(&randomness0, &sampled_coefficients, &out);
  while (true)
  {
    if (done)
    {
      break;
    }
    else
    {
      Eurydice_arr_5b0
      randomness =
        libcrux_ml_kem_hash_functions_portable_shake128_squeeze_next_block_4a_af(&xof_state);
      done = sample_from_uniform_distribution_next_530(&randomness, &sampled_coefficients, &out);
    }
  }
  Eurydice_arr_1e arr_mapped_str;
  KRML_MAYBE_FOR2(i,
    (size_t)0U,
    (size_t)2U,
    (size_t)1U,
    arr_mapped_str.data[i] = call_mut_0a_910(out.data[i]););
  return arr_mapped_str;
}

/**
A monomorphic instance of libcrux_ml_kem.matrix.sample_matrix_A
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$2size_t]]
with const generics
- K= 2
*/
static KRML_MUSTINLINE void
sample_matrix_A_910(Eurydice_arr_df0 *A_transpose, const Eurydice_arr_31 *seed, bool transpose)
{
  KRML_MAYBE_FOR2(i0,
    (size_t)0U,
    (size_t)2U,
    (size_t)1U,
    size_t i1 = i0;
    Eurydice_arr_bf seeds;
    Eurydice_arr_31 repeat_expression[2U];
    KRML_MAYBE_FOR2(i,
      (size_t)0U,
      (size_t)2U,
      (size_t)1U,
      repeat_expression[i] =
        core_array__core__clone__Clone_for__T__N___clone((size_t)34U,
          seed,
          uint8_t,
          Eurydice_arr_31););
    memcpy(seeds.data, repeat_expression, (size_t)2U * sizeof (Eurydice_arr_31));
    KRML_MAYBE_FOR2(i,
      (size_t)0U,
      (size_t)2U,
      (size_t)1U,
      size_t j = i;
      seeds.data[j].data[32U] = (uint8_t)i1;
      seeds.data[j].data[33U] = (uint8_t)j;);
    Eurydice_arr_1e sampled = sample_from_xof_910(&seeds);
    KRML_MAYBE_FOR2(i,
      (size_t)0U,
      (size_t)2U,
      (size_t)1U,
      size_t j = i;
      Eurydice_arr_9e sample = sampled.data[j];
      if (transpose)
      {
        A_transpose->data[j].data[i1] = sample;
      }
      else
      {
        A_transpose->data[i1].data[j] = sample;
      }););
}

/**
This function found in impl {libcrux_ml_kem::hash_functions::Hash<K> for libcrux_ml_kem::hash_functions::portable::PortableHash<K>}
*/
/**
A monomorphic instance of libcrux_ml_kem.hash_functions.portable.H_4a
with const generics
- K= 2
*/
static inline Eurydice_arr_ec H_4a_af(Eurydice_borrow_slice_u8 input)
{
  return libcrux_ml_kem_hash_functions_portable_H(input);
}

/**
 Generate an unpacked key from a serialized key.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.unpack_public_key
with types libcrux_ml_kem_hash_functions_portable_PortableHash[[$2size_t]], libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 2
- T_AS_NTT_ENCODED_SIZE= 768
- PUBLIC_KEY_SIZE= 800
*/
void
libcrux_ml_kem_ind_cca_unpacked_unpack_public_key_e0(
  const Eurydice_arr_03 *public_key,
  libcrux_ml_kem_ind_cca_unpacked_MlKemPublicKeyUnpacked_3b *unpacked_public_key
)
{
  Eurydice_borrow_slice_u8
  uu____0 = Eurydice_array_to_subslice_to_shared_212(public_key, (size_t)768U);
  deserialize_ring_elements_reduced_66(uu____0,
    &unpacked_public_key->ind_cpa_public_key.t_as_ntt);
  unpacked_public_key->ind_cpa_public_key.seed_for_A =
    libcrux_ml_kem_utils_into_padded_array_ce(Eurydice_array_to_subslice_from_shared_5f2(public_key,
        (size_t)768U));
  Eurydice_arr_df0 *uu____2 = &unpacked_public_key->ind_cpa_public_key.A;
  /* original Rust expression is not an lvalue in C */
  Eurydice_arr_31
  lvalue =
    libcrux_ml_kem_utils_into_padded_array_de(Eurydice_array_to_subslice_from_shared_5f2(public_key,
        (size_t)768U));
  sample_matrix_A_910(uu____2, &lvalue, false);
  Eurydice_arr_ec
  uu____3 =
    H_4a_af(Eurydice_array_to_slice_shared_3b(libcrux_ml_kem_types_as_slice_e6_df(public_key)));
  unpacked_public_key->public_key_hash = uu____3;
}

/**
 Call [`serialize_uncompressed_ring_element`] for each ring element.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.serialize_vector
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 2
*/
static KRML_MUSTINLINE void
serialize_vector_66(const Eurydice_arr_1e *key, Eurydice_mut_borrow_slice_u8 out)
{
  KRML_MAYBE_FOR2(i,
    (size_t)0U,
    (size_t)2U,
    (size_t)1U,
    size_t i0 = i;
    Eurydice_arr_9e re = key->data[i0];
    Eurydice_mut_borrow_slice_u8
    uu____0 =
      Eurydice_slice_subslice_mut_c8(out,
        (
          KRML_CLITERAL(core_ops_range_Range_87){
            .start = i0 * LIBCRUX_ML_KEM_CONSTANTS_BYTES_PER_RING_ELEMENT,
            .end = (i0 + (size_t)1U) * LIBCRUX_ML_KEM_CONSTANTS_BYTES_PER_RING_ELEMENT
          }
        ));
    /* original Rust expression is not an lvalue in C */
    Eurydice_arr_b20 lvalue = serialize_uncompressed_ring_element_ea(&re);
    Eurydice_slice_copy(uu____0, Eurydice_array_to_slice_shared_a9(&lvalue), uint8_t););
}

/**
 Concatenate `t` and `ρ` into the public key.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.serialize_public_key_mut
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 2
- PUBLIC_KEY_SIZE= 800
*/
static KRML_MUSTINLINE void
serialize_public_key_mut_53(
  const Eurydice_arr_1e *t_as_ntt,
  Eurydice_borrow_slice_u8 seed_for_a,
  Eurydice_arr_03 *serialized
)
{
  serialize_vector_66(t_as_ntt,
    Eurydice_array_to_subslice_mut_d411(serialized,
      (
        KRML_CLITERAL(core_ops_range_Range_87){
          .start = (size_t)0U,
          .end = libcrux_ml_kem_constants_ranked_bytes_per_ring_element((size_t)2U)
        }
      )));
  Eurydice_slice_copy(Eurydice_array_to_subslice_from_mut_5f2(serialized,
      libcrux_ml_kem_constants_ranked_bytes_per_ring_element((size_t)2U)),
    seed_for_a,
    uint8_t);
}

/**
 Get the serialized public key.
*/
/**
This function found in impl {libcrux_ml_kem::ind_cca::unpacked::MlKemPublicKeyUnpacked<Vector, K>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.serialized_mut_dd
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 2
- PUBLIC_KEY_SIZE= 800
*/
void
libcrux_ml_kem_ind_cca_unpacked_serialized_mut_dd_53(
  const libcrux_ml_kem_ind_cca_unpacked_MlKemPublicKeyUnpacked_3b *self,
  Eurydice_arr_03 *serialized
)
{
  serialize_public_key_mut_53(&self->ind_cpa_public_key.t_as_ntt,
    Eurydice_array_to_slice_shared_01(&self->ind_cpa_public_key.seed_for_A),
    serialized);
}

/**
 Get the serialized public key.
*/
/**
This function found in impl {libcrux_ml_kem::ind_cca::unpacked::MlKemKeyPairUnpacked<Vector, K>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.serialized_public_key_mut_11
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 2
- PUBLIC_KEY_SIZE= 800
*/
void
libcrux_ml_kem_ind_cca_unpacked_serialized_public_key_mut_11_53(
  const libcrux_ml_kem_mlkem512_portable_unpacked_MlKem512KeyPairUnpacked *self,
  Eurydice_arr_03 *serialized
)
{
  libcrux_ml_kem_ind_cca_unpacked_serialized_mut_dd_53(&self->public_key, serialized);
}

/**
 Concatenate `t` and `ρ` into the public key.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.serialize_public_key
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 2
- PUBLIC_KEY_SIZE= 800
*/
static KRML_MUSTINLINE Eurydice_arr_03
serialize_public_key_53(const Eurydice_arr_1e *t_as_ntt, Eurydice_borrow_slice_u8 seed_for_a)
{
  Eurydice_arr_03 public_key_serialized = { .data = { 0U } };
  serialize_public_key_mut_53(t_as_ntt, seed_for_a, &public_key_serialized);
  return public_key_serialized;
}

/**
 Get the serialized public key.
*/
/**
This function found in impl {libcrux_ml_kem::ind_cca::unpacked::MlKemPublicKeyUnpacked<Vector, K>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.serialized_dd
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 2
- PUBLIC_KEY_SIZE= 800
*/
static KRML_MUSTINLINE Eurydice_arr_03
serialized_dd_53(const libcrux_ml_kem_ind_cca_unpacked_MlKemPublicKeyUnpacked_3b *self)
{
  return
    libcrux_ml_kem_types_from_51_df(serialize_public_key_53(&self->ind_cpa_public_key.t_as_ntt,
        Eurydice_array_to_slice_shared_01(&self->ind_cpa_public_key.seed_for_A)));
}

/**
 Get the serialized public key.
*/
/**
This function found in impl {libcrux_ml_kem::ind_cca::unpacked::MlKemKeyPairUnpacked<Vector, K>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.serialized_public_key_11
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 2
- PUBLIC_KEY_SIZE= 800
*/
Eurydice_arr_03
libcrux_ml_kem_ind_cca_unpacked_serialized_public_key_11_53(
  const libcrux_ml_kem_mlkem512_portable_unpacked_MlKem512KeyPairUnpacked *self
)
{
  return serialized_dd_53(&self->public_key);
}

/**
 Serialize the secret key from the unpacked key pair generation.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.serialize_unpacked_secret_key
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 2
- PRIVATE_KEY_SIZE= 768
- PUBLIC_KEY_SIZE= 800
*/
static libcrux_ml_kem_utils_extraction_helper_Keypair512
serialize_unpacked_secret_key_44(
  const libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_3b *public_key,
  const Eurydice_arr_1e *private_key
)
{
  Eurydice_arr_03
  public_key_serialized =
    serialize_public_key_53(&public_key->t_as_ntt,
      Eurydice_array_to_slice_shared_01(&public_key->seed_for_A));
  Eurydice_arr_d2 secret_key_serialized = { .data = { 0U } };
  serialize_vector_66(private_key, Eurydice_array_to_slice_mut_27(&secret_key_serialized));
  return
    (
      KRML_CLITERAL(libcrux_ml_kem_utils_extraction_helper_Keypair512){
        .fst = secret_key_serialized,
        .snd = public_key_serialized
      }
    );
}

/**
 Serialize the secret key.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.serialize_kem_secret_key_mut
with types libcrux_ml_kem_hash_functions_portable_PortableHash[[$2size_t]]
with const generics
- K= 2
- SERIALIZED_KEY_LEN= 1632
*/
void
libcrux_ml_kem_ind_cca_serialize_kem_secret_key_mut_e2(
  Eurydice_borrow_slice_u8 private_key,
  Eurydice_borrow_slice_u8 public_key,
  Eurydice_borrow_slice_u8 implicit_rejection_value,
  Eurydice_arr_ab0 *serialized
)
{
  size_t pointer = (size_t)0U;
  Eurydice_slice_copy(Eurydice_array_to_subslice_mut_d416(serialized,
      (
        KRML_CLITERAL(core_ops_range_Range_87){
          .start = pointer,
          .end = pointer + private_key.meta
        }
      )),
    private_key,
    uint8_t);
  pointer += private_key.meta;
  Eurydice_slice_copy(Eurydice_array_to_subslice_mut_d416(serialized,
      (KRML_CLITERAL(core_ops_range_Range_87){ .start = pointer, .end = pointer + public_key.meta })),
    public_key,
    uint8_t);
  pointer += public_key.meta;
  Eurydice_mut_borrow_slice_u8
  uu____0 =
    Eurydice_array_to_subslice_mut_d416(serialized,
      (
        KRML_CLITERAL(core_ops_range_Range_87){
          .start = pointer,
          .end = pointer + LIBCRUX_ML_KEM_CONSTANTS_H_DIGEST_SIZE
        }
      ));
  /* original Rust expression is not an lvalue in C */
  Eurydice_arr_ec lvalue = H_4a_af(public_key);
  Eurydice_slice_copy(uu____0, Eurydice_array_to_slice_shared_01(&lvalue), uint8_t);
  pointer += LIBCRUX_ML_KEM_CONSTANTS_H_DIGEST_SIZE;
  Eurydice_slice_copy(Eurydice_array_to_subslice_mut_d416(serialized,
      (
        KRML_CLITERAL(core_ops_range_Range_87){
          .start = pointer,
          .end = pointer + implicit_rejection_value.meta
        }
      )),
    implicit_rejection_value,
    uint8_t);
}

/**
 Get the serialized private key.
*/
/**
This function found in impl {libcrux_ml_kem::ind_cca::unpacked::MlKemKeyPairUnpacked<Vector, K>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.serialized_private_key_mut_11
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 2
- CPA_PRIVATE_KEY_SIZE= 768
- PRIVATE_KEY_SIZE= 1632
- PUBLIC_KEY_SIZE= 800
*/
void
libcrux_ml_kem_ind_cca_unpacked_serialized_private_key_mut_11_a3(
  const libcrux_ml_kem_mlkem512_portable_unpacked_MlKem512KeyPairUnpacked *self,
  Eurydice_arr_ab0 *serialized
)
{
  libcrux_ml_kem_utils_extraction_helper_Keypair512
  uu____0 =
    serialize_unpacked_secret_key_44(&self->public_key.ind_cpa_public_key,
      &self->private_key.ind_cpa_private_key);
  Eurydice_arr_d2 ind_cpa_private_key = uu____0.fst;
  Eurydice_arr_03 ind_cpa_public_key = uu____0.snd;
  libcrux_ml_kem_ind_cca_serialize_kem_secret_key_mut_e2(Eurydice_array_to_slice_shared_27(&ind_cpa_private_key),
    Eurydice_array_to_slice_shared_3b(&ind_cpa_public_key),
    Eurydice_array_to_slice_shared_01(&self->private_key.implicit_rejection_value),
    serialized);
}

/**
 Get the serialized private key.
*/
/**
This function found in impl {libcrux_ml_kem::ind_cca::unpacked::MlKemKeyPairUnpacked<Vector, K>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.serialized_private_key_11
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 2
- CPA_PRIVATE_KEY_SIZE= 768
- PRIVATE_KEY_SIZE= 1632
- PUBLIC_KEY_SIZE= 800
*/
Eurydice_arr_ab0
libcrux_ml_kem_ind_cca_unpacked_serialized_private_key_11_a3(
  const libcrux_ml_kem_mlkem512_portable_unpacked_MlKem512KeyPairUnpacked *self
)
{
  Eurydice_arr_ab0 sk = libcrux_ml_kem_types_default_d3_be();
  libcrux_ml_kem_ind_cca_unpacked_serialized_private_key_mut_11_a3(self, &sk);
  return sk;
}

/**
 Call [`deserialize_to_uncompressed_ring_element`] for each ring element.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.deserialize_vector
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 2
*/
static KRML_MUSTINLINE void
deserialize_vector_66(Eurydice_borrow_slice_u8 secret_key, Eurydice_arr_1e *secret_as_ntt)
{
  KRML_MAYBE_FOR2(i,
    (size_t)0U,
    (size_t)2U,
    (size_t)1U,
    size_t i0 = i;
    Eurydice_arr_9e
    uu____0 =
      deserialize_to_uncompressed_ring_element_ea(Eurydice_slice_subslice_shared_c8(secret_key,
          (
            KRML_CLITERAL(core_ops_range_Range_87){
              .start = i0 * LIBCRUX_ML_KEM_CONSTANTS_BYTES_PER_RING_ELEMENT,
              .end = (i0 + (size_t)1U) * LIBCRUX_ML_KEM_CONSTANTS_BYTES_PER_RING_ELEMENT
            }
          )));
    secret_as_ntt->data[i0] = uu____0;);
}

/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.build_unpacked_public_key_mut
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$2size_t]]
with const generics
- K= 2
- T_AS_NTT_ENCODED_SIZE= 768
*/
static KRML_MUSTINLINE void
build_unpacked_public_key_mut_050(
  Eurydice_borrow_slice_u8 public_key,
  libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_3b *unpacked_public_key
)
{
  deserialize_ring_elements_reduced_66(Eurydice_slice_subslice_to_shared_72(public_key,
      (size_t)768U),
    &unpacked_public_key->t_as_ntt);
  Eurydice_borrow_slice_u8
  seed = Eurydice_slice_subslice_from_shared_6d(public_key, (size_t)768U);
  Eurydice_arr_df0 *uu____0 = &unpacked_public_key->A;
  /* original Rust expression is not an lvalue in C */
  Eurydice_arr_31 lvalue = libcrux_ml_kem_utils_into_padded_array_de(seed);
  sample_matrix_A_910(uu____0, &lvalue, false);
}

/**
 Take a serialized private key and generate an unpacked key pair from it.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.keys_from_private_key
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 2
- SECRET_KEY_SIZE= 1632
- CPA_SECRET_KEY_SIZE= 768
- PUBLIC_KEY_SIZE= 800
- T_AS_NTT_ENCODED_SIZE= 768
*/
void
libcrux_ml_kem_ind_cca_unpacked_keys_from_private_key_71(
  const Eurydice_arr_ab0 *private_key,
  libcrux_ml_kem_mlkem512_portable_unpacked_MlKem512KeyPairUnpacked *key_pair
)
{
  Eurydice_borrow_slice_u8_x4
  uu____0 =
    libcrux_ml_kem_types_unpack_private_key_e0(Eurydice_array_to_slice_shared_99(private_key));
  Eurydice_borrow_slice_u8 ind_cpa_secret_key = uu____0.fst;
  Eurydice_borrow_slice_u8 ind_cpa_public_key = uu____0.snd;
  Eurydice_borrow_slice_u8 ind_cpa_public_key_hash = uu____0.thd;
  Eurydice_borrow_slice_u8 implicit_rejection_value = uu____0.f3;
  deserialize_vector_66(ind_cpa_secret_key, &key_pair->private_key.ind_cpa_private_key);
  build_unpacked_public_key_mut_050(ind_cpa_public_key,
    &key_pair->public_key.ind_cpa_public_key);
  Eurydice_slice_copy(Eurydice_array_to_slice_mut_01(&key_pair->public_key.public_key_hash),
    ind_cpa_public_key_hash,
    uint8_t);
  Eurydice_slice_copy(Eurydice_array_to_slice_mut_01(&key_pair->private_key.implicit_rejection_value),
    implicit_rejection_value,
    uint8_t);
  Eurydice_slice_copy(Eurydice_array_to_slice_mut_01(&key_pair->public_key.ind_cpa_public_key.seed_for_A),
    Eurydice_slice_subslice_from_shared_6d(ind_cpa_public_key, (size_t)768U),
    uint8_t);
}

/**
This function found in impl {core::default::Default for libcrux_ml_kem::ind_cpa::unpacked::IndCpaPrivateKeyUnpacked<Vector, K>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.unpacked.default_70
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 2
*/
static Eurydice_arr_1e default_70_66(void)
{
  Eurydice_arr_1e lit;
  Eurydice_arr_9e repeat_expression[2U];
  KRML_MAYBE_FOR2(i, (size_t)0U, (size_t)2U, (size_t)1U, repeat_expression[i] = ZERO_d6_ea(););
  memcpy(lit.data, repeat_expression, (size_t)2U * sizeof (Eurydice_arr_9e));
  return lit;
}

/**
This function found in impl {core::default::Default for libcrux_ml_kem::ind_cpa::unpacked::IndCpaPublicKeyUnpacked<Vector, K>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.unpacked.default_8b
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 2
*/
static libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_3b default_8b_66(void)
{
  Eurydice_arr_1e uu____0;
  Eurydice_arr_9e repeat_expression0[2U];
  KRML_MAYBE_FOR2(i, (size_t)0U, (size_t)2U, (size_t)1U, repeat_expression0[i] = ZERO_d6_ea(););
  memcpy(uu____0.data, repeat_expression0, (size_t)2U * sizeof (Eurydice_arr_9e));
  Eurydice_arr_ec uu____1 = { .data = { 0U } };
  libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_3b lit0;
  lit0.t_as_ntt = uu____0;
  lit0.seed_for_A = uu____1;
  Eurydice_arr_1e repeat_expression1[2U];
  KRML_MAYBE_FOR2(i0,
    (size_t)0U,
    (size_t)2U,
    (size_t)1U,
    Eurydice_arr_1e lit;
    Eurydice_arr_9e repeat_expression[2U];
    KRML_MAYBE_FOR2(i, (size_t)0U, (size_t)2U, (size_t)1U, repeat_expression[i] = ZERO_d6_ea(););
    memcpy(lit.data, repeat_expression, (size_t)2U * sizeof (Eurydice_arr_9e));
    repeat_expression1[i0] = lit;);
  memcpy(lit0.A.data, repeat_expression1, (size_t)2U * sizeof (Eurydice_arr_1e));
  return lit0;
}

/**
This function found in impl {core::default::Default for libcrux_ml_kem::ind_cca::unpacked::MlKemPublicKeyUnpacked<Vector, K>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.default_30
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 2
*/
libcrux_ml_kem_ind_cca_unpacked_MlKemPublicKeyUnpacked_3b
libcrux_ml_kem_ind_cca_unpacked_default_30_66(void)
{
  return
    (
      KRML_CLITERAL(libcrux_ml_kem_ind_cca_unpacked_MlKemPublicKeyUnpacked_3b){
        .ind_cpa_public_key = default_8b_66(),
        .public_key_hash = { .data = { 0U } }
      }
    );
}

/**
This function found in impl {core::default::Default for libcrux_ml_kem::ind_cca::unpacked::MlKemKeyPairUnpacked<Vector, K>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.default_7b
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 2
*/
libcrux_ml_kem_mlkem512_portable_unpacked_MlKem512KeyPairUnpacked
libcrux_ml_kem_ind_cca_unpacked_default_7b_66(void)
{
  libcrux_ml_kem_ind_cca_unpacked_MlKemPrivateKeyUnpacked_3b
  uu____0 =
    { .ind_cpa_private_key = default_70_66(), .implicit_rejection_value = { .data = { 0U } } };
  return
    (
      KRML_CLITERAL(libcrux_ml_kem_mlkem512_portable_unpacked_MlKem512KeyPairUnpacked){
        .private_key = uu____0,
        .public_key = libcrux_ml_kem_ind_cca_unpacked_default_30_66()
      }
    );
}

/**
This function found in impl {libcrux_ml_kem::hash_functions::Hash<K> for libcrux_ml_kem::hash_functions::portable::PortableHash<K>}
*/
/**
A monomorphic instance of libcrux_ml_kem.hash_functions.portable.G_4a
with const generics
- K= 2
*/
static inline Eurydice_arr_c7 G_4a_af(Eurydice_borrow_slice_u8 input)
{
  return libcrux_ml_kem_hash_functions_portable_G(input);
}

/**
This function found in impl {libcrux_ml_kem::variant::Variant for libcrux_ml_kem::variant::MlKem}
*/
/**
A monomorphic instance of libcrux_ml_kem.variant.cpa_keygen_seed_39
with types libcrux_ml_kem_hash_functions_portable_PortableHash[[$2size_t]]
with const generics
- K= 2
*/
static KRML_MUSTINLINE Eurydice_arr_c7
cpa_keygen_seed_39_10(Eurydice_borrow_slice_u8 key_generation_seed)
{
  Eurydice_arr_fa seed = { .data = { 0U } };
  Eurydice_slice_copy(Eurydice_array_to_subslice_mut_d412(&seed,
      (
        KRML_CLITERAL(core_ops_range_Range_87){
          .start = (size_t)0U,
          .end = LIBCRUX_ML_KEM_CONSTANTS_CPA_PKE_KEY_GENERATION_SEED_SIZE
        }
      )),
    key_generation_seed,
    uint8_t);
  seed.data[LIBCRUX_ML_KEM_CONSTANTS_CPA_PKE_KEY_GENERATION_SEED_SIZE] = (uint8_t)(size_t)2U;
  return G_4a_af(Eurydice_array_to_slice_shared_b5(&seed));
}

/**
A monomorphic instance of libcrux_ml_kem.hash_functions.portable.PRFxN
with const generics
- K= 2
- LEN= 192
*/
static inline Eurydice_arr_eb PRFxN_d5(const Eurydice_arr_4d0 *input)
{
  Eurydice_arr_eb out = { .data = { { .data = { 0U } }, { .data = { 0U } } } };
  KRML_MAYBE_FOR2(i,
    (size_t)0U,
    (size_t)2U,
    (size_t)1U,
    size_t i0 = i;
    libcrux_sha3_portable_shake256(Eurydice_array_to_slice_mut_d9(&out.data[i0]),
      Eurydice_array_to_slice_shared_b5(&input->data[i0])););
  return out;
}

/**
This function found in impl {libcrux_ml_kem::hash_functions::Hash<K> for libcrux_ml_kem::hash_functions::portable::PortableHash<K>}
*/
/**
A monomorphic instance of libcrux_ml_kem.hash_functions.portable.PRFxN_4a
with const generics
- K= 2
- LEN= 192
*/
static inline Eurydice_arr_eb PRFxN_4a_d5(const Eurydice_arr_4d0 *input)
{
  return PRFxN_d5(input);
}

/**
A monomorphic instance of libcrux_ml_kem.sampling.sample_from_binomial_distribution
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- ETA= 3
*/
static KRML_MUSTINLINE Eurydice_arr_9e
sample_from_binomial_distribution_68(Eurydice_borrow_slice_u8 randomness)
{
  return sample_from_binomial_distribution_3_ea(randomness);
}

/**
 Sample a vector of ring elements from a centered binomial distribution and
 convert them into their NTT representations.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.sample_vector_cbd_then_ntt
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$2size_t]]
with const generics
- K= 2
- ETA= 3
- ETA_RANDOMNESS_SIZE= 192
*/
static KRML_MUSTINLINE uint8_t
sample_vector_cbd_then_ntt_bf0(
  Eurydice_arr_1e *re_as_ntt,
  const Eurydice_arr_fa *prf_input,
  uint8_t domain_separator
)
{
  Eurydice_arr_4d0 prf_inputs;
  Eurydice_arr_fa repeat_expression[2U];
  KRML_MAYBE_FOR2(i,
    (size_t)0U,
    (size_t)2U,
    (size_t)1U,
    repeat_expression[i] =
      core_array__core__clone__Clone_for__T__N___clone((size_t)33U,
        prf_input,
        uint8_t,
        Eurydice_arr_fa););
  memcpy(prf_inputs.data, repeat_expression, (size_t)2U * sizeof (Eurydice_arr_fa));
  domain_separator = libcrux_ml_kem_utils_prf_input_inc_af(&prf_inputs, domain_separator);
  Eurydice_arr_eb prf_outputs = PRFxN_4a_d5(&prf_inputs);
  KRML_MAYBE_FOR2(i,
    (size_t)0U,
    (size_t)2U,
    (size_t)1U,
    size_t i0 = i;
    Eurydice_arr_9e
    uu____0 =
      sample_from_binomial_distribution_68(Eurydice_array_to_slice_shared_d9(&prf_outputs.data[i0]));
    re_as_ntt->data[i0] = uu____0;
    ntt_binomially_sampled_ring_element_ea(&re_as_ntt->data[i0]););
  return domain_separator;
}

/**
This function found in impl {core::ops::function::FnMut<(usize), libcrux_ml_kem::polynomial::PolynomialRingElement<Vector>[TraitClause@0, TraitClause@3]> for libcrux_ml_kem::ind_cpa::generate_keypair_unpacked::closure<Vector, Hasher, Scheme, K, ETA1, ETA1_RANDOMNESS_SIZE>[TraitClause@0, TraitClause@1, TraitClause@2, TraitClause@3, TraitClause@4, TraitClause@5]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.generate_keypair_unpacked.call_mut_73
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$2size_t]], libcrux_ml_kem_variant_MlKem
with const generics
- K= 2
- ETA1= 3
- ETA1_RANDOMNESS_SIZE= 192
*/
static Eurydice_arr_9e call_mut_73_390(void **_)
{
  return ZERO_d6_ea();
}

/**
 Given two polynomial ring elements `lhs` and `rhs`, compute the pointwise
 sum of their constituent coefficients.
*/
/**
A monomorphic instance of libcrux_ml_kem.polynomial.add_to_ring_element
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 2
*/
static KRML_MUSTINLINE void
add_to_ring_element_66(Eurydice_arr_9e *myself, const Eurydice_arr_9e *rhs)
{
  KRML_MAYBE_FOR16(i,
    (size_t)0U,
    (size_t)16U,
    (size_t)1U,
    size_t i0 = i;
    Eurydice_arr_d6
    uu____0 = libcrux_ml_kem_vector_portable_add_b8(myself->data[i0], &rhs->data[i0]);
    myself->data[i0] = uu____0;);
}

/**
 Given two polynomial ring elements `lhs` and `rhs`, compute the pointwise
 sum of their constituent coefficients.
*/
/**
This function found in impl {libcrux_ml_kem::polynomial::PolynomialRingElement<Vector>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.polynomial.add_to_ring_element_d6
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 2
*/
static KRML_MUSTINLINE void
add_to_ring_element_d6_66(Eurydice_arr_9e *self, const Eurydice_arr_9e *rhs)
{
  add_to_ring_element_66(self, rhs);
}

/**
 Compute Â ◦ ŝ + ê
*/
/**
A monomorphic instance of libcrux_ml_kem.matrix.compute_As_plus_e
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 2
*/
static KRML_MUSTINLINE void
compute_As_plus_e_66(
  Eurydice_arr_1e *t_as_ntt,
  const Eurydice_arr_df0 *matrix_A,
  const Eurydice_arr_1e *s_as_ntt,
  const Eurydice_arr_1e *error_as_ntt
)
{
  KRML_MAYBE_FOR2(i,
    (size_t)0U,
    (size_t)2U,
    (size_t)1U,
    size_t i0 = i;
    const Eurydice_arr_1e *row = &matrix_A->data[i0];
    Eurydice_arr_9e uu____0 = ZERO_d6_ea();
    t_as_ntt->data[i0] = uu____0;
    KRML_MAYBE_FOR2(i1,
      (size_t)0U,
      (size_t)2U,
      (size_t)1U,
      size_t j = i1;
      const Eurydice_arr_9e *matrix_element = &row->data[j];
      Eurydice_arr_9e product = ntt_multiply_d6_ea(matrix_element, &s_as_ntt->data[j]);
      add_to_ring_element_d6_66(&t_as_ntt->data[i0], &product););
    add_standard_error_reduce_d6_ea(&t_as_ntt->data[i0], &error_as_ntt->data[i0]););
}

/**
 This function implements most of <strong>Algorithm 12</strong> of the
 NIST FIPS 203 specification; this is the Kyber CPA-PKE key generation algorithm.

 We say "most of" since Algorithm 12 samples the required randomness within
 the function itself, whereas this implementation expects it to be provided
 through the `key_generation_seed` parameter.

 Algorithm 12 is reproduced below:

 ```plaintext
 Output: encryption key ekₚₖₑ ∈ 𝔹^{384k+32}.
 Output: decryption key dkₚₖₑ ∈ 𝔹^{384k}.

 d ←$ B
 (ρ,σ) ← G(d)
 N ← 0
 for (i ← 0; i < k; i++)
     for(j ← 0; j < k; j++)
         Â[i,j] ← SampleNTT(XOF(ρ, i, j))
     end for
 end for
 for(i ← 0; i < k; i++)
     s[i] ← SamplePolyCBD_{η₁}(PRF_{η₁}(σ,N))
     N ← N + 1
 end for
 for(i ← 0; i < k; i++)
     e[i] ← SamplePolyCBD_{η₂}(PRF_{η₂}(σ,N))
     N ← N + 1
 end for
 ŝ ← NTT(s)
 ê ← NTT(e)
 t̂ ← Â◦ŝ + ê
 ekₚₖₑ ← ByteEncode₁₂(t̂) ‖ ρ
 dkₚₖₑ ← ByteEncode₁₂(ŝ)
 ```

 The NIST FIPS 203 standard can be found at
 <https://csrc.nist.gov/pubs/fips/203/ipd>.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.generate_keypair_unpacked
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$2size_t]], libcrux_ml_kem_variant_MlKem
with const generics
- K= 2
- ETA1= 3
- ETA1_RANDOMNESS_SIZE= 192
*/
static KRML_MUSTINLINE void
generate_keypair_unpacked_390(
  Eurydice_borrow_slice_u8 key_generation_seed,
  Eurydice_arr_1e *private_key,
  libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_3b *public_key
)
{
  Eurydice_arr_c7 hashed = cpa_keygen_seed_39_10(key_generation_seed);
  Eurydice_borrow_slice_u8_x2
  uu____0 =
    Eurydice_slice_split_at(Eurydice_array_to_slice_shared_17(&hashed),
      (size_t)32U,
      uint8_t,
      Eurydice_borrow_slice_u8_x2);
  Eurydice_borrow_slice_u8 seed_for_A = uu____0.fst;
  Eurydice_borrow_slice_u8 seed_for_secret_and_error = uu____0.snd;
  Eurydice_arr_df0 *uu____1 = &public_key->A;
  /* original Rust expression is not an lvalue in C */
  Eurydice_arr_31 lvalue0 = libcrux_ml_kem_utils_into_padded_array_de(seed_for_A);
  sample_matrix_A_910(uu____1, &lvalue0, true);
  Eurydice_arr_fa
  prf_input = libcrux_ml_kem_utils_into_padded_array_29(seed_for_secret_and_error);
  uint8_t domain_separator = sample_vector_cbd_then_ntt_bf0(private_key, &prf_input, 0U);
  Eurydice_arr_1e arr_struct;
  KRML_MAYBE_FOR2(i,
    (size_t)0U,
    (size_t)2U,
    (size_t)1U,
    /* original Rust expression is not an lvalue in C */
    void *lvalue = (void *)0U;
    arr_struct.data[i] = call_mut_73_390(&lvalue););
  Eurydice_arr_1e error_as_ntt = arr_struct;
  sample_vector_cbd_then_ntt_bf0(&error_as_ntt, &prf_input, domain_separator);
  compute_As_plus_e_66(&public_key->t_as_ntt, &public_key->A, &private_key[0U], &error_as_ntt);
  Eurydice_arr_ec arr;
  memcpy(arr.data, seed_for_A.ptr, (size_t)32U * sizeof (uint8_t));
  Eurydice_arr_ec
  uu____2 =
    core_result_unwrap_26_39((
        KRML_CLITERAL(core_result_Result_07){ .tag = core_result_Ok, .val = { .case_Ok = arr } }
      ));
  public_key->seed_for_A = uu____2;
}

/**
This function found in impl {core::ops::function::FnMut<(usize), libcrux_ml_kem::polynomial::PolynomialRingElement<Vector>[TraitClause@0, TraitClause@1]> for libcrux_ml_kem::ind_cca::unpacked::transpose_a::closure::closure<Vector, K>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.transpose_a.closure.call_mut_b4
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 2
*/
static Eurydice_arr_9e call_mut_b4_66(void **_)
{
  return ZERO_d6_ea();
}

/**
This function found in impl {core::ops::function::FnMut<(usize), [libcrux_ml_kem::polynomial::PolynomialRingElement<Vector>[TraitClause@0, TraitClause@1]; K]> for libcrux_ml_kem::ind_cca::unpacked::transpose_a::closure<Vector, K>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.transpose_a.call_mut_22
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 2
*/
static Eurydice_arr_1e call_mut_22_66(void **_)
{
  Eurydice_arr_1e arr_struct;
  KRML_MAYBE_FOR2(i,
    (size_t)0U,
    (size_t)2U,
    (size_t)1U,
    /* original Rust expression is not an lvalue in C */
    void *lvalue = (void *)0U;
    arr_struct.data[i] = call_mut_b4_66(&lvalue););
  return arr_struct;
}

/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.transpose_a
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 2
*/
static Eurydice_arr_df0 transpose_a_66(Eurydice_arr_df0 ind_cpa_a)
{
  Eurydice_arr_df0 arr_struct;
  KRML_MAYBE_FOR2(i,
    (size_t)0U,
    (size_t)2U,
    (size_t)1U,
    /* original Rust expression is not an lvalue in C */
    void *lvalue = (void *)0U;
    arr_struct.data[i] = call_mut_22_66(&lvalue););
  Eurydice_arr_df0 A = arr_struct;
  KRML_MAYBE_FOR2(i0,
    (size_t)0U,
    (size_t)2U,
    (size_t)1U,
    size_t i1 = i0;
    KRML_MAYBE_FOR2(i,
      (size_t)0U,
      (size_t)2U,
      (size_t)1U,
      size_t j = i;
      Eurydice_arr_9e uu____0 = clone_c1_ea(&ind_cpa_a.data[j].data[i1]);
      A.data[i1].data[j] = uu____0;););
  return A;
}

/**
 Generate Unpacked Keys
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.generate_keypair
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$2size_t]], libcrux_ml_kem_variant_MlKem
with const generics
- K= 2
- CPA_PRIVATE_KEY_SIZE= 768
- PRIVATE_KEY_SIZE= 1632
- PUBLIC_KEY_SIZE= 800
- ETA1= 3
- ETA1_RANDOMNESS_SIZE= 192
*/
void
libcrux_ml_kem_ind_cca_unpacked_generate_keypair_b80(
  Eurydice_arr_c7 randomness,
  libcrux_ml_kem_mlkem512_portable_unpacked_MlKem512KeyPairUnpacked *out
)
{
  Eurydice_borrow_slice_u8
  ind_cpa_keypair_randomness =
    Eurydice_array_to_subslice_shared_d47(&randomness,
      (
        KRML_CLITERAL(core_ops_range_Range_87){
          .start = (size_t)0U,
          .end = LIBCRUX_ML_KEM_CONSTANTS_CPA_PKE_KEY_GENERATION_SEED_SIZE
        }
      ));
  Eurydice_borrow_slice_u8
  implicit_rejection_value =
    Eurydice_array_to_subslice_from_shared_5f1(&randomness,
      LIBCRUX_ML_KEM_CONSTANTS_CPA_PKE_KEY_GENERATION_SEED_SIZE);
  generate_keypair_unpacked_390(ind_cpa_keypair_randomness,
    &out->private_key.ind_cpa_private_key,
    &out->public_key.ind_cpa_public_key);
  Eurydice_arr_df0 A = transpose_a_66(out->public_key.ind_cpa_public_key.A);
  out->public_key.ind_cpa_public_key.A = A;
  Eurydice_arr_03
  pk_serialized =
    serialize_public_key_53(&out->public_key.ind_cpa_public_key.t_as_ntt,
      Eurydice_array_to_slice_shared_01(&out->public_key.ind_cpa_public_key.seed_for_A));
  Eurydice_arr_ec uu____0 = H_4a_af(Eurydice_array_to_slice_shared_3b(&pk_serialized));
  out->public_key.public_key_hash = uu____0;
  Eurydice_arr_ec arr;
  memcpy(arr.data, implicit_rejection_value.ptr, (size_t)32U * sizeof (uint8_t));
  Eurydice_arr_ec
  uu____1 =
    core_result_unwrap_26_39((
        KRML_CLITERAL(core_result_Result_07){ .tag = core_result_Ok, .val = { .case_Ok = arr } }
      ));
  out->private_key.implicit_rejection_value = uu____1;
}

/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.encaps_prepare
with types libcrux_ml_kem_hash_functions_portable_PortableHash[[$2size_t]]
with const generics
- K= 2
*/
static Eurydice_arr_c7
encaps_prepare_10(Eurydice_borrow_slice_u8 randomness, Eurydice_borrow_slice_u8 pk_hash)
{
  Eurydice_arr_c7 to_hash = libcrux_ml_kem_utils_into_padded_array_c9(randomness);
  Eurydice_slice_copy(Eurydice_array_to_subslice_from_mut_5f1(&to_hash,
      LIBCRUX_ML_KEM_CONSTANTS_H_DIGEST_SIZE),
    pk_hash,
    uint8_t);
  return G_4a_af(Eurydice_array_to_slice_shared_17(&to_hash));
}

/**
A monomorphic instance of n-tuple
with types Eurydice_arr_1e, libcrux_ml_kem_polynomial_PolynomialRingElement_1d

*/
typedef struct tuple_77_s
{
  Eurydice_arr_1e fst;
  Eurydice_arr_9e snd;
}
tuple_77;

/**
This function found in impl {core::ops::function::FnMut<(usize), libcrux_ml_kem::polynomial::PolynomialRingElement<Vector>[TraitClause@0, TraitClause@2]> for libcrux_ml_kem::ind_cpa::encrypt_c1::closure<Vector, Hasher, K, C1_LEN, U_COMPRESSION_FACTOR, BLOCK_LEN, ETA1, ETA1_RANDOMNESS_SIZE, ETA2, ETA2_RANDOMNESS_SIZE>[TraitClause@0, TraitClause@1, TraitClause@2, TraitClause@3]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.encrypt_c1.call_mut_f1
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$2size_t]]
with const generics
- K= 2
- C1_LEN= 640
- U_COMPRESSION_FACTOR= 10
- BLOCK_LEN= 320
- ETA1= 3
- ETA1_RANDOMNESS_SIZE= 192
- ETA2= 2
- ETA2_RANDOMNESS_SIZE= 128
*/
static Eurydice_arr_9e call_mut_f1_870(void **_)
{
  return ZERO_d6_ea();
}

/**
This function found in impl {core::ops::function::FnMut<(usize), libcrux_ml_kem::polynomial::PolynomialRingElement<Vector>[TraitClause@0, TraitClause@2]> for libcrux_ml_kem::ind_cpa::encrypt_c1::closure#1<Vector, Hasher, K, C1_LEN, U_COMPRESSION_FACTOR, BLOCK_LEN, ETA1, ETA1_RANDOMNESS_SIZE, ETA2, ETA2_RANDOMNESS_SIZE>[TraitClause@0, TraitClause@1, TraitClause@2, TraitClause@3]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.encrypt_c1.call_mut_dd
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$2size_t]]
with const generics
- K= 2
- C1_LEN= 640
- U_COMPRESSION_FACTOR= 10
- BLOCK_LEN= 320
- ETA1= 3
- ETA1_RANDOMNESS_SIZE= 192
- ETA2= 2
- ETA2_RANDOMNESS_SIZE= 128
*/
static Eurydice_arr_9e call_mut_dd_870(void **_)
{
  return ZERO_d6_ea();
}

/**
A monomorphic instance of libcrux_ml_kem.hash_functions.portable.PRFxN
with const generics
- K= 2
- LEN= 128
*/
static inline Eurydice_arr_f3 PRFxN_d50(const Eurydice_arr_4d0 *input)
{
  Eurydice_arr_f3 out = { .data = { { .data = { 0U } }, { .data = { 0U } } } };
  KRML_MAYBE_FOR2(i,
    (size_t)0U,
    (size_t)2U,
    (size_t)1U,
    size_t i0 = i;
    libcrux_sha3_portable_shake256(Eurydice_array_to_slice_mut_78(&out.data[i0]),
      Eurydice_array_to_slice_shared_b5(&input->data[i0])););
  return out;
}

/**
This function found in impl {libcrux_ml_kem::hash_functions::Hash<K> for libcrux_ml_kem::hash_functions::portable::PortableHash<K>}
*/
/**
A monomorphic instance of libcrux_ml_kem.hash_functions.portable.PRFxN_4a
with const generics
- K= 2
- LEN= 128
*/
static inline Eurydice_arr_f3 PRFxN_4a_d50(const Eurydice_arr_4d0 *input)
{
  return PRFxN_d50(input);
}

/**
 Sample a vector of ring elements from a centered binomial distribution.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.sample_ring_element_cbd
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$2size_t]]
with const generics
- K= 2
- ETA2_RANDOMNESS_SIZE= 128
- ETA2= 2
*/
static KRML_MUSTINLINE uint8_t
sample_ring_element_cbd_bf0(
  const Eurydice_arr_fa *prf_input,
  uint8_t domain_separator,
  Eurydice_arr_1e *error_1
)
{
  Eurydice_arr_4d0 prf_inputs;
  Eurydice_arr_fa repeat_expression[2U];
  KRML_MAYBE_FOR2(i,
    (size_t)0U,
    (size_t)2U,
    (size_t)1U,
    repeat_expression[i] =
      core_array__core__clone__Clone_for__T__N___clone((size_t)33U,
        prf_input,
        uint8_t,
        Eurydice_arr_fa););
  memcpy(prf_inputs.data, repeat_expression, (size_t)2U * sizeof (Eurydice_arr_fa));
  domain_separator = libcrux_ml_kem_utils_prf_input_inc_af(&prf_inputs, domain_separator);
  Eurydice_arr_f3 prf_outputs = PRFxN_4a_d50(&prf_inputs);
  KRML_MAYBE_FOR2(i,
    (size_t)0U,
    (size_t)2U,
    (size_t)1U,
    size_t i0 = i;
    Eurydice_arr_9e
    uu____0 =
      sample_from_binomial_distribution_66(Eurydice_array_to_slice_shared_78(&prf_outputs.data[i0]));
    error_1->data[i0] = uu____0;);
  return domain_separator;
}

/**
This function found in impl {libcrux_ml_kem::hash_functions::Hash<K> for libcrux_ml_kem::hash_functions::portable::PortableHash<K>}
*/
/**
A monomorphic instance of libcrux_ml_kem.hash_functions.portable.PRF_4a
with const generics
- K= 2
- LEN= 128
*/
static inline Eurydice_arr_89 PRF_4a_d50(Eurydice_borrow_slice_u8 input)
{
  return PRF_ec(input);
}

/**
This function found in impl {core::ops::function::FnMut<(usize), libcrux_ml_kem::polynomial::PolynomialRingElement<Vector>[TraitClause@0, TraitClause@1]> for libcrux_ml_kem::matrix::compute_vector_u::closure<Vector, K>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.matrix.compute_vector_u.call_mut_a8
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 2
*/
static Eurydice_arr_9e call_mut_a8_66(void **_)
{
  return ZERO_d6_ea();
}

/**
A monomorphic instance of libcrux_ml_kem.invert_ntt.invert_ntt_montgomery
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 2
*/
static KRML_MUSTINLINE void invert_ntt_montgomery_66(Eurydice_arr_9e *re)
{
  size_t zeta_i = LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT / (size_t)2U;
  invert_ntt_at_layer_1_ea(&zeta_i, re);
  invert_ntt_at_layer_2_ea(&zeta_i, re);
  invert_ntt_at_layer_3_ea(&zeta_i, re);
  invert_ntt_at_layer_4_plus_ea(&zeta_i, re, (size_t)4U);
  invert_ntt_at_layer_4_plus_ea(&zeta_i, re, (size_t)5U);
  invert_ntt_at_layer_4_plus_ea(&zeta_i, re, (size_t)6U);
  invert_ntt_at_layer_4_plus_ea(&zeta_i, re, (size_t)7U);
  poly_barrett_reduce_d6_ea(re);
}

/**
 Compute u := InvertNTT(Aᵀ ◦ r̂) + e₁
*/
/**
A monomorphic instance of libcrux_ml_kem.matrix.compute_vector_u
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 2
*/
static KRML_MUSTINLINE Eurydice_arr_1e
compute_vector_u_66(
  const Eurydice_arr_df0 *a_as_ntt,
  const Eurydice_arr_1e *r_as_ntt,
  const Eurydice_arr_1e *error_1
)
{
  Eurydice_arr_1e arr_struct;
  KRML_MAYBE_FOR2(i,
    (size_t)0U,
    (size_t)2U,
    (size_t)1U,
    /* original Rust expression is not an lvalue in C */
    void *lvalue = (void *)0U;
    arr_struct.data[i] = call_mut_a8_66(&lvalue););
  Eurydice_arr_1e result = arr_struct;
  KRML_MAYBE_FOR2(i0,
    (size_t)0U,
    (size_t)2U,
    (size_t)1U,
    size_t i1 = i0;
    const Eurydice_arr_1e *row = &a_as_ntt->data[i1];
    KRML_MAYBE_FOR2(i,
      (size_t)0U,
      (size_t)2U,
      (size_t)1U,
      size_t j = i;
      const Eurydice_arr_9e *a_element = &row->data[j];
      Eurydice_arr_9e product = ntt_multiply_d6_ea(a_element, &r_as_ntt->data[j]);
      add_to_ring_element_d6_66(&result.data[i1], &product););
    invert_ntt_montgomery_66(&result.data[i1]);
    add_error_reduce_d6_ea(&result.data[i1], &error_1->data[i1]););
  return result;
}

/**
A monomorphic instance of libcrux_ml_kem.serialize.compress_then_serialize_10
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- OUT_LEN= 320
*/
static KRML_MUSTINLINE Eurydice_arr_b0 compress_then_serialize_10_e1(const Eurydice_arr_9e *re)
{
  Eurydice_arr_b0 serialized = { .data = { 0U } };
  for (size_t i = (size_t)0U; i < LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT; i++)
  {
    size_t i0 = i;
    Eurydice_arr_d6 coefficient = compress_b8_ef(to_unsigned_field_modulus_ea(re->data[i0]));
    Eurydice_arr_fc bytes = libcrux_ml_kem_vector_portable_serialize_10_b8(coefficient);
    Eurydice_slice_copy(Eurydice_array_to_subslice_mut_d413(&serialized,
        (
          KRML_CLITERAL(core_ops_range_Range_87){
            .start = (size_t)20U * i0,
            .end = (size_t)20U * i0 + (size_t)20U
          }
        )),
      Eurydice_array_to_slice_shared_8f(&bytes),
      uint8_t);
  }
  return serialized;
}

/**
A monomorphic instance of libcrux_ml_kem.serialize.compress_then_serialize_ring_element_u
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- COMPRESSION_FACTOR= 10
- OUT_LEN= 320
*/
static KRML_MUSTINLINE Eurydice_arr_b0
compress_then_serialize_ring_element_u_f7(const Eurydice_arr_9e *re)
{
  return compress_then_serialize_10_e1(re);
}

/**
 Call [`compress_then_serialize_ring_element_u`] on each ring element.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.compress_then_serialize_u
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 2
- OUT_LEN= 640
- COMPRESSION_FACTOR= 10
- BLOCK_LEN= 320
*/
static KRML_MUSTINLINE void
compress_then_serialize_u_a3(Eurydice_arr_1e input, Eurydice_mut_borrow_slice_u8 out)
{
  KRML_MAYBE_FOR2(i,
    (size_t)0U,
    (size_t)2U,
    (size_t)1U,
    size_t i0 = i;
    Eurydice_arr_9e re = input.data[i0];
    Eurydice_mut_borrow_slice_u8
    uu____0 =
      Eurydice_slice_subslice_mut_c8(out,
        (
          KRML_CLITERAL(core_ops_range_Range_87){
            .start = i0 * ((size_t)640U / (size_t)2U),
            .end = (i0 + (size_t)1U) * ((size_t)640U / (size_t)2U)
          }
        ));
    /* original Rust expression is not an lvalue in C */
    Eurydice_arr_b0 lvalue = compress_then_serialize_ring_element_u_f7(&re);
    Eurydice_slice_copy(uu____0, Eurydice_array_to_slice_shared_56(&lvalue), uint8_t););
}

/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.encrypt_c1
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$2size_t]]
with const generics
- K= 2
- C1_LEN= 640
- U_COMPRESSION_FACTOR= 10
- BLOCK_LEN= 320
- ETA1= 3
- ETA1_RANDOMNESS_SIZE= 192
- ETA2= 2
- ETA2_RANDOMNESS_SIZE= 128
*/
static KRML_MUSTINLINE tuple_77
encrypt_c1_870(
  Eurydice_borrow_slice_u8 randomness,
  const Eurydice_arr_df0 *matrix,
  Eurydice_mut_borrow_slice_u8 ciphertext
)
{
  Eurydice_arr_fa prf_input = libcrux_ml_kem_utils_into_padded_array_29(randomness);
  Eurydice_arr_1e arr_struct0;
  KRML_MAYBE_FOR2(i,
    (size_t)0U,
    (size_t)2U,
    (size_t)1U,
    /* original Rust expression is not an lvalue in C */
    void *lvalue = (void *)0U;
    arr_struct0.data[i] = call_mut_f1_870(&lvalue););
  Eurydice_arr_1e r_as_ntt = arr_struct0;
  uint8_t domain_separator0 = sample_vector_cbd_then_ntt_bf0(&r_as_ntt, &prf_input, 0U);
  Eurydice_arr_1e arr_struct;
  KRML_MAYBE_FOR2(i,
    (size_t)0U,
    (size_t)2U,
    (size_t)1U,
    /* original Rust expression is not an lvalue in C */
    void *lvalue = (void *)0U;
    arr_struct.data[i] = call_mut_dd_870(&lvalue););
  Eurydice_arr_1e error_1 = arr_struct;
  uint8_t
  domain_separator = sample_ring_element_cbd_bf0(&prf_input, domain_separator0, &error_1);
  prf_input.data[32U] = domain_separator;
  Eurydice_arr_89 prf_output = PRF_4a_d50(Eurydice_array_to_slice_shared_b5(&prf_input));
  Eurydice_arr_9e
  error_2 = sample_from_binomial_distribution_66(Eurydice_array_to_slice_shared_78(&prf_output));
  Eurydice_arr_1e u = compute_vector_u_66(matrix, &r_as_ntt, &error_1);
  compress_then_serialize_u_a3(u, ciphertext);
  return (KRML_CLITERAL(tuple_77){ .fst = r_as_ntt, .snd = error_2 });
}

/**
 Compute InverseNTT(tᵀ ◦ r̂) + e₂ + message
*/
/**
A monomorphic instance of libcrux_ml_kem.matrix.compute_ring_element_v
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 2
*/
static KRML_MUSTINLINE Eurydice_arr_9e
compute_ring_element_v_66(
  const Eurydice_arr_1e *t_as_ntt,
  const Eurydice_arr_1e *r_as_ntt,
  const Eurydice_arr_9e *error_2,
  const Eurydice_arr_9e *message
)
{
  Eurydice_arr_9e result = ZERO_d6_ea();
  KRML_MAYBE_FOR2(i,
    (size_t)0U,
    (size_t)2U,
    (size_t)1U,
    size_t i0 = i;
    Eurydice_arr_9e product = ntt_multiply_d6_ea(&t_as_ntt->data[i0], &r_as_ntt->data[i0]);
    add_to_ring_element_d6_66(&result, &product););
  invert_ntt_montgomery_66(&result);
  return add_message_error_reduce_d6_ea(error_2, message, result);
}

/**
A monomorphic instance of libcrux_ml_kem.serialize.compress_then_serialize_ring_element_v
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 2
- COMPRESSION_FACTOR= 4
- OUT_LEN= 128
*/
static KRML_MUSTINLINE void
compress_then_serialize_ring_element_v_44(Eurydice_arr_9e re, Eurydice_mut_borrow_slice_u8 out)
{
  compress_then_serialize_4_ea(re, out);
}

/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.encrypt_c2
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 2
- V_COMPRESSION_FACTOR= 4
- C2_LEN= 128
*/
static KRML_MUSTINLINE void
encrypt_c2_44(
  const Eurydice_arr_1e *t_as_ntt,
  const Eurydice_arr_1e *r_as_ntt,
  const Eurydice_arr_9e *error_2,
  const Eurydice_arr_ec *message,
  Eurydice_mut_borrow_slice_u8 ciphertext
)
{
  Eurydice_arr_9e message_as_ring_element = deserialize_then_decompress_message_ea(message);
  Eurydice_arr_9e
  v = compute_ring_element_v_66(t_as_ntt, r_as_ntt, error_2, &message_as_ring_element);
  compress_then_serialize_ring_element_v_44(v, ciphertext);
}

/**
 This function implements <strong>Algorithm 13</strong> of the
 NIST FIPS 203 specification; this is the Kyber CPA-PKE encryption algorithm.

 Algorithm 13 is reproduced below:

 ```plaintext
 Input: encryption key ekₚₖₑ ∈ 𝔹^{384k+32}.
 Input: message m ∈ 𝔹^{32}.
 Input: encryption randomness r ∈ 𝔹^{32}.
 Output: ciphertext c ∈ 𝔹^{32(dᵤk + dᵥ)}.

 N ← 0
 t̂ ← ByteDecode₁₂(ekₚₖₑ[0:384k])
 ρ ← ekₚₖₑ[384k: 384k + 32]
 for (i ← 0; i < k; i++)
     for(j ← 0; j < k; j++)
         Â[i,j] ← SampleNTT(XOF(ρ, i, j))
     end for
 end for
 for(i ← 0; i < k; i++)
     r[i] ← SamplePolyCBD_{η₁}(PRF_{η₁}(r,N))
     N ← N + 1
 end for
 for(i ← 0; i < k; i++)
     e₁[i] ← SamplePolyCBD_{η₂}(PRF_{η₂}(r,N))
     N ← N + 1
 end for
 e₂ ← SamplePolyCBD_{η₂}(PRF_{η₂}(r,N))
 r̂ ← NTT(r)
 u ← NTT-¹(Âᵀ ◦ r̂) + e₁
 μ ← Decompress₁(ByteDecode₁(m)))
 v ← NTT-¹(t̂ᵀ ◦ rˆ) + e₂ + μ
 c₁ ← ByteEncode_{dᵤ}(Compress_{dᵤ}(u))
 c₂ ← ByteEncode_{dᵥ}(Compress_{dᵥ}(v))
 return c ← (c₁ ‖ c₂)
 ```

 The NIST FIPS 203 standard can be found at
 <https://csrc.nist.gov/pubs/fips/203/ipd>.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.encrypt_unpacked
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$2size_t]]
with const generics
- K= 2
- CIPHERTEXT_SIZE= 768
- T_AS_NTT_ENCODED_SIZE= 768
- C1_LEN= 640
- C2_LEN= 128
- U_COMPRESSION_FACTOR= 10
- V_COMPRESSION_FACTOR= 4
- BLOCK_LEN= 320
- ETA1= 3
- ETA1_RANDOMNESS_SIZE= 192
- ETA2= 2
- ETA2_RANDOMNESS_SIZE= 128
*/
static KRML_MUSTINLINE Eurydice_arr_d2
encrypt_unpacked_d50(
  const libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_3b *public_key,
  const Eurydice_arr_ec *message,
  Eurydice_borrow_slice_u8 randomness
)
{
  Eurydice_arr_d2 ciphertext = { .data = { 0U } };
  tuple_77
  uu____0 =
    encrypt_c1_870(randomness,
      &public_key->A,
      Eurydice_array_to_subslice_mut_d414(&ciphertext,
        (KRML_CLITERAL(core_ops_range_Range_87){ .start = (size_t)0U, .end = (size_t)640U })));
  Eurydice_arr_1e r_as_ntt = uu____0.fst;
  Eurydice_arr_9e error_2 = uu____0.snd;
  encrypt_c2_44(&public_key->t_as_ntt,
    &r_as_ntt,
    &error_2,
    message,
    Eurydice_array_to_subslice_from_mut_5f3(&ciphertext, (size_t)640U));
  return ciphertext;
}

/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.encapsulate
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$2size_t]]
with const generics
- K= 2
- CIPHERTEXT_SIZE= 768
- PUBLIC_KEY_SIZE= 800
- T_AS_NTT_ENCODED_SIZE= 768
- C1_SIZE= 640
- C2_SIZE= 128
- VECTOR_U_COMPRESSION_FACTOR= 10
- VECTOR_V_COMPRESSION_FACTOR= 4
- VECTOR_U_BLOCK_LEN= 320
- ETA1= 3
- ETA1_RANDOMNESS_SIZE= 192
- ETA2= 2
- ETA2_RANDOMNESS_SIZE= 128
*/
tuple_ab
libcrux_ml_kem_ind_cca_unpacked_encapsulate_a70(
  const libcrux_ml_kem_ind_cca_unpacked_MlKemPublicKeyUnpacked_3b *public_key,
  const Eurydice_arr_ec *randomness
)
{
  Eurydice_arr_c7
  hashed =
    encaps_prepare_10(Eurydice_array_to_slice_shared_01(randomness),
      Eurydice_array_to_slice_shared_01(&public_key->public_key_hash));
  Eurydice_borrow_slice_u8_x2
  uu____0 =
    Eurydice_slice_split_at(Eurydice_array_to_slice_shared_17(&hashed),
      LIBCRUX_ML_KEM_CONSTANTS_SHARED_SECRET_SIZE,
      uint8_t,
      Eurydice_borrow_slice_u8_x2);
  Eurydice_borrow_slice_u8 shared_secret = uu____0.fst;
  Eurydice_borrow_slice_u8 pseudorandomness = uu____0.snd;
  Eurydice_arr_d2
  ciphertext =
    encrypt_unpacked_d50(&public_key->ind_cpa_public_key,
      randomness,
      pseudorandomness);
  Eurydice_arr_ec shared_secret_array = { .data = { 0U } };
  Eurydice_slice_copy(Eurydice_array_to_slice_mut_01(&shared_secret_array),
    shared_secret,
    uint8_t);
  return
    (
      KRML_CLITERAL(tuple_ab){
        .fst = libcrux_ml_kem_types_from_19_80(ciphertext),
        .snd = shared_secret_array
      }
    );
}

/**
This function found in impl {core::ops::function::FnMut<(usize), libcrux_ml_kem::polynomial::PolynomialRingElement<Vector>[TraitClause@0, TraitClause@1]> for libcrux_ml_kem::ind_cpa::deserialize_then_decompress_u::closure<Vector, K, CIPHERTEXT_SIZE, U_COMPRESSION_FACTOR>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.deserialize_then_decompress_u.call_mut_35
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 2
- CIPHERTEXT_SIZE= 768
- U_COMPRESSION_FACTOR= 10
*/
static Eurydice_arr_9e call_mut_35_44(void **_)
{
  return ZERO_d6_ea();
}

/**
A monomorphic instance of libcrux_ml_kem.serialize.deserialize_then_decompress_ring_element_u
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- COMPRESSION_FACTOR= 10
*/
static KRML_MUSTINLINE Eurydice_arr_9e
deserialize_then_decompress_ring_element_u_f7(Eurydice_borrow_slice_u8 serialized)
{
  return deserialize_then_decompress_10_ea(serialized);
}

/**
A monomorphic instance of libcrux_ml_kem.ntt.ntt_vector_u
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- VECTOR_U_COMPRESSION_FACTOR= 10
*/
static KRML_MUSTINLINE void ntt_vector_u_f7(Eurydice_arr_9e *re)
{
  size_t zeta_i = (size_t)0U;
  ntt_at_layer_4_plus_ea(&zeta_i, re, (size_t)7U);
  ntt_at_layer_4_plus_ea(&zeta_i, re, (size_t)6U);
  ntt_at_layer_4_plus_ea(&zeta_i, re, (size_t)5U);
  ntt_at_layer_4_plus_ea(&zeta_i, re, (size_t)4U);
  ntt_at_layer_3_ea(&zeta_i, re);
  ntt_at_layer_2_ea(&zeta_i, re);
  ntt_at_layer_1_ea(&zeta_i, re);
  poly_barrett_reduce_d6_ea(re);
}

/**
 Call [`deserialize_then_decompress_ring_element_u`] on each ring element
 in the `ciphertext`.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.deserialize_then_decompress_u
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 2
- CIPHERTEXT_SIZE= 768
- U_COMPRESSION_FACTOR= 10
*/
static KRML_MUSTINLINE Eurydice_arr_1e
deserialize_then_decompress_u_44(const Eurydice_arr_d2 *ciphertext)
{
  Eurydice_arr_1e arr_struct;
  KRML_MAYBE_FOR2(i,
    (size_t)0U,
    (size_t)2U,
    (size_t)1U,
    /* original Rust expression is not an lvalue in C */
    void *lvalue = (void *)0U;
    arr_struct.data[i] = call_mut_35_44(&lvalue););
  Eurydice_arr_1e u_as_ntt = arr_struct;
  for
  (size_t
    i = (size_t)0U;
    i <
      (size_t)768U /
        (LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT * (size_t)10U / (size_t)8U);
    i++)
  {
    size_t i0 = i;
    Eurydice_borrow_slice_u8
    u_bytes =
      Eurydice_array_to_subslice_shared_d45(ciphertext,
        (
          KRML_CLITERAL(core_ops_range_Range_87){
            .start = i0 *
              (LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT * (size_t)10U / (size_t)8U),
            .end = i0 *
              (LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT * (size_t)10U / (size_t)8U)
            + LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT * (size_t)10U / (size_t)8U
          }
        ));
    u_as_ntt.data[i0] = deserialize_then_decompress_ring_element_u_f7(u_bytes);
    ntt_vector_u_f7(&u_as_ntt.data[i0]);
  }
  return u_as_ntt;
}

/**
A monomorphic instance of libcrux_ml_kem.serialize.deserialize_then_decompress_ring_element_v
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 2
- COMPRESSION_FACTOR= 4
*/
static KRML_MUSTINLINE Eurydice_arr_9e
deserialize_then_decompress_ring_element_v_53(Eurydice_borrow_slice_u8 serialized)
{
  return deserialize_then_decompress_4_ea(serialized);
}

/**
 The following functions compute various expressions involving
 vectors and matrices. The computation of these expressions has been
 abstracted away into these functions in order to save on loop iterations.
 Compute v − InverseNTT(sᵀ ◦ NTT(u))
*/
/**
A monomorphic instance of libcrux_ml_kem.matrix.compute_message
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 2
*/
static KRML_MUSTINLINE Eurydice_arr_9e
compute_message_66(
  const Eurydice_arr_9e *v,
  const Eurydice_arr_1e *secret_as_ntt,
  const Eurydice_arr_1e *u_as_ntt
)
{
  Eurydice_arr_9e result = ZERO_d6_ea();
  KRML_MAYBE_FOR2(i,
    (size_t)0U,
    (size_t)2U,
    (size_t)1U,
    size_t i0 = i;
    Eurydice_arr_9e product = ntt_multiply_d6_ea(&secret_as_ntt->data[i0], &u_as_ntt->data[i0]);
    add_to_ring_element_d6_66(&result, &product););
  invert_ntt_montgomery_66(&result);
  return subtract_reduce_d6_ea(v, result);
}

/**
 This function implements <strong>Algorithm 14</strong> of the
 NIST FIPS 203 specification; this is the Kyber CPA-PKE decryption algorithm.

 Algorithm 14 is reproduced below:

 ```plaintext
 Input: decryption key dkₚₖₑ ∈ 𝔹^{384k}.
 Input: ciphertext c ∈ 𝔹^{32(dᵤk + dᵥ)}.
 Output: message m ∈ 𝔹^{32}.

 c₁ ← c[0 : 32dᵤk]
 c₂ ← c[32dᵤk : 32(dᵤk + dᵥ)]
 u ← Decompress_{dᵤ}(ByteDecode_{dᵤ}(c₁))
 v ← Decompress_{dᵥ}(ByteDecode_{dᵥ}(c₂))
 ŝ ← ByteDecode₁₂(dkₚₖₑ)
 w ← v - NTT-¹(ŝᵀ ◦ NTT(u))
 m ← ByteEncode₁(Compress₁(w))
 return m
 ```

 The NIST FIPS 203 standard can be found at
 <https://csrc.nist.gov/pubs/fips/203/ipd>.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.decrypt_unpacked
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 2
- CIPHERTEXT_SIZE= 768
- VECTOR_U_ENCODED_SIZE= 640
- U_COMPRESSION_FACTOR= 10
- V_COMPRESSION_FACTOR= 4
*/
static KRML_MUSTINLINE Eurydice_arr_ec
decrypt_unpacked_71(const Eurydice_arr_1e *secret_key, const Eurydice_arr_d2 *ciphertext)
{
  Eurydice_arr_1e u_as_ntt = deserialize_then_decompress_u_44(ciphertext);
  Eurydice_arr_9e
  v =
    deserialize_then_decompress_ring_element_v_53(Eurydice_array_to_subslice_from_shared_5f0(ciphertext,
        (size_t)640U));
  Eurydice_arr_9e message = compute_message_66(&v, secret_key, &u_as_ntt);
  return compress_then_serialize_message_ea(message);
}

/**
This function found in impl {libcrux_ml_kem::hash_functions::Hash<K> for libcrux_ml_kem::hash_functions::portable::PortableHash<K>}
*/
/**
A monomorphic instance of libcrux_ml_kem.hash_functions.portable.PRF_4a
with const generics
- K= 2
- LEN= 32
*/
static inline Eurydice_arr_ec PRF_4a_d5(Eurydice_borrow_slice_u8 input)
{
  return PRF_ce(input);
}

/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.decapsulate
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$2size_t]]
with const generics
- K= 2
- SECRET_KEY_SIZE= 1632
- CPA_SECRET_KEY_SIZE= 768
- PUBLIC_KEY_SIZE= 800
- CIPHERTEXT_SIZE= 768
- T_AS_NTT_ENCODED_SIZE= 768
- C1_SIZE= 640
- C2_SIZE= 128
- VECTOR_U_COMPRESSION_FACTOR= 10
- VECTOR_V_COMPRESSION_FACTOR= 4
- C1_BLOCK_SIZE= 320
- ETA1= 3
- ETA1_RANDOMNESS_SIZE= 192
- ETA2= 2
- ETA2_RANDOMNESS_SIZE= 128
- IMPLICIT_REJECTION_HASH_INPUT_SIZE= 800
*/
Eurydice_arr_ec
libcrux_ml_kem_ind_cca_unpacked_decapsulate_0c0(
  const libcrux_ml_kem_mlkem512_portable_unpacked_MlKem512KeyPairUnpacked *key_pair,
  const Eurydice_arr_d2 *ciphertext
)
{
  Eurydice_arr_ec
  decrypted = decrypt_unpacked_71(&key_pair->private_key.ind_cpa_private_key, ciphertext);
  Eurydice_arr_c7
  to_hash0 =
    libcrux_ml_kem_utils_into_padded_array_c9(Eurydice_array_to_slice_shared_01(&decrypted));
  Eurydice_mut_borrow_slice_u8
  uu____0 =
    Eurydice_array_to_subslice_from_mut_5f1(&to_hash0,
      LIBCRUX_ML_KEM_CONSTANTS_SHARED_SECRET_SIZE);
  Eurydice_slice_copy(uu____0,
    Eurydice_array_to_slice_shared_01(&key_pair->public_key.public_key_hash),
    uint8_t);
  Eurydice_arr_c7 hashed = G_4a_af(Eurydice_array_to_slice_shared_17(&to_hash0));
  Eurydice_borrow_slice_u8_x2
  uu____1 =
    Eurydice_slice_split_at(Eurydice_array_to_slice_shared_17(&hashed),
      LIBCRUX_ML_KEM_CONSTANTS_SHARED_SECRET_SIZE,
      uint8_t,
      Eurydice_borrow_slice_u8_x2);
  Eurydice_borrow_slice_u8 shared_secret = uu____1.fst;
  Eurydice_borrow_slice_u8 pseudorandomness = uu____1.snd;
  Eurydice_arr_03
  to_hash =
    libcrux_ml_kem_utils_into_padded_array_df(Eurydice_array_to_slice_shared_01(&key_pair->private_key.implicit_rejection_value));
  Eurydice_mut_borrow_slice_u8
  uu____2 =
    Eurydice_array_to_subslice_from_mut_5f2(&to_hash,
      LIBCRUX_ML_KEM_CONSTANTS_SHARED_SECRET_SIZE);
  Eurydice_slice_copy(uu____2, libcrux_ml_kem_types_as_ref_c1_80(ciphertext), uint8_t);
  Eurydice_arr_ec
  implicit_rejection_shared_secret = PRF_4a_d5(Eurydice_array_to_slice_shared_3b(&to_hash));
  Eurydice_arr_d2
  expected_ciphertext =
    encrypt_unpacked_d50(&key_pair->public_key.ind_cpa_public_key,
      &decrypted,
      pseudorandomness);
  Eurydice_borrow_slice_u8 uu____3 = libcrux_ml_kem_types_as_ref_c1_80(ciphertext);
  uint8_t
  selector =
    libcrux_ml_kem_constant_time_ops_compare_ciphertexts_in_constant_time(uu____3,
      Eurydice_array_to_slice_shared_27(&expected_ciphertext));
  return
    libcrux_ml_kem_constant_time_ops_select_shared_secret_in_constant_time(shared_secret,
      Eurydice_array_to_slice_shared_01(&implicit_rejection_shared_secret),
      selector);
}

/**
This function found in impl {core::ops::function::FnMut<(usize), libcrux_ml_kem::polynomial::PolynomialRingElement<Vector>[TraitClause@0, TraitClause@1]> for libcrux_ml_kem::serialize::deserialize_ring_elements_reduced_out::closure<Vector, K>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.serialize.deserialize_ring_elements_reduced_out.call_mut_0b
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 2
*/
static Eurydice_arr_9e call_mut_0b_66(void **_)
{
  return ZERO_d6_ea();
}

/**
 This function deserializes ring elements and reduces the result by the field
 modulus.

 This function MUST NOT be used on secret inputs.
*/
/**
A monomorphic instance of libcrux_ml_kem.serialize.deserialize_ring_elements_reduced_out
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 2
*/
static KRML_MUSTINLINE Eurydice_arr_1e
deserialize_ring_elements_reduced_out_66(Eurydice_borrow_slice_u8 public_key)
{
  Eurydice_arr_1e arr_struct;
  KRML_MAYBE_FOR2(i,
    (size_t)0U,
    (size_t)2U,
    (size_t)1U,
    /* original Rust expression is not an lvalue in C */
    void *lvalue = (void *)0U;
    arr_struct.data[i] = call_mut_0b_66(&lvalue););
  Eurydice_arr_1e deserialized_pk = arr_struct;
  deserialize_ring_elements_reduced_66(public_key, &deserialized_pk);
  return deserialized_pk;
}

/**
 Validate an ML-KEM public key.

 This implements the Modulus check in 7.2 2.
 Note that the size check in 7.2 1 is covered by the `PUBLIC_KEY_SIZE` in the
 `public_key` type.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.validate_public_key
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 2
- PUBLIC_KEY_SIZE= 800
*/
bool libcrux_ml_kem_ind_cca_validate_public_key_53(const Eurydice_arr_03 *public_key)
{
  Eurydice_arr_1e
  deserialized_pk =
    deserialize_ring_elements_reduced_out_66(Eurydice_array_to_subslice_to_shared_212(public_key,
        libcrux_ml_kem_constants_ranked_bytes_per_ring_element((size_t)2U)));
  Eurydice_arr_03
  public_key_serialized =
    serialize_public_key_53(&deserialized_pk,
      Eurydice_array_to_subslice_from_shared_5f2(public_key,
        libcrux_ml_kem_constants_ranked_bytes_per_ring_element((size_t)2U)));
  return Eurydice_array_eq((size_t)800U, public_key, &public_key_serialized, uint8_t);
}

/**
 Validate an ML-KEM private key.

 This implements the Hash check in 7.3 3.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.validate_private_key_only
with types libcrux_ml_kem_hash_functions_portable_PortableHash[[$2size_t]]
with const generics
- K= 2
- SECRET_KEY_SIZE= 1632
*/
bool libcrux_ml_kem_ind_cca_validate_private_key_only_e2(const Eurydice_arr_ab0 *private_key)
{
  Eurydice_arr_ec
  t =
    H_4a_af(Eurydice_array_to_subslice_shared_d48(private_key,
        (
          KRML_CLITERAL(core_ops_range_Range_87){
            .start = (size_t)384U * (size_t)2U,
            .end = (size_t)768U * (size_t)2U + (size_t)32U
          }
        )));
  Eurydice_borrow_slice_u8
  expected =
    Eurydice_array_to_subslice_shared_d48(private_key,
      (
        KRML_CLITERAL(core_ops_range_Range_87){
          .start = (size_t)768U * (size_t)2U + (size_t)32U,
          .end = (size_t)768U * (size_t)2U + (size_t)64U
        }
      ));
  return Eurydice_array_eq_slice_shared((size_t)32U, &t, &expected, uint8_t, bool);
}

/**
 Validate an ML-KEM private key.

 This implements the Hash check in 7.3 3.
 Note that the size checks in 7.2 1 and 2 are covered by the `SECRET_KEY_SIZE`
 and `CIPHERTEXT_SIZE` in the `private_key` and `ciphertext` types.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.validate_private_key
with types libcrux_ml_kem_hash_functions_portable_PortableHash[[$2size_t]]
with const generics
- K= 2
- SECRET_KEY_SIZE= 1632
- CIPHERTEXT_SIZE= 768
*/
bool
libcrux_ml_kem_ind_cca_validate_private_key_d5(
  const Eurydice_arr_ab0 *private_key,
  const Eurydice_arr_d2 *_ciphertext
)
{
  return libcrux_ml_kem_ind_cca_validate_private_key_only_e2(private_key);
}

/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.generate_keypair
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$2size_t]], libcrux_ml_kem_variant_MlKem
with const generics
- K= 2
- PRIVATE_KEY_SIZE= 768
- PUBLIC_KEY_SIZE= 800
- ETA1= 3
- ETA1_RANDOMNESS_SIZE= 192
*/
static KRML_MUSTINLINE libcrux_ml_kem_utils_extraction_helper_Keypair512
generate_keypair_300(Eurydice_borrow_slice_u8 key_generation_seed)
{
  Eurydice_arr_1e private_key = default_70_66();
  libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_3b public_key = default_8b_66();
  generate_keypair_unpacked_390(key_generation_seed, &private_key, &public_key);
  return serialize_unpacked_secret_key_44(&public_key, &private_key);
}

/**
A monomorphic instance of libcrux_ml_kem.ind_cca.serialize_kem_secret_key
with types libcrux_ml_kem_hash_functions_portable_PortableHash[[$2size_t]]
with const generics
- K= 2
- SERIALIZED_KEY_LEN= 1632
*/
static KRML_MUSTINLINE Eurydice_arr_ab0
serialize_kem_secret_key_e2(
  Eurydice_borrow_slice_u8 private_key,
  Eurydice_borrow_slice_u8 public_key,
  Eurydice_borrow_slice_u8 implicit_rejection_value
)
{
  Eurydice_arr_ab0 out = { .data = { 0U } };
  libcrux_ml_kem_ind_cca_serialize_kem_secret_key_mut_e2(private_key,
    public_key,
    implicit_rejection_value,
    &out);
  return out;
}

/**
 Packed API

 Generate a key pair.

 Depending on the `Vector` and `Hasher` used, this requires different hardware
 features
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.generate_keypair
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$2size_t]], libcrux_ml_kem_variant_MlKem
with const generics
- K= 2
- CPA_PRIVATE_KEY_SIZE= 768
- PRIVATE_KEY_SIZE= 1632
- PUBLIC_KEY_SIZE= 800
- ETA1= 3
- ETA1_RANDOMNESS_SIZE= 192
*/
libcrux_ml_kem_types_MlKemKeyPair_0d
libcrux_ml_kem_ind_cca_generate_keypair_b80(const Eurydice_arr_c7 *randomness)
{
  Eurydice_borrow_slice_u8
  ind_cpa_keypair_randomness =
    Eurydice_array_to_subslice_shared_d47(randomness,
      (
        KRML_CLITERAL(core_ops_range_Range_87){
          .start = (size_t)0U,
          .end = LIBCRUX_ML_KEM_CONSTANTS_CPA_PKE_KEY_GENERATION_SEED_SIZE
        }
      ));
  Eurydice_borrow_slice_u8
  implicit_rejection_value =
    Eurydice_array_to_subslice_from_shared_5f1(randomness,
      LIBCRUX_ML_KEM_CONSTANTS_CPA_PKE_KEY_GENERATION_SEED_SIZE);
  libcrux_ml_kem_utils_extraction_helper_Keypair512
  uu____0 = generate_keypair_300(ind_cpa_keypair_randomness);
  Eurydice_arr_d2 ind_cpa_private_key = uu____0.fst;
  Eurydice_arr_03 public_key = uu____0.snd;
  Eurydice_arr_ab0
  secret_key_serialized =
    serialize_kem_secret_key_e2(Eurydice_array_to_slice_shared_27(&ind_cpa_private_key),
      Eurydice_array_to_slice_shared_3b(&public_key),
      implicit_rejection_value);
  Eurydice_arr_ab0 private_key = libcrux_ml_kem_types_from_b2_be(secret_key_serialized);
  return
    libcrux_ml_kem_types_from_17_d6(private_key,
      libcrux_ml_kem_types_from_51_df(public_key));
}

/**
This function found in impl {libcrux_ml_kem::variant::Variant for libcrux_ml_kem::variant::MlKem}
*/
/**
A monomorphic instance of libcrux_ml_kem.variant.entropy_preprocess_39
with types libcrux_ml_kem_hash_functions_portable_PortableHash[[$2size_t]]
with const generics
- K= 2
*/
static KRML_MUSTINLINE Eurydice_arr_ec
entropy_preprocess_39_10(Eurydice_borrow_slice_u8 randomness)
{
  Eurydice_arr_ec out = { .data = { 0U } };
  Eurydice_slice_copy(Eurydice_array_to_slice_mut_01(&out), randomness, uint8_t);
  return out;
}

/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.build_unpacked_public_key
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$2size_t]]
with const generics
- K= 2
- T_AS_NTT_ENCODED_SIZE= 768
*/
static KRML_MUSTINLINE libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_3b
build_unpacked_public_key_050(Eurydice_borrow_slice_u8 public_key)
{
  libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_3b
  unpacked_public_key = default_8b_66();
  build_unpacked_public_key_mut_050(public_key, &unpacked_public_key);
  return unpacked_public_key;
}

/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.encrypt
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$2size_t]]
with const generics
- K= 2
- CIPHERTEXT_SIZE= 768
- T_AS_NTT_ENCODED_SIZE= 768
- C1_LEN= 640
- C2_LEN= 128
- U_COMPRESSION_FACTOR= 10
- V_COMPRESSION_FACTOR= 4
- BLOCK_LEN= 320
- ETA1= 3
- ETA1_RANDOMNESS_SIZE= 192
- ETA2= 2
- ETA2_RANDOMNESS_SIZE= 128
*/
static KRML_MUSTINLINE Eurydice_arr_d2
encrypt_d50(
  Eurydice_borrow_slice_u8 public_key,
  const Eurydice_arr_ec *message,
  Eurydice_borrow_slice_u8 randomness
)
{
  libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_3b
  unpacked_public_key = build_unpacked_public_key_050(public_key);
  return encrypt_unpacked_d50(&unpacked_public_key, message, randomness);
}

/**
This function found in impl {libcrux_ml_kem::variant::Variant for libcrux_ml_kem::variant::MlKem}
*/
/**
A monomorphic instance of libcrux_ml_kem.variant.kdf_39
with types libcrux_ml_kem_hash_functions_portable_PortableHash[[$2size_t]]
with const generics
- K= 2
- CIPHERTEXT_SIZE= 768
*/
static KRML_MUSTINLINE Eurydice_arr_ec kdf_39_e2(Eurydice_borrow_slice_u8 shared_secret)
{
  Eurydice_arr_ec out = { .data = { 0U } };
  Eurydice_slice_copy(Eurydice_array_to_slice_mut_01(&out), shared_secret, uint8_t);
  return out;
}

/**
A monomorphic instance of libcrux_ml_kem.ind_cca.encapsulate
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$2size_t]], libcrux_ml_kem_variant_MlKem
with const generics
- K= 2
- CIPHERTEXT_SIZE= 768
- PUBLIC_KEY_SIZE= 800
- T_AS_NTT_ENCODED_SIZE= 768
- C1_SIZE= 640
- C2_SIZE= 128
- VECTOR_U_COMPRESSION_FACTOR= 10
- VECTOR_V_COMPRESSION_FACTOR= 4
- C1_BLOCK_SIZE= 320
- ETA1= 3
- ETA1_RANDOMNESS_SIZE= 192
- ETA2= 2
- ETA2_RANDOMNESS_SIZE= 128
*/
tuple_ab
libcrux_ml_kem_ind_cca_encapsulate_990(
  const Eurydice_arr_03 *public_key,
  const Eurydice_arr_ec *randomness
)
{
  Eurydice_arr_ec
  randomness0 = entropy_preprocess_39_10(Eurydice_array_to_slice_shared_01(randomness));
  Eurydice_arr_c7
  to_hash =
    libcrux_ml_kem_utils_into_padded_array_c9(Eurydice_array_to_slice_shared_01(&randomness0));
  Eurydice_mut_borrow_slice_u8
  uu____0 =
    Eurydice_array_to_subslice_from_mut_5f1(&to_hash,
      LIBCRUX_ML_KEM_CONSTANTS_H_DIGEST_SIZE);
  /* original Rust expression is not an lvalue in C */
  Eurydice_arr_ec
  lvalue =
    H_4a_af(Eurydice_array_to_slice_shared_3b(libcrux_ml_kem_types_as_slice_e6_df(public_key)));
  Eurydice_slice_copy(uu____0, Eurydice_array_to_slice_shared_01(&lvalue), uint8_t);
  Eurydice_arr_c7 hashed = G_4a_af(Eurydice_array_to_slice_shared_17(&to_hash));
  Eurydice_borrow_slice_u8_x2
  uu____1 =
    Eurydice_slice_split_at(Eurydice_array_to_slice_shared_17(&hashed),
      LIBCRUX_ML_KEM_CONSTANTS_SHARED_SECRET_SIZE,
      uint8_t,
      Eurydice_borrow_slice_u8_x2);
  Eurydice_borrow_slice_u8 shared_secret = uu____1.fst;
  Eurydice_borrow_slice_u8 pseudorandomness = uu____1.snd;
  Eurydice_arr_d2
  ciphertext =
    encrypt_d50(Eurydice_array_to_slice_shared_3b(libcrux_ml_kem_types_as_slice_e6_df(public_key)),
      &randomness0,
      pseudorandomness);
  Eurydice_arr_d2 uu____2 = libcrux_ml_kem_types_from_19_80(ciphertext);
  return (KRML_CLITERAL(tuple_ab){ .fst = uu____2, .snd = kdf_39_e2(shared_secret) });
}

/**
This function found in impl {core::ops::function::FnMut<(usize), libcrux_ml_kem::polynomial::PolynomialRingElement<Vector>[TraitClause@0, TraitClause@1]> for libcrux_ml_kem::ind_cpa::decrypt::closure<Vector, K, CIPHERTEXT_SIZE, VECTOR_U_ENCODED_SIZE, U_COMPRESSION_FACTOR, V_COMPRESSION_FACTOR>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.decrypt.call_mut_0b
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 2
- CIPHERTEXT_SIZE= 768
- VECTOR_U_ENCODED_SIZE= 640
- U_COMPRESSION_FACTOR= 10
- V_COMPRESSION_FACTOR= 4
*/
static Eurydice_arr_9e call_mut_0b_71(void **_)
{
  return ZERO_d6_ea();
}

/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.decrypt
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 2
- CIPHERTEXT_SIZE= 768
- VECTOR_U_ENCODED_SIZE= 640
- U_COMPRESSION_FACTOR= 10
- V_COMPRESSION_FACTOR= 4
*/
static KRML_MUSTINLINE Eurydice_arr_ec
decrypt_71(Eurydice_borrow_slice_u8 secret_key, const Eurydice_arr_d2 *ciphertext)
{
  Eurydice_arr_1e arr_struct;
  KRML_MAYBE_FOR2(i,
    (size_t)0U,
    (size_t)2U,
    (size_t)1U,
    /* original Rust expression is not an lvalue in C */
    void *lvalue = (void *)0U;
    arr_struct.data[i] = call_mut_0b_71(&lvalue););
  Eurydice_arr_1e secret_key_unpacked = arr_struct;
  deserialize_vector_66(secret_key, &secret_key_unpacked);
  return decrypt_unpacked_71(&secret_key_unpacked, ciphertext);
}

/**
 This code verifies on some machines, runs out of memory on others
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.decapsulate
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$2size_t]], libcrux_ml_kem_variant_MlKem
with const generics
- K= 2
- SECRET_KEY_SIZE= 1632
- CPA_SECRET_KEY_SIZE= 768
- PUBLIC_KEY_SIZE= 800
- CIPHERTEXT_SIZE= 768
- T_AS_NTT_ENCODED_SIZE= 768
- C1_SIZE= 640
- C2_SIZE= 128
- VECTOR_U_COMPRESSION_FACTOR= 10
- VECTOR_V_COMPRESSION_FACTOR= 4
- C1_BLOCK_SIZE= 320
- ETA1= 3
- ETA1_RANDOMNESS_SIZE= 192
- ETA2= 2
- ETA2_RANDOMNESS_SIZE= 128
- IMPLICIT_REJECTION_HASH_INPUT_SIZE= 800
*/
Eurydice_arr_ec
libcrux_ml_kem_ind_cca_decapsulate_fd0(
  const Eurydice_arr_ab0 *private_key,
  const Eurydice_arr_d2 *ciphertext
)
{
  Eurydice_borrow_slice_u8_x4
  uu____0 =
    libcrux_ml_kem_types_unpack_private_key_e0(Eurydice_array_to_slice_shared_99(private_key));
  Eurydice_borrow_slice_u8 ind_cpa_secret_key = uu____0.fst;
  Eurydice_borrow_slice_u8 ind_cpa_public_key = uu____0.snd;
  Eurydice_borrow_slice_u8 ind_cpa_public_key_hash = uu____0.thd;
  Eurydice_borrow_slice_u8 implicit_rejection_value = uu____0.f3;
  Eurydice_arr_ec decrypted = decrypt_71(ind_cpa_secret_key, ciphertext);
  Eurydice_arr_c7
  to_hash0 =
    libcrux_ml_kem_utils_into_padded_array_c9(Eurydice_array_to_slice_shared_01(&decrypted));
  Eurydice_slice_copy(Eurydice_array_to_subslice_from_mut_5f1(&to_hash0,
      LIBCRUX_ML_KEM_CONSTANTS_SHARED_SECRET_SIZE),
    ind_cpa_public_key_hash,
    uint8_t);
  Eurydice_arr_c7 hashed = G_4a_af(Eurydice_array_to_slice_shared_17(&to_hash0));
  Eurydice_borrow_slice_u8_x2
  uu____1 =
    Eurydice_slice_split_at(Eurydice_array_to_slice_shared_17(&hashed),
      LIBCRUX_ML_KEM_CONSTANTS_SHARED_SECRET_SIZE,
      uint8_t,
      Eurydice_borrow_slice_u8_x2);
  Eurydice_borrow_slice_u8 shared_secret0 = uu____1.fst;
  Eurydice_borrow_slice_u8 pseudorandomness = uu____1.snd;
  Eurydice_arr_03 to_hash = libcrux_ml_kem_utils_into_padded_array_df(implicit_rejection_value);
  Eurydice_mut_borrow_slice_u8
  uu____2 =
    Eurydice_array_to_subslice_from_mut_5f2(&to_hash,
      LIBCRUX_ML_KEM_CONSTANTS_SHARED_SECRET_SIZE);
  Eurydice_slice_copy(uu____2, libcrux_ml_kem_types_as_ref_c1_80(ciphertext), uint8_t);
  Eurydice_arr_ec
  implicit_rejection_shared_secret = PRF_4a_d5(Eurydice_array_to_slice_shared_3b(&to_hash));
  Eurydice_arr_d2
  expected_ciphertext = encrypt_d50(ind_cpa_public_key, &decrypted, pseudorandomness);
  Eurydice_borrow_slice_u8
  uu____3 = Eurydice_array_to_slice_shared_01(&implicit_rejection_shared_secret);
  Eurydice_arr_ec implicit_rejection_shared_secret0 = kdf_39_e2(uu____3);
  Eurydice_arr_ec shared_secret = kdf_39_e2(shared_secret0);
  Eurydice_borrow_slice_u8 uu____4 = libcrux_ml_kem_types_as_ref_c1_80(ciphertext);
  return
    libcrux_ml_kem_constant_time_ops_compare_ciphertexts_select_shared_secret_in_constant_time(uu____4,
      Eurydice_array_to_slice_shared_27(&expected_ciphertext),
      Eurydice_array_to_slice_shared_01(&shared_secret),
      Eurydice_array_to_slice_shared_01(&implicit_rejection_shared_secret0));
}

/**
 See [deserialize_ring_elements_reduced_out].
*/
/**
A monomorphic instance of libcrux_ml_kem.serialize.deserialize_ring_elements_reduced
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
*/
static KRML_MUSTINLINE void
deserialize_ring_elements_reduced_68(
  Eurydice_borrow_slice_u8 public_key,
  Eurydice_arr_bb0 *deserialized_pk
)
{
  for
  (size_t
    i = (size_t)0U;
    i < public_key.meta / LIBCRUX_ML_KEM_CONSTANTS_BYTES_PER_RING_ELEMENT;
    i++)
  {
    size_t i0 = i;
    Eurydice_borrow_slice_u8
    ring_element =
      Eurydice_slice_subslice_shared_c8(public_key,
        (
          KRML_CLITERAL(core_ops_range_Range_87){
            .start = i0 * LIBCRUX_ML_KEM_CONSTANTS_BYTES_PER_RING_ELEMENT,
            .end = i0 * LIBCRUX_ML_KEM_CONSTANTS_BYTES_PER_RING_ELEMENT +
              LIBCRUX_ML_KEM_CONSTANTS_BYTES_PER_RING_ELEMENT
          }
        ));
    Eurydice_arr_9e uu____0 = deserialize_to_reduced_ring_element_ea(ring_element);
    deserialized_pk->data[i0] = uu____0;
  }
}

/**
A monomorphic instance of libcrux_ml_kem.hash_functions.portable.shake128_init_absorb_final
with const generics
- K= 3
*/
static inline Eurydice_arr_1b0 shake128_init_absorb_final_78(const Eurydice_arr_810 *input)
{
  Eurydice_arr_1b0 shake128_state;
  Eurydice_arr_7c repeat_expression[3U];
  KRML_MAYBE_FOR3(i,
    (size_t)0U,
    (size_t)3U,
    (size_t)1U,
    repeat_expression[i] = libcrux_sha3_portable_incremental_shake128_init(););
  memcpy(shake128_state.data, repeat_expression, (size_t)3U * sizeof (Eurydice_arr_7c));
  KRML_MAYBE_FOR3(i,
    (size_t)0U,
    (size_t)3U,
    (size_t)1U,
    size_t i0 = i;
    libcrux_sha3_portable_incremental_shake128_absorb_final(&shake128_state.data[i0],
      Eurydice_array_to_slice_shared_e9(&input->data[i0])););
  return shake128_state;
}

/**
This function found in impl {libcrux_ml_kem::hash_functions::Hash<K> for libcrux_ml_kem::hash_functions::portable::PortableHash<K>}
*/
/**
A monomorphic instance of libcrux_ml_kem.hash_functions.portable.shake128_init_absorb_final_4a
with const generics
- K= 3
*/
Eurydice_arr_1b0
libcrux_ml_kem_hash_functions_portable_shake128_init_absorb_final_4a_78(
  const Eurydice_arr_810 *input
)
{
  return shake128_init_absorb_final_78(input);
}

/**
A monomorphic instance of libcrux_ml_kem.hash_functions.portable.shake128_squeeze_first_three_blocks
with const generics
- K= 3
*/
static inline Eurydice_arr_7e shake128_squeeze_first_three_blocks_78(Eurydice_arr_1b0 *st)
{
  Eurydice_arr_7e
  out = { .data = { { .data = { 0U } }, { .data = { 0U } }, { .data = { 0U } } } };
  KRML_MAYBE_FOR3(i,
    (size_t)0U,
    (size_t)3U,
    (size_t)1U,
    size_t i0 = i;
    libcrux_sha3_portable_incremental_shake128_squeeze_first_three_blocks(&st->data[i0],
      Eurydice_array_to_slice_mut_48(&out.data[i0])););
  return out;
}

/**
This function found in impl {libcrux_ml_kem::hash_functions::Hash<K> for libcrux_ml_kem::hash_functions::portable::PortableHash<K>}
*/
/**
A monomorphic instance of libcrux_ml_kem.hash_functions.portable.shake128_squeeze_first_three_blocks_4a
with const generics
- K= 3
*/
Eurydice_arr_7e
libcrux_ml_kem_hash_functions_portable_shake128_squeeze_first_three_blocks_4a_78(
  Eurydice_arr_1b0 *self
)
{
  return shake128_squeeze_first_three_blocks_78(self);
}

/**
 If `bytes` contains a set of uniformly random bytes, this function
 uniformly samples a ring element `â` that is treated as being the NTT representation
 of the corresponding polynomial `a`.

 Since rejection sampling is used, it is possible the supplied bytes are
 not enough to sample the element, in which case an `Err` is returned and the
 caller must try again with a fresh set of bytes.

 This function <strong>partially</strong> implements <strong>Algorithm 6</strong> of the NIST FIPS 203 standard,
 We say "partially" because this implementation only accepts a finite set of
 bytes as input and returns an error if the set is not enough; Algorithm 6 of
 the FIPS 203 standard on the other hand samples from an infinite stream of bytes
 until the ring element is filled. Algorithm 6 is reproduced below:

 ```plaintext
 Input: byte stream B ∈ 𝔹*.
 Output: array â ∈ ℤ₂₅₆.

 i ← 0
 j ← 0
 while j < 256 do
     d₁ ← B[i] + 256·(B[i+1] mod 16)
     d₂ ← ⌊B[i+1]/16⌋ + 16·B[i+2]
     if d₁ < q then
         â[j] ← d₁
         j ← j + 1
     end if
     if d₂ < q and j < 256 then
         â[j] ← d₂
         j ← j + 1
     end if
     i ← i + 3
 end while
 return â
 ```

 The NIST FIPS 203 standard can be found at
 <https://csrc.nist.gov/pubs/fips/203/ipd>.
*/
/**
A monomorphic instance of libcrux_ml_kem.sampling.sample_from_uniform_distribution_next
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
- N= 504
*/
static KRML_MUSTINLINE bool
sample_from_uniform_distribution_next_b6(
  const Eurydice_arr_7e *randomness,
  Eurydice_arr_eb0 *sampled_coefficients,
  Eurydice_arr_b1 *out
)
{
  KRML_MAYBE_FOR3(i0,
    (size_t)0U,
    (size_t)3U,
    (size_t)1U,
    size_t i1 = i0;
    for (size_t i = (size_t)0U; i < (size_t)504U / (size_t)24U; i++)
    {
      size_t r = i;
      if (sampled_coefficients->data[i1] < LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT)
      {
        size_t
        sampled =
          libcrux_ml_kem_vector_portable_rej_sample_b8(Eurydice_array_to_subslice_shared_d46(&randomness->data[i1],
              (
                KRML_CLITERAL(core_ops_range_Range_87){
                  .start = r * (size_t)24U,
                  .end = r * (size_t)24U + (size_t)24U
                }
              )),
            Eurydice_array_to_subslice_mut_e7(&out->data[i1],
              (
                KRML_CLITERAL(core_ops_range_Range_87){
                  .start = sampled_coefficients->data[i1],
                  .end = sampled_coefficients->data[i1] + (size_t)16U
                }
              )));
        size_t uu____0 = i1;
        sampled_coefficients->data[uu____0] += sampled;
      }
    });
  bool done = true;
  KRML_MAYBE_FOR3(i,
    (size_t)0U,
    (size_t)3U,
    (size_t)1U,
    size_t i0 = i;
    if (sampled_coefficients->data[i0] >= LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT)
    {
      sampled_coefficients->data[i0] = LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT;
    }
    else
    {
      done = false;
    });
  return done;
}

/**
A monomorphic instance of libcrux_ml_kem.hash_functions.portable.shake128_squeeze_next_block
with const generics
- K= 3
*/
static inline Eurydice_arr_2c shake128_squeeze_next_block_78(Eurydice_arr_1b0 *st)
{
  Eurydice_arr_2c
  out = { .data = { { .data = { 0U } }, { .data = { 0U } }, { .data = { 0U } } } };
  KRML_MAYBE_FOR3(i,
    (size_t)0U,
    (size_t)3U,
    (size_t)1U,
    size_t i0 = i;
    libcrux_sha3_portable_incremental_shake128_squeeze_next_block(&st->data[i0],
      Eurydice_array_to_slice_mut_2c(&out.data[i0])););
  return out;
}

/**
This function found in impl {libcrux_ml_kem::hash_functions::Hash<K> for libcrux_ml_kem::hash_functions::portable::PortableHash<K>}
*/
/**
A monomorphic instance of libcrux_ml_kem.hash_functions.portable.shake128_squeeze_next_block_4a
with const generics
- K= 3
*/
Eurydice_arr_2c
libcrux_ml_kem_hash_functions_portable_shake128_squeeze_next_block_4a_78(
  Eurydice_arr_1b0 *self
)
{
  return shake128_squeeze_next_block_78(self);
}

/**
 If `bytes` contains a set of uniformly random bytes, this function
 uniformly samples a ring element `â` that is treated as being the NTT representation
 of the corresponding polynomial `a`.

 Since rejection sampling is used, it is possible the supplied bytes are
 not enough to sample the element, in which case an `Err` is returned and the
 caller must try again with a fresh set of bytes.

 This function <strong>partially</strong> implements <strong>Algorithm 6</strong> of the NIST FIPS 203 standard,
 We say "partially" because this implementation only accepts a finite set of
 bytes as input and returns an error if the set is not enough; Algorithm 6 of
 the FIPS 203 standard on the other hand samples from an infinite stream of bytes
 until the ring element is filled. Algorithm 6 is reproduced below:

 ```plaintext
 Input: byte stream B ∈ 𝔹*.
 Output: array â ∈ ℤ₂₅₆.

 i ← 0
 j ← 0
 while j < 256 do
     d₁ ← B[i] + 256·(B[i+1] mod 16)
     d₂ ← ⌊B[i+1]/16⌋ + 16·B[i+2]
     if d₁ < q then
         â[j] ← d₁
         j ← j + 1
     end if
     if d₂ < q and j < 256 then
         â[j] ← d₂
         j ← j + 1
     end if
     i ← i + 3
 end while
 return â
 ```

 The NIST FIPS 203 standard can be found at
 <https://csrc.nist.gov/pubs/fips/203/ipd>.
*/
/**
A monomorphic instance of libcrux_ml_kem.sampling.sample_from_uniform_distribution_next
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
- N= 168
*/
static KRML_MUSTINLINE bool
sample_from_uniform_distribution_next_b60(
  const Eurydice_arr_2c *randomness,
  Eurydice_arr_eb0 *sampled_coefficients,
  Eurydice_arr_b1 *out
)
{
  KRML_MAYBE_FOR3(i0,
    (size_t)0U,
    (size_t)3U,
    (size_t)1U,
    size_t i1 = i0;
    for (size_t i = (size_t)0U; i < (size_t)168U / (size_t)24U; i++)
    {
      size_t r = i;
      if (sampled_coefficients->data[i1] < LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT)
      {
        size_t
        sampled =
          libcrux_ml_kem_vector_portable_rej_sample_b8(Eurydice_array_to_subslice_shared_d40(&randomness->data[i1],
              (
                KRML_CLITERAL(core_ops_range_Range_87){
                  .start = r * (size_t)24U,
                  .end = r * (size_t)24U + (size_t)24U
                }
              )),
            Eurydice_array_to_subslice_mut_e7(&out->data[i1],
              (
                KRML_CLITERAL(core_ops_range_Range_87){
                  .start = sampled_coefficients->data[i1],
                  .end = sampled_coefficients->data[i1] + (size_t)16U
                }
              )));
        size_t uu____0 = i1;
        sampled_coefficients->data[uu____0] += sampled;
      }
    });
  bool done = true;
  KRML_MAYBE_FOR3(i,
    (size_t)0U,
    (size_t)3U,
    (size_t)1U,
    size_t i0 = i;
    if (sampled_coefficients->data[i0] >= LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT)
    {
      sampled_coefficients->data[i0] = LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT;
    }
    else
    {
      done = false;
    });
  return done;
}

/**
This function found in impl {core::ops::function::FnMut<([i16; 272usize]), libcrux_ml_kem::polynomial::PolynomialRingElement<Vector>[TraitClause@0, TraitClause@2]> for libcrux_ml_kem::sampling::sample_from_xof::closure<Vector, Hasher, K>[TraitClause@0, TraitClause@1, TraitClause@2, TraitClause@3]}
*/
/**
A monomorphic instance of libcrux_ml_kem.sampling.sample_from_xof.call_mut_0a
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$3size_t]]
with const generics
- K= 3
*/
static Eurydice_arr_9e call_mut_0a_91(Eurydice_arr_5b tupled_args)
{
  Eurydice_arr_5b s = tupled_args;
  return
    from_i16_array_d6_ea(Eurydice_array_to_subslice_shared_e70(&s,
        (KRML_CLITERAL(core_ops_range_Range_87){ .start = (size_t)0U, .end = (size_t)256U })));
}

/**
A monomorphic instance of libcrux_ml_kem.sampling.sample_from_xof
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$3size_t]]
with const generics
- K= 3
*/
static KRML_MUSTINLINE Eurydice_arr_bb0 sample_from_xof_91(const Eurydice_arr_810 *seeds)
{
  Eurydice_arr_eb0 sampled_coefficients = { .data = { 0U } };
  Eurydice_arr_b1
  out = { .data = { { .data = { 0U } }, { .data = { 0U } }, { .data = { 0U } } } };
  Eurydice_arr_1b0
  xof_state = libcrux_ml_kem_hash_functions_portable_shake128_init_absorb_final_4a_78(seeds);
  Eurydice_arr_7e
  randomness0 =
    libcrux_ml_kem_hash_functions_portable_shake128_squeeze_first_three_blocks_4a_78(&xof_state);
  bool
  done = sample_from_uniform_distribution_next_b6(&randomness0, &sampled_coefficients, &out);
  while (true)
  {
    if (done)
    {
      break;
    }
    else
    {
      Eurydice_arr_2c
      randomness =
        libcrux_ml_kem_hash_functions_portable_shake128_squeeze_next_block_4a_78(&xof_state);
      done = sample_from_uniform_distribution_next_b60(&randomness, &sampled_coefficients, &out);
    }
  }
  Eurydice_arr_bb0 arr_mapped_str;
  KRML_MAYBE_FOR3(i,
    (size_t)0U,
    (size_t)3U,
    (size_t)1U,
    arr_mapped_str.data[i] = call_mut_0a_91(out.data[i]););
  return arr_mapped_str;
}

/**
A monomorphic instance of libcrux_ml_kem.matrix.sample_matrix_A
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$3size_t]]
with const generics
- K= 3
*/
static KRML_MUSTINLINE void
sample_matrix_A_91(Eurydice_arr_c10 *A_transpose, const Eurydice_arr_31 *seed, bool transpose)
{
  KRML_MAYBE_FOR3(i0,
    (size_t)0U,
    (size_t)3U,
    (size_t)1U,
    size_t i1 = i0;
    Eurydice_arr_810 seeds;
    Eurydice_arr_31 repeat_expression[3U];
    KRML_MAYBE_FOR3(i,
      (size_t)0U,
      (size_t)3U,
      (size_t)1U,
      repeat_expression[i] =
        core_array__core__clone__Clone_for__T__N___clone((size_t)34U,
          seed,
          uint8_t,
          Eurydice_arr_31););
    memcpy(seeds.data, repeat_expression, (size_t)3U * sizeof (Eurydice_arr_31));
    KRML_MAYBE_FOR3(i,
      (size_t)0U,
      (size_t)3U,
      (size_t)1U,
      size_t j = i;
      seeds.data[j].data[32U] = (uint8_t)i1;
      seeds.data[j].data[33U] = (uint8_t)j;);
    Eurydice_arr_bb0 sampled = sample_from_xof_91(&seeds);
    KRML_MAYBE_FOR3(i,
      (size_t)0U,
      (size_t)3U,
      (size_t)1U,
      size_t j = i;
      Eurydice_arr_9e sample = sampled.data[j];
      if (transpose)
      {
        A_transpose->data[j].data[i1] = sample;
      }
      else
      {
        A_transpose->data[i1].data[j] = sample;
      }););
}

/**
This function found in impl {libcrux_ml_kem::hash_functions::Hash<K> for libcrux_ml_kem::hash_functions::portable::PortableHash<K>}
*/
/**
A monomorphic instance of libcrux_ml_kem.hash_functions.portable.H_4a
with const generics
- K= 3
*/
static inline Eurydice_arr_ec H_4a_78(Eurydice_borrow_slice_u8 input)
{
  return libcrux_ml_kem_hash_functions_portable_H(input);
}

/**
 Generate an unpacked key from a serialized key.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.unpack_public_key
with types libcrux_ml_kem_hash_functions_portable_PortableHash[[$3size_t]], libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
- T_AS_NTT_ENCODED_SIZE= 1152
- PUBLIC_KEY_SIZE= 1184
*/
void
libcrux_ml_kem_ind_cca_unpacked_unpack_public_key_22(
  const Eurydice_arr_5f *public_key,
  libcrux_ml_kem_ind_cca_unpacked_MlKemPublicKeyUnpacked_51 *unpacked_public_key
)
{
  Eurydice_borrow_slice_u8
  uu____0 = Eurydice_array_to_subslice_to_shared_213(public_key, (size_t)1152U);
  deserialize_ring_elements_reduced_68(uu____0,
    &unpacked_public_key->ind_cpa_public_key.t_as_ntt);
  unpacked_public_key->ind_cpa_public_key.seed_for_A =
    libcrux_ml_kem_utils_into_padded_array_ce(Eurydice_array_to_subslice_from_shared_5f4(public_key,
        (size_t)1152U));
  Eurydice_arr_c10 *uu____2 = &unpacked_public_key->ind_cpa_public_key.A;
  /* original Rust expression is not an lvalue in C */
  Eurydice_arr_31
  lvalue =
    libcrux_ml_kem_utils_into_padded_array_de(Eurydice_array_to_subslice_from_shared_5f4(public_key,
        (size_t)1152U));
  sample_matrix_A_91(uu____2, &lvalue, false);
  Eurydice_arr_ec
  uu____3 =
    H_4a_78(Eurydice_array_to_slice_shared_ff(libcrux_ml_kem_types_as_slice_e6_3d(public_key)));
  unpacked_public_key->public_key_hash = uu____3;
}

/**
 Get the serialized public key.
*/
/**
This function found in impl {libcrux_ml_kem::ind_cca::unpacked::MlKemKeyPairUnpacked<Vector, K>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.public_key_11
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
*/
const
libcrux_ml_kem_ind_cca_unpacked_MlKemPublicKeyUnpacked_51
*libcrux_ml_kem_ind_cca_unpacked_public_key_11_68(
  const libcrux_ml_kem_mlkem768_portable_unpacked_MlKem768KeyPairUnpacked *self
)
{
  return &self->public_key;
}

/**
This function found in impl {core::clone::Clone for libcrux_ml_kem::ind_cpa::unpacked::IndCpaPublicKeyUnpacked<Vector, K>[TraitClause@0, TraitClause@2]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.unpacked.clone_91
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
*/
static inline libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_51
clone_91_68(const libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_51 *self)
{
  Eurydice_arr_bb0
  uu____0 =
    core_array__core__clone__Clone_for__T__N___clone((size_t)3U,
      &self->t_as_ntt,
      Eurydice_arr_9e,
      Eurydice_arr_bb0);
  Eurydice_arr_ec
  uu____1 =
    core_array__core__clone__Clone_for__T__N___clone((size_t)32U,
      &self->seed_for_A,
      uint8_t,
      Eurydice_arr_ec);
  return
    (
      KRML_CLITERAL(libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_51){
        .t_as_ntt = uu____0,
        .seed_for_A = uu____1,
        .A = core_array__core__clone__Clone_for__T__N___clone((size_t)3U,
          &self->A,
          Eurydice_arr_bb0,
          Eurydice_arr_c10)
      }
    );
}

/**
This function found in impl {core::clone::Clone for libcrux_ml_kem::ind_cca::unpacked::MlKemPublicKeyUnpacked<Vector, K>[TraitClause@0, TraitClause@2]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.clone_d7
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
*/
libcrux_ml_kem_ind_cca_unpacked_MlKemPublicKeyUnpacked_51
libcrux_ml_kem_ind_cca_unpacked_clone_d7_68(
  const libcrux_ml_kem_ind_cca_unpacked_MlKemPublicKeyUnpacked_51 *self
)
{
  libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_51
  uu____0 = clone_91_68(&self->ind_cpa_public_key);
  return
    (
      KRML_CLITERAL(libcrux_ml_kem_ind_cca_unpacked_MlKemPublicKeyUnpacked_51){
        .ind_cpa_public_key = uu____0,
        .public_key_hash = core_array__core__clone__Clone_for__T__N___clone((size_t)32U,
          &self->public_key_hash,
          uint8_t,
          Eurydice_arr_ec)
      }
    );
}

/**
 Call [`serialize_uncompressed_ring_element`] for each ring element.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.serialize_vector
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
*/
static KRML_MUSTINLINE void
serialize_vector_68(const Eurydice_arr_bb0 *key, Eurydice_mut_borrow_slice_u8 out)
{
  KRML_MAYBE_FOR3(i,
    (size_t)0U,
    (size_t)3U,
    (size_t)1U,
    size_t i0 = i;
    Eurydice_arr_9e re = key->data[i0];
    Eurydice_mut_borrow_slice_u8
    uu____0 =
      Eurydice_slice_subslice_mut_c8(out,
        (
          KRML_CLITERAL(core_ops_range_Range_87){
            .start = i0 * LIBCRUX_ML_KEM_CONSTANTS_BYTES_PER_RING_ELEMENT,
            .end = (i0 + (size_t)1U) * LIBCRUX_ML_KEM_CONSTANTS_BYTES_PER_RING_ELEMENT
          }
        ));
    /* original Rust expression is not an lvalue in C */
    Eurydice_arr_b20 lvalue = serialize_uncompressed_ring_element_ea(&re);
    Eurydice_slice_copy(uu____0, Eurydice_array_to_slice_shared_a9(&lvalue), uint8_t););
}

/**
 Concatenate `t` and `ρ` into the public key.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.serialize_public_key_mut
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
- PUBLIC_KEY_SIZE= 1184
*/
static KRML_MUSTINLINE void
serialize_public_key_mut_b6(
  const Eurydice_arr_bb0 *t_as_ntt,
  Eurydice_borrow_slice_u8 seed_for_a,
  Eurydice_arr_5f *serialized
)
{
  serialize_vector_68(t_as_ntt,
    Eurydice_array_to_subslice_mut_d419(serialized,
      (
        KRML_CLITERAL(core_ops_range_Range_87){
          .start = (size_t)0U,
          .end = libcrux_ml_kem_constants_ranked_bytes_per_ring_element((size_t)3U)
        }
      )));
  Eurydice_slice_copy(Eurydice_array_to_subslice_from_mut_5f6(serialized,
      libcrux_ml_kem_constants_ranked_bytes_per_ring_element((size_t)3U)),
    seed_for_a,
    uint8_t);
}

/**
 Get the serialized public key.
*/
/**
This function found in impl {libcrux_ml_kem::ind_cca::unpacked::MlKemPublicKeyUnpacked<Vector, K>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.serialized_mut_dd
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
- PUBLIC_KEY_SIZE= 1184
*/
void
libcrux_ml_kem_ind_cca_unpacked_serialized_mut_dd_b6(
  const libcrux_ml_kem_ind_cca_unpacked_MlKemPublicKeyUnpacked_51 *self,
  Eurydice_arr_5f *serialized
)
{
  serialize_public_key_mut_b6(&self->ind_cpa_public_key.t_as_ntt,
    Eurydice_array_to_slice_shared_01(&self->ind_cpa_public_key.seed_for_A),
    serialized);
}

/**
 Get the serialized public key.
*/
/**
This function found in impl {libcrux_ml_kem::ind_cca::unpacked::MlKemKeyPairUnpacked<Vector, K>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.serialized_public_key_mut_11
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
- PUBLIC_KEY_SIZE= 1184
*/
void
libcrux_ml_kem_ind_cca_unpacked_serialized_public_key_mut_11_b6(
  const libcrux_ml_kem_mlkem768_portable_unpacked_MlKem768KeyPairUnpacked *self,
  Eurydice_arr_5f *serialized
)
{
  libcrux_ml_kem_ind_cca_unpacked_serialized_mut_dd_b6(&self->public_key, serialized);
}

/**
 Concatenate `t` and `ρ` into the public key.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.serialize_public_key
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
- PUBLIC_KEY_SIZE= 1184
*/
static KRML_MUSTINLINE Eurydice_arr_5f
serialize_public_key_b6(const Eurydice_arr_bb0 *t_as_ntt, Eurydice_borrow_slice_u8 seed_for_a)
{
  Eurydice_arr_5f public_key_serialized = { .data = { 0U } };
  serialize_public_key_mut_b6(t_as_ntt, seed_for_a, &public_key_serialized);
  return public_key_serialized;
}

/**
 Get the serialized public key.
*/
/**
This function found in impl {libcrux_ml_kem::ind_cca::unpacked::MlKemPublicKeyUnpacked<Vector, K>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.serialized_dd
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
- PUBLIC_KEY_SIZE= 1184
*/
static KRML_MUSTINLINE Eurydice_arr_5f
serialized_dd_b6(const libcrux_ml_kem_ind_cca_unpacked_MlKemPublicKeyUnpacked_51 *self)
{
  return
    libcrux_ml_kem_types_from_51_3d(serialize_public_key_b6(&self->ind_cpa_public_key.t_as_ntt,
        Eurydice_array_to_slice_shared_01(&self->ind_cpa_public_key.seed_for_A)));
}

/**
 Get the serialized public key.
*/
/**
This function found in impl {libcrux_ml_kem::ind_cca::unpacked::MlKemKeyPairUnpacked<Vector, K>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.serialized_public_key_11
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
- PUBLIC_KEY_SIZE= 1184
*/
Eurydice_arr_5f
libcrux_ml_kem_ind_cca_unpacked_serialized_public_key_11_b6(
  const libcrux_ml_kem_mlkem768_portable_unpacked_MlKem768KeyPairUnpacked *self
)
{
  return serialized_dd_b6(&self->public_key);
}

/**
 Serialize the secret key from the unpacked key pair generation.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.serialize_unpacked_secret_key
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
- PRIVATE_KEY_SIZE= 1152
- PUBLIC_KEY_SIZE= 1184
*/
static libcrux_ml_kem_utils_extraction_helper_Keypair768
serialize_unpacked_secret_key_30(
  const libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_51 *public_key,
  const Eurydice_arr_bb0 *private_key
)
{
  Eurydice_arr_5f
  public_key_serialized =
    serialize_public_key_b6(&public_key->t_as_ntt,
      Eurydice_array_to_slice_shared_01(&public_key->seed_for_A));
  Eurydice_arr_0e secret_key_serialized = { .data = { 0U } };
  serialize_vector_68(private_key, Eurydice_array_to_slice_mut_f4(&secret_key_serialized));
  return
    (
      KRML_CLITERAL(libcrux_ml_kem_utils_extraction_helper_Keypair768){
        .fst = secret_key_serialized,
        .snd = public_key_serialized
      }
    );
}

/**
 Serialize the secret key.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.serialize_kem_secret_key_mut
with types libcrux_ml_kem_hash_functions_portable_PortableHash[[$3size_t]]
with const generics
- K= 3
- SERIALIZED_KEY_LEN= 2400
*/
void
libcrux_ml_kem_ind_cca_serialize_kem_secret_key_mut_52(
  Eurydice_borrow_slice_u8 private_key,
  Eurydice_borrow_slice_u8 public_key,
  Eurydice_borrow_slice_u8 implicit_rejection_value,
  Eurydice_arr_7d *serialized
)
{
  size_t pointer = (size_t)0U;
  Eurydice_slice_copy(Eurydice_array_to_subslice_mut_d420(serialized,
      (
        KRML_CLITERAL(core_ops_range_Range_87){
          .start = pointer,
          .end = pointer + private_key.meta
        }
      )),
    private_key,
    uint8_t);
  pointer += private_key.meta;
  Eurydice_slice_copy(Eurydice_array_to_subslice_mut_d420(serialized,
      (KRML_CLITERAL(core_ops_range_Range_87){ .start = pointer, .end = pointer + public_key.meta })),
    public_key,
    uint8_t);
  pointer += public_key.meta;
  Eurydice_mut_borrow_slice_u8
  uu____0 =
    Eurydice_array_to_subslice_mut_d420(serialized,
      (
        KRML_CLITERAL(core_ops_range_Range_87){
          .start = pointer,
          .end = pointer + LIBCRUX_ML_KEM_CONSTANTS_H_DIGEST_SIZE
        }
      ));
  /* original Rust expression is not an lvalue in C */
  Eurydice_arr_ec lvalue = H_4a_78(public_key);
  Eurydice_slice_copy(uu____0, Eurydice_array_to_slice_shared_01(&lvalue), uint8_t);
  pointer += LIBCRUX_ML_KEM_CONSTANTS_H_DIGEST_SIZE;
  Eurydice_slice_copy(Eurydice_array_to_subslice_mut_d420(serialized,
      (
        KRML_CLITERAL(core_ops_range_Range_87){
          .start = pointer,
          .end = pointer + implicit_rejection_value.meta
        }
      )),
    implicit_rejection_value,
    uint8_t);
}

/**
 Get the serialized private key.
*/
/**
This function found in impl {libcrux_ml_kem::ind_cca::unpacked::MlKemKeyPairUnpacked<Vector, K>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.serialized_private_key_mut_11
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
- CPA_PRIVATE_KEY_SIZE= 1152
- PRIVATE_KEY_SIZE= 2400
- PUBLIC_KEY_SIZE= 1184
*/
void
libcrux_ml_kem_ind_cca_unpacked_serialized_private_key_mut_11_21(
  const libcrux_ml_kem_mlkem768_portable_unpacked_MlKem768KeyPairUnpacked *self,
  Eurydice_arr_7d *serialized
)
{
  libcrux_ml_kem_utils_extraction_helper_Keypair768
  uu____0 =
    serialize_unpacked_secret_key_30(&self->public_key.ind_cpa_public_key,
      &self->private_key.ind_cpa_private_key);
  Eurydice_arr_0e ind_cpa_private_key = uu____0.fst;
  Eurydice_arr_5f ind_cpa_public_key = uu____0.snd;
  libcrux_ml_kem_ind_cca_serialize_kem_secret_key_mut_52(Eurydice_array_to_slice_shared_f4(&ind_cpa_private_key),
    Eurydice_array_to_slice_shared_ff(&ind_cpa_public_key),
    Eurydice_array_to_slice_shared_01(&self->private_key.implicit_rejection_value),
    serialized);
}

/**
 Get the serialized private key.
*/
/**
This function found in impl {libcrux_ml_kem::ind_cca::unpacked::MlKemKeyPairUnpacked<Vector, K>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.serialized_private_key_11
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
- CPA_PRIVATE_KEY_SIZE= 1152
- PRIVATE_KEY_SIZE= 2400
- PUBLIC_KEY_SIZE= 1184
*/
Eurydice_arr_7d
libcrux_ml_kem_ind_cca_unpacked_serialized_private_key_11_21(
  const libcrux_ml_kem_mlkem768_portable_unpacked_MlKem768KeyPairUnpacked *self
)
{
  Eurydice_arr_7d sk = libcrux_ml_kem_types_default_d3_79();
  libcrux_ml_kem_ind_cca_unpacked_serialized_private_key_mut_11_21(self, &sk);
  return sk;
}

/**
 Call [`deserialize_to_uncompressed_ring_element`] for each ring element.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.deserialize_vector
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
*/
static KRML_MUSTINLINE void
deserialize_vector_68(Eurydice_borrow_slice_u8 secret_key, Eurydice_arr_bb0 *secret_as_ntt)
{
  KRML_MAYBE_FOR3(i,
    (size_t)0U,
    (size_t)3U,
    (size_t)1U,
    size_t i0 = i;
    Eurydice_arr_9e
    uu____0 =
      deserialize_to_uncompressed_ring_element_ea(Eurydice_slice_subslice_shared_c8(secret_key,
          (
            KRML_CLITERAL(core_ops_range_Range_87){
              .start = i0 * LIBCRUX_ML_KEM_CONSTANTS_BYTES_PER_RING_ELEMENT,
              .end = (i0 + (size_t)1U) * LIBCRUX_ML_KEM_CONSTANTS_BYTES_PER_RING_ELEMENT
            }
          )));
    secret_as_ntt->data[i0] = uu____0;);
}

/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.build_unpacked_public_key_mut
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$3size_t]]
with const generics
- K= 3
- T_AS_NTT_ENCODED_SIZE= 1152
*/
static KRML_MUSTINLINE void
build_unpacked_public_key_mut_05(
  Eurydice_borrow_slice_u8 public_key,
  libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_51 *unpacked_public_key
)
{
  deserialize_ring_elements_reduced_68(Eurydice_slice_subslice_to_shared_72(public_key,
      (size_t)1152U),
    &unpacked_public_key->t_as_ntt);
  Eurydice_borrow_slice_u8
  seed = Eurydice_slice_subslice_from_shared_6d(public_key, (size_t)1152U);
  Eurydice_arr_c10 *uu____0 = &unpacked_public_key->A;
  /* original Rust expression is not an lvalue in C */
  Eurydice_arr_31 lvalue = libcrux_ml_kem_utils_into_padded_array_de(seed);
  sample_matrix_A_91(uu____0, &lvalue, false);
}

/**
 Take a serialized private key and generate an unpacked key pair from it.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.keys_from_private_key
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
- SECRET_KEY_SIZE= 2400
- CPA_SECRET_KEY_SIZE= 1152
- PUBLIC_KEY_SIZE= 1184
- T_AS_NTT_ENCODED_SIZE= 1152
*/
void
libcrux_ml_kem_ind_cca_unpacked_keys_from_private_key_01(
  const Eurydice_arr_7d *private_key,
  libcrux_ml_kem_mlkem768_portable_unpacked_MlKem768KeyPairUnpacked *key_pair
)
{
  Eurydice_borrow_slice_u8_x4
  uu____0 =
    libcrux_ml_kem_types_unpack_private_key_64(Eurydice_array_to_slice_shared_51(private_key));
  Eurydice_borrow_slice_u8 ind_cpa_secret_key = uu____0.fst;
  Eurydice_borrow_slice_u8 ind_cpa_public_key = uu____0.snd;
  Eurydice_borrow_slice_u8 ind_cpa_public_key_hash = uu____0.thd;
  Eurydice_borrow_slice_u8 implicit_rejection_value = uu____0.f3;
  deserialize_vector_68(ind_cpa_secret_key, &key_pair->private_key.ind_cpa_private_key);
  build_unpacked_public_key_mut_05(ind_cpa_public_key, &key_pair->public_key.ind_cpa_public_key);
  Eurydice_slice_copy(Eurydice_array_to_slice_mut_01(&key_pair->public_key.public_key_hash),
    ind_cpa_public_key_hash,
    uint8_t);
  Eurydice_slice_copy(Eurydice_array_to_slice_mut_01(&key_pair->private_key.implicit_rejection_value),
    implicit_rejection_value,
    uint8_t);
  Eurydice_slice_copy(Eurydice_array_to_slice_mut_01(&key_pair->public_key.ind_cpa_public_key.seed_for_A),
    Eurydice_slice_subslice_from_shared_6d(ind_cpa_public_key, (size_t)1152U),
    uint8_t);
}

/**
This function found in impl {core::default::Default for libcrux_ml_kem::ind_cpa::unpacked::IndCpaPrivateKeyUnpacked<Vector, K>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.unpacked.default_70
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
*/
static Eurydice_arr_bb0 default_70_68(void)
{
  Eurydice_arr_bb0 lit;
  Eurydice_arr_9e repeat_expression[3U];
  KRML_MAYBE_FOR3(i, (size_t)0U, (size_t)3U, (size_t)1U, repeat_expression[i] = ZERO_d6_ea(););
  memcpy(lit.data, repeat_expression, (size_t)3U * sizeof (Eurydice_arr_9e));
  return lit;
}

/**
This function found in impl {core::default::Default for libcrux_ml_kem::ind_cpa::unpacked::IndCpaPublicKeyUnpacked<Vector, K>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.unpacked.default_8b
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
*/
static libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_51 default_8b_68(void)
{
  Eurydice_arr_bb0 uu____0;
  Eurydice_arr_9e repeat_expression0[3U];
  KRML_MAYBE_FOR3(i, (size_t)0U, (size_t)3U, (size_t)1U, repeat_expression0[i] = ZERO_d6_ea(););
  memcpy(uu____0.data, repeat_expression0, (size_t)3U * sizeof (Eurydice_arr_9e));
  Eurydice_arr_ec uu____1 = { .data = { 0U } };
  libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_51 lit0;
  lit0.t_as_ntt = uu____0;
  lit0.seed_for_A = uu____1;
  Eurydice_arr_bb0 repeat_expression1[3U];
  KRML_MAYBE_FOR3(i0,
    (size_t)0U,
    (size_t)3U,
    (size_t)1U,
    Eurydice_arr_bb0 lit;
    Eurydice_arr_9e repeat_expression[3U];
    KRML_MAYBE_FOR3(i, (size_t)0U, (size_t)3U, (size_t)1U, repeat_expression[i] = ZERO_d6_ea(););
    memcpy(lit.data, repeat_expression, (size_t)3U * sizeof (Eurydice_arr_9e));
    repeat_expression1[i0] = lit;);
  memcpy(lit0.A.data, repeat_expression1, (size_t)3U * sizeof (Eurydice_arr_bb0));
  return lit0;
}

/**
This function found in impl {core::default::Default for libcrux_ml_kem::ind_cca::unpacked::MlKemPublicKeyUnpacked<Vector, K>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.default_30
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
*/
libcrux_ml_kem_ind_cca_unpacked_MlKemPublicKeyUnpacked_51
libcrux_ml_kem_ind_cca_unpacked_default_30_68(void)
{
  return
    (
      KRML_CLITERAL(libcrux_ml_kem_ind_cca_unpacked_MlKemPublicKeyUnpacked_51){
        .ind_cpa_public_key = default_8b_68(),
        .public_key_hash = { .data = { 0U } }
      }
    );
}

/**
This function found in impl {core::default::Default for libcrux_ml_kem::ind_cca::unpacked::MlKemKeyPairUnpacked<Vector, K>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.default_7b
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
*/
libcrux_ml_kem_mlkem768_portable_unpacked_MlKem768KeyPairUnpacked
libcrux_ml_kem_ind_cca_unpacked_default_7b_68(void)
{
  libcrux_ml_kem_ind_cca_unpacked_MlKemPrivateKeyUnpacked_51
  uu____0 =
    { .ind_cpa_private_key = default_70_68(), .implicit_rejection_value = { .data = { 0U } } };
  return
    (
      KRML_CLITERAL(libcrux_ml_kem_mlkem768_portable_unpacked_MlKem768KeyPairUnpacked){
        .private_key = uu____0,
        .public_key = libcrux_ml_kem_ind_cca_unpacked_default_30_68()
      }
    );
}

/**
This function found in impl {libcrux_ml_kem::hash_functions::Hash<K> for libcrux_ml_kem::hash_functions::portable::PortableHash<K>}
*/
/**
A monomorphic instance of libcrux_ml_kem.hash_functions.portable.G_4a
with const generics
- K= 3
*/
static inline Eurydice_arr_c7 G_4a_78(Eurydice_borrow_slice_u8 input)
{
  return libcrux_ml_kem_hash_functions_portable_G(input);
}

/**
This function found in impl {libcrux_ml_kem::variant::Variant for libcrux_ml_kem::variant::MlKem}
*/
/**
A monomorphic instance of libcrux_ml_kem.variant.cpa_keygen_seed_39
with types libcrux_ml_kem_hash_functions_portable_PortableHash[[$3size_t]]
with const generics
- K= 3
*/
static KRML_MUSTINLINE Eurydice_arr_c7
cpa_keygen_seed_39_13(Eurydice_borrow_slice_u8 key_generation_seed)
{
  Eurydice_arr_fa seed = { .data = { 0U } };
  Eurydice_slice_copy(Eurydice_array_to_subslice_mut_d412(&seed,
      (
        KRML_CLITERAL(core_ops_range_Range_87){
          .start = (size_t)0U,
          .end = LIBCRUX_ML_KEM_CONSTANTS_CPA_PKE_KEY_GENERATION_SEED_SIZE
        }
      )),
    key_generation_seed,
    uint8_t);
  seed.data[LIBCRUX_ML_KEM_CONSTANTS_CPA_PKE_KEY_GENERATION_SEED_SIZE] = (uint8_t)(size_t)3U;
  return G_4a_78(Eurydice_array_to_slice_shared_b5(&seed));
}

/**
A monomorphic instance of libcrux_ml_kem.hash_functions.portable.PRFxN
with const generics
- K= 3
- LEN= 128
*/
static inline Eurydice_arr_58 PRFxN_3b(const Eurydice_arr_801 *input)
{
  Eurydice_arr_58
  out = { .data = { { .data = { 0U } }, { .data = { 0U } }, { .data = { 0U } } } };
  KRML_MAYBE_FOR3(i,
    (size_t)0U,
    (size_t)3U,
    (size_t)1U,
    size_t i0 = i;
    libcrux_sha3_portable_shake256(Eurydice_array_to_slice_mut_78(&out.data[i0]),
      Eurydice_array_to_slice_shared_b5(&input->data[i0])););
  return out;
}

/**
This function found in impl {libcrux_ml_kem::hash_functions::Hash<K> for libcrux_ml_kem::hash_functions::portable::PortableHash<K>}
*/
/**
A monomorphic instance of libcrux_ml_kem.hash_functions.portable.PRFxN_4a
with const generics
- K= 3
- LEN= 128
*/
static inline Eurydice_arr_58 PRFxN_4a_3b(const Eurydice_arr_801 *input)
{
  return PRFxN_3b(input);
}

/**
 Sample a vector of ring elements from a centered binomial distribution and
 convert them into their NTT representations.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.sample_vector_cbd_then_ntt
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$3size_t]]
with const generics
- K= 3
- ETA= 2
- ETA_RANDOMNESS_SIZE= 128
*/
static KRML_MUSTINLINE uint8_t
sample_vector_cbd_then_ntt_bf(
  Eurydice_arr_bb0 *re_as_ntt,
  const Eurydice_arr_fa *prf_input,
  uint8_t domain_separator
)
{
  Eurydice_arr_801 prf_inputs;
  Eurydice_arr_fa repeat_expression[3U];
  KRML_MAYBE_FOR3(i,
    (size_t)0U,
    (size_t)3U,
    (size_t)1U,
    repeat_expression[i] =
      core_array__core__clone__Clone_for__T__N___clone((size_t)33U,
        prf_input,
        uint8_t,
        Eurydice_arr_fa););
  memcpy(prf_inputs.data, repeat_expression, (size_t)3U * sizeof (Eurydice_arr_fa));
  domain_separator = libcrux_ml_kem_utils_prf_input_inc_78(&prf_inputs, domain_separator);
  Eurydice_arr_58 prf_outputs = PRFxN_4a_3b(&prf_inputs);
  KRML_MAYBE_FOR3(i,
    (size_t)0U,
    (size_t)3U,
    (size_t)1U,
    size_t i0 = i;
    Eurydice_arr_9e
    uu____0 =
      sample_from_binomial_distribution_66(Eurydice_array_to_slice_shared_78(&prf_outputs.data[i0]));
    re_as_ntt->data[i0] = uu____0;
    ntt_binomially_sampled_ring_element_ea(&re_as_ntt->data[i0]););
  return domain_separator;
}

/**
This function found in impl {core::ops::function::FnMut<(usize), libcrux_ml_kem::polynomial::PolynomialRingElement<Vector>[TraitClause@0, TraitClause@3]> for libcrux_ml_kem::ind_cpa::generate_keypair_unpacked::closure<Vector, Hasher, Scheme, K, ETA1, ETA1_RANDOMNESS_SIZE>[TraitClause@0, TraitClause@1, TraitClause@2, TraitClause@3, TraitClause@4, TraitClause@5]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.generate_keypair_unpacked.call_mut_73
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$3size_t]], libcrux_ml_kem_variant_MlKem
with const generics
- K= 3
- ETA1= 2
- ETA1_RANDOMNESS_SIZE= 128
*/
static Eurydice_arr_9e call_mut_73_39(void **_)
{
  return ZERO_d6_ea();
}

/**
 Given two polynomial ring elements `lhs` and `rhs`, compute the pointwise
 sum of their constituent coefficients.
*/
/**
A monomorphic instance of libcrux_ml_kem.polynomial.add_to_ring_element
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
*/
static KRML_MUSTINLINE void
add_to_ring_element_68(Eurydice_arr_9e *myself, const Eurydice_arr_9e *rhs)
{
  KRML_MAYBE_FOR16(i,
    (size_t)0U,
    (size_t)16U,
    (size_t)1U,
    size_t i0 = i;
    Eurydice_arr_d6
    uu____0 = libcrux_ml_kem_vector_portable_add_b8(myself->data[i0], &rhs->data[i0]);
    myself->data[i0] = uu____0;);
}

/**
 Given two polynomial ring elements `lhs` and `rhs`, compute the pointwise
 sum of their constituent coefficients.
*/
/**
This function found in impl {libcrux_ml_kem::polynomial::PolynomialRingElement<Vector>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.polynomial.add_to_ring_element_d6
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
*/
static KRML_MUSTINLINE void
add_to_ring_element_d6_68(Eurydice_arr_9e *self, const Eurydice_arr_9e *rhs)
{
  add_to_ring_element_68(self, rhs);
}

/**
 Compute Â ◦ ŝ + ê
*/
/**
A monomorphic instance of libcrux_ml_kem.matrix.compute_As_plus_e
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
*/
static KRML_MUSTINLINE void
compute_As_plus_e_68(
  Eurydice_arr_bb0 *t_as_ntt,
  const Eurydice_arr_c10 *matrix_A,
  const Eurydice_arr_bb0 *s_as_ntt,
  const Eurydice_arr_bb0 *error_as_ntt
)
{
  KRML_MAYBE_FOR3(i,
    (size_t)0U,
    (size_t)3U,
    (size_t)1U,
    size_t i0 = i;
    const Eurydice_arr_bb0 *row = &matrix_A->data[i0];
    Eurydice_arr_9e uu____0 = ZERO_d6_ea();
    t_as_ntt->data[i0] = uu____0;
    KRML_MAYBE_FOR3(i1,
      (size_t)0U,
      (size_t)3U,
      (size_t)1U,
      size_t j = i1;
      const Eurydice_arr_9e *matrix_element = &row->data[j];
      Eurydice_arr_9e product = ntt_multiply_d6_ea(matrix_element, &s_as_ntt->data[j]);
      add_to_ring_element_d6_68(&t_as_ntt->data[i0], &product););
    add_standard_error_reduce_d6_ea(&t_as_ntt->data[i0], &error_as_ntt->data[i0]););
}

/**
 This function implements most of <strong>Algorithm 12</strong> of the
 NIST FIPS 203 specification; this is the Kyber CPA-PKE key generation algorithm.

 We say "most of" since Algorithm 12 samples the required randomness within
 the function itself, whereas this implementation expects it to be provided
 through the `key_generation_seed` parameter.

 Algorithm 12 is reproduced below:

 ```plaintext
 Output: encryption key ekₚₖₑ ∈ 𝔹^{384k+32}.
 Output: decryption key dkₚₖₑ ∈ 𝔹^{384k}.

 d ←$ B
 (ρ,σ) ← G(d)
 N ← 0
 for (i ← 0; i < k; i++)
     for(j ← 0; j < k; j++)
         Â[i,j] ← SampleNTT(XOF(ρ, i, j))
     end for
 end for
 for(i ← 0; i < k; i++)
     s[i] ← SamplePolyCBD_{η₁}(PRF_{η₁}(σ,N))
     N ← N + 1
 end for
 for(i ← 0; i < k; i++)
     e[i] ← SamplePolyCBD_{η₂}(PRF_{η₂}(σ,N))
     N ← N + 1
 end for
 ŝ ← NTT(s)
 ê ← NTT(e)
 t̂ ← Â◦ŝ + ê
 ekₚₖₑ ← ByteEncode₁₂(t̂) ‖ ρ
 dkₚₖₑ ← ByteEncode₁₂(ŝ)
 ```

 The NIST FIPS 203 standard can be found at
 <https://csrc.nist.gov/pubs/fips/203/ipd>.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.generate_keypair_unpacked
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$3size_t]], libcrux_ml_kem_variant_MlKem
with const generics
- K= 3
- ETA1= 2
- ETA1_RANDOMNESS_SIZE= 128
*/
static KRML_MUSTINLINE void
generate_keypair_unpacked_39(
  Eurydice_borrow_slice_u8 key_generation_seed,
  Eurydice_arr_bb0 *private_key,
  libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_51 *public_key
)
{
  Eurydice_arr_c7 hashed = cpa_keygen_seed_39_13(key_generation_seed);
  Eurydice_borrow_slice_u8_x2
  uu____0 =
    Eurydice_slice_split_at(Eurydice_array_to_slice_shared_17(&hashed),
      (size_t)32U,
      uint8_t,
      Eurydice_borrow_slice_u8_x2);
  Eurydice_borrow_slice_u8 seed_for_A = uu____0.fst;
  Eurydice_borrow_slice_u8 seed_for_secret_and_error = uu____0.snd;
  Eurydice_arr_c10 *uu____1 = &public_key->A;
  /* original Rust expression is not an lvalue in C */
  Eurydice_arr_31 lvalue0 = libcrux_ml_kem_utils_into_padded_array_de(seed_for_A);
  sample_matrix_A_91(uu____1, &lvalue0, true);
  Eurydice_arr_fa
  prf_input = libcrux_ml_kem_utils_into_padded_array_29(seed_for_secret_and_error);
  uint8_t domain_separator = sample_vector_cbd_then_ntt_bf(private_key, &prf_input, 0U);
  Eurydice_arr_bb0 arr_struct;
  KRML_MAYBE_FOR3(i,
    (size_t)0U,
    (size_t)3U,
    (size_t)1U,
    /* original Rust expression is not an lvalue in C */
    void *lvalue = (void *)0U;
    arr_struct.data[i] = call_mut_73_39(&lvalue););
  Eurydice_arr_bb0 error_as_ntt = arr_struct;
  sample_vector_cbd_then_ntt_bf(&error_as_ntt, &prf_input, domain_separator);
  compute_As_plus_e_68(&public_key->t_as_ntt, &public_key->A, &private_key[0U], &error_as_ntt);
  Eurydice_arr_ec arr;
  memcpy(arr.data, seed_for_A.ptr, (size_t)32U * sizeof (uint8_t));
  Eurydice_arr_ec
  uu____2 =
    core_result_unwrap_26_39((
        KRML_CLITERAL(core_result_Result_07){ .tag = core_result_Ok, .val = { .case_Ok = arr } }
      ));
  public_key->seed_for_A = uu____2;
}

/**
This function found in impl {core::ops::function::FnMut<(usize), libcrux_ml_kem::polynomial::PolynomialRingElement<Vector>[TraitClause@0, TraitClause@1]> for libcrux_ml_kem::ind_cca::unpacked::transpose_a::closure::closure<Vector, K>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.transpose_a.closure.call_mut_b4
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
*/
static Eurydice_arr_9e call_mut_b4_68(void **_)
{
  return ZERO_d6_ea();
}

/**
This function found in impl {core::ops::function::FnMut<(usize), [libcrux_ml_kem::polynomial::PolynomialRingElement<Vector>[TraitClause@0, TraitClause@1]; K]> for libcrux_ml_kem::ind_cca::unpacked::transpose_a::closure<Vector, K>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.transpose_a.call_mut_22
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
*/
static Eurydice_arr_bb0 call_mut_22_68(void **_)
{
  Eurydice_arr_bb0 arr_struct;
  KRML_MAYBE_FOR3(i,
    (size_t)0U,
    (size_t)3U,
    (size_t)1U,
    /* original Rust expression is not an lvalue in C */
    void *lvalue = (void *)0U;
    arr_struct.data[i] = call_mut_b4_68(&lvalue););
  return arr_struct;
}

/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.transpose_a
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
*/
static Eurydice_arr_c10 transpose_a_68(Eurydice_arr_c10 ind_cpa_a)
{
  Eurydice_arr_c10 arr_struct;
  KRML_MAYBE_FOR3(i,
    (size_t)0U,
    (size_t)3U,
    (size_t)1U,
    /* original Rust expression is not an lvalue in C */
    void *lvalue = (void *)0U;
    arr_struct.data[i] = call_mut_22_68(&lvalue););
  Eurydice_arr_c10 A = arr_struct;
  KRML_MAYBE_FOR3(i0,
    (size_t)0U,
    (size_t)3U,
    (size_t)1U,
    size_t i1 = i0;
    KRML_MAYBE_FOR3(i,
      (size_t)0U,
      (size_t)3U,
      (size_t)1U,
      size_t j = i;
      Eurydice_arr_9e uu____0 = clone_c1_ea(&ind_cpa_a.data[j].data[i1]);
      A.data[i1].data[j] = uu____0;););
  return A;
}

/**
 Generate Unpacked Keys
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.generate_keypair
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$3size_t]], libcrux_ml_kem_variant_MlKem
with const generics
- K= 3
- CPA_PRIVATE_KEY_SIZE= 1152
- PRIVATE_KEY_SIZE= 2400
- PUBLIC_KEY_SIZE= 1184
- ETA1= 2
- ETA1_RANDOMNESS_SIZE= 128
*/
void
libcrux_ml_kem_ind_cca_unpacked_generate_keypair_b8(
  Eurydice_arr_c7 randomness,
  libcrux_ml_kem_mlkem768_portable_unpacked_MlKem768KeyPairUnpacked *out
)
{
  Eurydice_borrow_slice_u8
  ind_cpa_keypair_randomness =
    Eurydice_array_to_subslice_shared_d47(&randomness,
      (
        KRML_CLITERAL(core_ops_range_Range_87){
          .start = (size_t)0U,
          .end = LIBCRUX_ML_KEM_CONSTANTS_CPA_PKE_KEY_GENERATION_SEED_SIZE
        }
      ));
  Eurydice_borrow_slice_u8
  implicit_rejection_value =
    Eurydice_array_to_subslice_from_shared_5f1(&randomness,
      LIBCRUX_ML_KEM_CONSTANTS_CPA_PKE_KEY_GENERATION_SEED_SIZE);
  generate_keypair_unpacked_39(ind_cpa_keypair_randomness,
    &out->private_key.ind_cpa_private_key,
    &out->public_key.ind_cpa_public_key);
  Eurydice_arr_c10 A = transpose_a_68(out->public_key.ind_cpa_public_key.A);
  out->public_key.ind_cpa_public_key.A = A;
  Eurydice_arr_5f
  pk_serialized =
    serialize_public_key_b6(&out->public_key.ind_cpa_public_key.t_as_ntt,
      Eurydice_array_to_slice_shared_01(&out->public_key.ind_cpa_public_key.seed_for_A));
  Eurydice_arr_ec uu____0 = H_4a_78(Eurydice_array_to_slice_shared_ff(&pk_serialized));
  out->public_key.public_key_hash = uu____0;
  Eurydice_arr_ec arr;
  memcpy(arr.data, implicit_rejection_value.ptr, (size_t)32U * sizeof (uint8_t));
  Eurydice_arr_ec
  uu____1 =
    core_result_unwrap_26_39((
        KRML_CLITERAL(core_result_Result_07){ .tag = core_result_Ok, .val = { .case_Ok = arr } }
      ));
  out->private_key.implicit_rejection_value = uu____1;
}

/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.encaps_prepare
with types libcrux_ml_kem_hash_functions_portable_PortableHash[[$3size_t]]
with const generics
- K= 3
*/
static Eurydice_arr_c7
encaps_prepare_13(Eurydice_borrow_slice_u8 randomness, Eurydice_borrow_slice_u8 pk_hash)
{
  Eurydice_arr_c7 to_hash = libcrux_ml_kem_utils_into_padded_array_c9(randomness);
  Eurydice_slice_copy(Eurydice_array_to_subslice_from_mut_5f1(&to_hash,
      LIBCRUX_ML_KEM_CONSTANTS_H_DIGEST_SIZE),
    pk_hash,
    uint8_t);
  return G_4a_78(Eurydice_array_to_slice_shared_17(&to_hash));
}

/**
A monomorphic instance of n-tuple
with types Eurydice_arr_bb0, libcrux_ml_kem_polynomial_PolynomialRingElement_1d

*/
typedef struct tuple_c6_s
{
  Eurydice_arr_bb0 fst;
  Eurydice_arr_9e snd;
}
tuple_c6;

/**
This function found in impl {core::ops::function::FnMut<(usize), libcrux_ml_kem::polynomial::PolynomialRingElement<Vector>[TraitClause@0, TraitClause@2]> for libcrux_ml_kem::ind_cpa::encrypt_c1::closure<Vector, Hasher, K, C1_LEN, U_COMPRESSION_FACTOR, BLOCK_LEN, ETA1, ETA1_RANDOMNESS_SIZE, ETA2, ETA2_RANDOMNESS_SIZE>[TraitClause@0, TraitClause@1, TraitClause@2, TraitClause@3]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.encrypt_c1.call_mut_f1
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$3size_t]]
with const generics
- K= 3
- C1_LEN= 960
- U_COMPRESSION_FACTOR= 10
- BLOCK_LEN= 320
- ETA1= 2
- ETA1_RANDOMNESS_SIZE= 128
- ETA2= 2
- ETA2_RANDOMNESS_SIZE= 128
*/
static Eurydice_arr_9e call_mut_f1_87(void **_)
{
  return ZERO_d6_ea();
}

/**
This function found in impl {core::ops::function::FnMut<(usize), libcrux_ml_kem::polynomial::PolynomialRingElement<Vector>[TraitClause@0, TraitClause@2]> for libcrux_ml_kem::ind_cpa::encrypt_c1::closure#1<Vector, Hasher, K, C1_LEN, U_COMPRESSION_FACTOR, BLOCK_LEN, ETA1, ETA1_RANDOMNESS_SIZE, ETA2, ETA2_RANDOMNESS_SIZE>[TraitClause@0, TraitClause@1, TraitClause@2, TraitClause@3]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.encrypt_c1.call_mut_dd
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$3size_t]]
with const generics
- K= 3
- C1_LEN= 960
- U_COMPRESSION_FACTOR= 10
- BLOCK_LEN= 320
- ETA1= 2
- ETA1_RANDOMNESS_SIZE= 128
- ETA2= 2
- ETA2_RANDOMNESS_SIZE= 128
*/
static Eurydice_arr_9e call_mut_dd_87(void **_)
{
  return ZERO_d6_ea();
}

/**
 Sample a vector of ring elements from a centered binomial distribution.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.sample_ring_element_cbd
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$3size_t]]
with const generics
- K= 3
- ETA2_RANDOMNESS_SIZE= 128
- ETA2= 2
*/
static KRML_MUSTINLINE uint8_t
sample_ring_element_cbd_bf(
  const Eurydice_arr_fa *prf_input,
  uint8_t domain_separator,
  Eurydice_arr_bb0 *error_1
)
{
  Eurydice_arr_801 prf_inputs;
  Eurydice_arr_fa repeat_expression[3U];
  KRML_MAYBE_FOR3(i,
    (size_t)0U,
    (size_t)3U,
    (size_t)1U,
    repeat_expression[i] =
      core_array__core__clone__Clone_for__T__N___clone((size_t)33U,
        prf_input,
        uint8_t,
        Eurydice_arr_fa););
  memcpy(prf_inputs.data, repeat_expression, (size_t)3U * sizeof (Eurydice_arr_fa));
  domain_separator = libcrux_ml_kem_utils_prf_input_inc_78(&prf_inputs, domain_separator);
  Eurydice_arr_58 prf_outputs = PRFxN_4a_3b(&prf_inputs);
  KRML_MAYBE_FOR3(i,
    (size_t)0U,
    (size_t)3U,
    (size_t)1U,
    size_t i0 = i;
    Eurydice_arr_9e
    uu____0 =
      sample_from_binomial_distribution_66(Eurydice_array_to_slice_shared_78(&prf_outputs.data[i0]));
    error_1->data[i0] = uu____0;);
  return domain_separator;
}

/**
This function found in impl {libcrux_ml_kem::hash_functions::Hash<K> for libcrux_ml_kem::hash_functions::portable::PortableHash<K>}
*/
/**
A monomorphic instance of libcrux_ml_kem.hash_functions.portable.PRF_4a
with const generics
- K= 3
- LEN= 128
*/
static inline Eurydice_arr_89 PRF_4a_3b0(Eurydice_borrow_slice_u8 input)
{
  return PRF_ec(input);
}

/**
This function found in impl {core::ops::function::FnMut<(usize), libcrux_ml_kem::polynomial::PolynomialRingElement<Vector>[TraitClause@0, TraitClause@1]> for libcrux_ml_kem::matrix::compute_vector_u::closure<Vector, K>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.matrix.compute_vector_u.call_mut_a8
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
*/
static Eurydice_arr_9e call_mut_a8_68(void **_)
{
  return ZERO_d6_ea();
}

/**
A monomorphic instance of libcrux_ml_kem.invert_ntt.invert_ntt_montgomery
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
*/
static KRML_MUSTINLINE void invert_ntt_montgomery_68(Eurydice_arr_9e *re)
{
  size_t zeta_i = LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT / (size_t)2U;
  invert_ntt_at_layer_1_ea(&zeta_i, re);
  invert_ntt_at_layer_2_ea(&zeta_i, re);
  invert_ntt_at_layer_3_ea(&zeta_i, re);
  invert_ntt_at_layer_4_plus_ea(&zeta_i, re, (size_t)4U);
  invert_ntt_at_layer_4_plus_ea(&zeta_i, re, (size_t)5U);
  invert_ntt_at_layer_4_plus_ea(&zeta_i, re, (size_t)6U);
  invert_ntt_at_layer_4_plus_ea(&zeta_i, re, (size_t)7U);
  poly_barrett_reduce_d6_ea(re);
}

/**
 Compute u := InvertNTT(Aᵀ ◦ r̂) + e₁
*/
/**
A monomorphic instance of libcrux_ml_kem.matrix.compute_vector_u
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
*/
static KRML_MUSTINLINE Eurydice_arr_bb0
compute_vector_u_68(
  const Eurydice_arr_c10 *a_as_ntt,
  const Eurydice_arr_bb0 *r_as_ntt,
  const Eurydice_arr_bb0 *error_1
)
{
  Eurydice_arr_bb0 arr_struct;
  KRML_MAYBE_FOR3(i,
    (size_t)0U,
    (size_t)3U,
    (size_t)1U,
    /* original Rust expression is not an lvalue in C */
    void *lvalue = (void *)0U;
    arr_struct.data[i] = call_mut_a8_68(&lvalue););
  Eurydice_arr_bb0 result = arr_struct;
  KRML_MAYBE_FOR3(i0,
    (size_t)0U,
    (size_t)3U,
    (size_t)1U,
    size_t i1 = i0;
    const Eurydice_arr_bb0 *row = &a_as_ntt->data[i1];
    KRML_MAYBE_FOR3(i,
      (size_t)0U,
      (size_t)3U,
      (size_t)1U,
      size_t j = i;
      const Eurydice_arr_9e *a_element = &row->data[j];
      Eurydice_arr_9e product = ntt_multiply_d6_ea(a_element, &r_as_ntt->data[j]);
      add_to_ring_element_d6_68(&result.data[i1], &product););
    invert_ntt_montgomery_68(&result.data[i1]);
    add_error_reduce_d6_ea(&result.data[i1], &error_1->data[i1]););
  return result;
}

/**
 Call [`compress_then_serialize_ring_element_u`] on each ring element.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.compress_then_serialize_u
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
- OUT_LEN= 960
- COMPRESSION_FACTOR= 10
- BLOCK_LEN= 320
*/
static KRML_MUSTINLINE void
compress_then_serialize_u_21(Eurydice_arr_bb0 input, Eurydice_mut_borrow_slice_u8 out)
{
  KRML_MAYBE_FOR3(i,
    (size_t)0U,
    (size_t)3U,
    (size_t)1U,
    size_t i0 = i;
    Eurydice_arr_9e re = input.data[i0];
    Eurydice_mut_borrow_slice_u8
    uu____0 =
      Eurydice_slice_subslice_mut_c8(out,
        (
          KRML_CLITERAL(core_ops_range_Range_87){
            .start = i0 * ((size_t)960U / (size_t)3U),
            .end = (i0 + (size_t)1U) * ((size_t)960U / (size_t)3U)
          }
        ));
    /* original Rust expression is not an lvalue in C */
    Eurydice_arr_b0 lvalue = compress_then_serialize_ring_element_u_f7(&re);
    Eurydice_slice_copy(uu____0, Eurydice_array_to_slice_shared_56(&lvalue), uint8_t););
}

/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.encrypt_c1
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$3size_t]]
with const generics
- K= 3
- C1_LEN= 960
- U_COMPRESSION_FACTOR= 10
- BLOCK_LEN= 320
- ETA1= 2
- ETA1_RANDOMNESS_SIZE= 128
- ETA2= 2
- ETA2_RANDOMNESS_SIZE= 128
*/
static KRML_MUSTINLINE tuple_c6
encrypt_c1_87(
  Eurydice_borrow_slice_u8 randomness,
  const Eurydice_arr_c10 *matrix,
  Eurydice_mut_borrow_slice_u8 ciphertext
)
{
  Eurydice_arr_fa prf_input = libcrux_ml_kem_utils_into_padded_array_29(randomness);
  Eurydice_arr_bb0 arr_struct0;
  KRML_MAYBE_FOR3(i,
    (size_t)0U,
    (size_t)3U,
    (size_t)1U,
    /* original Rust expression is not an lvalue in C */
    void *lvalue = (void *)0U;
    arr_struct0.data[i] = call_mut_f1_87(&lvalue););
  Eurydice_arr_bb0 r_as_ntt = arr_struct0;
  uint8_t domain_separator0 = sample_vector_cbd_then_ntt_bf(&r_as_ntt, &prf_input, 0U);
  Eurydice_arr_bb0 arr_struct;
  KRML_MAYBE_FOR3(i,
    (size_t)0U,
    (size_t)3U,
    (size_t)1U,
    /* original Rust expression is not an lvalue in C */
    void *lvalue = (void *)0U;
    arr_struct.data[i] = call_mut_dd_87(&lvalue););
  Eurydice_arr_bb0 error_1 = arr_struct;
  uint8_t domain_separator = sample_ring_element_cbd_bf(&prf_input, domain_separator0, &error_1);
  prf_input.data[32U] = domain_separator;
  Eurydice_arr_89 prf_output = PRF_4a_3b0(Eurydice_array_to_slice_shared_b5(&prf_input));
  Eurydice_arr_9e
  error_2 = sample_from_binomial_distribution_66(Eurydice_array_to_slice_shared_78(&prf_output));
  Eurydice_arr_bb0 u = compute_vector_u_68(matrix, &r_as_ntt, &error_1);
  compress_then_serialize_u_21(u, ciphertext);
  return (KRML_CLITERAL(tuple_c6){ .fst = r_as_ntt, .snd = error_2 });
}

/**
 Compute InverseNTT(tᵀ ◦ r̂) + e₂ + message
*/
/**
A monomorphic instance of libcrux_ml_kem.matrix.compute_ring_element_v
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
*/
static KRML_MUSTINLINE Eurydice_arr_9e
compute_ring_element_v_68(
  const Eurydice_arr_bb0 *t_as_ntt,
  const Eurydice_arr_bb0 *r_as_ntt,
  const Eurydice_arr_9e *error_2,
  const Eurydice_arr_9e *message
)
{
  Eurydice_arr_9e result = ZERO_d6_ea();
  KRML_MAYBE_FOR3(i,
    (size_t)0U,
    (size_t)3U,
    (size_t)1U,
    size_t i0 = i;
    Eurydice_arr_9e product = ntt_multiply_d6_ea(&t_as_ntt->data[i0], &r_as_ntt->data[i0]);
    add_to_ring_element_d6_68(&result, &product););
  invert_ntt_montgomery_68(&result);
  return add_message_error_reduce_d6_ea(error_2, message, result);
}

/**
A monomorphic instance of libcrux_ml_kem.serialize.compress_then_serialize_ring_element_v
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
- COMPRESSION_FACTOR= 4
- OUT_LEN= 128
*/
static KRML_MUSTINLINE void
compress_then_serialize_ring_element_v_30(Eurydice_arr_9e re, Eurydice_mut_borrow_slice_u8 out)
{
  compress_then_serialize_4_ea(re, out);
}

/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.encrypt_c2
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
- V_COMPRESSION_FACTOR= 4
- C2_LEN= 128
*/
static KRML_MUSTINLINE void
encrypt_c2_30(
  const Eurydice_arr_bb0 *t_as_ntt,
  const Eurydice_arr_bb0 *r_as_ntt,
  const Eurydice_arr_9e *error_2,
  const Eurydice_arr_ec *message,
  Eurydice_mut_borrow_slice_u8 ciphertext
)
{
  Eurydice_arr_9e message_as_ring_element = deserialize_then_decompress_message_ea(message);
  Eurydice_arr_9e
  v = compute_ring_element_v_68(t_as_ntt, r_as_ntt, error_2, &message_as_ring_element);
  compress_then_serialize_ring_element_v_30(v, ciphertext);
}

/**
 This function implements <strong>Algorithm 13</strong> of the
 NIST FIPS 203 specification; this is the Kyber CPA-PKE encryption algorithm.

 Algorithm 13 is reproduced below:

 ```plaintext
 Input: encryption key ekₚₖₑ ∈ 𝔹^{384k+32}.
 Input: message m ∈ 𝔹^{32}.
 Input: encryption randomness r ∈ 𝔹^{32}.
 Output: ciphertext c ∈ 𝔹^{32(dᵤk + dᵥ)}.

 N ← 0
 t̂ ← ByteDecode₁₂(ekₚₖₑ[0:384k])
 ρ ← ekₚₖₑ[384k: 384k + 32]
 for (i ← 0; i < k; i++)
     for(j ← 0; j < k; j++)
         Â[i,j] ← SampleNTT(XOF(ρ, i, j))
     end for
 end for
 for(i ← 0; i < k; i++)
     r[i] ← SamplePolyCBD_{η₁}(PRF_{η₁}(r,N))
     N ← N + 1
 end for
 for(i ← 0; i < k; i++)
     e₁[i] ← SamplePolyCBD_{η₂}(PRF_{η₂}(r,N))
     N ← N + 1
 end for
 e₂ ← SamplePolyCBD_{η₂}(PRF_{η₂}(r,N))
 r̂ ← NTT(r)
 u ← NTT-¹(Âᵀ ◦ r̂) + e₁
 μ ← Decompress₁(ByteDecode₁(m)))
 v ← NTT-¹(t̂ᵀ ◦ rˆ) + e₂ + μ
 c₁ ← ByteEncode_{dᵤ}(Compress_{dᵤ}(u))
 c₂ ← ByteEncode_{dᵥ}(Compress_{dᵥ}(v))
 return c ← (c₁ ‖ c₂)
 ```

 The NIST FIPS 203 standard can be found at
 <https://csrc.nist.gov/pubs/fips/203/ipd>.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.encrypt_unpacked
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$3size_t]]
with const generics
- K= 3
- CIPHERTEXT_SIZE= 1088
- T_AS_NTT_ENCODED_SIZE= 1152
- C1_LEN= 960
- C2_LEN= 128
- U_COMPRESSION_FACTOR= 10
- V_COMPRESSION_FACTOR= 4
- BLOCK_LEN= 320
- ETA1= 2
- ETA1_RANDOMNESS_SIZE= 128
- ETA2= 2
- ETA2_RANDOMNESS_SIZE= 128
*/
static KRML_MUSTINLINE Eurydice_arr_2b
encrypt_unpacked_d5(
  const libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_51 *public_key,
  const Eurydice_arr_ec *message,
  Eurydice_borrow_slice_u8 randomness
)
{
  Eurydice_arr_2b ciphertext = { .data = { 0U } };
  tuple_c6
  uu____0 =
    encrypt_c1_87(randomness,
      &public_key->A,
      Eurydice_array_to_subslice_mut_d418(&ciphertext,
        (KRML_CLITERAL(core_ops_range_Range_87){ .start = (size_t)0U, .end = (size_t)960U })));
  Eurydice_arr_bb0 r_as_ntt = uu____0.fst;
  Eurydice_arr_9e error_2 = uu____0.snd;
  encrypt_c2_30(&public_key->t_as_ntt,
    &r_as_ntt,
    &error_2,
    message,
    Eurydice_array_to_subslice_from_mut_5f5(&ciphertext, (size_t)960U));
  return ciphertext;
}

/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.encapsulate
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$3size_t]]
with const generics
- K= 3
- CIPHERTEXT_SIZE= 1088
- PUBLIC_KEY_SIZE= 1184
- T_AS_NTT_ENCODED_SIZE= 1152
- C1_SIZE= 960
- C2_SIZE= 128
- VECTOR_U_COMPRESSION_FACTOR= 10
- VECTOR_V_COMPRESSION_FACTOR= 4
- VECTOR_U_BLOCK_LEN= 320
- ETA1= 2
- ETA1_RANDOMNESS_SIZE= 128
- ETA2= 2
- ETA2_RANDOMNESS_SIZE= 128
*/
tuple_f4
libcrux_ml_kem_ind_cca_unpacked_encapsulate_a7(
  const libcrux_ml_kem_ind_cca_unpacked_MlKemPublicKeyUnpacked_51 *public_key,
  const Eurydice_arr_ec *randomness
)
{
  Eurydice_arr_c7
  hashed =
    encaps_prepare_13(Eurydice_array_to_slice_shared_01(randomness),
      Eurydice_array_to_slice_shared_01(&public_key->public_key_hash));
  Eurydice_borrow_slice_u8_x2
  uu____0 =
    Eurydice_slice_split_at(Eurydice_array_to_slice_shared_17(&hashed),
      LIBCRUX_ML_KEM_CONSTANTS_SHARED_SECRET_SIZE,
      uint8_t,
      Eurydice_borrow_slice_u8_x2);
  Eurydice_borrow_slice_u8 shared_secret = uu____0.fst;
  Eurydice_borrow_slice_u8 pseudorandomness = uu____0.snd;
  Eurydice_arr_2b
  ciphertext = encrypt_unpacked_d5(&public_key->ind_cpa_public_key, randomness, pseudorandomness);
  Eurydice_arr_ec shared_secret_array = { .data = { 0U } };
  Eurydice_slice_copy(Eurydice_array_to_slice_mut_01(&shared_secret_array),
    shared_secret,
    uint8_t);
  return
    (
      KRML_CLITERAL(tuple_f4){
        .fst = libcrux_ml_kem_types_from_19_52(ciphertext),
        .snd = shared_secret_array
      }
    );
}

/**
This function found in impl {core::ops::function::FnMut<(usize), libcrux_ml_kem::polynomial::PolynomialRingElement<Vector>[TraitClause@0, TraitClause@1]> for libcrux_ml_kem::ind_cpa::deserialize_then_decompress_u::closure<Vector, K, CIPHERTEXT_SIZE, U_COMPRESSION_FACTOR>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.deserialize_then_decompress_u.call_mut_35
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
- CIPHERTEXT_SIZE= 1088
- U_COMPRESSION_FACTOR= 10
*/
static Eurydice_arr_9e call_mut_35_30(void **_)
{
  return ZERO_d6_ea();
}

/**
 Call [`deserialize_then_decompress_ring_element_u`] on each ring element
 in the `ciphertext`.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.deserialize_then_decompress_u
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
- CIPHERTEXT_SIZE= 1088
- U_COMPRESSION_FACTOR= 10
*/
static KRML_MUSTINLINE Eurydice_arr_bb0
deserialize_then_decompress_u_30(const Eurydice_arr_2b *ciphertext)
{
  Eurydice_arr_bb0 arr_struct;
  KRML_MAYBE_FOR3(i,
    (size_t)0U,
    (size_t)3U,
    (size_t)1U,
    /* original Rust expression is not an lvalue in C */
    void *lvalue = (void *)0U;
    arr_struct.data[i] = call_mut_35_30(&lvalue););
  Eurydice_arr_bb0 u_as_ntt = arr_struct;
  for
  (size_t
    i = (size_t)0U;
    i <
      (size_t)1088U /
        (LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT * (size_t)10U / (size_t)8U);
    i++)
  {
    size_t i0 = i;
    Eurydice_borrow_slice_u8
    u_bytes =
      Eurydice_array_to_subslice_shared_d49(ciphertext,
        (
          KRML_CLITERAL(core_ops_range_Range_87){
            .start = i0 *
              (LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT * (size_t)10U / (size_t)8U),
            .end = i0 *
              (LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT * (size_t)10U / (size_t)8U)
            + LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT * (size_t)10U / (size_t)8U
          }
        ));
    u_as_ntt.data[i0] = deserialize_then_decompress_ring_element_u_f7(u_bytes);
    ntt_vector_u_f7(&u_as_ntt.data[i0]);
  }
  return u_as_ntt;
}

/**
A monomorphic instance of libcrux_ml_kem.serialize.deserialize_then_decompress_ring_element_v
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
- COMPRESSION_FACTOR= 4
*/
static KRML_MUSTINLINE Eurydice_arr_9e
deserialize_then_decompress_ring_element_v_b6(Eurydice_borrow_slice_u8 serialized)
{
  return deserialize_then_decompress_4_ea(serialized);
}

/**
 The following functions compute various expressions involving
 vectors and matrices. The computation of these expressions has been
 abstracted away into these functions in order to save on loop iterations.
 Compute v − InverseNTT(sᵀ ◦ NTT(u))
*/
/**
A monomorphic instance of libcrux_ml_kem.matrix.compute_message
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
*/
static KRML_MUSTINLINE Eurydice_arr_9e
compute_message_68(
  const Eurydice_arr_9e *v,
  const Eurydice_arr_bb0 *secret_as_ntt,
  const Eurydice_arr_bb0 *u_as_ntt
)
{
  Eurydice_arr_9e result = ZERO_d6_ea();
  KRML_MAYBE_FOR3(i,
    (size_t)0U,
    (size_t)3U,
    (size_t)1U,
    size_t i0 = i;
    Eurydice_arr_9e product = ntt_multiply_d6_ea(&secret_as_ntt->data[i0], &u_as_ntt->data[i0]);
    add_to_ring_element_d6_68(&result, &product););
  invert_ntt_montgomery_68(&result);
  return subtract_reduce_d6_ea(v, result);
}

/**
 This function implements <strong>Algorithm 14</strong> of the
 NIST FIPS 203 specification; this is the Kyber CPA-PKE decryption algorithm.

 Algorithm 14 is reproduced below:

 ```plaintext
 Input: decryption key dkₚₖₑ ∈ 𝔹^{384k}.
 Input: ciphertext c ∈ 𝔹^{32(dᵤk + dᵥ)}.
 Output: message m ∈ 𝔹^{32}.

 c₁ ← c[0 : 32dᵤk]
 c₂ ← c[32dᵤk : 32(dᵤk + dᵥ)]
 u ← Decompress_{dᵤ}(ByteDecode_{dᵤ}(c₁))
 v ← Decompress_{dᵥ}(ByteDecode_{dᵥ}(c₂))
 ŝ ← ByteDecode₁₂(dkₚₖₑ)
 w ← v - NTT-¹(ŝᵀ ◦ NTT(u))
 m ← ByteEncode₁(Compress₁(w))
 return m
 ```

 The NIST FIPS 203 standard can be found at
 <https://csrc.nist.gov/pubs/fips/203/ipd>.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.decrypt_unpacked
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
- CIPHERTEXT_SIZE= 1088
- VECTOR_U_ENCODED_SIZE= 960
- U_COMPRESSION_FACTOR= 10
- V_COMPRESSION_FACTOR= 4
*/
static KRML_MUSTINLINE Eurydice_arr_ec
decrypt_unpacked_01(const Eurydice_arr_bb0 *secret_key, const Eurydice_arr_2b *ciphertext)
{
  Eurydice_arr_bb0 u_as_ntt = deserialize_then_decompress_u_30(ciphertext);
  Eurydice_arr_9e
  v =
    deserialize_then_decompress_ring_element_v_b6(Eurydice_array_to_subslice_from_shared_5f3(ciphertext,
        (size_t)960U));
  Eurydice_arr_9e message = compute_message_68(&v, secret_key, &u_as_ntt);
  return compress_then_serialize_message_ea(message);
}

/**
This function found in impl {libcrux_ml_kem::hash_functions::Hash<K> for libcrux_ml_kem::hash_functions::portable::PortableHash<K>}
*/
/**
A monomorphic instance of libcrux_ml_kem.hash_functions.portable.PRF_4a
with const generics
- K= 3
- LEN= 32
*/
static inline Eurydice_arr_ec PRF_4a_3b(Eurydice_borrow_slice_u8 input)
{
  return PRF_ce(input);
}

/**
A monomorphic instance of libcrux_ml_kem.ind_cca.unpacked.decapsulate
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$3size_t]]
with const generics
- K= 3
- SECRET_KEY_SIZE= 2400
- CPA_SECRET_KEY_SIZE= 1152
- PUBLIC_KEY_SIZE= 1184
- CIPHERTEXT_SIZE= 1088
- T_AS_NTT_ENCODED_SIZE= 1152
- C1_SIZE= 960
- C2_SIZE= 128
- VECTOR_U_COMPRESSION_FACTOR= 10
- VECTOR_V_COMPRESSION_FACTOR= 4
- C1_BLOCK_SIZE= 320
- ETA1= 2
- ETA1_RANDOMNESS_SIZE= 128
- ETA2= 2
- ETA2_RANDOMNESS_SIZE= 128
- IMPLICIT_REJECTION_HASH_INPUT_SIZE= 1120
*/
Eurydice_arr_ec
libcrux_ml_kem_ind_cca_unpacked_decapsulate_0c(
  const libcrux_ml_kem_mlkem768_portable_unpacked_MlKem768KeyPairUnpacked *key_pair,
  const Eurydice_arr_2b *ciphertext
)
{
  Eurydice_arr_ec
  decrypted = decrypt_unpacked_01(&key_pair->private_key.ind_cpa_private_key, ciphertext);
  Eurydice_arr_c7
  to_hash0 =
    libcrux_ml_kem_utils_into_padded_array_c9(Eurydice_array_to_slice_shared_01(&decrypted));
  Eurydice_mut_borrow_slice_u8
  uu____0 =
    Eurydice_array_to_subslice_from_mut_5f1(&to_hash0,
      LIBCRUX_ML_KEM_CONSTANTS_SHARED_SECRET_SIZE);
  Eurydice_slice_copy(uu____0,
    Eurydice_array_to_slice_shared_01(&key_pair->public_key.public_key_hash),
    uint8_t);
  Eurydice_arr_c7 hashed = G_4a_78(Eurydice_array_to_slice_shared_17(&to_hash0));
  Eurydice_borrow_slice_u8_x2
  uu____1 =
    Eurydice_slice_split_at(Eurydice_array_to_slice_shared_17(&hashed),
      LIBCRUX_ML_KEM_CONSTANTS_SHARED_SECRET_SIZE,
      uint8_t,
      Eurydice_borrow_slice_u8_x2);
  Eurydice_borrow_slice_u8 shared_secret = uu____1.fst;
  Eurydice_borrow_slice_u8 pseudorandomness = uu____1.snd;
  Eurydice_arr_af
  to_hash =
    libcrux_ml_kem_utils_into_padded_array_66(Eurydice_array_to_slice_shared_01(&key_pair->private_key.implicit_rejection_value));
  Eurydice_mut_borrow_slice_u8
  uu____2 =
    Eurydice_array_to_subslice_from_mut_5f4(&to_hash,
      LIBCRUX_ML_KEM_CONSTANTS_SHARED_SECRET_SIZE);
  Eurydice_slice_copy(uu____2, libcrux_ml_kem_types_as_ref_c1_52(ciphertext), uint8_t);
  Eurydice_arr_ec
  implicit_rejection_shared_secret = PRF_4a_3b(Eurydice_array_to_slice_shared_81(&to_hash));
  Eurydice_arr_2b
  expected_ciphertext =
    encrypt_unpacked_d5(&key_pair->public_key.ind_cpa_public_key,
      &decrypted,
      pseudorandomness);
  Eurydice_borrow_slice_u8 uu____3 = libcrux_ml_kem_types_as_ref_c1_52(ciphertext);
  uint8_t
  selector =
    libcrux_ml_kem_constant_time_ops_compare_ciphertexts_in_constant_time(uu____3,
      Eurydice_array_to_slice_shared_06(&expected_ciphertext));
  return
    libcrux_ml_kem_constant_time_ops_select_shared_secret_in_constant_time(shared_secret,
      Eurydice_array_to_slice_shared_01(&implicit_rejection_shared_secret),
      selector);
}

/**
This function found in impl {core::ops::function::FnMut<(usize), libcrux_ml_kem::polynomial::PolynomialRingElement<Vector>[TraitClause@0, TraitClause@1]> for libcrux_ml_kem::serialize::deserialize_ring_elements_reduced_out::closure<Vector, K>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.serialize.deserialize_ring_elements_reduced_out.call_mut_0b
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
*/
static Eurydice_arr_9e call_mut_0b_68(void **_)
{
  return ZERO_d6_ea();
}

/**
 This function deserializes ring elements and reduces the result by the field
 modulus.

 This function MUST NOT be used on secret inputs.
*/
/**
A monomorphic instance of libcrux_ml_kem.serialize.deserialize_ring_elements_reduced_out
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
*/
static KRML_MUSTINLINE Eurydice_arr_bb0
deserialize_ring_elements_reduced_out_68(Eurydice_borrow_slice_u8 public_key)
{
  Eurydice_arr_bb0 arr_struct;
  KRML_MAYBE_FOR3(i,
    (size_t)0U,
    (size_t)3U,
    (size_t)1U,
    /* original Rust expression is not an lvalue in C */
    void *lvalue = (void *)0U;
    arr_struct.data[i] = call_mut_0b_68(&lvalue););
  Eurydice_arr_bb0 deserialized_pk = arr_struct;
  deserialize_ring_elements_reduced_68(public_key, &deserialized_pk);
  return deserialized_pk;
}

/**
 Validate an ML-KEM public key.

 This implements the Modulus check in 7.2 2.
 Note that the size check in 7.2 1 is covered by the `PUBLIC_KEY_SIZE` in the
 `public_key` type.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.validate_public_key
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
- PUBLIC_KEY_SIZE= 1184
*/
bool libcrux_ml_kem_ind_cca_validate_public_key_b6(const Eurydice_arr_5f *public_key)
{
  Eurydice_arr_bb0
  deserialized_pk =
    deserialize_ring_elements_reduced_out_68(Eurydice_array_to_subslice_to_shared_213(public_key,
        libcrux_ml_kem_constants_ranked_bytes_per_ring_element((size_t)3U)));
  Eurydice_arr_5f
  public_key_serialized =
    serialize_public_key_b6(&deserialized_pk,
      Eurydice_array_to_subslice_from_shared_5f4(public_key,
        libcrux_ml_kem_constants_ranked_bytes_per_ring_element((size_t)3U)));
  return Eurydice_array_eq((size_t)1184U, public_key, &public_key_serialized, uint8_t);
}

/**
 Validate an ML-KEM private key.

 This implements the Hash check in 7.3 3.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.validate_private_key_only
with types libcrux_ml_kem_hash_functions_portable_PortableHash[[$3size_t]]
with const generics
- K= 3
- SECRET_KEY_SIZE= 2400
*/
bool libcrux_ml_kem_ind_cca_validate_private_key_only_52(const Eurydice_arr_7d *private_key)
{
  Eurydice_arr_ec
  t =
    H_4a_78(Eurydice_array_to_subslice_shared_d410(private_key,
        (
          KRML_CLITERAL(core_ops_range_Range_87){
            .start = (size_t)384U * (size_t)3U,
            .end = (size_t)768U * (size_t)3U + (size_t)32U
          }
        )));
  Eurydice_borrow_slice_u8
  expected =
    Eurydice_array_to_subslice_shared_d410(private_key,
      (
        KRML_CLITERAL(core_ops_range_Range_87){
          .start = (size_t)768U * (size_t)3U + (size_t)32U,
          .end = (size_t)768U * (size_t)3U + (size_t)64U
        }
      ));
  return Eurydice_array_eq_slice_shared((size_t)32U, &t, &expected, uint8_t, bool);
}

/**
 Validate an ML-KEM private key.

 This implements the Hash check in 7.3 3.
 Note that the size checks in 7.2 1 and 2 are covered by the `SECRET_KEY_SIZE`
 and `CIPHERTEXT_SIZE` in the `private_key` and `ciphertext` types.
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.validate_private_key
with types libcrux_ml_kem_hash_functions_portable_PortableHash[[$3size_t]]
with const generics
- K= 3
- SECRET_KEY_SIZE= 2400
- CIPHERTEXT_SIZE= 1088
*/
bool
libcrux_ml_kem_ind_cca_validate_private_key_ba(
  const Eurydice_arr_7d *private_key,
  const Eurydice_arr_2b *_ciphertext
)
{
  return libcrux_ml_kem_ind_cca_validate_private_key_only_52(private_key);
}

/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.generate_keypair
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$3size_t]], libcrux_ml_kem_variant_MlKem
with const generics
- K= 3
- PRIVATE_KEY_SIZE= 1152
- PUBLIC_KEY_SIZE= 1184
- ETA1= 2
- ETA1_RANDOMNESS_SIZE= 128
*/
static KRML_MUSTINLINE libcrux_ml_kem_utils_extraction_helper_Keypair768
generate_keypair_30(Eurydice_borrow_slice_u8 key_generation_seed)
{
  Eurydice_arr_bb0 private_key = default_70_68();
  libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_51 public_key = default_8b_68();
  generate_keypair_unpacked_39(key_generation_seed, &private_key, &public_key);
  return serialize_unpacked_secret_key_30(&public_key, &private_key);
}

/**
A monomorphic instance of libcrux_ml_kem.ind_cca.serialize_kem_secret_key
with types libcrux_ml_kem_hash_functions_portable_PortableHash[[$3size_t]]
with const generics
- K= 3
- SERIALIZED_KEY_LEN= 2400
*/
static KRML_MUSTINLINE Eurydice_arr_7d
serialize_kem_secret_key_52(
  Eurydice_borrow_slice_u8 private_key,
  Eurydice_borrow_slice_u8 public_key,
  Eurydice_borrow_slice_u8 implicit_rejection_value
)
{
  Eurydice_arr_7d out = { .data = { 0U } };
  libcrux_ml_kem_ind_cca_serialize_kem_secret_key_mut_52(private_key,
    public_key,
    implicit_rejection_value,
    &out);
  return out;
}

/**
 Packed API

 Generate a key pair.

 Depending on the `Vector` and `Hasher` used, this requires different hardware
 features
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.generate_keypair
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$3size_t]], libcrux_ml_kem_variant_MlKem
with const generics
- K= 3
- CPA_PRIVATE_KEY_SIZE= 1152
- PRIVATE_KEY_SIZE= 2400
- PUBLIC_KEY_SIZE= 1184
- ETA1= 2
- ETA1_RANDOMNESS_SIZE= 128
*/
libcrux_ml_kem_mlkem768_MlKem768KeyPair
libcrux_ml_kem_ind_cca_generate_keypair_b8(const Eurydice_arr_c7 *randomness)
{
  Eurydice_borrow_slice_u8
  ind_cpa_keypair_randomness =
    Eurydice_array_to_subslice_shared_d47(randomness,
      (
        KRML_CLITERAL(core_ops_range_Range_87){
          .start = (size_t)0U,
          .end = LIBCRUX_ML_KEM_CONSTANTS_CPA_PKE_KEY_GENERATION_SEED_SIZE
        }
      ));
  Eurydice_borrow_slice_u8
  implicit_rejection_value =
    Eurydice_array_to_subslice_from_shared_5f1(randomness,
      LIBCRUX_ML_KEM_CONSTANTS_CPA_PKE_KEY_GENERATION_SEED_SIZE);
  libcrux_ml_kem_utils_extraction_helper_Keypair768
  uu____0 = generate_keypair_30(ind_cpa_keypair_randomness);
  Eurydice_arr_0e ind_cpa_private_key = uu____0.fst;
  Eurydice_arr_5f public_key = uu____0.snd;
  Eurydice_arr_7d
  secret_key_serialized =
    serialize_kem_secret_key_52(Eurydice_array_to_slice_shared_f4(&ind_cpa_private_key),
      Eurydice_array_to_slice_shared_ff(&public_key),
      implicit_rejection_value);
  Eurydice_arr_7d private_key = libcrux_ml_kem_types_from_b2_79(secret_key_serialized);
  return
    libcrux_ml_kem_types_from_17_bc(private_key,
      libcrux_ml_kem_types_from_51_3d(public_key));
}

/**
This function found in impl {libcrux_ml_kem::variant::Variant for libcrux_ml_kem::variant::MlKem}
*/
/**
A monomorphic instance of libcrux_ml_kem.variant.entropy_preprocess_39
with types libcrux_ml_kem_hash_functions_portable_PortableHash[[$3size_t]]
with const generics
- K= 3
*/
static KRML_MUSTINLINE Eurydice_arr_ec
entropy_preprocess_39_13(Eurydice_borrow_slice_u8 randomness)
{
  Eurydice_arr_ec out = { .data = { 0U } };
  Eurydice_slice_copy(Eurydice_array_to_slice_mut_01(&out), randomness, uint8_t);
  return out;
}

/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.build_unpacked_public_key
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$3size_t]]
with const generics
- K= 3
- T_AS_NTT_ENCODED_SIZE= 1152
*/
static KRML_MUSTINLINE libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_51
build_unpacked_public_key_05(Eurydice_borrow_slice_u8 public_key)
{
  libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_51
  unpacked_public_key = default_8b_68();
  build_unpacked_public_key_mut_05(public_key, &unpacked_public_key);
  return unpacked_public_key;
}

/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.encrypt
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$3size_t]]
with const generics
- K= 3
- CIPHERTEXT_SIZE= 1088
- T_AS_NTT_ENCODED_SIZE= 1152
- C1_LEN= 960
- C2_LEN= 128
- U_COMPRESSION_FACTOR= 10
- V_COMPRESSION_FACTOR= 4
- BLOCK_LEN= 320
- ETA1= 2
- ETA1_RANDOMNESS_SIZE= 128
- ETA2= 2
- ETA2_RANDOMNESS_SIZE= 128
*/
static KRML_MUSTINLINE Eurydice_arr_2b
encrypt_d5(
  Eurydice_borrow_slice_u8 public_key,
  const Eurydice_arr_ec *message,
  Eurydice_borrow_slice_u8 randomness
)
{
  libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_51
  unpacked_public_key = build_unpacked_public_key_05(public_key);
  return encrypt_unpacked_d5(&unpacked_public_key, message, randomness);
}

/**
This function found in impl {libcrux_ml_kem::variant::Variant for libcrux_ml_kem::variant::MlKem}
*/
/**
A monomorphic instance of libcrux_ml_kem.variant.kdf_39
with types libcrux_ml_kem_hash_functions_portable_PortableHash[[$3size_t]]
with const generics
- K= 3
- CIPHERTEXT_SIZE= 1088
*/
static KRML_MUSTINLINE Eurydice_arr_ec kdf_39_52(Eurydice_borrow_slice_u8 shared_secret)
{
  Eurydice_arr_ec out = { .data = { 0U } };
  Eurydice_slice_copy(Eurydice_array_to_slice_mut_01(&out), shared_secret, uint8_t);
  return out;
}

/**
A monomorphic instance of libcrux_ml_kem.ind_cca.encapsulate
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$3size_t]], libcrux_ml_kem_variant_MlKem
with const generics
- K= 3
- CIPHERTEXT_SIZE= 1088
- PUBLIC_KEY_SIZE= 1184
- T_AS_NTT_ENCODED_SIZE= 1152
- C1_SIZE= 960
- C2_SIZE= 128
- VECTOR_U_COMPRESSION_FACTOR= 10
- VECTOR_V_COMPRESSION_FACTOR= 4
- C1_BLOCK_SIZE= 320
- ETA1= 2
- ETA1_RANDOMNESS_SIZE= 128
- ETA2= 2
- ETA2_RANDOMNESS_SIZE= 128
*/
tuple_f4
libcrux_ml_kem_ind_cca_encapsulate_99(
  const Eurydice_arr_5f *public_key,
  const Eurydice_arr_ec *randomness
)
{
  Eurydice_arr_ec
  randomness0 = entropy_preprocess_39_13(Eurydice_array_to_slice_shared_01(randomness));
  Eurydice_arr_c7
  to_hash =
    libcrux_ml_kem_utils_into_padded_array_c9(Eurydice_array_to_slice_shared_01(&randomness0));
  Eurydice_mut_borrow_slice_u8
  uu____0 =
    Eurydice_array_to_subslice_from_mut_5f1(&to_hash,
      LIBCRUX_ML_KEM_CONSTANTS_H_DIGEST_SIZE);
  /* original Rust expression is not an lvalue in C */
  Eurydice_arr_ec
  lvalue =
    H_4a_78(Eurydice_array_to_slice_shared_ff(libcrux_ml_kem_types_as_slice_e6_3d(public_key)));
  Eurydice_slice_copy(uu____0, Eurydice_array_to_slice_shared_01(&lvalue), uint8_t);
  Eurydice_arr_c7 hashed = G_4a_78(Eurydice_array_to_slice_shared_17(&to_hash));
  Eurydice_borrow_slice_u8_x2
  uu____1 =
    Eurydice_slice_split_at(Eurydice_array_to_slice_shared_17(&hashed),
      LIBCRUX_ML_KEM_CONSTANTS_SHARED_SECRET_SIZE,
      uint8_t,
      Eurydice_borrow_slice_u8_x2);
  Eurydice_borrow_slice_u8 shared_secret = uu____1.fst;
  Eurydice_borrow_slice_u8 pseudorandomness = uu____1.snd;
  Eurydice_arr_2b
  ciphertext =
    encrypt_d5(Eurydice_array_to_slice_shared_ff(libcrux_ml_kem_types_as_slice_e6_3d(public_key)),
      &randomness0,
      pseudorandomness);
  Eurydice_arr_2b uu____2 = libcrux_ml_kem_types_from_19_52(ciphertext);
  return (KRML_CLITERAL(tuple_f4){ .fst = uu____2, .snd = kdf_39_52(shared_secret) });
}

/**
This function found in impl {core::ops::function::FnMut<(usize), libcrux_ml_kem::polynomial::PolynomialRingElement<Vector>[TraitClause@0, TraitClause@1]> for libcrux_ml_kem::ind_cpa::decrypt::closure<Vector, K, CIPHERTEXT_SIZE, VECTOR_U_ENCODED_SIZE, U_COMPRESSION_FACTOR, V_COMPRESSION_FACTOR>[TraitClause@0, TraitClause@1]}
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.decrypt.call_mut_0b
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
- CIPHERTEXT_SIZE= 1088
- VECTOR_U_ENCODED_SIZE= 960
- U_COMPRESSION_FACTOR= 10
- V_COMPRESSION_FACTOR= 4
*/
static Eurydice_arr_9e call_mut_0b_01(void **_)
{
  return ZERO_d6_ea();
}

/**
A monomorphic instance of libcrux_ml_kem.ind_cpa.decrypt
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector
with const generics
- K= 3
- CIPHERTEXT_SIZE= 1088
- VECTOR_U_ENCODED_SIZE= 960
- U_COMPRESSION_FACTOR= 10
- V_COMPRESSION_FACTOR= 4
*/
static KRML_MUSTINLINE Eurydice_arr_ec
decrypt_01(Eurydice_borrow_slice_u8 secret_key, const Eurydice_arr_2b *ciphertext)
{
  Eurydice_arr_bb0 arr_struct;
  KRML_MAYBE_FOR3(i,
    (size_t)0U,
    (size_t)3U,
    (size_t)1U,
    /* original Rust expression is not an lvalue in C */
    void *lvalue = (void *)0U;
    arr_struct.data[i] = call_mut_0b_01(&lvalue););
  Eurydice_arr_bb0 secret_key_unpacked = arr_struct;
  deserialize_vector_68(secret_key, &secret_key_unpacked);
  return decrypt_unpacked_01(&secret_key_unpacked, ciphertext);
}

/**
 This code verifies on some machines, runs out of memory on others
*/
/**
A monomorphic instance of libcrux_ml_kem.ind_cca.decapsulate
with types libcrux_ml_kem_vector_portable_vector_type_PortableVector, libcrux_ml_kem_hash_functions_portable_PortableHash[[$3size_t]], libcrux_ml_kem_variant_MlKem
with const generics
- K= 3
- SECRET_KEY_SIZE= 2400
- CPA_SECRET_KEY_SIZE= 1152
- PUBLIC_KEY_SIZE= 1184
- CIPHERTEXT_SIZE= 1088
- T_AS_NTT_ENCODED_SIZE= 1152
- C1_SIZE= 960
- C2_SIZE= 128
- VECTOR_U_COMPRESSION_FACTOR= 10
- VECTOR_V_COMPRESSION_FACTOR= 4
- C1_BLOCK_SIZE= 320
- ETA1= 2
- ETA1_RANDOMNESS_SIZE= 128
- ETA2= 2
- ETA2_RANDOMNESS_SIZE= 128
- IMPLICIT_REJECTION_HASH_INPUT_SIZE= 1120
*/
Eurydice_arr_ec
libcrux_ml_kem_ind_cca_decapsulate_fd(
  const Eurydice_arr_7d *private_key,
  const Eurydice_arr_2b *ciphertext
)
{
  Eurydice_borrow_slice_u8_x4
  uu____0 =
    libcrux_ml_kem_types_unpack_private_key_64(Eurydice_array_to_slice_shared_51(private_key));
  Eurydice_borrow_slice_u8 ind_cpa_secret_key = uu____0.fst;
  Eurydice_borrow_slice_u8 ind_cpa_public_key = uu____0.snd;
  Eurydice_borrow_slice_u8 ind_cpa_public_key_hash = uu____0.thd;
  Eurydice_borrow_slice_u8 implicit_rejection_value = uu____0.f3;
  Eurydice_arr_ec decrypted = decrypt_01(ind_cpa_secret_key, ciphertext);
  Eurydice_arr_c7
  to_hash0 =
    libcrux_ml_kem_utils_into_padded_array_c9(Eurydice_array_to_slice_shared_01(&decrypted));
  Eurydice_slice_copy(Eurydice_array_to_subslice_from_mut_5f1(&to_hash0,
      LIBCRUX_ML_KEM_CONSTANTS_SHARED_SECRET_SIZE),
    ind_cpa_public_key_hash,
    uint8_t);
  Eurydice_arr_c7 hashed = G_4a_78(Eurydice_array_to_slice_shared_17(&to_hash0));
  Eurydice_borrow_slice_u8_x2
  uu____1 =
    Eurydice_slice_split_at(Eurydice_array_to_slice_shared_17(&hashed),
      LIBCRUX_ML_KEM_CONSTANTS_SHARED_SECRET_SIZE,
      uint8_t,
      Eurydice_borrow_slice_u8_x2);
  Eurydice_borrow_slice_u8 shared_secret0 = uu____1.fst;
  Eurydice_borrow_slice_u8 pseudorandomness = uu____1.snd;
  Eurydice_arr_af to_hash = libcrux_ml_kem_utils_into_padded_array_66(implicit_rejection_value);
  Eurydice_mut_borrow_slice_u8
  uu____2 =
    Eurydice_array_to_subslice_from_mut_5f4(&to_hash,
      LIBCRUX_ML_KEM_CONSTANTS_SHARED_SECRET_SIZE);
  Eurydice_slice_copy(uu____2, libcrux_ml_kem_types_as_ref_c1_52(ciphertext), uint8_t);
  Eurydice_arr_ec
  implicit_rejection_shared_secret = PRF_4a_3b(Eurydice_array_to_slice_shared_81(&to_hash));
  Eurydice_arr_2b
  expected_ciphertext = encrypt_d5(ind_cpa_public_key, &decrypted, pseudorandomness);
  Eurydice_borrow_slice_u8
  uu____3 = Eurydice_array_to_slice_shared_01(&implicit_rejection_shared_secret);
  Eurydice_arr_ec implicit_rejection_shared_secret0 = kdf_39_52(uu____3);
  Eurydice_arr_ec shared_secret = kdf_39_52(shared_secret0);
  Eurydice_borrow_slice_u8 uu____4 = libcrux_ml_kem_types_as_ref_c1_52(ciphertext);
  return
    libcrux_ml_kem_constant_time_ops_compare_ciphertexts_select_shared_secret_in_constant_time(uu____4,
      Eurydice_array_to_slice_shared_06(&expected_ciphertext),
      Eurydice_array_to_slice_shared_01(&shared_secret),
      Eurydice_array_to_slice_shared_01(&implicit_rejection_shared_secret0));
}

