From fa57a6c6e8e24780580c0a10fc4ea0c573c33bec Mon Sep 17 00:00:00 2001 From: Wouter Wijngaards Date: Tue, 17 Nov 2015 11:39:58 +0000 Subject: [PATCH] use digest_nettle function for nsec3_hash calls. git-svn-id: file:///svn/unbound/trunk@3537 be551aaa-1e26-0410-a405-d3ace91eadb9 --- validator/val_secalgo.c | 113 +++++++++++++++++++--------------------- 1 file changed, 53 insertions(+), 60 deletions(-) diff --git a/validator/val_secalgo.c b/validator/val_secalgo.c index 434b6870f..99caf8af1 100644 --- a/validator/val_secalgo.c +++ b/validator/val_secalgo.c @@ -1134,66 +1134,6 @@ verify_canonrrset(sldns_buffer* buf, int algo, unsigned char* sigblock, #include "ecc-curve.h" #endif -/* return size of digest if supported, or 0 otherwise */ -size_t -nsec3_hash_algo_size_supported(int id) -{ - switch(id) { - case NSEC3_HASH_SHA1: - return SHA1_DIGEST_SIZE; - default: - return 0; - } -} - -/* perform nsec3 hash. return false on failure */ -int -secalgo_nsec3_hash(int algo, unsigned char* buf, size_t len, - unsigned char* res) -{ - switch(algo) { - case NSEC3_HASH_SHA1: - { - struct sha1_ctx ctx; - sha1_init(&ctx); - sha1_update(&ctx, len, (uint8_t*)buf); - sha1_digest(&ctx, SHA1_DIGEST_SIZE, (uint8_t*)res); - } - return 1; - default: - return 0; - } -} - -/** - * Return size of DS digest according to its hash algorithm. - * @param algo: DS digest algo. - * @return size in bytes of digest, or 0 if not supported. - */ -size_t -ds_digest_size_supported(int algo) -{ - switch(algo) { - case LDNS_SHA1: - return SHA1_DIGEST_SIZE; -#ifdef USE_SHA2 - case LDNS_SHA256: - return SHA256_DIGEST_SIZE; -#endif -#ifdef USE_ECDSA - case LDNS_SHA384: - return SHA384_DIGEST_SIZE; -#endif - /* GOST not supported */ - case LDNS_HASH_GOST: - default: - break; - } - return 0; -} - - - static int _digest_nettle(int algo, uint8_t* buf, size_t len, unsigned char* res) @@ -1237,6 +1177,59 @@ _digest_nettle(int algo, uint8_t* buf, size_t len, return 0; } +/* return size of digest if supported, or 0 otherwise */ +size_t +nsec3_hash_algo_size_supported(int id) +{ + switch(id) { + case NSEC3_HASH_SHA1: + return SHA1_DIGEST_SIZE; + default: + return 0; + } +} + +/* perform nsec3 hash. return false on failure */ +int +secalgo_nsec3_hash(int algo, unsigned char* buf, size_t len, + unsigned char* res) +{ + switch(algo) { + case NSEC3_HASH_SHA1: + return _digest_nettle(SHA1_DIGEST_SIZE, (uint8_t*)buf, len, + res); + default: + return 0; + } +} + +/** + * Return size of DS digest according to its hash algorithm. + * @param algo: DS digest algo. + * @return size in bytes of digest, or 0 if not supported. + */ +size_t +ds_digest_size_supported(int algo) +{ + switch(algo) { + case LDNS_SHA1: + return SHA1_DIGEST_SIZE; +#ifdef USE_SHA2 + case LDNS_SHA256: + return SHA256_DIGEST_SIZE; +#endif +#ifdef USE_ECDSA + case LDNS_SHA384: + return SHA384_DIGEST_SIZE; +#endif + /* GOST not supported */ + case LDNS_HASH_GOST: + default: + break; + } + return 0; +} + int secalgo_ds_digest(int algo, unsigned char* buf, size_t len, unsigned char* res)