diff options
Diffstat (limited to 'g10/gpgcompose.c')
-rw-r--r-- | g10/gpgcompose.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/g10/gpgcompose.c b/g10/gpgcompose.c index d82995d1d..190949278 100644 --- a/g10/gpgcompose.c +++ b/g10/gpgcompose.c @@ -2169,6 +2169,42 @@ static struct option sk_esk_options[] = { " --literal --value foo | " GPG_NAME " --list-packets" } }; + +/* Old version of encrypt_seskey copied from encrypt.c. */ +static void +encrypt_seskey (DEK *dek, DEK **seskey, byte *enckey) +{ + gcry_cipher_hd_t hd; + byte buf[33]; + + log_assert ( dek->keylen <= 32 ); + if (!*seskey) + { + *seskey=xmalloc_clear(sizeof(DEK)); + (*seskey)->algo=dek->algo; + make_session_key(*seskey); + /*log_hexdump( "thekey", c->key, c->keylen );*/ + } + + /* The encrypted session key is prefixed with a one-octet algorithm id. */ + buf[0] = (*seskey)->algo; + memcpy( buf + 1, (*seskey)->key, (*seskey)->keylen ); + + /* We only pass already checked values to the following function, + thus we consider any failure as fatal. */ + if (openpgp_cipher_open (&hd, dek->algo, GCRY_CIPHER_MODE_CFB, 1)) + BUG (); + if (gcry_cipher_setkey (hd, dek->key, dek->keylen)) + BUG (); + gcry_cipher_setiv (hd, NULL, 0); + gcry_cipher_encrypt (hd, buf, (*seskey)->keylen + 1, NULL, 0); + gcry_cipher_close (hd); + + memcpy( enckey, buf, (*seskey)->keylen + 1 ); + wipememory( buf, sizeof buf ); /* burn key */ +} + + static int sk_esk (const char *option, int argc, char *argv[], void *cookie) { |