Skip to content

[3.8] bpo-38153: detect shake independently from sha3 (GH-16143) #16179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 16, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions Modules/_hashopenssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@

#define MUNCH_SIZE INT_MAX

#if defined(NID_sha3_224) && defined(EVP_MD_FLAG_XOF)
#ifdef NID_sha3_224
#define PY_OPENSSL_HAS_SHA3 1
#endif

#if defined(EVP_MD_FLAG_XOF) && defined(NID_shake128)
#define PY_OPENSSL_HAS_SHAKE 1
#endif

#ifdef NID_blake2b512
#define PY_OPENSSL_HAS_BLAKE2 1
#endif
Expand Down Expand Up @@ -139,6 +143,8 @@ py_digest_name(const EVP_MD *md)
case NID_sha3_512:
name ="sha3_512";
break;
#endif
#ifdef PY_OPENSSL_HAS_SHAKE
case NID_shake128:
name ="shake_128";
break;
Expand Down Expand Up @@ -177,8 +183,9 @@ py_digest_by_name(const char *name)
/* OpenSSL uses dash instead of underscore in names of some algorithms
* like SHA3 and SHAKE. Detect different spellings. */
if (digest == NULL) {
if (0) {}
#ifdef NID_sha512_224
if (!strcmp(name, "sha512_224") || !strcmp(name, "SHA512_224")) {
else if (!strcmp(name, "sha512_224") || !strcmp(name, "SHA512_224")) {
digest = EVP_sha512_224();
}
else if (!strcmp(name, "sha512_256") || !strcmp(name, "SHA512_256")) {
Expand All @@ -199,6 +206,8 @@ py_digest_by_name(const char *name)
else if (!strcmp(name, "sha3_512")) {
digest = EVP_sha3_512();
}
#endif
#ifdef PY_OPENSSL_HAS_SHAKE
else if (!strcmp(name, "shake_128")) {
digest = EVP_shake128();
}
Expand Down