diff options
Diffstat (limited to 'Modules/_hashopenssl.c')
-rw-r--r-- | Modules/_hashopenssl.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/Modules/_hashopenssl.c b/Modules/_hashopenssl.c index 0850d7b..26ed148 100644 --- a/Modules/_hashopenssl.c +++ b/Modules/_hashopenssl.c @@ -49,6 +49,10 @@ #define HASH_OBJ_CONSTRUCTOR 0 #endif +/* Minimum OpenSSL version needed to support sha224 and higher. */ +#if defined(OPENSSL_VERSION_NUMBER) && (OPENSSL_VERSION_NUMBER >= 0x00908000) +#define _OPENSSL_SUPPORTS_SHA2 +#endif typedef struct { PyObject_HEAD @@ -70,10 +74,12 @@ static PyTypeObject EVPtype; DEFINE_CONSTS_FOR_NEW(md5) DEFINE_CONSTS_FOR_NEW(sha1) +#ifdef _OPENSSL_SUPPORTS_SHA2 DEFINE_CONSTS_FOR_NEW(sha224) DEFINE_CONSTS_FOR_NEW(sha256) DEFINE_CONSTS_FOR_NEW(sha384) DEFINE_CONSTS_FOR_NEW(sha512) +#endif static EVPobject * @@ -537,10 +543,12 @@ EVP_new(PyObject *self, PyObject *args, PyObject *kwdict) GEN_CONSTRUCTOR(md5) GEN_CONSTRUCTOR(sha1) +#ifdef _OPENSSL_SUPPORTS_SHA2 GEN_CONSTRUCTOR(sha224) GEN_CONSTRUCTOR(sha256) GEN_CONSTRUCTOR(sha384) GEN_CONSTRUCTOR(sha512) +#endif /* List of functions exported by this module */ @@ -548,11 +556,13 @@ static struct PyMethodDef EVP_functions[] = { {"new", (PyCFunction)EVP_new, METH_VARARGS|METH_KEYWORDS, EVP_new__doc__}, CONSTRUCTOR_METH_DEF(md5), CONSTRUCTOR_METH_DEF(sha1), +#ifdef _OPENSSL_SUPPORTS_SHA2 CONSTRUCTOR_METH_DEF(sha224), CONSTRUCTOR_METH_DEF(sha256), CONSTRUCTOR_METH_DEF(sha384), CONSTRUCTOR_METH_DEF(sha512), - {NULL, NULL} /* Sentinel */ +#endif + {NULL, NULL} /* Sentinel */ }; @@ -599,9 +609,11 @@ PyInit__hashlib(void) /* these constants are used by the convenience constructors */ INIT_CONSTRUCTOR_CONSTANTS(md5); INIT_CONSTRUCTOR_CONSTANTS(sha1); +#ifdef _OPENSSL_SUPPORTS_SHA2 INIT_CONSTRUCTOR_CONSTANTS(sha224); INIT_CONSTRUCTOR_CONSTANTS(sha256); INIT_CONSTRUCTOR_CONSTANTS(sha384); INIT_CONSTRUCTOR_CONSTANTS(sha512); +#endif return m; } |