[Commits] [SCM] claws branch, master, updated. 3.17.3-52-ga09c703

ticho at claws-mail.org ticho at claws-mail.org
Sun Jan 27 12:18:51 CET 2019


The branch, master has been updated
       via  a09c703495e9e7e535051a24791c7dbb27877ff9 (commit)
      from  d92a8ab188823edb95760c128af3bfc1b7173263 (commit)

Summary of changes:
 src/common/pkcs5_pbkdf2.c |   24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)


- Log -----------------------------------------------------------------
commit a09c703495e9e7e535051a24791c7dbb27877ff9
Author: Andrej Kacian <ticho at claws-mail.org>
Date:   Sun Jan 27 11:38:36 2019 +0100

    Use hardcoded SHA digest length in pkcs5_pbkdf2.c
    
    This makes -Wvla happy and saves us two GnuTLS API calls
    with no real downside.

diff --git a/src/common/pkcs5_pbkdf2.c b/src/common/pkcs5_pbkdf2.c
index 1475a33..6f83fe5 100644
--- a/src/common/pkcs5_pbkdf2.c
+++ b/src/common/pkcs5_pbkdf2.c
@@ -26,6 +26,8 @@
 #include <stdio.h>
 
 #define CHECKSUM_BLOCKLEN 64
+#define SHA1_DIGESTLEN 20
+
 /*
  * HMAC-SHA-1 (from RFC 2202).
  */
@@ -34,21 +36,20 @@ hmac_sha1(const guchar *text, size_t text_len, const guchar *key,
     size_t key_len, guchar *digest)
 {
 	GChecksum *cksum;
-	gssize digestlen = g_checksum_type_get_length(G_CHECKSUM_SHA1);
 	gsize outlen;
 	guchar k_pad[CHECKSUM_BLOCKLEN];
-	guchar tk[digestlen];
+	guchar tk[SHA1_DIGESTLEN];
 	gint i;
 
 	if (key_len > CHECKSUM_BLOCKLEN) {
 		cksum = g_checksum_new(G_CHECKSUM_SHA1);
 		g_checksum_update(cksum, key, key_len);
-		outlen = digestlen;
+		outlen = SHA1_DIGESTLEN;
 		g_checksum_get_digest(cksum, tk, &outlen);
 		g_checksum_free(cksum);
 
 		key = tk;
-		key_len = digestlen;
+		key_len = SHA1_DIGESTLEN;
 	}
 
 	memset(k_pad, 0, sizeof k_pad);
@@ -59,7 +60,7 @@ hmac_sha1(const guchar *text, size_t text_len, const guchar *key,
 	cksum = g_checksum_new(G_CHECKSUM_SHA1);
 	g_checksum_update(cksum, k_pad, CHECKSUM_BLOCKLEN);
 	g_checksum_update(cksum, text, text_len);
-	outlen = digestlen;
+	outlen = SHA1_DIGESTLEN;
 	g_checksum_get_digest(cksum, digest, &outlen);
 	g_checksum_free(cksum);
 
@@ -70,8 +71,8 @@ hmac_sha1(const guchar *text, size_t text_len, const guchar *key,
 
 	cksum = g_checksum_new(G_CHECKSUM_SHA1);
 	g_checksum_update(cksum, k_pad, CHECKSUM_BLOCKLEN);
-	g_checksum_update(cksum, digest, digestlen);
-	outlen = digestlen;
+	g_checksum_update(cksum, digest, SHA1_DIGESTLEN);
+	outlen = SHA1_DIGESTLEN;
 	g_checksum_get_digest(cksum, digest, &outlen);
 	g_checksum_free(cksum);
 }
@@ -86,9 +87,8 @@ gint
 pkcs5_pbkdf2(const gchar *pass, size_t pass_len, const guchar *salt,
     size_t salt_len, guchar *key, size_t key_len, guint rounds)
 {
-	gssize digestlen = g_checksum_type_get_length(G_CHECKSUM_SHA1);
-	guchar *asalt, obuf[digestlen];
-	guchar d1[digestlen], d2[digestlen];
+	guchar *asalt, obuf[SHA1_DIGESTLEN];
+	guchar d1[SHA1_DIGESTLEN], d2[SHA1_DIGESTLEN];
 	guint i, j;
 	guint count;
 	size_t r;
@@ -119,7 +119,7 @@ pkcs5_pbkdf2(const gchar *pass, size_t pass_len, const guchar *salt,
 				obuf[j] ^= d1[j];
 		}
 
-		r = MIN(key_len, digestlen);
+		r = MIN(key_len, SHA1_DIGESTLEN);
 		memcpy(key, obuf, r);
 		key += r;
 		key_len -= r;
@@ -132,3 +132,5 @@ pkcs5_pbkdf2(const gchar *pass, size_t pass_len, const guchar *salt,
 
 	return 0;
 }
+
+#undef SHA1_DIGESTLEN

-----------------------------------------------------------------------


hooks/post-receive
-- 
Claws Mail


More information about the Commits mailing list