b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | --- a/Modules/_hashopenssl.c |
| 2 | +++ b/Modules/_hashopenssl.c |
| 3 | @@ -45,10 +45,18 @@ |
| 4 | |
| 5 | #define MUNCH_SIZE INT_MAX |
| 6 | |
| 7 | +#ifdef NID_id_scrypt |
| 8 | #define PY_OPENSSL_HAS_SCRYPT 1 |
| 9 | +#endif |
| 10 | +#ifdef NID_sha3_256 |
| 11 | #define PY_OPENSSL_HAS_SHA3 1 |
| 12 | +#endif |
| 13 | +#ifdef NID_shake256 |
| 14 | #define PY_OPENSSL_HAS_SHAKE 1 |
| 15 | +#endif |
| 16 | +#ifdef NID_blake2s256 |
| 17 | #define PY_OPENSSL_HAS_BLAKE2 1 |
| 18 | +#endif |
| 19 | |
| 20 | #if OPENSSL_VERSION_NUMBER >= 0x30000000L |
| 21 | #define PY_EVP_MD EVP_MD |
| 22 | @@ -120,19 +128,27 @@ static const py_hashentry_t py_hashes[] |
| 23 | PY_HASH_ENTRY(Py_hash_sha384, "SHA384", SN_sha384, NID_sha384), |
| 24 | PY_HASH_ENTRY(Py_hash_sha512, "SHA512", SN_sha512, NID_sha512), |
| 25 | /* truncated sha2 */ |
| 26 | +#ifdef NID_sha512_256 |
| 27 | PY_HASH_ENTRY(Py_hash_sha512_224, "SHA512_224", SN_sha512_224, NID_sha512_224), |
| 28 | PY_HASH_ENTRY(Py_hash_sha512_256, "SHA512_256", SN_sha512_256, NID_sha512_256), |
| 29 | +#endif |
| 30 | /* sha3 */ |
| 31 | +#ifdef PY_OPENSSL_HAS_SHA3 |
| 32 | PY_HASH_ENTRY(Py_hash_sha3_224, NULL, SN_sha3_224, NID_sha3_224), |
| 33 | PY_HASH_ENTRY(Py_hash_sha3_256, NULL, SN_sha3_256, NID_sha3_256), |
| 34 | PY_HASH_ENTRY(Py_hash_sha3_384, NULL, SN_sha3_384, NID_sha3_384), |
| 35 | PY_HASH_ENTRY(Py_hash_sha3_512, NULL, SN_sha3_512, NID_sha3_512), |
| 36 | +#endif |
| 37 | /* sha3 shake */ |
| 38 | +#ifdef PY_OPENSSL_HAS_SHAKE |
| 39 | PY_HASH_ENTRY(Py_hash_shake_128, NULL, SN_shake128, NID_shake128), |
| 40 | PY_HASH_ENTRY(Py_hash_shake_256, NULL, SN_shake256, NID_shake256), |
| 41 | +#endif |
| 42 | /* blake2 digest */ |
| 43 | +#ifdef PY_OPENSSL_HAS_BLAKE2 |
| 44 | PY_HASH_ENTRY(Py_hash_blake2s, "blake2s256", SN_blake2s256, NID_blake2s256), |
| 45 | PY_HASH_ENTRY(Py_hash_blake2b, "blake2b512", SN_blake2b512, NID_blake2b512), |
| 46 | +#endif |
| 47 | PY_HASH_ENTRY(NULL, NULL, NULL, 0), |
| 48 | }; |
| 49 | |
| 50 | @@ -874,11 +890,15 @@ py_evp_fromname(PyObject *module, const |
| 51 | goto exit; |
| 52 | } |
| 53 | |
| 54 | +#ifndef EVP_MD_FLAG_XOF |
| 55 | + type = get_hashlib_state(module)->EVPtype; |
| 56 | +#else |
| 57 | if ((EVP_MD_flags(digest) & EVP_MD_FLAG_XOF) == EVP_MD_FLAG_XOF) { |
| 58 | type = get_hashlib_state(module)->EVPXOFtype; |
| 59 | } else { |
| 60 | type = get_hashlib_state(module)->EVPtype; |
| 61 | } |
| 62 | +#endif |
| 63 | |
| 64 | self = newEVPobject(type); |
| 65 | if (self == NULL) { |