xref: /freebsd/crypto/openssh/mlkem_mldsa.sh (revision bb5c77e9d281d6def6835d48249898764bc6a5fe)
1*bb5c77e9SEd Maste#!/bin/sh
2*bb5c77e9SEd Maste#       $OpenBSD: mlkem_mldsa.sh,v 1.1 2026/06/14 03:59:34 djm Exp $
3*bb5c77e9SEd Maste#       Placed in the Public Domain.
4*bb5c77e9SEd Maste#
5*bb5c77e9SEd Maste
6*bb5c77e9SEd MasteWANT_LIBCRUX_REVISION="origin/jonas/combined-extraction-mldsa"
7*bb5c77e9SEd Maste
8*bb5c77e9SEd MasteBASE="libcrux/combined_extraction/generated"
9*bb5c77e9SEd MasteFILES="
10*bb5c77e9SEd Maste	$BASE/eurydice_glue.h
11*bb5c77e9SEd Maste	$BASE/combined_core.h
12*bb5c77e9SEd Maste	$BASE/libcrux_sha3_portable.h
13*bb5c77e9SEd Maste	$BASE/libcrux_mlkem_core.h
14*bb5c77e9SEd Maste	$BASE/libcrux_mldsa_core.h
15*bb5c77e9SEd Maste	$BASE/libcrux_ct_ops.h
16*bb5c77e9SEd Maste	$BASE/libcrux_mldsa_portable.h
17*bb5c77e9SEd Maste	$BASE/libcrux_mldsa44_portable.h
18*bb5c77e9SEd Maste	$BASE/libcrux_mldsa65_portable.h
19*bb5c77e9SEd Maste	$BASE/libcrux_mldsa87_portable.h
20*bb5c77e9SEd Maste	$BASE/libcrux_mlkem768_portable.h
21*bb5c77e9SEd Maste"
22*bb5c77e9SEd Maste
23*bb5c77e9SEd MasteSTART="$PWD"
24*bb5c77e9SEd Mastedie() {
25*bb5c77e9SEd Maste	echo "$@" 1>&2
26*bb5c77e9SEd Maste	exit 1
27*bb5c77e9SEd Maste}
28*bb5c77e9SEd Maste
29*bb5c77e9SEd Masteset -xeuo pipefail
30*bb5c77e9SEd Mastetest -d libcrux || git clone https://github.com/cryspen/libcrux
31*bb5c77e9SEd Mastecd libcrux
32*bb5c77e9SEd Mastetest `git diff | wc -l` -ne 0 && die "tree has unstaged changes"
33*bb5c77e9SEd Mastegit fetch
34*bb5c77e9SEd Mastegit checkout -B extract 1>&2
35*bb5c77e9SEd Mastegit reset --hard $WANT_LIBCRUX_REVISION 1>&2
36*bb5c77e9SEd MasteLIBCRUX_REVISION=`git rev-parse HEAD`
37*bb5c77e9SEd Masteset +x
38*bb5c77e9SEd Maste
39*bb5c77e9SEd Mastecd $START
40*bb5c77e9SEd Maste(
41*bb5c77e9SEd Masteprintf '/*  $Open'; printf 'BSD$ */\n' # Sigh
42*bb5c77e9SEd Masteecho
43*bb5c77e9SEd Masteecho "/* Extracted from libcrux revision $LIBCRUX_REVISION */"
44*bb5c77e9SEd Masteecho
45*bb5c77e9SEd Masteecho '/*'
46*bb5c77e9SEd Mastecat libcrux/LICENSE-MIT | sed 's/^/ * /;s/ *$//'
47*bb5c77e9SEd Masteecho ' */'
48*bb5c77e9SEd Masteecho
49*bb5c77e9SEd Maste
50*bb5c77e9SEd MasteLSHIFT="<<"
51*bb5c77e9SEd Mastecat << _EOF
52*bb5c77e9SEd Maste#if !defined(__GNUC__) || (__GNUC__ < 2)
53*bb5c77e9SEd Maste# define __attribute__(x)
54*bb5c77e9SEd Maste#endif
55*bb5c77e9SEd Maste#define KRML_MUSTINLINE inline
56*bb5c77e9SEd Maste#define KRML_NOINLINE __attribute__((noinline, unused))
57*bb5c77e9SEd Maste#define KRML_HOST_EPRINTF(...)
58*bb5c77e9SEd Maste#define KRML_HOST_EXIT(x) fatal_f("internal error")
59*bb5c77e9SEd Maste#define KRML_UNION_CONSTRUCTOR(T)
60*bb5c77e9SEd Maste
61*bb5c77e9SEd Mastestatic inline void
62*bb5c77e9SEd Mastestore64_le(uint8_t dst[8], uint64_t src)
63*bb5c77e9SEd Maste{
64*bb5c77e9SEd Maste	dst[0] = src & 0xff;
65*bb5c77e9SEd Maste	dst[1] = (src >> 8) & 0xff;
66*bb5c77e9SEd Maste	dst[2] = (src >> 16) & 0xff;
67*bb5c77e9SEd Maste	dst[3] = (src >> 24) & 0xff;
68*bb5c77e9SEd Maste	dst[4] = (src >> 32) & 0xff;
69*bb5c77e9SEd Maste	dst[5] = (src >> 40) & 0xff;
70*bb5c77e9SEd Maste	dst[6] = (src >> 48) & 0xff;
71*bb5c77e9SEd Maste	dst[7] = (src >> 56) & 0xff;
72*bb5c77e9SEd Maste}
73*bb5c77e9SEd Maste
74*bb5c77e9SEd Mastestatic inline void
75*bb5c77e9SEd Mastestore32_le(uint8_t dst[4], uint32_t src)
76*bb5c77e9SEd Maste{
77*bb5c77e9SEd Maste	dst[0] = src & 0xff;
78*bb5c77e9SEd Maste	dst[1] = (src >> 8) & 0xff;
79*bb5c77e9SEd Maste	dst[2] = (src >> 16) & 0xff;
80*bb5c77e9SEd Maste	dst[3] = (src >> 24) & 0xff;
81*bb5c77e9SEd Maste}
82*bb5c77e9SEd Maste
83*bb5c77e9SEd Mastestatic inline void
84*bb5c77e9SEd Mastestore16_le(uint8_t dst[2], uint16_t src)
85*bb5c77e9SEd Maste{
86*bb5c77e9SEd Maste	dst[0] = src & 0xff;
87*bb5c77e9SEd Maste	dst[1] = (src >> 8) & 0xff;
88*bb5c77e9SEd Maste}
89*bb5c77e9SEd Maste
90*bb5c77e9SEd Mastestatic inline void
91*bb5c77e9SEd Mastestore32_be(uint8_t dst[4], uint32_t src)
92*bb5c77e9SEd Maste{
93*bb5c77e9SEd Maste	dst[0] = (src >> 24) & 0xff;
94*bb5c77e9SEd Maste	dst[1] = (src >> 16) & 0xff;
95*bb5c77e9SEd Maste	dst[2] = (src >> 8) & 0xff;
96*bb5c77e9SEd Maste	dst[3] = src & 0xff;
97*bb5c77e9SEd Maste}
98*bb5c77e9SEd Maste
99*bb5c77e9SEd Mastestatic inline uint64_t
100*bb5c77e9SEd Masteload64_le(uint8_t src[8])
101*bb5c77e9SEd Maste{
102*bb5c77e9SEd Maste	return (uint64_t)(src[0]) |
103*bb5c77e9SEd Maste	    ((uint64_t)(src[1]) $LSHIFT 8) |
104*bb5c77e9SEd Maste	    ((uint64_t)(src[2]) $LSHIFT 16) |
105*bb5c77e9SEd Maste	    ((uint64_t)(src[3]) $LSHIFT 24) |
106*bb5c77e9SEd Maste	    ((uint64_t)(src[4]) $LSHIFT 32) |
107*bb5c77e9SEd Maste	    ((uint64_t)(src[5]) $LSHIFT 40) |
108*bb5c77e9SEd Maste	    ((uint64_t)(src[6]) $LSHIFT 48) |
109*bb5c77e9SEd Maste	    ((uint64_t)(src[7]) $LSHIFT 56);
110*bb5c77e9SEd Maste}
111*bb5c77e9SEd Maste
112*bb5c77e9SEd Mastestatic inline uint32_t
113*bb5c77e9SEd Masteload32_le(uint8_t src[4])
114*bb5c77e9SEd Maste{
115*bb5c77e9SEd Maste	return (uint32_t)(src[0]) |
116*bb5c77e9SEd Maste	    ((uint32_t)(src[1]) $LSHIFT 8) |
117*bb5c77e9SEd Maste	    ((uint32_t)(src[2]) $LSHIFT 16) |
118*bb5c77e9SEd Maste	    ((uint32_t)(src[3]) $LSHIFT 24);
119*bb5c77e9SEd Maste}
120*bb5c77e9SEd Maste
121*bb5c77e9SEd Mastestatic inline uint16_t
122*bb5c77e9SEd Masteload16_le(uint8_t src[4])
123*bb5c77e9SEd Maste{
124*bb5c77e9SEd Maste	return (uint16_t)(src[0]) |
125*bb5c77e9SEd Maste	    ((uint16_t)(src[1]) $LSHIFT 8);
126*bb5c77e9SEd Maste}
127*bb5c77e9SEd Maste
128*bb5c77e9SEd Maste#ifdef MISSING_BUILTIN_POPCOUNT
129*bb5c77e9SEd Mastestatic inline unsigned int
130*bb5c77e9SEd Maste__builtin_popcount(unsigned int num)
131*bb5c77e9SEd Maste{
132*bb5c77e9SEd Maste  const int v[16] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 };
133*bb5c77e9SEd Maste  return v[num & 0xf] + v[(num >> 4) & 0xf];
134*bb5c77e9SEd Maste}
135*bb5c77e9SEd Maste#endif
136*bb5c77e9SEd Maste
137*bb5c77e9SEd Maste_EOF
138*bb5c77e9SEd Maste
139*bb5c77e9SEd Mastefor i in $FILES; do
140*bb5c77e9SEd Maste	echo "/* from $i */"
141*bb5c77e9SEd Maste	# Changes to all files:
142*bb5c77e9SEd Maste	#  - remove all includes, we inline everything required.
143*bb5c77e9SEd Maste	#  - cleanup whitespace
144*bb5c77e9SEd Maste	#  - convert C++-style constructors to C-style compound literals
145*bb5c77e9SEd Maste	#  - convert Result constructors to C initializers
146*bb5c77e9SEd Maste	#  - use anonymous unions to avoid "union U" redefinition errors
147*bb5c77e9SEd Maste	sed -e "/#include/d" \
148*bb5c77e9SEd Maste	    -e 's/[	 ]*$//' \
149*bb5c77e9SEd Maste	    $i | \
150*bb5c77e9SEd Maste	case "$i" in
151*bb5c77e9SEd Maste	*/eurydice_glue.h)
152*bb5c77e9SEd Maste		# Replace endian function for consistency.
153*bb5c77e9SEd Maste		perl -0777 -pe 's/(static inline void core_num__u32__to_be_bytes.*\n)([^}]*\n)/\1  store32_be(dst, src);\n/'
154*bb5c77e9SEd Maste		;;
155*bb5c77e9SEd Maste	# Default: pass through.
156*bb5c77e9SEd Maste	*)
157*bb5c77e9SEd Maste		cat
158*bb5c77e9SEd Maste		;;
159*bb5c77e9SEd Maste	esac | \
160*bb5c77e9SEd Maste	perl -0777 -pe 's/ <<\n\s+\(uint32_t\)\(int32_t\)0//g'
161*bb5c77e9SEd Maste	echo
162*bb5c77e9SEd Mastedone
163*bb5c77e9SEd Maste
164*bb5c77e9SEd Mastecat << _EOF
165*bb5c77e9SEd Maste
166*bb5c77e9SEd Maste/* rename some types to be a bit more ergonomic */
167*bb5c77e9SEd Maste
168*bb5c77e9SEd Maste/* ML-KEM 768 */
169*bb5c77e9SEd Mastetypedef Eurydice_arr_c7 libcrux_mlkem768_keypair_rnd;
170*bb5c77e9SEd Mastetypedef Eurydice_arr_ec libcrux_mlkem768_enc_rnd;
171*bb5c77e9SEd Mastetypedef libcrux_ml_kem_mlkem768_MlKem768KeyPair libcrux_mlkem768_keypair;
172*bb5c77e9SEd Mastetypedef Eurydice_arr_5f libcrux_mlkem768_pk;
173*bb5c77e9SEd Mastetypedef Eurydice_arr_7d libcrux_mlkem768_sk;
174*bb5c77e9SEd Mastetypedef Eurydice_arr_2b libcrux_mlkem768_ciphertext;
175*bb5c77e9SEd Mastetypedef tuple_f4 libcrux_mlkem768_enc_result;
176*bb5c77e9SEd Mastetypedef Eurydice_arr_ec libcrux_mlkem768_dec_result;
177*bb5c77e9SEd Maste/* ML-DSA 44 */
178*bb5c77e9SEd Mastetypedef Eurydice_arr_ec libcrux_mldsa44_keypair_rnd;
179*bb5c77e9SEd Mastetypedef libcrux_ml_dsa_ml_dsa_generic_ml_dsa_44_MLDSA44KeyPair
180*bb5c77e9SEd Maste    libcrux_mldsa44_keypair;
181*bb5c77e9SEd Mastetypedef Eurydice_arr_10 libcrux_mldsa44_sk;
182*bb5c77e9SEd Mastetypedef Eurydice_arr_02 libcrux_mldsa44_pk;
183*bb5c77e9SEd Mastetypedef Eurydice_borrow_slice_u8 libcrux_mldsa44_message;
184*bb5c77e9SEd Mastetypedef Eurydice_arr_ec libcrux_mldsa44_sign_rnd;
185*bb5c77e9SEd Mastetypedef core_result_Result_48 libcrux_mldsa44_sign_result;
186*bb5c77e9SEd Mastetypedef core_result_Result_41 libcrux_mldsa44_verify_result;
187*bb5c77e9SEd Mastetypedef Eurydice_arr_85 libcrux_mldsa44_signature;
188*bb5c77e9SEd Maste/* ML-DSA 65 */
189*bb5c77e9SEd Mastetypedef Eurydice_arr_ec libcrux_mldsa65_keypair_rnd;
190*bb5c77e9SEd Mastetypedef libcrux_ml_dsa_ml_dsa_generic_ml_dsa_65_MLDSA65KeyPair
191*bb5c77e9SEd Maste    libcrux_mldsa65_keypair;
192*bb5c77e9SEd Mastetypedef Eurydice_arr_24 libcrux_mldsa65_sk;
193*bb5c77e9SEd Mastetypedef Eurydice_arr_29 libcrux_mldsa65_pk;
194*bb5c77e9SEd Mastetypedef Eurydice_borrow_slice_u8 libcrux_mldsa65_message;
195*bb5c77e9SEd Mastetypedef Eurydice_arr_ec libcrux_mldsa65_sign_rnd;
196*bb5c77e9SEd Mastetypedef core_result_Result_8c libcrux_mldsa65_sign_result;
197*bb5c77e9SEd Mastetypedef core_result_Result_41 libcrux_mldsa65_verify_result;
198*bb5c77e9SEd Mastetypedef Eurydice_arr_0c libcrux_mldsa65_signature;
199*bb5c77e9SEd Maste/* ML-DSA 87 */
200*bb5c77e9SEd Mastetypedef Eurydice_arr_ec libcrux_mldsa87_keypair_rnd;
201*bb5c77e9SEd Mastetypedef libcrux_ml_dsa_ml_dsa_generic_ml_dsa_87_MLDSA87KeyPair
202*bb5c77e9SEd Maste    libcrux_mldsa87_keypair;
203*bb5c77e9SEd Mastetypedef Eurydice_arr_e2 libcrux_mldsa87_sk;
204*bb5c77e9SEd Mastetypedef Eurydice_arr_43 libcrux_mldsa87_pk;
205*bb5c77e9SEd Mastetypedef Eurydice_borrow_slice_u8 libcrux_mldsa87_message;
206*bb5c77e9SEd Mastetypedef Eurydice_arr_ec libcrux_mldsa87_sign_rnd;
207*bb5c77e9SEd Mastetypedef core_result_Result_8b libcrux_mldsa87_sign_result;
208*bb5c77e9SEd Mastetypedef core_result_Result_41 libcrux_mldsa87_verify_result;
209*bb5c77e9SEd Mastetypedef Eurydice_arr_93 libcrux_mldsa87_signature;
210*bb5c77e9SEd Maste
211*bb5c77e9SEd Maste#define LIBCRUX_RESULT_OK	core_result_Ok
212*bb5c77e9SEd Maste
213*bb5c77e9SEd Maste_EOF
214*bb5c77e9SEd Maste
215*bb5c77e9SEd Maste) > libcrux_internal.h_new
216*bb5c77e9SEd Maste
217*bb5c77e9SEd Maste# Do some checks on the resultant file
218*bb5c77e9SEd Maste
219*bb5c77e9SEd Mastecat > libcrux_internal_check.c << _EOF
220*bb5c77e9SEd Maste#include <sys/types.h>
221*bb5c77e9SEd Maste#include <stdio.h>
222*bb5c77e9SEd Maste#include <stdint.h>
223*bb5c77e9SEd Maste#include <stdlib.h>
224*bb5c77e9SEd Maste#include <stdbool.h>
225*bb5c77e9SEd Maste#include <string.h>
226*bb5c77e9SEd Maste#include <signal.h>
227*bb5c77e9SEd Maste#include <err.h>
228*bb5c77e9SEd Maste#include "crypto_api.h"
229*bb5c77e9SEd Maste#define fatal_f(x) exit(1)
230*bb5c77e9SEd Maste#include "libcrux_internal.h_new"
231*bb5c77e9SEd Maste
232*bb5c77e9SEd Maste#define TEST_MLDSA(L) do { \
233*bb5c77e9SEd Maste	libcrux_mldsa##L##_keypair_rnd kpseed##L = {0}; \
234*bb5c77e9SEd Maste	libcrux_mldsa##L##_keypair kp##L = {0}; \
235*bb5c77e9SEd Maste	libcrux_mldsa##L##_sk sk##L = {0}; \
236*bb5c77e9SEd Maste	libcrux_mldsa##L##_pk pk##L = {0}; \
237*bb5c77e9SEd Maste	const uint8_t msgdata##L[6] = { 0x4a, 0x75, 0x6c, 0x69, 0x75, 0x73 }; \
238*bb5c77e9SEd Maste	libcrux_mldsa##L##_message msg##L = { \
239*bb5c77e9SEd Maste		msgdata##L, sizeof(msgdata##L) \
240*bb5c77e9SEd Maste	}; \
241*bb5c77e9SEd Maste	const uint8_t ctxdata##L[4] = { 0x48, 0x75, 0x67, 0x6f }; \
242*bb5c77e9SEd Maste	libcrux_mldsa##L##_message ctx##L = { \
243*bb5c77e9SEd Maste		ctxdata##L, sizeof(ctxdata##L) \
244*bb5c77e9SEd Maste	}; \
245*bb5c77e9SEd Maste	libcrux_mldsa##L##_sign_rnd signseed##L = {0}; \
246*bb5c77e9SEd Maste	libcrux_mldsa##L##_sign_result signresult##L = {0}; \
247*bb5c77e9SEd Maste	libcrux_mldsa##L##_verify_result verifyresult##L = {0}; \
248*bb5c77e9SEd Maste	libcrux_mldsa##L##_signature sig##L = {0}; \
249*bb5c77e9SEd Maste	\
250*bb5c77e9SEd Maste	if (sizeof(kpseed##L.data) != MLDSA##L##_SEEDBYTES) \
251*bb5c77e9SEd Maste		errx(1, "libcrux_mldsa%d_keypair_rnd bad", L); \
252*bb5c77e9SEd Maste	if (sizeof(kp##L.verification_key.data) != MLDSA##L##_PUBLICKEYBYTES) \
253*bb5c77e9SEd Maste		errx(1, "libcrux_mldsa%d_keypair verification_key bad", L); \
254*bb5c77e9SEd Maste	if (sizeof(kp##L.signing_key.data) != MLDSA##L##_SECRETKEYBYTES) \
255*bb5c77e9SEd Maste		errx(1, "libcrux_mldsa%d_keypair signing_key bad", L); \
256*bb5c77e9SEd Maste	if (sizeof(pk##L.data) != MLDSA##L##_PUBLICKEYBYTES) \
257*bb5c77e9SEd Maste		errx(1, "libcrux_mldsa%d_pk bad", L); \
258*bb5c77e9SEd Maste	if (sizeof(sk##L.data) != MLDSA##L##_SECRETKEYBYTES) \
259*bb5c77e9SEd Maste		errx(1, "libcrux_mldsa%d_sk bad", L); \
260*bb5c77e9SEd Maste	if (sizeof(signresult##L.val.case_Ok.data) != MLDSA##L##_SIGBYTES) \
261*bb5c77e9SEd Maste		errx(1, "libcrux_mldsa%d_sign_result bad", L); \
262*bb5c77e9SEd Maste	if (sizeof(sig##L.data) != MLDSA##L##_SIGBYTES) \
263*bb5c77e9SEd Maste		errx(1, "libcrux_mldsa%d_signature bad", L); \
264*bb5c77e9SEd Maste	\
265*bb5c77e9SEd Maste	kp##L = libcrux_ml_dsa_ml_dsa_##L##_portable_generate_key_pair( \
266*bb5c77e9SEd Maste	    kpseed##L); \
267*bb5c77e9SEd Maste	sk##L = kp##L.signing_key; \
268*bb5c77e9SEd Maste	pk##L = kp##L.verification_key; \
269*bb5c77e9SEd Maste	signresult##L = libcrux_ml_dsa_ml_dsa_##L##_portable_sign(&sk##L, \
270*bb5c77e9SEd Maste	    msg##L, ctx##L, signseed##L); \
271*bb5c77e9SEd Maste	if (signresult##L.tag != LIBCRUX_RESULT_OK) \
272*bb5c77e9SEd Maste		errx(1, "libcrux_ml_dsa_ml_dsa_%d_portable_sign failed", L); \
273*bb5c77e9SEd Maste	sig##L = signresult##L.val.case_Ok; \
274*bb5c77e9SEd Maste	verifyresult##L = libcrux_ml_dsa_ml_dsa_##L##_portable_verify(&pk##L, \
275*bb5c77e9SEd Maste	    msg##L, ctx##L, &sig##L); \
276*bb5c77e9SEd Maste	if (verifyresult##L.tag != LIBCRUX_RESULT_OK) \
277*bb5c77e9SEd Maste		errx(1, "libcrux_ml_dsa_ml_dsa_%d_portable_verify failed", L); \
278*bb5c77e9SEd Maste	sig##L.data[10] ^= 0x10; /* corrupt the signature */ \
279*bb5c77e9SEd Maste	verifyresult##L = libcrux_ml_dsa_ml_dsa_##L##_portable_verify(&pk##L, \
280*bb5c77e9SEd Maste	    msg##L, ctx##L, &sig##L); \
281*bb5c77e9SEd Maste	if (verifyresult##L.tag == LIBCRUX_RESULT_OK) \
282*bb5c77e9SEd Maste		errx(1, "libcrux_ml_dsa_ml_dsa_%d_portable_verify fail2", L); \
283*bb5c77e9SEd Maste} while (0)
284*bb5c77e9SEd Maste
285*bb5c77e9SEd Masteint main(void) {
286*bb5c77e9SEd Maste	libcrux_mlkem768_keypair keypair = {0};
287*bb5c77e9SEd Maste	libcrux_mlkem768_pk pk = {0};
288*bb5c77e9SEd Maste	libcrux_mlkem768_sk sk = {0};
289*bb5c77e9SEd Maste	libcrux_mlkem768_ciphertext ct = {0};
290*bb5c77e9SEd Maste	libcrux_mlkem768_enc_result enc_result = {0};
291*bb5c77e9SEd Maste	libcrux_mlkem768_keypair_rnd kp_seed = {0};
292*bb5c77e9SEd Maste	libcrux_mlkem768_enc_rnd enc_seed = {0};
293*bb5c77e9SEd Maste	libcrux_mlkem768_dec_result shared_secret = {0};
294*bb5c77e9SEd Maste	uint8_t shared_key[crypto_kem_mlkem768_BYTES];
295*bb5c77e9SEd Maste
296*bb5c77e9SEd Maste	if (sizeof(keypair.pk.data) != crypto_kem_mlkem768_PUBLICKEYBYTES)
297*bb5c77e9SEd Maste		errx(1, "keypair.pk bad");
298*bb5c77e9SEd Maste	if (sizeof(keypair.sk.data) != crypto_kem_mlkem768_SECRETKEYBYTES)
299*bb5c77e9SEd Maste		errx(1, "keypair.sk bad");
300*bb5c77e9SEd Maste	if (sizeof(pk.data) != crypto_kem_mlkem768_PUBLICKEYBYTES)
301*bb5c77e9SEd Maste		errx(1, "pk bad");
302*bb5c77e9SEd Maste	if (sizeof(sk.data) != crypto_kem_mlkem768_SECRETKEYBYTES)
303*bb5c77e9SEd Maste		errx(1, "sk bad");
304*bb5c77e9SEd Maste	if (sizeof(ct.data) != crypto_kem_mlkem768_CIPHERTEXTBYTES)
305*bb5c77e9SEd Maste		errx(1, "ct bad");
306*bb5c77e9SEd Maste	if (sizeof(enc_result.fst.data) != crypto_kem_mlkem768_CIPHERTEXTBYTES)
307*bb5c77e9SEd Maste		errx(1, "enc_result ct bad");
308*bb5c77e9SEd Maste	if (sizeof(enc_result.snd.data) != crypto_kem_mlkem768_BYTES)
309*bb5c77e9SEd Maste		errx(1, "enc_result shared key bad");
310*bb5c77e9SEd Maste	if (sizeof(kp_seed.data) != crypto_kem_mlkem768_KEYPAIRSEEDBYTES)
311*bb5c77e9SEd Maste		errx(1, "keypair rnd bad");
312*bb5c77e9SEd Maste	if (sizeof(enc_seed.data) != crypto_kem_mlkem768_ENCSEEDBYTES)
313*bb5c77e9SEd Maste		errx(1, "keypair rnd bad");
314*bb5c77e9SEd Maste
315*bb5c77e9SEd Maste	keypair = libcrux_ml_kem_mlkem768_portable_generate_key_pair(kp_seed);
316*bb5c77e9SEd Maste	if (!libcrux_ml_kem_mlkem768_portable_validate_public_key(&keypair.pk))
317*bb5c77e9SEd Maste		errx(1, "valid smoke failed");
318*bb5c77e9SEd Maste	enc_result = libcrux_ml_kem_mlkem768_portable_encapsulate(&keypair.pk,
319*bb5c77e9SEd Maste	    enc_seed);
320*bb5c77e9SEd Maste	shared_secret = libcrux_ml_kem_mlkem768_portable_decapsulate(
321*bb5c77e9SEd Maste	    &keypair.sk, &enc_result.fst);
322*bb5c77e9SEd Maste	memcpy(shared_key, shared_secret.data, sizeof(shared_key));
323*bb5c77e9SEd Maste	if (memcmp(shared_key, enc_result.snd.data, sizeof(shared_key)) != 0)
324*bb5c77e9SEd Maste		errx(1, "smoke failed");
325*bb5c77e9SEd Maste
326*bb5c77e9SEd Maste	TEST_MLDSA(44);
327*bb5c77e9SEd Maste	TEST_MLDSA(65);
328*bb5c77e9SEd Maste	TEST_MLDSA(87);
329*bb5c77e9SEd Maste
330*bb5c77e9SEd Maste	return 0;
331*bb5c77e9SEd Maste}
332*bb5c77e9SEd Maste_EOF
333*bb5c77e9SEd Mastecc -Wall -Wextra -Wno-unused-parameter -I . -o libcrux_internal_check \
334*bb5c77e9SEd Maste	libcrux_internal_check.c
335*bb5c77e9SEd Maste./libcrux_internal_check
336*bb5c77e9SEd Maste
337*bb5c77e9SEd Mastemv libcrux_internal.h_new libcrux_internal.h
338*bb5c77e9SEd Masterm libcrux_internal_check libcrux_internal_check.c
339*bb5c77e9SEd Masteecho 1>&2
340*bb5c77e9SEd Masteecho "libcrux_internal.h OK" 1>&2
341*bb5c77e9SEd Maste
342