diff options
author | beck <> | 2025-08-14 15:48:48 +0000 |
---|---|---|
committer | beck <> | 2025-08-14 15:48:48 +0000 |
commit | 6452fa9fc6f33dac80ee572764b9fe29a469f8ce (patch) | |
tree | 0956ae670e4f193442bcf99d2b1fb70a43a6b5b5 /src/regress/lib/libcrypto/mlkem/mlkem_tests_util.c | |
parent | 9bef27f78e41e8026f1d588e4e36e385061f3deb (diff) | |
download | openbsd-6452fa9fc6f33dac80ee572764b9fe29a469f8ce.tar.gz openbsd-6452fa9fc6f33dac80ee572764b9fe29a469f8ce.tar.bz2 openbsd-6452fa9fc6f33dac80ee572764b9fe29a469f8ce.zip |
Add a reasonable ML-KEM API for public use.
Adapt the tests to use this API.
This does not yet make the symbols public in Symbols.list
which will happen shortly with a bump.
This includes some partial rototilling of the non-public
interfaces which will be shortly continued when the internal
code is deduplicated to not have multiple copies for ML-KEM
768 and ML-KEM 1024 (which is just an artifact of unravelling
the boring C++ code).
ok jsing@, tb@
Diffstat (limited to 'src/regress/lib/libcrypto/mlkem/mlkem_tests_util.c')
-rw-r--r-- | src/regress/lib/libcrypto/mlkem/mlkem_tests_util.c | 158 |
1 files changed, 2 insertions, 156 deletions
diff --git a/src/regress/lib/libcrypto/mlkem/mlkem_tests_util.c b/src/regress/lib/libcrypto/mlkem/mlkem_tests_util.c index 68bd5d4871..9d6e604386 100644 --- a/src/regress/lib/libcrypto/mlkem/mlkem_tests_util.c +++ b/src/regress/lib/libcrypto/mlkem/mlkem_tests_util.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: mlkem_tests_util.c,v 1.8 2025/05/20 00:33:41 beck Exp $ */ | 1 | /* $OpenBSD: mlkem_tests_util.c,v 1.9 2025/08/14 15:48:48 beck Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2024 Google Inc. | 3 | * Copyright (c) 2024 Google Inc. |
4 | * Copyright (c) 2024 Bob Beck <beck@obtuse.com> | 4 | * Copyright (c) 2024 Bob Beck <beck@obtuse.com> |
@@ -23,7 +23,7 @@ | |||
23 | #include <string.h> | 23 | #include <string.h> |
24 | 24 | ||
25 | #include "bytestring.h" | 25 | #include "bytestring.h" |
26 | #include "mlkem.h" | 26 | #include <openssl/mlkem.h> |
27 | 27 | ||
28 | #include "mlkem_internal.h" | 28 | #include "mlkem_internal.h" |
29 | 29 | ||
@@ -59,157 +59,3 @@ compare_data(const uint8_t *want, const uint8_t *got, size_t len, const char *ms | |||
59 | 59 | ||
60 | return 1; | 60 | return 1; |
61 | } | 61 | } |
62 | |||
63 | int | ||
64 | mlkem768_marshal_private_key(const void *private_key, uint8_t **out_buf, | ||
65 | size_t *out_len) | ||
66 | { | ||
67 | return MLKEM768_marshal_private_key(private_key, out_buf, out_len); | ||
68 | } | ||
69 | |||
70 | int | ||
71 | mlkem768_marshal_public_key(const void *public_key, uint8_t **out_buf, | ||
72 | size_t *out_len) | ||
73 | { | ||
74 | return MLKEM768_marshal_public_key(out_buf, out_len, public_key); | ||
75 | } | ||
76 | |||
77 | int | ||
78 | mlkem1024_marshal_private_key(const void *private_key, uint8_t **out_buf, | ||
79 | size_t *out_len) | ||
80 | { | ||
81 | return MLKEM1024_marshal_private_key(private_key, out_buf, out_len); | ||
82 | } | ||
83 | |||
84 | int | ||
85 | mlkem1024_marshal_public_key(const void *public_key, uint8_t **out_buf, | ||
86 | size_t *out_len) | ||
87 | { | ||
88 | return MLKEM1024_marshal_public_key(out_buf, out_len, public_key); | ||
89 | } | ||
90 | |||
91 | int | ||
92 | mlkem768_decap(uint8_t out_shared_secret[MLKEM_SHARED_SECRET_BYTES], | ||
93 | const uint8_t *ciphertext, size_t ciphertext_len, const void *private_key) | ||
94 | { | ||
95 | return MLKEM768_decap(out_shared_secret, ciphertext, ciphertext_len, | ||
96 | private_key); | ||
97 | } | ||
98 | |||
99 | void | ||
100 | mlkem768_encap(uint8_t *out_ciphertext, | ||
101 | uint8_t out_shared_secret[MLKEM_SHARED_SECRET_BYTES], | ||
102 | const void *public_key) | ||
103 | { | ||
104 | MLKEM768_encap(out_ciphertext, out_shared_secret, public_key); | ||
105 | } | ||
106 | |||
107 | void | ||
108 | mlkem768_encap_external_entropy(uint8_t *out_ciphertext, | ||
109 | uint8_t out_shared_secret[MLKEM_SHARED_SECRET_BYTES], | ||
110 | const void *public_key, const uint8_t entropy[MLKEM_ENCAP_ENTROPY]) | ||
111 | { | ||
112 | MLKEM768_encap_external_entropy(out_ciphertext, out_shared_secret, | ||
113 | public_key, entropy); | ||
114 | } | ||
115 | |||
116 | int | ||
117 | mlkem768_generate_key(uint8_t *out_encoded_public_key, | ||
118 | uint8_t optional_out_seed[MLKEM_SEED_BYTES], void *out_private_key) | ||
119 | { | ||
120 | return MLKEM768_generate_key(out_encoded_public_key, optional_out_seed, | ||
121 | out_private_key); | ||
122 | } | ||
123 | |||
124 | int | ||
125 | mlkem768_generate_key_external_entropy(uint8_t *out_encoded_public_key, | ||
126 | void *out_private_key, const uint8_t entropy[MLKEM_SEED_BYTES]) | ||
127 | { | ||
128 | return MLKEM768_generate_key_external_entropy(out_encoded_public_key, | ||
129 | out_private_key, entropy); | ||
130 | } | ||
131 | |||
132 | int | ||
133 | mlkem768_parse_private_key(void *out_private_key, const uint8_t *private_key, | ||
134 | size_t private_key_len) | ||
135 | { | ||
136 | return MLKEM768_parse_private_key(out_private_key, private_key, | ||
137 | private_key_len); | ||
138 | } | ||
139 | |||
140 | int | ||
141 | mlkem768_parse_public_key(void *out_public_key, const uint8_t *public_key, | ||
142 | size_t public_key_len) | ||
143 | { | ||
144 | return MLKEM768_parse_public_key(out_public_key, public_key, | ||
145 | public_key_len); | ||
146 | } | ||
147 | |||
148 | void | ||
149 | mlkem768_public_from_private(void *out_public_key, const void *private_key) | ||
150 | { | ||
151 | MLKEM768_public_from_private(out_public_key, private_key); | ||
152 | } | ||
153 | |||
154 | int | ||
155 | mlkem1024_decap(uint8_t out_shared_secret[MLKEM_SHARED_SECRET_BYTES], | ||
156 | const uint8_t *ciphertext, size_t ciphertext_len, const void *private_key) | ||
157 | { | ||
158 | return MLKEM1024_decap(out_shared_secret, ciphertext, ciphertext_len, | ||
159 | private_key); | ||
160 | } | ||
161 | |||
162 | void | ||
163 | mlkem1024_encap(uint8_t *out_ciphertext, | ||
164 | uint8_t out_shared_secret[MLKEM_SHARED_SECRET_BYTES], | ||
165 | const void *public_key) | ||
166 | { | ||
167 | MLKEM1024_encap(out_ciphertext, out_shared_secret, public_key); | ||
168 | } | ||
169 | |||
170 | void | ||
171 | mlkem1024_encap_external_entropy(uint8_t *out_ciphertext, | ||
172 | uint8_t out_shared_secret[MLKEM_SHARED_SECRET_BYTES], | ||
173 | const void *public_key, const uint8_t entropy[MLKEM_ENCAP_ENTROPY]) | ||
174 | { | ||
175 | MLKEM1024_encap_external_entropy(out_ciphertext, out_shared_secret, | ||
176 | public_key, entropy); | ||
177 | } | ||
178 | |||
179 | int | ||
180 | mlkem1024_generate_key(uint8_t *out_encoded_public_key, | ||
181 | uint8_t optional_out_seed[MLKEM_SEED_BYTES], void *out_private_key) | ||
182 | { | ||
183 | return MLKEM1024_generate_key(out_encoded_public_key, optional_out_seed, | ||
184 | out_private_key); | ||
185 | } | ||
186 | |||
187 | int | ||
188 | mlkem1024_generate_key_external_entropy(uint8_t *out_encoded_public_key, | ||
189 | void *out_private_key, const uint8_t entropy[MLKEM_SEED_BYTES]) | ||
190 | { | ||
191 | return MLKEM1024_generate_key_external_entropy(out_encoded_public_key, | ||
192 | out_private_key, entropy); | ||
193 | } | ||
194 | |||
195 | int | ||
196 | mlkem1024_parse_private_key(void *out_private_key, const uint8_t *private_key, | ||
197 | size_t private_key_len) | ||
198 | { | ||
199 | return MLKEM1024_parse_private_key(out_private_key, private_key, | ||
200 | private_key_len); | ||
201 | } | ||
202 | |||
203 | void | ||
204 | mlkem1024_public_from_private(void *out_public_key, const void *private_key) | ||
205 | { | ||
206 | MLKEM1024_public_from_private(out_public_key, private_key); | ||
207 | } | ||
208 | |||
209 | int | ||
210 | mlkem1024_parse_public_key(void *out_public_key, const uint8_t *public_key, | ||
211 | size_t public_key_len) | ||
212 | { | ||
213 | return MLKEM1024_parse_public_key(out_public_key, public_key, | ||
214 | public_key_len); | ||
215 | } | ||