]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
use digest_nettle function for nsec3_hash calls.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Tue, 17 Nov 2015 11:39:58 +0000 (11:39 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Tue, 17 Nov 2015 11:39:58 +0000 (11:39 +0000)
git-svn-id: file:///svn/unbound/trunk@3537 be551aaa-1e26-0410-a405-d3ace91eadb9

validator/val_secalgo.c

index 434b6870f4663a58df3db176eb8aa6e38bc4bbe2..99caf8af1cf49fa80d45d1fd2155a8631dcfab43 100644 (file)
@@ -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)