diff options
author | Werner Koch <[email protected]> | 1998-05-26 13:38:00 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 1998-05-26 13:38:00 +0000 |
commit | eed2faab53f859c98bf85f1e324614da640bf3ff (patch) | |
tree | 4a701250cb3300121456599f90cd7a22e03e8b59 /cipher | |
parent | new release (diff) | |
download | gnupg-eed2faab53f859c98bf85f1e324614da640bf3ff.tar.gz gnupg-eed2faab53f859c98bf85f1e324614da640bf3ff.zip |
add-key works
Diffstat (limited to 'cipher')
-rw-r--r-- | cipher/ChangeLog | 8 | ||||
-rw-r--r-- | cipher/cipher.c | 41 | ||||
-rw-r--r-- | cipher/md.c | 33 | ||||
-rw-r--r-- | cipher/rand-unix.c | 2 |
4 files changed, 65 insertions, 19 deletions
diff --git a/cipher/ChangeLog b/cipher/ChangeLog index f72c64f4b..5e37e8f1a 100644 --- a/cipher/ChangeLog +++ b/cipher/ChangeLog @@ -1,3 +1,11 @@ +Fri May 22 07:30:39 1998 Werner Koch ([email protected]) + + * md.c (md_get_oid): Add a new one for TIGER. + +Thu May 21 13:24:52 1998 Werner Koch ([email protected]) + + * cipher.c: Add support for a dummy cipher + Thu May 14 15:40:36 1998 Werner Koch ([email protected]) * rmd160.c (transform): fixed sigbus - I should better diff --git a/cipher/cipher.c b/cipher/cipher.c index f449a99b5..3f1d19924 100644 --- a/cipher/cipher.c +++ b/cipher/cipher.c @@ -46,10 +46,10 @@ static struct { const char *name; int algo; int keylen; } cipher_names[] = { { "3DES", CIPHER_ALGO_3DES ,0 }, { "CAST", CIPHER_ALGO_CAST ,128 }, { "BLOWFISH160", CIPHER_ALGO_BLOWFISH160 ,160 }, - { "ROT_N", CIPHER_ALGO_ROT_N ,0 }, { "SAFER_SK128", CIPHER_ALGO_SAFER_SK128 ,0 }, { "DES_SK", CIPHER_ALGO_DES_SK ,0 }, { "BLOWFISH", CIPHER_ALGO_BLOWFISH ,128 }, + { "DUMMY" , CIPHER_ALGO_DUMMY ,128 }, {NULL} }; @@ -76,6 +76,14 @@ struct cipher_handle_s { }; +static void +dummy_setkey( void *c, byte *key, unsigned keylen ) { } +static void +dummy_encrypt_block( void *c, byte *outbuf, byte *inbuf ) { BUG(); } +static void +dummy_decrypt_block( void *c, byte *outbuf, byte *inbuf ) { BUG(); } + + /**************** * Map a string to the cipher algo */ @@ -115,6 +123,7 @@ check_cipher_algo( int algo ) case CIPHER_ALGO_BLOWFISH160: case CIPHER_ALGO_BLOWFISH: case CIPHER_ALGO_CAST: + case CIPHER_ALGO_DUMMY: return 0; default: return G10ERR_CIPHER_ALGO; @@ -154,7 +163,9 @@ cipher_open( int algo, int mode, int secure ) hd = secure ? m_alloc_secure_clear( sizeof *hd ) : m_alloc_clear( sizeof *hd ); hd->algo = algo; - if( mode == CIPHER_MODE_AUTO_CFB ) { + if( algo == CIPHER_ALGO_DUMMY ) + hd->mode = CIPHER_MODE_DUMMY; + else if( mode == CIPHER_MODE_AUTO_CFB ) { if( algo != CIPHER_ALGO_BLOWFISH160 ) hd->mode = CIPHER_MODE_PHILS_CFB; else @@ -176,6 +187,12 @@ cipher_open( int algo, int mode, int secure ) hd->decrypt = FNCCAST_CRYPT(cast5_decrypt_block); break; + case CIPHER_ALGO_DUMMY: + hd->setkey = FNCCAST_SETKEY(dummy_setkey); + hd->encrypt = FNCCAST_CRYPT(dummy_encrypt_block); + hd->decrypt = FNCCAST_CRYPT(dummy_decrypt_block); + break; + default: log_fatal("cipher_open: invalid algo %d\n", algo ); } @@ -217,8 +234,8 @@ do_ecb_encrypt( CIPHER_HANDLE c, byte *outbuf, byte *inbuf, unsigned nblocks ) for(n=0; n < nblocks; n++ ) { (*c->encrypt)( &c->c.context, outbuf, inbuf ); - inbuf += CAST5_BLOCKSIZE;; - outbuf += CAST5_BLOCKSIZE; + inbuf += STD_BLOCKSIZE;; + outbuf += STD_BLOCKSIZE; } } @@ -229,8 +246,8 @@ do_ecb_decrypt( CIPHER_HANDLE c, byte *outbuf, byte *inbuf, unsigned nblocks ) for(n=0; n < nblocks; n++ ) { (*c->decrypt)( &c->c.context, outbuf, inbuf ); - inbuf += CAST5_BLOCKSIZE;; - outbuf += CAST5_BLOCKSIZE; + inbuf += STD_BLOCKSIZE;; + outbuf += STD_BLOCKSIZE; } } @@ -397,6 +414,10 @@ cipher_encrypt( CIPHER_HANDLE c, byte *outbuf, byte *inbuf, unsigned nbytes ) case CIPHER_MODE_PHILS_CFB: do_cfb_encrypt(c, outbuf, inbuf, nbytes ); break; + case CIPHER_MODE_DUMMY: + if( inbuf != outbuf ) + memmove( outbuf, inbuf, nbytes ); + break; default: log_fatal("cipher_encrypt: invalid mode %d\n", c->mode ); } } @@ -419,6 +440,10 @@ cipher_decrypt( CIPHER_HANDLE c, byte *outbuf, byte *inbuf, unsigned nbytes ) case CIPHER_MODE_PHILS_CFB: do_cfb_decrypt(c, outbuf, inbuf, nbytes ); break; + case CIPHER_MODE_DUMMY: + if( inbuf != outbuf ) + memmove( outbuf, inbuf, nbytes ); + break; default: log_fatal("cipher_decrypt: invalid mode %d\n", c->mode ); } } @@ -433,8 +458,8 @@ void cipher_sync( CIPHER_HANDLE c ) { if( c->mode == CIPHER_MODE_PHILS_CFB && c->unused ) { - memmove(c->iv + c->unused, c->iv, CAST5_BLOCKSIZE - c->unused ); - memcpy(c->iv, c->lastiv + CAST5_BLOCKSIZE - c->unused, c->unused); + memmove(c->iv + c->unused, c->iv, STD_BLOCKSIZE - c->unused ); + memcpy(c->iv, c->lastiv + STD_BLOCKSIZE - c->unused, c->unused); c->unused = 0; } } diff --git a/cipher/md.c b/cipher/md.c index 87e66d995..4341b3968 100644 --- a/cipher/md.c +++ b/cipher/md.c @@ -216,35 +216,48 @@ md_digest_length( int algo ) } +/* fixme: put the oids in a table and add a mode to enumerate the OIDs + * to make g10/sig-check.c more portable */ const byte * md_asn_oid( int algo, size_t *asnlen, size_t *mdlen ) { - size_t alen, mlen; + size_t alen; byte *p; if( algo == DIGEST_ALGO_MD5 ) { static byte asn[18] = /* Object ID is 1.2.840.113549.2.5 */ { 0x30, 0x20, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86,0x48, 0x86, 0xf7, 0x0d, 0x02, 0x05, 0x05, 0x00, 0x04, 0x10 }; - mlen = 16; alen = DIM(asn); p = asn; + alen = DIM(asn); p = asn; } else if( algo == DIGEST_ALGO_RMD160 ) { static byte asn[15] = /* Object ID is 1.3.36.3.2.1 */ { 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x24, 0x03, 0x02, 0x01, 0x05, 0x00, 0x04, 0x14 }; - mlen = 20; alen = DIM(asn); p = asn; + alen = DIM(asn); p = asn; } else if( algo == DIGEST_ALGO_TIGER ) { - static byte asn[15] = /* FIXME: Object ID is ???????????? */ - { 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, - 0x42, 0x42, 0x42, 0x42, 0x42, 0x42 }; - mlen = 24; alen = DIM(asn); p = asn; + /* 40: SEQUENCE { + * 12: SEQUENCE { + * 8: OCTET STRING :54 49 47 45 52 31 39 32 + * 0: NULL + * : } + * 24: OCTET STRING + * : } + * + * By replacing the 5th byte (0x04) with 0x16 we would have; + * 8: IA5String 'TIGER192' + */ + static byte asn[18] = + { 0x30, 0x28, 0x30, 0x0c, 0x04, 0x08, 0x54, 0x49, 0x47, + 0x45, 0x52, 0x31, 0x39, 0x32, 0x05, 0x00, 0x04, 0x18 }; + alen = DIM(asn); p = asn; } else if( algo == DIGEST_ALGO_SHA1 ) { - static byte asn[15] = /* Objet ID is 1.3.14.3.2.26 */ + static byte asn[15] = /* Object ID is 1.3.14.3.2.26 */ { 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14 }; - mlen = 20; alen = DIM(asn); p = asn; + alen = DIM(asn); p = asn; } else log_bug("md_asn_oid(%d)", algo ); @@ -252,7 +265,7 @@ md_asn_oid( int algo, size_t *asnlen, size_t *mdlen ) if( asnlen ) *asnlen = alen; if( mdlen ) - *mdlen = mlen; + *mdlen = p[alen-1]; return p; } diff --git a/cipher/rand-unix.c b/cipher/rand-unix.c index a0f19d824..c0b7bc702 100644 --- a/cipher/rand-unix.c +++ b/cipher/rand-unix.c @@ -62,7 +62,7 @@ fast_random_poll() { #if HAVE_GETHRTIME { hrtime_t tv; - tv = gethrtime(void); + tv = gethrtime(); add_randomness( &tv, sizeof(tv), 1 ); } #elif HAVE_GETTIMEOFTIME |