bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] crypto modules: the integer literals in BLOCKSIZE may be too lar


From: Hong Xu
Subject: [PATCH] crypto modules: the integer literals in BLOCKSIZE may be too large
Date: Sun, 10 Jan 2016 17:20:41 -0800

The BLOCKSIZE is defined as 32768, which may be too large if the default
signed integer size is no larger than 16 bits.
---
 lib/md2.c    | 5 +++--
 lib/md4.c    | 5 +++--
 lib/md5.c    | 5 +++--
 lib/sha1.c   | 5 +++--
 lib/sha256.c | 5 +++--
 lib/sha512.c | 5 +++--
 6 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/lib/md2.c b/lib/md2.c
index 5a9dce1c0ed2..f93f13145d4b 100644
--- a/lib/md2.c
+++ b/lib/md2.c
@@ -33,10 +33,11 @@
 # include "unlocked-io.h"
 #endif
 
-#define BLOCKSIZE 32768
-#if BLOCKSIZE % 64 != 0
+#define BLOCK_SIZE 32768UL
+#if BLOCK_SIZE % 64 != 0
 # error "invalid BLOCKSIZE"
 #endif
+#define BLOCKSIZE ((size_t) BLOCK_SIZE)
 
 static void md2_update_chksum (struct md2_ctx *md);
 static void md2_compress (struct md2_ctx *md);
diff --git a/lib/md4.c b/lib/md4.c
index 4f6193a643a7..94fd81ee2186 100644
--- a/lib/md4.c
+++ b/lib/md4.c
@@ -40,10 +40,11 @@
 # define SWAP(n) (n)
 #endif
 
-#define BLOCKSIZE 32768
-#if BLOCKSIZE % 64 != 0
+#define BLOCK_SIZE 32768UL
+#if BLOCK_SIZE % 64 != 0
 # error "invalid BLOCKSIZE"
 #endif
+#define BLOCKSIZE ((size_t) BLOCK_SIZE)
 
 /* This array contains the bytes used to pad the buffer to the next
    64-byte boundary.  (RFC 1320, 3.1: Step 1)  */
diff --git a/lib/md5.c b/lib/md5.c
index 33c3a08b7388..0037a44f6e39 100644
--- a/lib/md5.c
+++ b/lib/md5.c
@@ -59,10 +59,11 @@
 # define SWAP(n) (n)
 #endif
 
-#define BLOCKSIZE 32768
-#if BLOCKSIZE % 64 != 0
+#define BLOCK_SIZE 32768UL
+#if BLOCK_SIZE % 64 != 0
 # error "invalid BLOCKSIZE"
 #endif
+#define BLOCKSIZE ((size_t) BLOCK_SIZE)
 
 #if ! HAVE_OPENSSL_MD5
 /* This array contains the bytes used to pad the buffer to the next
diff --git a/lib/sha1.c b/lib/sha1.c
index d679d42fdccb..e03080daf7b3 100644
--- a/lib/sha1.c
+++ b/lib/sha1.c
@@ -44,10 +44,11 @@
     (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
 #endif
 
-#define BLOCKSIZE 32768
-#if BLOCKSIZE % 64 != 0
+#define BLOCK_SIZE 32768UL
+#if BLOCK_SIZE % 64 != 0
 # error "invalid BLOCKSIZE"
 #endif
+#define BLOCKSIZE ((size_t) BLOCK_SIZE)
 
 #if ! HAVE_OPENSSL_SHA1
 /* This array contains the bytes used to pad the buffer to the next
diff --git a/lib/sha256.c b/lib/sha256.c
index 0be8fd2a858b..7b20f91ed25a 100644
--- a/lib/sha256.c
+++ b/lib/sha256.c
@@ -43,10 +43,11 @@
     (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
 #endif
 
-#define BLOCKSIZE 32768
-#if BLOCKSIZE % 64 != 0
+#define BLOCK_SIZE 32768UL
+#if BLOCK_SIZE % 64 != 0
 # error "invalid BLOCKSIZE"
 #endif
+#define BLOCKSIZE ((size_t) BLOCK_SIZE)
 
 #if ! HAVE_OPENSSL_SHA256
 /* This array contains the bytes used to pad the buffer to the next
diff --git a/lib/sha512.c b/lib/sha512.c
index 5494dcbdbad7..a76787e1bb37 100644
--- a/lib/sha512.c
+++ b/lib/sha512.c
@@ -50,10 +50,11 @@
                          u64shr (n, 56))))
 #endif
 
-#define BLOCKSIZE 32768
-#if BLOCKSIZE % 128 != 0
+#define BLOCK_SIZE 32768UL
+#if BLOCK_SIZE % 128 != 0
 # error "invalid BLOCKSIZE"
 #endif
+#define BLOCKSIZE ((size_t) BLOCK_SIZE)
 
 #if ! HAVE_OPENSSL_SHA512
 /* This array contains the bytes used to pad the buffer to the next
-- 
2.1.4





reply via email to

[Prev in Thread] Current Thread [Next in Thread]