Skip to content

Commit 7aaaeeb

Browse files
tiranmcepl
authored andcommitted
OpenSSL 3.0.0: Fix hashlib issue
The FIPS_mode() function has been deprecated and removed. It no longer makes sense with the new provider and context system in OpenSSL 3.0.0. EVP_default_properties_is_fips_enabled() is good enough for our needs in unit tests. It's an internal API, too. Fixes: bpo-40479 From-PR: gh#python/cpython!20107 Patch: openssl-300-fix-hashlib-issue.patch Released-in: 3.9.0 Signed-off-by: Christian Heimes <[email protected]>
1 parent 763d57a commit 7aaaeeb

File tree

3 files changed

+160
-0
lines changed

3 files changed

+160
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The :mod:`hashlib` now compiles with OpenSSL 3.0.0-alpha2.

Modules/_hashopenssl.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,47 @@ generate_hash_name_list(void)
965965
return ret_obj; \
966966
}
967967

968+
#ifndef LIBRESSL_VERSION_NUMBER
969+
/*[clinic input]
970+
_hashlib.get_fips_mode -> int
971+
972+
Determine the OpenSSL FIPS mode of operation.
973+
974+
For OpenSSL 3.0.0 and newer it returns the state of the default provider
975+
in the default OSSL context. It's not quite the same as FIPS_mode() but good
976+
enough for unittests.
977+
978+
Effectively any non-zero return value indicates FIPS mode;
979+
values other than 1 may have additional significance.
980+
[clinic start generated code]*/
981+
982+
static int
983+
_hashlib_get_fips_mode_impl(PyObject *module)
984+
/*[clinic end generated code: output=87eece1bab4d3fa9 input=2db61538c41c6fef]*/
985+
986+
{
987+
int result;
988+
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
989+
result = EVP_default_properties_is_fips_enabled(NULL);
990+
#else
991+
ERR_clear_error();
992+
result = FIPS_mode();
993+
if (result == 0) {
994+
// "If the library was built without support of the FIPS Object Module,
995+
// then the function will return 0 with an error code of
996+
// CRYPTO_R_FIPS_MODE_NOT_SUPPORTED (0x0f06d065)."
997+
// But 0 is also a valid result value.
998+
unsigned long errcode = ERR_peek_last_error();
999+
if (errcode) {
1000+
_setException(PyExc_ValueError);
1001+
return -1;
1002+
}
1003+
}
1004+
return result;
1005+
#endif
1006+
}
1007+
#endif // !LIBRESSL_VERSION_NUMBER
1008+
9681009
/* a PyMethodDef structure for the constructor */
9691010
#define CONSTRUCTOR_METH_DEF(NAME) \
9701011
{"openssl_" #NAME, (PyCFunction)EVP_new_ ## NAME, METH_VARARGS, \

Modules/clinic/_hashopenssl.c.h

Lines changed: 118 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)