Update copyright notices.
[tinc] / src / openssl / digest.c
index 09ed666..79db491 100644 (file)
@@ -1,6 +1,6 @@
 /*
     digest.c -- Digest handling
-    Copyright (C) 2007 Guus Sliepen <guus@tinc-vpn.org>
+    Copyright (C) 2007-2012 Guus Sliepen <guus@tinc-vpn.org>
 
     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
@@ -41,7 +41,7 @@ bool digest_open_by_name(digest_t *digest, const char *name, int maclength) {
        digest->key = NULL;
 
        if(!digest->digest) {
-               logger(LOG_DEBUG, "Unknown digest name '%s'!", name);
+               logger(DEBUG_ALWAYS, LOG_DEBUG, "Unknown digest name '%s'!", name);
                return false;
        }
 
@@ -54,7 +54,7 @@ bool digest_open_by_nid(digest_t *digest, int nid, int maclength) {
        digest->key = NULL;
 
        if(!digest->digest) {
-               logger(LOG_DEBUG, "Unknown digest nid %d!", nid);
+               logger(DEBUG_ALWAYS, LOG_DEBUG, "Unknown digest nid %d!", nid);
                return false;
        }
 
@@ -78,8 +78,7 @@ bool digest_set_key(digest_t *digest, const void *key, size_t len) {
 }
 
 void digest_close(digest_t *digest) {
-       if(digest->key)
-               free(digest->key);
+       free(digest->key);
        digest->key = NULL;
 }
 
@@ -95,7 +94,7 @@ bool digest_create(digest_t *digest, const void *indata, size_t inlen, void *out
                if(!EVP_DigestInit(&ctx, digest->digest)
                                || !EVP_DigestUpdate(&ctx, indata, inlen)
                                || !EVP_DigestFinal(&ctx, tmpdata, NULL)) {
-                       logger(LOG_DEBUG, "Error creating digest: %s", ERR_error_string(ERR_get_error(), NULL));
+                       logger(DEBUG_ALWAYS, LOG_DEBUG, "Error creating digest: %s", ERR_error_string(ERR_get_error(), NULL));
                        return false;
                }
        }
@@ -115,6 +114,10 @@ int digest_get_nid(const digest_t *digest) {
        return digest->digest ? digest->digest->type : 0;
 }
 
+size_t digest_keylength(const digest_t *digest) {
+       return digest->digest->md_size;
+}
+
 size_t digest_length(const digest_t *digest) {
        return digest->maclength;
 }