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 */ |