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
51 changes: 43 additions & 8 deletions mldsa/sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,41 @@ int crypto_sign_keypair(uint8_t *pk, uint8_t *sk)
return result;
}

static void mld_shake256_absorb_with_residual(mld_shake256ctx *state,
const uint8_t *in, size_t inlen,
uint8_t *residual, size_t *pos)
{
size_t nb;
if (in)
{
if (*pos)
{
nb = inlen < 8 - *pos ? inlen : 8 - *pos;
memcpy(residual + *pos, in, nb);
inlen -= nb;
in += nb;
*pos += nb;
if (*pos == 8)
{
mld_shake256_absorb(state, residual, 8U);
*pos = 0;
}
}
nb = inlen & ~7UL;
if (nb)
{
mld_shake256_absorb(state, in, nb);
in += nb;
inlen -= nb;
}
if (inlen)
{
memcpy(residual, in, inlen);
*pos = inlen;
}
}
}

/*************************************************
* Name: mld_H
*
Expand Down Expand Up @@ -269,22 +304,22 @@ __contract__(
)
{
mld_shake256ctx state;
uint8_t buf[8];
size_t pos = 0;
mld_shake256_init(&state);
mld_shake256_absorb(&state, in1, in1len);
if (in2 != NULL)
{
mld_shake256_absorb(&state, in2, in2len);
}
if (in3 != NULL)
mld_shake256_absorb_with_residual(&state, in1, in1len, buf, &pos);
mld_shake256_absorb_with_residual(&state, in2, in2len, buf, &pos);
mld_shake256_absorb_with_residual(&state, in3, in3len, buf, &pos);
if (pos)
{
mld_shake256_absorb(&state, in3, in3len);
mld_shake256_absorb(&state, buf, pos);
}
mld_shake256_finalize(&state);
mld_shake256_squeeze(out, outlen, &state);
mld_shake256_release(&state);

/* @[FIPS204, Section 3.6.3] Destruction of intermediate values. */
mld_zeroize(&state, sizeof(state));
mld_zeroize(&buf, sizeof(buf));
}

/* Reference: The reference implementation does not explicitly */
Expand Down
2 changes: 1 addition & 1 deletion proofs/cbmc/H/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ FUNCTION_NAME = mld_h
# EXPENSIVE = true

# This function is large enough to need...
CBMC_OBJECT_BITS = 8
CBMC_OBJECT_BITS = 9

# If you require access to a file-local ("static") function or object to conduct
# your proof, set the following (and do not include the original source file
Expand Down
Loading