From: Bruno Haible Date: Sat, 5 May 2018 18:27:33 +0000 (+0200) Subject: af_alg: New module. X-Git-Tag: v1.0~5649 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=459221a854b083ca9709e65de463dd05b1101851;p=gnulib.git af_alg: New module. * lib/af_alg.h: Test HAVE_* macro through '#if', not '#ifdef'. * lib/af_alg.c: Include "af_alg.h" before the other header files. * lib/md5.c: Include "af_alg.h" unconditionally. (md5_stream): Invoke afalg_stream unconditionally. * lib/sha1.c: Include "af_alg.h" unconditionally. (sha1_stream): Invoke afalg_stream unconditionally. * lib/sha256.c: Include "af_alg.h" unconditionally. (sha256_stream, sha224_stream): Invoke afalg_stream unconditionally. * lib/sha512.c: Include "af_alg.h" unconditionally. (sha512_stream, sha384_stream): Invoke afalg_stream unconditionally. * m4/af_alg.m4: Renamed from m4/linux-if-alg.m4. (gl_AF_ALG): Renamed from gl_LINUX_IF_ALG_H. * modules/crypto/af_alg: New file. * modules/crypto/md5 (Files): Remove files that are now in the 'crypto/af_alg' module. (Depends-on): Add crypto/af_alg. (configure.ac): Remove gl_LINUX_IF_ALG_H invocation. (Makefile.am): Don't mention af_alg.c here. * modules/crypto/sha1 (Files): Remove files that are now in the 'crypto/af_alg' module. (Depends-on): Add crypto/af_alg. (configure.ac): Remove gl_LINUX_IF_ALG_H invocation. (Makefile.am): Don't mention af_alg.c here. * modules/crypto/sha256 (Files): Remove files that are now in the 'crypto/af_alg' module. (Depends-on): Add crypto/af_alg. (configure.ac): Remove gl_LINUX_IF_ALG_H invocation. (Makefile.am): Don't mention af_alg.c here. * modules/crypto/sha512 (Files): Remove files that are now in the 'crypto/af_alg' module. (Depends-on): Add crypto/af_alg. (configure.ac): Remove gl_LINUX_IF_ALG_H invocation. (Makefile.am): Don't mention af_alg.c here. --- diff --git a/ChangeLog b/ChangeLog index 82ab6c1c6d..fd07f8b441 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,40 @@ +2018-05-05 Bruno Haible + + af_alg: New module. + * lib/af_alg.h: Test HAVE_* macro through '#if', not '#ifdef'. + * lib/af_alg.c: Include "af_alg.h" before the other header files. + * lib/md5.c: Include "af_alg.h" unconditionally. + (md5_stream): Invoke afalg_stream unconditionally. + * lib/sha1.c: Include "af_alg.h" unconditionally. + (sha1_stream): Invoke afalg_stream unconditionally. + * lib/sha256.c: Include "af_alg.h" unconditionally. + (sha256_stream, sha224_stream): Invoke afalg_stream unconditionally. + * lib/sha512.c: Include "af_alg.h" unconditionally. + (sha512_stream, sha384_stream): Invoke afalg_stream unconditionally. + * m4/af_alg.m4: Renamed from m4/linux-if-alg.m4. + (gl_AF_ALG): Renamed from gl_LINUX_IF_ALG_H. + * modules/crypto/af_alg: New file. + * modules/crypto/md5 (Files): Remove files that are now in the + 'crypto/af_alg' module. + (Depends-on): Add crypto/af_alg. + (configure.ac): Remove gl_LINUX_IF_ALG_H invocation. + (Makefile.am): Don't mention af_alg.c here. + * modules/crypto/sha1 (Files): Remove files that are now in the + 'crypto/af_alg' module. + (Depends-on): Add crypto/af_alg. + (configure.ac): Remove gl_LINUX_IF_ALG_H invocation. + (Makefile.am): Don't mention af_alg.c here. + * modules/crypto/sha256 (Files): Remove files that are now in the + 'crypto/af_alg' module. + (Depends-on): Add crypto/af_alg. + (configure.ac): Remove gl_LINUX_IF_ALG_H invocation. + (Makefile.am): Don't mention af_alg.c here. + * modules/crypto/sha512 (Files): Remove files that are now in the + 'crypto/af_alg' module. + (Depends-on): Add crypto/af_alg. + (configure.ac): Remove gl_LINUX_IF_ALG_H invocation. + (Makefile.am): Don't mention af_alg.c here. + 2018-05-05 Paul Eggert crypto tests: pacify GCC diff --git a/lib/af_alg.c b/lib/af_alg.c index 519d6f8f3e..dc3ac6aa15 100644 --- a/lib/af_alg.c +++ b/lib/af_alg.c @@ -19,7 +19,9 @@ #include -#ifdef HAVE_LINUX_IF_ALG_H +#if HAVE_LINUX_IF_ALG_H + +#include "af_alg.h" #include #include @@ -28,8 +30,6 @@ #include #include -#include "af_alg.h" - #include "sys-limits.h" #define BLOCKSIZE 32768 diff --git a/lib/af_alg.h b/lib/af_alg.h index aacb8f606a..295f0f9b59 100644 --- a/lib/af_alg.h +++ b/lib/af_alg.h @@ -36,7 +36,7 @@ extern "C" { # endif -# ifdef HAVE_LINUX_IF_ALG_H +# if HAVE_LINUX_IF_ALG_H /* Computes a message digest of the contents of a file. STREAM is an open file stream. Regular files are handled more efficiently diff --git a/lib/md5.c b/lib/md5.c index e6bd2099e5..2bf2f0c75e 100644 --- a/lib/md5.c +++ b/lib/md5.c @@ -32,9 +32,7 @@ #include #include -#ifdef HAVE_LINUX_IF_ALG_H -# include "af_alg.h" -#endif +#include "af_alg.h" #if USE_UNLOCKED_IO # include "unlocked-io.h" @@ -148,16 +146,14 @@ md5_stream (FILE *stream, void *resblock) size_t sum; char *buffer; -#ifdef HAVE_LINUX_IF_ALG_H - int ret; - - ret = afalg_stream (stream, "md5", resblock, MD5_DIGEST_SIZE); - if (!ret) + { + int ret = afalg_stream (stream, "md5", resblock, MD5_DIGEST_SIZE); + if (!ret) return 0; - if (ret == -EIO) + if (ret == -EIO) return 1; -#endif + } buffer = malloc (BLOCKSIZE + 72); if (!buffer) diff --git a/lib/sha1.c b/lib/sha1.c index b670267c2b..e7cd2a305a 100644 --- a/lib/sha1.c +++ b/lib/sha1.c @@ -33,9 +33,7 @@ #include #include -#ifdef HAVE_LINUX_IF_ALG_H -# include "af_alg.h" -#endif +#include "af_alg.h" #if USE_UNLOCKED_IO # include "unlocked-io.h" @@ -127,7 +125,7 @@ sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf) #endif /* Compute SHA1 message digest for bytes read from STREAM. The - resulting message digest number will be written into the 16 bytes + resulting message digest number will be written into the 20 bytes beginning at RESBLOCK. */ int sha1_stream (FILE *stream, void *resblock) @@ -135,16 +133,15 @@ sha1_stream (FILE *stream, void *resblock) struct sha1_ctx ctx; size_t sum; char *buffer; -#ifdef HAVE_LINUX_IF_ALG_H - int ret; - ret = afalg_stream (stream, "sha1", resblock, SHA1_DIGEST_SIZE); - if (!ret) + { + int ret = afalg_stream (stream, "sha1", resblock, SHA1_DIGEST_SIZE); + if (!ret) return 0; - if (ret == -EIO) + if (ret == -EIO) return 1; -#endif + } buffer = malloc (BLOCKSIZE + 72); if (!buffer) diff --git a/lib/sha256.c b/lib/sha256.c index fab119a16e..410bd98c2e 100644 --- a/lib/sha256.c +++ b/lib/sha256.c @@ -32,9 +32,7 @@ #include #include -#ifdef HAVE_LINUX_IF_ALG_H -# include "af_alg.h" -#endif +#include "af_alg.h" #if USE_UNLOCKED_IO # include "unlocked-io.h" @@ -183,16 +181,14 @@ sha256_stream (FILE *stream, void *resblock) size_t sum; char *buffer; -#ifdef HAVE_LINUX_IF_ALG_H - int ret; - - ret = afalg_stream(stream, "sha256", resblock, SHA256_DIGEST_SIZE); - if (!ret) + { + int ret = afalg_stream (stream, "sha256", resblock, SHA256_DIGEST_SIZE); + if (!ret) return 0; - if (ret == -EIO) + if (ret == -EIO) return 1; -#endif + } buffer = malloc (BLOCKSIZE + 72); if (!buffer) @@ -266,16 +262,14 @@ sha224_stream (FILE *stream, void *resblock) size_t sum; char *buffer; -#ifdef HAVE_LINUX_IF_ALG_H - int ret; - - ret = afalg_stream (stream, "sha224", resblock, SHA224_DIGEST_SIZE); - if (!ret) + { + int ret = afalg_stream(stream, "sha224", resblock, SHA224_DIGEST_SIZE); + if (!ret) return 0; - if (ret == -EIO) + if (ret == -EIO) return 1; -#endif + } buffer = malloc (BLOCKSIZE + 72); if (!buffer) diff --git a/lib/sha512.c b/lib/sha512.c index ff7c0cb07d..7a0234828b 100644 --- a/lib/sha512.c +++ b/lib/sha512.c @@ -32,9 +32,7 @@ #include #include -#ifdef HAVE_LINUX_IF_ALG_H -# include "af_alg.h" -#endif +#include "af_alg.h" #if USE_UNLOCKED_IO # include "unlocked-io.h" @@ -191,16 +189,14 @@ sha512_stream (FILE *stream, void *resblock) size_t sum; char *buffer; -#ifdef HAVE_LINUX_IF_ALG_H - int ret; - - ret = afalg_stream (stream, "sha512", resblock, SHA512_DIGEST_SIZE); - if (!ret) + { + int ret = afalg_stream (stream, "sha512", resblock, SHA512_DIGEST_SIZE); + if (!ret) return 0; - if (ret == -EIO) + if (ret == -EIO) return 1; -#endif + } buffer = malloc (BLOCKSIZE + 72); if (!buffer) @@ -274,16 +270,14 @@ sha384_stream (FILE *stream, void *resblock) size_t sum; char *buffer; -#ifdef HAVE_LINUX_IF_ALG_H - int ret; - - ret = afalg_stream (stream, "sha384", resblock, SHA384_DIGEST_SIZE); - if (!ret) + { + int ret = afalg_stream(stream, "sha384", resblock, SHA384_DIGEST_SIZE); + if (!ret) return 0; - if (ret == -EIO) + if (ret == -EIO) return 1; -#endif + } buffer = malloc (BLOCKSIZE + 72); if (!buffer) diff --git a/m4/af_alg.m4 b/m4/af_alg.m4 new file mode 100644 index 0000000000..1c57e2ca22 --- /dev/null +++ b/m4/af_alg.m4 @@ -0,0 +1,30 @@ +# af_alg.m4 serial 1 +dnl Check whether linux/if_alg.h has needed features. + +dnl Copyright 2018 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 From Matteo Croce. + +AC_DEFUN_ONCE([gl_AF_ALG], +[ + AC_REQUIRE([gl_HEADER_SYS_SOCKET]) + AC_CACHE_CHECK([whether linux/if_alg.h has struct sockaddr_alg.], + [gl_cv_header_linux_if_alg_salg], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([[#include + #include + struct sockaddr_alg salg = { + .salg_family = AF_ALG, + .salg_type = "hash", + .salg_name = "sha1", + };]])], + [gl_cv_header_linux_if_alg_salg=yes], + [gl_cv_header_linux_if_alg_salg=no])]) + if test "$gl_cv_header_linux_if_alg_salg" = yes; then + AC_DEFINE([HAVE_LINUX_IF_ALG_H], [1], + [Define to 1 if you have 'struct sockaddr_alg' defined.]) + fi +]) diff --git a/m4/linux-if-alg.m4 b/m4/linux-if-alg.m4 deleted file mode 100644 index 3ed18ae334..0000000000 --- a/m4/linux-if-alg.m4 +++ /dev/null @@ -1,29 +0,0 @@ -dnl Check whether linux/if_alg.h has needed features. - -dnl Copyright 2018 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 From Matteo Croce. - -AC_DEFUN_ONCE([gl_LINUX_IF_ALG_H], -[ - AC_REQUIRE([gl_HEADER_SYS_SOCKET]) - AC_CACHE_CHECK([whether linux/if_alg.h has struct sockaddr_alg.], - [gl_cv_header_linux_if_alg_salg], - [AC_COMPILE_IFELSE( - [AC_LANG_PROGRAM([[#include - #include - struct sockaddr_alg salg = { - .salg_family = AF_ALG, - .salg_type = "hash", - .salg_name = "sha1", - };]])], - [gl_cv_header_linux_if_alg_salg=yes], - [gl_cv_header_linux_if_alg_salg=no])]) - if test "$gl_cv_header_linux_if_alg_salg" = yes; then - AC_DEFINE([HAVE_LINUX_IF_ALG_H], [1], - [Define to 1 if you have `struct sockaddr_alg' defined.]) - fi -]) diff --git a/modules/crypto/af_alg b/modules/crypto/af_alg new file mode 100644 index 0000000000..c9602dc3b7 --- /dev/null +++ b/modules/crypto/af_alg @@ -0,0 +1,27 @@ +Description: +Compute message digest using kernel-supported cryptography algorithms. + +Files: +lib/af_alg.h +lib/af_alg.c +lib/sys-limits.h +m4/af_alg.m4 + +Depends-on: +sys_socket +sys_stat + +configure.ac: +gl_AF_ALG + +Makefile.am: +lib_SOURCES += af_alg.c + +Include: +"af_alg.h" + +License: +LGPLv2+ + +Maintainer: +all diff --git a/modules/crypto/md5 b/modules/crypto/md5 index 80f14c2fd2..1d5130b6b5 100644 --- a/modules/crypto/md5 +++ b/modules/crypto/md5 @@ -5,14 +5,11 @@ Files: lib/gl_openssl.h lib/md5.h lib/md5.c -lib/af_alg.h -lib/af_alg.c -lib/sys-limits.h m4/gl-openssl.m4 m4/md5.m4 -m4/linux-if-alg.m4 Depends-on: +crypto/af_alg extern-inline stdalign stdint @@ -21,10 +18,9 @@ sys_stat configure.ac: gl_MD5 -gl_LINUX_IF_ALG_H Makefile.am: -lib_SOURCES += md5.c af_alg.c +lib_SOURCES += md5.c Include: "md5.h" diff --git a/modules/crypto/sha1 b/modules/crypto/sha1 index 3bdf0ea0ae..90bd7e4791 100644 --- a/modules/crypto/sha1 +++ b/modules/crypto/sha1 @@ -5,14 +5,11 @@ Files: lib/gl_openssl.h lib/sha1.h lib/sha1.c -lib/af_alg.h -lib/af_alg.c -lib/sys-limits.h m4/gl-openssl.m4 m4/sha1.m4 -m4/linux-if-alg.m4 Depends-on: +crypto/af_alg extern-inline stdalign stdint @@ -21,10 +18,9 @@ sys_stat configure.ac: gl_SHA1 -gl_LINUX_IF_ALG_H Makefile.am: -lib_SOURCES += sha1.c af_alg.c +lib_SOURCES += sha1.c Include: "sha1.h" diff --git a/modules/crypto/sha256 b/modules/crypto/sha256 index d7c373581f..633bf04cbd 100644 --- a/modules/crypto/sha256 +++ b/modules/crypto/sha256 @@ -5,14 +5,11 @@ Files: lib/gl_openssl.h lib/sha256.h lib/sha256.c -lib/af_alg.h -lib/af_alg.c -lib/sys-limits.h m4/gl-openssl.m4 m4/sha256.m4 -m4/linux-if-alg.m4 Depends-on: +crypto/af_alg extern-inline stdalign stdint @@ -21,10 +18,9 @@ sys_stat configure.ac: gl_SHA256 -gl_LINUX_IF_ALG_H Makefile.am: -lib_SOURCES += sha256.c af_alg.c +lib_SOURCES += sha256.c Include: "sha256.h" diff --git a/modules/crypto/sha512 b/modules/crypto/sha512 index d6f9b9986d..cedc31c1dc 100644 --- a/modules/crypto/sha512 +++ b/modules/crypto/sha512 @@ -5,14 +5,11 @@ Files: lib/gl_openssl.h lib/sha512.h lib/sha512.c -lib/af_alg.h -lib/af_alg.c -lib/sys-limits.h m4/gl-openssl.m4 m4/sha512.m4 -m4/linux-if-alg.m4 Depends-on: +crypto/af_alg extern-inline stdalign stdint @@ -22,10 +19,9 @@ u64 configure.ac: gl_SHA512 -gl_LINUX_IF_ALG_H Makefile.am: -lib_SOURCES += sha512.c af_alg.c +lib_SOURCES += sha512.c Include: "sha512.h"