Skip to content

Commit 22b5e0c

Browse files
committed
CBMC: Add proof and spec for poly_uniform_eta_4x
Resolves #249 Signed-off-by: Matthias J. Kannwischer <[email protected]>
1 parent 441fdb4 commit 22b5e0c

File tree

4 files changed

+96
-1
lines changed

4 files changed

+96
-1
lines changed

mldsa/poly.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,18 @@ void poly_uniform_eta_4x(poly *r0, poly *r1, poly *r2, poly *r3,
545545
buflen = STREAM256_BLOCKBYTES;
546546
while (ctr[0] < MLDSA_N || ctr[1] < MLDSA_N || ctr[2] < MLDSA_N ||
547547
ctr[3] < MLDSA_N)
548+
__loop__(
549+
assigns(ctr, state, memory_slice(r0, sizeof(poly)),
550+
memory_slice(r1, sizeof(poly)), memory_slice(r2, sizeof(poly)),
551+
memory_slice(r3, sizeof(poly)), object_whole(buf[0]),
552+
object_whole(buf[1]), object_whole(buf[2]),
553+
object_whole(buf[3]))
554+
invariant(ctr[0] <= MLDSA_N && ctr[1] <= MLDSA_N)
555+
invariant(ctr[2] <= MLDSA_N && ctr[3] <= MLDSA_N)
556+
invariant(array_abs_bound(r0->coeffs, 0, ctr[0], MLDSA_ETA + 1))
557+
invariant(array_abs_bound(r1->coeffs, 0, ctr[1], MLDSA_ETA + 1))
558+
invariant(array_abs_bound(r2->coeffs, 0, ctr[2], MLDSA_ETA + 1))
559+
invariant(array_abs_bound(r3->coeffs, 0, ctr[3], MLDSA_ETA + 1)))
548560
{
549561
mld_xof256_x4_squeezeblocks(buf, 1, &state);
550562
ctr[0] = rej_eta(r0->coeffs, MLDSA_N, ctr[0], buf[0], buflen);

mldsa/poly.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,22 @@ __contract__(
351351
**************************************************/
352352
void poly_uniform_eta_4x(poly *r0, poly *r1, poly *r2, poly *r3,
353353
const uint8_t seed[MLDSA_CRHBYTES], uint8_t nonce0,
354-
uint8_t nonce1, uint8_t nonce2, uint8_t nonce3);
354+
uint8_t nonce1, uint8_t nonce2, uint8_t nonce3)
355+
__contract__(
356+
requires(memory_no_alias(r0, sizeof(poly)))
357+
requires(memory_no_alias(r1, sizeof(poly)))
358+
requires(memory_no_alias(r2, sizeof(poly)))
359+
requires(memory_no_alias(r3, sizeof(poly)))
360+
requires(memory_no_alias(seed, MLDSA_CRHBYTES))
361+
assigns(memory_slice(r0, sizeof(poly)))
362+
assigns(memory_slice(r1, sizeof(poly)))
363+
assigns(memory_slice(r2, sizeof(poly)))
364+
assigns(memory_slice(r3, sizeof(poly)))
365+
ensures(array_abs_bound(r0->coeffs, 0, MLDSA_N, MLDSA_ETA + 1))
366+
ensures(array_abs_bound(r1->coeffs, 0, MLDSA_N, MLDSA_ETA + 1))
367+
ensures(array_abs_bound(r2->coeffs, 0, MLDSA_N, MLDSA_ETA + 1))
368+
ensures(array_abs_bound(r3->coeffs, 0, MLDSA_N, MLDSA_ETA + 1))
369+
);
355370

356371
#define poly_uniform_gamma1 MLD_NAMESPACE(poly_uniform_gamma1)
357372
/*************************************************
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright (c) The mldsa-native project authors
2+
# SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
3+
4+
include ../Makefile_params.common
5+
6+
HARNESS_ENTRY = harness
7+
HARNESS_FILE = poly_uniform_eta_4x_harness
8+
9+
# This should be a unique identifier for this proof, and will appear on the
10+
# Litani dashboard. It can be human-readable and contain spaces if you wish.
11+
PROOF_UID = poly_uniform_eta_4x
12+
13+
DEFINES +=
14+
INCLUDES +=
15+
16+
REMOVE_FUNCTION_BODY +=
17+
UNWINDSET +=
18+
19+
PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c
20+
PROJECT_SOURCES += $(SRCDIR)/mldsa/poly.c $(SRCDIR)/mldsa/fips202/fips202x4.c
21+
22+
CHECK_FUNCTION_CONTRACTS=$(MLD_NAMESPACE)poly_uniform_eta_4x
23+
USE_FUNCTION_CONTRACTS=$(FIPS202_NAMESPACE)shake256x4_absorb_once $(FIPS202_NAMESPACE)shake256x4_squeezeblocks rej_eta
24+
APPLY_LOOP_CONTRACTS=on
25+
USE_DYNAMIC_FRAMES=1
26+
27+
# Disable any setting of EXTERNAL_SAT_SOLVER, and choose SMT backend instead
28+
EXTERNAL_SAT_SOLVER=
29+
CBMCFLAGS=--smt2
30+
31+
FUNCTION_NAME = poly_uniform_eta_4x
32+
33+
# If this proof is found to consume huge amounts of RAM, you can set the
34+
# EXPENSIVE variable. With new enough versions of the proof tools, this will
35+
# restrict the number of EXPENSIVE CBMC jobs running at once. See the
36+
# documentation in Makefile.common under the "Job Pools" heading for details.
37+
# EXPENSIVE = true
38+
39+
# This function is large enough to need...
40+
CBMC_OBJECT_BITS = 9
41+
42+
# If you require access to a file-local ("static") function or object to conduct
43+
# your proof, set the following (and do not include the original source file
44+
# ("mldsa/poly.c") in PROJECT_SOURCES).
45+
# REWRITTEN_SOURCES = $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i
46+
# include ../Makefile.common
47+
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_SOURCE = $(SRCDIR)/mldsa/poly.c
48+
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_FUNCTIONS = foo bar
49+
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_OBJECTS = baz
50+
# Care is required with variables on the left-hand side: REWRITTEN_SOURCES must
51+
# be set before including Makefile.common, but any use of variables on the
52+
# left-hand side requires those variables to be defined. Hence, _SOURCE,
53+
# _FUNCTIONS, _OBJECTS is set after including Makefile.common.
54+
55+
include ../Makefile.common
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) The mldsa-native project authors
2+
// SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
3+
4+
#include "poly.h"
5+
6+
void harness(void)
7+
{
8+
poly *r0, *r1, *r2, *r3;
9+
const uint8_t *seed;
10+
uint8_t n0, n1, n2, n3;
11+
12+
poly_uniform_eta_4x(r0, r1, r2, r3, seed, n0, n1, n2, n3);
13+
}

0 commit comments

Comments
 (0)