Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mldsa/src/ct.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ __contract__(
ensures((return_value == 0) == forall(i, 0, len, (a[i] == b[i]))))
{
uint8_t r = 0, s = 0;
unsigned i;
size_t i;

for (i = 0; i < len; i++)
__loop__(
Expand Down
10 changes: 7 additions & 3 deletions mldsa/src/fips202/fips202.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ __contract__(
assigns(memory_slice(s, sizeof(uint64_t) * MLD_KECCAK_LANES))
ensures(return_value < r))
{
while (inlen >= r - pos)
/* Safety: widen r to avoid type mismatch warning */
size_t rsize = r;
while (inlen >= rsize - pos)
__loop__(
assigns(pos, in, inlen,
memory_slice(s, sizeof(uint64_t) * MLD_KECCAK_LANES))
Expand Down Expand Up @@ -150,6 +152,8 @@ __contract__(
ensures(return_value <= r))
{
unsigned int i;
/* Safety: widen r to avoid type mismatch warning */
size_t rsize = r;
size_t out_offset = 0;

/* Reference: This code is re-factored from the reference implementation
Expand All @@ -174,8 +178,8 @@ __contract__(
mld_keccakf1600_permute(s);
pos = 0;
}
/* Safety: If bytes_to_go < r - pos, truncation to unsigned is safe. */
i = bytes_to_go < r - pos ? (unsigned)bytes_to_go : r - pos;
/* Safety: If bytes_to_go < rsize - pos, truncation to unsigned is safe. */
i = bytes_to_go < rsize - pos ? (unsigned)bytes_to_go : r - pos;
mld_keccakf1600_extract_bytes(s, out + out_offset, pos, i);
bytes_to_go -= i;
pos += i;
Expand Down
6 changes: 4 additions & 2 deletions mldsa/src/fips202/fips202x4.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ __contract__(
requires(memory_no_alias(in3, inlen))
assigns(memory_slice(s, sizeof(uint64_t) * MLD_KECCAK_LANES * MLD_KECCAK_WAY)))
{
while (inlen >= r)
/* Safety: widen r to avoid type mismatch warning */
size_t rsize = r;
while (inlen >= rsize)
__loop__(
assigns(inlen, in0, in1, in2, in3, memory_slice(s, sizeof(uint64_t) * MLD_KECCAK_LANES * MLD_KECCAK_WAY))
invariant(inlen <= loop_entry(inlen))
Expand All @@ -66,7 +68,7 @@ __contract__(
mld_keccakf1600x4_xor_bytes(s, in0, in1, in2, in3, 0, (unsigned)inlen);
}

if (inlen == r - 1)
if (inlen == rsize - 1)
{
p |= 128;
mld_keccakf1600x4_xor_bytes(s, &p, &p, &p, &p, (unsigned)inlen, 1);
Expand Down
Loading