diff options
Diffstat (limited to 'cipher')
-rw-r--r-- | cipher/ChangeLog | 10 | ||||
-rw-r--r-- | cipher/Makefile.am | 8 | ||||
-rw-r--r-- | cipher/cipher.c | 51 | ||||
-rw-r--r-- | cipher/dynload.c | 24 | ||||
-rw-r--r-- | cipher/md.c | 4 | ||||
-rw-r--r-- | cipher/rndegd.c | 2 |
6 files changed, 90 insertions, 9 deletions
diff --git a/cipher/ChangeLog b/cipher/ChangeLog index b2fc6401..30d2ddd2 100644 --- a/cipher/ChangeLog +++ b/cipher/ChangeLog @@ -1,3 +1,13 @@ +Sat Jun 26 12:15:59 CEST 1999 Werner Koch <wk@isil.d.shuttle.de> + + + * rndegd.c (do_write): s/ssize_t/int/ due to SunOS 4.1 probs. + + * cipher.c (do_cbc_encrypt, do_cbc_decrypt): New. + + * dynload.c (HAVE_DL_SHL_LOAD): Map hpux API to dlopen (Dave Dykstra). + * Makefile.am (install-exec-hook): Removed. + Sun May 23 14:20:22 CEST 1999 Werner Koch <wk@isil.d.shuttle.de> * cipher.c (setup_cipher_table): Enable Twofish diff --git a/cipher/Makefile.am b/cipher/Makefile.am index a3b77a1a..af6d8024 100644 --- a/cipher/Makefile.am +++ b/cipher/Makefile.am @@ -98,11 +98,3 @@ rndegd: $(srcdir)/rndegd.c -install-exec-hook: - @list='$(pkglib_PROGRAMS)'; for p in $$list; do \ - if test -f $(pkglibdir)/$$p; then \ - echo "chmod 644 $(pkglibdir)/$$p"; \ - chmod 644 $(pkglibdir)/$$p; \ - fi; \ - done - diff --git a/cipher/cipher.c b/cipher/cipher.c index a44dcc4a..59b6f2ef 100644 --- a/cipher/cipher.c +++ b/cipher/cipher.c @@ -408,6 +408,49 @@ do_ecb_decrypt( CIPHER_HANDLE c, byte *outbuf, byte *inbuf, unsigned nblocks ) } } +static void +do_cbc_encrypt( CIPHER_HANDLE c, byte *outbuf, byte *inbuf, unsigned nblocks ) +{ + unsigned int n; + byte *ivp; + int i; + size_t blocksize = c->blocksize; + + for(n=0; n < nblocks; n++ ) { + /* fixme: the xor should works on words and not on + * bytes. Maybe it is a good idea to enhance the cipher backend + * API to allow for CBC handling in the backend */ + for(ivp=c->iv,i=0; i < blocksize; i++ ) + outbuf[i] ^= *ivp++; + (*c->encrypt)( &c->context.c, outbuf, outbuf ); + memcpy(c->iv, outbuf, blocksize ); + inbuf += c->blocksize; + outbuf += c->blocksize; + } +} + +static void +do_cbc_decrypt( CIPHER_HANDLE c, byte *outbuf, byte *inbuf, unsigned nblocks ) +{ + unsigned int n; + byte *ivp; + int i; + size_t blocksize = c->blocksize; + + for(n=0; n < nblocks; n++ ) { + /* because outbuf and inbuf might be the same, we have + * to save the original ciphertext block. We use lastiv + * for this here because it is not used otherwise */ + memcpy(c->lastiv, inbuf, blocksize ); + (*c->decrypt)( &c->context.c, outbuf, inbuf ); + for(ivp=c->iv,i=0; i < blocksize; i++ ) + outbuf[i] ^= *ivp++; + memcpy(c->iv, c->lastiv, blocksize ); + inbuf += c->blocksize; + outbuf += c->blocksize; + } +} + static void do_cfb_encrypt( CIPHER_HANDLE c, byte *outbuf, byte *inbuf, unsigned nbytes ) @@ -524,6 +567,10 @@ cipher_encrypt( CIPHER_HANDLE c, byte *outbuf, byte *inbuf, unsigned nbytes ) assert(!(nbytes%8)); do_ecb_encrypt(c, outbuf, inbuf, nbytes/8 ); break; + case CIPHER_MODE_CBC: + assert(!(nbytes%8)); /* fixme: should be blocksize */ + do_cbc_encrypt(c, outbuf, inbuf, nbytes/8 ); + break; case CIPHER_MODE_CFB: case CIPHER_MODE_PHILS_CFB: do_cfb_encrypt(c, outbuf, inbuf, nbytes ); @@ -550,6 +597,10 @@ cipher_decrypt( CIPHER_HANDLE c, byte *outbuf, byte *inbuf, unsigned nbytes ) assert(!(nbytes%8)); do_ecb_decrypt(c, outbuf, inbuf, nbytes/8 ); break; + case CIPHER_MODE_CBC: + assert(!(nbytes%8)); /* fixme: should assert on blocksize */ + do_cbc_decrypt(c, outbuf, inbuf, nbytes/8 ); + break; case CIPHER_MODE_CFB: case CIPHER_MODE_PHILS_CFB: do_cfb_decrypt(c, outbuf, inbuf, nbytes ); diff --git a/cipher/dynload.c b/cipher/dynload.c index 6caeb063..e2c988e0 100644 --- a/cipher/dynload.c +++ b/cipher/dynload.c @@ -27,6 +27,9 @@ #include <dlfcn.h> #elif defined(HAVE_DLD_DLD_LINK) #include <dld.h> +#elif defined(HAVE_DL_SHL_LOAD) + #include <dl.h> + #include <errno.h> #endif #include "util.h" #include "cipher.h" @@ -45,6 +48,27 @@ #define RTLD_NOW 1 #endif +#ifdef HAVE_DL_SHL_LOAD /* HPUX has shl_load instead of dlopen */ +#define HAVE_DL_DLOPEN +#define dlopen(PATHNAME,MODE) \ + ((void *) shl_load(PATHNAME, DYNAMIC_PATH | \ + (((MODE) & RTLD_NOW) ? BIND_IMMEDIATE : BIND_DEFERRED), 0L)) +#define dlclose(HANDLE) shl_unload((shl_t) (HANDLE)) +#define dlerror() (errno == 0 ? NULL : strerror(errno)) + +static void * +dlsym(void *handle, char *name) +{ + void *addr; + if (shl_findsym((shl_t *)&handle,name,(short)TYPE_UNDEFINED,&addr) != 0) { + return NULL; + } + return addr; +} +#endif /*HAVE_DL_SHL_LOAD*/ + + + typedef struct ext_list { struct ext_list *next; int internal; diff --git a/cipher/md.c b/cipher/md.c index fc740479..be921e4b 100644 --- a/cipher/md.c +++ b/cipher/md.c @@ -341,12 +341,16 @@ md_final(MD_HANDLE a) { struct md_digest_list_s *r; + if( a->finalized ) + return; + if( a->bufcount ) md_write( a, NULL, 0 ); for(r=a->list; r; r = r->next ) { (*r->final)( &r->context.c ); } + a->finalized = 1; } diff --git a/cipher/rndegd.c b/cipher/rndegd.c index 49558623..7f2598f6 100644 --- a/cipher/rndegd.c +++ b/cipher/rndegd.c @@ -50,7 +50,7 @@ static int do_write( int fd, void *buf, size_t nbytes ) { size_t nleft = nbytes; - ssize_t nwritten; + int nwritten; while( nleft > 0 ) { nwritten = write( fd, buf, nleft); |