mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-02 22:46:30 +02:00
cast5 does now work
This commit is contained in:
parent
aa713cb0f5
commit
53a578711f
22 changed files with 644 additions and 183 deletions
|
@ -28,13 +28,16 @@
|
|||
#include "packet.h"
|
||||
#include "mpi.h"
|
||||
#include "cipher.h"
|
||||
#include "options.h"
|
||||
|
||||
|
||||
static int decode_filter( void *opaque, int control, IOBUF a,
|
||||
byte *buf, size_t *ret_len);
|
||||
|
||||
typedef struct {
|
||||
int is_cast5;
|
||||
BLOWFISH_context *bf_ctx;
|
||||
CAST5_context *cast5_ctx;
|
||||
} decode_filter_ctx_t;
|
||||
|
||||
|
||||
|
@ -50,16 +53,32 @@ decrypt_data( PKT_encrypted *ed, DEK *dek )
|
|||
int c, i;
|
||||
byte temp[16];
|
||||
|
||||
|
||||
if( opt.verbose ) {
|
||||
const char *s = cipher_algo_to_string( dek->algo );
|
||||
if( s )
|
||||
log_info("%s encrypted data\n", s );
|
||||
else
|
||||
log_info("encrypted with unknown algorithm %d\n", dek->algo );
|
||||
}
|
||||
if( dek->algo != CIPHER_ALGO_BLOWFISH
|
||||
&& dek->algo != CIPHER_ALGO_BLOWFISH128 )
|
||||
&& dek->algo != CIPHER_ALGO_BLOWFISH128
|
||||
&& dek->algo != CIPHER_ALGO_CAST )
|
||||
return G10ERR_CIPHER_ALGO;
|
||||
if( ed->len && ed->len < 10 )
|
||||
log_bug("Nanu\n"); /* oops: found a bug */
|
||||
|
||||
dfx.bf_ctx = m_alloc_secure( sizeof *dfx.bf_ctx );
|
||||
blowfish_setkey( dfx.bf_ctx, dek->key, dek->keylen );
|
||||
blowfish_setiv( dfx.bf_ctx, NULL );
|
||||
if( dek->algo == CIPHER_ALGO_CAST ) {
|
||||
dfx.is_cast5 = 1;
|
||||
dfx.cast5_ctx = m_alloc_secure( sizeof *dfx.cast5_ctx );
|
||||
cast5_setkey( dfx.cast5_ctx, dek->key, dek->keylen );
|
||||
cast5_setiv( dfx.cast5_ctx, NULL );
|
||||
}
|
||||
else {
|
||||
dfx.is_cast5 = 0;
|
||||
dfx.bf_ctx = m_alloc_secure( sizeof *dfx.bf_ctx );
|
||||
blowfish_setkey( dfx.bf_ctx, dek->key, dek->keylen );
|
||||
blowfish_setiv( dfx.bf_ctx, NULL );
|
||||
}
|
||||
|
||||
if( ed->len ) {
|
||||
iobuf_set_limit( ed->buf, ed->len );
|
||||
|
@ -74,7 +93,12 @@ decrypt_data( PKT_encrypted *ed, DEK *dek )
|
|||
else
|
||||
temp[i] = c;
|
||||
}
|
||||
blowfish_decode_cfb( dfx.bf_ctx, temp, temp, 10);
|
||||
if( dfx.is_cast5 ) {
|
||||
cast5_decode_cfb( dfx.cast5_ctx, temp, temp, 10);
|
||||
cast5_sync_cfb( dfx.cast5_ctx );
|
||||
}
|
||||
else
|
||||
blowfish_decode_cfb( dfx.bf_ctx, temp, temp, 10);
|
||||
p = temp;
|
||||
if( p[6] != p[8] || p[7] != p[9] ) {
|
||||
m_free(dfx.bf_ctx);
|
||||
|
@ -108,8 +132,12 @@ decode_filter( void *opaque, int control, IOBUF a, byte *buf, size_t *ret_len)
|
|||
buf[n] = c;
|
||||
}
|
||||
|
||||
if( n )
|
||||
blowfish_decode_cfb( fc->bf_ctx, buf, buf, n);
|
||||
if( n ) {
|
||||
if( fc->is_cast5 )
|
||||
cast5_decode_cfb( fc->cast5_ctx, buf, buf, n);
|
||||
else
|
||||
blowfish_decode_cfb( fc->bf_ctx, buf, buf, n);
|
||||
}
|
||||
else
|
||||
rc = -1; /* eof */
|
||||
*ret_len = n;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue