diff options
Diffstat (limited to 'cipher')
-rw-r--r-- | cipher/Makefile.in | 2 | ||||
-rw-r--r-- | cipher/blowfish.c | 2 | ||||
-rw-r--r-- | cipher/elgamal.c | 28 | ||||
-rw-r--r-- | cipher/md5.c | 13 | ||||
-rw-r--r-- | cipher/rmd160.c | 17 | ||||
-rw-r--r-- | cipher/sha1.c | 22 |
6 files changed, 67 insertions, 17 deletions
diff --git a/cipher/Makefile.in b/cipher/Makefile.in index 9e4860f6a..e4ab5edac 100644 --- a/cipher/Makefile.in +++ b/cipher/Makefile.in @@ -130,7 +130,7 @@ AR = ar CFLAGS = @CFLAGS@ COMPILE = $(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) LINK = $(CC) $(CFLAGS) $(LDFLAGS) -o $@ -DIST_COMMON = Makefile.am Makefile.in +DIST_COMMON = ChangeLog Makefile.am Makefile.in DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) diff --git a/cipher/blowfish.c b/cipher/blowfish.c index 81e33d080..8e3a49301 100644 --- a/cipher/blowfish.c +++ b/cipher/blowfish.c @@ -228,7 +228,7 @@ static const u32 ps[BLOWFISH_ROUNDS+2] = { -static u32 +static inline u32 function_F( BLOWFISH_context *bc, u32 x ) { u16 a, b, c, d; diff --git a/cipher/elgamal.c b/cipher/elgamal.c index 5e6bd0c84..13b8579fe 100644 --- a/cipher/elgamal.c +++ b/cipher/elgamal.c @@ -311,25 +311,37 @@ elg_verify(MPI a, MPI b, MPI input, ELG_public_key *pkey ) int rc; MPI t1; MPI t2; + MPI base[4]; + MPI exp[4]; if( !(mpi_cmp_ui( a, 0 ) > 0 && mpi_cmp( a, pkey->p ) < 0) ) return 0; /* assertion 0 < a < p failed */ t1 = mpi_alloc( mpi_get_nlimbs(a) ); t2 = mpi_alloc( mpi_get_nlimbs(a) ); - /* t1 = (y^a mod p) * (a^b mod p) mod p - * fixme: should be calculated by a call which evalutes - * t1 = y^a * a^b mod p - * direct. - */ - mpi_powm( t1, pkey->y, a, pkey->p ); - mpi_powm( t2, a, b, pkey->p ); - mpi_mulm( t1, t1, t2, pkey->p ); + + #if 0 + /* t1 = (y^a mod p) * (a^b mod p) mod p */ + base[0] = pkey->y; exp[0] = a; + base[1] = a; exp[1] = b; + base[2] = NULL; exp[2] = NULL; + mpi_mulpowm( t1, base, exp, pkey->p ); /* t2 = g ^ input mod p */ mpi_powm( t2, pkey->g, input, pkey->p ); rc = !mpi_cmp( t1, t2 ); + #else + /* t1 = g ^ - input * y ^ a * a ^ b mod p */ + mpi_invm(t2, pkey->g, pkey->p ); + base[0] = t2 ; exp[0] = input; + base[1] = pkey->y; exp[1] = a; + base[2] = a; exp[2] = b; + base[3] = NULL; exp[3] = NULL; + mpi_mulpowm( t1, base, exp, pkey->p ); + rc = !mpi_cmp_ui( t1, 1 ); + + #endif mpi_free(t1); mpi_free(t2); diff --git a/cipher/md5.c b/cipher/md5.c index c9f9a86b4..ef95c7ef8 100644 --- a/cipher/md5.c +++ b/cipher/md5.c @@ -93,7 +93,18 @@ static byte PADDING[64] = { #define I(x, y, z) ((y) ^ ((x) | (~z))) /* ROTATE_LEFT rotates x left n bits */ -#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) +#if defined(__GNUC__) && defined(__i386__) +static inline u32 +ROTATE_LEFT(u32 x, int n) +{ + __asm__("roll %%cl,%0" + :"=r" (x) + :"0" (x),"c" (n)); + return x; +} +#else + #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) +#endif /* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4 */ /* Rotation is separate from addition to prevent recomputation */ diff --git a/cipher/rmd160.c b/cipher/rmd160.c index 0b501d77b..39f1c740c 100644 --- a/cipher/rmd160.c +++ b/cipher/rmd160.c @@ -151,6 +151,20 @@ 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 */ @@ -209,9 +223,6 @@ transform( RMD160_CONTEXT *hd, byte *data ) (a) < 64 ? F3((x),(y),(z)) : \ F4((x),(y),(z)) ) -#define rol(n,x) ( ((x) << (n)) | ((x) >> (32-(n))) ) - - #ifdef BIG_ENDIAN_HOST { int i; byte *p2, *p1; diff --git a/cipher/sha1.c b/cipher/sha1.c index 51029c451..a54ec6a80 100644 --- a/cipher/sha1.c +++ b/cipher/sha1.c @@ -99,14 +99,30 @@ #define K3 0x8F1BBCDCL /* Rounds 40-59 */ #define K4 0xCA62C1D6L /* Rounds 60-79 */ -#define ROTL(n,X) ( ( ( X ) << n ) | ( ( X ) >> ( 32 - n ) ) ) + +#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 + + + + #define expand(W,i) ( W[ i & 15 ] = \ - ROTL( 1, ( W[ i & 15 ] ^ W[ (i - 14) & 15 ] ^ \ + rol( 1, ( W[ i & 15 ] ^ W[ (i - 14) & 15 ] ^ \ W[ (i - 8) & 15 ] ^ W[ (i - 3) & 15 ] ) ) ) #define subRound(a, b, c, d, e, f, k, data) \ - ( e += ROTL( 5, a ) + f( b, c, d ) + k + data, b = ROTL( 30, b ) ) + ( e += rol( 5, a ) + f( b, c, d ) + k + data, b = rol( 30, b ) ) void |