From ulm at gentoo.org Thu Feb 16 20:12:55 2012 From: ulm at gentoo.org (Ulrich Mueller) Date: Thu, 16 Feb 2012 20:12:55 +0100 Subject: IDEA support In-Reply-To: <20237.54781.307379.448936@a1i15.kph.uni-mainz.de> References: <19921.24220.826380.56157@a1i15.kph.uni-mainz.de> <871uzyv6w4.fsf@vigenere.g10code.de> <20231.40601.138265.57633@a1i15.kph.uni-mainz.de> <87mx9x3umt.fsf@vigenere.g10code.de> <20237.12522.644856.464955@a1i15.kph.uni-mainz.de> <87ipkizl95.fsf@vigenere.g10code.de> <20237.54781.307379.448936@a1i15.kph.uni-mainz.de> Message-ID: <20285.21815.42242.228224@a1i15.kph.uni-mainz.de> >>>>> On Wed, 11 Jan 2012, Ulrich Mueller wrote: >>>>> On Wed, 11 Jan 2012, Werner Koch wrote: >> To apply this patch you first need to sign copyright assignments > I've requested the forms from the FSF. Let's see how long it will > take this time. So it took about one month, but the paperwork should be completed now. An updated patch is included below, this time with a commit log according to your new policy. Ulrich >From 9f7e939f69682df7bd359a5a4acb6716abc3cffd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ulrich=20M=C3=BCller?= Date: Wed, 11 Jan 2012 13:20:48 +0100 Subject: [PATCH] Add support for the IDEA cipher. Adapt idea.c to the Libgcrypt framework. Add IDEA to cipher_table and to the build system. Patents on IDEA have expired: Europe: EP0482154 on 2011-05-16, Japan: JP3225440 on 2011-05-16, U.S.: 5,214,703 on 2012-01-07. * configure.ac: Add idea to the list of available ciphers. Define USE_IDEA if idea is enabled. * cipher/cipher.c (cipher_table): Add entry for IDEA. * cipher/idea.c: Update comment about patents. Include proper header files and remove redundant declarations. (expand_key, cipher, do_setkey, encrypt_block, decrypt_block): Define function arguments as const where appropriate. (cipher): Test for !WORDS_BIGENDIAN instead of LITTLE_ENDIAN_HOST. (do_setkey, decrypt_block): Don't call selftest. (idea_setkey): New function, wrapper for do_setkey. (idea_encrypt): New function, wrapper for encrypt_block. (_gcry_cipher_spec_idea): Define. * cipher/Makefile.am (EXTRA_libcipher_la_SOURCES): Add idea.c. * src/cipher.h (_gcry_cipher_spec_idea): Declare. * tests/basic.c (check_ciphers): Add GCRY_CIPHER_IDEA. --- cipher/Makefile.am | 1 + cipher/cipher.c | 4 + cipher/idea.c | 196 ++++++++++++++-------------------------------------- configure.ac | 8 ++- src/cipher.h | 1 + tests/basic.c | 3 + 6 files changed, 68 insertions(+), 145 deletions(-) diff --git a/cipher/Makefile.am b/cipher/Makefile.am index dcb4a47..473e3c8 100644 --- a/cipher/Makefile.am +++ b/cipher/Makefile.am @@ -53,6 +53,7 @@ des.c \ dsa.c \ elgamal.c \ ecc.c \ +idea.c \ md4.c \ md5.c \ rijndael.c rijndael-tables.h \ diff --git a/cipher/cipher.c b/cipher/cipher.c index 589c262..389bf7a 100644 --- a/cipher/cipher.c +++ b/cipher/cipher.c @@ -100,6 +100,10 @@ static struct cipher_table_entry { &_gcry_cipher_spec_camellia256, &dummy_extra_spec, GCRY_CIPHER_CAMELLIA256 }, #endif +#ifdef USE_IDEA + { &_gcry_cipher_spec_idea, + &dummy_extra_spec, GCRY_CIPHER_IDEA }, +#endif { NULL } }; diff --git a/cipher/idea.c b/cipher/idea.c index 65a8ec3..fe14b21 100644 --- a/cipher/idea.c +++ b/cipher/idea.c @@ -22,10 +22,10 @@ * used in advertising or otherwise to promote the sale, use or other dealings * in this Software without prior written authorization from Werner Koch. * - * DUE TO PATENT CLAIMS THE DISTRIBUTION OF THE SOFTWARE IS NOT ALLOWED IN - * THESE COUNTRIES: - * AUSTRIA, FRANCE, GERMANY, ITALY, JAPAN, THE NETHERLANDS, - * SPAIN, SWEDEN, SWITZERLAND, THE UK AND THE US. + * Patents on IDEA have expired: + * Europe: EP0482154 on 2011-05-16, + * Japan: JP3225440 on 2011-05-16, + * U.S.: 5,214,703 on 2012-01-07. */ /* @@ -34,60 +34,22 @@ * * The code herein is based on the one from: * Bruce Schneier: Applied Cryptography. John Wiley & Sons, 1996. - * ISBN 0-471-11709-9. . - * - * How to compile: - gcc -Wall -O2 -shared -fPIC -o idea idea.c - * - * 2001-06-08 wk Changed distribution conditions - * 2001-06-11 wk Fixed invert_key (which is not used in CFB mode) - * Thanks to Mark A. Borgerding. Added defintion for - * the PowerPC. + * ISBN 0-471-11709-9. */ +#include #include #include #include #include -/* configuration stuff */ -#ifdef __alpha__ - #define SIZEOF_UNSIGNED_LONG 8 -#else - #define SIZEOF_UNSIGNED_LONG 4 -#endif - -#if defined(__mc68000__) || defined (__sparc__) || defined (__PPC__) \ - || (defined(__mips__) && (defined(MIPSEB) || defined (__MIPSEB__)) ) \ - || defined(__powerpc__) \ - || defined(__hpux__) /* should be replaced by the Macro for the PA */ - #define BIG_ENDIAN_HOST 1 -#else - #define LITTLE_ENDIAN_HOST 1 -#endif - -typedef unsigned long ulong; -typedef unsigned short ushort; -typedef unsigned char byte; - -typedef unsigned short u16; -typedef unsigned long u32; - -/* end configurable stuff */ - -#ifndef DIM - #define DIM(v) (sizeof(v)/sizeof((v)[0])) - #define DIMof(type,member) DIM(((type *)0)->member) -#endif - -/* imports */ -void g10_log_fatal( const char *fmt, ... ); - +#include "types.h" /* for byte and u32 typedefs */ +#include "g10lib.h" +#include "cipher.h" -/* local stuff */ -#define FNCCAST_SETKEY(f) ((int(*)(void*, byte*, unsigned))(f)) +#define FNCCAST_SETKEY(f) ((int(*)(void*, byte*, unsigned int))(f)) #define FNCCAST_CRYPT(f) ((void(*)(void*, byte*, byte*))(f)) #define IDEA_KEYSIZE 16 @@ -102,13 +64,6 @@ typedef struct { } IDEA_context; -static int do_setkey( IDEA_context *c, byte *key, unsigned keylen ); -static void encrypt_block( IDEA_context *bc, byte *outbuf, byte *inbuf ); -static void decrypt_block( IDEA_context *bc, byte *outbuf, byte *inbuf ); -static void selftest(int); - - - static u16 mul_inv( u16 x ) { @@ -139,7 +94,7 @@ mul_inv( u16 x ) static void -expand_key( byte *userkey, u16 *ek ) +expand_key( const byte *userkey, u16 *ek ) { int i,j; @@ -202,7 +157,7 @@ invert_key( u16 *ek, u16 dk[IDEA_KEYLEN] ) static void -cipher( byte *outbuf, byte *inbuf, u16 *key ) +cipher( byte *outbuf, const byte *inbuf, u16 *key ) { u16 x1, x2, x3,x4, s2, s3; u16 *in, *out; @@ -230,7 +185,7 @@ cipher( byte *outbuf, byte *inbuf, u16 *key ) x2 = *in++; x3 = *in++; x4 = *in; - #ifdef LITTLE_ENDIAN_HOST + #ifndef WORDS_BIGENDIAN x1 = (x1>>8) | (x1<<8); x2 = (x2>>8) | (x2<<8); x3 = (x3>>8) | (x3<<8); @@ -263,7 +218,7 @@ cipher( byte *outbuf, byte *inbuf, u16 *key ) MUL(x4, *key); out = (u16*)outbuf; - #ifdef LITTLE_ENDIAN_HOST + #ifndef WORDS_BIGENDIAN *out++ = (x1>>8) | (x1<<8); *out++ = (x3>>8) | (x3<<8); *out++ = (x2>>8) | (x2<<8); @@ -279,14 +234,16 @@ cipher( byte *outbuf, byte *inbuf, u16 *key ) static int -do_setkey( IDEA_context *c, byte *key, unsigned keylen ) +do_setkey( IDEA_context *c, const byte *key, unsigned int keylen ) { +#if 0 static int initialized = 0; if( !initialized ) { initialized = 1; selftest(0); } +#endif assert(keylen == 16); c->have_dk = 0; expand_key( key, c->ek ); @@ -294,21 +251,40 @@ do_setkey( IDEA_context *c, byte *key, unsigned keylen ) return 0; } +static gcry_err_code_t +idea_setkey (void *context, const byte *key, unsigned int keylen) +{ + IDEA_context *ctx = context; + int rc = do_setkey (ctx, key, keylen); + _gcry_burn_stack (23+6*sizeof(void*)); + return rc; +} + static void -encrypt_block( IDEA_context *c, byte *outbuf, byte *inbuf ) +encrypt_block( IDEA_context *c, byte *outbuf, const byte *inbuf ) { cipher( outbuf, inbuf, c->ek ); } static void -decrypt_block( IDEA_context *c, byte *outbuf, byte *inbuf ) +idea_encrypt (void *context, byte *out, const byte *in) +{ + IDEA_context *ctx = context; + encrypt_block (ctx, out, in); + _gcry_burn_stack (24+3*sizeof (void*)); +} + +static void +decrypt_block( IDEA_context *c, byte *outbuf, const byte *inbuf ) { +#if 0 static int initialized; if( !initialized ) { initialized = 1; selftest(1); } +#endif if( !c->have_dk ) { c->have_dk = 1; invert_key( c->ek, c->dk ); @@ -316,7 +292,16 @@ decrypt_block( IDEA_context *c, byte *outbuf, byte *inbuf ) cipher( outbuf, inbuf, c->dk ); } +static void +idea_decrypt (void *context, byte *out, const byte *in) +{ + IDEA_context *ctx = context; + decrypt_block (ctx, out, in); + _gcry_burn_stack (24+3*sizeof (void*)); +} + +#if 0 static void selftest( int check_decrypt ) { @@ -388,89 +373,12 @@ static struct { } } } +#endif -/**************** - * Return some information about the algorithm. We need algo here to - * distinguish different flavors of the algorithm. - * Returns: A pointer to string describing the algorithm or NULL if - * the ALGO is invalid. - */ -const char * -idea_get_info( int algo, size_t *keylen, - size_t *blocksize, size_t *contextsize, - int (**r_setkey)( void *c, byte *key, unsigned keylen ), - void (**r_encrypt)( void *c, byte *outbuf, byte *inbuf ), - void (**r_decrypt)( void *c, byte *outbuf, byte *inbuf ) - ) +gcry_cipher_spec_t _gcry_cipher_spec_idea = { - *keylen = 128; - *blocksize = 8; - *contextsize = sizeof(IDEA_context); - *r_setkey = FNCCAST_SETKEY(do_setkey); - *r_encrypt= FNCCAST_CRYPT(encrypt_block); - *r_decrypt= FNCCAST_CRYPT(decrypt_block); - if( algo == 1 ) - return "IDEA"; - return NULL; -} - - - -const char * const gnupgext_version = "IDEA ($Revision: 1.11 $)"; - -static struct { - int class; - int version; - int value; - void (*func)(void); -} func_table[] = { - { 20, 1, 0, (void(*)(void))idea_get_info }, - { 21, 1, 1 }, + "IDEA", NULL, NULL, IDEA_BLOCKSIZE, 128, + sizeof (IDEA_context), + idea_setkey, idea_encrypt, idea_decrypt }; - - - -/**************** - * Enumerate the names of the functions together with informations about - * this function. Set sequence to an integer with a initial value of 0 and - * do not change it. - * If what is 0 all kind of functions are returned. - * Return values: class := class of function: - * 10 = message digest algorithm info function - * 11 = integer with available md algorithms - * 20 = cipher algorithm info function - * 21 = integer with available cipher algorithms - * 30 = public key algorithm info function - * 31 = integer with available pubkey algorithms - * version = interface version of the function/pointer - * (currently this is 1 for all functions) - */ -void * -gnupgext_enum_func( int what, int *sequence, int *class, int *vers ) -{ - void *ret; - int i = *sequence; - - do { - if( i >= DIM(func_table) || i < 0 ) { - return NULL; - } - *class = func_table[i].class; - *vers = func_table[i].version; - switch( *class ) { - case 11: - case 21: - case 31: - ret = &func_table[i].value; - break; - default: - ret = func_table[i].func; - break; - } - i++; - } while( what && what != *class ); - - *sequence = i; - return ret; -} diff --git a/configure.ac b/configure.ac index c354836..cf4a082 100644 --- a/configure.ac +++ b/configure.ac @@ -174,7 +174,7 @@ LIBGCRYPT_CONFIG_HOST="$host" # Definitions for symmetric ciphers. available_ciphers="arcfour blowfish cast5 des aes twofish serpent rfc2268 seed" -available_ciphers="$available_ciphers camellia" +available_ciphers="$available_ciphers camellia idea" enabled_ciphers="" # Definitions for public-key ciphers. @@ -1080,6 +1080,12 @@ if test "$found" = "1" ; then AC_DEFINE(USE_CAMELLIA, 1, [Defined if this module should be included]) fi +LIST_MEMBER(idea, $enabled_ciphers) +if test "$found" = "1" ; then + GCRYPT_CIPHERS="$GCRYPT_CIPHERS idea.lo" + AC_DEFINE(USE_IDEA, 1, [Defined if this module should be included]) +fi + LIST_MEMBER(dsa, $enabled_pubkey_ciphers) if test "$found" = "1" ; then GCRYPT_PUBKEY_CIPHERS="$GCRYPT_PUBKEY_CIPHERS dsa.lo" diff --git a/src/cipher.h b/src/cipher.h index 0f923d7..48eeeda 100644 --- a/src/cipher.h +++ b/src/cipher.h @@ -135,6 +135,7 @@ extern gcry_cipher_spec_t _gcry_cipher_spec_seed; extern gcry_cipher_spec_t _gcry_cipher_spec_camellia128; extern gcry_cipher_spec_t _gcry_cipher_spec_camellia192; extern gcry_cipher_spec_t _gcry_cipher_spec_camellia256; +extern gcry_cipher_spec_t _gcry_cipher_spec_idea; extern cipher_extra_spec_t _gcry_cipher_extraspec_tripledes; extern cipher_extra_spec_t _gcry_cipher_extraspec_aes; diff --git a/tests/basic.c b/tests/basic.c index 4d5196f..8001e86 100644 --- a/tests/basic.c +++ b/tests/basic.c @@ -1568,6 +1568,9 @@ check_ciphers (void) GCRY_CIPHER_CAMELLIA192, GCRY_CIPHER_CAMELLIA256, #endif +#if USE_IDEA + GCRY_CIPHER_IDEA, +#endif 0 }; static int algos2[] = { -- 1.7.8.4 From wk at gnupg.org Thu Feb 16 21:02:10 2012 From: wk at gnupg.org (Werner Koch) Date: Thu, 16 Feb 2012 21:02:10 +0100 Subject: IDEA support In-Reply-To: <20285.21815.42242.228224@a1i15.kph.uni-mainz.de> (Ulrich Mueller's message of "Thu, 16 Feb 2012 20:12:55 +0100") References: <19921.24220.826380.56157@a1i15.kph.uni-mainz.de> <871uzyv6w4.fsf@vigenere.g10code.de> <20231.40601.138265.57633@a1i15.kph.uni-mainz.de> <87mx9x3umt.fsf@vigenere.g10code.de> <20237.12522.644856.464955@a1i15.kph.uni-mainz.de> <87ipkizl95.fsf@vigenere.g10code.de> <20237.54781.307379.448936@a1i15.kph.uni-mainz.de> <20285.21815.42242.228224@a1i15.kph.uni-mainz.de> Message-ID: <87lio2v97m.fsf@vigenere.g10code.de> On Thu, 16 Feb 2012 20:12, ulm at gentoo.org said: > So it took about one month, but the paperwork should be completed now. > > An updated patch is included below, this time with a commit log > according to your new policy. Very good. Thanks. I just pushed the changes. I noticed that you disabled the selftests. Maybe you can find the time to rework them to match what we do in rijndael.c etc. Shalom-Salam, Werner -- Die Gedanken sind frei. Ausnahmen regelt ein Bundesgesetz. From benjamin.pousse at member.fsf.org Thu Feb 16 22:09:38 2012 From: benjamin.pousse at member.fsf.org (Benjamin Pousse) Date: Thu, 16 Feb 2012 22:09:38 +0100 Subject: Malfunction of gcry_sexp_car Message-ID: <1329426581.1817.92.camel@ben-desktop> Hello, (This is my first contribution. So I apologize if this is not the right way to contribute.) The function gcry_sexp_car seems buggy to me (tested on libgcrypt version 1.4.6, 1.5.0, 1.6.0-git6078b05): it doesn't return any result on S-expression starting with a data element. For example, applied to the S-expression (hello "123"), it returns an empty S-expression (I expect the S-expression (hello)). In fact, after some "investigation", the function gcry_sexp_nth appears unable to return the n-th element of a S-expression when this element is not a list. More precisely, in the function gcry_sexp_nth, the code in the first "if" after the first loop "while" does not construct a valid gcry_sexp. Please find at the end of this mail my patch to solve this problem (the patch is large because I apply a regular indentation on the full function). Regards, Benjamin. diff --git a/src/sexp.c b/src/sexp.c index 0877773..12b57ba 100644 --- a/src/sexp.c +++ b/src/sexp.c @@ -549,73 +549,96 @@ gcry_sexp_nth( const gcry_sexp_t list, int number ) int level = 0; if ( !list || list->d[0] != ST_OPEN ) - return NULL; + return NULL; p = list->d; - while ( number > 0 ) { - p++; - if ( *p == ST_DATA ) { - memcpy ( &n, ++p, sizeof n ); - p += sizeof n + n; - p--; - if ( !level ) - number--; - } - else if ( *p == ST_OPEN ) { - level++; - } - else if ( *p == ST_CLOSE ) { - level--; - if ( !level ) - number--; - } - else if ( *p == ST_STOP ) { - return NULL; - } - } + while ( number > 0 ) + { + p++; + if ( *p == ST_DATA ) + { + memcpy ( &n, ++p, sizeof n ); + p += sizeof n + n; + p--; + if ( !level ) + number--; + } + else if ( *p == ST_OPEN ) + { + level++; + } + else if ( *p == ST_CLOSE ) + { + level--; + if ( !level ) + number--; + } + else if ( *p == ST_STOP ) + { + return NULL; + } + } p++; - if ( *p == ST_DATA ) { - memcpy ( &n, p, sizeof n ); p += sizeof n; - newlist = gcry_malloc ( sizeof *newlist + n + 1 ); + if ( *p == ST_DATA ) + { + memcpy ( &n, p + 1, sizeof n ); + /* Allocate 1 (= sizeof *newlist) byte for ST_OPEN + 1 byte for ST_DATA + sizeof n byte for n + n byte for the data + 1 byte for ST_CLOSE + 1 byte for ST_STOP*/ + newlist = gcry_malloc ( sizeof *newlist + 1 + sizeof n + n + 2 ); if (!newlist) return NULL; - d = newlist->d; - memcpy ( d, p, n ); d += n; - *d++ = ST_STOP; - } - else if ( *p == ST_OPEN ) { - const byte *head = p; - - level = 1; - do { - p++; - if ( *p == ST_DATA ) { - memcpy ( &n, ++p, sizeof n ); - p += sizeof n + n; - p--; - } - else if ( *p == ST_OPEN ) { - level++; - } - else if ( *p == ST_CLOSE ) { - level--; - } - else if ( *p == ST_STOP ) { - BUG (); - } - } while ( level ); - n = p + 1 - head; + d = newlist->d; + *d = ST_OPEN; + d++; + memcpy ( d, p, 1 + sizeof n + n ); /* Copy ST_DATA, n and the data from p to d*/ + d += 1 + sizeof n + n; + *d = ST_CLOSE; + d++; + *d = ST_STOP; + } + else if ( *p == ST_OPEN ) + { + const byte *head = p; + + level = 1; + do + { + p++; + if ( *p == ST_DATA ) + { + memcpy ( &n, ++p, sizeof n ); + p += sizeof n + n; + p--; + } + else if ( *p == ST_OPEN ) + { + level++; + } + else if ( *p == ST_CLOSE ) + { + level--; + } + else if ( *p == ST_STOP ) + { + BUG (); + } + } while ( level ); + n = p + 1 - head; - newlist = gcry_malloc ( sizeof *newlist + n ); + newlist = gcry_malloc ( sizeof *newlist + n ); if (!newlist) return NULL; - d = newlist->d; - memcpy ( d, head, n ); d += n; - *d++ = ST_STOP; - } + d = newlist->d; + memcpy ( d, head, n ); d += n; + *d++ = ST_STOP; + } else - newlist = NULL; + newlist = NULL; return normalize (newlist); } From ulm at gentoo.org Thu Feb 16 23:26:07 2012 From: ulm at gentoo.org (Ulrich Mueller) Date: Thu, 16 Feb 2012 23:26:07 +0100 Subject: IDEA support In-Reply-To: <87lio2v97m.fsf@vigenere.g10code.de> References: <19921.24220.826380.56157@a1i15.kph.uni-mainz.de> <871uzyv6w4.fsf@vigenere.g10code.de> <20231.40601.138265.57633@a1i15.kph.uni-mainz.de> <87mx9x3umt.fsf@vigenere.g10code.de> <20237.12522.644856.464955@a1i15.kph.uni-mainz.de> <87ipkizl95.fsf@vigenere.g10code.de> <20237.54781.307379.448936@a1i15.kph.uni-mainz.de> <20285.21815.42242.228224@a1i15.kph.uni-mainz.de> <87lio2v97m.fsf@vigenere.g10code.de> Message-ID: <20285.33407.938984.282161@a1i15.kph.uni-mainz.de> >>>>> On Thu, 16 Feb 2012, Werner Koch wrote: > Very good. Thanks. I just pushed the changes. Thank you. > I noticed that you disabled the selftests. Maybe you can find the > time to rework them to match what we do in rijndael.c etc. Patch is included below. Ulrich >From 96676cf780f1776de214996b099643e5ef50d6bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ulrich=20M=C3=BCller?= Date: Thu, 16 Feb 2012 21:58:52 +0100 Subject: [PATCH] Rework selftest in idea.c. * cipher/idea.c (do_setkey): Execute selftest when first called. (decrypt_block): Remove commented-out code. (selftest): Execute all selftests. Return NULL on success, or string in case of error. --- cipher/idea.c | 44 +++++++++++++++++++------------------------- 1 files changed, 19 insertions(+), 25 deletions(-) diff --git a/cipher/idea.c b/cipher/idea.c index fe14b21..39c9720 100644 --- a/cipher/idea.c +++ b/cipher/idea.c @@ -63,6 +63,8 @@ typedef struct { int have_dk; } IDEA_context; +static const char *selftest(void); + static u16 mul_inv( u16 x ) @@ -236,14 +238,18 @@ cipher( byte *outbuf, const byte *inbuf, u16 *key ) static int do_setkey( IDEA_context *c, const byte *key, unsigned int keylen ) { -#if 0 static int initialized = 0; + static const char *selftest_failed = 0; if( !initialized ) { initialized = 1; - selftest(0); + selftest_failed = selftest(); + if( selftest_failed ) + log_error( "%s\n", selftest_failed ); } -#endif + if( selftest_failed ) + return GPG_ERR_SELFTEST_FAILED; + assert(keylen == 16); c->have_dk = 0; expand_key( key, c->ek ); @@ -277,14 +283,6 @@ idea_encrypt (void *context, byte *out, const byte *in) static void decrypt_block( IDEA_context *c, byte *outbuf, const byte *inbuf ) { -#if 0 - static int initialized; - - if( !initialized ) { - initialized = 1; - selftest(1); - } -#endif if( !c->have_dk ) { c->have_dk = 1; invert_key( c->ek, c->dk ); @@ -301,9 +299,8 @@ idea_decrypt (void *context, byte *out, const byte *in) } -#if 0 -static void -selftest( int check_decrypt ) +static const char * +selftest( void ) { static struct { byte key[16]; @@ -361,19 +358,16 @@ static struct { for(i=0; i < DIM(test_vectors); i++ ) { do_setkey( &c, test_vectors[i].key, 16 ); - if( !check_decrypt ) { - encrypt_block( &c, buffer, test_vectors[i].plain ); - if( memcmp( buffer, test_vectors[i].cipher, 8 ) ) - g10_log_fatal("idea encryption (%d) failed\n", i); - } - else { - decrypt_block( &c, buffer, test_vectors[i].cipher ); - if( memcmp( buffer, test_vectors[i].plain, 8 ) ) - g10_log_fatal("idea decryption (%d) failed\n", i); - } + encrypt_block( &c, buffer, test_vectors[i].plain ); + if( memcmp( buffer, test_vectors[i].cipher, 8 ) ) + return "IDEA test encryption failed."; + decrypt_block( &c, buffer, test_vectors[i].cipher ); + if( memcmp( buffer, test_vectors[i].plain, 8 ) ) + return "IDEA test decryption failed."; } + + return NULL; } -#endif gcry_cipher_spec_t _gcry_cipher_spec_idea = -- 1.7.8.4 From wk at gnupg.org Fri Feb 17 08:56:59 2012 From: wk at gnupg.org (Werner Koch) Date: Fri, 17 Feb 2012 08:56:59 +0100 Subject: IDEA support In-Reply-To: <20285.33407.938984.282161@a1i15.kph.uni-mainz.de> (Ulrich Mueller's message of "Thu, 16 Feb 2012 23:26:07 +0100") References: <19921.24220.826380.56157@a1i15.kph.uni-mainz.de> <871uzyv6w4.fsf@vigenere.g10code.de> <20231.40601.138265.57633@a1i15.kph.uni-mainz.de> <87mx9x3umt.fsf@vigenere.g10code.de> <20237.12522.644856.464955@a1i15.kph.uni-mainz.de> <87ipkizl95.fsf@vigenere.g10code.de> <20237.54781.307379.448936@a1i15.kph.uni-mainz.de> <20285.21815.42242.228224@a1i15.kph.uni-mainz.de> <87lio2v97m.fsf@vigenere.g10code.de> <20285.33407.938984.282161@a1i15.kph.uni-mainz.de> Message-ID: <87fwe9vqno.fsf@vigenere.g10code.de> On Thu, 16 Feb 2012 23:26, ulm at gentoo.org said: > > Patch is included below. Thanks. Salam-Shalom, Werner -- Die Gedanken sind frei. Ausnahmen regelt ein Bundesgesetz. From wk at gnupg.org Fri Feb 17 17:17:59 2012 From: wk at gnupg.org (Werner Koch) Date: Fri, 17 Feb 2012 17:17:59 +0100 Subject: Malfunction of gcry_sexp_car In-Reply-To: <1329426581.1817.92.camel@ben-desktop> (Benjamin Pousse's message of "Thu, 16 Feb 2012 22:09:38 +0100") References: <1329426581.1817.92.camel@ben-desktop> Message-ID: <87fwe9tow8.fsf@vigenere.g10code.de> On Thu, 16 Feb 2012 22:09, benjamin.pousse at member.fsf.org said: > Please find at the end of this mail my patch to solve this problem (the > patch is large because I apply a regular indentation on the full > function). Thanks for looking into this. Can you please send a patch without that indentation change. That makes it easier to see what you did. A small patch may also be applied without signing a copyright assignment or a disclaimer. Indentation changes should be done by a separate patch; it is also best to let one of the core hackers do that. Shalom-Salam, Werner -- Die Gedanken sind frei. Ausnahmen regelt ein Bundesgesetz. From benjamin.pousse at member.fsf.org Fri Feb 17 18:23:00 2012 From: benjamin.pousse at member.fsf.org (Benjamin Pousse) Date: Fri, 17 Feb 2012 18:23:00 +0100 Subject: Malfunction of gcry_sexp_car In-Reply-To: <87fwe9tow8.fsf@vigenere.g10code.de> References: <1329426581.1817.92.camel@ben-desktop> <87fwe9tow8.fsf@vigenere.g10code.de> Message-ID: <1329499382.1773.121.camel@ben-desktop> Hello, Le vendredi 17 f?vrier 2012 ? 17:17 +0100, Werner Koch a ?crit : > On Thu, 16 Feb 2012 22:09, benjamin.pousse at member.fsf.org said: > > > Please find at the end of this mail my patch to solve this problem (the > > patch is large because I apply a regular indentation on the full > > function). > > Thanks for looking into this. > > Can you please send a patch without that indentation change. That makes > it easier to see what you did. Of course. Here it is. Regards, Benjamin. diff --git a/src/sexp.c b/src/sexp.c index 0877773..2450c82 100644 --- a/src/sexp.c +++ b/src/sexp.c @@ -576,13 +576,24 @@ gcry_sexp_nth( const gcry_sexp_t list, int number ) p++; if ( *p == ST_DATA ) { - memcpy ( &n, p, sizeof n ); p += sizeof n; - newlist = gcry_malloc ( sizeof *newlist + n + 1 ); + memcpy ( &n, p, sizeof n ); + /* Allocate 1 (=sizeof *newlist) byte for ST_OPEN + 1 byte for ST_DATA + sizeof n byte for n + n byte for the data + 1 byte for ST_CLOSE + 1 byte for ST_STOP */ + newlist = gcry_malloc ( sizeof *newlist + 1 + sizeof n + n + 2 ); if (!newlist) return NULL; d = newlist->d; - memcpy ( d, p, n ); d += n; - *d++ = ST_STOP; + *d = ST_OPEN; /* Put the ST_OPEN flag */ + d++; /* Move forward */ + memcpy ( d, p, 1 + sizeof n + n ); /* Copy ST_DATA, n and the data from p to d */ + d += 1 + sizeof n + n; /* Move after the data copied */ + *d = ST_CLOSE; /* Put the ST_CLOSE flag */ + d++; /* Move forward */ + *d = ST_STOP; /* Put the ST_STOP flag */ } else if ( *p == ST_OPEN ) { const byte *head = p; From benjamin.pousse at member.fsf.org Fri Feb 17 22:16:12 2012 From: benjamin.pousse at member.fsf.org (Benjamin Pousse) Date: Fri, 17 Feb 2012 22:16:12 +0100 Subject: Malfunction of gcry_sexp_car In-Reply-To: References: <1329426581.1817.92.camel@ben-desktop> <87fwe9tow8.fsf@vigenere.g10code.de> <1329499382.1773.121.camel@ben-desktop> Message-ID: 2012/2/17 Andre Amorim : > I cant read the code, need to USE "TAB" (80, col) format > Sorry for this. Looks like my mail manager sends lines of 71 characters. Let's try with my webmail : diff --git a/src/sexp.c b/src/sexp.c index 0877773..380235b 100644 --- a/src/sexp.c +++ b/src/sexp.c @@ -576,13 +576,25 @@ gcry_sexp_nth( const gcry_sexp_t list, int number ) p++; if ( *p == ST_DATA ) { - memcpy ( &n, p, sizeof n ); p += sizeof n; - newlist = gcry_malloc ( sizeof *newlist + n + 1 ); + memcpy ( &n, p, sizeof n ); + /* Allocate 1 (=sizeof *newlist) byte for ST_OPEN + 1 byte for ST_DATA + sizeof n byte for n + n byte for the data + 1 byte for ST_CLOSE + 1 byte for ST_STOP */ + newlist = gcry_malloc ( sizeof *newlist + 1 + sizeof n + n + 2 ); if (!newlist) return NULL; - d = newlist->d; - memcpy ( d, p, n ); d += n; - *d++ = ST_STOP; + d = newlist->d; + *d = ST_OPEN; /* Put the ST_OPEN flag */ + d++; /* Move forward */ + /* Copy ST_DATA, n and the data from p to d */ + memcpy ( d, p, 1 + sizeof n + n ); + d += 1 + sizeof n + n; /* Move after the data copied */ + *d = ST_CLOSE; /* Put the ST_CLOSE flag */ + d++; /* Move forward */ + *d = ST_STOP; /* Put the ST_STOP flag */ } else if ( *p == ST_OPEN ) { const byte *head = p; From dbaryshkov at gmail.com Mon Feb 20 16:54:53 2012 From: dbaryshkov at gmail.com (Dmitry Eremin-Solenikov) Date: Mon, 20 Feb 2012 19:54:53 +0400 Subject: [PATCH 1/2] Update .gitingore to ignore more files Message-ID: <1329753294-13216-1-git-send-email-dbaryshkov@gmail.com> * .gitignore: add more tests, temporary files, etc to the list of ignored files. Signed-off-by: Dmitry Eremin-Solenikov --- .gitignore | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-) diff --git a/.gitignore b/.gitignore index ec7f8bb..3fd7446 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ po/*.gmo po/messages.mo /aclocal.m4 /autom4te.cache +/config.h.in~ /config.h.in /config.h /config.log @@ -35,9 +36,12 @@ doc/Makefile doc/fips-fsm.eps doc/fips-fsm.pdf doc/fips-fsm.png +doc/hmac256.1 doc/libgcrypt-modules.eps doc/libgcrypt-modules.pdf doc/libgcrypt-modules.png +doc/yat2m +doc/yat2m-stamp mpi/Makefile mpi/asm-syntax.h mpi/libmpi.la @@ -60,6 +64,8 @@ src/hmac256 src/libgcrypt-config src/libgcrypt.la src/versioninfo.rc +tags +TAGS tests/Makefile tests/ac tests/ac-data @@ -67,17 +73,20 @@ tests/ac-schemes tests/aeswrap tests/basic tests/benchmark +tests/curves tests/fips186-dsa tests/fipsdrv tests/hmac tests/keygen tests/keygrip tests/mpitests +tests/pkcs1v2 tests/prime tests/pubkey tests/random tests/register tests/rsacvt +tests/t-kdf tests/t-mpi-bit tests/tsexp tests/version -- 1.7.9 From dbaryshkov at gmail.com Mon Feb 20 16:54:54 2012 From: dbaryshkov at gmail.com (Dmitry Eremin-Solenikov) Date: Mon, 20 Feb 2012 19:54:54 +0400 Subject: [PATCH 2/2] Fix several warnings in configure.ac In-Reply-To: <1329753294-13216-1-git-send-email-dbaryshkov@gmail.com> References: <1329753294-13216-1-git-send-email-dbaryshkov@gmail.com> Message-ID: <1329753294-13216-2-git-send-email-dbaryshkov@gmail.com> * configure.ac: fix warnings in configure.ac due to unescaped AC_LANG_PROGRAM. Warnings are observed with autoconf 2.68. There are several more warnings observed here due to unescaped AC_LANG_xxx macros inside libtool m4 files. configure.ac:771: warning: AC_LANG_CONFTEST: no AC_LANG_SOURCE call detected in body ../../lib/autoconf/lang.m4:194: AC_LANG_CONFTEST is expanded from... ../../lib/autoconf/general.m4:2591: _AC_COMPILE_IFELSE is expanded from... ../../lib/autoconf/general.m4:2607: AC_COMPILE_IFELSE is expanded from... configure.ac:771: the top level configure.ac:971: warning: AC_LANG_CONFTEST: no AC_LANG_SOURCE call detected in body ../../lib/autoconf/lang.m4:194: AC_LANG_CONFTEST is expanded from... ../../lib/autoconf/general.m4:2591: _AC_COMPILE_IFELSE is expanded from... ../../lib/autoconf/general.m4:2607: AC_COMPILE_IFELSE is expanded from... configure.ac:971: the top level configure.ac:985: warning: AC_LANG_CONFTEST: no AC_LANG_SOURCE call detected in body ../../lib/autoconf/lang.m4:194: AC_LANG_CONFTEST is expanded from... ../../lib/autoconf/general.m4:2591: _AC_COMPILE_IFELSE is expanded from... ../../lib/autoconf/general.m4:2607: AC_COMPILE_IFELSE is expanded from... configure.ac:985: the top level Signed-off-by: Dmitry Eremin-Solenikov --- configure.ac | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index cf4a082..796261a 100644 --- a/configure.ac +++ b/configure.ac @@ -768,7 +768,7 @@ if test "$gcry_cv_visibility_attribute" = "yes"; then [gcry_cv_gcc_has_f_visibility=no _gcc_cflags_save=$CFLAGS CFLAGS="-fvisibility=hidden" - AC_COMPILE_IFELSE(AC_LANG_PROGRAM([]), + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], gcry_cv_gcc_has_f_visibility=yes) CFLAGS=$_gcc_cflags_save; ]) @@ -968,7 +968,7 @@ if test "$GCC" = yes; then AC_MSG_CHECKING([if gcc supports -Wno-missing-field-initializers]) _gcc_cflags_save=$CFLAGS CFLAGS="-Wno-missing-field-initializers" - AC_COMPILE_IFELSE(AC_LANG_PROGRAM([]),_gcc_wopt=yes,_gcc_wopt=no) + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],_gcc_wopt=yes,_gcc_wopt=no) AC_MSG_RESULT($_gcc_wopt) CFLAGS=$_gcc_cflags_save; if test x"$_gcc_wopt" = xyes ; then @@ -982,7 +982,7 @@ if test "$GCC" = yes; then AC_MSG_CHECKING([if gcc supports -Wpointer-arith]) _gcc_cflags_save=$CFLAGS CFLAGS="-Wpointer-arith" - AC_COMPILE_IFELSE(AC_LANG_PROGRAM([]),_gcc_wopt=yes,_gcc_wopt=no) + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],_gcc_wopt=yes,_gcc_wopt=no) AC_MSG_RESULT($_gcc_wopt) CFLAGS=$_gcc_cflags_save; if test x"$_gcc_wopt" = xyes ; then -- 1.7.9 From wk at gnupg.org Tue Feb 21 09:19:04 2012 From: wk at gnupg.org (Werner Koch) Date: Tue, 21 Feb 2012 09:19:04 +0100 Subject: [PATCH 1/2] Update .gitingore to ignore more files In-Reply-To: <1329753294-13216-1-git-send-email-dbaryshkov@gmail.com> (Dmitry Eremin-Solenikov's message of "Mon, 20 Feb 2012 19:54:53 +0400") References: <1329753294-13216-1-git-send-email-dbaryshkov@gmail.com> Message-ID: <87hayksio7.fsf@vigenere.g10code.de> On Mon, 20 Feb 2012 16:54, dbaryshkov at gmail.com said: > +/config.h.in~ You should have some entries in your ~/.gitignore. For example: ========== /GPATH /GRTAGS /GSYMS /GTAGS *~ .#* \#*# x y z out err po/*.gmo po/messages.mo a.out ============== In particular ====== *~ .#* \#*# ====== are pretty useful. IMHO, it does not make sense to put such patterns into specific .gitignore files. Note that we need copyright assignments for all non-trivial changes. The complexity of the changes doesn't matter, copyright is only about the text. Shalom-Salam, Werner