]> Savannah Git Hosting - gnulib.git/commitdiff
af_alg: New module.
authorBruno Haible <bruno@clisp.org>
Sat, 5 May 2018 18:27:33 +0000 (20:27 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 5 May 2018 18:34:30 +0000 (20:34 +0200)
* 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.

14 files changed:
ChangeLog
lib/af_alg.c
lib/af_alg.h
lib/md5.c
lib/sha1.c
lib/sha256.c
lib/sha512.c
m4/af_alg.m4 [new file with mode: 0644]
m4/linux-if-alg.m4 [deleted file]
modules/crypto/af_alg [new file with mode: 0644]
modules/crypto/md5
modules/crypto/sha1
modules/crypto/sha256
modules/crypto/sha512

index 82ab6c1c6dc8625d3578bbfbe6f06d0b7997326f..fd07f8b441aace6ea0404552bdea111693eb9ac0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,40 @@
+2018-05-05  Bruno Haible  <bruno@clisp.org>
+
+       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  <eggert@cs.ucla.edu>
 
        crypto tests: pacify GCC
index 519d6f8f3e04a44133aa6e1f498a0e9daccd1e17..dc3ac6aa1533f1525b45cf5312af9bcd282742b1 100644 (file)
@@ -19,7 +19,9 @@
 
 #include <config.h>
 
-#ifdef HAVE_LINUX_IF_ALG_H
+#if HAVE_LINUX_IF_ALG_H
+
+#include "af_alg.h"
 
 #include <unistd.h>
 #include <string.h>
@@ -28,8 +30,6 @@
 #include <sys/sendfile.h>
 #include <sys/socket.h>
 
-#include "af_alg.h"
-
 #include "sys-limits.h"
 
 #define BLOCKSIZE 32768
index aacb8f606a47ada9fc619cc973d061f3ba0207dc..295f0f9b599838eaf498802e689f26ee93110d0b 100644 (file)
@@ -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
index e6bd2099e5d783024b1a822904ba660d72bc72e4..2bf2f0c75ee048195ac27b4e500b1e21323e3350 100644 (file)
--- a/lib/md5.c
+++ b/lib/md5.c
@@ -32,9 +32,7 @@
 #include <string.h>
 #include <sys/types.h>
 
-#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)
index b670267c2b2514f8386d0f949f784e51b43dcec5..e7cd2a305a52ab54a7dda60c6287700af66092ea 100644 (file)
@@ -33,9 +33,7 @@
 #include <stdlib.h>
 #include <string.h>
 
-#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)
index fab119a16eec7cca84dd2d313cafe99ec2cc8765..410bd98c2e13b431455e7cb5fc5dd90bfbbd6339 100644 (file)
@@ -32,9 +32,7 @@
 #include <stdlib.h>
 #include <string.h>
 
-#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)
index ff7c0cb07dceb61553b2daae0fac2159dc250ae2..7a0234828b7e208274f3adfb6f63dfd71d376fb8 100644 (file)
@@ -32,9 +32,7 @@
 #include <stdlib.h>
 #include <string.h>
 
-#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 (file)
index 0000000..1c57e2c
--- /dev/null
@@ -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 <sys/socket.h>
+                          #include <linux/if_alg.h>
+                          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 (file)
index 3ed18ae..0000000
+++ /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 <sys/socket.h>
-                          #include <linux/if_alg.h>
-                          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 (file)
index 0000000..c9602dc
--- /dev/null
@@ -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
index 80f14c2fd2fe212f940904f9bf601cbf7d3eac8d..1d5130b6b5b607ba3bed9b3ce437cc7193dd1a0d 100644 (file)
@@ -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"
index 3bdf0ea0ae58d74ad3e01ee1a9cdc1d04b0d0c42..90bd7e4791c1fdf5364a4ceca1c2375d0de92f72 100644 (file)
@@ -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"
index d7c373581f134c85aea3a3fdbcd384fbd31fa8cb..633bf04cbdcac31c5ff32bcfc04d52417c608964 100644 (file)
@@ -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"
index d6f9b9986d9cb64c14e7ddd1e442b8b8c00602db..cedc31c1dc05e01fcac57dc8159d448f44eb034d 100644 (file)
@@ -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"