diff options
-rw-r--r-- | cipher/ChangeLog | 26 | ||||
-rw-r--r-- | cipher/blowfish.c | 14 | ||||
-rw-r--r-- | cipher/elgamal.c | 8 | ||||
-rw-r--r-- | cipher/md5.c | 17 | ||||
-rw-r--r-- | cipher/random.c | 4 | ||||
-rw-r--r-- | cipher/rijndael.c | 9 | ||||
-rw-r--r-- | cipher/rmd160.c | 17 | ||||
-rw-r--r-- | cipher/rndw32.c | 6 | ||||
-rw-r--r-- | cipher/sha1.c | 17 | ||||
-rw-r--r-- | cipher/tiger.c | 19 | ||||
-rw-r--r-- | cipher/twofish.c | 4 | ||||
-rw-r--r-- | mpi/ChangeLog | 8 | ||||
-rw-r--r-- | mpi/config.links | 38 | ||||
-rw-r--r-- | mpi/mpi-mul.c | 21 |
14 files changed, 130 insertions, 78 deletions
diff --git a/cipher/ChangeLog b/cipher/ChangeLog index daaaf1ab..1822f02e 100644 --- a/cipher/ChangeLog +++ b/cipher/ChangeLog @@ -1,3 +1,29 @@ +2001-03-29 Werner Koch <wk@gnupg.org> + + * md5.c (md5_final): Fixed calculation of hashed length. Thanks + to disastry@saiknes.lv for pointing out that it was horrible wrong + for more than 512MB of input. + * sha1.c (sha1_final): Ditto. + * rmd160.c (rmd160_final): Ditto. + * tiger.c (tiger_final): Ditto. + + * blowfish.c (encrypt,do_encrypt): Changed name to do_encrypt to + avoid name clashes with an encrypt function in stdlib.h of + Dynix/PIX. Thanks to Gene Carter. + * elgamal.c (encrypt,do_encrypt): Ditto. + + * twofish.c (gnupgext_enum_func): Use only when when compiled as a + module. + * rijndael.c (gnupgext_enum_func): Ditto. + + * tiger.c (tiger_get_info): Return "TIGER192" and not just + "TIGER". By Edwin Woudt. + + * random.c: Always include time.h - standard requirement. Thanks + to James Troup. + + * rndw32.c: Fixes to the macros. + 2001-01-11 Werner Koch <wk@gnupg.org> * cipher.c (cipher_encrypt,gcry_cipher_encrypt): Use blocksize and diff --git a/cipher/blowfish.c b/cipher/blowfish.c index e85b8520..660bdd8a 100644 --- a/cipher/blowfish.c +++ b/cipher/blowfish.c @@ -283,7 +283,7 @@ function_F( BLOWFISH_context *bc, u32 x ) static void -encrypt( BLOWFISH_context *bc, u32 *ret_xl, u32 *ret_xr ) +do_encrypt( BLOWFISH_context *bc, u32 *ret_xl, u32 *ret_xr ) { #if BLOWFISH_ROUNDS == 16 u32 xl, xr, *s0, *s1, *s2, *s3, *p; @@ -422,7 +422,7 @@ encrypt_block( BLOWFISH_context *bc, byte *outbuf, byte *inbuf ) d1 = inbuf[0] << 24 | inbuf[1] << 16 | inbuf[2] << 8 | inbuf[3]; d2 = inbuf[4] << 24 | inbuf[5] << 16 | inbuf[6] << 8 | inbuf[7]; - encrypt( bc, &d1, &d2 ); + do_encrypt( bc, &d1, &d2 ); outbuf[0] = (d1 >> 24) & 0xff; outbuf[1] = (d1 >> 16) & 0xff; outbuf[2] = (d1 >> 8) & 0xff; @@ -527,27 +527,27 @@ bf_setkey( BLOWFISH_context *c, byte *key, unsigned keylen ) datal = datar = 0; for(i=0; i < BLOWFISH_ROUNDS+2; i += 2 ) { - encrypt( c, &datal, &datar ); + do_encrypt( c, &datal, &datar ); c->p[i] = datal; c->p[i+1] = datar; } for(i=0; i < 256; i += 2 ) { - encrypt( c, &datal, &datar ); + do_encrypt( c, &datal, &datar ); c->s0[i] = datal; c->s0[i+1] = datar; } for(i=0; i < 256; i += 2 ) { - encrypt( c, &datal, &datar ); + do_encrypt( c, &datal, &datar ); c->s1[i] = datal; c->s1[i+1] = datar; } for(i=0; i < 256; i += 2 ) { - encrypt( c, &datal, &datar ); + do_encrypt( c, &datal, &datar ); c->s2[i] = datal; c->s2[i+1] = datar; } for(i=0; i < 256; i += 2 ) { - encrypt( c, &datal, &datar ); + do_encrypt( c, &datal, &datar ); c->s3[i] = datal; c->s3[i+1] = datar; } diff --git a/cipher/elgamal.c b/cipher/elgamal.c index d65f2d50..253edae8 100644 --- a/cipher/elgamal.c +++ b/cipher/elgamal.c @@ -50,7 +50,7 @@ static void test_keys( ELG_secret_key *sk, unsigned nbits ); static MPI gen_k( MPI p ); static void generate( ELG_secret_key *sk, unsigned nbits, MPI **factors ); static int check_secret_key( ELG_secret_key *sk ); -static void encrypt(MPI a, MPI b, MPI input, ELG_public_key *pkey ); +static void do_encrypt(MPI a, MPI b, MPI input, ELG_public_key *pkey ); static void decrypt(MPI output, MPI a, MPI b, ELG_secret_key *skey ); static void sign(MPI a, MPI b, MPI input, ELG_secret_key *skey); static int verify(MPI a, MPI b, MPI input, ELG_public_key *pkey); @@ -132,7 +132,7 @@ test_keys( ELG_secret_key *sk, unsigned nbits ) gcry_mpi_randomize( test, nbits, GCRY_WEAK_RANDOM ); - encrypt( out1_a, out1_b, test, &pk ); + do_encrypt( out1_a, out1_b, test, &pk ); decrypt( out2, out1_a, out1_b, sk ); if( mpi_cmp( test, out2 ) ) log_fatal("ElGamal operation: encrypt, decrypt failed\n"); @@ -337,7 +337,7 @@ check_secret_key( ELG_secret_key *sk ) static void -encrypt(MPI a, MPI b, MPI input, ELG_public_key *pkey ) +do_encrypt(MPI a, MPI b, MPI input, ELG_public_key *pkey ) { MPI k; @@ -552,7 +552,7 @@ elg_encrypt( int algo, MPI *resarr, MPI data, MPI *pkey ) pk.y = pkey[2]; resarr[0] = mpi_alloc( mpi_get_nlimbs( pk.p ) ); resarr[1] = mpi_alloc( mpi_get_nlimbs( pk.p ) ); - encrypt( resarr[0], resarr[1], data, &pk ); + do_encrypt( resarr[0], resarr[1], data, &pk ); return 0; } diff --git a/cipher/md5.c b/cipher/md5.c index c4351f1f..f7cc2ed1 100644 --- a/cipher/md5.c +++ b/cipher/md5.c @@ -258,18 +258,19 @@ md5_final( MD5_CONTEXT *hd ) md5_write(hd, NULL, 0); /* flush */; - msb = 0; t = hd->nblocks; - if( (lsb = t << 6) < t ) /* multiply by 64 to make a byte count */ - msb++; - msb += t >> 26; + /* multiply by 64 to make a byte count */ + lsb = t << 6; + msb = t >> 26; + /* add the count */ t = lsb; - if( (lsb = t + hd->count) < t ) /* add the count */ + if( (lsb += hd->count) < t ) msb++; + /* multiply by 8 to make a bit count */ t = lsb; - if( (lsb = t << 3) < t ) /* multiply by 8 to make a bit count */ - msb++; - msb += t >> 29; + lsb <<= 3; + msb <<= 3; + msb |= t >> 29; if( hd->count < 56 ) { /* enough room */ hd->buf[hd->count++] = 0x80; /* pad */ diff --git a/cipher/random.c b/cipher/random.c index 2d99f21a..5018fd12 100644 --- a/cipher/random.c +++ b/cipher/random.c @@ -37,15 +37,13 @@ #include <sys/stat.h> #include <unistd.h> #include <fcntl.h> +#include <time.h> #ifdef HAVE_GETHRTIME #include <sys/times.h> #endif #ifdef HAVE_GETTIMEOFDAY #include <sys/times.h> #endif -#ifdef HAVE_CLOCK_GETTIME - #include <time.h> -#endif #ifdef HAVE_GETRUSAGE #include <sys/resource.h> #endif diff --git a/cipher/rijndael.c b/cipher/rijndael.c index e852f042..2372240e 100644 --- a/cipher/rijndael.c +++ b/cipher/rijndael.c @@ -2121,9 +2121,7 @@ rijndael_get_info (int algo, size_t *keylen, } -#ifndef IS_MODULE -static -#endif +#ifdef IS_MODULE const char * const gnupgext_version = "RIJNDAEL ($Revision$)"; static struct { @@ -2155,9 +2153,6 @@ static struct { * version = interface version of the function/pointer * (currently this is 1 for all functions) */ -#ifndef IS_MODULE -static -#endif void * gnupgext_enum_func ( int what, int *sequence, int *class, int *vers ) { @@ -2186,7 +2181,7 @@ gnupgext_enum_func ( int what, int *sequence, int *class, int *vers ) *sequence = i; return ret; } - +#endif diff --git a/cipher/rmd160.c b/cipher/rmd160.c index 381e6531..d7f3bb0c 100644 --- a/cipher/rmd160.c +++ b/cipher/rmd160.c @@ -461,18 +461,19 @@ rmd160_final( RMD160_CONTEXT *hd ) rmd160_write(hd, NULL, 0); /* flush */; - msb = 0; t = hd->nblocks; - if( (lsb = t << 6) < t ) /* multiply by 64 to make a byte count */ - msb++; - msb += t >> 26; + /* multiply by 64 to make a byte count */ + lsb = t << 6; + msb = t >> 26; + /* add the count */ t = lsb; - if( (lsb = t + hd->count) < t ) /* add the count */ + if( (lsb += hd->count) < t ) msb++; + /* multiply by 8 to make a bit count */ t = lsb; - if( (lsb = t << 3) < t ) /* multiply by 8 to make a bit count */ - msb++; - msb += t >> 29; + lsb <<= 3; + msb <<= 3; + msb |= t >> 29; if( hd->count < 56 ) { /* enough room */ hd->buf[hd->count++] = 0x80; /* pad */ diff --git a/cipher/rndw32.c b/cipher/rndw32.c index ae9f4bca..993fafd2 100644 --- a/cipher/rndw32.c +++ b/cipher/rndw32.c @@ -299,15 +299,21 @@ gather_random_fast( void (*add)(const void*, size_t, int), int requester ) * Definitions which are missing from the current GNU Windows32Api */ +#ifndef TH32CS_SNAPHEAPLIST #define TH32CS_SNAPHEAPLIST 1 #define TH32CS_SNAPPROCESS 2 #define TH32CS_SNAPTHREAD 4 #define TH32CS_SNAPMODULE 8 #define TH32CS_SNAPALL (1|2|4|8) #define TH32CS_INHERIT 0x80000000 +#endif /*TH32CS_SNAPHEAPLIST*/ +#ifndef IOCTL_DISK_PERFORMANCE #define IOCTL_DISK_PERFORMANCE 0x00070020 +#endif +#ifndef VER_PLATFORM_WIN32_WINDOWS #define VER_PLATFORM_WIN32_WINDOWS 1 +#endif typedef struct { diff --git a/cipher/sha1.c b/cipher/sha1.c index 9c7369c5..da9bd153 100644 --- a/cipher/sha1.c +++ b/cipher/sha1.c @@ -254,18 +254,19 @@ sha1_final(SHA1_CONTEXT *hd) sha1_write(hd, NULL, 0); /* flush */; - msb = 0; t = hd->nblocks; - if( (lsb = t << 6) < t ) /* multiply by 64 to make a byte count */ - msb++; - msb += t >> 26; + /* multiply by 64 to make a byte count */ + lsb = t << 6; + msb = t >> 26; + /* add the count */ t = lsb; - if( (lsb = t + hd->count) < t ) /* add the count */ + if( (lsb += hd->count) < t ) msb++; + /* multiply by 8 to make a bit count */ t = lsb; - if( (lsb = t << 3) < t ) /* multiply by 8 to make a bit count */ - msb++; - msb += t >> 29; + lsb <<= 3; + msb <<= 3; + msb |= t >> 29; if( hd->count < 56 ) { /* enough room */ hd->buf[hd->count++] = 0x80; /* pad */ diff --git a/cipher/tiger.c b/cipher/tiger.c index e68959ca..7152492e 100644 --- a/cipher/tiger.c +++ b/cipher/tiger.c @@ -805,18 +805,19 @@ tiger_final( TIGER_CONTEXT *hd ) tiger_write(hd, NULL, 0); /* flush */; - msb = 0; t = hd->nblocks; - if( (lsb = t << 6) < t ) /* multiply by 64 to make a byte count */ - msb++; - msb += t >> 26; + /* multiply by 64 to make a byte count */ + lsb = t << 6; + msb = t >> 26; + /* add the count */ t = lsb; - if( (lsb = t + hd->count) < t ) /* add the count */ + if( (lsb += hd->count) < t ) msb++; + /* multiply by 8 to make a bit count */ t = lsb; - if( (lsb = t << 3) < t ) /* multiply by 8 to make a bit count */ - msb++; - msb += t >> 29; + lsb <<= 3; + msb <<= 3; + msb |= t >> 29; if( hd->count < 56 ) { /* enough room */ hd->buf[hd->count++] = 0x01; /* pad */ @@ -904,7 +905,7 @@ tiger_get_info( int algo, size_t *contextsize, *(void (**)(TIGER_CONTEXT *))r_final = tiger_final; *(byte *(**)(TIGER_CONTEXT *))r_read = tiger_read; - return "TIGER"; + return "TIGER192"; } diff --git a/cipher/twofish.c b/cipher/twofish.c index 5766021c..ffd75360 100644 --- a/cipher/twofish.c +++ b/cipher/twofish.c @@ -1002,7 +1002,7 @@ twofish_get_info (int algo, size_t *keylen, return NULL; } - +#ifdef IS_MODULE const char * const gnupgext_version = "TWOFISH ($Revision$)"; static struct { @@ -1061,4 +1061,4 @@ gnupgext_enum_func ( int what, int *sequence, int *class, int *vers ) *sequence = i; return ret; } - +#endif /*IS_MODULE*/ diff --git a/mpi/ChangeLog b/mpi/ChangeLog index c1a10811..a9ce8dea 100644 --- a/mpi/ChangeLog +++ b/mpi/ChangeLog @@ -1,3 +1,11 @@ +2001-03-29 Werner Koch <wk@gnupg.org> + + * mpi-mul.c (mpi_mul): Make sure that secret temporary results are + not stored in w. Suggested by Florian Weimer. + + * config.links: Use i386 code for i386. According to tests by + Kevin Ryde the i586 code runs slow on i386 CPUs. Ditto for i786. + 2001-01-11 Werner Koch <wk@gnupg.org> * Makefile.am: Removed mpi.h. diff --git a/mpi/config.links b/mpi/config.links index 2a261ed3..48c7977c 100644 --- a/mpi/config.links +++ b/mpi/config.links @@ -12,18 +12,18 @@ echo '/* created by config.links - do not edit */' >./mpi/asm-syntax.h if test "$try_asm_modules" = "yes" ; then case "${target}" in - i[34]86*-*-freebsd*-elf | \ - i[34]86*-*-freebsd[3-9]* | \ - i[34]86*-*-freebsdelf* | \ - i[34]86*-*-netbsd* ) + i[3467]86*-*-freebsd*-elf | \ + i[3467]86*-*-freebsd[3-9]* | \ + i[3467]86*-*-freebsdelf* | \ + i[3467]86*-*-netbsd* ) echo '#define ELF_SYNTAX' >>./mpi/asm-syntax.h cat $srcdir/mpi/i386/syntax.h >>./mpi/asm-syntax.h path="i386" ;; - i[56]86*-*-freebsd*-elf | \ - i[56]86*-*-freebsd[3-9]* | \ - i[56]86*-*-freebsdelf* | \ - i[56]86*-*-netbsd* | \ + i586*-*-freebsd*-elf | \ + i586*-*-freebsd[3-9]* | \ + i586*-*-freebsdelf* | \ + i586*-*-netbsd* | \ pentium-*-netbsd* | \ pentiumpro-*-netbsd*) echo '#define ELF_SYNTAX' >>./mpi/asm-syntax.h @@ -35,38 +35,38 @@ case "${target}" in cat $srcdir/mpi/i386/syntax.h >>./mpi/asm-syntax.h path="i386" ;; - i[34]86*-*-linuxaout* | \ - i[34]86*-*-linuxoldld* | \ - i[34]86*-*-*bsd*) + i[3467]86*-*-linuxaout* | \ + i[3467]86*-*-linuxoldld* | \ + i[3467]86*-*-*bsd*) echo '#define BSD_SYNTAX' >>./mpi/asm-syntax.h echo '#define X86_BROKEN_ALIGN' >>./mpi/asm-syntax.h cat $srcdir/mpi/i386/syntax.h >>./mpi/asm-syntax.h path="i386" ;; - i[56]86*-*-linuxaout* | \ - i[56]86*-*-linuxoldld* | \ - i[56]86*-*-*bsd*) + i586*-*-linuxaout* | \ + i586*-*-linuxoldld* | \ + i586*-*-*bsd*) echo '#define BSD_SYNTAX' >>./mpi/asm-syntax.h echo '#define X86_BROKEN_ALIGN' >>./mpi/asm-syntax.h cat $srcdir/mpi/i386/syntax.h >>./mpi/asm-syntax.h path="i586 i386" ;; - i[34]86*-msdosdjgpp*) + i[3467]86*-msdosdjgpp*) echo '#define BSD_SYNTAX' >>./mpi/asm-syntax.h cat $srcdir/mpi/i386/syntax.h >>./mpi/asm-syntax.h path="i386" ;; - i[56]86*-msdosdjgpp*) + i586*-msdosdjgpp*) echo '#define BSD_SYNTAX' >>./mpi/asm-syntax.h cat $srcdir/mpi/i386/syntax.h >>./mpi/asm-syntax.h path="i586 i386" ;; - i[34]86*-*-*) + i[3467]86*-*-*) echo '#define ELF_SYNTAX' >>./mpi/asm-syntax.h cat $srcdir/mpi/i386/syntax.h >>./mpi/asm-syntax.h path="i386" ;; - i[56]86*-*-* | \ + i586*-*-* | \ pentium-*-* | \ pentiumpro-*-*) echo '#define ELF_SYNTAX' >>./mpi/asm-syntax.h @@ -187,7 +187,6 @@ case "${target}" in path="powerpc32" ;; - rs6000-*-aix[456789]* | \ rs6000-*-aix3.2.[456789]) mpi_sflags="-Wa,-mpwr" @@ -288,4 +287,3 @@ for dir in $path ; do break; fi done - diff --git a/mpi/mpi-mul.c b/mpi/mpi-mul.c index 082d179e..280e47a9 100644 --- a/mpi/mpi-mul.c +++ b/mpi/mpi-mul.c @@ -120,6 +120,7 @@ mpi_mul( MPI w, MPI u, MPI v) int assign_wp=0; mpi_ptr_t tmp_limb=NULL; + if( u->nlimbs < v->nlimbs ) { /* Swap U and V. */ usize = v->nlimbs; usign = v->sign; @@ -145,7 +146,15 @@ mpi_mul( MPI w, MPI u, MPI v) /* Ensure W has space enough to store the result. */ wsize = usize + vsize; - if( w->alloced < wsize ) { + if ( !mpi_is_secure (w) && (mpi_is_secure (u) || mpi_is_secure (v)) ) { + /* w is not allocated in secure space but u or v is. To make sure + * that no temporray results are stored in w, we temporary use + * a newly allocated limb space for w */ + wp = mpi_alloc_limb_space( wsize, 1 ); + assign_wp = 2; /* mark it as 2 so that we can later copy it back to + * mormal memory */ + } + else if( w->alloced < wsize ) { if( wp == up || wp == vp ) { wp = mpi_alloc_limb_space( wsize, mpi_is_secure(w) ); assign_wp = 1; @@ -180,8 +189,16 @@ mpi_mul( MPI w, MPI u, MPI v) wsize -= cy? 0:1; } - if( assign_wp ) + if( assign_wp ) { + if (assign_wp == 2) { + /* copy the temp wp from secure memory back to normal memory */ + mpi_ptr_t tmp_wp = mpi_alloc_limb_space (wsize, 0); + MPN_COPY (tmp_wp, wp, wsize); + mpi_free_limb_space (wp); + wp = tmp_wp; + } mpi_assign_limb_space( w, wp, wsize ); + } w->nlimbs = wsize; w->sign = sign_product; if( tmp_limb ) |