From dd5b7862d001ae7610755eabd2b4ff125617de1f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Niels=20M=C3=B6ller?= Date: Wed, 10 Sep 2025 09:31:20 +0200 Subject: [PATCH] Use union slh_hash_ctx exclusively for allocation. --- slh-dsa-internal.h | 14 +++++++------- slh-fors.c | 4 ++-- slh-wots.c | 20 ++++++++++---------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/slh-dsa-internal.h b/slh-dsa-internal.h index 1d680136..c4af8a58 100644 --- a/slh-dsa-internal.h +++ b/slh-dsa-internal.h @@ -103,14 +103,14 @@ typedef void slh_hash_msg_digest_func (const uint8_t *randomizer, const uint8_t size_t msg_length, const uint8_t *msg, size_t digest_size, uint8_t *digest); -typedef void slh_hash_init_tree_func (union slh_hash_ctx *tree_ctx, const uint8_t *public_seed, +typedef void slh_hash_init_tree_func (void *tree_ctx, const uint8_t *public_seed, uint32_t layer, uint64_t tree_idx); -typedef void slh_hash_init_hash_func (const union slh_hash_ctx *tree_ctx, union slh_hash_ctx *ctx, +typedef void slh_hash_init_hash_func (const void *tree_ctx, void *ctx, const struct slh_address_hash *ah); -typedef void slh_hash_secret_func (const union slh_hash_ctx *tree_ctx, +typedef void slh_hash_secret_func (const void *tree_ctx, const struct slh_address_hash *ah, const uint8_t *secret, uint8_t *out); -typedef void slh_hash_node_func (const union slh_hash_ctx *tree_ctx, +typedef void slh_hash_node_func (const void *tree_ctx, const struct slh_address_hash *ah, const uint8_t *left, const uint8_t *right, uint8_t *out); @@ -194,19 +194,19 @@ _slh_sha256_msg_digest (const uint8_t *randomizer, const uint8_t *pub, #define WOTS_SIGNATURE_SIZE (_WOTS_SIGNATURE_LENGTH*_SLH_DSA_128_SIZE) void -_wots_gen (const struct slh_hash *hash, const union slh_hash_ctx *tree_ctx, +_wots_gen (const struct slh_hash *hash, const void *tree_ctx, const uint8_t *secret_seed, uint32_t keypair, uint8_t *pub); void -_wots_sign (const struct slh_hash *hash, const union slh_hash_ctx *tree_ctx, +_wots_sign (const struct slh_hash *hash, const void *tree_ctx, const uint8_t *secret_seed, unsigned keypair, const uint8_t *msg, uint8_t *signature, uint8_t *pub); /* Computes candidate public key from signature. */ void -_wots_verify (const struct slh_hash *hash, const union slh_hash_ctx *tree_ctx, +_wots_verify (const struct slh_hash *hash, const void *tree_ctx, unsigned keypair, const uint8_t *msg, const uint8_t *signature, uint8_t *pub); /* Merkle tree functions. Could be generalized for other merkle tree diff --git a/slh-fors.c b/slh-fors.c index e9906436..2818487d 100644 --- a/slh-fors.c +++ b/slh-fors.c @@ -78,7 +78,7 @@ fors_node (const struct slh_merkle_ctx_public *ctx, unsigned height, unsigned in static void fors_sign_one (const struct slh_merkle_ctx_secret *ctx, unsigned a, - unsigned idx, uint8_t *signature, union slh_hash_ctx *pub) + unsigned idx, uint8_t *signature, void *pub) { uint8_t hash[_SLH_DSA_128_SIZE]; @@ -122,7 +122,7 @@ _fors_sign (const struct slh_merkle_ctx_secret *ctx, static void fors_verify_one (const struct slh_merkle_ctx_public *ctx, unsigned a, - unsigned idx, const uint8_t *signature, union slh_hash_ctx *pub) + unsigned idx, const uint8_t *signature, void *pub) { uint8_t root[_SLH_DSA_128_SIZE]; struct slh_address_hash ah = diff --git a/slh-wots.c b/slh-wots.c index c04fa620..f00a9a9e 100644 --- a/slh-wots.c +++ b/slh-wots.c @@ -42,7 +42,7 @@ dst. For the ah argument, leaves ah->keypair and ah->height_chain unchanged, but overwrites the other fields. */ static const uint8_t * -wots_chain (const struct slh_hash *hash, const union slh_hash_ctx *ctx, +wots_chain (const struct slh_hash *hash, const void *ctx, struct slh_address_hash *ah, unsigned i, unsigned s, const uint8_t *src, uint8_t *dst) @@ -67,9 +67,9 @@ wots_chain (const struct slh_hash *hash, const union slh_hash_ctx *ctx, } static void -wots_pk_init (const struct slh_hash *hash, const union slh_hash_ctx *tree_ctx, +wots_pk_init (const struct slh_hash *hash, const void *tree_ctx, unsigned keypair, struct slh_address_hash *ah, - union slh_hash_ctx *ctx) + void *ctx) { ah->type = bswap32_if_le (SLH_WOTS_PK); ah->keypair = bswap32_if_le (keypair); @@ -79,7 +79,7 @@ wots_pk_init (const struct slh_hash *hash, const union slh_hash_ctx *tree_ctx, } void -_wots_gen (const struct slh_hash *hash, const union slh_hash_ctx *tree_ctx, +_wots_gen (const struct slh_hash *hash, const void *tree_ctx, const uint8_t *secret_seed, uint32_t keypair, uint8_t *pub) { @@ -109,10 +109,10 @@ _wots_gen (const struct slh_hash *hash, const union slh_hash_ctx *tree_ctx, /* Produces signature hash corresponding to the ith message nybble. Modifies addr. */ static void -wots_sign_one (const struct slh_hash *hash, const union slh_hash_ctx *tree_ctx, +wots_sign_one (const struct slh_hash *hash, const void *tree_ctx, const uint8_t *secret_seed, uint32_t keypair, unsigned i, uint8_t msg, - uint8_t *signature, union slh_hash_ctx *ctx) + uint8_t *signature, void *ctx) { struct slh_address_hash ah; uint8_t pub[_SLH_DSA_128_SIZE]; @@ -133,7 +133,7 @@ wots_sign_one (const struct slh_hash *hash, const union slh_hash_ctx *tree_ctx, } void -_wots_sign (const struct slh_hash *hash, const union slh_hash_ctx *tree_ctx, +_wots_sign (const struct slh_hash *hash, const void *tree_ctx, const uint8_t *secret_seed, unsigned keypair, const uint8_t *msg, uint8_t *signature, uint8_t *pub) { @@ -164,9 +164,9 @@ _wots_sign (const struct slh_hash *hash, const union slh_hash_ctx *tree_ctx, } static void -wots_verify_one (const struct slh_hash *hash, const union slh_hash_ctx *tree_ctx, +wots_verify_one (const struct slh_hash *hash, const void *tree_ctx, uint32_t keypair, unsigned i, uint8_t msg, - const uint8_t *signature, union slh_hash_ctx *ctx) + const uint8_t *signature, void *ctx) { struct slh_address_hash ah; uint8_t out[_SLH_DSA_128_SIZE]; @@ -180,7 +180,7 @@ wots_verify_one (const struct slh_hash *hash, const union slh_hash_ctx *tree_ctx } void -_wots_verify (const struct slh_hash *hash, const union slh_hash_ctx *tree_ctx, +_wots_verify (const struct slh_hash *hash, const void *tree_ctx, unsigned keypair, const uint8_t *msg, const uint8_t *signature, uint8_t *pub) { struct slh_address_hash ah; -- 2.47.3