aboutsummaryrefslogtreecommitdiffstats
path: root/g10/encode.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--g10/encode.c38
1 files changed, 24 insertions, 14 deletions
diff --git a/g10/encode.c b/g10/encode.c
index d3d88ca7b..3d4ad9917 100644
--- a/g10/encode.c
+++ b/g10/encode.c
@@ -329,26 +329,36 @@ write_pubkey_enc_from_list( PKC_LIST pkc_list, DEK *dek, IOBUF out )
int rc;
for( ; pkc_list; pkc_list = pkc_list->next ) {
+ MPI frame;
pkc = pkc_list->pkc;
enc = m_alloc_clear( sizeof *enc );
enc->pubkey_algo = pkc->pubkey_algo;
- if( is_ELGAMAL(enc->pubkey_algo) )
- g10_elg_encrypt( pkc, enc, dek );
- else if( is_RSA(enc->pubkey_algo) )
- g10_rsa_encrypt( pkc, enc, dek );
- else
- BUG();
- /* and write it */
- init_packet(&pkt);
- pkt.pkttype = PKT_PUBKEY_ENC;
- pkt.pkt.pubkey_enc = enc;
- rc = build_packet( out, &pkt );
+ keyid_from_pkc( pkc, enc->keyid );
+ frame = encode_session_key( dek, pubkey_nbits( pkc->pubkey_algo,
+ pkc->pkey ) );
+ rc = pubkey_encrypt( pkc->pubkey_algo, enc->data, frame, pkc->pkey );
+ mpi_free( frame );
+ if( rc )
+ log_error("pubkey_encrypt failed: %s\n", g10_errstr(rc) );
+ else {
+ if( opt.verbose ) {
+ char *ustr = get_user_id_string( enc->keyid );
+ log_info("%s encrypted for: %s\n",
+ pubkey_algo_to_string(enc->pubkey_algo), ustr );
+ m_free(ustr);
+ }
+ /* and write it */
+ init_packet(&pkt);
+ pkt.pkttype = PKT_PUBKEY_ENC;
+ pkt.pkt.pubkey_enc = enc;
+ rc = build_packet( out, &pkt );
+ if( rc )
+ log_error("build_packet(pubkey_enc) failed: %s\n", g10_errstr(rc));
+ }
free_pubkey_enc(enc);
- if( rc ) {
- log_error("build pubkey_enc packet failed: %s\n", g10_errstr(rc) );
+ if( rc )
return rc;
- }
}
return 0;
}