diff options
-rw-r--r-- | AUTHORS | 6 | ||||
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | Makefile.am | 8 | ||||
-rw-r--r-- | THANKS | 1 | ||||
-rw-r--r-- | acinclude.m4 | 2 | ||||
-rw-r--r-- | cipher/pubkey.c | 2 | ||||
-rw-r--r-- | configure.in | 19 | ||||
-rw-r--r-- | src/gcrypt.h | 18 | ||||
-rw-r--r-- | src/mdapi.c | 16 | ||||
-rw-r--r-- | src/mpiapi.c | 171 | ||||
-rw-r--r-- | src/symapi.c | 2 |
11 files changed, 233 insertions, 18 deletions
@@ -29,10 +29,10 @@ nh@df.lth.se Weak key patches. -GNUPG Rémi Guyomarch ???????????? -Assigns changes. +GNUPG Rémi Guyomarch 1999-05-25 +Assigns past and future changes. (g10/compress.c, g10/encr-data.c, +g10/free-packet.c, g10/mdfilter.c, g10/plaintext.c, util/iobuf.c) rguyom@mail.dotcom.fr -Various speed up patches. TRANSLATIONS Marco d'Itri 1997-02-22 @@ -1,5 +1,9 @@ -Thu Jun 10 14:18:23 CEST 1999 Werner Koch <wk@isil.d.shuttle.de> +Tue Jun 15 12:21:08 CEST 1999 Werner Koch <wk@isil.d.shuttle.de> + + * acinclude.m4 (GNUPG_SYS_NM_PARSE): Support for {net,free}bsd, + +Thu Jun 10 14:18:23 CEST 1999 Werner Koch <wk@isil.d.shuttle.de> * configure.in (ZLIB,GDBM): Check both, header and lib. diff --git a/Makefile.am b/Makefile.am index 9793c146..b07b909f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,6 +1,12 @@ ## Process this file with automake to produce Makefile.in -SUBDIRS = intl zlib util mpi cipher tools g10 po doc checks +if COMPILE_LIBGCRYPT +gcrypt = gcrypt +else +gcrypt = +endif + +SUBDIRS = intl zlib util mpi cipher tools g10 po doc checks ${gcrypt} EXTRA_DIST = VERSION PROJECTS BUGS @@ -58,6 +58,7 @@ Max Valianskiy maxcom@maxcom.ml.org Michael Roth mroth@nessie.de Michael Sobolev mss@despair.transas.com Nicolas Graner Nicolas.Graner@cri.u-psud.fr +NIIBE Yutaka gniibe@chroot.org Niklas Hernaeus Nimrod Zimerman zimerman@forfree.at N J Doye nic@niss.ac.uk diff --git a/acinclude.m4 b/acinclude.m4 index fdb8d147..f124fc45 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -404,7 +404,7 @@ case "$host_os" in aix*) ac_symcode='[BCDTU]' ;; -openbsd* | sunos* | cygwin32* | mingw32*) +freebsd* | netbsd* | openbsd* | sunos* | cygwin32* | mingw32*) ac_sympat='_\([_A-Za-z][_A-Za-z0-9]*\)' ac_symxfrm='_\1 \1' ;; diff --git a/cipher/pubkey.c b/cipher/pubkey.c index 5695e752..81574dbd 100644 --- a/cipher/pubkey.c +++ b/cipher/pubkey.c @@ -89,6 +89,8 @@ dummy_get_nbits( int algo, MPI *pkey ) /**************** * Put the static entries into the table. + * This is out constructor function which fill the table + * of algorithms with the one we have statically linked. */ static void setup_pubkey_table(void) diff --git a/configure.in b/configure.in index a414e64d..63b5539d 100644 --- a/configure.in +++ b/configure.in @@ -102,6 +102,16 @@ AC_ARG_WITH(included-zlib, [g10_force_zlib=yes], [g10_force_zlib=no] ) AC_MSG_RESULT($g10_force_zlib) +dnl +dnl Check wether we want to compile libgcrypt +dnl +AC_MSG_CHECKING([whether compilation of libgcrypt is requested]) +AC_ARG_ENABLE(libgcrypt, + [ --enable-libgcrypt compile the libgcrypt [default=no]], +[compile_libgcrypt="$enableval"],[compile_libgcrypt=yes]) +AM_CONDITIONAL(COMPILE_LIBGCRYPT, test x$compile_libgcrypt = xyes) +AC_MSG_RESULT($compile_libgcrypt) + dnl Checks for programs. @@ -121,6 +131,14 @@ AC_ISC_POSIX AC_PROG_INSTALL AC_PROG_RANLIB + +if test x$compile_libgcrypt = xyes; then + dnl Don't default to build shared libs + AM_DISABLE_SHARED + AM_PROG_LIBTOOL +fi + + MPI_OPT_FLAGS="" if test "$GCC" = yes; then CFLAGS="$CFLAGS -Wall -Wcast-align -Wshadow -Wstrict-prototypes" @@ -577,6 +595,7 @@ doc/Makefile tools/Makefile zlib/Makefile checks/Makefile +gcrypt/Makefile ]) dnl *-*wedit:notab*-* Please keep this as the last line. diff --git a/src/gcrypt.h b/src/gcrypt.h index 3d301d1a..e3dacbf7 100644 --- a/src/gcrypt.h +++ b/src/gcrypt.h @@ -45,8 +45,10 @@ enum { GCRYERR_INV_ALGO = 4, /* invalid algorithm */ GCRYERR_INV_ARG = 5, /* invalid argument */ GCRYERR_INTERNAL = 6, /* internal error */ - GCRYERR_TOO_SHORT = 7, /* provided buffer too short */ - GCRYERR_EOF = 8, /* (-1) is remapped to this value */ + GCRYERR_EOF = 7, /* (-1) is remapped to this value */ + GCRYERR_TOO_SHORT = 8, /* provided buffer too short */ + GCRYERR_TOO_LARGE = 9, /* object is too large */ + GCRYERR_INV_OBJ = 10, /* an object is not valid */ }; @@ -84,6 +86,12 @@ enum gcry_mpi_opcode { GCRYMPI_CMP_UI = 10 }; +enum gcry_mpi_format { + GCRYMPI_FMT_STD = 0, /* As used by OpenPGP */ + GCRYMPI_FMT_SSH = 1, /* As used by SSH */ + GCRYMPI_FMT_HEX = 2, /* hex format */ +}; + struct gcry_mpi; int gcry_mpi_api( enum gcry_mpi_opcode opcode, int n_args, ... ); @@ -91,6 +99,10 @@ struct gcry_mpi *gcry_mpi_new( enum gcry_mpi_opcode opcode, unsigned int size, struct gcry_mpi *val ); +int gcry_mpi_scan( struct gcry_mpi **ret_mpi, enum gcry_mpi_format format, + const char *buffer, size_t *nbytes ); +int gcry_mpi_print( enum gcry_mpi_format format, char *buffer, size_t *nbytes, + struct gcry_mpi *a ); #ifndef GCRYPT_NO_MPI_MACROS #define mpi_new( nbits ) gcry_mpi_new( GCRYMPI_NEW, (nbits), NULL ) @@ -225,7 +237,7 @@ GCRY_MD_HD gcry_md_copy( GCRY_MD_HD hd ); int gcry_md_ctl( GCRY_MD_HD hd, int cmd, byte *buffer, size_t buflen); void gcry_md_write( GCRY_MD_HD hd, byte *inbuf, size_t inlen); byte *gcry_md_read( GCRY_MD_HD hd, int algo ); -int gcry_md_get( GCYR_MD_HD hd, int algo, byte *buffer, int buflen ); +int gcry_md_get( GCRY_MD_HD hd, int algo, byte *buffer, int buflen ); #define gcry_md_final( a ) gcry_md_ctl( (a), GCRYCTL_FINALIZE, NULL, 0 ) diff --git a/src/mdapi.c b/src/mdapi.c index 68c51c0a..9d895fd2 100644 --- a/src/mdapi.c +++ b/src/mdapi.c @@ -28,32 +28,32 @@ #include "g10lib.h" -GCRY_MD_HD +GCRY_MD_HD gcry_md_open( int algo, unsigned flags ) { } -void +void gcry_md_close( GCRY_MD_HD hd ) { } -void +void gcry_md_enable( GCRY_MD_HD hd, int algo ) { } -GCRY_MD_HD +GCRY_MD_HD gcry_md_copy( GCRY_MD_HD hd ) { } -int +int gcry_md_ctl( GCRY_MD_HD hd, int cmd, byte *buffer, size_t buflen) { } -void +void gcry_md_write( GCRY_MD_HD hd, byte *inbuf, size_t inlen) { } @@ -64,8 +64,8 @@ gcry_md_read( GCRY_MD_HD hd, int algo ) } -int -gcry_md_get( GCYR_MD_HD hd, int algo, byte *buffer, int buflen ) +int +gcry_md_get( GCRY_MD_HD hd, int algo, byte *buffer, int buflen ) { } diff --git a/src/mpiapi.c b/src/mpiapi.c index 041d34c8..dfdaeb99 100644 --- a/src/mpiapi.c +++ b/src/mpiapi.c @@ -63,3 +63,174 @@ gcry_mpi_new( enum gcry_mpi_opcode opcode, } } + +int +gcry_mpi_scan( struct gcry_mpi **ret_mpi, enum gcry_mpi_format format, + const char *buffer, size_t *nbytes ) +{ + struct gcry_mpi *a = NULL; + unsigned int len; + + len = nbytes? *nbytes : strlen(buffer); + + /* TODO: add formats to allocate the MPI in secure memory */ + if( format == GCRYMPI_FMT_STD ) { + a = mpi_read_from_buffer( (char*)buffer, &len, 0 ); + if( nbytes ) + *nbytes = len; + if( ret_mpi ) + *ret_mpi = a; + else + mpi_free(a); + return a? 0 : GCRYERR_INV_OBJ; + } + else if( format == GCRYMPI_FMT_SSH ) { + const byte *s = buffer; + size_t n; + + if( len < 4 ) + return GCRYERR_TOO_SHORT; + n = s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]; + s += 4; len -= 4; + if( n > len ) + return GCRYERR_TOO_LARGE; /* or should it be too_short */ + + a = mpi_alloc( (n+BYTES_PER_MPI_LIMB-1) / BYTES_PER_MPI_LIMB ); + if( len ) { /* not zero */ + a->sign = *s & 0x80; + if( a->sign ) { + /* FIXME: we have to convert from 2compl to magnitude format */ + mpi_free(a); + return GCRYERR_INTERNAL; + } + else + mpi_set_buffer( a, s, n, 0 ); + } + if( nbytes ) + *nbytes = n+4; + if( ret_mpi ) + *ret_mpi = a; + else + mpi_free(a); + return 0; + } + else + return GCRYERR_INV_ARG; +} + +/**************** + * Write a in format into buffer which has a length of *NBYTES. + * Return the number of bytes actually written in nbytes. + * TODO: Move this stuff to mpicoder.c or replace mpicoder.c + */ +int +gcry_mpi_print( enum gcry_mpi_format format, char *buffer, size_t *nbytes, + struct gcry_mpi *a ) +{ + unsigned int nbits = mpi_get_nbits(a); + size_t len; + + if( !nbytes ) + return GCRYERR_INV_ARG; + + len = *nbytes; + if( format == GCRYMPI_FMT_STD ) { + unsigned int n = (nbits + 7)/8; + byte *s = buffer; + char *tmp; + + if( a->sign ) + return GCRYERR_INV_ARG; /* pgp format can only handle unsigned */ + + if( n+2 > len ) + return GCRYERR_TOO_SHORT; /* the provided buffer is too short */ + s[0] = nbits >> 8; + s[1] = nbits; + + tmp = mpi_get_buffer( a, &n, NULL ); + memcpy( s+2, tmp, n ); + m_free(tmp); + *nbytes = n+2; + return 0; + } + else if( format == GCRYMPI_FMT_SSH ) { + byte *s = buffer; + char *tmp; + int extra = 0; + unsigned int n; + + if( a->sign ) + return GCRYERR_INTERNAL; /* can't handle it yet */ + + tmp = mpi_get_buffer( a, &n, NULL ); + if( n && (*tmp & 0x80) ) { + n++; + extra=1; + } + + if( n+4 > len ) { + m_free(tmp); + return GCRYERR_TOO_SHORT; /* the provided buffer is too short */ + } + *s++ = n >> 24; + *s++ = n >> 16; + *s++ = n >> 8; + *s++ = n; + if( extra ) + *s++ = 0; + + memcpy( s, tmp, n-extra ); + m_free(tmp); + *nbytes = 4+n; + return 0; + } + else if( format == GCRYMPI_FMT_HEX ) { + byte *s = buffer; + byte *tmp; + int i; + int extra = 0; + unsigned int n=0; + + if( a->sign ) + return GCRYERR_INTERNAL; /* can't handle it yet */ + + tmp = mpi_get_buffer( a, &n, NULL ); + if( n && (*tmp & 0x80) ) { + n++; + extra=1; + } + + if( 2*n+2+1 > len ) { + m_free(tmp); + return GCRYERR_TOO_SHORT; /* the provided buffer is too short */ + } + if( extra || !n ) { + *s++ = '0'; + *s++ = '0'; + n += 2; + } + + #if BYTES_PER_MPI_LIMB == 2 + #define X "4" + #elif BYTES_PER_MPI_LIMB == 4 + #define X "8" + #elif BYTES_PER_MPI_LIMB == 8 + #define X "16" + #else + #error please define the format here + #endif + for(i=0; i < n; i++ ) { + unsigned int c = tmp[i]; + *s++ = (c >> 4) < 10? '0'+(c>>4) : 'A'+(c>>4)-10 ; + c &= 15; + *s++ = c < 10? '0'+c : 'A'+c-10 ; + } + *s++ = 0; + *nbytes = (char*)s - buffer; + #undef X + return 0; + } + else + return GCRYERR_INV_ARG; +} + diff --git a/src/symapi.c b/src/symapi.c index ffe967a5..8b27ae8f 100644 --- a/src/symapi.c +++ b/src/symapi.c @@ -111,7 +111,7 @@ int gcry_cipher_ctl( GCRY_CIPHER_HD h, int cmd, byte *buffer, size_t buflen) cipher_setkey( h->hd, buffer, buflen ); break; case GCRYCTL_SET_IV: - cipher_setiv( h->hd, buffer ); + cipher_setiv( h->hd, buffer, buflen ); break; case GCRYCTL_CFB_SYNC: cipher_sync( h->hd ); |