@@ -20,6 +20,30 @@ typedef struct
2020} MLK_ALIGN mlk_shake128x4ctx ;
2121
2222#define mlk_shake128x4_absorb_once MLK_NAMESPACE(shake128x4_absorb_once)
23+ /*************************************************
24+ * Name: mlk_shake128x4_absorb_once
25+ *
26+ * Description: 4x-batched one-shot absorb step of the SHAKE128 XOF.
27+ *
28+ * For call-sites (in mlkem-native):
29+ * - This function MUST ONLY be called straight after
30+ * mlk_shake128x4_init().
31+ * - This function MUST ONLY be called once.
32+ *
33+ * Consequently, for providers of custom FIPS202 code
34+ * to be used with mlkem-native:
35+ * - You may assume that the input context is
36+ * freshly initialized via mlk_shake128x4_init().
37+ * - You may assume that this function is
38+ * called exactly once.
39+ *
40+ * Arguments: - mlk_shake128x4ctx *state:
41+ * pointer to SHAKE128x4 context
42+ * - const uint8_t *in0, *in1, *in2, *in3:
43+ * pointers to inputs to be absorbed.
44+ * - size_t inlen:
45+ * length of input buffers in bytes
46+ **************************************************/
2347void mlk_shake128x4_absorb_once (mlk_shake128x4ctx * state , const uint8_t * in0 ,
2448 const uint8_t * in1 , const uint8_t * in2 ,
2549 const uint8_t * in3 , size_t inlen )
@@ -34,12 +58,27 @@ __contract__(
3458);
3559
3660#define mlk_shake128x4_squeezeblocks MLK_NAMESPACE(shake128x4_squeezeblocks)
61+ /*************************************************
62+ * Name: mlk_shake128x4_squeezeblocks
63+ *
64+ * Description: 4x-batched squeeze step of SHAKE128 XOF. Squeezes full blocks of
65+ * SHAKE128_RATE bytes each. Modifies the state. Can be called
66+ * multiple times to keep squeezing, i.e., is incremental.
67+ *
68+ * Arguments: - uint8_t *out0, *out1, *out2, *out3:
69+ * pointers to output blocks
70+ * Can be assumed to be 8-byte aligned.
71+ * - size_t nblocks:
72+ * number of blocks to be squeezed (written to output)
73+ * - mlk_shake128x4ctx *state: pointer to in/output Keccak state
74+ **************************************************/
3775void mlk_shake128x4_squeezeblocks (uint8_t * out0 , uint8_t * out1 , uint8_t * out2 ,
3876 uint8_t * out3 , size_t nblocks ,
3977 mlk_shake128x4ctx * state )
4078__contract__ (
4179 requires (nblocks <= 8 /* somewhat arbitrary bound */ )
4280 requires (memory_no_alias (state , sizeof (mlk_shake128x4ctx )))
81+ /* We can't express alignment of out{0,1,2,3} as a CBMC preconditions. */
4382 requires (memory_no_alias (out0 , nblocks * SHAKE128_RATE ))
4483 requires (memory_no_alias (out1 , nblocks * SHAKE128_RATE ))
4584 requires (memory_no_alias (out2 , nblocks * SHAKE128_RATE ))
@@ -58,12 +97,33 @@ void mlk_shake128x4_init(mlk_shake128x4ctx *state);
5897void mlk_shake128x4_release (mlk_shake128x4ctx * state );
5998
6099#define mlk_shake256x4 MLK_NAMESPACE(shake256x4)
100+ /*************************************************
101+ * Name: mlk_shake256x4
102+ *
103+ * Description: 4x-batched SHAKE256 XOF with non-incremental API
104+ *
105+ * Arguments: - uint8_t *out0, *out1, *out2, *out3:
106+ * pointers to output buffers
107+ * Can be assumed to be 8-byte aligned.
108+ * - size_t outlen:
109+ * requested output length in bytes
110+ * Can be assumed to be 8-byte aligned.
111+ * - const uint8_t *input:
112+ * pointer to input
113+ * - size_t inlen:
114+ * length of input in bytes
115+ **************************************************/
61116void mlk_shake256x4 (uint8_t * out0 , uint8_t * out1 , uint8_t * out2 , uint8_t * out3 ,
62117 size_t outlen , uint8_t * in0 , uint8_t * in1 , uint8_t * in2 ,
63118 uint8_t * in3 , size_t inlen )
64119__contract__ (
65120 requires (inlen <= MLK_MAX_BUFFER_SIZE )
66121 requires (outlen <= MLK_MAX_BUFFER_SIZE )
122+ /* The alignment constraint is not needed for the implementation, but
123+ * serves as an additional preconditions for users wishing to use an
124+ * alternative FIPS202 implementation. */
125+ requires (outlen % 8 == 0 )
126+ /* We can't express alignment of out{0,1,2,3} as a CBMC preconditions. */
67127 requires (memory_no_alias (in0 , inlen ))
68128 requires (memory_no_alias (in1 , inlen ))
69129 requires (memory_no_alias (in2 , inlen ))
0 commit comments