]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
Use union slh_hash_ctx exclusively for allocation.
authorNiels Möller <nisse@lysator.liu.se>
Wed, 10 Sep 2025 07:31:20 +0000 (09:31 +0200)
committerNiels Möller <nisse@lysator.liu.se>
Wed, 10 Sep 2025 07:31:20 +0000 (09:31 +0200)
slh-dsa-internal.h
slh-fors.c
slh-wots.c

index 1d680136f635f31715a850edbca4cc67a020dc1b..c4af8a58b08e8e41d0554e5cd55e216dce8be911 100644 (file)
@@ -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
index e990643663d04ce0e87ae7a9aac5df2f429468e2..2818487d38b60db44505409f5da79ee5130e521a 100644 (file)
@@ -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 =
index c04fa620b7791fc0dc4b2fd7a28c18b09c06260d..f00a9a9ec9663109dca9bfab953bb6cfb271814b 100644 (file)
@@ -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;