@@ -42,13 +42,20 @@ typedef struct
4242 * Arguments: - mlk_shake128ctx *state: pointer to SHAKE128 context
4343 * - const uint8_t *input: pointer to input to be absorbed into
4444 * the state
45+ * Can be assumed to be 8-byte aligned.
4546 * - size_t inlen: length of input in bytes
47+ * Can be assumed to be 8-byte aligned.
4648 **************************************************/
4749void mlk_shake128_absorb_once (mlk_shake128ctx * state , const uint8_t * input ,
4850 size_t inlen )
4951__contract__ (
5052 requires (inlen <= MLK_MAX_BUFFER_SIZE )
53+ /* The alignment constraints are not needed for the implementation, but
54+ * serve as additional preconditions for users wishing to use an
55+ * alternative FIPS202 implementation. */
56+ requires (inlen % 8 == 0 )
5157 requires (memory_no_alias (state , sizeof (mlk_shake128ctx )))
58+ /* We can't express alignment of input as a CBMC precondition. */
5259 requires (memory_no_alias (input , inlen ))
5360 assigns (memory_slice (state , sizeof (mlk_shake128ctx )))
5461);
@@ -62,6 +69,7 @@ __contract__(
6269 * multiple times to keep squeezing, i.e., is incremental.
6370 *
6471 * Arguments: - uint8_t *output: pointer to output blocks
72+ * Can be assumed to be 8-byte aligned.
6573 * - size_t nblocks: number of blocks to be squeezed (written
6674 * to output)
6775 * - mlk_shake128ctx *state: pointer to in/output Keccak state
@@ -71,6 +79,7 @@ void mlk_shake128_squeezeblocks(uint8_t *output, size_t nblocks,
7179__contract__ (
7280 requires (nblocks <= 8 /* somewhat arbitrary bound */ )
7381 requires (memory_no_alias (state , sizeof (mlk_shake128ctx )))
82+ /* We can't express alignment of output as a CBMC precondition. */
7483 requires (memory_no_alias (output , nblocks * SHAKE128_RATE ))
7584 assigns (memory_slice (output , nblocks * SHAKE128_RATE ), memory_slice (state , sizeof (mlk_shake128ctx )))
7685);
@@ -90,15 +99,25 @@ void mlk_shake128_release(mlk_shake128ctx *state);
9099 * Description: SHAKE256 XOF with non-incremental API
91100 *
92101 * Arguments: - uint8_t *output: pointer to output
102+ * Can be assumed to be 8-byte aligned.
93103 * - size_t outlen: requested output length in bytes
104+ * Can be assumed to be 8-byte aligned.
94105 * - const uint8_t *input: pointer to input
106+ * Can be assumed to be 8-byte aligned.
95107 * - size_t inlen: length of input in bytes
108+ * Can be assumed to be 8-byte aligned.
96109 **************************************************/
97110void mlk_shake256 (uint8_t * output , size_t outlen , const uint8_t * input ,
98111 size_t inlen )
99112__contract__ (
100113 requires (inlen <= MLK_MAX_BUFFER_SIZE )
101114 requires (outlen <= MLK_MAX_BUFFER_SIZE )
115+ /* The alignment constraints are not needed for the implementation, but
116+ * serve as additional preconditions for users wishing to use an
117+ * alternative FIPS202 implementation. */
118+ requires (inlen % 8 == 0 )
119+ requires (outlen % 8 == 0 )
120+ /* We can't express alignment of input and output as a CBMC precondition. */
102121 requires (memory_no_alias (input , inlen ))
103122 requires (memory_no_alias (output , outlen ))
104123 assigns (memory_slice (output , outlen ))
@@ -114,12 +133,20 @@ __contract__(
114133 * Description: SHA3-256 with non-incremental API
115134 *
116135 * Arguments: - uint8_t *output: pointer to output
136+ * Can be assumed to be 8-byte aligned.
117137 * - const uint8_t *input: pointer to input
138+ * Can be assumed to be 8-byte aligned.
118139 * - size_t inlen: length of input in bytes
140+ * Can be assumed to be 8-byte aligned.
119141 **************************************************/
120142void mlk_sha3_256 (uint8_t * output , const uint8_t * input , size_t inlen )
121143__contract__ (
122144 requires (inlen <= MLK_MAX_BUFFER_SIZE )
145+ /* This is not needed for the implementation, but serves
146+ * as an additional precondition for users wishing to use
147+ * an alternative FIPS202 implementation. */
148+ requires (inlen % 8 == 0 )
149+ /* We can't express alignment of input and output as a CBMC precondition. */
123150 requires (memory_no_alias (input , inlen ))
124151 requires (memory_no_alias (output , SHA3_256_HASHBYTES ))
125152 assigns (memory_slice (output , SHA3_256_HASHBYTES ))
@@ -136,11 +163,18 @@ __contract__(
136163 *
137164 * Arguments: - uint8_t *output: pointer to output
138165 * - const uint8_t *input: pointer to input
139- * - size_t inlen: length of input in bytes
166+ * Can be assumed to be 8-byte aligned.
167+ * - size_t inlen: length of input in bytes.
168+ * Can be assumed to be 8-byte aligned.
140169 **************************************************/
141170void mlk_sha3_512 (uint8_t * output , const uint8_t * input , size_t inlen )
142171__contract__ (
143172 requires (inlen <= MLK_MAX_BUFFER_SIZE )
173+ /* This is not needed for the implementation, but serves
174+ * as an additional precondition for users wishing to use
175+ * an alternative FIPS202 implementation. */
176+ requires (inlen % 8 == 0 )
177+ /* We can't express alignment of input and output as a CBMC precondition. */
144178 requires (memory_no_alias (input , inlen ))
145179 requires (memory_no_alias (output , SHA3_512_HASHBYTES ))
146180 assigns (memory_slice (output , SHA3_512_HASHBYTES ))
0 commit comments