diff options
Diffstat (limited to 'src/regress/lib/libcrypto/mlkem/mlkem_tests_util.c')
-rw-r--r-- | src/regress/lib/libcrypto/mlkem/mlkem_tests_util.c | 118 |
1 files changed, 33 insertions, 85 deletions
diff --git a/src/regress/lib/libcrypto/mlkem/mlkem_tests_util.c b/src/regress/lib/libcrypto/mlkem/mlkem_tests_util.c index 1bb2ed3a8b..68bd5d4871 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.5 2024/12/26 00:04:24 tb Exp $ */ | 1 | /* $OpenBSD: mlkem_tests_util.c,v 1.8 2025/05/20 00:33:41 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> |
@@ -61,91 +61,31 @@ compare_data(const uint8_t *want, const uint8_t *got, size_t len, const char *ms | |||
61 | } | 61 | } |
62 | 62 | ||
63 | int | 63 | int |
64 | mlkem768_encode_private_key(const void *private_key, uint8_t **out_buf, | 64 | mlkem768_marshal_private_key(const void *private_key, uint8_t **out_buf, |
65 | size_t *out_len) | 65 | size_t *out_len) |
66 | { | 66 | { |
67 | CBB cbb; | 67 | return MLKEM768_marshal_private_key(private_key, out_buf, out_len); |
68 | int ret = 0; | ||
69 | |||
70 | if (!CBB_init(&cbb, MLKEM768_PUBLIC_KEY_BYTES)) | ||
71 | goto err; | ||
72 | if (!MLKEM768_marshal_private_key(&cbb, private_key)) | ||
73 | goto err; | ||
74 | if (!CBB_finish(&cbb, out_buf, out_len)) | ||
75 | goto err; | ||
76 | |||
77 | ret = 1; | ||
78 | |||
79 | err: | ||
80 | CBB_cleanup(&cbb); | ||
81 | |||
82 | return ret; | ||
83 | } | 68 | } |
84 | 69 | ||
85 | int | 70 | int |
86 | mlkem768_encode_public_key(const void *public_key, uint8_t **out_buf, | 71 | mlkem768_marshal_public_key(const void *public_key, uint8_t **out_buf, |
87 | size_t *out_len) | 72 | size_t *out_len) |
88 | { | 73 | { |
89 | CBB cbb; | 74 | return MLKEM768_marshal_public_key(out_buf, out_len, public_key); |
90 | int ret = 0; | ||
91 | |||
92 | if (!CBB_init(&cbb, MLKEM768_PUBLIC_KEY_BYTES)) | ||
93 | goto err; | ||
94 | if (!MLKEM768_marshal_public_key(&cbb, public_key)) | ||
95 | goto err; | ||
96 | if (!CBB_finish(&cbb, out_buf, out_len)) | ||
97 | goto err; | ||
98 | |||
99 | ret = 1; | ||
100 | |||
101 | err: | ||
102 | CBB_cleanup(&cbb); | ||
103 | |||
104 | return ret; | ||
105 | } | 75 | } |
106 | 76 | ||
107 | int | 77 | int |
108 | mlkem1024_encode_private_key(const void *private_key, uint8_t **out_buf, | 78 | mlkem1024_marshal_private_key(const void *private_key, uint8_t **out_buf, |
109 | size_t *out_len) | 79 | size_t *out_len) |
110 | { | 80 | { |
111 | CBB cbb; | 81 | return MLKEM1024_marshal_private_key(private_key, out_buf, out_len); |
112 | int ret = 0; | ||
113 | |||
114 | if (!CBB_init(&cbb, MLKEM1024_PUBLIC_KEY_BYTES)) | ||
115 | goto err; | ||
116 | if (!MLKEM1024_marshal_private_key(&cbb, private_key)) | ||
117 | goto err; | ||
118 | if (!CBB_finish(&cbb, out_buf, out_len)) | ||
119 | goto err; | ||
120 | |||
121 | ret = 1; | ||
122 | |||
123 | err: | ||
124 | CBB_cleanup(&cbb); | ||
125 | |||
126 | return ret; | ||
127 | } | 82 | } |
128 | 83 | ||
129 | int | 84 | int |
130 | mlkem1024_encode_public_key(const void *public_key, uint8_t **out_buf, | 85 | mlkem1024_marshal_public_key(const void *public_key, uint8_t **out_buf, |
131 | size_t *out_len) | 86 | size_t *out_len) |
132 | { | 87 | { |
133 | CBB cbb; | 88 | return MLKEM1024_marshal_public_key(out_buf, out_len, public_key); |
134 | int ret = 0; | ||
135 | |||
136 | if (!CBB_init(&cbb, MLKEM1024_PUBLIC_KEY_BYTES)) | ||
137 | goto err; | ||
138 | if (!MLKEM1024_marshal_public_key(&cbb, public_key)) | ||
139 | goto err; | ||
140 | if (!CBB_finish(&cbb, out_buf, out_len)) | ||
141 | goto err; | ||
142 | |||
143 | ret = 1; | ||
144 | |||
145 | err: | ||
146 | CBB_cleanup(&cbb); | ||
147 | |||
148 | return ret; | ||
149 | } | 89 | } |
150 | 90 | ||
151 | int | 91 | int |
@@ -173,32 +113,36 @@ mlkem768_encap_external_entropy(uint8_t *out_ciphertext, | |||
173 | public_key, entropy); | 113 | public_key, entropy); |
174 | } | 114 | } |
175 | 115 | ||
176 | void | 116 | int |
177 | mlkem768_generate_key(uint8_t *out_encoded_public_key, | 117 | mlkem768_generate_key(uint8_t *out_encoded_public_key, |
178 | uint8_t optional_out_seed[MLKEM_SEED_BYTES], void *out_private_key) | 118 | uint8_t optional_out_seed[MLKEM_SEED_BYTES], void *out_private_key) |
179 | { | 119 | { |
180 | MLKEM768_generate_key(out_encoded_public_key, optional_out_seed, | 120 | return MLKEM768_generate_key(out_encoded_public_key, optional_out_seed, |
181 | out_private_key); | 121 | out_private_key); |
182 | } | 122 | } |
183 | 123 | ||
184 | void | 124 | int |
185 | mlkem768_generate_key_external_entropy(uint8_t *out_encoded_public_key, | 125 | mlkem768_generate_key_external_entropy(uint8_t *out_encoded_public_key, |
186 | void *out_private_key, const uint8_t entropy[MLKEM_SEED_BYTES]) | 126 | void *out_private_key, const uint8_t entropy[MLKEM_SEED_BYTES]) |
187 | { | 127 | { |
188 | MLKEM768_generate_key_external_entropy(out_encoded_public_key, | 128 | return MLKEM768_generate_key_external_entropy(out_encoded_public_key, |
189 | out_private_key, entropy); | 129 | out_private_key, entropy); |
190 | } | 130 | } |
191 | 131 | ||
192 | int | 132 | int |
193 | mlkem768_parse_private_key(void *out_private_key, CBS *private_key_cbs) | 133 | mlkem768_parse_private_key(void *out_private_key, const uint8_t *private_key, |
134 | size_t private_key_len) | ||
194 | { | 135 | { |
195 | return MLKEM768_parse_private_key(out_private_key, private_key_cbs); | 136 | return MLKEM768_parse_private_key(out_private_key, private_key, |
137 | private_key_len); | ||
196 | } | 138 | } |
197 | 139 | ||
198 | int | 140 | int |
199 | mlkem768_parse_public_key(void *out_public_key, CBS *public_key_cbs) | 141 | mlkem768_parse_public_key(void *out_public_key, const uint8_t *public_key, |
142 | size_t public_key_len) | ||
200 | { | 143 | { |
201 | return MLKEM768_parse_public_key(out_public_key, public_key_cbs); | 144 | return MLKEM768_parse_public_key(out_public_key, public_key, |
145 | public_key_len); | ||
202 | } | 146 | } |
203 | 147 | ||
204 | void | 148 | void |
@@ -232,26 +176,28 @@ mlkem1024_encap_external_entropy(uint8_t *out_ciphertext, | |||
232 | public_key, entropy); | 176 | public_key, entropy); |
233 | } | 177 | } |
234 | 178 | ||
235 | void | 179 | int |
236 | mlkem1024_generate_key(uint8_t *out_encoded_public_key, | 180 | mlkem1024_generate_key(uint8_t *out_encoded_public_key, |
237 | uint8_t optional_out_seed[MLKEM_SEED_BYTES], void *out_private_key) | 181 | uint8_t optional_out_seed[MLKEM_SEED_BYTES], void *out_private_key) |
238 | { | 182 | { |
239 | MLKEM1024_generate_key(out_encoded_public_key, optional_out_seed, | 183 | return MLKEM1024_generate_key(out_encoded_public_key, optional_out_seed, |
240 | out_private_key); | 184 | out_private_key); |
241 | } | 185 | } |
242 | 186 | ||
243 | void | 187 | int |
244 | mlkem1024_generate_key_external_entropy(uint8_t *out_encoded_public_key, | 188 | mlkem1024_generate_key_external_entropy(uint8_t *out_encoded_public_key, |
245 | void *out_private_key, const uint8_t entropy[MLKEM_SEED_BYTES]) | 189 | void *out_private_key, const uint8_t entropy[MLKEM_SEED_BYTES]) |
246 | { | 190 | { |
247 | MLKEM1024_generate_key_external_entropy(out_encoded_public_key, | 191 | return MLKEM1024_generate_key_external_entropy(out_encoded_public_key, |
248 | out_private_key, entropy); | 192 | out_private_key, entropy); |
249 | } | 193 | } |
250 | 194 | ||
251 | int | 195 | int |
252 | mlkem1024_parse_private_key(void *out_private_key, CBS *private_key_cbs) | 196 | mlkem1024_parse_private_key(void *out_private_key, const uint8_t *private_key, |
197 | size_t private_key_len) | ||
253 | { | 198 | { |
254 | return MLKEM1024_parse_private_key(out_private_key, private_key_cbs); | 199 | return MLKEM1024_parse_private_key(out_private_key, private_key, |
200 | private_key_len); | ||
255 | } | 201 | } |
256 | 202 | ||
257 | void | 203 | void |
@@ -261,7 +207,9 @@ mlkem1024_public_from_private(void *out_public_key, const void *private_key) | |||
261 | } | 207 | } |
262 | 208 | ||
263 | int | 209 | int |
264 | mlkem1024_parse_public_key(void *out_public_key, CBS *public_key_cbs) | 210 | mlkem1024_parse_public_key(void *out_public_key, const uint8_t *public_key, |
211 | size_t public_key_len) | ||
265 | { | 212 | { |
266 | return MLKEM1024_parse_public_key(out_public_key, public_key_cbs); | 213 | return MLKEM1024_parse_public_key(out_public_key, public_key, |
214 | public_key_len); | ||
267 | } | 215 | } |