From 41bd0848d38d40c872dd36e17a728b405acff4dc Mon Sep 17 00:00:00 2001 From: beck <> Date: Mon, 19 May 2025 07:53:00 +0000 Subject: Fix up MLKEM768_marshal_private_key to not use a passed in CBB Even though this should remain internal, make it the same as the public key marshal function, and make the needed fallout changes in regress. This does not yet do the bikeshed of renaming the structure field in the regress ctx, that will wait until a follow on to convert 1024 in a similar manner ok tb@ --- .../lib/libcrypto/mlkem/mlkem_iteration_tests.c | 4 ++-- src/regress/lib/libcrypto/mlkem/mlkem_tests.c | 4 ++-- src/regress/lib/libcrypto/mlkem/mlkem_tests_util.c | 21 +++------------------ src/regress/lib/libcrypto/mlkem/mlkem_tests_util.h | 4 ++-- src/regress/lib/libcrypto/mlkem/mlkem_unittest.c | 4 ++-- 5 files changed, 11 insertions(+), 26 deletions(-) (limited to 'src/regress') diff --git a/src/regress/lib/libcrypto/mlkem/mlkem_iteration_tests.c b/src/regress/lib/libcrypto/mlkem/mlkem_iteration_tests.c index a8495f55e3..e0fd9ca241 100644 --- a/src/regress/lib/libcrypto/mlkem/mlkem_iteration_tests.c +++ b/src/regress/lib/libcrypto/mlkem/mlkem_iteration_tests.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mlkem_iteration_tests.c,v 1.3 2025/05/19 06:47:40 beck Exp $ */ +/* $OpenBSD: mlkem_iteration_tests.c,v 1.4 2025/05/19 07:53:00 beck Exp $ */ /* * Copyright (c) 2024 Google Inc. * Copyright (c) 2024 Bob Beck @@ -185,7 +185,7 @@ main(void) .priv = &priv768, .pub = &pub768, .encap_external_entropy = mlkem768_encap_external_entropy, - .encode_private_key = mlkem768_encode_private_key, + .encode_private_key = mlkem768_marshal_private_key, .generate_key_external_entropy = mlkem768_generate_key_external_entropy, .public_from_private = mlkem768_public_from_private, diff --git a/src/regress/lib/libcrypto/mlkem/mlkem_tests.c b/src/regress/lib/libcrypto/mlkem/mlkem_tests.c index a4e7208c76..84b71aebb0 100644 --- a/src/regress/lib/libcrypto/mlkem/mlkem_tests.c +++ b/src/regress/lib/libcrypto/mlkem/mlkem_tests.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mlkem_tests.c,v 1.4 2025/05/19 06:47:40 beck Exp $ */ +/* $OpenBSD: mlkem_tests.c,v 1.5 2025/05/19 07:53:00 beck Exp $ */ /* * Copyright (c) 2024 Google Inc. * Copyright (c) 2024 Theo Buehler @@ -662,7 +662,7 @@ mlkem_keygen_tests(const char *fn, size_t size, enum test_type test_type) .generate_key_external_entropy = mlkem768_generate_key_external_entropy, .encode_private_key = - mlkem768_encode_private_key, + mlkem768_marshal_private_key, }; struct MLKEM1024_private_key private_key1024; uint8_t encoded_public_key1024[MLKEM1024_PUBLIC_KEY_BYTES]; diff --git a/src/regress/lib/libcrypto/mlkem/mlkem_tests_util.c b/src/regress/lib/libcrypto/mlkem/mlkem_tests_util.c index 8677713c8e..5ec8c08585 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 @@ -/* $OpenBSD: mlkem_tests_util.c,v 1.6 2025/05/19 06:47:40 beck Exp $ */ +/* $OpenBSD: mlkem_tests_util.c,v 1.7 2025/05/19 07:53:00 beck Exp $ */ /* * Copyright (c) 2024 Google Inc. * Copyright (c) 2024 Bob Beck @@ -61,25 +61,10 @@ compare_data(const uint8_t *want, const uint8_t *got, size_t len, const char *ms } int -mlkem768_encode_private_key(const void *private_key, uint8_t **out_buf, +mlkem768_marshal_private_key(const void *private_key, uint8_t **out_buf, size_t *out_len) { - CBB cbb; - int ret = 0; - - if (!CBB_init(&cbb, MLKEM768_PUBLIC_KEY_BYTES)) - goto err; - if (!MLKEM768_marshal_private_key(&cbb, private_key)) - goto err; - if (!CBB_finish(&cbb, out_buf, out_len)) - goto err; - - ret = 1; - - err: - CBB_cleanup(&cbb); - - return ret; + return MLKEM768_marshal_private_key(private_key, out_buf, out_len); } int diff --git a/src/regress/lib/libcrypto/mlkem/mlkem_tests_util.h b/src/regress/lib/libcrypto/mlkem/mlkem_tests_util.h index a3b255082f..5c2c400ea5 100644 --- a/src/regress/lib/libcrypto/mlkem/mlkem_tests_util.h +++ b/src/regress/lib/libcrypto/mlkem/mlkem_tests_util.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mlkem_tests_util.h,v 1.5 2025/05/19 06:47:40 beck Exp $ */ +/* $OpenBSD: mlkem_tests_util.h,v 1.6 2025/05/19 07:53:00 beck Exp $ */ /* * Copyright (c) 2024 Bob Beck * Copyright (c) 2024 Theo Buehler @@ -30,7 +30,7 @@ int compare_data(const uint8_t *want, const uint8_t *got, size_t len, const char *msg); -int mlkem768_encode_private_key(const void *priv, uint8_t **out_buf, +int mlkem768_marshal_private_key(const void *priv, uint8_t **out_buf, size_t *out_len); int mlkem768_marshal_public_key(const void *pub, uint8_t **out_buf, size_t *out_len); diff --git a/src/regress/lib/libcrypto/mlkem/mlkem_unittest.c b/src/regress/lib/libcrypto/mlkem/mlkem_unittest.c index a1adc88569..ce1e797904 100644 --- a/src/regress/lib/libcrypto/mlkem/mlkem_unittest.c +++ b/src/regress/lib/libcrypto/mlkem/mlkem_unittest.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mlkem_unittest.c,v 1.8 2025/05/19 06:47:40 beck Exp $ */ +/* $OpenBSD: mlkem_unittest.c,v 1.9 2025/05/19 07:53:00 beck Exp $ */ /* * Copyright (c) 2024 Google Inc. * Copyright (c) 2024 Bob Beck @@ -205,7 +205,7 @@ mlkem768_unittest(void) .generate_key = mlkem768_generate_key, .parse_private_key = mlkem768_parse_private_key, .parse_public_key = mlkem768_parse_public_key, - .encode_private_key = mlkem768_encode_private_key, + .encode_private_key = mlkem768_marshal_private_key, .marshal_public_key = mlkem768_marshal_public_key, .public_from_private = mlkem768_public_from_private, }; -- cgit v1.2.3-55-g6feb