Skip to content

Commit

Permalink
Re-baseline and introduce new fast NTT and inverse NTT code, followin…
Browse files Browse the repository at this point in the history
…g source re-organization in PR#674.

See comments on older PR#610.

All tests, proofs, and lint OK.

Signed-off-by: Rod Chapman <rodchap@amazon.com>

Correct list of called functions for this proof.

Signed-off-by: Rod Chapman <rodchap@amazon.com>

Update autogenerated files aftre rebase

Signed-off-by: Rod Chapman <rodchap@amazon.com>

Re-generate autogenerated files following rebase

Signed-off-by: Rod Chapman <rodchap@amazon.com>

Update auto-generated files and copyright messages following rebase

Signed-off-by: Rod Chapman <rodchap@amazon.com>

Update copyright notices for these news files

Signed-off-by: Rod Chapman <rodchap@amazon.com>

Update one more copyright notice

Signed-off-by: Rod Chapman <rodchap@amazon.com>
  • Loading branch information
rod-chapman authored and hanno-becker committed Feb 5, 2025
1 parent 7739a8f commit 676a80c
Show file tree
Hide file tree
Showing 35 changed files with 1,145 additions and 206 deletions.
688 changes: 541 additions & 147 deletions mlkem/poly.c

Large diffs are not rendered by default.

16 changes: 0 additions & 16 deletions proofs/cbmc/invntt_layer/invntt_layer_harness.c

This file was deleted.

55 changes: 55 additions & 0 deletions proofs/cbmc/invntt_layer321/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 = invntt_layer321_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 = invntt_layer321

DEFINES +=
INCLUDES +=

REMOVE_FUNCTION_BODY +=
UNWINDSET +=

PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c
PROJECT_SOURCES += $(SRCDIR)/mlkem/zetas.c
PROJECT_SOURCES += $(SRCDIR)/mlkem/poly.c

CHECK_FUNCTION_CONTRACTS=$(MLKEM_NAMESPACE)invntt_layer321
USE_FUNCTION_CONTRACTS=$(MLKEM_NAMESPACE)fqmul
APPLY_LOOP_CONTRACTS=on
USE_DYNAMIC_FRAMES=1

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

FUNCTION_NAME = $(MLKEM_NAMESPACE)invntt_layer321

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

# 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
# ("mlkem/poly.c") in PROJECT_SOURCES).
# REWRITTEN_SOURCES = $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i
# include ../Makefile.common
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_SOURCE = $(SRCDIR)/mlkem/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
File renamed without changes.
18 changes: 18 additions & 0 deletions proofs/cbmc/invntt_layer321/invntt_layer321_harness.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) 2024-2025 The mlkem-native project authors
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT-0

#include <poly.h>

#define invntt_layer321 MLKEM_NAMESPACE(invntt_layer321)
void invntt_layer321(int16_t *r);

/**
* @brief Starting point for formal analysis
*
*/
void harness(void)
{
int16_t *a;
invntt_layer321(a);
}
54 changes: 54 additions & 0 deletions proofs/cbmc/invntt_layer54/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# SPDX-License-Identifier: Apache-2.0

include ../Makefile_params.common

HARNESS_ENTRY = harness
HARNESS_FILE = invntt_layer54_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 = invntt_layer54

DEFINES +=
INCLUDES +=

REMOVE_FUNCTION_BODY +=
UNWINDSET +=

PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c
PROJECT_SOURCES += $(SRCDIR)/mlkem/poly.c

CHECK_FUNCTION_CONTRACTS=$(MLKEM_NAMESPACE)invntt_layer54
USE_FUNCTION_CONTRACTS=$(MLKEM_NAMESPACE)invntt_layer54_butterfly
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 = $(MLKEM_NAMESPACE)invntt_layer54

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

# 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
# ("mlkem/poly.c") in PROJECT_SOURCES).
# REWRITTEN_SOURCES = $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i
# include ../Makefile.common
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_SOURCE = $(SRCDIR)/mlkem/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
File renamed without changes.
18 changes: 18 additions & 0 deletions proofs/cbmc/invntt_layer54/invntt_layer54_harness.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) 2024-2025 The mlkem-native project authors
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT-0

#include <poly.h>

#define invntt_layer54 MLKEM_NAMESPACE(invntt_layer54)
void invntt_layer54(int16_t *r);

/**
* @brief Starting point for formal analysis
*
*/
void harness(void)
{
int16_t *a;
invntt_layer54(a);
}
55 changes: 55 additions & 0 deletions proofs/cbmc/invntt_layer54_butterfly/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 = invntt_layer54_butterfly_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 = invntt_layer54_butterfly

DEFINES +=
INCLUDES +=

REMOVE_FUNCTION_BODY +=
UNWINDSET +=

PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c
PROJECT_SOURCES += $(SRCDIR)/mlkem/zetas.c
PROJECT_SOURCES += $(SRCDIR)/mlkem/poly.c

CHECK_FUNCTION_CONTRACTS=$(MLKEM_NAMESPACE)invntt_layer54_butterfly
USE_FUNCTION_CONTRACTS=$(MLKEM_NAMESPACE)fqmul $(MLKEM_NAMESPACE)barrett_reduce
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 = $(MLKEM_NAMESPACE)invntt_layer54_butterfly

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

# 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
# ("mlkem/poly.c") in PROJECT_SOURCES).
# REWRITTEN_SOURCES = $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i
# include ../Makefile.common
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_SOURCE = $(SRCDIR)/mlkem/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
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) 2024-2025 The mlkem-native project authors
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT-0

#include <poly.h>

#define invntt_layer54_butterfly MLKEM_NAMESPACE(invntt_layer54_butterfly)
void invntt_layer54_butterfly(int16_t r[MLKEM_N], const unsigned zeta_index,
const unsigned start);

/**
* @brief Starting point for formal analysis
*
*/
void harness(void)
{
int16_t *a;
unsigned zi;
unsigned start;
invntt_layer54_butterfly(a, zi, start);
}
55 changes: 55 additions & 0 deletions proofs/cbmc/invntt_layer6/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 = invntt_layer6_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 = invntt_layer6

DEFINES +=
INCLUDES +=

REMOVE_FUNCTION_BODY +=
UNWINDSET +=

PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c
PROJECT_SOURCES += $(SRCDIR)/mlkem/zetas.c
PROJECT_SOURCES += $(SRCDIR)/mlkem/poly.c

CHECK_FUNCTION_CONTRACTS=$(MLKEM_NAMESPACE)invntt_layer6
USE_FUNCTION_CONTRACTS=$(MLKEM_NAMESPACE)fqmul
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 = $(MLKEM_NAMESPACE)invntt_layer6

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

# 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
# ("mlkem/poly.c") in PROJECT_SOURCES).
# REWRITTEN_SOURCES = $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i
# include ../Makefile.common
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_SOURCE = $(SRCDIR)/mlkem/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
3 changes: 3 additions & 0 deletions proofs/cbmc/invntt_layer6/cbmc-proof.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SPDX-License-Identifier: Apache-2.0

# This file marks this directory as containing a CBMC proof.
18 changes: 18 additions & 0 deletions proofs/cbmc/invntt_layer6/invntt_layer6_harness.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) 2024-2025 The mlkem-native project authors
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT-0

#include <poly.h>

#define invntt_layer6 MLKEM_NAMESPACE(invntt_layer6)
void invntt_layer6(int16_t *r);

/**
* @brief Starting point for formal analysis
*
*/
void harness(void)
{
int16_t *a;
invntt_layer6(a);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
include ../Makefile_params.common

HARNESS_ENTRY = harness
HARNESS_FILE = invntt_layer_harness
HARNESS_FILE = invntt_layer7_invert_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 = invntt_layer
PROOF_UID = invntt_layer7_invert

DEFINES +=
INCLUDES +=
Expand All @@ -16,9 +16,10 @@ REMOVE_FUNCTION_BODY +=
UNWINDSET +=

PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c
PROJECT_SOURCES += $(SRCDIR)/mlkem/poly.c $(SRCDIR)/mlkem/zetas.c
PROJECT_SOURCES += $(SRCDIR)/mlkem/zetas.c
PROJECT_SOURCES += $(SRCDIR)/mlkem/poly.c

CHECK_FUNCTION_CONTRACTS=$(MLKEM_NAMESPACE)invntt_layer
CHECK_FUNCTION_CONTRACTS=$(MLKEM_NAMESPACE)invntt_layer7_invert
USE_FUNCTION_CONTRACTS=$(MLKEM_NAMESPACE)fqmul $(MLKEM_NAMESPACE)barrett_reduce
APPLY_LOOP_CONTRACTS=on
USE_DYNAMIC_FRAMES=1
Expand All @@ -27,7 +28,7 @@ USE_DYNAMIC_FRAMES=1
EXTERNAL_SAT_SOLVER=
CBMCFLAGS=--smt2

FUNCTION_NAME = invntt_layer
FUNCTION_NAME = invntt_layer7_invert

# 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
Expand Down
3 changes: 3 additions & 0 deletions proofs/cbmc/invntt_layer7_invert/cbmc-proof.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SPDX-License-Identifier: Apache-2.0

# This file marks this directory as containing a CBMC proof.
18 changes: 18 additions & 0 deletions proofs/cbmc/invntt_layer7_invert/invntt_layer7_invert_harness.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) 2024-2025 The mlkem-native project authors
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT-0

#include <poly.h>

#define invntt_layer7_invert MLKEM_NAMESPACE(invntt_layer7_invert)
void invntt_layer7_invert(int16_t *r);

/**
* @brief Starting point for formal analysis
*
*/
void harness(void)
{
int16_t *a;
invntt_layer7_invert(a);
}
Loading

0 comments on commit 676a80c

Please sign in to comment.