From d00d2d43d637e434cb5eb84138df62de4d66dd8a Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 26 Aug 2023 22:45:17 +0200 Subject: [PATCH] crypto/{sha*,md5,sm3}-buffer: Ignore too old OpenSSL versions. * lib/sha1.h: If would give a compile-time error, undefine HAVE_OPENSSL_SHA1. * lib/sha256.h: If would give a compile-time error, undefine HAVE_OPENSSL_SHA256. * lib/sha512.h: If would give a compile-time error, undefine HAVE_OPENSSL_SHA512. * lib/md5.h: If would give a compile-time error, undefine HAVE_OPENSSL_MD5. * lib/sm3.h: If would give a compile-time error, undefine HAVE_OPENSSL_SM3. --- ChangeLog | 14 ++++++++++++++ lib/md5.h | 12 +++++++++++- lib/sha1.h | 12 +++++++++++- lib/sha256.h | 12 +++++++++++- lib/sha512.h | 12 +++++++++++- lib/sm3.h | 12 +++++++++++- 6 files changed, 69 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2c23db0c57..657819e6d6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2023-08-26 Bruno Haible + + crypto/{sha*,md5,sm3}-buffer: Ignore too old OpenSSL versions. + * lib/sha1.h: If would give a compile-time error, + undefine HAVE_OPENSSL_SHA1. + * lib/sha256.h: If would give a compile-time error, + undefine HAVE_OPENSSL_SHA256. + * lib/sha512.h: If would give a compile-time error, + undefine HAVE_OPENSSL_SHA512. + * lib/md5.h: If would give a compile-time error, + undefine HAVE_OPENSSL_MD5. + * lib/sm3.h: If would give a compile-time error, + undefine HAVE_OPENSSL_SM3. + 2023-08-26 Bruno Haible uchar: Make #include_next work right. diff --git a/lib/md5.h b/lib/md5.h index f34e7cb8df..7992999f8c 100644 --- a/lib/md5.h +++ b/lib/md5.h @@ -27,7 +27,17 @@ # ifndef OPENSSL_API_COMPAT # define OPENSSL_API_COMPAT 0x10101000L /* FIXME: Use OpenSSL 1.1+ API. */ # endif -# include +/* If would give a compile-time error, don't use OpenSSL. */ +# include +# if (OPENSSL_CONFIGURED_API \ + < (OPENSSL_API_COMPAT < 0x900000L ? OPENSSL_API_COMPAT : \ + ((OPENSSL_API_COMPAT >> 28) & 0xF) * 10000 \ + + ((OPENSSL_API_COMPAT >> 20) & 0xFF) * 100 \ + + ((OPENSSL_API_COMPAT >> 12) & 0xFF))) +# undef HAVE_OPENSSL_MD5 +# else +# include +# endif # endif #define MD5_DIGEST_SIZE 16 diff --git a/lib/sha1.h b/lib/sha1.h index 5a58b567ce..9a7af61512 100644 --- a/lib/sha1.h +++ b/lib/sha1.h @@ -26,7 +26,17 @@ # ifndef OPENSSL_API_COMPAT # define OPENSSL_API_COMPAT 0x10101000L /* FIXME: Use OpenSSL 1.1+ API. */ # endif -# include +/* If would give a compile-time error, don't use OpenSSL. */ +# include +# if (OPENSSL_CONFIGURED_API \ + < (OPENSSL_API_COMPAT < 0x900000L ? OPENSSL_API_COMPAT : \ + ((OPENSSL_API_COMPAT >> 28) & 0xF) * 10000 \ + + ((OPENSSL_API_COMPAT >> 20) & 0xFF) * 100 \ + + ((OPENSSL_API_COMPAT >> 12) & 0xFF))) +# undef HAVE_OPENSSL_SHA1 +# else +# include +# endif # endif # ifdef __cplusplus diff --git a/lib/sha256.h b/lib/sha256.h index 2879477e89..67ef8d00e4 100644 --- a/lib/sha256.h +++ b/lib/sha256.h @@ -25,7 +25,17 @@ # ifndef OPENSSL_API_COMPAT # define OPENSSL_API_COMPAT 0x10101000L /* FIXME: Use OpenSSL 1.1+ API. */ # endif -# include +/* If would give a compile-time error, don't use OpenSSL. */ +# include +# if (OPENSSL_CONFIGURED_API \ + < (OPENSSL_API_COMPAT < 0x900000L ? OPENSSL_API_COMPAT : \ + ((OPENSSL_API_COMPAT >> 28) & 0xF) * 10000 \ + + ((OPENSSL_API_COMPAT >> 20) & 0xFF) * 100 \ + + ((OPENSSL_API_COMPAT >> 12) & 0xFF))) +# undef HAVE_OPENSSL_SHA256 +# else +# include +# endif # endif # ifdef __cplusplus diff --git a/lib/sha512.h b/lib/sha512.h index e3a98a2644..98db0a1921 100644 --- a/lib/sha512.h +++ b/lib/sha512.h @@ -25,7 +25,17 @@ # ifndef OPENSSL_API_COMPAT # define OPENSSL_API_COMPAT 0x10101000L /* FIXME: Use OpenSSL 1.1+ API. */ # endif -# include +/* If would give a compile-time error, don't use OpenSSL. */ +# include +# if (OPENSSL_CONFIGURED_API \ + < (OPENSSL_API_COMPAT < 0x900000L ? OPENSSL_API_COMPAT : \ + ((OPENSSL_API_COMPAT >> 28) & 0xF) * 10000 \ + + ((OPENSSL_API_COMPAT >> 20) & 0xFF) * 100 \ + + ((OPENSSL_API_COMPAT >> 12) & 0xFF))) +# undef HAVE_OPENSSL_SHA512 +# else +# include +# endif # endif # ifdef __cplusplus diff --git a/lib/sm3.h b/lib/sm3.h index 4ca7f7a103..f581f13420 100644 --- a/lib/sm3.h +++ b/lib/sm3.h @@ -34,7 +34,17 @@ # ifndef OPENSSL_API_COMPAT # define OPENSSL_API_COMPAT 0x10101000L /* FIXME: Use OpenSSL 1.1+ API. */ # endif -# include +/* If would give a compile-time error, don't use OpenSSL. */ +# include +# if (OPENSSL_CONFIGURED_API \ + < (OPENSSL_API_COMPAT < 0x900000L ? OPENSSL_API_COMPAT : \ + ((OPENSSL_API_COMPAT >> 28) & 0xF) * 10000 \ + + ((OPENSSL_API_COMPAT >> 20) & 0xFF) * 100 \ + + ((OPENSSL_API_COMPAT >> 12) & 0xFF))) +# undef HAVE_OPENSSL_SM3 +# else +# include +# endif # endif # ifdef __cplusplus -- 2.39.5