diff options
author | Werner Koch <wk@gnupg.org> | 1999-09-13 08:56:41 +0000 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 1999-09-13 08:56:41 +0000 |
commit | 6d57d176567a469dd3caf8cae45702a1451a06ad (patch) | |
tree | f67dd15f0bd2e5d8bccbd8b100d6191efbd54fd5 | |
parent | 2a8d5684daee285e1658856db147dd83fdb107d6 (diff) | |
download | libgcrypt-6d57d176567a469dd3caf8cae45702a1451a06ad.tar.gz |
See ChangeLog: Mon Sep 13 10:55:14 CEST 1999 Werner Koch
-rw-r--r-- | cipher/ChangeLog | 6 | ||||
-rw-r--r-- | cipher/Makefile.am | 1 | ||||
-rw-r--r-- | cipher/bithelp.h | 41 | ||||
-rw-r--r-- | cipher/md5.c | 10 | ||||
-rw-r--r-- | cipher/rmd160.c | 19 | ||||
-rw-r--r-- | cipher/sha1.c | 19 |
6 files changed, 59 insertions, 37 deletions
diff --git a/cipher/ChangeLog b/cipher/ChangeLog index 6ad5648d..584a7557 100644 --- a/cipher/ChangeLog +++ b/cipher/ChangeLog @@ -1,3 +1,9 @@ +Mon Sep 13 10:51:29 CEST 1999 Werner Koch <wk@isil.d.shuttle.de> + + + * bithelp.h: New. + * rmd160.h, sha1.h, md5.h: Use the rol macro from bithelp.h + Tue Sep 7 16:23:36 CEST 1999 Werner Koch <wk@isil.d.shuttle.de> diff --git a/cipher/Makefile.am b/cipher/Makefile.am index 5680a4e9..4b2ef2e3 100644 --- a/cipher/Makefile.am +++ b/cipher/Makefile.am @@ -39,6 +39,7 @@ libcipher_la_SOURCES = cipher.c \ md.c \ dynload.c \ dynload.h \ + bithelp.h \ des.c \ des.h \ twofish.c \ diff --git a/cipher/bithelp.h b/cipher/bithelp.h new file mode 100644 index 00000000..188db168 --- /dev/null +++ b/cipher/bithelp.h @@ -0,0 +1,41 @@ +/* bithelp.h - Some bit manipulation helpers + * Copyright (C) 1999 Free Software Foundation, Inc. + * + * This file is part of GnuPG. + * + * GnuPG is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GnuPG 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 General Public License for more details. + * + * You should have received a copy of the GNU 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_BITHELP_H +#define G10_BITHELP_H + + +/**************** + * Rotate a 32 bit integer by n bytes + */ +#if defined(__GNUC__) && defined(__i386__) +static inline u32 +rol( u32 x, int n) +{ + __asm__("roll %%cl,%0" + :"=r" (x) + :"0" (x),"c" (n)); + return x; +} +#else + #define rol(x,n) ( ((x) << (n)) | ((x) >> (32-(n))) ) +#endif + + +#endif /*G10_BITHELP_H*/ diff --git a/cipher/md5.c b/cipher/md5.c index 035eaf11..bb930d04 100644 --- a/cipher/md5.c +++ b/cipher/md5.c @@ -37,6 +37,8 @@ #include "memory.h" #include "dynload.h" +#include "bithelp.h" + typedef struct { u32 A,B,C,D; /* chaining variables */ @@ -104,15 +106,11 @@ transform( MD5_CONTEXT *ctx, byte *data ) do \ { \ a += FF (b, c, d) + (*cwp++) + T; \ - CYCLIC (a, s); \ + a = rol(a, s); \ a += b; \ } \ while (0) - /* It is unfortunate that C does not provide an operator for - cyclic rotation. Hope the C compiler is smart enough. */ -#define CYCLIC(w, s) (w = (w << s) | (w >> (32 - s))) - /* Before we start, one word about the strange constants. They are defined in RFC 1321 as @@ -142,7 +140,7 @@ transform( MD5_CONTEXT *ctx, byte *data ) do \ { \ a += f (b, c, d) + correct_words[k] + T; \ - CYCLIC (a, s); \ + a = rol(a, s); \ a += b; \ } \ while (0) diff --git a/cipher/rmd160.c b/cipher/rmd160.c index e8771883..ecd65b35 100644 --- a/cipher/rmd160.c +++ b/cipher/rmd160.c @@ -29,6 +29,8 @@ #include "cipher.h" /* only used for the rmd160_hash_buffer() prototype */ #include "dynload.h" +#include "bithelp.h" + /********************************* * RIPEMD-160 is not patented, see (as of 25.10.97) * http://www.esat.kuleuven.ac.be/~bosselae/ripemd160.html @@ -153,19 +155,6 @@ rmd160_init( RMD160_CONTEXT *hd ) } -#if defined(__GNUC__) && defined(__i386__) -static inline u32 -rol(int n, u32 x) -{ - __asm__("roll %%cl,%0" - :"=r" (x) - :"0" (x),"c" (n)); - return x; -} -#else - #define rol(n,x) ( ((x) << (n)) | ((x) >> (32-(n))) ) -#endif - /**************** * Transform the message X which consists of 16 32-bit-words @@ -218,8 +207,8 @@ transform( RMD160_CONTEXT *hd, byte *data ) #define F3(x,y,z) ( ((x) & (z)) | ((y) & ~(z)) ) #define F4(x,y,z) ( (x) ^ ((y) | ~(z)) ) #define R(a,b,c,d,e,f,k,r,s) do { t = a + f(b,c,d) + k + x[r]; \ - a = rol(s,t) + e; \ - c = rol(10,c); \ + a = rol(t,s) + e; \ + c = rol(c,10); \ } while(0) /* left lane */ diff --git a/cipher/sha1.c b/cipher/sha1.c index 04bdbac9..40ad62f1 100644 --- a/cipher/sha1.c +++ b/cipher/sha1.c @@ -39,6 +39,7 @@ #include "util.h" #include "memory.h" #include "dynload.h" +#include "bithelp.h" typedef struct { @@ -49,20 +50,6 @@ typedef struct { } SHA1_CONTEXT; -#if defined(__GNUC__) && defined(__i386__) -static inline u32 -rol(int n, u32 x) -{ - __asm__("roll %%cl,%0" - :"=r" (x) - :"0" (x),"c" (n)); - return x; -} -#else - #define rol(n,x) ( ((x) << (n)) | ((x) >> (32-(n))) ) -#endif - - void @@ -123,11 +110,11 @@ transform( SHA1_CONTEXT *hd, byte *data ) ^ x[(i-8)&0x0f] ^ x[(i-3)&0x0f] \ , (x[i&0x0f] = (tm << 1) | (tm >> 31)) ) -#define R(a,b,c,d,e,f,k,m) do { e += rol( 5, a ) \ +#define R(a,b,c,d,e,f,k,m) do { e += rol( a, 5 ) \ + f( b, c, d ) \ + k \ + m; \ - b = rol( 30, b ); \ + b = rol( b, 30 ); \ } while(0) R( a, b, c, d, e, F1, K1, x[ 0] ); R( e, a, b, c, d, F1, K1, x[ 1] ); |