File tree Expand file tree Collapse file tree 3 files changed +20
-1
lines changed Expand file tree Collapse file tree 3 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -223,6 +223,10 @@ def test_algorithms_guaranteed(self):
223
223
def test_algorithms_available (self ):
224
224
self .assertTrue (set (hashlib .algorithms_guaranteed ).
225
225
issubset (hashlib .algorithms_available ))
226
+ # all available algorithms must be loadable, bpo-47101
227
+ self .assertNotIn ("undefined" , hashlib .algorithms_available )
228
+ for name in hashlib .algorithms_available :
229
+ digest = hashlib .new (name , usedforsecurity = False )
226
230
227
231
def test_usedforsecurity_true (self ):
228
232
hashlib .new ("sha256" , usedforsecurity = True )
Original file line number Diff line number Diff line change
1
+ :const: `hashlib.algorithms_available ` now lists only algorithms that are
2
+ provided by activated crypto providers on OpenSSL 3.0. Legacy algorithms are
3
+ not listed unless the legacy provider has been loaded into the default
4
+ OSSL context.
Original file line number Diff line number Diff line change @@ -1836,15 +1836,21 @@ typedef struct _internal_name_mapper_state {
1836
1836
1837
1837
/* A callback function to pass to OpenSSL's OBJ_NAME_do_all(...) */
1838
1838
static void
1839
+ #if OPENSSL_VERSION_NUMBER >= 0x30000000L
1840
+ _openssl_hash_name_mapper (EVP_MD * md , void * arg )
1841
+ #else
1839
1842
_openssl_hash_name_mapper (const EVP_MD * md , const char * from ,
1840
1843
const char * to , void * arg )
1844
+ #endif
1841
1845
{
1842
1846
_InternalNameMapperState * state = (_InternalNameMapperState * )arg ;
1843
1847
PyObject * py_name ;
1844
1848
1845
1849
assert (state != NULL );
1846
- if (md == NULL )
1850
+ // ignore all undefined providers
1851
+ if ((md == NULL ) || (EVP_MD_nid (md ) == NID_undef )) {
1847
1852
return ;
1853
+ }
1848
1854
1849
1855
py_name = py_digest_name (md );
1850
1856
if (py_name == NULL ) {
@@ -1870,7 +1876,12 @@ hashlib_md_meth_names(PyObject *module)
1870
1876
return -1 ;
1871
1877
}
1872
1878
1879
+ #if OPENSSL_VERSION_NUMBER >= 0x30000000L
1880
+ // get algorithms from all activated providers in default context
1881
+ EVP_MD_do_all_provided (NULL , & _openssl_hash_name_mapper , & state );
1882
+ #else
1873
1883
EVP_MD_do_all (& _openssl_hash_name_mapper , & state );
1884
+ #endif
1874
1885
1875
1886
if (state .error ) {
1876
1887
Py_DECREF (state .set );
You can’t perform that action at this time.
0 commit comments