1 Index: Lib/test/test_hashlib.py
2 ===================================================================
3 --- Lib/test/test_hashlib.py (revision 64642)
4 +++ Lib/test/test_hashlib.py (working copy)
8 from test import test_support
9 +from test.test_support import _4G, precisionbigmemtest
16 m2.update(aas + bees + cees)
17 self.assertEqual(m1.digest(), m2.digest())
20 def check(self, name, data, digest):
21 # test the direct constructors
22 computed = getattr(hashlib, name)(data).hexdigest()
24 def test_case_md5_2(self):
25 self.check('md5', 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
26 'd174ab98d277d9f5a5611c2c9f419d9f')
28 + @precisionbigmemtest(size=_4G + 5, memuse=1)
29 + def test_case_md5_huge(self, size):
32 + self.check('md5', 'A'*size, 'c9af2dff37468ce5dfee8f2cfc0a9c6d')
33 + except OverflowError:
36 + @precisionbigmemtest(size=_4G - 1, memuse=1)
37 + def test_case_md5_uintmax(self, size):
40 + self.check('md5', 'A'*size, '28138d306ff1b8281f1a9067e1a1a2b3')
41 + except OverflowError:
45 # use the three examples from Federal Information Processing Standards
46 # Publication 180-1, Secure Hash Standard, 1995 April 17
47 # http://www.itl.nist.gov/div897/pubs/fip180-1.htm
48 Index: Modules/_hashopenssl.c
49 ===================================================================
50 --- Modules/_hashopenssl.c (revision 64642)
51 +++ Modules/_hashopenssl.c (working copy)
53 /* EVP is the preferred interface to hashing in OpenSSL */
54 #include <openssl/evp.h>
56 +#define MUNCH_SIZE INT_MAX
59 #ifndef HASH_OBJ_CONSTRUCTOR
60 #define HASH_OBJ_CONSTRUCTOR 0
63 if (!PyArg_ParseTuple(args, "s#:update", &cp, &len))
66 + if (len > 0 && len <= MUNCH_SIZE) {
67 EVP_DigestUpdate(&self->ctx, cp, Py_SAFE_DOWNCAST(len, Py_ssize_t,
71 + Py_ssize_t offset = 0;
73 + unsigned int process = len > MUNCH_SIZE ? MUNCH_SIZE : len;
74 + EVP_DigestUpdate(&self->ctx, cp + offset, process);
83 self->name = name_obj;
84 Py_INCREF(self->name);
88 + if (len > 0 && len <= MUNCH_SIZE) {
89 EVP_DigestUpdate(&self->ctx, cp, Py_SAFE_DOWNCAST(len, Py_ssize_t,
93 + Py_ssize_t offset = 0;
95 + unsigned int process = len > MUNCH_SIZE ? MUNCH_SIZE : len;
96 + EVP_DigestUpdate(&self->ctx, cp + offset, process);
108 EVPnew(PyObject *name_obj,
109 const EVP_MD *digest, const EVP_MD_CTX *initial_ctx,
110 - const unsigned char *cp, unsigned int len)
111 + const unsigned char *cp, Py_ssize_t len)
116 EVP_DigestInit(&self->ctx, digest);
120 - EVP_DigestUpdate(&self->ctx, cp, len);
122 + if (len > 0 && len <= MUNCH_SIZE) {
123 + EVP_DigestUpdate(&self->ctx, cp, Py_SAFE_DOWNCAST(len, Py_ssize_t,
126 + Py_ssize_t offset = 0;
128 + unsigned int process = len > MUNCH_SIZE ? MUNCH_SIZE : len;
129 + EVP_DigestUpdate(&self->ctx, cp + offset, process);
136 return (PyObject *)self;
140 digest = EVP_get_digestbyname(name);
142 - return EVPnew(name_obj, digest, NULL, cp, Py_SAFE_DOWNCAST(len, Py_ssize_t,
144 + return EVPnew(name_obj, digest, NULL, cp, len);
149 CONST_ ## NAME ## _name_obj, \
151 CONST_new_ ## NAME ## _ctx_p, \
152 - cp, Py_SAFE_DOWNCAST(len, Py_ssize_t, unsigned int)); \
156 /* a PyMethodDef structure for the constructor */