From 34e71cce0c9f7d7c6c92805ada14b627396bb9b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96zg=C3=BCr=20Kesim?= Date: Sun, 30 Jan 2022 14:18:04 +0100 Subject: [PATCH] [WIP - DOESN'T COMPILE] age_commitment_hash added --- src/include/taler_crypto_lib.h | 24 ++++++++++++++++++++++++ src/util/crypto.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/src/include/taler_crypto_lib.h b/src/include/taler_crypto_lib.h index ab69d4dfb..069c0d3ca 100644 --- a/src/include/taler_crypto_lib.h +++ b/src/include/taler_crypto_lib.h @@ -317,6 +317,30 @@ extern const struct TALER_AgeHash TALER_AgeHash_zeroHash; &TALER_AgeHash_zeroHash, \ sizeof(struct \ TALER_AgeHash)))) +/* + * @brief Representation of an age commitment: one public key per age group. + * + * The number of keys must be be the same as the number of bits set in the + * corresponding age mask. + */ +struct TALER_AgeCommitment +{ + struct TALER_AgeMask mask; + struct GNUNET_CRYPTO_EddsaPublicKey *keys; + size_t num_keys; +}; + + +/* + * @brief Generates a hash of the public keys in the age commitment. + * @param commitment the age commitment - one public key per age group + * @param[out] hash resulting hash + */ +void +TALER_age_commitment_hash ( + const struct TALER_AgeCommitment *commitment, + struct TALER_AgeHash *hash); + /** * @brief Type of public keys for Taler coins. The same key material is used diff --git a/src/util/crypto.c b/src/util/crypto.c index 817ad3cd7..c0ad07387 100644 --- a/src/util/crypto.c +++ b/src/util/crypto.c @@ -20,6 +20,7 @@ * @author Florian Dold * @author Benedikt Mueller * @author Christian Grothoff + * @author Özgür Kesim */ #include "platform.h" #include "taler_util.h" @@ -356,4 +357,33 @@ TALER_coin_pub_hash (const struct TALER_CoinSpendPublicKeyP *coin_pub, } +void +TALER_age_commitment_hash ( + const struct TALER_AgeCommitment *commitment, + struct TALER_AgeHash *ahash) +{ + struct GNUNET_HashContext *hash_context; + struct GNUNET_HashCode hash; + GNUNET_assert (NULL != commitment); + GNUNET_assert (__builtin_popcount (commitment->mask.mask) == + commitment->num_keys); + + hash_context = GNUNET_CRYPTO_hash_context_start (); + + for (size_t i = 0; i < commitment->num_keys; i++) + { + GNUNET_CRYPTO_hash_context_read (hash_context, + &commitment->keys[i], + sizeof(struct + GNUNET_CRYPTO_EddsaPublicKey)); + } + + GNUNET_CRYPTO_hash_context_finish (hash_context, + &hash); + GNUNET_memcpy (&ahash->shash.bits, + &hash.bits, + sizeof(ahash->shash.bits)); +} + + /* end of crypto.c */