diff options
author | Dwayne Litzenberger <dlitz@dlitz.net> | 2013-02-17 11:21:28 -0800 |
---|---|---|
committer | Dwayne Litzenberger <dlitz@dlitz.net> | 2013-02-17 19:00:50 -0800 |
commit | 59018ff99c97261f9bbaee33f919938871e05118 (patch) | |
tree | a07cdc2d6404d983314e1b5cbae78757e5a7a9be /src | |
parent | 4e4cc0beefbb316db2a8750e747e697df0b754d7 (diff) | |
download | pycrypto-59018ff99c97261f9bbaee33f919938871e05118.tar.gz |
Hash: Remove "oid" attributes; add "name" attribute
In PyCrypto v2.5, the "oid" attribute was added to hash objects. In
retrospect, this was not a good idea, since the OID is not really a
property of the hash algorithm, it's a protocol-specific identifer for
the hash functions. PKCS#1 v1.5 uses it, but other protocols (e.g.
OpenPGP, DNSSEC, SSH, etc.) use different identifiers, and it doesn't make
sense to add these to Crypto.Hash.* every time a new algorithm is added.
This also has the benefit of being compatible with the Python standard
library's "hashlib" objects, which also have a name attribute.
Diffstat (limited to 'src')
-rw-r--r-- | src/MD2.c | 1 | ||||
-rw-r--r-- | src/MD4.c | 1 | ||||
-rw-r--r-- | src/RIPEMD160.c | 1 | ||||
-rw-r--r-- | src/SHA224.c | 1 | ||||
-rw-r--r-- | src/SHA256.c | 1 | ||||
-rw-r--r-- | src/SHA384.c | 1 | ||||
-rw-r--r-- | src/SHA512.c | 1 | ||||
-rw-r--r-- | src/hash_template.c | 4 |
8 files changed, 11 insertions, 0 deletions
@@ -32,6 +32,7 @@ #include "pycrypto_compat.h" #define MODULE_NAME _MD2 +#define ALGORITHM_NAME "MD2" #define DIGEST_SIZE 16 #define BLOCK_SIZE 64 @@ -32,6 +32,7 @@ #include "pycrypto_compat.h" #define MODULE_NAME _MD4 +#define ALGORITHM_NAME "MD4" #define DIGEST_SIZE 16 #define BLOCK_SIZE 64 diff --git a/src/RIPEMD160.c b/src/RIPEMD160.c index 8ff3fc5..37d4c73 100644 --- a/src/RIPEMD160.c +++ b/src/RIPEMD160.c @@ -402,6 +402,7 @@ static int ripemd160_digest(const ripemd160_state *self, unsigned char *out) /* Template definitions */ #define MODULE_NAME _RIPEMD160 +#define ALGORITHM_NAME "RIPEMD160" #define DIGEST_SIZE RIPEMD160_DIGEST_SIZE #define hash_state ripemd160_state #define hash_init ripemd160_init diff --git a/src/SHA224.c b/src/SHA224.c index ca70fbd..99e2f7c 100644 --- a/src/SHA224.c +++ b/src/SHA224.c @@ -28,6 +28,7 @@ */ #define MODULE_NAME _SHA224 +#define ALGORITHM_NAME "SHA224" #define DIGEST_SIZE (224/8) #define BLOCK_SIZE (512/8) #define WORD_SIZE 4 diff --git a/src/SHA256.c b/src/SHA256.c index 61a2d74..8cc3265 100644 --- a/src/SHA256.c +++ b/src/SHA256.c @@ -27,6 +27,7 @@ * */ #define MODULE_NAME _SHA256 +#define ALGORITHM_NAME "SHA256" #define DIGEST_SIZE (256/8) #define BLOCK_SIZE (512/8) #define WORD_SIZE 4 diff --git a/src/SHA384.c b/src/SHA384.c index 05dfe25..24b200c 100644 --- a/src/SHA384.c +++ b/src/SHA384.c @@ -28,6 +28,7 @@ */ #define MODULE_NAME _SHA384 +#define ALGORITHM_NAME "SHA384" #define DIGEST_SIZE (384/8) #define BLOCK_SIZE (1024/8) #define WORD_SIZE 8 diff --git a/src/SHA512.c b/src/SHA512.c index 3370e8e..3b227ab 100644 --- a/src/SHA512.c +++ b/src/SHA512.c @@ -28,6 +28,7 @@ */ #define MODULE_NAME _SHA512 +#define ALGORITHM_NAME "SHA512" #define DIGEST_SIZE (512/8) #define BLOCK_SIZE (1024/8) #define WORD_SIZE 8 diff --git a/src/hash_template.c b/src/hash_template.c index 10b1b1c..afffbfb 100644 --- a/src/hash_template.c +++ b/src/hash_template.c @@ -209,9 +209,13 @@ ALG_getattr(PyObject *self, char *name) if (PyUnicode_CompareWithASCIIString(attr, "digest_size")==0) return PyLong_FromLong(DIGEST_SIZE); + if (PyUnicode_CompareWithASCIIString(attr, "name")==0) + return PyUnicode_FromString(ALGORITHM_NAME); #else if (strcmp(name, "digest_size")==0) return PyInt_FromLong(DIGEST_SIZE); + if (strcmp(name, "name")==0) + return PyString_FromString(ALGORITHM_NAME); #endif #ifdef IS_PY3K |