Skip to content

CBMC: Add proof and contract for mldsa_shake256_stream_init #201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2025
Merged
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/symmetric-shake.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void mldsa_shake256_stream_init(keccak_state *state,
uint16_t nonce)
{
uint8_t t[2];
t[0] = nonce;
t[0] = nonce & 0xFF;
t[1] = nonce >> 8;

shake256_init(state);
Expand Down
7 changes: 6 additions & 1 deletion mldsa/symmetric.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ __contract__(
#define mldsa_shake256_stream_init MLD_NAMESPACE(mldsa_shake256_stream_init)
void mldsa_shake256_stream_init(keccak_state *state,
const uint8_t seed[MLDSA_CRHBYTES],
uint16_t nonce);
uint16_t nonce)
__contract__(
requires(memory_no_alias(state, sizeof(keccak_state)))
requires(memory_no_alias(seed, MLDSA_CRHBYTES))
assigns(memory_slice(state, sizeof(keccak_state)))
);

#define STREAM128_BLOCKBYTES SHAKE128_RATE
#define STREAM256_BLOCKBYTES SHAKE256_RATE
Expand Down
55 changes: 55 additions & 0 deletions proofs/cbmc/mldsa_shake256_stream_init/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# SPDX-License-Identifier: Apache-2.0

include ../Makefile_params.common

HARNESS_ENTRY = harness
HARNESS_FILE = mldsa_shake256_stream_init_harness

# This should be a unique identifier for this proof, and will appear on the
# Litani dashboard. It can be human-readable and contain spaces if you wish.
PROOF_UID = mldsa_shake256_stream_init

DEFINES +=
INCLUDES +=

REMOVE_FUNCTION_BODY +=
UNWINDSET +=

PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c
PROJECT_SOURCES += $(SRCDIR)/mldsa/symmetric-shake.c

CHECK_FUNCTION_CONTRACTS=$(MLD_NAMESPACE)mldsa_shake256_stream_init
USE_FUNCTION_CONTRACTS=$(FIPS202_NAMESPACE)shake256_init $(FIPS202_NAMESPACE)shake256_absorb $(FIPS202_NAMESPACE)shake256_finalize

APPLY_LOOP_CONTRACTS=on
USE_DYNAMIC_FRAMES=1

# Disable any setting of EXTERNAL_SAT_SOLVER, and choose SMT backend instead
EXTERNAL_SAT_SOLVER=
CBMCFLAGS=--smt2

FUNCTION_NAME = mldsa_shake256_stream_init

# If this proof is found to consume huge amounts of RAM, you can set the
# EXPENSIVE variable. With new enough versions of the proof tools, this will
# restrict the number of EXPENSIVE CBMC jobs running at once. See the
# documentation in Makefile.common under the "Job Pools" heading for details.
# EXPENSIVE = true

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

# 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
# ("mldsa/poly.c") in PROJECT_SOURCES).
# REWRITTEN_SOURCES = $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i
# include ../Makefile.common
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_SOURCE = $(SRCDIR)/mldsa/poly.c
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_FUNCTIONS = foo bar
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_OBJECTS = baz
# Care is required with variables on the left-hand side: REWRITTEN_SOURCES must
# be set before including Makefile.common, but any use of variables on the
# left-hand side requires those variables to be defined. Hence, _SOURCE,
# _FUNCTIONS, _OBJECTS is set after including Makefile.common.

include ../Makefile.common
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) 2025 The mldsa-native project authors
// SPDX-License-Identifier: Apache-2.0

#include "params.h"
#include "symmetric.h"

void harness(void)
{
keccak_state *s;
const uint8_t *seed;
uint16_t nonce;

mldsa_shake256_stream_init(s, seed, nonce);
}
Loading