2005-08-21 15:45:59 -03:00
|
|
|
/* Module that wraps all OpenSSL hash algorithms */
|
|
|
|
|
|
|
|
/*
|
2010-01-09 14:45:30 -04:00
|
|
|
* Copyright (C) 2005-2010 Gregory P. Smith (greg@krypto.org)
|
2005-08-21 15:45:59 -03:00
|
|
|
* Licensed to PSF under a Contributor Agreement.
|
|
|
|
*
|
|
|
|
* Derived from a skeleton of shamodule.c containing work performed by:
|
|
|
|
*
|
|
|
|
* Andrew Kuchling (amk@amk.ca)
|
|
|
|
* Greg Stein (gstein@lyra.org)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2006-03-01 17:50:07 -04:00
|
|
|
#define PY_SSIZE_T_CLEAN
|
|
|
|
|
2005-08-21 15:45:59 -03:00
|
|
|
#include "Python.h"
|
|
|
|
#include "structmember.h"
|
2009-02-12 03:35:29 -04:00
|
|
|
#include "hashlib.h"
|
2015-04-25 20:42:38 -03:00
|
|
|
#include "pystrhex.h"
|
2005-08-21 15:45:59 -03:00
|
|
|
|
2009-01-08 17:17:16 -04:00
|
|
|
|
2009-05-03 21:45:33 -03:00
|
|
|
/* EVP is the preferred interface to hashing in OpenSSL */
|
|
|
|
#include <openssl/evp.h>
|
2018-01-27 04:53:43 -04:00
|
|
|
#include <openssl/hmac.h>
|
2010-09-06 05:30:23 -03:00
|
|
|
/* We use the object interface to discover what hashes OpenSSL supports. */
|
|
|
|
#include <openssl/objects.h>
|
2013-10-12 19:52:43 -03:00
|
|
|
#include "openssl/err.h"
|
2009-05-03 21:45:33 -03:00
|
|
|
|
2016-09-06 15:22:28 -03:00
|
|
|
#include "clinic/_hashopenssl.c.h"
|
|
|
|
/*[clinic input]
|
|
|
|
module _hashlib
|
|
|
|
[clinic start generated code]*/
|
|
|
|
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=c2b4ff081bac4be1]*/
|
|
|
|
|
2009-05-03 21:45:33 -03:00
|
|
|
#define MUNCH_SIZE INT_MAX
|
|
|
|
|
|
|
|
#ifndef HASH_OBJ_CONSTRUCTOR
|
|
|
|
#define HASH_OBJ_CONSTRUCTOR 0
|
|
|
|
#endif
|
|
|
|
|
2016-09-05 18:19:05 -03:00
|
|
|
#if (OPENSSL_VERSION_NUMBER < 0x10100000L) || defined(LIBRESSL_VERSION_NUMBER)
|
|
|
|
/* OpenSSL < 1.1.0 */
|
|
|
|
#define EVP_MD_CTX_new EVP_MD_CTX_create
|
|
|
|
#define EVP_MD_CTX_free EVP_MD_CTX_destroy
|
|
|
|
#define HAS_FAST_PKCS5_PBKDF2_HMAC 0
|
|
|
|
#include <openssl/hmac.h>
|
|
|
|
#else
|
|
|
|
/* OpenSSL >= 1.1.0 */
|
|
|
|
#define HAS_FAST_PKCS5_PBKDF2_HMAC 1
|
|
|
|
#endif
|
|
|
|
|
2009-05-03 21:45:33 -03:00
|
|
|
|
2005-08-21 15:45:59 -03:00
|
|
|
typedef struct {
|
|
|
|
PyObject_HEAD
|
|
|
|
PyObject *name; /* name of this hash algorithm */
|
2016-09-05 18:19:05 -03:00
|
|
|
EVP_MD_CTX *ctx; /* OpenSSL message digest context */
|
2009-01-08 17:17:16 -04:00
|
|
|
PyThread_type_lock lock; /* OpenSSL context lock */
|
2005-08-21 15:45:59 -03:00
|
|
|
} EVPobject;
|
|
|
|
|
|
|
|
|
|
|
|
static PyTypeObject EVPtype;
|
|
|
|
|
|
|
|
|
|
|
|
#define DEFINE_CONSTS_FOR_NEW(Name) \
|
2013-02-01 21:05:29 -04:00
|
|
|
static PyObject *CONST_ ## Name ## _name_obj = NULL; \
|
2005-08-21 15:45:59 -03:00
|
|
|
static EVP_MD_CTX *CONST_new_ ## Name ## _ctx_p = NULL;
|
|
|
|
|
2006-01-07 17:20:24 -04:00
|
|
|
DEFINE_CONSTS_FOR_NEW(md5)
|
|
|
|
DEFINE_CONSTS_FOR_NEW(sha1)
|
|
|
|
DEFINE_CONSTS_FOR_NEW(sha224)
|
|
|
|
DEFINE_CONSTS_FOR_NEW(sha256)
|
|
|
|
DEFINE_CONSTS_FOR_NEW(sha384)
|
|
|
|
DEFINE_CONSTS_FOR_NEW(sha512)
|
2005-08-21 15:45:59 -03:00
|
|
|
|
|
|
|
|
2016-09-05 18:19:05 -03:00
|
|
|
/* LCOV_EXCL_START */
|
|
|
|
static PyObject *
|
|
|
|
_setException(PyObject *exc)
|
|
|
|
{
|
|
|
|
unsigned long errcode;
|
|
|
|
const char *lib, *func, *reason;
|
|
|
|
|
|
|
|
errcode = ERR_peek_last_error();
|
|
|
|
if (!errcode) {
|
|
|
|
PyErr_SetString(exc, "unknown reasons");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
ERR_clear_error();
|
|
|
|
|
|
|
|
lib = ERR_lib_error_string(errcode);
|
|
|
|
func = ERR_func_error_string(errcode);
|
|
|
|
reason = ERR_reason_error_string(errcode);
|
|
|
|
|
|
|
|
if (lib && func) {
|
|
|
|
PyErr_Format(exc, "[%s: %s] %s", lib, func, reason);
|
|
|
|
}
|
|
|
|
else if (lib) {
|
|
|
|
PyErr_Format(exc, "[%s] %s", lib, reason);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PyErr_SetString(exc, reason);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/* LCOV_EXCL_STOP */
|
|
|
|
|
2005-08-21 15:45:59 -03:00
|
|
|
static EVPobject *
|
|
|
|
newEVPobject(PyObject *name)
|
|
|
|
{
|
|
|
|
EVPobject *retval = (EVPobject *)PyObject_New(EVPobject, &EVPtype);
|
2016-09-05 18:19:05 -03:00
|
|
|
if (retval == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-03-04 12:17:30 -04:00
|
|
|
/* save the name for .name to return */
|
|
|
|
Py_INCREF(name);
|
|
|
|
retval->name = name;
|
|
|
|
retval->lock = NULL;
|
|
|
|
|
2016-09-05 18:19:05 -03:00
|
|
|
retval->ctx = EVP_MD_CTX_new();
|
|
|
|
if (retval->ctx == NULL) {
|
2019-03-04 12:17:30 -04:00
|
|
|
Py_DECREF(retval);
|
2016-09-05 18:19:05 -03:00
|
|
|
PyErr_NoMemory();
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-08-21 15:45:59 -03:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2009-01-08 17:17:16 -04:00
|
|
|
static void
|
|
|
|
EVP_hash(EVPobject *self, const void *vp, Py_ssize_t len)
|
|
|
|
{
|
|
|
|
unsigned int process;
|
|
|
|
const unsigned char *cp = (const unsigned char *)vp;
|
|
|
|
while (0 < len) {
|
|
|
|
if (len > (Py_ssize_t)MUNCH_SIZE)
|
|
|
|
process = MUNCH_SIZE;
|
|
|
|
else
|
|
|
|
process = Py_SAFE_DOWNCAST(len, Py_ssize_t, unsigned int);
|
2017-05-24 04:04:38 -03:00
|
|
|
if (!EVP_DigestUpdate(self->ctx, (const void*)cp, process)) {
|
|
|
|
_setException(PyExc_ValueError);
|
|
|
|
break;
|
|
|
|
}
|
2009-01-08 17:17:16 -04:00
|
|
|
len -= process;
|
|
|
|
cp += process;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-21 15:45:59 -03:00
|
|
|
/* Internal methods for a hash object */
|
|
|
|
|
|
|
|
static void
|
2009-01-08 17:17:16 -04:00
|
|
|
EVP_dealloc(EVPobject *self)
|
2005-08-21 15:45:59 -03:00
|
|
|
{
|
2009-01-08 17:17:16 -04:00
|
|
|
if (self->lock != NULL)
|
|
|
|
PyThread_free_lock(self->lock);
|
2016-09-05 18:19:05 -03:00
|
|
|
EVP_MD_CTX_free(self->ctx);
|
2009-01-08 17:17:16 -04:00
|
|
|
Py_XDECREF(self->name);
|
|
|
|
PyObject_Del(self);
|
2005-08-21 15:45:59 -03:00
|
|
|
}
|
|
|
|
|
2016-09-05 18:19:05 -03:00
|
|
|
static int
|
|
|
|
locked_EVP_MD_CTX_copy(EVP_MD_CTX *new_ctx_p, EVPobject *self)
|
2009-05-03 21:45:33 -03:00
|
|
|
{
|
2016-09-05 18:19:05 -03:00
|
|
|
int result;
|
2009-05-03 21:45:33 -03:00
|
|
|
ENTER_HASHLIB(self);
|
2016-09-05 18:19:05 -03:00
|
|
|
result = EVP_MD_CTX_copy(new_ctx_p, self->ctx);
|
2009-05-03 21:45:33 -03:00
|
|
|
LEAVE_HASHLIB(self);
|
2016-09-05 18:19:05 -03:00
|
|
|
return result;
|
2009-05-03 21:45:33 -03:00
|
|
|
}
|
2005-08-21 15:45:59 -03:00
|
|
|
|
|
|
|
/* External methods for a hash object */
|
|
|
|
|
|
|
|
PyDoc_STRVAR(EVP_copy__doc__, "Return a copy of the hash object.");
|
|
|
|
|
2009-05-03 21:45:33 -03:00
|
|
|
|
2005-08-21 15:45:59 -03:00
|
|
|
static PyObject *
|
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
merge in bad ways, so I'll have to merge that extra-carefully (probably manually.)
Merged revisions 46495-46605 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r46495 | tim.peters | 2006-05-28 03:52:38 +0200 (Sun, 28 May 2006) | 2 lines
Added missing svn:eol-style property to text files.
........
r46497 | tim.peters | 2006-05-28 12:41:29 +0200 (Sun, 28 May 2006) | 3 lines
PyErr_Display(), PyErr_WriteUnraisable(): Coverity found a cut-and-paste
bug in both: `className` was referenced before being checked for NULL.
........
r46499 | fredrik.lundh | 2006-05-28 14:06:46 +0200 (Sun, 28 May 2006) | 5 lines
needforspeed: added Py_MEMCPY macro (currently tuned for Visual C only),
and use it for string copy operations. this gives a 20% speedup on some
string benchmarks.
........
r46501 | michael.hudson | 2006-05-28 17:51:40 +0200 (Sun, 28 May 2006) | 26 lines
Quality control, meet exceptions.c.
Fix a number of problems with the need for speed code:
One is doing this sort of thing:
Py_DECREF(self->field);
self->field = newval;
Py_INCREF(self->field);
without being very sure that self->field doesn't start with a
value that has a __del__, because that almost certainly can lead
to segfaults.
As self->args is constrained to be an exact tuple we may as well
exploit this fact consistently. This leads to quite a lot of
simplification (and, hey, probably better performance).
Add some error checking in places lacking it.
Fix some rather strange indentation in the Unicode code.
Delete some trailing whitespace.
More to come, I haven't fixed all the reference leaks yet...
........
r46502 | george.yoshida | 2006-05-28 18:39:09 +0200 (Sun, 28 May 2006) | 3 lines
Patch #1080727: add "encoding" parameter to doctest.DocFileSuite
Contributed by Bjorn Tillenius.
........
r46503 | martin.v.loewis | 2006-05-28 18:57:38 +0200 (Sun, 28 May 2006) | 4 lines
Rest of patch #1490384: Commit icon source, remove
claim that Erik von Blokland is the author of the
installer picture.
........
r46504 | michael.hudson | 2006-05-28 19:40:29 +0200 (Sun, 28 May 2006) | 16 lines
Quality control, meet exceptions.c, round two.
Make some functions that should have been static static.
Fix a bunch of refleaks by fixing the definition of
MiddlingExtendsException.
Remove all the __new__ implementations apart from
BaseException_new. Rewrite most code that needs it to cope with
NULL fields (such code could get excercised anyway, the
__new__-removal just makes it more likely). This involved
editing the code for WindowsError, which I can't test.
This fixes all the refleaks in at least the start of a regrtest
-R :: run.
........
r46505 | marc-andre.lemburg | 2006-05-28 19:46:58 +0200 (Sun, 28 May 2006) | 10 lines
Initial version of systimes - a module to provide platform dependent
performance measurements.
The module is currently just a proof-of-concept implementation, but
will integrated into pybench once it is stable enough.
License: pybench license.
Author: Marc-Andre Lemburg.
........
r46507 | armin.rigo | 2006-05-28 21:13:17 +0200 (Sun, 28 May 2006) | 15 lines
("Forward-port" of r46506)
Remove various dependencies on dictionary order in the standard library
tests, and one (clearly an oversight, potentially critical) in the
standard library itself - base64.py.
Remaining open issues:
* test_extcall is an output test, messy to make robust
* tarfile.py has a potential bug here, but I'm not familiar
enough with this code. Filed in as SF bug #1496501.
* urllib2.HTTPPasswordMgr() returns a random result if there is more
than one matching root path. I'm asking python-dev for
clarification...
........
r46508 | georg.brandl | 2006-05-28 22:11:45 +0200 (Sun, 28 May 2006) | 4 lines
The empty string is a valid import path.
(fixes #1496539)
........
r46509 | georg.brandl | 2006-05-28 22:23:12 +0200 (Sun, 28 May 2006) | 3 lines
Patch #1496206: urllib2 PasswordMgr ./. default ports
........
r46510 | georg.brandl | 2006-05-28 22:57:09 +0200 (Sun, 28 May 2006) | 3 lines
Fix refleaks in UnicodeError get and set methods.
........
r46511 | michael.hudson | 2006-05-28 23:19:03 +0200 (Sun, 28 May 2006) | 3 lines
use the UnicodeError traversal and clearing functions in UnicodeError
subclasses.
........
r46512 | thomas.wouters | 2006-05-28 23:32:12 +0200 (Sun, 28 May 2006) | 4 lines
Make last patch valid C89 so Windows compilers can deal with it.
........
r46513 | georg.brandl | 2006-05-28 23:42:54 +0200 (Sun, 28 May 2006) | 3 lines
Fix ref-antileak in _struct.c which eventually lead to deallocating None.
........
r46514 | georg.brandl | 2006-05-28 23:57:35 +0200 (Sun, 28 May 2006) | 4 lines
Correct None refcount issue in Mac modules. (Are they
still used?)
........
r46515 | armin.rigo | 2006-05-29 00:07:08 +0200 (Mon, 29 May 2006) | 3 lines
A clearer error message when passing -R to regrtest.py with
release builds of Python.
........
r46516 | georg.brandl | 2006-05-29 00:14:04 +0200 (Mon, 29 May 2006) | 3 lines
Fix C function calling conventions in _sre module.
........
r46517 | georg.brandl | 2006-05-29 00:34:51 +0200 (Mon, 29 May 2006) | 3 lines
Convert audioop over to METH_VARARGS.
........
r46518 | georg.brandl | 2006-05-29 00:38:57 +0200 (Mon, 29 May 2006) | 3 lines
METH_NOARGS functions do get called with two args.
........
r46519 | georg.brandl | 2006-05-29 11:46:51 +0200 (Mon, 29 May 2006) | 4 lines
Fix refleak in socketmodule. Replace bogus Py_BuildValue calls.
Fix refleak in exceptions.
........
r46520 | nick.coghlan | 2006-05-29 14:43:05 +0200 (Mon, 29 May 2006) | 7 lines
Apply modified version of Collin Winter's patch #1478788
Renames functional extension module to _functools and adds a Python
functools module so that utility functions like update_wrapper can be
added easily.
........
r46522 | georg.brandl | 2006-05-29 15:53:16 +0200 (Mon, 29 May 2006) | 3 lines
Convert fmmodule to METH_VARARGS.
........
r46523 | georg.brandl | 2006-05-29 16:13:21 +0200 (Mon, 29 May 2006) | 3 lines
Fix #1494605.
........
r46524 | georg.brandl | 2006-05-29 16:28:05 +0200 (Mon, 29 May 2006) | 3 lines
Handle PyMem_Malloc failure in pystrtod.c. Closes #1494671.
........
r46525 | georg.brandl | 2006-05-29 16:33:55 +0200 (Mon, 29 May 2006) | 3 lines
Fix compiler warning.
........
r46526 | georg.brandl | 2006-05-29 16:39:00 +0200 (Mon, 29 May 2006) | 3 lines
Fix #1494787 (pyclbr counts whitespace as superclass name)
........
r46527 | bob.ippolito | 2006-05-29 17:47:29 +0200 (Mon, 29 May 2006) | 1 line
simplify the struct code a bit (no functional changes)
........
r46528 | armin.rigo | 2006-05-29 19:59:47 +0200 (Mon, 29 May 2006) | 2 lines
Silence a warning.
........
r46529 | georg.brandl | 2006-05-29 21:39:45 +0200 (Mon, 29 May 2006) | 3 lines
Correct some value converting strangenesses.
........
r46530 | nick.coghlan | 2006-05-29 22:27:44 +0200 (Mon, 29 May 2006) | 1 line
When adding a module like functools, it helps to let SVN know about the file.
........
r46531 | georg.brandl | 2006-05-29 22:52:54 +0200 (Mon, 29 May 2006) | 4 lines
Patches #1497027 and #972322: try HTTP digest auth first,
and watch out for handler name collisions.
........
r46532 | georg.brandl | 2006-05-29 22:57:01 +0200 (Mon, 29 May 2006) | 3 lines
Add News entry for last commit.
........
r46533 | georg.brandl | 2006-05-29 23:04:52 +0200 (Mon, 29 May 2006) | 4 lines
Make use of METH_O and METH_NOARGS where possible.
Use Py_UnpackTuple instead of PyArg_ParseTuple where possible.
........
r46534 | georg.brandl | 2006-05-29 23:58:42 +0200 (Mon, 29 May 2006) | 3 lines
Convert more modules to METH_VARARGS.
........
r46535 | georg.brandl | 2006-05-30 00:00:30 +0200 (Tue, 30 May 2006) | 3 lines
Whoops.
........
r46536 | fredrik.lundh | 2006-05-30 00:42:07 +0200 (Tue, 30 May 2006) | 4 lines
fixed "abc".count("", 100) == -96 error (hopefully, nobody's relying on
the current behaviour ;-)
........
r46537 | bob.ippolito | 2006-05-30 00:55:48 +0200 (Tue, 30 May 2006) | 1 line
struct: modulo math plus warning on all endian-explicit formats for compatibility with older struct usage (ugly)
........
r46539 | bob.ippolito | 2006-05-30 02:26:01 +0200 (Tue, 30 May 2006) | 1 line
Add a length check to aifc to ensure it doesn't write a bogus file
........
r46540 | tim.peters | 2006-05-30 04:25:25 +0200 (Tue, 30 May 2006) | 10 lines
deprecated_err(): Stop bizarre warning messages when the tests
are run in the order:
test_genexps (or any other doctest-based test)
test_struct
test_doctest
The `warnings` module needs an advertised way to save/restore
its internal filter list.
........
r46541 | tim.peters | 2006-05-30 04:26:46 +0200 (Tue, 30 May 2006) | 2 lines
Whitespace normalization.
........
r46542 | tim.peters | 2006-05-30 04:30:30 +0200 (Tue, 30 May 2006) | 2 lines
Set a binary svn:mime-type property on this UTF-8 encoded file.
........
r46543 | neal.norwitz | 2006-05-30 05:18:50 +0200 (Tue, 30 May 2006) | 1 line
Simplify further by using AddStringConstant
........
r46544 | tim.peters | 2006-05-30 06:16:25 +0200 (Tue, 30 May 2006) | 6 lines
Convert relevant dict internals to Py_ssize_t.
I don't have a box with nearly enough RAM, or an OS,
that could get close to tickling this, though (requires
a dict w/ at least 2**31 entries).
........
r46545 | neal.norwitz | 2006-05-30 06:19:21 +0200 (Tue, 30 May 2006) | 1 line
Remove stray | in comment
........
r46546 | neal.norwitz | 2006-05-30 06:25:05 +0200 (Tue, 30 May 2006) | 1 line
Use Py_SAFE_DOWNCAST for safety. Fix format strings. Remove 2 more stray | in comment
........
r46547 | neal.norwitz | 2006-05-30 06:43:23 +0200 (Tue, 30 May 2006) | 1 line
No DOWNCAST is required since sizeof(Py_ssize_t) >= sizeof(int) and Py_ReprEntr returns an int
........
r46548 | tim.peters | 2006-05-30 07:04:59 +0200 (Tue, 30 May 2006) | 3 lines
dict_print(): Explicitly narrow the return value
from a (possibly) wider variable.
........
r46549 | tim.peters | 2006-05-30 07:23:59 +0200 (Tue, 30 May 2006) | 5 lines
dict_print(): So that Neal & I don't spend the rest of
our lives taking turns rewriting code that works ;-),
get rid of casting illusions by declaring a new variable
with the obvious type.
........
r46550 | georg.brandl | 2006-05-30 09:04:55 +0200 (Tue, 30 May 2006) | 3 lines
Restore exception pickle support. #1497319.
........
r46551 | georg.brandl | 2006-05-30 09:13:29 +0200 (Tue, 30 May 2006) | 3 lines
Add a test case for exception pickling. args is never NULL.
........
r46552 | neal.norwitz | 2006-05-30 09:21:10 +0200 (Tue, 30 May 2006) | 1 line
Don't fail if the (sub)pkgname already exist.
........
r46553 | georg.brandl | 2006-05-30 09:34:45 +0200 (Tue, 30 May 2006) | 3 lines
Disallow keyword args for exceptions.
........
r46554 | neal.norwitz | 2006-05-30 09:36:54 +0200 (Tue, 30 May 2006) | 5 lines
I'm impatient. I think this will fix a few more problems with the buildbots.
I'm not sure this is the best approach, but I can't think of anything better.
If this creates problems, feel free to revert, but I think it's safe and
should make things a little better.
........
r46555 | georg.brandl | 2006-05-30 10:17:00 +0200 (Tue, 30 May 2006) | 4 lines
Do the check for no keyword arguments in __init__ so that
subclasses of Exception can be supplied keyword args
........
r46556 | georg.brandl | 2006-05-30 10:47:19 +0200 (Tue, 30 May 2006) | 3 lines
Convert test_exceptions to unittest.
........
r46557 | andrew.kuchling | 2006-05-30 14:52:01 +0200 (Tue, 30 May 2006) | 1 line
Add SoC name, and reorganize this section a bit
........
r46559 | tim.peters | 2006-05-30 17:53:34 +0200 (Tue, 30 May 2006) | 11 lines
PyLong_FromString(): Continued fraction analysis (explained in
a new comment) suggests there are almost certainly large input
integers in all non-binary input bases for which one Python digit
too few is initally allocated to hold the final result. Instead
of assert-failing when that happens, allocate more space. Alas,
I estimate it would take a few days to find a specific such case,
so this isn't backed up by a new test (not to mention that such
a case may take hours to run, since conversion time is quadratic
in the number of digits, and preliminary attempts suggested that
the smallest such inputs contain at least a million digits).
........
r46560 | fredrik.lundh | 2006-05-30 19:11:48 +0200 (Tue, 30 May 2006) | 3 lines
changed find/rfind to return -1 for matches outside the source string
........
r46561 | bob.ippolito | 2006-05-30 19:37:54 +0200 (Tue, 30 May 2006) | 1 line
Change wrapping terminology to overflow masking
........
r46562 | fredrik.lundh | 2006-05-30 19:39:58 +0200 (Tue, 30 May 2006) | 3 lines
changed count to return 0 for slices outside the source string
........
r46568 | tim.peters | 2006-05-31 01:28:02 +0200 (Wed, 31 May 2006) | 2 lines
Whitespace normalization.
........
r46569 | brett.cannon | 2006-05-31 04:19:54 +0200 (Wed, 31 May 2006) | 5 lines
Clarify wording on default values for strptime(); defaults are used when better
values cannot be inferred.
Closes bug #1496315.
........
r46572 | neal.norwitz | 2006-05-31 09:43:27 +0200 (Wed, 31 May 2006) | 1 line
Calculate smallest properly (it was off by one) and use proper ssize_t types for Win64
........
r46573 | neal.norwitz | 2006-05-31 10:01:08 +0200 (Wed, 31 May 2006) | 1 line
Revert last checkin, it is better to do make distclean
........
r46574 | neal.norwitz | 2006-05-31 11:02:44 +0200 (Wed, 31 May 2006) | 3 lines
On 64-bit platforms running test_struct after test_tarfile would fail
since the deprecation warning wouldn't be raised.
........
r46575 | thomas.heller | 2006-05-31 13:37:58 +0200 (Wed, 31 May 2006) | 3 lines
PyTuple_Pack is not available in Python 2.3, but ctypes must stay
compatible with that.
........
r46576 | andrew.kuchling | 2006-05-31 15:18:56 +0200 (Wed, 31 May 2006) | 1 line
'functional' module was renamed to 'functools'
........
r46577 | kristjan.jonsson | 2006-05-31 15:35:41 +0200 (Wed, 31 May 2006) | 1 line
Fixup the PCBuild8 project directory. exceptions.c have moved to Objects, and the functionalmodule.c has been replaced with _functoolsmodule.c. Other minor changes to .vcproj files and .sln to fix compilation
........
r46578 | andrew.kuchling | 2006-05-31 16:08:48 +0200 (Wed, 31 May 2006) | 15 lines
[Bug #1473048]
SimpleXMLRPCServer and DocXMLRPCServer don't look at
the path of the HTTP request at all; you can POST or
GET from / or /RPC2 or /blahblahblah with the same results.
Security scanners that look for /cgi-bin/phf will therefore report
lots of vulnerabilities.
Fix: add a .rpc_paths attribute to the SimpleXMLRPCServer class,
and report a 404 error if the path isn't on the allowed list.
Possibly-controversial aspect of this change: the default makes only
'/' and '/RPC2' legal. Maybe this will break people's applications
(though I doubt it). We could just set the default to an empty tuple,
which would exactly match the current behaviour.
........
r46579 | andrew.kuchling | 2006-05-31 16:12:47 +0200 (Wed, 31 May 2006) | 1 line
Mention SimpleXMLRPCServer change
........
r46580 | tim.peters | 2006-05-31 16:28:07 +0200 (Wed, 31 May 2006) | 2 lines
Trimmed trailing whitespace.
........
r46581 | tim.peters | 2006-05-31 17:33:22 +0200 (Wed, 31 May 2006) | 4 lines
_range_error(): Speed and simplify (there's no real need for
loops here). Assert that size_t is actually big enough, and
that f->size is at least one. Wrap a long line.
........
r46582 | tim.peters | 2006-05-31 17:34:37 +0200 (Wed, 31 May 2006) | 2 lines
Repaired error in new comment.
........
r46584 | neal.norwitz | 2006-06-01 07:32:49 +0200 (Thu, 01 Jun 2006) | 4 lines
Remove ; at end of macro. There was a compiler recently that warned
about extra semi-colons. It may have been the HP C compiler.
This file will trigger a bunch of those warnings now.
........
r46585 | georg.brandl | 2006-06-01 08:39:19 +0200 (Thu, 01 Jun 2006) | 3 lines
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
........
r46586 | georg.brandl | 2006-06-01 10:27:32 +0200 (Thu, 01 Jun 2006) | 3 lines
Correctly allocate complex types with tp_alloc. (bug #1498638)
........
r46587 | georg.brandl | 2006-06-01 14:30:46 +0200 (Thu, 01 Jun 2006) | 2 lines
Correctly dispatch Faults in loads (patch #1498627)
........
r46588 | georg.brandl | 2006-06-01 15:00:49 +0200 (Thu, 01 Jun 2006) | 3 lines
Some code style tweaks, and remove apply.
........
r46589 | armin.rigo | 2006-06-01 15:19:12 +0200 (Thu, 01 Jun 2006) | 5 lines
[ 1497053 ] Let dicts propagate the exceptions in user __eq__().
[ 1456209 ] dictresize() vulnerability ( <- backport candidate ).
........
r46590 | tim.peters | 2006-06-01 15:41:46 +0200 (Thu, 01 Jun 2006) | 2 lines
Whitespace normalization.
........
r46591 | tim.peters | 2006-06-01 15:49:23 +0200 (Thu, 01 Jun 2006) | 2 lines
Record bugs 1275608 and 1456209 as being fixed.
........
r46592 | tim.peters | 2006-06-01 15:56:26 +0200 (Thu, 01 Jun 2006) | 5 lines
Re-enable a new empty-string test added during the NFS sprint,
but disabled then because str and unicode strings gave different
results. The implementations were repaired later during the
sprint, but the new test remained disabled.
........
r46594 | tim.peters | 2006-06-01 17:50:44 +0200 (Thu, 01 Jun 2006) | 7 lines
Armin committed his patch while I was reviewing it (I'm sure
he didn't know this), so merged in some changes I made during
review. Nothing material apart from changing a new `mask` local
from int to Py_ssize_t. Mostly this is repairing comments that
were made incorrect, and adding new comments. Also a few
minor code rewrites for clarity or helpful succinctness.
........
r46599 | neal.norwitz | 2006-06-02 06:45:53 +0200 (Fri, 02 Jun 2006) | 1 line
Convert docstrings to comments so regrtest -v prints method names
........
r46600 | neal.norwitz | 2006-06-02 06:50:49 +0200 (Fri, 02 Jun 2006) | 2 lines
Fix memory leak found by valgrind.
........
r46601 | neal.norwitz | 2006-06-02 06:54:52 +0200 (Fri, 02 Jun 2006) | 1 line
More memory leaks from valgrind
........
r46602 | neal.norwitz | 2006-06-02 08:23:00 +0200 (Fri, 02 Jun 2006) | 11 lines
Patch #1357836:
Prevent an invalid memory read from test_coding in case the done flag is set.
In that case, the loop isn't entered. I wonder if rather than setting
the done flag in the cases before the loop, if they should just exit early.
This code looks like it should be refactored.
Backport candidate (also the early break above if decoding_fgets fails)
........
r46603 | martin.blais | 2006-06-02 15:03:43 +0200 (Fri, 02 Jun 2006) | 1 line
Fixed struct test to not use unittest.
........
r46605 | tim.peters | 2006-06-03 01:22:51 +0200 (Sat, 03 Jun 2006) | 10 lines
pprint functions used to sort a dict (by key) if and only if
the output required more than one line. "Small" dicts got
displayed in seemingly random order (the hash-induced order
produced by dict.__repr__). None of this was documented.
Now pprint functions always sort dicts by key, and the docs
promise it.
This was proposed and agreed to during the PyCon 2006 core
sprint -- I just didn't have time for it before now.
........
2006-06-08 11:42:34 -03:00
|
|
|
EVP_copy(EVPobject *self, PyObject *unused)
|
2005-08-21 15:45:59 -03:00
|
|
|
{
|
|
|
|
EVPobject *newobj;
|
|
|
|
|
|
|
|
if ( (newobj = newEVPobject(self->name))==NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2016-09-05 18:19:05 -03:00
|
|
|
if (!locked_EVP_MD_CTX_copy(newobj->ctx, self)) {
|
2019-03-04 12:17:30 -04:00
|
|
|
Py_DECREF(newobj);
|
2016-09-05 18:19:05 -03:00
|
|
|
return _setException(PyExc_ValueError);
|
|
|
|
}
|
2005-08-21 15:45:59 -03:00
|
|
|
return (PyObject *)newobj;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(EVP_digest__doc__,
|
2018-10-19 20:20:56 -03:00
|
|
|
"Return the digest value as a bytes object.");
|
2005-08-21 15:45:59 -03:00
|
|
|
|
|
|
|
static PyObject *
|
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
merge in bad ways, so I'll have to merge that extra-carefully (probably manually.)
Merged revisions 46495-46605 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r46495 | tim.peters | 2006-05-28 03:52:38 +0200 (Sun, 28 May 2006) | 2 lines
Added missing svn:eol-style property to text files.
........
r46497 | tim.peters | 2006-05-28 12:41:29 +0200 (Sun, 28 May 2006) | 3 lines
PyErr_Display(), PyErr_WriteUnraisable(): Coverity found a cut-and-paste
bug in both: `className` was referenced before being checked for NULL.
........
r46499 | fredrik.lundh | 2006-05-28 14:06:46 +0200 (Sun, 28 May 2006) | 5 lines
needforspeed: added Py_MEMCPY macro (currently tuned for Visual C only),
and use it for string copy operations. this gives a 20% speedup on some
string benchmarks.
........
r46501 | michael.hudson | 2006-05-28 17:51:40 +0200 (Sun, 28 May 2006) | 26 lines
Quality control, meet exceptions.c.
Fix a number of problems with the need for speed code:
One is doing this sort of thing:
Py_DECREF(self->field);
self->field = newval;
Py_INCREF(self->field);
without being very sure that self->field doesn't start with a
value that has a __del__, because that almost certainly can lead
to segfaults.
As self->args is constrained to be an exact tuple we may as well
exploit this fact consistently. This leads to quite a lot of
simplification (and, hey, probably better performance).
Add some error checking in places lacking it.
Fix some rather strange indentation in the Unicode code.
Delete some trailing whitespace.
More to come, I haven't fixed all the reference leaks yet...
........
r46502 | george.yoshida | 2006-05-28 18:39:09 +0200 (Sun, 28 May 2006) | 3 lines
Patch #1080727: add "encoding" parameter to doctest.DocFileSuite
Contributed by Bjorn Tillenius.
........
r46503 | martin.v.loewis | 2006-05-28 18:57:38 +0200 (Sun, 28 May 2006) | 4 lines
Rest of patch #1490384: Commit icon source, remove
claim that Erik von Blokland is the author of the
installer picture.
........
r46504 | michael.hudson | 2006-05-28 19:40:29 +0200 (Sun, 28 May 2006) | 16 lines
Quality control, meet exceptions.c, round two.
Make some functions that should have been static static.
Fix a bunch of refleaks by fixing the definition of
MiddlingExtendsException.
Remove all the __new__ implementations apart from
BaseException_new. Rewrite most code that needs it to cope with
NULL fields (such code could get excercised anyway, the
__new__-removal just makes it more likely). This involved
editing the code for WindowsError, which I can't test.
This fixes all the refleaks in at least the start of a regrtest
-R :: run.
........
r46505 | marc-andre.lemburg | 2006-05-28 19:46:58 +0200 (Sun, 28 May 2006) | 10 lines
Initial version of systimes - a module to provide platform dependent
performance measurements.
The module is currently just a proof-of-concept implementation, but
will integrated into pybench once it is stable enough.
License: pybench license.
Author: Marc-Andre Lemburg.
........
r46507 | armin.rigo | 2006-05-28 21:13:17 +0200 (Sun, 28 May 2006) | 15 lines
("Forward-port" of r46506)
Remove various dependencies on dictionary order in the standard library
tests, and one (clearly an oversight, potentially critical) in the
standard library itself - base64.py.
Remaining open issues:
* test_extcall is an output test, messy to make robust
* tarfile.py has a potential bug here, but I'm not familiar
enough with this code. Filed in as SF bug #1496501.
* urllib2.HTTPPasswordMgr() returns a random result if there is more
than one matching root path. I'm asking python-dev for
clarification...
........
r46508 | georg.brandl | 2006-05-28 22:11:45 +0200 (Sun, 28 May 2006) | 4 lines
The empty string is a valid import path.
(fixes #1496539)
........
r46509 | georg.brandl | 2006-05-28 22:23:12 +0200 (Sun, 28 May 2006) | 3 lines
Patch #1496206: urllib2 PasswordMgr ./. default ports
........
r46510 | georg.brandl | 2006-05-28 22:57:09 +0200 (Sun, 28 May 2006) | 3 lines
Fix refleaks in UnicodeError get and set methods.
........
r46511 | michael.hudson | 2006-05-28 23:19:03 +0200 (Sun, 28 May 2006) | 3 lines
use the UnicodeError traversal and clearing functions in UnicodeError
subclasses.
........
r46512 | thomas.wouters | 2006-05-28 23:32:12 +0200 (Sun, 28 May 2006) | 4 lines
Make last patch valid C89 so Windows compilers can deal with it.
........
r46513 | georg.brandl | 2006-05-28 23:42:54 +0200 (Sun, 28 May 2006) | 3 lines
Fix ref-antileak in _struct.c which eventually lead to deallocating None.
........
r46514 | georg.brandl | 2006-05-28 23:57:35 +0200 (Sun, 28 May 2006) | 4 lines
Correct None refcount issue in Mac modules. (Are they
still used?)
........
r46515 | armin.rigo | 2006-05-29 00:07:08 +0200 (Mon, 29 May 2006) | 3 lines
A clearer error message when passing -R to regrtest.py with
release builds of Python.
........
r46516 | georg.brandl | 2006-05-29 00:14:04 +0200 (Mon, 29 May 2006) | 3 lines
Fix C function calling conventions in _sre module.
........
r46517 | georg.brandl | 2006-05-29 00:34:51 +0200 (Mon, 29 May 2006) | 3 lines
Convert audioop over to METH_VARARGS.
........
r46518 | georg.brandl | 2006-05-29 00:38:57 +0200 (Mon, 29 May 2006) | 3 lines
METH_NOARGS functions do get called with two args.
........
r46519 | georg.brandl | 2006-05-29 11:46:51 +0200 (Mon, 29 May 2006) | 4 lines
Fix refleak in socketmodule. Replace bogus Py_BuildValue calls.
Fix refleak in exceptions.
........
r46520 | nick.coghlan | 2006-05-29 14:43:05 +0200 (Mon, 29 May 2006) | 7 lines
Apply modified version of Collin Winter's patch #1478788
Renames functional extension module to _functools and adds a Python
functools module so that utility functions like update_wrapper can be
added easily.
........
r46522 | georg.brandl | 2006-05-29 15:53:16 +0200 (Mon, 29 May 2006) | 3 lines
Convert fmmodule to METH_VARARGS.
........
r46523 | georg.brandl | 2006-05-29 16:13:21 +0200 (Mon, 29 May 2006) | 3 lines
Fix #1494605.
........
r46524 | georg.brandl | 2006-05-29 16:28:05 +0200 (Mon, 29 May 2006) | 3 lines
Handle PyMem_Malloc failure in pystrtod.c. Closes #1494671.
........
r46525 | georg.brandl | 2006-05-29 16:33:55 +0200 (Mon, 29 May 2006) | 3 lines
Fix compiler warning.
........
r46526 | georg.brandl | 2006-05-29 16:39:00 +0200 (Mon, 29 May 2006) | 3 lines
Fix #1494787 (pyclbr counts whitespace as superclass name)
........
r46527 | bob.ippolito | 2006-05-29 17:47:29 +0200 (Mon, 29 May 2006) | 1 line
simplify the struct code a bit (no functional changes)
........
r46528 | armin.rigo | 2006-05-29 19:59:47 +0200 (Mon, 29 May 2006) | 2 lines
Silence a warning.
........
r46529 | georg.brandl | 2006-05-29 21:39:45 +0200 (Mon, 29 May 2006) | 3 lines
Correct some value converting strangenesses.
........
r46530 | nick.coghlan | 2006-05-29 22:27:44 +0200 (Mon, 29 May 2006) | 1 line
When adding a module like functools, it helps to let SVN know about the file.
........
r46531 | georg.brandl | 2006-05-29 22:52:54 +0200 (Mon, 29 May 2006) | 4 lines
Patches #1497027 and #972322: try HTTP digest auth first,
and watch out for handler name collisions.
........
r46532 | georg.brandl | 2006-05-29 22:57:01 +0200 (Mon, 29 May 2006) | 3 lines
Add News entry for last commit.
........
r46533 | georg.brandl | 2006-05-29 23:04:52 +0200 (Mon, 29 May 2006) | 4 lines
Make use of METH_O and METH_NOARGS where possible.
Use Py_UnpackTuple instead of PyArg_ParseTuple where possible.
........
r46534 | georg.brandl | 2006-05-29 23:58:42 +0200 (Mon, 29 May 2006) | 3 lines
Convert more modules to METH_VARARGS.
........
r46535 | georg.brandl | 2006-05-30 00:00:30 +0200 (Tue, 30 May 2006) | 3 lines
Whoops.
........
r46536 | fredrik.lundh | 2006-05-30 00:42:07 +0200 (Tue, 30 May 2006) | 4 lines
fixed "abc".count("", 100) == -96 error (hopefully, nobody's relying on
the current behaviour ;-)
........
r46537 | bob.ippolito | 2006-05-30 00:55:48 +0200 (Tue, 30 May 2006) | 1 line
struct: modulo math plus warning on all endian-explicit formats for compatibility with older struct usage (ugly)
........
r46539 | bob.ippolito | 2006-05-30 02:26:01 +0200 (Tue, 30 May 2006) | 1 line
Add a length check to aifc to ensure it doesn't write a bogus file
........
r46540 | tim.peters | 2006-05-30 04:25:25 +0200 (Tue, 30 May 2006) | 10 lines
deprecated_err(): Stop bizarre warning messages when the tests
are run in the order:
test_genexps (or any other doctest-based test)
test_struct
test_doctest
The `warnings` module needs an advertised way to save/restore
its internal filter list.
........
r46541 | tim.peters | 2006-05-30 04:26:46 +0200 (Tue, 30 May 2006) | 2 lines
Whitespace normalization.
........
r46542 | tim.peters | 2006-05-30 04:30:30 +0200 (Tue, 30 May 2006) | 2 lines
Set a binary svn:mime-type property on this UTF-8 encoded file.
........
r46543 | neal.norwitz | 2006-05-30 05:18:50 +0200 (Tue, 30 May 2006) | 1 line
Simplify further by using AddStringConstant
........
r46544 | tim.peters | 2006-05-30 06:16:25 +0200 (Tue, 30 May 2006) | 6 lines
Convert relevant dict internals to Py_ssize_t.
I don't have a box with nearly enough RAM, or an OS,
that could get close to tickling this, though (requires
a dict w/ at least 2**31 entries).
........
r46545 | neal.norwitz | 2006-05-30 06:19:21 +0200 (Tue, 30 May 2006) | 1 line
Remove stray | in comment
........
r46546 | neal.norwitz | 2006-05-30 06:25:05 +0200 (Tue, 30 May 2006) | 1 line
Use Py_SAFE_DOWNCAST for safety. Fix format strings. Remove 2 more stray | in comment
........
r46547 | neal.norwitz | 2006-05-30 06:43:23 +0200 (Tue, 30 May 2006) | 1 line
No DOWNCAST is required since sizeof(Py_ssize_t) >= sizeof(int) and Py_ReprEntr returns an int
........
r46548 | tim.peters | 2006-05-30 07:04:59 +0200 (Tue, 30 May 2006) | 3 lines
dict_print(): Explicitly narrow the return value
from a (possibly) wider variable.
........
r46549 | tim.peters | 2006-05-30 07:23:59 +0200 (Tue, 30 May 2006) | 5 lines
dict_print(): So that Neal & I don't spend the rest of
our lives taking turns rewriting code that works ;-),
get rid of casting illusions by declaring a new variable
with the obvious type.
........
r46550 | georg.brandl | 2006-05-30 09:04:55 +0200 (Tue, 30 May 2006) | 3 lines
Restore exception pickle support. #1497319.
........
r46551 | georg.brandl | 2006-05-30 09:13:29 +0200 (Tue, 30 May 2006) | 3 lines
Add a test case for exception pickling. args is never NULL.
........
r46552 | neal.norwitz | 2006-05-30 09:21:10 +0200 (Tue, 30 May 2006) | 1 line
Don't fail if the (sub)pkgname already exist.
........
r46553 | georg.brandl | 2006-05-30 09:34:45 +0200 (Tue, 30 May 2006) | 3 lines
Disallow keyword args for exceptions.
........
r46554 | neal.norwitz | 2006-05-30 09:36:54 +0200 (Tue, 30 May 2006) | 5 lines
I'm impatient. I think this will fix a few more problems with the buildbots.
I'm not sure this is the best approach, but I can't think of anything better.
If this creates problems, feel free to revert, but I think it's safe and
should make things a little better.
........
r46555 | georg.brandl | 2006-05-30 10:17:00 +0200 (Tue, 30 May 2006) | 4 lines
Do the check for no keyword arguments in __init__ so that
subclasses of Exception can be supplied keyword args
........
r46556 | georg.brandl | 2006-05-30 10:47:19 +0200 (Tue, 30 May 2006) | 3 lines
Convert test_exceptions to unittest.
........
r46557 | andrew.kuchling | 2006-05-30 14:52:01 +0200 (Tue, 30 May 2006) | 1 line
Add SoC name, and reorganize this section a bit
........
r46559 | tim.peters | 2006-05-30 17:53:34 +0200 (Tue, 30 May 2006) | 11 lines
PyLong_FromString(): Continued fraction analysis (explained in
a new comment) suggests there are almost certainly large input
integers in all non-binary input bases for which one Python digit
too few is initally allocated to hold the final result. Instead
of assert-failing when that happens, allocate more space. Alas,
I estimate it would take a few days to find a specific such case,
so this isn't backed up by a new test (not to mention that such
a case may take hours to run, since conversion time is quadratic
in the number of digits, and preliminary attempts suggested that
the smallest such inputs contain at least a million digits).
........
r46560 | fredrik.lundh | 2006-05-30 19:11:48 +0200 (Tue, 30 May 2006) | 3 lines
changed find/rfind to return -1 for matches outside the source string
........
r46561 | bob.ippolito | 2006-05-30 19:37:54 +0200 (Tue, 30 May 2006) | 1 line
Change wrapping terminology to overflow masking
........
r46562 | fredrik.lundh | 2006-05-30 19:39:58 +0200 (Tue, 30 May 2006) | 3 lines
changed count to return 0 for slices outside the source string
........
r46568 | tim.peters | 2006-05-31 01:28:02 +0200 (Wed, 31 May 2006) | 2 lines
Whitespace normalization.
........
r46569 | brett.cannon | 2006-05-31 04:19:54 +0200 (Wed, 31 May 2006) | 5 lines
Clarify wording on default values for strptime(); defaults are used when better
values cannot be inferred.
Closes bug #1496315.
........
r46572 | neal.norwitz | 2006-05-31 09:43:27 +0200 (Wed, 31 May 2006) | 1 line
Calculate smallest properly (it was off by one) and use proper ssize_t types for Win64
........
r46573 | neal.norwitz | 2006-05-31 10:01:08 +0200 (Wed, 31 May 2006) | 1 line
Revert last checkin, it is better to do make distclean
........
r46574 | neal.norwitz | 2006-05-31 11:02:44 +0200 (Wed, 31 May 2006) | 3 lines
On 64-bit platforms running test_struct after test_tarfile would fail
since the deprecation warning wouldn't be raised.
........
r46575 | thomas.heller | 2006-05-31 13:37:58 +0200 (Wed, 31 May 2006) | 3 lines
PyTuple_Pack is not available in Python 2.3, but ctypes must stay
compatible with that.
........
r46576 | andrew.kuchling | 2006-05-31 15:18:56 +0200 (Wed, 31 May 2006) | 1 line
'functional' module was renamed to 'functools'
........
r46577 | kristjan.jonsson | 2006-05-31 15:35:41 +0200 (Wed, 31 May 2006) | 1 line
Fixup the PCBuild8 project directory. exceptions.c have moved to Objects, and the functionalmodule.c has been replaced with _functoolsmodule.c. Other minor changes to .vcproj files and .sln to fix compilation
........
r46578 | andrew.kuchling | 2006-05-31 16:08:48 +0200 (Wed, 31 May 2006) | 15 lines
[Bug #1473048]
SimpleXMLRPCServer and DocXMLRPCServer don't look at
the path of the HTTP request at all; you can POST or
GET from / or /RPC2 or /blahblahblah with the same results.
Security scanners that look for /cgi-bin/phf will therefore report
lots of vulnerabilities.
Fix: add a .rpc_paths attribute to the SimpleXMLRPCServer class,
and report a 404 error if the path isn't on the allowed list.
Possibly-controversial aspect of this change: the default makes only
'/' and '/RPC2' legal. Maybe this will break people's applications
(though I doubt it). We could just set the default to an empty tuple,
which would exactly match the current behaviour.
........
r46579 | andrew.kuchling | 2006-05-31 16:12:47 +0200 (Wed, 31 May 2006) | 1 line
Mention SimpleXMLRPCServer change
........
r46580 | tim.peters | 2006-05-31 16:28:07 +0200 (Wed, 31 May 2006) | 2 lines
Trimmed trailing whitespace.
........
r46581 | tim.peters | 2006-05-31 17:33:22 +0200 (Wed, 31 May 2006) | 4 lines
_range_error(): Speed and simplify (there's no real need for
loops here). Assert that size_t is actually big enough, and
that f->size is at least one. Wrap a long line.
........
r46582 | tim.peters | 2006-05-31 17:34:37 +0200 (Wed, 31 May 2006) | 2 lines
Repaired error in new comment.
........
r46584 | neal.norwitz | 2006-06-01 07:32:49 +0200 (Thu, 01 Jun 2006) | 4 lines
Remove ; at end of macro. There was a compiler recently that warned
about extra semi-colons. It may have been the HP C compiler.
This file will trigger a bunch of those warnings now.
........
r46585 | georg.brandl | 2006-06-01 08:39:19 +0200 (Thu, 01 Jun 2006) | 3 lines
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
........
r46586 | georg.brandl | 2006-06-01 10:27:32 +0200 (Thu, 01 Jun 2006) | 3 lines
Correctly allocate complex types with tp_alloc. (bug #1498638)
........
r46587 | georg.brandl | 2006-06-01 14:30:46 +0200 (Thu, 01 Jun 2006) | 2 lines
Correctly dispatch Faults in loads (patch #1498627)
........
r46588 | georg.brandl | 2006-06-01 15:00:49 +0200 (Thu, 01 Jun 2006) | 3 lines
Some code style tweaks, and remove apply.
........
r46589 | armin.rigo | 2006-06-01 15:19:12 +0200 (Thu, 01 Jun 2006) | 5 lines
[ 1497053 ] Let dicts propagate the exceptions in user __eq__().
[ 1456209 ] dictresize() vulnerability ( <- backport candidate ).
........
r46590 | tim.peters | 2006-06-01 15:41:46 +0200 (Thu, 01 Jun 2006) | 2 lines
Whitespace normalization.
........
r46591 | tim.peters | 2006-06-01 15:49:23 +0200 (Thu, 01 Jun 2006) | 2 lines
Record bugs 1275608 and 1456209 as being fixed.
........
r46592 | tim.peters | 2006-06-01 15:56:26 +0200 (Thu, 01 Jun 2006) | 5 lines
Re-enable a new empty-string test added during the NFS sprint,
but disabled then because str and unicode strings gave different
results. The implementations were repaired later during the
sprint, but the new test remained disabled.
........
r46594 | tim.peters | 2006-06-01 17:50:44 +0200 (Thu, 01 Jun 2006) | 7 lines
Armin committed his patch while I was reviewing it (I'm sure
he didn't know this), so merged in some changes I made during
review. Nothing material apart from changing a new `mask` local
from int to Py_ssize_t. Mostly this is repairing comments that
were made incorrect, and adding new comments. Also a few
minor code rewrites for clarity or helpful succinctness.
........
r46599 | neal.norwitz | 2006-06-02 06:45:53 +0200 (Fri, 02 Jun 2006) | 1 line
Convert docstrings to comments so regrtest -v prints method names
........
r46600 | neal.norwitz | 2006-06-02 06:50:49 +0200 (Fri, 02 Jun 2006) | 2 lines
Fix memory leak found by valgrind.
........
r46601 | neal.norwitz | 2006-06-02 06:54:52 +0200 (Fri, 02 Jun 2006) | 1 line
More memory leaks from valgrind
........
r46602 | neal.norwitz | 2006-06-02 08:23:00 +0200 (Fri, 02 Jun 2006) | 11 lines
Patch #1357836:
Prevent an invalid memory read from test_coding in case the done flag is set.
In that case, the loop isn't entered. I wonder if rather than setting
the done flag in the cases before the loop, if they should just exit early.
This code looks like it should be refactored.
Backport candidate (also the early break above if decoding_fgets fails)
........
r46603 | martin.blais | 2006-06-02 15:03:43 +0200 (Fri, 02 Jun 2006) | 1 line
Fixed struct test to not use unittest.
........
r46605 | tim.peters | 2006-06-03 01:22:51 +0200 (Sat, 03 Jun 2006) | 10 lines
pprint functions used to sort a dict (by key) if and only if
the output required more than one line. "Small" dicts got
displayed in seemingly random order (the hash-induced order
produced by dict.__repr__). None of this was documented.
Now pprint functions always sort dicts by key, and the docs
promise it.
This was proposed and agreed to during the PyCon 2006 core
sprint -- I just didn't have time for it before now.
........
2006-06-08 11:42:34 -03:00
|
|
|
EVP_digest(EVPobject *self, PyObject *unused)
|
2005-08-21 15:45:59 -03:00
|
|
|
{
|
|
|
|
unsigned char digest[EVP_MAX_MD_SIZE];
|
2016-09-05 18:19:05 -03:00
|
|
|
EVP_MD_CTX *temp_ctx;
|
2005-08-21 15:45:59 -03:00
|
|
|
PyObject *retval;
|
|
|
|
unsigned int digest_size;
|
|
|
|
|
2016-09-05 18:19:05 -03:00
|
|
|
temp_ctx = EVP_MD_CTX_new();
|
|
|
|
if (temp_ctx == NULL) {
|
|
|
|
PyErr_NoMemory();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!locked_EVP_MD_CTX_copy(temp_ctx, self)) {
|
|
|
|
return _setException(PyExc_ValueError);
|
|
|
|
}
|
|
|
|
digest_size = EVP_MD_CTX_size(temp_ctx);
|
2017-05-24 04:04:38 -03:00
|
|
|
if (!EVP_DigestFinal(temp_ctx, digest, NULL)) {
|
|
|
|
_setException(PyExc_ValueError);
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-08-21 15:45:59 -03:00
|
|
|
|
2008-05-26 10:28:38 -03:00
|
|
|
retval = PyBytes_FromStringAndSize((const char *)digest, digest_size);
|
2016-09-05 18:19:05 -03:00
|
|
|
EVP_MD_CTX_free(temp_ctx);
|
2005-08-21 15:45:59 -03:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(EVP_hexdigest__doc__,
|
|
|
|
"Return the digest value as a string of hexadecimal digits.");
|
|
|
|
|
|
|
|
static PyObject *
|
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
merge in bad ways, so I'll have to merge that extra-carefully (probably manually.)
Merged revisions 46495-46605 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r46495 | tim.peters | 2006-05-28 03:52:38 +0200 (Sun, 28 May 2006) | 2 lines
Added missing svn:eol-style property to text files.
........
r46497 | tim.peters | 2006-05-28 12:41:29 +0200 (Sun, 28 May 2006) | 3 lines
PyErr_Display(), PyErr_WriteUnraisable(): Coverity found a cut-and-paste
bug in both: `className` was referenced before being checked for NULL.
........
r46499 | fredrik.lundh | 2006-05-28 14:06:46 +0200 (Sun, 28 May 2006) | 5 lines
needforspeed: added Py_MEMCPY macro (currently tuned for Visual C only),
and use it for string copy operations. this gives a 20% speedup on some
string benchmarks.
........
r46501 | michael.hudson | 2006-05-28 17:51:40 +0200 (Sun, 28 May 2006) | 26 lines
Quality control, meet exceptions.c.
Fix a number of problems with the need for speed code:
One is doing this sort of thing:
Py_DECREF(self->field);
self->field = newval;
Py_INCREF(self->field);
without being very sure that self->field doesn't start with a
value that has a __del__, because that almost certainly can lead
to segfaults.
As self->args is constrained to be an exact tuple we may as well
exploit this fact consistently. This leads to quite a lot of
simplification (and, hey, probably better performance).
Add some error checking in places lacking it.
Fix some rather strange indentation in the Unicode code.
Delete some trailing whitespace.
More to come, I haven't fixed all the reference leaks yet...
........
r46502 | george.yoshida | 2006-05-28 18:39:09 +0200 (Sun, 28 May 2006) | 3 lines
Patch #1080727: add "encoding" parameter to doctest.DocFileSuite
Contributed by Bjorn Tillenius.
........
r46503 | martin.v.loewis | 2006-05-28 18:57:38 +0200 (Sun, 28 May 2006) | 4 lines
Rest of patch #1490384: Commit icon source, remove
claim that Erik von Blokland is the author of the
installer picture.
........
r46504 | michael.hudson | 2006-05-28 19:40:29 +0200 (Sun, 28 May 2006) | 16 lines
Quality control, meet exceptions.c, round two.
Make some functions that should have been static static.
Fix a bunch of refleaks by fixing the definition of
MiddlingExtendsException.
Remove all the __new__ implementations apart from
BaseException_new. Rewrite most code that needs it to cope with
NULL fields (such code could get excercised anyway, the
__new__-removal just makes it more likely). This involved
editing the code for WindowsError, which I can't test.
This fixes all the refleaks in at least the start of a regrtest
-R :: run.
........
r46505 | marc-andre.lemburg | 2006-05-28 19:46:58 +0200 (Sun, 28 May 2006) | 10 lines
Initial version of systimes - a module to provide platform dependent
performance measurements.
The module is currently just a proof-of-concept implementation, but
will integrated into pybench once it is stable enough.
License: pybench license.
Author: Marc-Andre Lemburg.
........
r46507 | armin.rigo | 2006-05-28 21:13:17 +0200 (Sun, 28 May 2006) | 15 lines
("Forward-port" of r46506)
Remove various dependencies on dictionary order in the standard library
tests, and one (clearly an oversight, potentially critical) in the
standard library itself - base64.py.
Remaining open issues:
* test_extcall is an output test, messy to make robust
* tarfile.py has a potential bug here, but I'm not familiar
enough with this code. Filed in as SF bug #1496501.
* urllib2.HTTPPasswordMgr() returns a random result if there is more
than one matching root path. I'm asking python-dev for
clarification...
........
r46508 | georg.brandl | 2006-05-28 22:11:45 +0200 (Sun, 28 May 2006) | 4 lines
The empty string is a valid import path.
(fixes #1496539)
........
r46509 | georg.brandl | 2006-05-28 22:23:12 +0200 (Sun, 28 May 2006) | 3 lines
Patch #1496206: urllib2 PasswordMgr ./. default ports
........
r46510 | georg.brandl | 2006-05-28 22:57:09 +0200 (Sun, 28 May 2006) | 3 lines
Fix refleaks in UnicodeError get and set methods.
........
r46511 | michael.hudson | 2006-05-28 23:19:03 +0200 (Sun, 28 May 2006) | 3 lines
use the UnicodeError traversal and clearing functions in UnicodeError
subclasses.
........
r46512 | thomas.wouters | 2006-05-28 23:32:12 +0200 (Sun, 28 May 2006) | 4 lines
Make last patch valid C89 so Windows compilers can deal with it.
........
r46513 | georg.brandl | 2006-05-28 23:42:54 +0200 (Sun, 28 May 2006) | 3 lines
Fix ref-antileak in _struct.c which eventually lead to deallocating None.
........
r46514 | georg.brandl | 2006-05-28 23:57:35 +0200 (Sun, 28 May 2006) | 4 lines
Correct None refcount issue in Mac modules. (Are they
still used?)
........
r46515 | armin.rigo | 2006-05-29 00:07:08 +0200 (Mon, 29 May 2006) | 3 lines
A clearer error message when passing -R to regrtest.py with
release builds of Python.
........
r46516 | georg.brandl | 2006-05-29 00:14:04 +0200 (Mon, 29 May 2006) | 3 lines
Fix C function calling conventions in _sre module.
........
r46517 | georg.brandl | 2006-05-29 00:34:51 +0200 (Mon, 29 May 2006) | 3 lines
Convert audioop over to METH_VARARGS.
........
r46518 | georg.brandl | 2006-05-29 00:38:57 +0200 (Mon, 29 May 2006) | 3 lines
METH_NOARGS functions do get called with two args.
........
r46519 | georg.brandl | 2006-05-29 11:46:51 +0200 (Mon, 29 May 2006) | 4 lines
Fix refleak in socketmodule. Replace bogus Py_BuildValue calls.
Fix refleak in exceptions.
........
r46520 | nick.coghlan | 2006-05-29 14:43:05 +0200 (Mon, 29 May 2006) | 7 lines
Apply modified version of Collin Winter's patch #1478788
Renames functional extension module to _functools and adds a Python
functools module so that utility functions like update_wrapper can be
added easily.
........
r46522 | georg.brandl | 2006-05-29 15:53:16 +0200 (Mon, 29 May 2006) | 3 lines
Convert fmmodule to METH_VARARGS.
........
r46523 | georg.brandl | 2006-05-29 16:13:21 +0200 (Mon, 29 May 2006) | 3 lines
Fix #1494605.
........
r46524 | georg.brandl | 2006-05-29 16:28:05 +0200 (Mon, 29 May 2006) | 3 lines
Handle PyMem_Malloc failure in pystrtod.c. Closes #1494671.
........
r46525 | georg.brandl | 2006-05-29 16:33:55 +0200 (Mon, 29 May 2006) | 3 lines
Fix compiler warning.
........
r46526 | georg.brandl | 2006-05-29 16:39:00 +0200 (Mon, 29 May 2006) | 3 lines
Fix #1494787 (pyclbr counts whitespace as superclass name)
........
r46527 | bob.ippolito | 2006-05-29 17:47:29 +0200 (Mon, 29 May 2006) | 1 line
simplify the struct code a bit (no functional changes)
........
r46528 | armin.rigo | 2006-05-29 19:59:47 +0200 (Mon, 29 May 2006) | 2 lines
Silence a warning.
........
r46529 | georg.brandl | 2006-05-29 21:39:45 +0200 (Mon, 29 May 2006) | 3 lines
Correct some value converting strangenesses.
........
r46530 | nick.coghlan | 2006-05-29 22:27:44 +0200 (Mon, 29 May 2006) | 1 line
When adding a module like functools, it helps to let SVN know about the file.
........
r46531 | georg.brandl | 2006-05-29 22:52:54 +0200 (Mon, 29 May 2006) | 4 lines
Patches #1497027 and #972322: try HTTP digest auth first,
and watch out for handler name collisions.
........
r46532 | georg.brandl | 2006-05-29 22:57:01 +0200 (Mon, 29 May 2006) | 3 lines
Add News entry for last commit.
........
r46533 | georg.brandl | 2006-05-29 23:04:52 +0200 (Mon, 29 May 2006) | 4 lines
Make use of METH_O and METH_NOARGS where possible.
Use Py_UnpackTuple instead of PyArg_ParseTuple where possible.
........
r46534 | georg.brandl | 2006-05-29 23:58:42 +0200 (Mon, 29 May 2006) | 3 lines
Convert more modules to METH_VARARGS.
........
r46535 | georg.brandl | 2006-05-30 00:00:30 +0200 (Tue, 30 May 2006) | 3 lines
Whoops.
........
r46536 | fredrik.lundh | 2006-05-30 00:42:07 +0200 (Tue, 30 May 2006) | 4 lines
fixed "abc".count("", 100) == -96 error (hopefully, nobody's relying on
the current behaviour ;-)
........
r46537 | bob.ippolito | 2006-05-30 00:55:48 +0200 (Tue, 30 May 2006) | 1 line
struct: modulo math plus warning on all endian-explicit formats for compatibility with older struct usage (ugly)
........
r46539 | bob.ippolito | 2006-05-30 02:26:01 +0200 (Tue, 30 May 2006) | 1 line
Add a length check to aifc to ensure it doesn't write a bogus file
........
r46540 | tim.peters | 2006-05-30 04:25:25 +0200 (Tue, 30 May 2006) | 10 lines
deprecated_err(): Stop bizarre warning messages when the tests
are run in the order:
test_genexps (or any other doctest-based test)
test_struct
test_doctest
The `warnings` module needs an advertised way to save/restore
its internal filter list.
........
r46541 | tim.peters | 2006-05-30 04:26:46 +0200 (Tue, 30 May 2006) | 2 lines
Whitespace normalization.
........
r46542 | tim.peters | 2006-05-30 04:30:30 +0200 (Tue, 30 May 2006) | 2 lines
Set a binary svn:mime-type property on this UTF-8 encoded file.
........
r46543 | neal.norwitz | 2006-05-30 05:18:50 +0200 (Tue, 30 May 2006) | 1 line
Simplify further by using AddStringConstant
........
r46544 | tim.peters | 2006-05-30 06:16:25 +0200 (Tue, 30 May 2006) | 6 lines
Convert relevant dict internals to Py_ssize_t.
I don't have a box with nearly enough RAM, or an OS,
that could get close to tickling this, though (requires
a dict w/ at least 2**31 entries).
........
r46545 | neal.norwitz | 2006-05-30 06:19:21 +0200 (Tue, 30 May 2006) | 1 line
Remove stray | in comment
........
r46546 | neal.norwitz | 2006-05-30 06:25:05 +0200 (Tue, 30 May 2006) | 1 line
Use Py_SAFE_DOWNCAST for safety. Fix format strings. Remove 2 more stray | in comment
........
r46547 | neal.norwitz | 2006-05-30 06:43:23 +0200 (Tue, 30 May 2006) | 1 line
No DOWNCAST is required since sizeof(Py_ssize_t) >= sizeof(int) and Py_ReprEntr returns an int
........
r46548 | tim.peters | 2006-05-30 07:04:59 +0200 (Tue, 30 May 2006) | 3 lines
dict_print(): Explicitly narrow the return value
from a (possibly) wider variable.
........
r46549 | tim.peters | 2006-05-30 07:23:59 +0200 (Tue, 30 May 2006) | 5 lines
dict_print(): So that Neal & I don't spend the rest of
our lives taking turns rewriting code that works ;-),
get rid of casting illusions by declaring a new variable
with the obvious type.
........
r46550 | georg.brandl | 2006-05-30 09:04:55 +0200 (Tue, 30 May 2006) | 3 lines
Restore exception pickle support. #1497319.
........
r46551 | georg.brandl | 2006-05-30 09:13:29 +0200 (Tue, 30 May 2006) | 3 lines
Add a test case for exception pickling. args is never NULL.
........
r46552 | neal.norwitz | 2006-05-30 09:21:10 +0200 (Tue, 30 May 2006) | 1 line
Don't fail if the (sub)pkgname already exist.
........
r46553 | georg.brandl | 2006-05-30 09:34:45 +0200 (Tue, 30 May 2006) | 3 lines
Disallow keyword args for exceptions.
........
r46554 | neal.norwitz | 2006-05-30 09:36:54 +0200 (Tue, 30 May 2006) | 5 lines
I'm impatient. I think this will fix a few more problems with the buildbots.
I'm not sure this is the best approach, but I can't think of anything better.
If this creates problems, feel free to revert, but I think it's safe and
should make things a little better.
........
r46555 | georg.brandl | 2006-05-30 10:17:00 +0200 (Tue, 30 May 2006) | 4 lines
Do the check for no keyword arguments in __init__ so that
subclasses of Exception can be supplied keyword args
........
r46556 | georg.brandl | 2006-05-30 10:47:19 +0200 (Tue, 30 May 2006) | 3 lines
Convert test_exceptions to unittest.
........
r46557 | andrew.kuchling | 2006-05-30 14:52:01 +0200 (Tue, 30 May 2006) | 1 line
Add SoC name, and reorganize this section a bit
........
r46559 | tim.peters | 2006-05-30 17:53:34 +0200 (Tue, 30 May 2006) | 11 lines
PyLong_FromString(): Continued fraction analysis (explained in
a new comment) suggests there are almost certainly large input
integers in all non-binary input bases for which one Python digit
too few is initally allocated to hold the final result. Instead
of assert-failing when that happens, allocate more space. Alas,
I estimate it would take a few days to find a specific such case,
so this isn't backed up by a new test (not to mention that such
a case may take hours to run, since conversion time is quadratic
in the number of digits, and preliminary attempts suggested that
the smallest such inputs contain at least a million digits).
........
r46560 | fredrik.lundh | 2006-05-30 19:11:48 +0200 (Tue, 30 May 2006) | 3 lines
changed find/rfind to return -1 for matches outside the source string
........
r46561 | bob.ippolito | 2006-05-30 19:37:54 +0200 (Tue, 30 May 2006) | 1 line
Change wrapping terminology to overflow masking
........
r46562 | fredrik.lundh | 2006-05-30 19:39:58 +0200 (Tue, 30 May 2006) | 3 lines
changed count to return 0 for slices outside the source string
........
r46568 | tim.peters | 2006-05-31 01:28:02 +0200 (Wed, 31 May 2006) | 2 lines
Whitespace normalization.
........
r46569 | brett.cannon | 2006-05-31 04:19:54 +0200 (Wed, 31 May 2006) | 5 lines
Clarify wording on default values for strptime(); defaults are used when better
values cannot be inferred.
Closes bug #1496315.
........
r46572 | neal.norwitz | 2006-05-31 09:43:27 +0200 (Wed, 31 May 2006) | 1 line
Calculate smallest properly (it was off by one) and use proper ssize_t types for Win64
........
r46573 | neal.norwitz | 2006-05-31 10:01:08 +0200 (Wed, 31 May 2006) | 1 line
Revert last checkin, it is better to do make distclean
........
r46574 | neal.norwitz | 2006-05-31 11:02:44 +0200 (Wed, 31 May 2006) | 3 lines
On 64-bit platforms running test_struct after test_tarfile would fail
since the deprecation warning wouldn't be raised.
........
r46575 | thomas.heller | 2006-05-31 13:37:58 +0200 (Wed, 31 May 2006) | 3 lines
PyTuple_Pack is not available in Python 2.3, but ctypes must stay
compatible with that.
........
r46576 | andrew.kuchling | 2006-05-31 15:18:56 +0200 (Wed, 31 May 2006) | 1 line
'functional' module was renamed to 'functools'
........
r46577 | kristjan.jonsson | 2006-05-31 15:35:41 +0200 (Wed, 31 May 2006) | 1 line
Fixup the PCBuild8 project directory. exceptions.c have moved to Objects, and the functionalmodule.c has been replaced with _functoolsmodule.c. Other minor changes to .vcproj files and .sln to fix compilation
........
r46578 | andrew.kuchling | 2006-05-31 16:08:48 +0200 (Wed, 31 May 2006) | 15 lines
[Bug #1473048]
SimpleXMLRPCServer and DocXMLRPCServer don't look at
the path of the HTTP request at all; you can POST or
GET from / or /RPC2 or /blahblahblah with the same results.
Security scanners that look for /cgi-bin/phf will therefore report
lots of vulnerabilities.
Fix: add a .rpc_paths attribute to the SimpleXMLRPCServer class,
and report a 404 error if the path isn't on the allowed list.
Possibly-controversial aspect of this change: the default makes only
'/' and '/RPC2' legal. Maybe this will break people's applications
(though I doubt it). We could just set the default to an empty tuple,
which would exactly match the current behaviour.
........
r46579 | andrew.kuchling | 2006-05-31 16:12:47 +0200 (Wed, 31 May 2006) | 1 line
Mention SimpleXMLRPCServer change
........
r46580 | tim.peters | 2006-05-31 16:28:07 +0200 (Wed, 31 May 2006) | 2 lines
Trimmed trailing whitespace.
........
r46581 | tim.peters | 2006-05-31 17:33:22 +0200 (Wed, 31 May 2006) | 4 lines
_range_error(): Speed and simplify (there's no real need for
loops here). Assert that size_t is actually big enough, and
that f->size is at least one. Wrap a long line.
........
r46582 | tim.peters | 2006-05-31 17:34:37 +0200 (Wed, 31 May 2006) | 2 lines
Repaired error in new comment.
........
r46584 | neal.norwitz | 2006-06-01 07:32:49 +0200 (Thu, 01 Jun 2006) | 4 lines
Remove ; at end of macro. There was a compiler recently that warned
about extra semi-colons. It may have been the HP C compiler.
This file will trigger a bunch of those warnings now.
........
r46585 | georg.brandl | 2006-06-01 08:39:19 +0200 (Thu, 01 Jun 2006) | 3 lines
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
........
r46586 | georg.brandl | 2006-06-01 10:27:32 +0200 (Thu, 01 Jun 2006) | 3 lines
Correctly allocate complex types with tp_alloc. (bug #1498638)
........
r46587 | georg.brandl | 2006-06-01 14:30:46 +0200 (Thu, 01 Jun 2006) | 2 lines
Correctly dispatch Faults in loads (patch #1498627)
........
r46588 | georg.brandl | 2006-06-01 15:00:49 +0200 (Thu, 01 Jun 2006) | 3 lines
Some code style tweaks, and remove apply.
........
r46589 | armin.rigo | 2006-06-01 15:19:12 +0200 (Thu, 01 Jun 2006) | 5 lines
[ 1497053 ] Let dicts propagate the exceptions in user __eq__().
[ 1456209 ] dictresize() vulnerability ( <- backport candidate ).
........
r46590 | tim.peters | 2006-06-01 15:41:46 +0200 (Thu, 01 Jun 2006) | 2 lines
Whitespace normalization.
........
r46591 | tim.peters | 2006-06-01 15:49:23 +0200 (Thu, 01 Jun 2006) | 2 lines
Record bugs 1275608 and 1456209 as being fixed.
........
r46592 | tim.peters | 2006-06-01 15:56:26 +0200 (Thu, 01 Jun 2006) | 5 lines
Re-enable a new empty-string test added during the NFS sprint,
but disabled then because str and unicode strings gave different
results. The implementations were repaired later during the
sprint, but the new test remained disabled.
........
r46594 | tim.peters | 2006-06-01 17:50:44 +0200 (Thu, 01 Jun 2006) | 7 lines
Armin committed his patch while I was reviewing it (I'm sure
he didn't know this), so merged in some changes I made during
review. Nothing material apart from changing a new `mask` local
from int to Py_ssize_t. Mostly this is repairing comments that
were made incorrect, and adding new comments. Also a few
minor code rewrites for clarity or helpful succinctness.
........
r46599 | neal.norwitz | 2006-06-02 06:45:53 +0200 (Fri, 02 Jun 2006) | 1 line
Convert docstrings to comments so regrtest -v prints method names
........
r46600 | neal.norwitz | 2006-06-02 06:50:49 +0200 (Fri, 02 Jun 2006) | 2 lines
Fix memory leak found by valgrind.
........
r46601 | neal.norwitz | 2006-06-02 06:54:52 +0200 (Fri, 02 Jun 2006) | 1 line
More memory leaks from valgrind
........
r46602 | neal.norwitz | 2006-06-02 08:23:00 +0200 (Fri, 02 Jun 2006) | 11 lines
Patch #1357836:
Prevent an invalid memory read from test_coding in case the done flag is set.
In that case, the loop isn't entered. I wonder if rather than setting
the done flag in the cases before the loop, if they should just exit early.
This code looks like it should be refactored.
Backport candidate (also the early break above if decoding_fgets fails)
........
r46603 | martin.blais | 2006-06-02 15:03:43 +0200 (Fri, 02 Jun 2006) | 1 line
Fixed struct test to not use unittest.
........
r46605 | tim.peters | 2006-06-03 01:22:51 +0200 (Sat, 03 Jun 2006) | 10 lines
pprint functions used to sort a dict (by key) if and only if
the output required more than one line. "Small" dicts got
displayed in seemingly random order (the hash-induced order
produced by dict.__repr__). None of this was documented.
Now pprint functions always sort dicts by key, and the docs
promise it.
This was proposed and agreed to during the PyCon 2006 core
sprint -- I just didn't have time for it before now.
........
2006-06-08 11:42:34 -03:00
|
|
|
EVP_hexdigest(EVPobject *self, PyObject *unused)
|
2005-08-21 15:45:59 -03:00
|
|
|
{
|
|
|
|
unsigned char digest[EVP_MAX_MD_SIZE];
|
2016-09-05 18:19:05 -03:00
|
|
|
EVP_MD_CTX *temp_ctx;
|
2015-04-25 20:42:38 -03:00
|
|
|
unsigned int digest_size;
|
2005-08-21 15:45:59 -03:00
|
|
|
|
2016-09-05 18:19:05 -03:00
|
|
|
temp_ctx = EVP_MD_CTX_new();
|
|
|
|
if (temp_ctx == NULL) {
|
|
|
|
PyErr_NoMemory();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-08-21 15:45:59 -03:00
|
|
|
/* Get the raw (binary) digest value */
|
2016-09-05 18:19:05 -03:00
|
|
|
if (!locked_EVP_MD_CTX_copy(temp_ctx, self)) {
|
|
|
|
return _setException(PyExc_ValueError);
|
|
|
|
}
|
|
|
|
digest_size = EVP_MD_CTX_size(temp_ctx);
|
2017-05-24 04:04:38 -03:00
|
|
|
if (!EVP_DigestFinal(temp_ctx, digest, NULL)) {
|
|
|
|
_setException(PyExc_ValueError);
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-08-21 15:45:59 -03:00
|
|
|
|
2016-09-05 18:19:05 -03:00
|
|
|
EVP_MD_CTX_free(temp_ctx);
|
2005-08-21 15:45:59 -03:00
|
|
|
|
2015-04-25 20:42:38 -03:00
|
|
|
return _Py_strhex((const char *)digest, digest_size);
|
2005-08-21 15:45:59 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(EVP_update__doc__,
|
|
|
|
"Update this hash object's state with the provided string.");
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
EVP_update(EVPobject *self, PyObject *args)
|
|
|
|
{
|
2007-08-25 23:58:36 -03:00
|
|
|
PyObject *obj;
|
2007-09-22 23:00:13 -03:00
|
|
|
Py_buffer view;
|
2005-08-21 15:45:59 -03:00
|
|
|
|
2007-08-25 23:58:36 -03:00
|
|
|
if (!PyArg_ParseTuple(args, "O:update", &obj))
|
2005-08-21 15:45:59 -03:00
|
|
|
return NULL;
|
|
|
|
|
2009-02-12 03:35:29 -04:00
|
|
|
GET_BUFFER_VIEW_OR_ERROUT(obj, &view);
|
2009-01-08 17:17:16 -04:00
|
|
|
|
|
|
|
if (self->lock == NULL && view.len >= HASHLIB_GIL_MINSIZE) {
|
|
|
|
self->lock = PyThread_allocate_lock();
|
2009-05-03 21:45:33 -03:00
|
|
|
/* fail? lock = NULL and we fail over to non-threaded code. */
|
2008-09-24 19:53:33 -03:00
|
|
|
}
|
2005-08-21 15:45:59 -03:00
|
|
|
|
2009-01-08 17:17:16 -04:00
|
|
|
if (self->lock != NULL) {
|
|
|
|
Py_BEGIN_ALLOW_THREADS
|
|
|
|
PyThread_acquire_lock(self->lock, 1);
|
|
|
|
EVP_hash(self, view.buf, view.len);
|
|
|
|
PyThread_release_lock(self->lock);
|
|
|
|
Py_END_ALLOW_THREADS
|
|
|
|
} else {
|
|
|
|
EVP_hash(self, view.buf, view.len);
|
|
|
|
}
|
|
|
|
|
|
|
|
PyBuffer_Release(&view);
|
|
|
|
Py_RETURN_NONE;
|
2005-08-21 15:45:59 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyMethodDef EVP_methods[] = {
|
2009-01-08 17:17:16 -04:00
|
|
|
{"update", (PyCFunction)EVP_update, METH_VARARGS, EVP_update__doc__},
|
|
|
|
{"digest", (PyCFunction)EVP_digest, METH_NOARGS, EVP_digest__doc__},
|
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
merge in bad ways, so I'll have to merge that extra-carefully (probably manually.)
Merged revisions 46495-46605 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r46495 | tim.peters | 2006-05-28 03:52:38 +0200 (Sun, 28 May 2006) | 2 lines
Added missing svn:eol-style property to text files.
........
r46497 | tim.peters | 2006-05-28 12:41:29 +0200 (Sun, 28 May 2006) | 3 lines
PyErr_Display(), PyErr_WriteUnraisable(): Coverity found a cut-and-paste
bug in both: `className` was referenced before being checked for NULL.
........
r46499 | fredrik.lundh | 2006-05-28 14:06:46 +0200 (Sun, 28 May 2006) | 5 lines
needforspeed: added Py_MEMCPY macro (currently tuned for Visual C only),
and use it for string copy operations. this gives a 20% speedup on some
string benchmarks.
........
r46501 | michael.hudson | 2006-05-28 17:51:40 +0200 (Sun, 28 May 2006) | 26 lines
Quality control, meet exceptions.c.
Fix a number of problems with the need for speed code:
One is doing this sort of thing:
Py_DECREF(self->field);
self->field = newval;
Py_INCREF(self->field);
without being very sure that self->field doesn't start with a
value that has a __del__, because that almost certainly can lead
to segfaults.
As self->args is constrained to be an exact tuple we may as well
exploit this fact consistently. This leads to quite a lot of
simplification (and, hey, probably better performance).
Add some error checking in places lacking it.
Fix some rather strange indentation in the Unicode code.
Delete some trailing whitespace.
More to come, I haven't fixed all the reference leaks yet...
........
r46502 | george.yoshida | 2006-05-28 18:39:09 +0200 (Sun, 28 May 2006) | 3 lines
Patch #1080727: add "encoding" parameter to doctest.DocFileSuite
Contributed by Bjorn Tillenius.
........
r46503 | martin.v.loewis | 2006-05-28 18:57:38 +0200 (Sun, 28 May 2006) | 4 lines
Rest of patch #1490384: Commit icon source, remove
claim that Erik von Blokland is the author of the
installer picture.
........
r46504 | michael.hudson | 2006-05-28 19:40:29 +0200 (Sun, 28 May 2006) | 16 lines
Quality control, meet exceptions.c, round two.
Make some functions that should have been static static.
Fix a bunch of refleaks by fixing the definition of
MiddlingExtendsException.
Remove all the __new__ implementations apart from
BaseException_new. Rewrite most code that needs it to cope with
NULL fields (such code could get excercised anyway, the
__new__-removal just makes it more likely). This involved
editing the code for WindowsError, which I can't test.
This fixes all the refleaks in at least the start of a regrtest
-R :: run.
........
r46505 | marc-andre.lemburg | 2006-05-28 19:46:58 +0200 (Sun, 28 May 2006) | 10 lines
Initial version of systimes - a module to provide platform dependent
performance measurements.
The module is currently just a proof-of-concept implementation, but
will integrated into pybench once it is stable enough.
License: pybench license.
Author: Marc-Andre Lemburg.
........
r46507 | armin.rigo | 2006-05-28 21:13:17 +0200 (Sun, 28 May 2006) | 15 lines
("Forward-port" of r46506)
Remove various dependencies on dictionary order in the standard library
tests, and one (clearly an oversight, potentially critical) in the
standard library itself - base64.py.
Remaining open issues:
* test_extcall is an output test, messy to make robust
* tarfile.py has a potential bug here, but I'm not familiar
enough with this code. Filed in as SF bug #1496501.
* urllib2.HTTPPasswordMgr() returns a random result if there is more
than one matching root path. I'm asking python-dev for
clarification...
........
r46508 | georg.brandl | 2006-05-28 22:11:45 +0200 (Sun, 28 May 2006) | 4 lines
The empty string is a valid import path.
(fixes #1496539)
........
r46509 | georg.brandl | 2006-05-28 22:23:12 +0200 (Sun, 28 May 2006) | 3 lines
Patch #1496206: urllib2 PasswordMgr ./. default ports
........
r46510 | georg.brandl | 2006-05-28 22:57:09 +0200 (Sun, 28 May 2006) | 3 lines
Fix refleaks in UnicodeError get and set methods.
........
r46511 | michael.hudson | 2006-05-28 23:19:03 +0200 (Sun, 28 May 2006) | 3 lines
use the UnicodeError traversal and clearing functions in UnicodeError
subclasses.
........
r46512 | thomas.wouters | 2006-05-28 23:32:12 +0200 (Sun, 28 May 2006) | 4 lines
Make last patch valid C89 so Windows compilers can deal with it.
........
r46513 | georg.brandl | 2006-05-28 23:42:54 +0200 (Sun, 28 May 2006) | 3 lines
Fix ref-antileak in _struct.c which eventually lead to deallocating None.
........
r46514 | georg.brandl | 2006-05-28 23:57:35 +0200 (Sun, 28 May 2006) | 4 lines
Correct None refcount issue in Mac modules. (Are they
still used?)
........
r46515 | armin.rigo | 2006-05-29 00:07:08 +0200 (Mon, 29 May 2006) | 3 lines
A clearer error message when passing -R to regrtest.py with
release builds of Python.
........
r46516 | georg.brandl | 2006-05-29 00:14:04 +0200 (Mon, 29 May 2006) | 3 lines
Fix C function calling conventions in _sre module.
........
r46517 | georg.brandl | 2006-05-29 00:34:51 +0200 (Mon, 29 May 2006) | 3 lines
Convert audioop over to METH_VARARGS.
........
r46518 | georg.brandl | 2006-05-29 00:38:57 +0200 (Mon, 29 May 2006) | 3 lines
METH_NOARGS functions do get called with two args.
........
r46519 | georg.brandl | 2006-05-29 11:46:51 +0200 (Mon, 29 May 2006) | 4 lines
Fix refleak in socketmodule. Replace bogus Py_BuildValue calls.
Fix refleak in exceptions.
........
r46520 | nick.coghlan | 2006-05-29 14:43:05 +0200 (Mon, 29 May 2006) | 7 lines
Apply modified version of Collin Winter's patch #1478788
Renames functional extension module to _functools and adds a Python
functools module so that utility functions like update_wrapper can be
added easily.
........
r46522 | georg.brandl | 2006-05-29 15:53:16 +0200 (Mon, 29 May 2006) | 3 lines
Convert fmmodule to METH_VARARGS.
........
r46523 | georg.brandl | 2006-05-29 16:13:21 +0200 (Mon, 29 May 2006) | 3 lines
Fix #1494605.
........
r46524 | georg.brandl | 2006-05-29 16:28:05 +0200 (Mon, 29 May 2006) | 3 lines
Handle PyMem_Malloc failure in pystrtod.c. Closes #1494671.
........
r46525 | georg.brandl | 2006-05-29 16:33:55 +0200 (Mon, 29 May 2006) | 3 lines
Fix compiler warning.
........
r46526 | georg.brandl | 2006-05-29 16:39:00 +0200 (Mon, 29 May 2006) | 3 lines
Fix #1494787 (pyclbr counts whitespace as superclass name)
........
r46527 | bob.ippolito | 2006-05-29 17:47:29 +0200 (Mon, 29 May 2006) | 1 line
simplify the struct code a bit (no functional changes)
........
r46528 | armin.rigo | 2006-05-29 19:59:47 +0200 (Mon, 29 May 2006) | 2 lines
Silence a warning.
........
r46529 | georg.brandl | 2006-05-29 21:39:45 +0200 (Mon, 29 May 2006) | 3 lines
Correct some value converting strangenesses.
........
r46530 | nick.coghlan | 2006-05-29 22:27:44 +0200 (Mon, 29 May 2006) | 1 line
When adding a module like functools, it helps to let SVN know about the file.
........
r46531 | georg.brandl | 2006-05-29 22:52:54 +0200 (Mon, 29 May 2006) | 4 lines
Patches #1497027 and #972322: try HTTP digest auth first,
and watch out for handler name collisions.
........
r46532 | georg.brandl | 2006-05-29 22:57:01 +0200 (Mon, 29 May 2006) | 3 lines
Add News entry for last commit.
........
r46533 | georg.brandl | 2006-05-29 23:04:52 +0200 (Mon, 29 May 2006) | 4 lines
Make use of METH_O and METH_NOARGS where possible.
Use Py_UnpackTuple instead of PyArg_ParseTuple where possible.
........
r46534 | georg.brandl | 2006-05-29 23:58:42 +0200 (Mon, 29 May 2006) | 3 lines
Convert more modules to METH_VARARGS.
........
r46535 | georg.brandl | 2006-05-30 00:00:30 +0200 (Tue, 30 May 2006) | 3 lines
Whoops.
........
r46536 | fredrik.lundh | 2006-05-30 00:42:07 +0200 (Tue, 30 May 2006) | 4 lines
fixed "abc".count("", 100) == -96 error (hopefully, nobody's relying on
the current behaviour ;-)
........
r46537 | bob.ippolito | 2006-05-30 00:55:48 +0200 (Tue, 30 May 2006) | 1 line
struct: modulo math plus warning on all endian-explicit formats for compatibility with older struct usage (ugly)
........
r46539 | bob.ippolito | 2006-05-30 02:26:01 +0200 (Tue, 30 May 2006) | 1 line
Add a length check to aifc to ensure it doesn't write a bogus file
........
r46540 | tim.peters | 2006-05-30 04:25:25 +0200 (Tue, 30 May 2006) | 10 lines
deprecated_err(): Stop bizarre warning messages when the tests
are run in the order:
test_genexps (or any other doctest-based test)
test_struct
test_doctest
The `warnings` module needs an advertised way to save/restore
its internal filter list.
........
r46541 | tim.peters | 2006-05-30 04:26:46 +0200 (Tue, 30 May 2006) | 2 lines
Whitespace normalization.
........
r46542 | tim.peters | 2006-05-30 04:30:30 +0200 (Tue, 30 May 2006) | 2 lines
Set a binary svn:mime-type property on this UTF-8 encoded file.
........
r46543 | neal.norwitz | 2006-05-30 05:18:50 +0200 (Tue, 30 May 2006) | 1 line
Simplify further by using AddStringConstant
........
r46544 | tim.peters | 2006-05-30 06:16:25 +0200 (Tue, 30 May 2006) | 6 lines
Convert relevant dict internals to Py_ssize_t.
I don't have a box with nearly enough RAM, or an OS,
that could get close to tickling this, though (requires
a dict w/ at least 2**31 entries).
........
r46545 | neal.norwitz | 2006-05-30 06:19:21 +0200 (Tue, 30 May 2006) | 1 line
Remove stray | in comment
........
r46546 | neal.norwitz | 2006-05-30 06:25:05 +0200 (Tue, 30 May 2006) | 1 line
Use Py_SAFE_DOWNCAST for safety. Fix format strings. Remove 2 more stray | in comment
........
r46547 | neal.norwitz | 2006-05-30 06:43:23 +0200 (Tue, 30 May 2006) | 1 line
No DOWNCAST is required since sizeof(Py_ssize_t) >= sizeof(int) and Py_ReprEntr returns an int
........
r46548 | tim.peters | 2006-05-30 07:04:59 +0200 (Tue, 30 May 2006) | 3 lines
dict_print(): Explicitly narrow the return value
from a (possibly) wider variable.
........
r46549 | tim.peters | 2006-05-30 07:23:59 +0200 (Tue, 30 May 2006) | 5 lines
dict_print(): So that Neal & I don't spend the rest of
our lives taking turns rewriting code that works ;-),
get rid of casting illusions by declaring a new variable
with the obvious type.
........
r46550 | georg.brandl | 2006-05-30 09:04:55 +0200 (Tue, 30 May 2006) | 3 lines
Restore exception pickle support. #1497319.
........
r46551 | georg.brandl | 2006-05-30 09:13:29 +0200 (Tue, 30 May 2006) | 3 lines
Add a test case for exception pickling. args is never NULL.
........
r46552 | neal.norwitz | 2006-05-30 09:21:10 +0200 (Tue, 30 May 2006) | 1 line
Don't fail if the (sub)pkgname already exist.
........
r46553 | georg.brandl | 2006-05-30 09:34:45 +0200 (Tue, 30 May 2006) | 3 lines
Disallow keyword args for exceptions.
........
r46554 | neal.norwitz | 2006-05-30 09:36:54 +0200 (Tue, 30 May 2006) | 5 lines
I'm impatient. I think this will fix a few more problems with the buildbots.
I'm not sure this is the best approach, but I can't think of anything better.
If this creates problems, feel free to revert, but I think it's safe and
should make things a little better.
........
r46555 | georg.brandl | 2006-05-30 10:17:00 +0200 (Tue, 30 May 2006) | 4 lines
Do the check for no keyword arguments in __init__ so that
subclasses of Exception can be supplied keyword args
........
r46556 | georg.brandl | 2006-05-30 10:47:19 +0200 (Tue, 30 May 2006) | 3 lines
Convert test_exceptions to unittest.
........
r46557 | andrew.kuchling | 2006-05-30 14:52:01 +0200 (Tue, 30 May 2006) | 1 line
Add SoC name, and reorganize this section a bit
........
r46559 | tim.peters | 2006-05-30 17:53:34 +0200 (Tue, 30 May 2006) | 11 lines
PyLong_FromString(): Continued fraction analysis (explained in
a new comment) suggests there are almost certainly large input
integers in all non-binary input bases for which one Python digit
too few is initally allocated to hold the final result. Instead
of assert-failing when that happens, allocate more space. Alas,
I estimate it would take a few days to find a specific such case,
so this isn't backed up by a new test (not to mention that such
a case may take hours to run, since conversion time is quadratic
in the number of digits, and preliminary attempts suggested that
the smallest such inputs contain at least a million digits).
........
r46560 | fredrik.lundh | 2006-05-30 19:11:48 +0200 (Tue, 30 May 2006) | 3 lines
changed find/rfind to return -1 for matches outside the source string
........
r46561 | bob.ippolito | 2006-05-30 19:37:54 +0200 (Tue, 30 May 2006) | 1 line
Change wrapping terminology to overflow masking
........
r46562 | fredrik.lundh | 2006-05-30 19:39:58 +0200 (Tue, 30 May 2006) | 3 lines
changed count to return 0 for slices outside the source string
........
r46568 | tim.peters | 2006-05-31 01:28:02 +0200 (Wed, 31 May 2006) | 2 lines
Whitespace normalization.
........
r46569 | brett.cannon | 2006-05-31 04:19:54 +0200 (Wed, 31 May 2006) | 5 lines
Clarify wording on default values for strptime(); defaults are used when better
values cannot be inferred.
Closes bug #1496315.
........
r46572 | neal.norwitz | 2006-05-31 09:43:27 +0200 (Wed, 31 May 2006) | 1 line
Calculate smallest properly (it was off by one) and use proper ssize_t types for Win64
........
r46573 | neal.norwitz | 2006-05-31 10:01:08 +0200 (Wed, 31 May 2006) | 1 line
Revert last checkin, it is better to do make distclean
........
r46574 | neal.norwitz | 2006-05-31 11:02:44 +0200 (Wed, 31 May 2006) | 3 lines
On 64-bit platforms running test_struct after test_tarfile would fail
since the deprecation warning wouldn't be raised.
........
r46575 | thomas.heller | 2006-05-31 13:37:58 +0200 (Wed, 31 May 2006) | 3 lines
PyTuple_Pack is not available in Python 2.3, but ctypes must stay
compatible with that.
........
r46576 | andrew.kuchling | 2006-05-31 15:18:56 +0200 (Wed, 31 May 2006) | 1 line
'functional' module was renamed to 'functools'
........
r46577 | kristjan.jonsson | 2006-05-31 15:35:41 +0200 (Wed, 31 May 2006) | 1 line
Fixup the PCBuild8 project directory. exceptions.c have moved to Objects, and the functionalmodule.c has been replaced with _functoolsmodule.c. Other minor changes to .vcproj files and .sln to fix compilation
........
r46578 | andrew.kuchling | 2006-05-31 16:08:48 +0200 (Wed, 31 May 2006) | 15 lines
[Bug #1473048]
SimpleXMLRPCServer and DocXMLRPCServer don't look at
the path of the HTTP request at all; you can POST or
GET from / or /RPC2 or /blahblahblah with the same results.
Security scanners that look for /cgi-bin/phf will therefore report
lots of vulnerabilities.
Fix: add a .rpc_paths attribute to the SimpleXMLRPCServer class,
and report a 404 error if the path isn't on the allowed list.
Possibly-controversial aspect of this change: the default makes only
'/' and '/RPC2' legal. Maybe this will break people's applications
(though I doubt it). We could just set the default to an empty tuple,
which would exactly match the current behaviour.
........
r46579 | andrew.kuchling | 2006-05-31 16:12:47 +0200 (Wed, 31 May 2006) | 1 line
Mention SimpleXMLRPCServer change
........
r46580 | tim.peters | 2006-05-31 16:28:07 +0200 (Wed, 31 May 2006) | 2 lines
Trimmed trailing whitespace.
........
r46581 | tim.peters | 2006-05-31 17:33:22 +0200 (Wed, 31 May 2006) | 4 lines
_range_error(): Speed and simplify (there's no real need for
loops here). Assert that size_t is actually big enough, and
that f->size is at least one. Wrap a long line.
........
r46582 | tim.peters | 2006-05-31 17:34:37 +0200 (Wed, 31 May 2006) | 2 lines
Repaired error in new comment.
........
r46584 | neal.norwitz | 2006-06-01 07:32:49 +0200 (Thu, 01 Jun 2006) | 4 lines
Remove ; at end of macro. There was a compiler recently that warned
about extra semi-colons. It may have been the HP C compiler.
This file will trigger a bunch of those warnings now.
........
r46585 | georg.brandl | 2006-06-01 08:39:19 +0200 (Thu, 01 Jun 2006) | 3 lines
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
........
r46586 | georg.brandl | 2006-06-01 10:27:32 +0200 (Thu, 01 Jun 2006) | 3 lines
Correctly allocate complex types with tp_alloc. (bug #1498638)
........
r46587 | georg.brandl | 2006-06-01 14:30:46 +0200 (Thu, 01 Jun 2006) | 2 lines
Correctly dispatch Faults in loads (patch #1498627)
........
r46588 | georg.brandl | 2006-06-01 15:00:49 +0200 (Thu, 01 Jun 2006) | 3 lines
Some code style tweaks, and remove apply.
........
r46589 | armin.rigo | 2006-06-01 15:19:12 +0200 (Thu, 01 Jun 2006) | 5 lines
[ 1497053 ] Let dicts propagate the exceptions in user __eq__().
[ 1456209 ] dictresize() vulnerability ( <- backport candidate ).
........
r46590 | tim.peters | 2006-06-01 15:41:46 +0200 (Thu, 01 Jun 2006) | 2 lines
Whitespace normalization.
........
r46591 | tim.peters | 2006-06-01 15:49:23 +0200 (Thu, 01 Jun 2006) | 2 lines
Record bugs 1275608 and 1456209 as being fixed.
........
r46592 | tim.peters | 2006-06-01 15:56:26 +0200 (Thu, 01 Jun 2006) | 5 lines
Re-enable a new empty-string test added during the NFS sprint,
but disabled then because str and unicode strings gave different
results. The implementations were repaired later during the
sprint, but the new test remained disabled.
........
r46594 | tim.peters | 2006-06-01 17:50:44 +0200 (Thu, 01 Jun 2006) | 7 lines
Armin committed his patch while I was reviewing it (I'm sure
he didn't know this), so merged in some changes I made during
review. Nothing material apart from changing a new `mask` local
from int to Py_ssize_t. Mostly this is repairing comments that
were made incorrect, and adding new comments. Also a few
minor code rewrites for clarity or helpful succinctness.
........
r46599 | neal.norwitz | 2006-06-02 06:45:53 +0200 (Fri, 02 Jun 2006) | 1 line
Convert docstrings to comments so regrtest -v prints method names
........
r46600 | neal.norwitz | 2006-06-02 06:50:49 +0200 (Fri, 02 Jun 2006) | 2 lines
Fix memory leak found by valgrind.
........
r46601 | neal.norwitz | 2006-06-02 06:54:52 +0200 (Fri, 02 Jun 2006) | 1 line
More memory leaks from valgrind
........
r46602 | neal.norwitz | 2006-06-02 08:23:00 +0200 (Fri, 02 Jun 2006) | 11 lines
Patch #1357836:
Prevent an invalid memory read from test_coding in case the done flag is set.
In that case, the loop isn't entered. I wonder if rather than setting
the done flag in the cases before the loop, if they should just exit early.
This code looks like it should be refactored.
Backport candidate (also the early break above if decoding_fgets fails)
........
r46603 | martin.blais | 2006-06-02 15:03:43 +0200 (Fri, 02 Jun 2006) | 1 line
Fixed struct test to not use unittest.
........
r46605 | tim.peters | 2006-06-03 01:22:51 +0200 (Sat, 03 Jun 2006) | 10 lines
pprint functions used to sort a dict (by key) if and only if
the output required more than one line. "Small" dicts got
displayed in seemingly random order (the hash-induced order
produced by dict.__repr__). None of this was documented.
Now pprint functions always sort dicts by key, and the docs
promise it.
This was proposed and agreed to during the PyCon 2006 core
sprint -- I just didn't have time for it before now.
........
2006-06-08 11:42:34 -03:00
|
|
|
{"hexdigest", (PyCFunction)EVP_hexdigest, METH_NOARGS, EVP_hexdigest__doc__},
|
2009-01-08 17:17:16 -04:00
|
|
|
{"copy", (PyCFunction)EVP_copy, METH_NOARGS, EVP_copy__doc__},
|
|
|
|
{NULL, NULL} /* sentinel */
|
2005-08-21 15:45:59 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
EVP_get_block_size(EVPobject *self, void *closure)
|
|
|
|
{
|
2009-01-08 17:17:16 -04:00
|
|
|
long block_size;
|
2016-09-05 18:19:05 -03:00
|
|
|
block_size = EVP_MD_CTX_block_size(self->ctx);
|
2009-01-08 17:17:16 -04:00
|
|
|
return PyLong_FromLong(block_size);
|
2005-08-21 15:45:59 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
EVP_get_digest_size(EVPobject *self, void *closure)
|
|
|
|
{
|
2009-01-08 17:17:16 -04:00
|
|
|
long size;
|
2016-09-05 18:19:05 -03:00
|
|
|
size = EVP_MD_CTX_size(self->ctx);
|
2009-01-08 17:17:16 -04:00
|
|
|
return PyLong_FromLong(size);
|
2005-08-21 15:45:59 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyMemberDef EVP_members[] = {
|
|
|
|
{"name", T_OBJECT, offsetof(EVPobject, name), READONLY, PyDoc_STR("algorithm name.")},
|
|
|
|
{NULL} /* Sentinel */
|
|
|
|
};
|
|
|
|
|
|
|
|
static PyGetSetDef EVP_getseters[] = {
|
|
|
|
{"digest_size",
|
|
|
|
(getter)EVP_get_digest_size, NULL,
|
|
|
|
NULL,
|
|
|
|
NULL},
|
|
|
|
{"block_size",
|
|
|
|
(getter)EVP_get_block_size, NULL,
|
|
|
|
NULL,
|
|
|
|
NULL},
|
|
|
|
{NULL} /* Sentinel */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
2009-01-08 17:17:16 -04:00
|
|
|
EVP_repr(EVPobject *self)
|
2005-08-21 15:45:59 -03:00
|
|
|
{
|
2010-03-12 13:00:41 -04:00
|
|
|
return PyUnicode_FromFormat("<%U HASH object @ %p>", self->name, self);
|
2005-08-21 15:45:59 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
#if HASH_OBJ_CONSTRUCTOR
|
|
|
|
static int
|
|
|
|
EVP_tp_init(EVPobject *self, PyObject *args, PyObject *kwds)
|
|
|
|
{
|
2006-02-27 12:46:16 -04:00
|
|
|
static char *kwlist[] = {"name", "string", NULL};
|
2005-08-21 15:45:59 -03:00
|
|
|
PyObject *name_obj = NULL;
|
2007-08-25 23:58:36 -03:00
|
|
|
PyObject *data_obj = NULL;
|
2007-09-22 23:00:13 -03:00
|
|
|
Py_buffer view;
|
2005-08-21 15:45:59 -03:00
|
|
|
char *nameStr;
|
|
|
|
const EVP_MD *digest;
|
|
|
|
|
2007-08-25 23:58:36 -03:00
|
|
|
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O:HASH", kwlist,
|
|
|
|
&name_obj, &data_obj)) {
|
2005-08-21 15:45:59 -03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-08-25 23:58:36 -03:00
|
|
|
if (data_obj)
|
2009-02-12 03:35:29 -04:00
|
|
|
GET_BUFFER_VIEW_OR_ERROUT(data_obj, &view);
|
2007-08-25 23:58:36 -03:00
|
|
|
|
2005-08-21 15:45:59 -03:00
|
|
|
if (!PyArg_Parse(name_obj, "s", &nameStr)) {
|
|
|
|
PyErr_SetString(PyExc_TypeError, "name must be a string");
|
2007-08-25 23:58:36 -03:00
|
|
|
if (data_obj)
|
2008-08-13 12:53:07 -03:00
|
|
|
PyBuffer_Release(&view);
|
2005-08-21 15:45:59 -03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
digest = EVP_get_digestbyname(nameStr);
|
|
|
|
if (!digest) {
|
|
|
|
PyErr_SetString(PyExc_ValueError, "unknown hash function");
|
2007-08-25 23:58:36 -03:00
|
|
|
if (data_obj)
|
2008-08-13 12:53:07 -03:00
|
|
|
PyBuffer_Release(&view);
|
2005-08-21 15:45:59 -03:00
|
|
|
return -1;
|
|
|
|
}
|
2017-05-24 04:04:38 -03:00
|
|
|
if (!EVP_DigestInit(self->ctx, digest)) {
|
|
|
|
_setException(PyExc_ValueError);
|
|
|
|
if (data_obj)
|
|
|
|
PyBuffer_Release(&view);
|
|
|
|
return -1;
|
|
|
|
}
|
2005-08-21 15:45:59 -03:00
|
|
|
|
2018-02-13 07:32:18 -04:00
|
|
|
Py_INCREF(name_obj);
|
|
|
|
Py_XSETREF(self->name, name_obj);
|
2005-08-21 15:45:59 -03:00
|
|
|
|
2007-08-25 23:58:36 -03:00
|
|
|
if (data_obj) {
|
2009-01-08 17:17:16 -04:00
|
|
|
if (view.len >= HASHLIB_GIL_MINSIZE) {
|
|
|
|
Py_BEGIN_ALLOW_THREADS
|
|
|
|
EVP_hash(self, view.buf, view.len);
|
|
|
|
Py_END_ALLOW_THREADS
|
2008-09-24 19:53:33 -03:00
|
|
|
} else {
|
2009-01-08 17:17:16 -04:00
|
|
|
EVP_hash(self, view.buf, view.len);
|
2008-09-24 19:53:33 -03:00
|
|
|
}
|
2008-08-13 12:53:07 -03:00
|
|
|
PyBuffer_Release(&view);
|
2007-08-25 23:58:36 -03:00
|
|
|
}
|
2009-01-08 17:17:16 -04:00
|
|
|
|
2005-08-21 15:45:59 -03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
PyDoc_STRVAR(hashtype_doc,
|
|
|
|
"A hash represents the object used to calculate a checksum of a\n\
|
|
|
|
string of information.\n\
|
|
|
|
\n\
|
|
|
|
Methods:\n\
|
|
|
|
\n\
|
|
|
|
update() -- updates the current digest with an additional string\n\
|
|
|
|
digest() -- return the current digest value\n\
|
|
|
|
hexdigest() -- return the current digest as a string of hexadecimal digits\n\
|
|
|
|
copy() -- return a copy of the current hash object\n\
|
|
|
|
\n\
|
|
|
|
Attributes:\n\
|
|
|
|
\n\
|
|
|
|
name -- the hash algorithm being used by this object\n\
|
|
|
|
digest_size -- number of bytes in this hashes output\n");
|
|
|
|
|
|
|
|
static PyTypeObject EVPtype = {
|
Merged revisions 56467-56482 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/p3yk
................
r56477 | martin.v.loewis | 2007-07-21 09:04:38 +0200 (Sa, 21 Jul 2007) | 11 lines
Merged revisions 56466-56476 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r56476 | martin.v.loewis | 2007-07-21 08:55:02 +0200 (Sa, 21 Jul 2007) | 4 lines
PEP 3123: Provide forward compatibility with Python 3.0, while keeping
backwards compatibility. Add Py_Refcnt, Py_Type, Py_Size, and
PyVarObject_HEAD_INIT.
........
................
r56478 | martin.v.loewis | 2007-07-21 09:47:23 +0200 (Sa, 21 Jul 2007) | 2 lines
PEP 3123: Use proper C inheritance for PyObject.
................
r56479 | martin.v.loewis | 2007-07-21 10:06:55 +0200 (Sa, 21 Jul 2007) | 3 lines
Add longintrepr.h to Python.h, so that the compiler can
see that PyFalse is really some kind of PyObject*.
................
r56480 | martin.v.loewis | 2007-07-21 10:47:18 +0200 (Sa, 21 Jul 2007) | 2 lines
Qualify SHIFT, MASK, BASE.
................
r56482 | martin.v.loewis | 2007-07-21 19:10:57 +0200 (Sa, 21 Jul 2007) | 2 lines
Correctly refer to _ob_next.
................
2007-07-21 14:22:18 -03:00
|
|
|
PyVarObject_HEAD_INIT(NULL, 0)
|
2005-08-21 15:45:59 -03:00
|
|
|
"_hashlib.HASH", /*tp_name*/
|
2009-01-08 17:17:16 -04:00
|
|
|
sizeof(EVPobject), /*tp_basicsize*/
|
|
|
|
0, /*tp_itemsize*/
|
2005-08-21 15:45:59 -03:00
|
|
|
/* methods */
|
2009-01-08 17:17:16 -04:00
|
|
|
(destructor)EVP_dealloc, /*tp_dealloc*/
|
|
|
|
0, /*tp_print*/
|
2005-08-21 15:45:59 -03:00
|
|
|
0, /*tp_getattr*/
|
|
|
|
0, /*tp_setattr*/
|
2009-02-02 16:36:42 -04:00
|
|
|
0, /*tp_reserved*/
|
2009-01-08 17:17:16 -04:00
|
|
|
(reprfunc)EVP_repr, /*tp_repr*/
|
2005-08-21 15:45:59 -03:00
|
|
|
0, /*tp_as_number*/
|
|
|
|
0, /*tp_as_sequence*/
|
|
|
|
0, /*tp_as_mapping*/
|
|
|
|
0, /*tp_hash*/
|
|
|
|
0, /*tp_call*/
|
|
|
|
0, /*tp_str*/
|
|
|
|
0, /*tp_getattro*/
|
|
|
|
0, /*tp_setattro*/
|
|
|
|
0, /*tp_as_buffer*/
|
|
|
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
|
|
|
hashtype_doc, /*tp_doc*/
|
|
|
|
0, /*tp_traverse*/
|
2009-01-08 17:17:16 -04:00
|
|
|
0, /*tp_clear*/
|
|
|
|
0, /*tp_richcompare*/
|
|
|
|
0, /*tp_weaklistoffset*/
|
|
|
|
0, /*tp_iter*/
|
|
|
|
0, /*tp_iternext*/
|
|
|
|
EVP_methods, /* tp_methods */
|
|
|
|
EVP_members, /* tp_members */
|
2005-08-21 15:45:59 -03:00
|
|
|
EVP_getseters, /* tp_getset */
|
|
|
|
#if 1
|
|
|
|
0, /* tp_base */
|
|
|
|
0, /* tp_dict */
|
|
|
|
0, /* tp_descr_get */
|
|
|
|
0, /* tp_descr_set */
|
|
|
|
0, /* tp_dictoffset */
|
|
|
|
#endif
|
|
|
|
#if HASH_OBJ_CONSTRUCTOR
|
|
|
|
(initproc)EVP_tp_init, /* tp_init */
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
EVPnew(PyObject *name_obj,
|
|
|
|
const EVP_MD *digest, const EVP_MD_CTX *initial_ctx,
|
2008-09-24 19:53:33 -03:00
|
|
|
const unsigned char *cp, Py_ssize_t len)
|
2005-08-21 15:45:59 -03:00
|
|
|
{
|
|
|
|
EVPobject *self;
|
|
|
|
|
|
|
|
if (!digest && !initial_ctx) {
|
|
|
|
PyErr_SetString(PyExc_ValueError, "unsupported hash type");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((self = newEVPobject(name_obj)) == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (initial_ctx) {
|
2016-09-05 18:19:05 -03:00
|
|
|
EVP_MD_CTX_copy(self->ctx, initial_ctx);
|
2005-08-21 15:45:59 -03:00
|
|
|
} else {
|
2017-05-24 04:04:38 -03:00
|
|
|
if (!EVP_DigestInit(self->ctx, digest)) {
|
|
|
|
_setException(PyExc_ValueError);
|
|
|
|
Py_DECREF(self);
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-08-21 15:45:59 -03:00
|
|
|
}
|
|
|
|
|
2008-09-24 19:53:33 -03:00
|
|
|
if (cp && len) {
|
2009-01-08 17:17:16 -04:00
|
|
|
if (len >= HASHLIB_GIL_MINSIZE) {
|
|
|
|
Py_BEGIN_ALLOW_THREADS
|
|
|
|
EVP_hash(self, cp, len);
|
|
|
|
Py_END_ALLOW_THREADS
|
2008-09-24 19:53:33 -03:00
|
|
|
} else {
|
2009-01-08 17:17:16 -04:00
|
|
|
EVP_hash(self, cp, len);
|
2008-09-24 19:53:33 -03:00
|
|
|
}
|
|
|
|
}
|
2005-08-21 15:45:59 -03:00
|
|
|
|
|
|
|
return (PyObject *)self;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* The module-level function: new() */
|
|
|
|
|
|
|
|
PyDoc_STRVAR(EVP_new__doc__,
|
|
|
|
"Return a new hash object using the named algorithm.\n\
|
|
|
|
An optional string argument may be provided and will be\n\
|
|
|
|
automatically hashed.\n\
|
|
|
|
\n\
|
|
|
|
The MD5 and SHA1 algorithms are always supported.\n");
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
EVP_new(PyObject *self, PyObject *args, PyObject *kwdict)
|
|
|
|
{
|
2006-02-27 12:46:16 -04:00
|
|
|
static char *kwlist[] = {"name", "string", NULL};
|
2005-08-21 15:45:59 -03:00
|
|
|
PyObject *name_obj = NULL;
|
2007-08-25 23:58:36 -03:00
|
|
|
PyObject *data_obj = NULL;
|
2007-09-22 23:00:13 -03:00
|
|
|
Py_buffer view = { 0 };
|
2007-08-25 23:58:36 -03:00
|
|
|
PyObject *ret_obj;
|
2005-08-21 15:45:59 -03:00
|
|
|
char *name;
|
|
|
|
const EVP_MD *digest;
|
|
|
|
|
2007-08-25 23:58:36 -03:00
|
|
|
if (!PyArg_ParseTupleAndKeywords(args, kwdict, "O|O:new", kwlist,
|
|
|
|
&name_obj, &data_obj)) {
|
2005-08-21 15:45:59 -03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!PyArg_Parse(name_obj, "s", &name)) {
|
|
|
|
PyErr_SetString(PyExc_TypeError, "name must be a string");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-08-25 23:58:36 -03:00
|
|
|
if (data_obj)
|
2009-02-12 03:35:29 -04:00
|
|
|
GET_BUFFER_VIEW_OR_ERROUT(data_obj, &view);
|
2007-08-25 23:58:36 -03:00
|
|
|
|
2005-08-21 15:45:59 -03:00
|
|
|
digest = EVP_get_digestbyname(name);
|
|
|
|
|
2008-09-24 19:53:33 -03:00
|
|
|
ret_obj = EVPnew(name_obj, digest, NULL, (unsigned char*)view.buf, view.len);
|
2007-08-25 23:58:36 -03:00
|
|
|
|
|
|
|
if (data_obj)
|
2008-08-13 12:53:07 -03:00
|
|
|
PyBuffer_Release(&view);
|
2007-08-25 23:58:36 -03:00
|
|
|
return ret_obj;
|
2005-08-21 15:45:59 -03:00
|
|
|
}
|
|
|
|
|
2013-10-19 12:59:48 -03:00
|
|
|
#if (OPENSSL_VERSION_NUMBER >= 0x10000000 && !defined(OPENSSL_NO_HMAC) \
|
|
|
|
&& !defined(OPENSSL_NO_SHA))
|
2013-10-19 09:24:44 -03:00
|
|
|
|
2013-10-12 19:52:43 -03:00
|
|
|
#define PY_PBKDF2_HMAC 1
|
|
|
|
|
2016-09-05 18:19:05 -03:00
|
|
|
#if !HAS_FAST_PKCS5_PBKDF2_HMAC
|
2013-10-19 09:24:44 -03:00
|
|
|
/* Improved implementation of PKCS5_PBKDF2_HMAC()
|
|
|
|
*
|
|
|
|
* PKCS5_PBKDF2_HMAC_fast() hashes the password exactly one time instead of
|
|
|
|
* `iter` times. Today (2013) the iteration count is typically 100,000 or
|
|
|
|
* more. The improved algorithm is not subject to a Denial-of-Service
|
|
|
|
* vulnerability with overly large passwords.
|
|
|
|
*
|
|
|
|
* Also OpenSSL < 1.0 don't provide PKCS5_PBKDF2_HMAC(), only
|
|
|
|
* PKCS5_PBKDF2_SHA1.
|
|
|
|
*/
|
2013-10-20 08:23:03 -03:00
|
|
|
static int
|
|
|
|
PKCS5_PBKDF2_HMAC_fast(const char *pass, int passlen,
|
|
|
|
const unsigned char *salt, int saltlen,
|
|
|
|
int iter, const EVP_MD *digest,
|
|
|
|
int keylen, unsigned char *out)
|
2013-10-19 09:24:44 -03:00
|
|
|
{
|
|
|
|
unsigned char digtmp[EVP_MAX_MD_SIZE], *p, itmp[4];
|
|
|
|
int cplen, j, k, tkeylen, mdlen;
|
|
|
|
unsigned long i = 1;
|
|
|
|
HMAC_CTX hctx_tpl, hctx;
|
|
|
|
|
|
|
|
mdlen = EVP_MD_size(digest);
|
|
|
|
if (mdlen < 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
HMAC_CTX_init(&hctx_tpl);
|
|
|
|
HMAC_CTX_init(&hctx);
|
|
|
|
p = out;
|
|
|
|
tkeylen = keylen;
|
|
|
|
if (!HMAC_Init_ex(&hctx_tpl, pass, passlen, digest, NULL)) {
|
|
|
|
HMAC_CTX_cleanup(&hctx_tpl);
|
|
|
|
return 0;
|
|
|
|
}
|
2015-09-27 06:13:40 -03:00
|
|
|
while (tkeylen) {
|
|
|
|
if (tkeylen > mdlen)
|
2013-10-19 09:24:44 -03:00
|
|
|
cplen = mdlen;
|
|
|
|
else
|
|
|
|
cplen = tkeylen;
|
|
|
|
/* We are unlikely to ever use more than 256 blocks (5120 bits!)
|
|
|
|
* but just in case...
|
|
|
|
*/
|
|
|
|
itmp[0] = (unsigned char)((i >> 24) & 0xff);
|
|
|
|
itmp[1] = (unsigned char)((i >> 16) & 0xff);
|
|
|
|
itmp[2] = (unsigned char)((i >> 8) & 0xff);
|
|
|
|
itmp[3] = (unsigned char)(i & 0xff);
|
|
|
|
if (!HMAC_CTX_copy(&hctx, &hctx_tpl)) {
|
|
|
|
HMAC_CTX_cleanup(&hctx_tpl);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!HMAC_Update(&hctx, salt, saltlen)
|
|
|
|
|| !HMAC_Update(&hctx, itmp, 4)
|
|
|
|
|| !HMAC_Final(&hctx, digtmp, NULL)) {
|
|
|
|
HMAC_CTX_cleanup(&hctx_tpl);
|
|
|
|
HMAC_CTX_cleanup(&hctx);
|
|
|
|
return 0;
|
|
|
|
}
|
2013-11-06 12:25:17 -04:00
|
|
|
HMAC_CTX_cleanup(&hctx);
|
2013-10-19 09:24:44 -03:00
|
|
|
memcpy(p, digtmp, cplen);
|
|
|
|
for (j = 1; j < iter; j++) {
|
|
|
|
if (!HMAC_CTX_copy(&hctx, &hctx_tpl)) {
|
|
|
|
HMAC_CTX_cleanup(&hctx_tpl);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!HMAC_Update(&hctx, digtmp, mdlen)
|
|
|
|
|| !HMAC_Final(&hctx, digtmp, NULL)) {
|
|
|
|
HMAC_CTX_cleanup(&hctx_tpl);
|
|
|
|
HMAC_CTX_cleanup(&hctx);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
HMAC_CTX_cleanup(&hctx);
|
|
|
|
for (k = 0; k < cplen; k++) {
|
|
|
|
p[k] ^= digtmp[k];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tkeylen-= cplen;
|
|
|
|
i++;
|
|
|
|
p+= cplen;
|
|
|
|
}
|
|
|
|
HMAC_CTX_cleanup(&hctx_tpl);
|
|
|
|
return 1;
|
|
|
|
}
|
2016-09-05 18:19:05 -03:00
|
|
|
#endif
|
2013-10-19 09:24:44 -03:00
|
|
|
|
|
|
|
|
2013-10-12 19:52:43 -03:00
|
|
|
PyDoc_STRVAR(pbkdf2_hmac__doc__,
|
|
|
|
"pbkdf2_hmac(hash_name, password, salt, iterations, dklen=None) -> key\n\
|
|
|
|
\n\
|
|
|
|
Password based key derivation function 2 (PKCS #5 v2.0) with HMAC as\n\
|
|
|
|
pseudorandom function.");
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
pbkdf2_hmac(PyObject *self, PyObject *args, PyObject *kwdict)
|
|
|
|
{
|
|
|
|
static char *kwlist[] = {"hash_name", "password", "salt", "iterations",
|
|
|
|
"dklen", NULL};
|
|
|
|
PyObject *key_obj = NULL, *dklen_obj = Py_None;
|
|
|
|
char *name, *key;
|
|
|
|
Py_buffer password, salt;
|
|
|
|
long iterations, dklen;
|
|
|
|
int retval;
|
|
|
|
const EVP_MD *digest;
|
|
|
|
|
|
|
|
if (!PyArg_ParseTupleAndKeywords(args, kwdict, "sy*y*l|O:pbkdf2_hmac",
|
|
|
|
kwlist, &name, &password, &salt,
|
|
|
|
&iterations, &dklen_obj)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
digest = EVP_get_digestbyname(name);
|
|
|
|
if (digest == NULL) {
|
|
|
|
PyErr_SetString(PyExc_ValueError, "unsupported hash type");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (password.len > INT_MAX) {
|
|
|
|
PyErr_SetString(PyExc_OverflowError,
|
|
|
|
"password is too long.");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (salt.len > INT_MAX) {
|
|
|
|
PyErr_SetString(PyExc_OverflowError,
|
|
|
|
"salt is too long.");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iterations < 1) {
|
|
|
|
PyErr_SetString(PyExc_ValueError,
|
|
|
|
"iteration value must be greater than 0.");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
if (iterations > INT_MAX) {
|
|
|
|
PyErr_SetString(PyExc_OverflowError,
|
|
|
|
"iteration value is too great.");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dklen_obj == Py_None) {
|
|
|
|
dklen = EVP_MD_size(digest);
|
|
|
|
} else {
|
|
|
|
dklen = PyLong_AsLong(dklen_obj);
|
|
|
|
if ((dklen == -1) && PyErr_Occurred()) {
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (dklen < 1) {
|
|
|
|
PyErr_SetString(PyExc_ValueError,
|
|
|
|
"key length must be greater than 0.");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
if (dklen > INT_MAX) {
|
|
|
|
/* INT_MAX is always smaller than dkLen max (2^32 - 1) * hLen */
|
|
|
|
PyErr_SetString(PyExc_OverflowError,
|
|
|
|
"key length is too great.");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
key_obj = PyBytes_FromStringAndSize(NULL, dklen);
|
|
|
|
if (key_obj == NULL) {
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
key = PyBytes_AS_STRING(key_obj);
|
|
|
|
|
|
|
|
Py_BEGIN_ALLOW_THREADS
|
2016-09-05 18:19:05 -03:00
|
|
|
#if HAS_FAST_PKCS5_PBKDF2_HMAC
|
|
|
|
retval = PKCS5_PBKDF2_HMAC((char*)password.buf, (int)password.len,
|
|
|
|
(unsigned char *)salt.buf, (int)salt.len,
|
|
|
|
iterations, digest, dklen,
|
|
|
|
(unsigned char *)key);
|
|
|
|
#else
|
2013-11-15 19:27:16 -04:00
|
|
|
retval = PKCS5_PBKDF2_HMAC_fast((char*)password.buf, (int)password.len,
|
2013-11-18 04:59:44 -04:00
|
|
|
(unsigned char *)salt.buf, (int)salt.len,
|
2013-10-19 09:24:44 -03:00
|
|
|
iterations, digest, dklen,
|
|
|
|
(unsigned char *)key);
|
2016-09-05 18:19:05 -03:00
|
|
|
#endif
|
2013-10-12 19:52:43 -03:00
|
|
|
Py_END_ALLOW_THREADS
|
|
|
|
|
|
|
|
if (!retval) {
|
|
|
|
Py_CLEAR(key_obj);
|
|
|
|
_setException(PyExc_ValueError);
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
end:
|
|
|
|
PyBuffer_Release(&password);
|
|
|
|
PyBuffer_Release(&salt);
|
|
|
|
return key_obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2010-09-06 05:30:23 -03:00
|
|
|
|
2016-09-06 15:22:28 -03:00
|
|
|
#if OPENSSL_VERSION_NUMBER > 0x10100000L && !defined(OPENSSL_NO_SCRYPT) && !defined(LIBRESSL_VERSION_NUMBER)
|
|
|
|
#define PY_SCRYPT 1
|
|
|
|
|
2018-07-31 04:22:44 -03:00
|
|
|
/* XXX: Parameters salt, n, r and p should be required keyword-only parameters.
|
|
|
|
They are optional in the Argument Clinic declaration only due to a
|
|
|
|
limitation of PyArg_ParseTupleAndKeywords. */
|
|
|
|
|
2016-09-06 15:22:28 -03:00
|
|
|
/*[clinic input]
|
|
|
|
_hashlib.scrypt
|
|
|
|
|
|
|
|
password: Py_buffer
|
|
|
|
*
|
|
|
|
salt: Py_buffer = None
|
|
|
|
n as n_obj: object(subclass_of='&PyLong_Type') = None
|
|
|
|
r as r_obj: object(subclass_of='&PyLong_Type') = None
|
|
|
|
p as p_obj: object(subclass_of='&PyLong_Type') = None
|
|
|
|
maxmem: long = 0
|
|
|
|
dklen: long = 64
|
|
|
|
|
|
|
|
|
|
|
|
scrypt password-based key derivation function.
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_hashlib_scrypt_impl(PyObject *module, Py_buffer *password, Py_buffer *salt,
|
|
|
|
PyObject *n_obj, PyObject *r_obj, PyObject *p_obj,
|
|
|
|
long maxmem, long dklen)
|
|
|
|
/*[clinic end generated code: output=14849e2aa2b7b46c input=48a7d63bf3f75c42]*/
|
|
|
|
{
|
|
|
|
PyObject *key_obj = NULL;
|
|
|
|
char *key;
|
|
|
|
int retval;
|
|
|
|
unsigned long n, r, p;
|
|
|
|
|
|
|
|
if (password->len > INT_MAX) {
|
|
|
|
PyErr_SetString(PyExc_OverflowError,
|
|
|
|
"password is too long.");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (salt->buf == NULL) {
|
|
|
|
PyErr_SetString(PyExc_TypeError,
|
|
|
|
"salt is required");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (salt->len > INT_MAX) {
|
|
|
|
PyErr_SetString(PyExc_OverflowError,
|
|
|
|
"salt is too long.");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
n = PyLong_AsUnsignedLong(n_obj);
|
|
|
|
if (n == (unsigned long) -1 && PyErr_Occurred()) {
|
|
|
|
PyErr_SetString(PyExc_TypeError,
|
|
|
|
"n is required and must be an unsigned int");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (n < 2 || n & (n - 1)) {
|
|
|
|
PyErr_SetString(PyExc_ValueError,
|
|
|
|
"n must be a power of 2.");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = PyLong_AsUnsignedLong(r_obj);
|
|
|
|
if (r == (unsigned long) -1 && PyErr_Occurred()) {
|
|
|
|
PyErr_SetString(PyExc_TypeError,
|
|
|
|
"r is required and must be an unsigned int");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = PyLong_AsUnsignedLong(p_obj);
|
|
|
|
if (p == (unsigned long) -1 && PyErr_Occurred()) {
|
|
|
|
PyErr_SetString(PyExc_TypeError,
|
|
|
|
"p is required and must be an unsigned int");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (maxmem < 0 || maxmem > INT_MAX) {
|
2017-11-08 18:44:44 -04:00
|
|
|
/* OpenSSL 1.1.0 restricts maxmem to 32 MiB. It may change in the
|
2016-09-06 15:22:28 -03:00
|
|
|
future. The maxmem constant is private to OpenSSL. */
|
|
|
|
PyErr_Format(PyExc_ValueError,
|
|
|
|
"maxmem must be positive and smaller than %d",
|
|
|
|
INT_MAX);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dklen < 1 || dklen > INT_MAX) {
|
|
|
|
PyErr_Format(PyExc_ValueError,
|
|
|
|
"dklen must be greater than 0 and smaller than %d",
|
|
|
|
INT_MAX);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* let OpenSSL validate the rest */
|
|
|
|
retval = EVP_PBE_scrypt(NULL, 0, NULL, 0, n, r, p, maxmem, NULL, 0);
|
|
|
|
if (!retval) {
|
|
|
|
/* sorry, can't do much better */
|
|
|
|
PyErr_SetString(PyExc_ValueError,
|
2019-03-06 10:54:54 -04:00
|
|
|
"Invalid parameter combination for n, r, p, maxmem.");
|
2016-09-06 15:22:28 -03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
key_obj = PyBytes_FromStringAndSize(NULL, dklen);
|
|
|
|
if (key_obj == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
key = PyBytes_AS_STRING(key_obj);
|
|
|
|
|
|
|
|
Py_BEGIN_ALLOW_THREADS
|
|
|
|
retval = EVP_PBE_scrypt(
|
|
|
|
(const char*)password->buf, (size_t)password->len,
|
|
|
|
(const unsigned char *)salt->buf, (size_t)salt->len,
|
|
|
|
n, r, p, maxmem,
|
|
|
|
(unsigned char *)key, (size_t)dklen
|
|
|
|
);
|
|
|
|
Py_END_ALLOW_THREADS
|
|
|
|
|
|
|
|
if (!retval) {
|
|
|
|
Py_CLEAR(key_obj);
|
|
|
|
_setException(PyExc_ValueError);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return key_obj;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-01-27 04:53:43 -04:00
|
|
|
/* Fast HMAC for hmac.digest()
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*[clinic input]
|
|
|
|
_hashlib.hmac_digest
|
|
|
|
|
|
|
|
key: Py_buffer
|
|
|
|
msg: Py_buffer
|
|
|
|
digest: str
|
|
|
|
|
2018-07-31 04:22:44 -03:00
|
|
|
Single-shot HMAC.
|
2018-01-27 04:53:43 -04:00
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_hashlib_hmac_digest_impl(PyObject *module, Py_buffer *key, Py_buffer *msg,
|
|
|
|
const char *digest)
|
2018-07-31 04:22:44 -03:00
|
|
|
/*[clinic end generated code: output=75630e684cdd8762 input=562d2f4249511bd3]*/
|
2018-01-27 04:53:43 -04:00
|
|
|
{
|
|
|
|
unsigned char md[EVP_MAX_MD_SIZE] = {0};
|
|
|
|
unsigned int md_len = 0;
|
|
|
|
unsigned char *result;
|
|
|
|
const EVP_MD *evp;
|
|
|
|
|
|
|
|
evp = EVP_get_digestbyname(digest);
|
|
|
|
if (evp == NULL) {
|
|
|
|
PyErr_SetString(PyExc_ValueError, "unsupported hash type");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (key->len > INT_MAX) {
|
|
|
|
PyErr_SetString(PyExc_OverflowError,
|
|
|
|
"key is too long.");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (msg->len > INT_MAX) {
|
|
|
|
PyErr_SetString(PyExc_OverflowError,
|
|
|
|
"msg is too long.");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Py_BEGIN_ALLOW_THREADS
|
|
|
|
result = HMAC(
|
|
|
|
evp,
|
|
|
|
(const void*)key->buf, (int)key->len,
|
|
|
|
(const unsigned char*)msg->buf, (int)msg->len,
|
|
|
|
md, &md_len
|
|
|
|
);
|
|
|
|
Py_END_ALLOW_THREADS
|
|
|
|
|
|
|
|
if (result == NULL) {
|
|
|
|
_setException(PyExc_ValueError);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return PyBytes_FromStringAndSize((const char*)md, md_len);
|
|
|
|
}
|
|
|
|
|
2010-09-06 05:30:23 -03:00
|
|
|
/* State for our callback function so that it can accumulate a result. */
|
|
|
|
typedef struct _internal_name_mapper_state {
|
|
|
|
PyObject *set;
|
|
|
|
int error;
|
|
|
|
} _InternalNameMapperState;
|
|
|
|
|
|
|
|
|
|
|
|
/* A callback function to pass to OpenSSL's OBJ_NAME_do_all(...) */
|
|
|
|
static void
|
|
|
|
_openssl_hash_name_mapper(const OBJ_NAME *openssl_obj_name, void *arg)
|
|
|
|
{
|
|
|
|
_InternalNameMapperState *state = (_InternalNameMapperState *)arg;
|
|
|
|
PyObject *py_name;
|
|
|
|
|
|
|
|
assert(state != NULL);
|
|
|
|
if (openssl_obj_name == NULL)
|
|
|
|
return;
|
|
|
|
/* Ignore aliased names, they pollute the list and OpenSSL appears to
|
2015-11-01 23:37:02 -04:00
|
|
|
* have its own definition of alias as the resulting list still
|
2010-09-06 05:30:23 -03:00
|
|
|
* contains duplicate and alternate names for several algorithms. */
|
|
|
|
if (openssl_obj_name->alias)
|
|
|
|
return;
|
|
|
|
|
|
|
|
py_name = PyUnicode_FromString(openssl_obj_name->name);
|
|
|
|
if (py_name == NULL) {
|
|
|
|
state->error = 1;
|
|
|
|
} else {
|
|
|
|
if (PySet_Add(state->set, py_name) != 0) {
|
|
|
|
state->error = 1;
|
|
|
|
}
|
2013-10-29 08:14:55 -03:00
|
|
|
Py_DECREF(py_name);
|
2010-09-06 05:30:23 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Ask OpenSSL for a list of supported ciphers, filling in a Python set. */
|
|
|
|
static PyObject*
|
|
|
|
generate_hash_name_list(void)
|
|
|
|
{
|
|
|
|
_InternalNameMapperState state;
|
|
|
|
state.set = PyFrozenSet_New(NULL);
|
|
|
|
if (state.set == NULL)
|
|
|
|
return NULL;
|
|
|
|
state.error = 0;
|
|
|
|
|
|
|
|
OBJ_NAME_do_all(OBJ_NAME_TYPE_MD_METH, &_openssl_hash_name_mapper, &state);
|
|
|
|
|
|
|
|
if (state.error) {
|
|
|
|
Py_DECREF(state.set);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return state.set;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-08-21 15:45:59 -03:00
|
|
|
/*
|
|
|
|
* This macro generates constructor function definitions for specific
|
|
|
|
* hash algorithms. These constructors are much faster than calling
|
2016-08-30 14:47:49 -03:00
|
|
|
* the generic one passing it a python string and are noticeably
|
2018-02-03 21:41:43 -04:00
|
|
|
* faster than calling a python new() wrapper. That is important for
|
2005-08-21 15:45:59 -03:00
|
|
|
* code that wants to make hashes of a bunch of small strings.
|
2017-05-24 04:04:38 -03:00
|
|
|
* The first call will lazy-initialize, which reports an exception
|
|
|
|
* if initialization fails.
|
2005-08-21 15:45:59 -03:00
|
|
|
*/
|
|
|
|
#define GEN_CONSTRUCTOR(NAME) \
|
|
|
|
static PyObject * \
|
2017-12-15 07:11:11 -04:00
|
|
|
EVP_new_ ## NAME (PyObject *self, PyObject *const *args, Py_ssize_t nargs) \
|
2005-08-21 15:45:59 -03:00
|
|
|
{ \
|
2007-08-25 23:58:36 -03:00
|
|
|
PyObject *data_obj = NULL; \
|
2007-09-22 23:00:13 -03:00
|
|
|
Py_buffer view = { 0 }; \
|
2007-08-25 23:58:36 -03:00
|
|
|
PyObject *ret_obj; \
|
2017-01-16 23:20:26 -04:00
|
|
|
\
|
2017-06-15 12:05:23 -03:00
|
|
|
if (!_PyArg_ParseStack(args, nargs, "|O:" #NAME , &data_obj)) { \
|
2005-08-21 15:45:59 -03:00
|
|
|
return NULL; \
|
|
|
|
} \
|
2017-05-24 04:04:38 -03:00
|
|
|
\
|
|
|
|
if (CONST_new_ ## NAME ## _ctx_p == NULL) { \
|
|
|
|
EVP_MD_CTX *ctx_p = EVP_MD_CTX_new(); \
|
|
|
|
if (!EVP_get_digestbyname(#NAME) || \
|
|
|
|
!EVP_DigestInit(ctx_p, EVP_get_digestbyname(#NAME))) { \
|
|
|
|
_setException(PyExc_ValueError); \
|
|
|
|
EVP_MD_CTX_free(ctx_p); \
|
|
|
|
return NULL; \
|
|
|
|
} \
|
|
|
|
CONST_new_ ## NAME ## _ctx_p = ctx_p; \
|
|
|
|
} \
|
2005-08-21 15:45:59 -03:00
|
|
|
\
|
2007-08-25 23:58:36 -03:00
|
|
|
if (data_obj) \
|
2009-02-12 03:35:29 -04:00
|
|
|
GET_BUFFER_VIEW_OR_ERROUT(data_obj, &view); \
|
2007-08-25 23:58:36 -03:00
|
|
|
\
|
|
|
|
ret_obj = EVPnew( \
|
|
|
|
CONST_ ## NAME ## _name_obj, \
|
|
|
|
NULL, \
|
|
|
|
CONST_new_ ## NAME ## _ctx_p, \
|
|
|
|
(unsigned char*)view.buf, \
|
2008-09-24 19:53:33 -03:00
|
|
|
view.len); \
|
2007-08-25 23:58:36 -03:00
|
|
|
\
|
|
|
|
if (data_obj) \
|
2008-08-13 12:53:07 -03:00
|
|
|
PyBuffer_Release(&view); \
|
2007-08-25 23:58:36 -03:00
|
|
|
return ret_obj; \
|
2005-08-21 15:45:59 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* a PyMethodDef structure for the constructor */
|
|
|
|
#define CONSTRUCTOR_METH_DEF(NAME) \
|
2017-07-10 05:25:34 -03:00
|
|
|
{"openssl_" #NAME, (PyCFunction)EVP_new_ ## NAME, METH_FASTCALL, \
|
2005-08-21 15:45:59 -03:00
|
|
|
PyDoc_STR("Returns a " #NAME \
|
|
|
|
" hash object; optionally initialized with a string") \
|
|
|
|
}
|
|
|
|
|
2013-02-01 21:05:29 -04:00
|
|
|
/* used in the init function to setup a constructor: initialize OpenSSL
|
|
|
|
constructor constants if they haven't been initialized already. */
|
2005-08-21 15:45:59 -03:00
|
|
|
#define INIT_CONSTRUCTOR_CONSTANTS(NAME) do { \
|
2013-02-01 21:05:29 -04:00
|
|
|
if (CONST_ ## NAME ## _name_obj == NULL) { \
|
|
|
|
CONST_ ## NAME ## _name_obj = PyUnicode_FromString(#NAME); \
|
2005-08-21 15:45:59 -03:00
|
|
|
} \
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
GEN_CONSTRUCTOR(md5)
|
|
|
|
GEN_CONSTRUCTOR(sha1)
|
|
|
|
GEN_CONSTRUCTOR(sha224)
|
|
|
|
GEN_CONSTRUCTOR(sha256)
|
|
|
|
GEN_CONSTRUCTOR(sha384)
|
|
|
|
GEN_CONSTRUCTOR(sha512)
|
|
|
|
|
|
|
|
/* List of functions exported by this module */
|
|
|
|
|
|
|
|
static struct PyMethodDef EVP_functions[] = {
|
|
|
|
{"new", (PyCFunction)EVP_new, METH_VARARGS|METH_KEYWORDS, EVP_new__doc__},
|
2013-10-12 19:52:43 -03:00
|
|
|
#ifdef PY_PBKDF2_HMAC
|
|
|
|
{"pbkdf2_hmac", (PyCFunction)pbkdf2_hmac, METH_VARARGS|METH_KEYWORDS,
|
|
|
|
pbkdf2_hmac__doc__},
|
|
|
|
#endif
|
2016-09-06 15:22:28 -03:00
|
|
|
_HASHLIB_SCRYPT_METHODDEF
|
2018-01-27 04:53:43 -04:00
|
|
|
_HASHLIB_HMAC_DIGEST_METHODDEF
|
2005-08-21 15:45:59 -03:00
|
|
|
CONSTRUCTOR_METH_DEF(md5),
|
|
|
|
CONSTRUCTOR_METH_DEF(sha1),
|
|
|
|
CONSTRUCTOR_METH_DEF(sha224),
|
|
|
|
CONSTRUCTOR_METH_DEF(sha256),
|
|
|
|
CONSTRUCTOR_METH_DEF(sha384),
|
|
|
|
CONSTRUCTOR_METH_DEF(sha512),
|
2010-08-11 14:31:17 -03:00
|
|
|
{NULL, NULL} /* Sentinel */
|
2005-08-21 15:45:59 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Initialize this module. */
|
|
|
|
|
2008-06-11 02:26:20 -03:00
|
|
|
|
|
|
|
static struct PyModuleDef _hashlibmodule = {
|
2009-01-08 17:17:16 -04:00
|
|
|
PyModuleDef_HEAD_INIT,
|
|
|
|
"_hashlib",
|
|
|
|
NULL,
|
|
|
|
-1,
|
|
|
|
EVP_functions,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL
|
2008-06-11 02:26:20 -03:00
|
|
|
};
|
|
|
|
|
2005-08-21 15:45:59 -03:00
|
|
|
PyMODINIT_FUNC
|
2008-06-11 02:26:20 -03:00
|
|
|
PyInit__hashlib(void)
|
2005-08-21 15:45:59 -03:00
|
|
|
{
|
2010-09-06 05:30:23 -03:00
|
|
|
PyObject *m, *openssl_md_meth_names;
|
2005-08-21 15:45:59 -03:00
|
|
|
|
2019-09-16 16:49:07 -03:00
|
|
|
#if (OPENSSL_VERSION_NUMBER < 0x10100000L) || defined(LIBRESSL_VERSION_NUMBER)
|
2017-09-05 10:47:11 -03:00
|
|
|
/* Load all digest algorithms and initialize cpuid */
|
|
|
|
OPENSSL_add_all_algorithms_noconf();
|
2013-10-21 14:48:22 -03:00
|
|
|
ERR_load_crypto_strings();
|
2017-09-05 10:47:11 -03:00
|
|
|
#endif
|
2005-08-21 15:45:59 -03:00
|
|
|
|
|
|
|
/* TODO build EVP_functions openssl_* entries dynamically based
|
|
|
|
* on what hashes are supported rather than listing many
|
|
|
|
* but having some be unsupported. Only init appropriate
|
|
|
|
* constants. */
|
|
|
|
|
2007-12-18 22:45:37 -04:00
|
|
|
Py_TYPE(&EVPtype) = &PyType_Type;
|
2005-08-21 15:45:59 -03:00
|
|
|
if (PyType_Ready(&EVPtype) < 0)
|
2008-06-11 02:26:20 -03:00
|
|
|
return NULL;
|
2005-08-21 15:45:59 -03:00
|
|
|
|
2008-06-11 02:26:20 -03:00
|
|
|
m = PyModule_Create(&_hashlibmodule);
|
2005-08-21 15:45:59 -03:00
|
|
|
if (m == NULL)
|
2008-06-11 02:26:20 -03:00
|
|
|
return NULL;
|
2005-08-21 15:45:59 -03:00
|
|
|
|
2010-09-06 05:30:23 -03:00
|
|
|
openssl_md_meth_names = generate_hash_name_list();
|
|
|
|
if (openssl_md_meth_names == NULL) {
|
|
|
|
Py_DECREF(m);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (PyModule_AddObject(m, "openssl_md_meth_names", openssl_md_meth_names)) {
|
|
|
|
Py_DECREF(m);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-10-22 10:05:23 -03:00
|
|
|
Py_INCREF((PyObject *)&EVPtype);
|
2005-08-21 15:45:59 -03:00
|
|
|
PyModule_AddObject(m, "HASH", (PyObject *)&EVPtype);
|
|
|
|
|
|
|
|
/* these constants are used by the convenience constructors */
|
|
|
|
INIT_CONSTRUCTOR_CONSTANTS(md5);
|
|
|
|
INIT_CONSTRUCTOR_CONSTANTS(sha1);
|
|
|
|
INIT_CONSTRUCTOR_CONSTANTS(sha224);
|
|
|
|
INIT_CONSTRUCTOR_CONSTANTS(sha256);
|
|
|
|
INIT_CONSTRUCTOR_CONSTANTS(sha384);
|
|
|
|
INIT_CONSTRUCTOR_CONSTANTS(sha512);
|
2008-06-11 02:26:20 -03:00
|
|
|
return m;
|
2005-08-21 15:45:59 -03:00
|
|
|
}
|