aboutsummaryrefslogtreecommitdiffstats
path: root/g10/encr-data.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--g10/encr-data.c47
1 files changed, 13 insertions, 34 deletions
diff --git a/g10/encr-data.c b/g10/encr-data.c
index 4f8aa897d..e7e56408a 100644
--- a/g10/encr-data.c
+++ b/g10/encr-data.c
@@ -35,9 +35,7 @@ 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;
+ CIPHER_HANDLE cipher_hd;
} decode_filter_ctx_t;
@@ -50,7 +48,7 @@ decrypt_data( PKT_encrypted *ed, DEK *dek )
{
decode_filter_ctx_t dfx;
byte *p;
- int c, i;
+ int rc, c, i;
byte temp[16];
if( opt.verbose ) {
@@ -60,25 +58,14 @@ decrypt_data( PKT_encrypted *ed, DEK *dek )
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_CAST )
- return G10ERR_CIPHER_ALGO;
+ if( (rc=check_cipher_algo(dek->algo)) )
+ return rc;
if( ed->len && ed->len < 10 )
log_bug("Nanu\n"); /* oops: found a bug */
- 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 );
- }
+ dfx.cipher_hd = cipher_open( dek->algo, CIPHER_MODE_AUTO_CFB, 1 );
+ cipher_setkey( dfx.cipher_hd, dek->key, dek->keylen );
+ cipher_setiv( dfx.cipher_hd, NULL );
if( ed->len ) {
iobuf_set_limit( ed->buf, ed->len );
@@ -93,15 +80,11 @@ decrypt_data( PKT_encrypted *ed, DEK *dek )
else
temp[i] = c;
}
- 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);
+ cipher_decrypt( dfx.cipher_hd, temp, temp, 10);
+ cipher_sync( dfx.cipher_hd );
p = temp;
if( p[6] != p[8] || p[7] != p[9] ) {
- m_free(dfx.bf_ctx);
+ cipher_close(dfx.cipher_hd);
return G10ERR_BAD_KEY;
}
iobuf_push_filter( ed->buf, decode_filter, &dfx );
@@ -112,7 +95,7 @@ decrypt_data( PKT_encrypted *ed, DEK *dek )
else
iobuf_clear_eof( ed->buf );
ed->buf = NULL;
- m_free(dfx.bf_ctx);
+ cipher_close(dfx.cipher_hd);
return 0;
}
@@ -132,12 +115,8 @@ decode_filter( void *opaque, int control, IOBUF a, byte *buf, size_t *ret_len)
buf[n] = c;
}
- 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);
- }
+ if( n )
+ cipher_decrypt( fc->cipher_hd, buf, buf, n);
else
rc = -1; /* eof */
*ret_len = n;