From: Wouter Wijngaards Date: Tue, 17 Nov 2015 11:39:58 +0000 (+0000) Subject: use digest_nettle function for nsec3_hash calls. X-Git-Tag: release-1.5.7rc1~33 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fa57a6c6e8e24780580c0a10fc4ea0c573c33bec;p=thirdparty%2Funbound.git use digest_nettle function for nsec3_hash calls. git-svn-id: file:///svn/unbound/trunk@3537 be551aaa-1e26-0410-a405-d3ace91eadb9 --- 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,6 +1134,49 @@ verify_canonrrset(sldns_buffer* buf, int algo, unsigned char* sigblock, #include "ecc-curve.h" #endif +static int +_digest_nettle(int algo, uint8_t* buf, size_t len, + unsigned char* res) +{ + switch(algo) { + case SHA1_DIGEST_SIZE: + { + struct sha1_ctx ctx; + sha1_init(&ctx); + sha1_update(&ctx, len, buf); + sha1_digest(&ctx, SHA1_DIGEST_SIZE, res); + return 1; + } + case SHA256_DIGEST_SIZE: + { + struct sha256_ctx ctx; + sha256_init(&ctx); + sha256_update(&ctx, len, buf); + sha256_digest(&ctx, SHA256_DIGEST_SIZE, res); + return 1; + } + case SHA384_DIGEST_SIZE: + { + struct sha384_ctx ctx; + sha384_init(&ctx); + sha384_update(&ctx, len, buf); + sha384_digest(&ctx, SHA384_DIGEST_SIZE, res); + return 1; + } + case SHA512_DIGEST_SIZE: + { + struct sha512_ctx ctx; + sha512_init(&ctx); + sha512_update(&ctx, len, buf); + sha512_digest(&ctx, SHA512_DIGEST_SIZE, res); + return 1; + } + default: + break; + } + return 0; +} + /* return size of digest if supported, or 0 otherwise */ size_t nsec3_hash_algo_size_supported(int id) @@ -1153,13 +1196,8 @@ secalgo_nsec3_hash(int algo, unsigned char* buf, size_t len, { 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; + return _digest_nettle(SHA1_DIGEST_SIZE, (uint8_t*)buf, len, + res); default: return 0; } @@ -1192,51 +1230,6 @@ ds_digest_size_supported(int algo) return 0; } - - -static int -_digest_nettle(int algo, uint8_t* buf, size_t len, - unsigned char* res) -{ - switch(algo) { - case SHA1_DIGEST_SIZE: - { - struct sha1_ctx ctx; - sha1_init(&ctx); - sha1_update(&ctx, len, buf); - sha1_digest(&ctx, SHA1_DIGEST_SIZE, res); - return 1; - } - case SHA256_DIGEST_SIZE: - { - struct sha256_ctx ctx; - sha256_init(&ctx); - sha256_update(&ctx, len, buf); - sha256_digest(&ctx, SHA256_DIGEST_SIZE, res); - return 1; - } - case SHA384_DIGEST_SIZE: - { - struct sha384_ctx ctx; - sha384_init(&ctx); - sha384_update(&ctx, len, buf); - sha384_digest(&ctx, SHA384_DIGEST_SIZE, res); - return 1; - } - case SHA512_DIGEST_SIZE: - { - struct sha512_ctx ctx; - sha512_init(&ctx); - sha512_update(&ctx, len, buf); - sha512_digest(&ctx, SHA512_DIGEST_SIZE, res); - return 1; - } - default: - break; - } - return 0; -} - int secalgo_ds_digest(int algo, unsigned char* buf, size_t len, unsigned char* res)