summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>1999-02-24 10:12:28 +0000
committerWerner Koch <wk@gnupg.org>1999-02-24 10:12:28 +0000
commit3ce95e16405624c50413c443edc09e16fa87149a (patch)
tree41f549b73250f7180bebb42ce2fa2e58bdc324dc
parent16dc1fd523cb67d95b1cb4b01e06354863879b16 (diff)
downloadlibgcrypt-3ce95e16405624c50413c443edc09e16fa87149a.tar.gz
See ChangeLog: Wed Feb 24 11:07:27 CET 1999 Werner Koch
-rw-r--r--AUTHORS1
-rw-r--r--ChangeLog4
-rw-r--r--THANKS4
-rw-r--r--cipher/ChangeLog7
-rw-r--r--cipher/cipher.c22
-rw-r--r--cipher/md.c35
-rw-r--r--cipher/rndegd.c84
-rw-r--r--cipher/rndunix.c3
-rw-r--r--configure.in76
-rw-r--r--mpi/ChangeLog5
-rw-r--r--mpi/mips3/mpih-sub1.S2
11 files changed, 159 insertions, 84 deletions
diff --git a/AUTHORS b/AUTHORS
index d69b1757..01a837c1 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -56,6 +56,7 @@ es_ES.po
TRANSLATIONS Thiago Jung Bauermann ????????????????
pt_BR.po
+jungmann@cwb.matrix.com.br
TRANSLATIONS Janusz A. Urbanowicz ???????????
diff --git a/ChangeLog b/ChangeLog
index c6447569..fc78f89a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Wed Feb 24 11:07:27 CET 1999 Werner Koch <wk@isil.d.shuttle.de>
+
+ * configure.in: New option --enable-static-rnd.
+
Mon Feb 22 20:04:00 CET 1999 Werner Koch <wk@isil.d.shuttle.de>
* BUGS: Now we assign bug numbers.
diff --git a/THANKS b/THANKS
index 3bc233f4..be926061 100644
--- a/THANKS
+++ b/THANKS
@@ -37,6 +37,7 @@ Janusz A. Urbanowicz alex@bofh.torun.pl
James Troup james@nocrew.org
Jean-loup Gailly gzip@prep.ai.mit.edu
Jens Bachem bachem@rrz.uni-koeln.de
+Joachim Backes backes@rhrk.uni-kl.de
John A. Martin jam@jamux.com
Johnny Teveßen j.tevessen@gmx.de
Jörg Schilling schilling@fokus.gmd.de
@@ -64,6 +65,7 @@ Philippe Laliberte arsphl@oeil.qc.ca
Peter Gutmann pgut001@cs.auckland.ac.nz
QingLong qinglong@bolizm.ihep.su
Ralph Gillen gillen@theochem.uni-duesseldorf.de
+Rat ratinox@peorth.gweep.net
Reinhard Wobst R.Wobst@ifw-dresden.de
Reuben Sumner rasumner@wisdom.weizmann.ac.il
Roddy Strachan roddy@satlink.com.au
@@ -76,7 +78,7 @@ Steffen Ullrich ccrlphr@xensei.com
Steffen Zahn zahn@berlin.snafu.de
Steven Bakker steven@icoe.att.com
Susanne Schultz schultz@hsp.de
-Thiago Jung Bauermann jungmann@usa.net
+Thiago Jung Bauermann jungmann@cwb.matrix.com.br
Thomas Roessler roessler@guug.de
Tom Spindler dogcow@home.merit.edu
Tom Zerucha tzeruch@ceddec.com
diff --git a/cipher/ChangeLog b/cipher/ChangeLog
index a11af403..442591f1 100644
--- a/cipher/ChangeLog
+++ b/cipher/ChangeLog
@@ -1,3 +1,10 @@
+Wed Feb 24 11:07:27 CET 1999 Werner Koch <wk@isil.d.shuttle.de>
+
+ * cipher.c (context): Fixed alignment
+ * md.c: Ditto.
+
+ * rndegd.c: New
+
Mon Feb 22 20:04:00 CET 1999 Werner Koch <wk@isil.d.shuttle.de>
* rndegd.c: New.
diff --git a/cipher/cipher.c b/cipher/cipher.c
index 601165b7..ca79fa9b 100644
--- a/cipher/cipher.c
+++ b/cipher/cipher.c
@@ -60,7 +60,7 @@ struct cipher_handle_s {
int (*setkey)( void *c, byte *key, unsigned keylen );
void (*encrypt)( void *c, byte *outbuf, byte *inbuf );
void (*decrypt)( void *c, byte *outbuf, byte *inbuf );
- byte context[1];
+ PROPERLY_ALIGNED_TYPE context;
};
@@ -328,8 +328,10 @@ cipher_open( int algo, int mode, int secure )
/* ? perform selftest here and mark this with a flag in cipher_table ? */
hd = secure ? m_alloc_secure_clear( sizeof *hd
- + cipher_table[i].contextsize )
- : m_alloc_clear( sizeof *hd + cipher_table[i].contextsize );
+ + cipher_table[i].contextsize
+ - sizeof(PROPERLY_ALIGNED_TYPE) )
+ : m_alloc_clear( sizeof *hd + cipher_table[i].contextsize
+ - sizeof(PROPERLY_ALIGNED_TYPE) );
hd->algo = algo;
hd->blocksize = cipher_table[i].blocksize;
hd->setkey = cipher_table[i].setkey;
@@ -360,7 +362,7 @@ cipher_close( CIPHER_HANDLE c )
int
cipher_setkey( CIPHER_HANDLE c, byte *key, unsigned keylen )
{
- return (*c->setkey)( &c->context, key, keylen );
+ return (*c->setkey)( &c->context.c, key, keylen );
}
@@ -383,7 +385,7 @@ do_ecb_encrypt( CIPHER_HANDLE c, byte *outbuf, byte *inbuf, unsigned nblocks )
unsigned n;
for(n=0; n < nblocks; n++ ) {
- (*c->encrypt)( &c->context, outbuf, inbuf );
+ (*c->encrypt)( &c->context.c, outbuf, inbuf );
inbuf += c->blocksize;
outbuf += c->blocksize;
}
@@ -395,7 +397,7 @@ do_ecb_decrypt( CIPHER_HANDLE c, byte *outbuf, byte *inbuf, unsigned nblocks )
unsigned n;
for(n=0; n < nblocks; n++ ) {
- (*c->decrypt)( &c->context, outbuf, inbuf );
+ (*c->decrypt)( &c->context.c, outbuf, inbuf );
inbuf += c->blocksize;
outbuf += c->blocksize;
}
@@ -428,7 +430,7 @@ do_cfb_encrypt( CIPHER_HANDLE c, byte *outbuf, byte *inbuf, unsigned nbytes )
int i;
/* encrypt the IV (and save the current one) */
memcpy( c->lastiv, c->iv, blocksize );
- (*c->encrypt)( &c->context, c->iv, c->iv );
+ (*c->encrypt)( &c->context.c, c->iv, c->iv );
/* XOR the input with the IV and store input into IV */
for(ivp=c->iv,i=0; i < blocksize; i++ )
*outbuf++ = (*ivp++ ^= *inbuf++);
@@ -437,7 +439,7 @@ do_cfb_encrypt( CIPHER_HANDLE c, byte *outbuf, byte *inbuf, unsigned nbytes )
if( nbytes ) { /* process the remaining bytes */
/* encrypt the IV (and save the current one) */
memcpy( c->lastiv, c->iv, blocksize );
- (*c->encrypt)( &c->context, c->iv, c->iv );
+ (*c->encrypt)( &c->context.c, c->iv, c->iv );
c->unused = blocksize;
/* and apply the xor */
c->unused -= nbytes;
@@ -479,7 +481,7 @@ do_cfb_decrypt( CIPHER_HANDLE c, byte *outbuf, byte *inbuf, unsigned nbytes )
int i;
/* encrypt the IV (and save the current one) */
memcpy( c->lastiv, c->iv, blocksize );
- (*c->encrypt)( &c->context, c->iv, c->iv );
+ (*c->encrypt)( &c->context.c, c->iv, c->iv );
/* XOR the input with the IV and store input into IV */
for(ivp=c->iv,i=0; i < blocksize; i++ ) {
temp = *inbuf++;
@@ -491,7 +493,7 @@ do_cfb_decrypt( CIPHER_HANDLE c, byte *outbuf, byte *inbuf, unsigned nbytes )
if( nbytes ) { /* process the remaining bytes */
/* encrypt the IV (and save the current one) */
memcpy( c->lastiv, c->iv, blocksize );
- (*c->encrypt)( &c->context, c->iv, c->iv );
+ (*c->encrypt)( &c->context.c, c->iv, c->iv );
c->unused = blocksize;
/* and apply the xor */
c->unused -= nbytes;
diff --git a/cipher/md.c b/cipher/md.c
index 95167ff4..0a297440 100644
--- a/cipher/md.c
+++ b/cipher/md.c
@@ -47,7 +47,7 @@ struct md_digest_list_s {
void (*final)( void *c );
byte *(*read)( void *c );
size_t contextsize; /* allocate this amount of context */
- char context[1];
+ PROPERLY_ALIGNED_TYPE context;
};
static struct md_digest_list_s *digest_list;
@@ -238,13 +238,15 @@ md_enable( MD_HANDLE h, int algo )
return;
}
/* and allocate a new list entry */
- ac = h->secure? m_alloc_secure( sizeof *ac + r->contextsize )
- : m_alloc( sizeof *ac + r->contextsize );
+ ac = h->secure? m_alloc_secure( sizeof *ac + r->contextsize
+ - sizeof(r->context) )
+ : m_alloc( sizeof *ac + r->contextsize
+ - sizeof(r->context) );
*ac = *r;
ac->next = h->list;
h->list = ac;
/* and init this instance */
- (*ac->init)( &ac->context );
+ (*ac->init)( &ac->context.c );
}
@@ -264,9 +266,12 @@ md_copy( MD_HANDLE a )
/* and now copy the complete list of algorithms */
/* I know that the copied list is reversed, but that doesn't matter */
for( ar=a->list; ar; ar = ar->next ) {
- br = a->secure ? m_alloc_secure( sizeof *br + ar->contextsize )
- : m_alloc( sizeof *br + ar->contextsize );
- memcpy( br, ar, sizeof(*br) + ar->contextsize );
+ br = a->secure ? m_alloc_secure( sizeof *br + ar->contextsize
+ - sizeof(ar->context) )
+ : m_alloc( sizeof *br + ar->contextsize
+ - sizeof(ar->context) );
+ memcpy( br, ar, sizeof(*br) + ar->contextsize
+ - sizeof(ar->context) );
br->next = b->list;
b->list = br;
}
@@ -288,8 +293,8 @@ md_reset( MD_HANDLE a )
a->bufcount = 0;
for( r=a->list; r; r = r->next ) {
- memset( r->context, 0, r->contextsize );
- (*r->init)( &r->context );
+ memset( r->context.c, 0, r->contextsize );
+ (*r->init)( &r->context.c );
}
}
@@ -323,8 +328,8 @@ md_write( MD_HANDLE a, byte *inbuf, size_t inlen)
BUG();
}
for(r=a->list; r; r = r->next ) {
- (*r->write)( &r->context, a->buffer, a->bufcount );
- (*r->write)( &r->context, inbuf, inlen );
+ (*r->write)( &r->context.c, a->buffer, a->bufcount );
+ (*r->write)( &r->context.c, inbuf, inlen );
}
a->bufcount = 0;
}
@@ -340,7 +345,7 @@ md_final(MD_HANDLE a)
md_write( a, NULL, 0 );
for(r=a->list; r; r = r->next ) {
- (*r->final)( &r->context );
+ (*r->final)( &r->context.c );
}
}
@@ -357,13 +362,13 @@ md_read( MD_HANDLE a, int algo )
if( (r=a->list) ) {
if( r->next )
log_debug("more than algorithm in md_read(0)\n");
- return (*r->read)( &r->context );
+ return (*r->read)( &r->context.c );
}
}
else {
for(r=a->list; r; r = r->next )
if( r->algo == algo )
- return (*r->read)( &r->context );
+ return (*r->read)( &r->context.c );
}
BUG();
return NULL;
@@ -408,7 +413,7 @@ md_digest( MD_HANDLE a, int algo, byte *buffer, int buflen )
* the context (extra overhead - should be fixed)*/
context = a->secure ? m_alloc_secure( r->contextsize )
: m_alloc( r->contextsize );
- memcpy( context, r->context, r->contextsize );
+ memcpy( context, r->context.c, r->contextsize );
(*r->final)( context );
digest = (*r->read)( context );
diff --git a/cipher/rndegd.c b/cipher/rndegd.c
index ef9f6e04..15aa38d8 100644
--- a/cipher/rndegd.c
+++ b/cipher/rndegd.c
@@ -24,11 +24,12 @@
#include <assert.h>
#include <errno.h>
#include <sys/time.h>
-#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <unistd.h>
+#include <sys/types.h>
#include <sys/socket.h>
+#include <sys/un.h>
#include "types.h"
#include "util.h"
#include "ttyio.h"
@@ -40,17 +41,10 @@
#include "i18n.h"
#endif
-static int gather_random( void (*add)(const void*, size_t, int), int requester,
- size_t length, int level );
-
-#ifdef IS_MODULE
-static void tty_printf(const char *fmt, ... )
-{
- g10_log_info("tty_printf not available (%s)\n", fmt );
-}
+#ifndef offsetof
+#define offsetof(type, member) ((size_t) &((type *)0)->member)
#endif
-
static int
do_write( int fd, void *buf, size_t nbytes )
{
@@ -60,7 +54,7 @@ do_write( int fd, void *buf, size_t nbytes )
while( nleft > 0 ) {
nwritten = write( fd, buf, nleft);
if( nwritten < 0 ) {
- if( errno = EINTR )
+ if( errno == EINTR )
continue;
return -1;
}
@@ -70,18 +64,6 @@ do_write( int fd, void *buf, size_t nbytes )
return 0;
}
- my $bytes = shift;
- $msg = pack("CC", 0x01, $bytes);
- $s->syswrite($msg, length($msg));
- my $nread = $s->sysread($buf, 1);
- die unless $nread == 1;
- my $count = unpack("C",$buf);
- $nread = $s->sysread($buf, $count);
- die "didn't get all the entropy" unless $nread == $count;
- print "got $count bytes of entropy: ",unpack("H*",$buf),"\n";
-
-
-
static int
gather_random( void (*add)(const void*, size_t, int), int requester,
@@ -90,7 +72,7 @@ gather_random( void (*add)(const void*, size_t, int), int requester,
static int fd = -1;
int n;
int warn=0;
- byte buffer[768];
+ byte buffer[256+2];
if( fd == -1 ) {
const char *name = "/tmp/entropy";
@@ -100,7 +82,8 @@ gather_random( void (*add)(const void*, size_t, int), int requester,
memset( &addr, 0, sizeof addr );
addr.sun_family = AF_UNIX;
strcpy( addr.sun_path, name ); /* fixme: check that it is long enough */
- addr_len = strlen(addr.sun_path) + sizeof addr.sun_family;
+ addr_len = offsetof( struct sockaddr_un, sun_path )
+ + strlen( addr.sun_path );
fd = socket(AF_UNIX, SOCK_STREAM, 0);
if( fd == -1 )
@@ -111,44 +94,65 @@ gather_random( void (*add)(const void*, size_t, int), int requester,
name, strerror(errno) );
}
- if( do_write( fd, "\x01", 1 ) == -1 )
- g10_log_fatal("can't write to the EGD: %s\n", strerror(errno) );
while( length ) {
fd_set rfds;
struct timeval tv;
int rc;
-
+ int nbytes;
+ int cmd;
+
+ nbytes = length < 255? length : 255;
+ /* send request */
+ cmd = level >= 2 ? 2 : 1;
+ buffer[0] = cmd;
+ buffer[1] = nbytes;
+ if( do_write( fd, buffer, 2 ) == -1 )
+ g10_log_fatal("can't write to the EGD: %s\n", strerror(errno) );
+ /* wait on reply */
FD_ZERO(&rfds);
FD_SET(fd, &rfds);
tv.tv_sec = 3;
tv.tv_usec = 0;
if( !(rc=select(fd+1, &rfds, NULL, NULL, &tv)) ) {
if( !warn )
- tty_printf( _(
+ #ifdef IS_MODULE
+ fprintf( stderr,
+ #else
+ tty_printf(
+ #endif
+ _(
"\n"
"Not enough random bytes available. Please do some other work to give\n"
"the OS a chance to collect more entropy! (Need %d more bytes)\n"), length );
- warn = 0; /* set to 1 to print onyl one warning */
+ warn = 0; /* <--- set to 1 to display the message only once */
continue;
}
else if( rc == -1 ) {
- tty_printf("select() error: %s\n", strerror(errno));
+ g10_log_error("select error on EGD: %s\n", strerror(errno));
continue;
}
+ /* collect reply */
do {
- int nbytes = length < sizeof(buffer)? length : sizeof(buffer);
- n = read(fd, buffer, nbytes );
- if( n >= 0 && n > nbytes ) {
- g10_log_error("bogus read from random device (n=%d)\n", n );
- n = nbytes;
- }
+ n = read(fd, buffer, nbytes+2 );
} while( n == -1 && errno == EINTR );
+ /* process reply */
if( n == -1 )
- g10_log_fatal("read error on EGD: %s\n", strerror(errno));
- (*add)( buffer, n, requester );
- length -= n;
+ g10_log_error("read error on EGD: %s\n", strerror(errno));
+ else if( n < 2 )
+ g10_log_error("bad EGD reply: too short\n");
+ else if( buffer[0] != cmd )
+ g10_log_error("bad EGD reply: cmd mismatch %d/%d\n",
+ cmd, *buffer );
+ else if( buffer[1] != nbytes )
+ g10_log_error("bad EGD reply: count mismatch %d/%d\n",
+ nbytes, buffer[1] );
+ else {
+ n -= 2;
+ (*add)( buffer+2, n, requester );
+ length -= n;
+ }
}
memset(buffer, 0, sizeof(buffer) );
diff --git a/cipher/rndunix.c b/cipher/rndunix.c
index 71f75dfc..145f17fb 100644
--- a/cipher/rndunix.c
+++ b/cipher/rndunix.c
@@ -477,13 +477,14 @@ slow_poll(FILE *dbgfp, int dbgall, size_t *nbytes )
/* Try and estimate how much entropy we're getting
* from a data source */
- if (dataSources[i].usefulness)
+ if (dataSources[i].usefulness) {
if (dataSources[i].usefulness < 0)
total = (dataSources[i].length + 999)
/ -dataSources[i].usefulness;
else
total = dataSources[i].length
/ dataSources[i].usefulness;
+ }
if( dbgfp )
fprintf(dbgfp,
"%s %s contributed %d bytes, "
diff --git a/configure.in b/configure.in
index 35aaa624..85be8d9b 100644
--- a/configure.in
+++ b/configure.in
@@ -24,12 +24,45 @@ AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE")
MODULES_IN_CIPHER=`awk '/# MODULES: / { for(i=3;i<=NF;i++) print $i}' \
$srcdir/cipher/Makefile.am`
+dnl
+dnl Check for random module options
+dnl
+dnl Fixme: get the list of available modules from MODULES_IN_CIPHER
+dnl and check agiants this list
+
+AC_MSG_CHECKING([which static random module to use])
+AC_ARG_ENABLE(static-rnd,
+ [ --enable-static-rnd=[egd|unix|linux|nonde] ],
+[use_static_rnd=$enableval], [use_static_rnd=default] )
+
+if test "$use_static_rnd" = no; then
+ use_static_rnd=default
+fi
+
+case "$use_static_rnd" in
+ egd | linux | unix | none | default )
+ AC_MSG_RESULT($use_static_rnd)
+ ;;
+ * )
+ AC_MSG_RESULT(invalid argument)
+ AC_MSG_ERROR(there is no random module rnd$use_static_rnd)
+ ;;
+esac
+
+dnl
+dnl See whether the user wants to disable checking for 7dev/random
+
AC_MSG_CHECKING([whether use of /dev/random is requested])
AC_ARG_ENABLE(dev-random,
[ --disable-dev-random disable the use of dev random],
try_dev_random=$enableval, try_dev_random=yes)
AC_MSG_RESULT($try_dev_random)
+
+dnl
+dnl Check other options
+dnl
+
AC_MSG_CHECKING([whether use of extensions is requested])
AC_ARG_ENABLE(dynload,
[ --disable-dynload disable use of extensions],
@@ -68,6 +101,7 @@ AC_ARG_WITH(included-zlib,
[g10_force_zlib=yes], [g10_force_zlib=no] )
AC_MSG_RESULT($g10_force_zlib)
+
dnl Checks for programs.
AC_CANONICAL_SYSTEM
@@ -300,23 +334,31 @@ dnl Figure out the default linkage mode for cipher modules
dnl
dnl (We always need a static rmd160)
static_modules="$static_modules rmd160"
-if test "$ac_cv_have_dev_random" = yes; then
- static_modules="$static_modules rndlinux"
+if test "$use_static_rnd" = default; then
+ if test "$ac_cv_have_dev_random" = yes; then
+ static_modules="$static_modules rndlinux"
+ else
+ case "${target}" in
+ i386--mingw32)
+ static_modules="$static_modules rndw32"
+ ;;
+ i386-emx-os2)
+ static_modules="$static_modules rndos2"
+ ;;
+ m68k-atari-mint)
+ static_modules="$static_modules rndatari"
+ ;;
+ *)
+ static_modules="$static_modules rndunix"
+ ;;
+ esac
+ fi
else
- case "${target}" in
- i386--mingw32)
- static_modules="$static_modules rndw32"
- ;;
- i386-emx-os2)
- static_modules="$static_modules rndos2"
- ;;
- m68k-atari-mint)
- static_modules="$static_modules rndatari"
- ;;
- *)
- static_modules="$static_modules rndunix"
- ;;
- esac
+ if test "$use_static_rnd" = none; then
+ :
+ else
+ static_modules="$static_modules rnd$use_static_rnd"
+ fi
fi
dnl
@@ -350,6 +392,8 @@ AC_SUBST(DYNAMIC_CIPHER_MODS)
dnl
dnl And build the constructor file
dnl
+
+test -d cipher || mkdir cipher
cat <<EOF >cipher/construct.c
/* automatically generated by configure - do not edit */
diff --git a/mpi/ChangeLog b/mpi/ChangeLog
index 24d1defc..78bc0dd6 100644
--- a/mpi/ChangeLog
+++ b/mpi/ChangeLog
@@ -1,3 +1,8 @@
+Wed Feb 24 11:07:27 CET 1999 Werner Koch <wk@isil.d.shuttle.de>
+
+ * mips3/mpih-sub1.S: Removed left over junk in last line. (Should I
+ blame me or my editor?).
+
Sat Feb 13 12:04:43 CET 1999 Werner Koch <wk@isil.d.shuttle.de>
* Makefile.am: Removed the +=. Add MPI_OPT_FLAGS.
diff --git a/mpi/mips3/mpih-sub1.S b/mpi/mips3/mpih-sub1.S
index f4ad4c99..4bc3ad29 100644
--- a/mpi/mips3/mpih-sub1.S
+++ b/mpi/mips3/mpih-sub1.S
@@ -120,4 +120,4 @@ mpihelp_sub_n:
or $2,$2,$8
.end mpihelp_sub_n
- n
+