Skip to content

Commit ddbf57e

Browse files
committed
Initial code donation.
Signed-off-by: Markku-Juhani O. Saarinen <[email protected]>
1 parent 880a5f5 commit ddbf57e

27 files changed

+5865
-0
lines changed

.clang-format

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
2+
#
3+
# clang-format style file for mlkem-native
4+
#
5+
BasedOnStyle: Google
6+
MaxEmptyLinesToKeep: 3
7+
AllowShortIfStatementsOnASingleLine: false
8+
AllowShortLoopsOnASingleLine: false
9+
DerivePointerAlignment: false
10+
PointerAlignment: Right
11+
# TODO(davidben): The default for Google style is now Regroup, but the default
12+
# IncludeCategories does not recognize <openssl/header.h>. We should
13+
# reconfigure IncludeCategories to match. For now, keep it at Preserve.
14+
IncludeBlocks: Preserve
15+
16+
# Designate CBMC contracts/macros that appear in .h files
17+
# as "attributes" so they don't get increasingly indented line after line
18+
BreakBeforeBraces: Allman
19+
InsertBraces: true
20+
WhitespaceSensitiveMacros: ['__contract__', '__loop__' ]
21+
Macros:
22+
# Make this artifically long to avoid function bodies after short contracts
23+
- __contract__(x)={ void a; void b; void c; void d; void e; void f; } void abcdefghijklmnopqrstuvw()
24+
- __loop__(x)={}
25+
# Make this artifically long to force line break
26+
- MLK_INTERNAL_API=void abcdefghijklmnopqrstuvwabcdefghijklmnopqrstuvwabcdefg();

.gitignore

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# project specific
2+
xtest
3+
xkat
4+
xfips205
5+
acvp_cases.sh
6+
7+
__pycache__
8+
*/__pycache__
9+
*.rsp
10+
.DS_Store
11+
firmware.*
12+
*.vvp
13+
14+
# Prerequisites
15+
*.d
16+
17+
# Object files
18+
*.o
19+
*.ko
20+
*.obj
21+
*.elf
22+
23+
# Linker output
24+
*.ilk
25+
*.map
26+
*.exp
27+
28+
# Precompiled Headers
29+
*.gch
30+
*.pch
31+
32+
# Libraries
33+
*.lib
34+
*.a
35+
*.la
36+
*.lo
37+
38+
# Shared objects (inc. Windows DLLs)
39+
*.dll
40+
*.so
41+
*.so.*
42+
*.dylib
43+
44+
# Executables
45+
*.exe
46+
*.out
47+
*.app
48+
*.i*86
49+
*.x86_64
50+
*.hex
51+
52+
# Debug files
53+
*.dSYM/
54+
*.su
55+
*.idb
56+
*.pdb
57+
58+
# Kernel Module Compile Results
59+
*.mod*
60+
*.cmd
61+
.tmp_versions/
62+
modules.order
63+
Module.symvers
64+
Mkfile.old
65+
dkms.conf

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "test/ACVP-Server"]
2+
path = test/ACVP-Server
3+
url = https://github.com/usnistgov/ACVP-Server.git

LICENSE

Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
(The code was originally written by Markku-Juhani O. Saarinen in 2023-25 and
2+
donated to the slhdsa-c project and derived projects.)
3+
4+
5+
ISC license
6+
-----------
7+
8+
Copyright (c) The slhdsa-c project authors
9+
10+
Permission to use, copy, modify, and/or distribute this software for any purpose
11+
with or without fee is hereby granted, provided that the above copyright notice
12+
and this permission notice appear in all copies.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
15+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16+
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
17+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
18+
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19+
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
20+
THIS SOFTWARE.
21+
22+
23+
MIT license
24+
-----------
25+
26+
Copyright (c) The slhdsa-c project authors
27+
28+
Permission is hereby granted, free of charge, to any person obtaining a copy of
29+
this software and associated documentation files (the “Software”), to deal in
30+
the Software without restriction, including without limitation the rights to
31+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
32+
the Software, and to permit persons to whom the Software is furnished to do so,
33+
subject to the following conditions:
34+
35+
The above copyright notice and this permission notice shall be included in all
36+
copies or substantial portions of the Software.
37+
38+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
39+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
40+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
41+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
42+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
43+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
44+
45+
Apache-2.0 license for slhdsa-c content
46+
---------------------------------------
47+
48+
Apache License
49+
Version 2.0, January 2004
50+
http://www.apache.org/licenses/
51+
52+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
53+
54+
1. Definitions.
55+
56+
"License" shall mean the terms and conditions for use, reproduction,
57+
and distribution as defined by Sections 1 through 9 of this document.
58+
59+
"Licensor" shall mean the copyright owner or entity authorized by
60+
the copyright owner that is granting the License.
61+
62+
"Legal Entity" shall mean the union of the acting entity and all
63+
other entities that control, are controlled by, or are under common
64+
control with that entity. For the purposes of this definition,
65+
"control" means (i) the power, direct or indirect, to cause the
66+
direction or management of such entity, whether by contract or
67+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
68+
outstanding shares, or (iii) beneficial ownership of such entity.
69+
70+
"You" (or "Your") shall mean an individual or Legal Entity
71+
exercising permissions granted by this License.
72+
73+
"Source" form shall mean the preferred form for making modifications,
74+
including but not limited to software source code, documentation
75+
source, and configuration files.
76+
77+
"Object" form shall mean any form resulting from mechanical
78+
transformation or translation of a Source form, including but
79+
not limited to compiled object code, generated documentation,
80+
and conversions to other media types.
81+
82+
"Work" shall mean the work of authorship, whether in Source or
83+
Object form, made available under the License, as indicated by a
84+
copyright notice that is included in or attached to the work
85+
(an example is provided in the Appendix below).
86+
87+
"Derivative Works" shall mean any work, whether in Source or Object
88+
form, that is based on (or derived from) the Work and for which the
89+
editorial revisions, annotations, elaborations, or other modifications
90+
represent, as a whole, an original work of authorship. For the purposes
91+
of this License, Derivative Works shall not include works that remain
92+
separable from, or merely link (or bind by name) to the interfaces of,
93+
the Work and Derivative Works thereof.
94+
95+
"Contribution" shall mean any work of authorship, including
96+
the original version of the Work and any modifications or additions
97+
to that Work or Derivative Works thereof, that is intentionally
98+
submitted to Licensor for inclusion in the Work by the copyright owner
99+
or by an individual or Legal Entity authorized to submit on behalf of
100+
the copyright owner. For the purposes of this definition, "submitted"
101+
means any form of electronic, verbal, or written communication sent
102+
to the Licensor or its representatives, including but not limited to
103+
communication on electronic mailing lists, source code control systems,
104+
and issue tracking systems that are managed by, or on behalf of, the
105+
Licensor for the purpose of discussing and improving the Work, but
106+
excluding communication that is conspicuously marked or otherwise
107+
designated in writing by the copyright owner as "Not a Contribution."
108+
109+
"Contributor" shall mean Licensor and any individual or Legal Entity
110+
on behalf of whom a Contribution has been received by Licensor and
111+
subsequently incorporated within the Work.
112+
113+
2. Grant of Copyright License. Subject to the terms and conditions of
114+
this License, each Contributor hereby grants to You a perpetual,
115+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
116+
copyright license to reproduce, prepare Derivative Works of,
117+
publicly display, publicly perform, sublicense, and distribute the
118+
Work and such Derivative Works in Source or Object form.
119+
120+
3. Grant of Patent License. Subject to the terms and conditions of
121+
this License, each Contributor hereby grants to You a perpetual,
122+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
123+
(except as stated in this section) patent license to make, have made,
124+
use, offer to sell, sell, import, and otherwise transfer the Work,
125+
where such license applies only to those patent claims licensable
126+
by such Contributor that are necessarily infringed by their
127+
Contribution(s) alone or by combination of their Contribution(s)
128+
with the Work to which such Contribution(s) was submitted. If You
129+
institute patent litigation against any entity (including a
130+
cross-claim or counterclaim in a lawsuit) alleging that the Work
131+
or a Contribution incorporated within the Work constitutes direct
132+
or contributory patent infringement, then any patent licenses
133+
granted to You under this License for that Work shall terminate
134+
as of the date such litigation is filed.
135+
136+
4. Redistribution. You may reproduce and distribute copies of the
137+
Work or Derivative Works thereof in any medium, with or without
138+
modifications, and in Source or Object form, provided that You
139+
meet the following conditions:
140+
141+
(a) You must give any other recipients of the Work or
142+
Derivative Works a copy of this License; and
143+
144+
(b) You must cause any modified files to carry prominent notices
145+
stating that You changed the files; and
146+
147+
(c) You must retain, in the Source form of any Derivative Works
148+
that You distribute, all copyright, patent, trademark, and
149+
attribution notices from the Source form of the Work,
150+
excluding those notices that do not pertain to any part of
151+
the Derivative Works; and
152+
153+
(d) If the Work includes a "NOTICE" text file as part of its
154+
distribution, then any Derivative Works that You distribute must
155+
include a readable copy of the attribution notices contained
156+
within such NOTICE file, excluding those notices that do not
157+
pertain to any part of the Derivative Works, in at least one
158+
of the following places: within a NOTICE text file distributed
159+
as part of the Derivative Works; within the Source form or
160+
documentation, if provided along with the Derivative Works; or,
161+
within a display generated by the Derivative Works, if and
162+
wherever such third-party notices normally appear. The contents
163+
of the NOTICE file are for informational purposes only and
164+
do not modify the License. You may add Your own attribution
165+
notices within Derivative Works that You distribute, alongside
166+
or as an addendum to the NOTICE text from the Work, provided
167+
that such additional attribution notices cannot be construed
168+
as modifying the License.
169+
170+
You may add Your own copyright statement to Your modifications and
171+
may provide additional or different license terms and conditions
172+
for use, reproduction, or distribution of Your modifications, or
173+
for any such Derivative Works as a whole, provided Your use,
174+
reproduction, and distribution of the Work otherwise complies with
175+
the conditions stated in this License.
176+
177+
5. Submission of Contributions. Unless You explicitly state otherwise,
178+
any Contribution intentionally submitted for inclusion in the Work
179+
by You to the Licensor shall be under the terms and conditions of
180+
this License, without any additional terms or conditions.
181+
Notwithstanding the above, nothing herein shall supersede or modify
182+
the terms of any separate license agreement you may have executed
183+
with Licensor regarding such Contributions.
184+
185+
6. Trademarks. This License does not grant permission to use the trade
186+
names, trademarks, service marks, or product names of the Licensor,
187+
except as required for reasonable and customary use in describing the
188+
origin of the Work and reproducing the content of the NOTICE file.
189+
190+
7. Disclaimer of Warranty. Unless required by applicable law or
191+
agreed to in writing, Licensor provides the Work (and each
192+
Contributor provides its Contributions) on an "AS IS" BASIS,
193+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
194+
implied, including, without limitation, any warranties or conditions
195+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
196+
PARTICULAR PURPOSE. You are solely responsible for determining the
197+
appropriateness of using or redistributing the Work and assume any
198+
risks associated with Your exercise of permissions under this License.
199+
200+
8. Limitation of Liability. In no event and under no legal theory,
201+
whether in tort (including negligence), contract, or otherwise,
202+
unless required by applicable law (such as deliberate and grossly
203+
negligent acts) or agreed to in writing, shall any Contributor be
204+
liable to You for damages, including any direct, indirect, special,
205+
incidental, or consequential damages of any character arising as a
206+
result of this License or out of the use or inability to use the
207+
Work (including but not limited to damages for loss of goodwill,
208+
work stoppage, computer failure or malfunction, or any and all
209+
other commercial damages or losses), even if such Contributor
210+
has been advised of the possibility of such damages.
211+
212+
9. Accepting Warranty or Additional Liability. While redistributing
213+
the Work or Derivative Works thereof, You may choose to offer,
214+
and charge a fee for, acceptance of support, warranty, indemnity,
215+
or other liability obligations and/or rights consistent with this
216+
License. However, in accepting such obligations, You may act only
217+
on Your own behalf and on Your sole responsibility, not on behalf
218+
of any other Contributor, and only if You agree to indemnify,
219+
defend, and hold each Contributor harmless for any liability
220+
incurred by, or claims asserted against, such Contributor by reason
221+
of your accepting any such warranty or additional liability.
222+
223+
END OF TERMS AND CONDITIONS
224+
225+
APPENDIX: How to apply the Apache License to your work.
226+
227+
To apply the Apache License to your work, attach the following
228+
boilerplate notice, with the fields enclosed by brackets "[]"
229+
replaced with your own identifying information. (Don't include
230+
the brackets!) The text should be enclosed in the appropriate
231+
comment syntax for the file format. We also recommend that a
232+
file or class name and description of purpose be included on the
233+
same "printed page" as the copyright notice for easier
234+
identification within third-party archives.
235+
236+
Copyright (c) The slhdsa-c project authors
237+
238+
Licensed under the Apache License, Version 2.0 (the "License");
239+
you may not use this file except in compliance with the License.
240+
You may obtain a copy of the License at
241+
242+
http://www.apache.org/licenses/LICENSE-2.0
243+
244+
Unless required by applicable law or agreed to in writing, software
245+
distributed under the License is distributed on an "AS IS" BASIS,
246+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
247+
See the License for the specific language governing permissions and
248+
limitations under the License.

Makefile

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Copyright (c) The slhdsa-c project authors
2+
# SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
3+
4+
.PHONY: test
5+
6+
XTEST ?= xfips205
7+
CSRC = $(wildcard *.c) test/xfips205.c
8+
OBJS = $(CSRC:.c=.o)
9+
KATNUM ?= 1
10+
11+
CC = gcc
12+
CFLAGS := -Wall \
13+
-Wextra \
14+
-Werror=unused-result \
15+
-Wpedantic \
16+
-Werror \
17+
-Wmissing-prototypes \
18+
-Wshadow \
19+
-Wpointer-arith \
20+
-Wredundant-decls \
21+
-Wno-long-long \
22+
-Wno-unknown-pragmas \
23+
-O3 \
24+
-fomit-frame-pointer \
25+
-std=c99 \
26+
-pedantic
27+
28+
LDLIBS +=
29+
30+
$(XTEST): $(OBJS)
31+
$(CC) $(LDFLAGS) $(CFLAGS) -o $(XTEST) $(OBJS) $(LDLIBS)
32+
33+
%.o: %.[cS]
34+
$(CC) $(CFLAGS) -c $^ -o $@
35+
36+
# without gnu parallel: bash test/acvp_cases.sh | tee test.log
37+
test: $(XTEST) test/acvp_cases.sh
38+
cat test/acvp_cases.sh | parallel --pipe bash | tee test.log
39+
@echo "=== test summary ==="
40+
@echo "PASS:" `grep -c PASS test.log`
41+
@echo "SKIP:" `grep -c SKIP test.log`
42+
@echo "FAIL:" `grep -c FAIL test.log`
43+
44+
test/acvp_cases.sh:
45+
cd test && $(MAKE) acvp_cases.sh
46+
47+
clean:
48+
$(RM) -rf $(XTEST) $(OBJS) *.rsp *.req *.log
49+
cd test && $(MAKE) clean

0 commit comments

Comments
 (0)