Branch
Hash :
a351f5c2
Author :
Date :
2025-09-01T22:57:22
crypto/sha3-buffer: Add support for OpenSSL. * lib/sha3.c (DEFINE_SHA3_INIT_CTX, sha3_read_ctx, sha3_finish_ctx) (DEFINE_SHA3_BUFFER, sha3_process_bytes, sha3_process_block) [HAVE_OPENSSL_SHA3]: Define these functions/macros using the OpenSSL EVP API. * lib/sha3.h [HAVE_OPENSSL_SHA3]: Include <openssl/evp.h>. (struct sha3_ctx) [HAVE_OPENSSL_SHA3]: Only store a pointer to an EVP_MD_CTX in the structure. * m4/gl-openssl.m4 (gl_CRYPTO_CHECK): If the argument is SHA3 check for EVP_sha3_224. * m4/sha3.m4 (gl_SHA3): New file, based on m4/sha512.m4. * modules/crypto/sha3-buffer (Files): Add m4/gl-openssl.m4 and m4/sha3.m4. (configure.ac): Invoke gl_SHA3. Remove gl_BIGENDIAN. * modules/crypto/sha3-buffer-tests (Makefile.am): Link to @LIB_CRYPTO@.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
# gl-openssl.m4
# serial 8
dnl Copyright (C) 2013-2025 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
dnl This file is offered as-is, without any warranty.
AC_DEFUN([gl_SET_CRYPTO_CHECK_DEFAULT],
[
m4_define([gl_CRYPTO_CHECK_DEFAULT], [$1])
])
gl_SET_CRYPTO_CHECK_DEFAULT([no])
AC_DEFUN([gl_CRYPTO_CHECK],
[
dnl gnulib users set this before gl_INIT with gl_SET_CRYPTO_CHECK_DEFAULT()
m4_divert_once([DEFAULTS], [with_openssl_default='gl_CRYPTO_CHECK_DEFAULT'])
dnl Only clear once, so crypto routines can be checked for individually
m4_divert_once([DEFAULTS], [LIB_CRYPTO=])
AC_ARG_WITH([openssl],
[[ --with-openssl[=ARG] use libcrypto hash routines for the hash functions
MD5, SHA-1, SHA-224, SHA-256, SHA-384, SHA-512.
Valid ARGs are:
'yes',
'no',
'auto' => use if any version available,
'auto-gpl-compat' => use if GPL compatible version
available,
'optional' => use if available
and warn if not available;
Default is ']gl_CRYPTO_CHECK_DEFAULT['.]m4_ifdef([gl_AF_ALG], [
Note also --with-linux-crypto, which will enable the
use of Linux kernel crypto routines (if available),
which has precedence for files.])],
[],
[with_openssl=$with_openssl_default])
AC_SUBST([LIB_CRYPTO])
if test "x$with_openssl" != xno; then
if test "x$with_openssl" = xauto-gpl-compat; then
dnl OpenSSL versions < 3 are under the OpenSSL license, which is not
dnl GPL compatible.
dnl See <https://www.gnu.org/licenses/license-list.en.html#OpenSSL>.
AC_CACHE_CHECK([whether openssl is GPL compatible],
[gl_cv_openssl_gpl_compat],
[AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([[
#include <openssl/opensslv.h>
#if OPENSSL_VERSION_MAJOR < 3
#error "openssl >= version 3 not found"
#endif
]])],
[gl_cv_openssl_gpl_compat=yes],
[gl_cv_openssl_gpl_compat=no])])
fi
if test "x$with_openssl" != xauto-gpl-compat ||
test "x$gl_cv_openssl_gpl_compat" = xyes; then
m4_if([$1], [SHA3],
[AC_CHECK_LIB([crypto], [EVP_sha3_224],
[LIB_CRYPTO=-lcrypto
AC_DEFINE([HAVE_OPENSSL_$1], [1],
[Define to 1 if libcrypto is used for $1.])])],
[AC_CHECK_LIB([crypto], [$1],
[AC_CHECK_HEADERS(
m4_if([$1], [MD5], [openssl/md5.h], [openssl/sha.h]),
[LIB_CRYPTO=-lcrypto
AC_DEFINE([HAVE_OPENSSL_$1], [1],
[Define to 1 if libcrypto is used for $1.])])])])
fi
if test "x$LIB_CRYPTO" = x; then
message='openssl development library not found for $1.
If you want to install it, first find the pre-built package name:
- On Debian and Debian-based systems: libssl-dev,
- On Red Hat distributions: openssl-devel.
- Other: https://repology.org/project/openssl/versions'
if test "x$with_openssl" = xyes; then
AC_MSG_ERROR([$message])
elif test "x$with_openssl" = xoptional; then
AC_MSG_WARN([$message])
fi
fi
fi
])