ed25519-hash-custom.h (1121B)
1 /* 2 a custom hash must have a 512bit digest and implement: 3 4 struct ed25519_hash_context; 5 6 void ed25519_hash_init(ed25519_hash_context *ctx); 7 void ed25519_hash_update(ed25519_hash_context *ctx, const uint8_t *in, size_t inlen); 8 void ed25519_hash_final(ed25519_hash_context *ctx, uint8_t *hash); 9 void ed25519_hash(uint8_t *hash, const uint8_t *in, size_t inlen); 10 */ 11 12 #include "lib/crypt_ops/crypto_digest.h" 13 14 typedef struct ed25519_hash_context { 15 crypto_digest_t *ctx; 16 } ed25519_hash_context; 17 18 19 static void 20 ed25519_hash_init(ed25519_hash_context *ctx) 21 { 22 ctx->ctx = crypto_digest512_new(DIGEST_SHA512); 23 } 24 static void 25 ed25519_hash_update(ed25519_hash_context *ctx, const uint8_t *in, size_t inlen) 26 { 27 crypto_digest_add_bytes(ctx->ctx, (const char *)in, inlen); 28 } 29 static void 30 ed25519_hash_final(ed25519_hash_context *ctx, uint8_t *hash) 31 { 32 crypto_digest_get_digest(ctx->ctx, (char *)hash, DIGEST512_LEN); 33 crypto_digest_free(ctx->ctx); 34 ctx->ctx = NULL; 35 } 36 static void 37 ed25519_hash(uint8_t *hash, const uint8_t *in, size_t inlen) 38 { 39 crypto_digest512((char *)hash, (const char *)in, inlen, 40 DIGEST_SHA512); 41 }