diff options
| author | beck <> | 2025-05-19 06:47:40 +0000 |
|---|---|---|
| committer | beck <> | 2025-05-19 06:47:40 +0000 |
| commit | b5d568ea85f2380b8447d6b8b652e81e0cbdfb8d (patch) | |
| tree | c0473c2a6778acc8c1c57a2e73ed27b1d35552a6 /src/regress/lib/libcrypto/mlkem/mlkem_tests_util.c | |
| parent | 4ec16279eb7cfd33c1785a5832ba16feff4a0ed8 (diff) | |
| download | openbsd-b5d568ea85f2380b8447d6b8b652e81e0cbdfb8d.tar.gz openbsd-b5d568ea85f2380b8447d6b8b652e81e0cbdfb8d.tar.bz2 openbsd-b5d568ea85f2380b8447d6b8b652e81e0cbdfb8d.zip | |
API changes for ML-KEM
- Get rid of CBB/CBS usage in public api
- Make void functions return int that can fail if malloc fails.
Along with some fallout and resulting bikeshedding in the regress tests.
ok jsing@, tb@
Diffstat (limited to '')
| -rw-r--r-- | src/regress/lib/libcrypto/mlkem/mlkem_tests_util.c | 80 |
1 files changed, 29 insertions, 51 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..8677713c8e 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.6 2025/05/19 06:47:40 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> |
| @@ -83,25 +83,10 @@ mlkem768_encode_private_key(const void *private_key, uint8_t **out_buf, | |||
| 83 | } | 83 | } |
| 84 | 84 | ||
| 85 | int | 85 | int |
| 86 | mlkem768_encode_public_key(const void *public_key, uint8_t **out_buf, | 86 | mlkem768_marshal_public_key(const void *public_key, uint8_t **out_buf, |
| 87 | size_t *out_len) | 87 | size_t *out_len) |
| 88 | { | 88 | { |
| 89 | CBB cbb; | 89 | 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 | } | 90 | } |
| 106 | 91 | ||
| 107 | int | 92 | int |
| @@ -127,25 +112,10 @@ mlkem1024_encode_private_key(const void *private_key, uint8_t **out_buf, | |||
| 127 | } | 112 | } |
| 128 | 113 | ||
| 129 | int | 114 | int |
| 130 | mlkem1024_encode_public_key(const void *public_key, uint8_t **out_buf, | 115 | mlkem1024_marshal_public_key(const void *public_key, uint8_t **out_buf, |
| 131 | size_t *out_len) | 116 | size_t *out_len) |
| 132 | { | 117 | { |
| 133 | CBB cbb; | 118 | 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 | } | 119 | } |
| 150 | 120 | ||
| 151 | int | 121 | int |
| @@ -173,32 +143,36 @@ mlkem768_encap_external_entropy(uint8_t *out_ciphertext, | |||
| 173 | public_key, entropy); | 143 | public_key, entropy); |
| 174 | } | 144 | } |
| 175 | 145 | ||
| 176 | void | 146 | int |
| 177 | mlkem768_generate_key(uint8_t *out_encoded_public_key, | 147 | mlkem768_generate_key(uint8_t *out_encoded_public_key, |
| 178 | uint8_t optional_out_seed[MLKEM_SEED_BYTES], void *out_private_key) | 148 | uint8_t optional_out_seed[MLKEM_SEED_BYTES], void *out_private_key) |
| 179 | { | 149 | { |
| 180 | MLKEM768_generate_key(out_encoded_public_key, optional_out_seed, | 150 | return MLKEM768_generate_key(out_encoded_public_key, optional_out_seed, |
| 181 | out_private_key); | 151 | out_private_key); |
| 182 | } | 152 | } |
| 183 | 153 | ||
| 184 | void | 154 | int |
| 185 | mlkem768_generate_key_external_entropy(uint8_t *out_encoded_public_key, | 155 | mlkem768_generate_key_external_entropy(uint8_t *out_encoded_public_key, |
| 186 | void *out_private_key, const uint8_t entropy[MLKEM_SEED_BYTES]) | 156 | void *out_private_key, const uint8_t entropy[MLKEM_SEED_BYTES]) |
| 187 | { | 157 | { |
| 188 | MLKEM768_generate_key_external_entropy(out_encoded_public_key, | 158 | return MLKEM768_generate_key_external_entropy(out_encoded_public_key, |
| 189 | out_private_key, entropy); | 159 | out_private_key, entropy); |
| 190 | } | 160 | } |
| 191 | 161 | ||
| 192 | int | 162 | int |
| 193 | mlkem768_parse_private_key(void *out_private_key, CBS *private_key_cbs) | 163 | mlkem768_parse_private_key(void *out_private_key, const uint8_t *private_key, |
| 164 | size_t private_key_len) | ||
| 194 | { | 165 | { |
| 195 | return MLKEM768_parse_private_key(out_private_key, private_key_cbs); | 166 | return MLKEM768_parse_private_key(out_private_key, private_key, |
| 167 | private_key_len); | ||
| 196 | } | 168 | } |
| 197 | 169 | ||
| 198 | int | 170 | int |
| 199 | mlkem768_parse_public_key(void *out_public_key, CBS *public_key_cbs) | 171 | mlkem768_parse_public_key(void *out_public_key, const uint8_t *public_key, |
| 172 | size_t public_key_len) | ||
| 200 | { | 173 | { |
| 201 | return MLKEM768_parse_public_key(out_public_key, public_key_cbs); | 174 | return MLKEM768_parse_public_key(out_public_key, public_key, |
| 175 | public_key_len); | ||
| 202 | } | 176 | } |
| 203 | 177 | ||
| 204 | void | 178 | void |
| @@ -232,26 +206,28 @@ mlkem1024_encap_external_entropy(uint8_t *out_ciphertext, | |||
| 232 | public_key, entropy); | 206 | public_key, entropy); |
| 233 | } | 207 | } |
| 234 | 208 | ||
| 235 | void | 209 | int |
| 236 | mlkem1024_generate_key(uint8_t *out_encoded_public_key, | 210 | mlkem1024_generate_key(uint8_t *out_encoded_public_key, |
| 237 | uint8_t optional_out_seed[MLKEM_SEED_BYTES], void *out_private_key) | 211 | uint8_t optional_out_seed[MLKEM_SEED_BYTES], void *out_private_key) |
| 238 | { | 212 | { |
| 239 | MLKEM1024_generate_key(out_encoded_public_key, optional_out_seed, | 213 | return MLKEM1024_generate_key(out_encoded_public_key, optional_out_seed, |
| 240 | out_private_key); | 214 | out_private_key); |
| 241 | } | 215 | } |
| 242 | 216 | ||
| 243 | void | 217 | int |
| 244 | mlkem1024_generate_key_external_entropy(uint8_t *out_encoded_public_key, | 218 | mlkem1024_generate_key_external_entropy(uint8_t *out_encoded_public_key, |
| 245 | void *out_private_key, const uint8_t entropy[MLKEM_SEED_BYTES]) | 219 | void *out_private_key, const uint8_t entropy[MLKEM_SEED_BYTES]) |
| 246 | { | 220 | { |
| 247 | MLKEM1024_generate_key_external_entropy(out_encoded_public_key, | 221 | return MLKEM1024_generate_key_external_entropy(out_encoded_public_key, |
| 248 | out_private_key, entropy); | 222 | out_private_key, entropy); |
| 249 | } | 223 | } |
| 250 | 224 | ||
| 251 | int | 225 | int |
| 252 | mlkem1024_parse_private_key(void *out_private_key, CBS *private_key_cbs) | 226 | mlkem1024_parse_private_key(void *out_private_key, const uint8_t *private_key, |
| 227 | size_t private_key_len) | ||
| 253 | { | 228 | { |
| 254 | return MLKEM1024_parse_private_key(out_private_key, private_key_cbs); | 229 | return MLKEM1024_parse_private_key(out_private_key, private_key, |
| 230 | private_key_len); | ||
| 255 | } | 231 | } |
| 256 | 232 | ||
| 257 | void | 233 | void |
| @@ -261,7 +237,9 @@ mlkem1024_public_from_private(void *out_public_key, const void *private_key) | |||
| 261 | } | 237 | } |
| 262 | 238 | ||
| 263 | int | 239 | int |
| 264 | mlkem1024_parse_public_key(void *out_public_key, CBS *public_key_cbs) | 240 | mlkem1024_parse_public_key(void *out_public_key, const uint8_t *public_key, |
| 241 | size_t public_key_len) | ||
| 265 | { | 242 | { |
| 266 | return MLKEM1024_parse_public_key(out_public_key, public_key_cbs); | 243 | return MLKEM1024_parse_public_key(out_public_key, public_key, |
| 244 | public_key_len); | ||
| 267 | } | 245 | } |
