~ubuntu-branches/ubuntu/precise/gnupg2/precise-proposed

« back to all changes in this revision

Viewing changes to g10/rsa.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Urlichs
  • Date: 2006-01-24 04:31:42 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060124043142-pbg192or6qxv3yk2
Tags: 1.9.20-1
* New Upstream version. Closes:#306890,#344530
  * Closes:#320490: gpg-protect-tool fails to decrypt PKCS-12 files 
* Depend on libopensc2-dev, not -1-. Closes:#348106

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* rsa.c  - glue code for RSA cipher
 
2
 *      Copyright (C) 1998 Free Software Foundation, Inc.
 
3
 *
 
4
 * This file is part of GNUPG.
 
5
 *
 
6
 * GNUPG is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * GNUPG is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 
19
 */
 
20
 
 
21
#include <config.h>
 
22
#include <stdio.h>
 
23
#include <stdlib.h>
 
24
#include <string.h>
 
25
#include <errno.h>
 
26
#include <assert.h>
 
27
 
 
28
#include "options.h"
 
29
#include "packet.h"
 
30
#include "errors.h"
 
31
#include "iobuf.h"
 
32
#include "keydb.h"
 
33
#include "memory.h"
 
34
#include "util.h"
 
35
#include "main.h"
 
36
 
 
37
void
 
38
g10_rsa_encrypt( PKT_public_cert *pkc, PKT_pubkey_enc *enc, DEK *dek )
 
39
{
 
40
  #ifdef HAVE_RSA_CIPHER
 
41
    assert( is_RSA(enc->pubkey_algo) );
 
42
 
 
43
    keyid_from_pkc( pkc, enc->keyid );
 
44
    enc->d.rsa.rsa_integer = encode_session_key( dek,
 
45
                                mpi_get_nbits(pkc->d.rsa.rsa_n) );
 
46
    if( DBG_CIPHER )
 
47
        log_mpidump("Plain DEK frame: ", enc->d.rsa.rsa_integer);
 
48
    rsa_public( enc->d.rsa.rsa_integer, enc->d.rsa.rsa_integer, &pkc->d.rsa);
 
49
    if( DBG_CIPHER )
 
50
        log_mpidump("Encry DEK frame: ", enc->d.rsa.rsa_integer);
 
51
    if( opt.verbose ) {
 
52
        char *ustr = get_user_id_string( enc->keyid );
 
53
        log_info("RSA encrypted for: %s\n", ustr );
 
54
        m_free(ustr);
 
55
    }
 
56
 #else
 
57
    BUG();
 
58
 #endif/* ! HAVE_RSA_CIPHER*/
 
59
}
 
60
 
 
61
 
 
62
void
 
63
g10_rsa_sign( PKT_secret_cert *skc, PKT_signature *sig,
 
64
                                    MD_HANDLE md, int digest_algo )
 
65
{
 
66
 #ifdef HAVE_RSA_CIPHER
 
67
    byte *dp;
 
68
 
 
69
    assert( is_RSA(sig->pubkey_algo) );
 
70
    if( !digest_algo )
 
71
        digest_algo = md_get_algo(md);
 
72
 
 
73
    dp = md_read( md, digest_algo );
 
74
    sig->digest_algo = digest_algo;
 
75
    sig->digest_start[0] = dp[0];
 
76
    sig->digest_start[1] = dp[1];
 
77
    sig->d.rsa.rsa_integer =
 
78
           encode_md_value( md, digest_algo, mpi_get_nbits(skc->d.rsa.rsa_n));
 
79
    rsa_secret( sig->d.rsa.rsa_integer, sig->d.rsa.rsa_integer, &skc->d.rsa );
 
80
    if( opt.verbose ) {
 
81
        char *ustr = get_user_id_string( sig->keyid );
 
82
        log_info("RSA signature from: %s\n", ustr );
 
83
        m_free(ustr);
 
84
    }
 
85
 #else
 
86
    BUG();
 
87
 #endif/* ! HAVE_RSA_CIPHER*/
 
88
}
 
89