Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 230640 | Differences between
and this patch

Collapse All | Expand All

(-)Lib/test/test_hashlib.py (-3 / +17 lines)
Lines 9-16 Link Here
9
import hashlib
9
import hashlib
10
import unittest
10
import unittest
11
from test import test_support
11
from test import test_support
12
from test.test_support import _4G, precisionbigmemtest
12
13
13
14
def hexstr(s):
14
def hexstr(s):
15
    import string
15
    import string
16
    h = string.hexdigits
16
    h = string.hexdigits
Lines 55-61 Link Here
55
            m2.update(aas + bees + cees)
55
            m2.update(aas + bees + cees)
56
            self.assertEqual(m1.digest(), m2.digest())
56
            self.assertEqual(m1.digest(), m2.digest())
57
57
58
59
    def check(self, name, data, digest):
58
    def check(self, name, data, digest):
60
        # test the direct constructors
59
        # test the direct constructors
61
        computed = getattr(hashlib, name)(data).hexdigest()
60
        computed = getattr(hashlib, name)(data).hexdigest()
Lines 74-81 Link Here
74
    def test_case_md5_2(self):
73
    def test_case_md5_2(self):
75
        self.check('md5', 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
74
        self.check('md5', 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
76
                   'd174ab98d277d9f5a5611c2c9f419d9f')
75
                   'd174ab98d277d9f5a5611c2c9f419d9f')
76
    
77
    @precisionbigmemtest(size=_4G + 5, memuse=1)
78
    def test_case_md5_huge(self, size):
79
        if size == _4G + 5:
80
            try:
81
                self.check('md5', 'A'*size, 'c9af2dff37468ce5dfee8f2cfc0a9c6d')
82
            except OverflowError:
83
                pass # 32-bit arch
84
    
85
    @precisionbigmemtest(size=_4G - 1, memuse=1)
86
    def test_case_md5_uintmax(self, size):
87
        if size == _4G - 1:
88
            try:
89
                self.check('md5', 'A'*size, '28138d306ff1b8281f1a9067e1a1a2b3')
90
            except OverflowError:
91
                pass # 32-bit arch
77
92
78
79
    # use the three examples from Federal Information Processing Standards
93
    # use the three examples from Federal Information Processing Standards
80
    # Publication 180-1, Secure Hash Standard,  1995 April 17
94
    # Publication 180-1, Secure Hash Standard,  1995 April 17
81
    # http://www.itl.nist.gov/div897/pubs/fip180-1.htm
95
    # http://www.itl.nist.gov/div897/pubs/fip180-1.htm
(-)Modules/_hashopenssl.c (-9 / +42 lines)
Lines 19-25 Link Here
19
/* EVP is the preferred interface to hashing in OpenSSL */
19
/* EVP is the preferred interface to hashing in OpenSSL */
20
#include <openssl/evp.h>
20
#include <openssl/evp.h>
21
21
22
#define MUNCH_SIZE INT_MAX
22
23
24
23
#ifndef HASH_OBJ_CONSTRUCTOR
25
#ifndef HASH_OBJ_CONSTRUCTOR
24
#define HASH_OBJ_CONSTRUCTOR 0
26
#define HASH_OBJ_CONSTRUCTOR 0
25
#endif
27
#endif
Lines 164-172 Link Here
164
    if (!PyArg_ParseTuple(args, "s#:update", &cp, &len))
166
    if (!PyArg_ParseTuple(args, "s#:update", &cp, &len))
165
        return NULL;
167
        return NULL;
166
168
169
    if (len > 0 && len <= MUNCH_SIZE) {
167
    EVP_DigestUpdate(&self->ctx, cp, Py_SAFE_DOWNCAST(len, Py_ssize_t,
170
    EVP_DigestUpdate(&self->ctx, cp, Py_SAFE_DOWNCAST(len, Py_ssize_t,
168
                                                      unsigned int));
171
                                                      unsigned int));
169
172
    } else {
173
        Py_ssize_t offset = 0;
174
        while (len) {
175
            unsigned int process = len > MUNCH_SIZE ? MUNCH_SIZE : len;
176
            EVP_DigestUpdate(&self->ctx, cp + offset, process);
177
            len -= process;
178
            offset += process;
179
        }
180
    }
170
    Py_INCREF(Py_None);
181
    Py_INCREF(Py_None);
171
    return Py_None;
182
    return Py_None;
172
}
183
}
Lines 255-264 Link Here
255
    self->name = name_obj;
266
    self->name = name_obj;
256
    Py_INCREF(self->name);
267
    Py_INCREF(self->name);
257
268
258
    if (cp && len)
269
    if (cp && len) {
270
        if (len > 0 && len <= MUNCH_SIZE) {
259
        EVP_DigestUpdate(&self->ctx, cp, Py_SAFE_DOWNCAST(len, Py_ssize_t,
271
        EVP_DigestUpdate(&self->ctx, cp, Py_SAFE_DOWNCAST(len, Py_ssize_t,
260
                                                          unsigned int));
272
                                                          unsigned int));
261
273
        } else {
274
            Py_ssize_t offset = 0;
275
            while (len) {
276
                unsigned int process = len > MUNCH_SIZE ? MUNCH_SIZE : len;
277
                EVP_DigestUpdate(&self->ctx, cp + offset, process);
278
                len -= process;
279
                offset += process;
280
            }
281
        }
282
    }
283
    
262
    return 0;
284
    return 0;
263
}
285
}
264
#endif
286
#endif
Lines 327-333 Link Here
327
static PyObject *
349
static PyObject *
328
EVPnew(PyObject *name_obj,
350
EVPnew(PyObject *name_obj,
329
       const EVP_MD *digest, const EVP_MD_CTX *initial_ctx,
351
       const EVP_MD *digest, const EVP_MD_CTX *initial_ctx,
330
       const unsigned char *cp, unsigned int len)
352
       const unsigned char *cp, Py_ssize_t len)
331
{
353
{
332
    EVPobject *self;
354
    EVPobject *self;
333
355
Lines 345-352 Link Here
345
        EVP_DigestInit(&self->ctx, digest);
367
        EVP_DigestInit(&self->ctx, digest);
346
    }
368
    }
347
369
348
    if (cp && len)
370
    if (cp && len) {
349
        EVP_DigestUpdate(&self->ctx, cp, len);
371
        if (len > 0 && len <= MUNCH_SIZE) {
372
            EVP_DigestUpdate(&self->ctx, cp, Py_SAFE_DOWNCAST(len, Py_ssize_t,
373
                                                              unsigned int));
374
        } else {
375
            Py_ssize_t offset = 0;
376
            while (len) {
377
                unsigned int process = len > MUNCH_SIZE ? MUNCH_SIZE : len;
378
                EVP_DigestUpdate(&self->ctx, cp + offset, process);
379
                len -= process;
380
                offset += process;
381
            }
382
        }
383
    }
350
384
351
    return (PyObject *)self;
385
    return (PyObject *)self;
352
}
386
}
Lines 383-390 Link Here
383
417
384
    digest = EVP_get_digestbyname(name);
418
    digest = EVP_get_digestbyname(name);
385
419
386
    return EVPnew(name_obj, digest, NULL, cp, Py_SAFE_DOWNCAST(len, Py_ssize_t,
420
    return EVPnew(name_obj, digest, NULL, cp, len);
387
                                                               unsigned int));
388
}
421
}
389
422
390
/*
423
/*
Lines 409-415 Link Here
409
                CONST_ ## NAME ## _name_obj, \
442
                CONST_ ## NAME ## _name_obj, \
410
                NULL, \
443
                NULL, \
411
                CONST_new_ ## NAME ## _ctx_p, \
444
                CONST_new_ ## NAME ## _ctx_p, \
412
                cp, Py_SAFE_DOWNCAST(len, Py_ssize_t, unsigned int)); \
445
                cp, len); \
413
    }
446
    }
414
447
415
/* a PyMethodDef structure for the constructor */
448
/* a PyMethodDef structure for the constructor */

Return to bug 230640