summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrédéric Bertolus <fred@linkeos.com>2011-04-08 18:23:07 +0200
committerFrédéric Bertolus <fred@linkeos.com>2011-04-08 18:23:07 +0200
commit577d0dbd7dfeeb07d55ec0a3412298722cdd2337 (patch)
treecc8d30dc07a5d9a132a531d451a1eb7457510203
parenta65e9e86bfce406fc72bc21f219c8de4eba42181 (diff)
downloadpycrypto-577d0dbd7dfeeb07d55ec0a3412298722cdd2337.tar.gz
Add variable block size support to HMAC-SHA384 and HMAC-SHA512 which use
block of 128 bytes long
-rw-r--r--lib/Crypto/Hash/HMAC.py8
-rw-r--r--lib/Crypto/Hash/SHA.py1
-rw-r--r--lib/Crypto/Hash/SHA224.py2
-rw-r--r--lib/Crypto/Hash/SHA384.py2
-rw-r--r--lib/Crypto/Hash/SHA512.py2
-rw-r--r--src/MD2.c1
-rw-r--r--src/MD4.c1
-rw-r--r--src/RIPEMD160.c1
-rw-r--r--src/SHA256.c1
-rw-r--r--src/hash_template.c1
10 files changed, 16 insertions, 4 deletions
diff --git a/lib/Crypto/Hash/HMAC.py b/lib/Crypto/Hash/HMAC.py
index 4daff2f..96e0afc 100644
--- a/lib/Crypto/Hash/HMAC.py
+++ b/lib/Crypto/Hash/HMAC.py
@@ -76,7 +76,13 @@ class HMAC:
except AttributeError:
self.digest_size = len(self.outer.digest())
- blocksize = 64
+ try:
+ # The block size is 128 bytes for SHA384 and SHA512 and 64 bytes
+ # for the others hash function
+ blocksize = digestmod.block_size
+ except AttributeError:
+ blocksize = 64
+
ipad = 0x36
opad = 0x5C
diff --git a/lib/Crypto/Hash/SHA.py b/lib/Crypto/Hash/SHA.py
index 13f69e1..c289f05 100644
--- a/lib/Crypto/Hash/SHA.py
+++ b/lib/Crypto/Hash/SHA.py
@@ -38,3 +38,4 @@ except ImportError:
digest_size = digestsize
del digestsize
del sha
+block_size = 64
diff --git a/lib/Crypto/Hash/SHA224.py b/lib/Crypto/Hash/SHA224.py
index 9d91788..e2a6876 100644
--- a/lib/Crypto/Hash/SHA224.py
+++ b/lib/Crypto/Hash/SHA224.py
@@ -28,4 +28,4 @@ import hashlib
def new(data=""):
return hashlib.sha224(data)
digest_size = new().digest_size
-
+block_size = 64
diff --git a/lib/Crypto/Hash/SHA384.py b/lib/Crypto/Hash/SHA384.py
index fb74e42..8d0fa30 100644
--- a/lib/Crypto/Hash/SHA384.py
+++ b/lib/Crypto/Hash/SHA384.py
@@ -28,4 +28,4 @@ import hashlib
def new(data=""):
return hashlib.sha384(data)
digest_size = new().digest_size
-
+block_size = 128
diff --git a/lib/Crypto/Hash/SHA512.py b/lib/Crypto/Hash/SHA512.py
index 4968f15..f6c4787 100644
--- a/lib/Crypto/Hash/SHA512.py
+++ b/lib/Crypto/Hash/SHA512.py
@@ -28,4 +28,4 @@ import hashlib
def new(data=""):
return hashlib.sha512(data)
digest_size = new().digest_size
-
+block_size = 128
diff --git a/src/MD2.c b/src/MD2.c
index a3974c6..78a3c03 100644
--- a/src/MD2.c
+++ b/src/MD2.c
@@ -32,6 +32,7 @@
#define MODULE_NAME MD2
#define DIGEST_SIZE 16
+#define BLOCK_SIZE 64
typedef unsigned char U8;
typedef unsigned int U32;
diff --git a/src/MD4.c b/src/MD4.c
index 51cbd31..2691e4d 100644
--- a/src/MD4.c
+++ b/src/MD4.c
@@ -32,6 +32,7 @@
#define MODULE_NAME MD4
#define DIGEST_SIZE 16
+#define BLOCK_SIZE 64
typedef unsigned int U32;
typedef unsigned char U8;
diff --git a/src/RIPEMD160.c b/src/RIPEMD160.c
index da2e72c..e6bd2fb 100644
--- a/src/RIPEMD160.c
+++ b/src/RIPEMD160.c
@@ -49,6 +49,7 @@
#include "Python.h"
#define RIPEMD160_DIGEST_SIZE 20
+#define BLOCK_SIZE 64
#define RIPEMD160_MAGIC 0x9f19dd68u
typedef struct {
diff --git a/src/SHA256.c b/src/SHA256.c
index 8150242..13be586 100644
--- a/src/SHA256.c
+++ b/src/SHA256.c
@@ -34,6 +34,7 @@
#include "Python.h"
#define MODULE_NAME SHA256
#define DIGEST_SIZE 32
+#define BLOCK_SIZE 64
typedef unsigned char U8;
#ifdef __alpha__
diff --git a/src/hash_template.c b/src/hash_template.c
index 78e37be..60270c2 100644
--- a/src/hash_template.c
+++ b/src/hash_template.c
@@ -258,6 +258,7 @@ _MODULE_NAME (void)
/* Add some symbolic constants to the module */
PyModule_AddIntConstant(m, "digest_size", DIGEST_SIZE);
+ PyModule_AddIntConstant(m, "block_size", BLOCK_SIZE);
/* Check for errors */
if (PyErr_Occurred())