]> git.meshlink.io Git - meshlink/blobdiff - src/openssl/digest.c
Rename tinc.texi to meshlink.texi.
[meshlink] / src / openssl / digest.c
index 9699d37b5d94623ff00edbb5da3d2fcdb6a8a035..8d6e64da40f3bce367433465f0d78bdf02256044 100644 (file)
@@ -1,6 +1,6 @@
 /*
     digest.c -- Digest handling
-    Copyright (C) 2007-2013 Guus Sliepen <guus@tinc-vpn.org>
+    Copyright (C) 2014 Guus Sliepen <guus@meshlink.io>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -88,7 +88,10 @@ bool digest_create(digest_t *digest, const void *indata, size_t inlen, void *out
        unsigned char tmpdata[len];
 
        if(digest->key) {
-               HMAC(digest->digest, digest->key, digest->keylength, indata, inlen, tmpdata, NULL);
+               if(!HMAC(digest->digest, digest->key, digest->keylength, indata, inlen, tmpdata, NULL)) {
+                       logger(DEBUG_ALWAYS, LOG_DEBUG, "Error creating digest: %s", ERR_error_string(ERR_get_error(), NULL));
+                       return false;
+               }
        } else {
                EVP_MD_CTX ctx;
 
@@ -112,14 +115,23 @@ bool digest_verify(digest_t *digest, const void *indata, size_t inlen, const voi
 }
 
 int digest_get_nid(const digest_t *digest) {
-       return digest->digest ? digest->digest->type : 0;
+       if(!digest || !digest->digest)
+               return 0;
+
+       return digest->digest->type;
 }
 
 size_t digest_keylength(const digest_t *digest) {
+       if(!digest || !digest->digest)
+               return 0;
+
        return digest->digest->md_size;
 }
 
 size_t digest_length(const digest_t *digest) {
+       if(!digest)
+               return 0;
+
        return digest->maclength;
 }