summaryrefslogtreecommitdiffstats
path: root/g10/passphrase.c
diff options
context:
space:
mode:
Diffstat (limited to 'g10/passphrase.c')
-rw-r--r--g10/passphrase.c38
1 files changed, 20 insertions, 18 deletions
diff --git a/g10/passphrase.c b/g10/passphrase.c
index 6026ff7f9..46527d8f5 100644
--- a/g10/passphrase.c
+++ b/g10/passphrase.c
@@ -159,14 +159,14 @@ passphrase_to_dek( u32 *keyid, int pubkey_algo,
tty_printf(_("\nYou need a passphrase to unlock the secret key for\n"
"user: \"") );
p = get_user_id( keyid, &n );
- tty_print_string( p, n );
+ tty_print_utf8_string( p, n );
m_free(p);
tty_printf("\"\n");
if( !get_pubkey( pk, keyid ) ) {
- const char *s = pubkey_algo_to_string( pk->pubkey_algo );
tty_printf( _("%u-bit %s key, ID %08lX, created %s"),
- nbits_from_pk( pk ), s?s:"?", (ulong)keyid[1],
+ nbits_from_pk( pk ),
+ gcry_pk_algo_name( pk->pubkey_algo ), (ulong)keyid[1],
strtimestamp(pk->timestamp) );
if( keyid[2] && keyid[3] && keyid[0] != keyid[2]
&& keyid[1] != keyid[3] )
@@ -229,22 +229,24 @@ passphrase_to_dek( u32 *keyid, int pubkey_algo,
static void
hash_passphrase( DEK *dek, char *pw, STRING2KEY *s2k, int create )
{
- MD_HANDLE md;
+ GCRY_MD_HD md;
int pass, i;
int used = 0;
int pwlen = strlen(pw);
assert( s2k->hash_algo );
- dek->keylen = cipher_get_keylen( dek->algo ) / 8;
+ dek->keylen = gcry_cipher_get_algo_keylen( dek->algo );
if( !(dek->keylen > 0 && dek->keylen <= DIM(dek->key)) )
BUG();
- md = md_open( s2k->hash_algo, 1);
+ if( !(md = gcry_md_open( s2k->hash_algo, GCRY_MD_FLAG_SECURE )) )
+ BUG();
+
for(pass=0; used < dek->keylen ; pass++ ) {
if( pass ) {
- md_reset(md);
+ gcry_md_reset(md);
for(i=0; i < pass; i++ ) /* preset the hash context */
- md_putc(md, 0 );
+ gcry_md_putc(md, 0 );
}
if( s2k->mode == 1 || s2k->mode == 3 ) {
@@ -264,28 +266,28 @@ hash_passphrase( DEK *dek, char *pw, STRING2KEY *s2k, int create )
}
/* a little bit complicated because we need a ulong for count */
while( count > len2 ) { /* maybe iterated+salted */
- md_write( md, s2k->salt, 8 );
- md_write( md, pw, pwlen );
+ gcry_md_write( md, s2k->salt, 8 );
+ gcry_md_write( md, pw, pwlen );
count -= len2;
}
if( count < 8 )
- md_write( md, s2k->salt, count );
+ gcry_md_write( md, s2k->salt, count );
else {
- md_write( md, s2k->salt, 8 );
+ gcry_md_write( md, s2k->salt, 8 );
count -= 8;
assert( count >= 0 );
- md_write( md, pw, count );
+ gcry_md_write( md, pw, count );
}
}
else
- md_write( md, pw, pwlen );
- md_final( md );
- i = md_digest_length( s2k->hash_algo );
+ gcry_md_write( md, pw, pwlen );
+ gcry_md_final( md );
+ i = gcry_md_get_algo_dlen( s2k->hash_algo );
if( i > dek->keylen - used )
i = dek->keylen - used;
- memcpy( dek->key+used, md_read(md, s2k->hash_algo), i );
+ memcpy( dek->key+used, gcry_md_read(md, s2k->hash_algo), i );
used += i;
}
- md_close(md);
+ gcry_md_close(md);
}