From fcce0cb6e8af70b134c6ecc3f56afa07a7d31f27 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Thu, 31 Mar 2016 20:16:10 +0200 Subject: cipher: Remove specialized rmd160 functions. * cipher/rmd160.c: Replace rmd.h by hash-common.h. (RMD160_CONTEXT): Move from rmd.h to here. (_gcry_rmd160_init): Remove. (_gcry_rmd160_mixblock): Remove. (_gcry_rmd160_hash_buffer): Use rmd160_init directly. * cipher/md.c: Remove rmd.h which was not actually used. * cipher/rmd.h: Remove. * cipher/Makefile.am (libcipher_la_SOURCES): Remove rmd.h. * configure.ac (USE_RMD160): Allow to build without RMD160. -- Those functions are not anymore required because random-csprng.c now uses SHA-1. Signed-off-by: Werner Koch --- cipher/Makefile.am | 2 +- cipher/md.c | 2 -- cipher/rmd.h | 35 ----------------------------------- cipher/rmd160.c | 45 +++++++++++---------------------------------- configure.ac | 12 +++++++++--- 5 files changed, 21 insertions(+), 75 deletions(-) delete mode 100644 cipher/rmd.h diff --git a/cipher/Makefile.am b/cipher/Makefile.am index 85248a2d..f60338a6 100644 --- a/cipher/Makefile.am +++ b/cipher/Makefile.am @@ -57,7 +57,7 @@ bufhelp.h \ primegen.c \ hash-common.c hash-common.h \ dsa-common.c rsa-common.c \ -sha1.h rmd.h +sha1.h EXTRA_libcipher_la_SOURCES = \ arcfour.c arcfour-amd64.S \ diff --git a/cipher/md.c b/cipher/md.c index 5b4f0c13..d0ef00fe 100644 --- a/cipher/md.c +++ b/cipher/md.c @@ -28,8 +28,6 @@ #include "g10lib.h" #include "cipher.h" -#include "rmd.h" - /* This is the list of the digest implementations included in libgcrypt. */ diff --git a/cipher/rmd.h b/cipher/rmd.h deleted file mode 100644 index a56ee49c..00000000 --- a/cipher/rmd.h +++ /dev/null @@ -1,35 +0,0 @@ -/* rmd.h - RIPE-MD hash functions - * Copyright (C) 1998, 2001, 2002 Free Software Foundation, Inc. - * - * This file is part of Libgcrypt. - * - * Libgcrypt is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * Libgcrypt is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ -#ifndef G10_RMD_H -#define G10_RMD_H - -#include "hash-common.h" - -/* We need this here because random.c must have direct access. */ -typedef struct -{ - gcry_md_block_ctx_t bctx; - u32 h0,h1,h2,h3,h4; -} RMD160_CONTEXT; - -void _gcry_rmd160_init ( void *context ); -void _gcry_rmd160_mixblock ( RMD160_CONTEXT *hd, void *blockof64byte ); - -#endif /*G10_RMD_H*/ diff --git a/cipher/rmd160.c b/cipher/rmd160.c index cf7531e5..0a019b9c 100644 --- a/cipher/rmd160.c +++ b/cipher/rmd160.c @@ -24,7 +24,7 @@ #include #include "g10lib.h" -#include "rmd.h" +#include "hash-common.h" #include "cipher.h" /* Only used for the rmd160_hash_buffer() prototype. */ #include "bithelp.h" @@ -140,6 +140,13 @@ * 1 million times "a" 52783243c1697bdbe16d37f97f68f08325dc1528 */ +typedef struct +{ + gcry_md_block_ctx_t bctx; + u32 h0,h1,h2,h3,h4; +} RMD160_CONTEXT; + + static unsigned int transform ( void *ctx, const unsigned char *data, size_t nblks ); @@ -164,13 +171,6 @@ rmd160_init (void *context, unsigned int flags) } -void -_gcry_rmd160_init (void *context) -{ - rmd160_init (context, 0); -} - - /**************** * Transform the message X which consists of 16 32-bit-words */ @@ -399,32 +399,9 @@ transform ( void *c, const unsigned char *data, size_t nblks ) } -/**************** - * Apply the rmd160 transform function on the buffer which must have - * a length 64 bytes. Do not use this function together with the - * other functions, use rmd160_init to initialize internal variables. - * Buffer must be 32-bit aligned. - * Returns: 20 bytes in buffer with the mixed contents of buffer. +/* + * The routine terminates the computation */ -void -_gcry_rmd160_mixblock ( RMD160_CONTEXT *hd, void *blockof64byte ) -{ - u32 *p = blockof64byte; - - transform ( hd, blockof64byte, 1 ); -#define X(a) do { p[a] = hd->h##a; } while(0) - X(0); - X(1); - X(2); - X(3); - X(4); -#undef X -} - - -/* The routine terminates the computation - */ - static void rmd160_final( void *context ) { @@ -503,7 +480,7 @@ _gcry_rmd160_hash_buffer (void *outbuf, const void *buffer, size_t length ) { RMD160_CONTEXT hd; - _gcry_rmd160_init ( &hd ); + rmd160_init (&hd, 0); _gcry_md_block_write ( &hd, buffer, length ); rmd160_final ( &hd ); memcpy ( outbuf, hd.bctx.buf, 20 ); diff --git a/configure.ac b/configure.ac index 6a2d61bf..716c6ece 100644 --- a/configure.ac +++ b/configure.ac @@ -2066,6 +2066,12 @@ if test "$found" = "1" ; then AC_DEFINE(USE_MD5, 1, [Defined if this module should be included]) fi +LIST_MEMBER(rmd160, $enabled_digests) +if test "$found" = "1" ; then + GCRYPT_DIGESTS="$GCRYPT_DIGESTS rmd160.lo" + AC_DEFINE(USE_RMD160, 1, [Defined if this module should be included]) +fi + LIST_MEMBER(sha256, $enabled_digests) if test "$found" = "1" ; then GCRYPT_DIGESTS="$GCRYPT_DIGESTS sha256.lo" @@ -2142,9 +2148,9 @@ if test "$found" = "1" ; then esac fi -# rmd160 and sha1 should be included always. -GCRYPT_DIGESTS="$GCRYPT_DIGESTS rmd160.lo sha1.lo" -AC_DEFINE(USE_RMD160, 1, [Defined if this module should be included]) +# SHA-1 needs to be included always for example because it is used by +# random-csprng.c. +GCRYPT_DIGESTS="$GCRYPT_DIGESTS sha1.lo" AC_DEFINE(USE_SHA1, 1, [Defined if this module should be included]) case "${host}" in -- cgit v1.2.1