Skip to content

Commit d36977f

Browse files
committed
ensure that openssl is linked
1 parent 9bee955 commit d36977f

File tree

3 files changed

+151
-33
lines changed

3 files changed

+151
-33
lines changed

Modules/hmacmodule.c

Lines changed: 63 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,45 @@ static PyMethodDef hmacmodule_methods[] = {
573573

574574
// --- HMAC static information table ------------------------------------------
575575

576+
#define Py_OpenSSL_LN_md5 LN_md5
577+
#define Py_OpenSSL_LN_sha1 LN_sha1
578+
579+
#define Py_OpenSSL_LN_sha2_224 LN_sha224
580+
#define Py_OpenSSL_LN_sha2_256 LN_sha256
581+
#define Py_OpenSSL_LN_sha2_384 LN_sha384
582+
#define Py_OpenSSL_LN_sha2_512 LN_sha512
583+
584+
#if defined(LN_sha3_224)
585+
# define Py_OpenSSL_LN_sha3_224 LN_sha3_224
586+
#else
587+
# define Py_OpenSSL_LN_sha3_224 "sha3_224"
588+
#endif
589+
#if defined(LN_sha3_256)
590+
# define Py_OpenSSL_LN_sha3_256 LN_sha3_256
591+
#else
592+
# define Py_OpenSSL_LN_sha3_256 "sha3_256"
593+
#endif
594+
#if defined(LN_sha3_384)
595+
# define Py_OpenSSL_LN_sha3_384 LN_sha3_384
596+
#else
597+
# define Py_OpenSSL_LN_sha3_384 "sha3_384"
598+
#endif
599+
#if defined(LN_sha3_512)
600+
# define Py_OpenSSL_LN_sha3_512 LN_sha3_512
601+
#else
602+
# define Py_OpenSSL_LN_sha3_512 "sha3_512"
603+
#endif
604+
605+
#if defined(LN_blake2s256)
606+
# define Py_OpenSSL_LN_blake2s_32 LN_blake2s256
607+
#else
608+
# define Py_OpenSSL_LN_blake2s_32 "blake2s256"
609+
#endif
610+
#if defined(LN_blake2b512)
611+
# define Py_OpenSSL_LN_blake2b_32 LN_blake2b512
612+
#else
613+
# define Py_OpenSSL_LN_blake2b_32 "blake2b512"
614+
#endif
576615

577616
/* Static information used to construct the hash table. */
578617
static const py_hmac_hinfo py_hmac_static_hinfo[] = {
@@ -582,36 +621,36 @@ static const py_hmac_hinfo py_hmac_static_hinfo[] = {
582621
.compute_py = &_hmac_compute_## HACL_HID ##_impl, \
583622
}
584623

585-
#define Py_HMAC_HINFO_ENTRY(HACL_HID, HLIB_NAME, HLIB_ALTN, OSSL_NAME) \
586-
{ \
587-
.name = Py_STRINGIFY(HACL_HID), \
588-
.p_name = NULL, \
589-
.kind = Py_hmac_kind_hmac_ ## HACL_HID, \
590-
.block_size = Py_hmac_## HACL_HID ##_block_size, \
591-
.digest_size = Py_hmac_## HACL_HID ##_digest_size, \
592-
.api = Py_HMAC_HINFO_HACL_API(HACL_HID), \
593-
.hashlib_name = HLIB_NAME, \
594-
.hashlib_altn = HLIB_ALTN, \
595-
.openssl_name = OSSL_NAME, \
596-
.refcnt = 0, \
624+
#define Py_HMAC_HINFO_ENTRY(HACL_HID, HLIB_NAME, HLIB_ALTN) \
625+
{ \
626+
.name = Py_STRINGIFY(HACL_HID), \
627+
.p_name = NULL, \
628+
.kind = Py_hmac_kind_hmac_ ## HACL_HID, \
629+
.block_size = Py_hmac_## HACL_HID ##_block_size, \
630+
.digest_size = Py_hmac_## HACL_HID ##_digest_size, \
631+
.api = Py_HMAC_HINFO_HACL_API(HACL_HID), \
632+
.hashlib_name = HLIB_NAME, \
633+
.hashlib_altn = HLIB_ALTN, \
634+
.openssl_name = Py_OpenSSL_LN_ ## HACL_HID, \
635+
.refcnt = 0, \
597636
}
598637
/* MD5 */
599-
Py_HMAC_HINFO_ENTRY(md5, "md5", "MD5", LN_md5),
638+
Py_HMAC_HINFO_ENTRY(md5, "md5", "MD5"),
600639
/* SHA-1 */
601-
Py_HMAC_HINFO_ENTRY(sha1, "sha1", "SHA1", LN_sha1),
640+
Py_HMAC_HINFO_ENTRY(sha1, "sha1", "SHA1"),
602641
/* SHA-2 family */
603-
Py_HMAC_HINFO_ENTRY(sha2_224, "sha224", "SHA224", LN_sha224),
604-
Py_HMAC_HINFO_ENTRY(sha2_256, "sha256", "SHA256", LN_sha256),
605-
Py_HMAC_HINFO_ENTRY(sha2_384, "sha384", "SHA384", LN_sha384),
606-
Py_HMAC_HINFO_ENTRY(sha2_512, "sha512", "SHA512", LN_sha512),
642+
Py_HMAC_HINFO_ENTRY(sha2_224, "sha224", "SHA224"),
643+
Py_HMAC_HINFO_ENTRY(sha2_256, "sha256", "SHA256"),
644+
Py_HMAC_HINFO_ENTRY(sha2_384, "sha384", "SHA384"),
645+
Py_HMAC_HINFO_ENTRY(sha2_512, "sha512", "SHA512"),
607646
/* SHA-3 family */
608-
Py_HMAC_HINFO_ENTRY(sha3_224, NULL, NULL, LN_sha3_224),
609-
Py_HMAC_HINFO_ENTRY(sha3_256, NULL, NULL, LN_sha3_256),
610-
Py_HMAC_HINFO_ENTRY(sha3_384, NULL, NULL, LN_sha3_384),
611-
Py_HMAC_HINFO_ENTRY(sha3_512, NULL, NULL, LN_sha3_512),
647+
Py_HMAC_HINFO_ENTRY(sha3_224, NULL, NULL),
648+
Py_HMAC_HINFO_ENTRY(sha3_256, NULL, NULL),
649+
Py_HMAC_HINFO_ENTRY(sha3_384, NULL, NULL),
650+
Py_HMAC_HINFO_ENTRY(sha3_512, NULL, NULL),
612651
/* Blake family */
613-
Py_HMAC_HINFO_ENTRY(blake2s_32, "blake2s256", NULL, LN_blake2s256),
614-
Py_HMAC_HINFO_ENTRY(blake2b_32, "blake2b512", NULL, LN_blake2b512),
652+
Py_HMAC_HINFO_ENTRY(blake2s_32, "blake2s256", NULL),
653+
Py_HMAC_HINFO_ENTRY(blake2b_32, "blake2b512", NULL),
615654
#undef Py_HMAC_HINFO_ENTRY
616655
#undef Py_HMAC_HINFO_HACL_API
617656
/* sentinel */

configure

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

configure.ac

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7387,6 +7387,18 @@ WITH_SAVE_ENV([
73877387
])
73887388
])
73897389

7390+
WITH_SAVE_ENV([
7391+
LIBS="$LIBS $LIBCRYPTO_LIBS"
7392+
CFLAGS="$CFLAGS $OPENSSL_INCLUDES"
7393+
LDFLAGS="$LDFLAGS $OPENSSL_LDFLAGS $OPENSSL_LDFLAGS_RPATH"
7394+
7395+
AC_CACHE_CHECK([whether OpenSSL provides LN_* macros], [ac_cv_working_openssl_hmac], [
7396+
AC_LINK_IFELSE([AC_LANG_PROGRAM([
7397+
#include <openssl/obj_mac.h> // for LN_* macros
7398+
], [])], [ac_cv_working_openssl_hmac=yes], [ac_cv_working_openssl_hmac=no])
7399+
])
7400+
])
7401+
73907402
# ssl module default cipher suite string
73917403
AH_TEMPLATE([PY_SSL_DEFAULT_CIPHERS],
73927404
[Default cipher suites list for ssl module.
@@ -7801,7 +7813,8 @@ PY_STDLIB_MOD([_sha2], [test "$with_builtin_sha2" = yes])
78017813
PY_STDLIB_MOD([_sha3], [test "$with_builtin_sha3" = yes])
78027814
PY_STDLIB_MOD([_blake2], [test "$with_builtin_blake2" = yes])
78037815

7804-
PY_STDLIB_MOD_SIMPLE([_hmac])
7816+
PY_STDLIB_MOD([_hmac], [], [test "$ac_cv_working_openssl_hmac" = yes],
7817+
[$OPENSSL_INCLUDES], [$OPENSSL_LDFLAGS $OPENSSL_LDFLAGS_RPATH $LIBCRYPTO_LIBS])
78057818

78067819
LIBHACL_CFLAGS='-I$(srcdir)/Modules/_hacl -I$(srcdir)/Modules/_hacl/include -D_BSD_SOURCE -D_DEFAULT_SOURCE $(PY_STDMODULE_CFLAGS) $(CCSHARED)'
78077820
case "$ac_sys_system" in

0 commit comments

Comments
 (0)