From 3a96e8b49ce8b23e5ae5ee7d4cc071603e3a8f4c Mon Sep 17 00:00:00 2001 From: Loup Vaillant Date: Sun, 1 Dec 2019 13:57:17 +0100 Subject: [PATCH] Renamed crypto_hash_vtable into crypto_sign_vtable The vtable holds hash functions, but it's really a vtable for crypto_sign_ctx_abstract (and its check typedef). It's more tied to EdDSA than to the hash itself. --- src/monocypher.c | 8 ++++---- src/monocypher.h | 12 ++++++------ src/optional/ed25519.c | 2 +- src/optional/ed25519.h | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/monocypher.c b/src/monocypher.c index d000608..96b380f 100644 --- a/src/monocypher.c +++ b/src/monocypher.c @@ -647,7 +647,7 @@ static void blake2b_vtable_final(void *ctx, u8 *h) crypto_blake2b_final(&((crypto_sign_ctx*)ctx)->hash, h); } -const crypto_hash_vtable crypto_blake2b_vtable = { +const crypto_sign_vtable crypto_blake2b_vtable = { crypto_blake2b, blake2b_vtable_init, blake2b_vtable_update, @@ -1914,7 +1914,7 @@ static void ge_scalarmult_base(ge *p, const u8 scalar[32]) void crypto_sign_public_key_custom_hash(u8 public_key[32], const u8 secret_key[32], - const crypto_hash_vtable *hash) + const crypto_sign_vtable *hash) { u8 a[64]; hash->hash(a, secret_key, 32); @@ -1935,7 +1935,7 @@ void crypto_sign_public_key(u8 public_key[32], const u8 secret_key[32]) void crypto_sign_init_first_pass_custom_hash(crypto_sign_ctx_abstract *ctx, const u8 secret_key[32], const u8 public_key[32], - const crypto_hash_vtable *hash) + const crypto_sign_vtable *hash) { ctx->hash = hash; // set vtable u8 *a = ctx->buf; @@ -2025,7 +2025,7 @@ void crypto_sign(u8 signature[64], void crypto_check_init_custom_hash(crypto_check_ctx_abstract *ctx, const u8 signature[64], const u8 public_key[32], - const crypto_hash_vtable *hash) + const crypto_sign_vtable *hash) { ctx->hash = hash; // set vtable FOR (i, 0, 64) { ctx->buf[i] = signature [i]; } diff --git a/src/monocypher.h b/src/monocypher.h index f60366b..0d99b04 100644 --- a/src/monocypher.h +++ b/src/monocypher.h @@ -19,7 +19,7 @@ typedef struct { void (*update)(void *ctx, const uint8_t *message, size_t message_size); void (*final )(void *ctx, uint8_t *hash); size_t ctx_size; -} crypto_hash_vtable; +} crypto_sign_vtable; // Do not rely on the size or contents of any of the types below, // they may change without notice. @@ -44,7 +44,7 @@ typedef struct { // Signatures (EdDSA) typedef struct { - const crypto_hash_vtable *hash; + const crypto_sign_vtable *hash; uint8_t buf[96]; uint8_t pk [32]; } crypto_sign_ctx_abstract; @@ -126,7 +126,7 @@ void crypto_blake2b_general_init(crypto_blake2b_ctx *ctx, size_t hash_size, const uint8_t *key, size_t key_size); // vtable for signatures -extern const crypto_hash_vtable crypto_blake2b_vtable; +extern const crypto_sign_vtable crypto_blake2b_vtable; // Password key derivation (Argon2 i) @@ -191,15 +191,15 @@ int crypto_check_final (crypto_check_ctx_abstract *ctx); // Custom hash interface void crypto_sign_public_key_custom_hash(uint8_t public_key[32], const uint8_t secret_key[32], - const crypto_hash_vtable *hash); + const crypto_sign_vtable *hash); void crypto_sign_init_first_pass_custom_hash(crypto_sign_ctx_abstract *ctx, const uint8_t secret_key[32], const uint8_t public_key[32], - const crypto_hash_vtable *hash); + const crypto_sign_vtable *hash); void crypto_check_init_custom_hash(crypto_check_ctx_abstract *ctx, const uint8_t signature[64], const uint8_t public_key[32], - const crypto_hash_vtable *hash); + const crypto_sign_vtable *hash); //////////////////////////// /// Low level primitives /// diff --git a/src/optional/ed25519.c b/src/optional/ed25519.c index 3782994..5279c2e 100644 --- a/src/optional/ed25519.c +++ b/src/optional/ed25519.c @@ -220,7 +220,7 @@ static void sha512_vtable_final(void *ctx, u8 *h) crypto_sha512_final(&((crypto_sign_sha512_ctx*)ctx)->hash, h); } -const crypto_hash_vtable crypto_sha512_vtable = { +const crypto_sign_vtable crypto_sha512_vtable = { crypto_sha512, sha512_vtable_init, sha512_vtable_update, diff --git a/src/optional/ed25519.h b/src/optional/ed25519.h index 3753c21..981140e 100644 --- a/src/optional/ed25519.h +++ b/src/optional/ed25519.h @@ -34,7 +34,7 @@ void crypto_sha512_final (crypto_sha512_ctx *ctx, uint8_t hash[64]); void crypto_sha512(uint8_t *out,const uint8_t *message, size_t message_size); // vtable for signatures -extern const crypto_hash_vtable crypto_sha512_vtable; +extern const crypto_sign_vtable crypto_sha512_vtable; // Ed25519 -- 2.47.3