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
3 changes: 2 additions & 1 deletion mldsa/src/native/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ __contract__(
requires(memory_no_alias(p, sizeof(int32_t) * MLDSA_N))
requires(array_bound(p, 0, MLDSA_N, 0, MLDSA_Q))
assigns(memory_slice(p, sizeof(int32_t) * MLDSA_N))
ensures(array_bound(p, 0, MLDSA_N, 0, MLDSA_Q)));
ensures(array_bound(p, 0, MLDSA_N, 0, MLDSA_Q))
);
#endif /* MLD_USE_NATIVE_NTT_CUSTOM_ORDER */


Expand Down
61 changes: 24 additions & 37 deletions mldsa/src/polyvec.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
* with native backends, which are currently not yet namespaced. */
#define mld_polymat_permute_bitrev_to_custom \
MLD_ADD_PARAM_SET(mld_polymat_permute_bitrev_to_custom)
#define mld_polyvecl_permute_bitrev_to_custom \
MLD_ADD_PARAM_SET(mld_polyvecl_permute_bitrev_to_custom)
#define mld_polyvecl_pointwise_acc_montgomery_c \
MLD_ADD_PARAM_SET(mld_polyvecl_pointwise_acc_montgomery_c)

Expand All @@ -37,36 +35,6 @@
* No-op unless a native backend with a custom ordering is used.
*/

static void mld_polyvecl_permute_bitrev_to_custom(mld_polyvecl *v)
__contract__(
/* We don't specify that this should be a permutation, but only
* that it does not change the bound established at the end of
* mld_polyvec_matrix_expand.
*/
requires(memory_no_alias(v, sizeof(mld_polyvecl)))
requires(forall(x, 0, MLDSA_L,
array_bound(v->vec[x].coeffs, 0, MLDSA_N, 0, MLDSA_Q)))
assigns(memory_slice(v, sizeof(mld_polyvecl)))
ensures(forall(x, 0, MLDSA_L,
array_bound(v->vec[x].coeffs, 0, MLDSA_N, 0, MLDSA_Q))))
{
#if defined(MLD_USE_NATIVE_NTT_CUSTOM_ORDER)
unsigned i;
for (i = 0; i < MLDSA_L; i++)
__loop__(
assigns(i, memory_slice(v, sizeof(mld_polyvecl)))
invariant(i <= MLDSA_L)
invariant(forall(x, 0, MLDSA_L,
array_bound(v->vec[x].coeffs, 0, MLDSA_N, 0, MLDSA_Q))))
{
mld_poly_permute_bitrev_to_custom(v->vec[i].coeffs);
}
#else /* MLD_USE_NATIVE_NTT_CUSTOM_ORDER */
/* Nothing to do */
(void)v;
#endif /* !MLD_USE_NATIVE_NTT_CUSTOM_ORDER */
}

static void mld_polymat_permute_bitrev_to_custom(mld_polymat *mat)
__contract__(
/* We don't specify that this should be a permutation, but only
Expand All @@ -81,16 +49,36 @@ __contract__(
array_bound(mat->vec[k1].vec[l1].coeffs, 0, MLDSA_N, 0, MLDSA_Q))))
)
{
unsigned int i;
#if defined(MLD_USE_NATIVE_NTT_CUSTOM_ORDER)

unsigned int i, j;
for (i = 0; i < MLDSA_K; i++)
__loop__(
assigns(i, memory_slice(mat, sizeof(mld_polymat)))
assigns(i, j, memory_slice(mat, sizeof(mld_polymat)))
invariant(i <= MLDSA_K)
invariant(forall(k1, 0, MLDSA_K, forall(l1, 0, MLDSA_L,
array_bound(mat->vec[k1].vec[l1].coeffs, 0, MLDSA_N, 0, MLDSA_Q)))))
array_bound(mat->vec[k1].vec[l1].coeffs, 0, MLDSA_N, 0, MLDSA_Q))))
)
{
mld_polyvecl_permute_bitrev_to_custom(&mat->vec[i]);
for (j = 0; j < MLDSA_L; j++)
__loop__(
assigns(j, memory_slice(mat, sizeof(mld_polymat)))
invariant(i <= MLDSA_K)
invariant(j <= MLDSA_L)
invariant(forall(k2, 0, MLDSA_K, forall(l2, 0, MLDSA_L,
array_bound(mat->vec[k2].vec[l2].coeffs, 0, MLDSA_N, 0, MLDSA_Q))))
)
{
mld_poly_permute_bitrev_to_custom(mat->vec[i].vec[j].coeffs);
}
}

#else /* MLD_USE_NATIVE_NTT_CUSTOM_ORDER */

/* Nothing to do */
((void)mat);

#endif /* !MLD_USE_NATIVE_NTT_CUSTOM_ORDER */
}
#endif /* !MLD_CONFIG_REDUCE_RAM */

Expand Down Expand Up @@ -951,5 +939,4 @@ void mld_polyveck_unpack_t0(mld_polyveck *p,
/* To facilitate single-compilation-unit (SCU) builds, undefine all macros.
* Don't modify by hand -- this is auto-generated by scripts/autogen. */
#undef mld_polymat_permute_bitrev_to_custom
#undef mld_polyvecl_permute_bitrev_to_custom
#undef mld_polyvecl_pointwise_acc_montgomery_c
6 changes: 3 additions & 3 deletions nix/cbmc/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ buildEnv {
cbmc = cbmc.overrideAttrs (old: rec {
version = "6.8.0";
src = fetchFromGitHub {
owner = "diffblue";
owner = "tautschnig";
repo = "cbmc";
hash = "sha256-PT6AYiwkplCeyMREZnGZA0BKl4ZESRC02/9ibKg7mYU=";
tag = "cbmc-6.8.0";
hash = "sha256-ng1zjICpmoHUWkG1PuLRmLtaUBmEALpRgNEpbsrnMV8=";
rev = "4f514dbd70c89e3bae03a59f1dc9837acf25885c";
};
});
litani = callPackage ./litani.nix { }; # 1.29.0
Expand Down
2 changes: 1 addition & 1 deletion proofs/cbmc/polymat_permute_bitrev_to_custom/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c
PROJECT_SOURCES += $(SRCDIR)/mldsa/src/polyvec.c

CHECK_FUNCTION_CONTRACTS=mld_polymat_permute_bitrev_to_custom
USE_FUNCTION_CONTRACTS=mld_polyvecl_permute_bitrev_to_custom
USE_FUNCTION_CONTRACTS=
APPLY_LOOP_CONTRACTS=on
USE_DYNAMIC_FRAMES=1

Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
# Copyright (c) The mlkem-native project authors
# Copyright (c) The mldsa-native project authors
# SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT

include ../Makefile_params.common

HARNESS_ENTRY = harness
HARNESS_FILE = polyvecl_permute_bitrev_to_custom_native_harness
HARNESS_FILE = polymat_permute_bitrev_to_custom_native_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 = mld_polyvecl_permute_bitrev_to_custom_native
PROOF_UID = polymat_permute_bitrev_to_custom_native

DEFINES += -DMLD_CONFIG_USE_NATIVE_BACKEND_ARITH -DMLD_CONFIG_ARITH_BACKEND_FILE="\"dummy_backend.h\""
INCLUDES +=
UNWINDSET +=

REMOVE_FUNCTION_BODY +=
UNWINDSET +=

PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c
PROJECT_SOURCES += $(SRCDIR)/mldsa/src/polyvec.c

CHECK_FUNCTION_CONTRACTS=mld_polyvecl_permute_bitrev_to_custom
USE_FUNCTION_CONTRACTS= mld_poly_permute_bitrev_to_custom
CHECK_FUNCTION_CONTRACTS=mld_polymat_permute_bitrev_to_custom
USE_FUNCTION_CONTRACTS=mld_poly_permute_bitrev_to_custom
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 --slice-formula --no-array-field-sensitivity

FUNCTION_NAME = mld_polyvecl_permute_bitrev_to_custom_native
FUNCTION_NAME = polymat_permute_bitrev_to_custom_native

# 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
CBMC_OBJECT_BITS = 10

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

# 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
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

#include "polyvec.h"

void mld_polyvecl_permute_bitrev_to_custom(mld_polyvecl *v);
void mld_polymat_permute_bitrev_to_custom(mld_polymat *mat);

void harness(void)
{
mld_polyvecl *v;
mld_polyvecl_permute_bitrev_to_custom(v);
mld_polymat *mat;
mld_polymat_permute_bitrev_to_custom(mat);
}
55 changes: 0 additions & 55 deletions proofs/cbmc/polyvecl_permute_bitrev_to_custom/Makefile

This file was deleted.

This file was deleted.

Loading