~ubuntu-branches/ubuntu/karmic/gnupg2/karmic-updates

« back to all changes in this revision

Viewing changes to g10/elg.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
/* elg.c
 
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_elg_encrypt( PKT_public_cert *pkc, PKT_pubkey_enc *enc, DEK *dek )
 
39
{
 
40
    MPI frame;
 
41
 
 
42
    assert( is_ELGAMAL(enc->pubkey_algo) );
 
43
 
 
44
    enc->d.elg.a = mpi_alloc( mpi_get_nlimbs(pkc->d.elg.p) );
 
45
    enc->d.elg.b = mpi_alloc( mpi_get_nlimbs(pkc->d.elg.p) );
 
46
    keyid_from_pkc( pkc, enc->keyid );
 
47
    frame = encode_session_key( dek, mpi_get_nbits(pkc->d.elg.p) );
 
48
    if( DBG_CIPHER )
 
49
        log_mpidump("Plain DEK frame: ", frame);
 
50
    elg_encrypt( enc->d.elg.a, enc->d.elg.b, frame, &pkc->d.elg );
 
51
    mpi_free( frame );
 
52
    if( DBG_CIPHER ) {
 
53
        log_mpidump("Encry DEK a: ", enc->d.elg.a );
 
54
        log_mpidump("      DEK b: ", enc->d.elg.b );
 
55
    }
 
56
    if( opt.verbose ) {
 
57
        char *ustr = get_user_id_string( enc->keyid );
 
58
        log_info("ElGamal encrypted for: %s\n", ustr );
 
59
        m_free(ustr);
 
60
    }
 
61
}
 
62
 
 
63
 
 
64
void
 
65
g10_elg_sign( PKT_secret_cert *skc, PKT_signature *sig,
 
66
              MD_HANDLE md, int digest_algo )
 
67
{
 
68
    MPI frame;
 
69
    byte *dp;
 
70
 
 
71
    assert( is_ELGAMAL(sig->pubkey_algo) );
 
72
    if( !digest_algo )
 
73
        digest_algo = md_get_algo(md);
 
74
 
 
75
    dp = md_read( md, digest_algo );
 
76
    sig->digest_algo = digest_algo;
 
77
    sig->digest_start[0] = dp[0];
 
78
    sig->digest_start[1] = dp[1];
 
79
    sig->d.elg.a = mpi_alloc( mpi_get_nlimbs(skc->d.elg.p) );
 
80
    sig->d.elg.b = mpi_alloc( mpi_get_nlimbs(skc->d.elg.p) );
 
81
    frame = encode_md_value( md, digest_algo,  mpi_get_nbits(skc->d.elg.p));
 
82
    if( DBG_CIPHER )
 
83
        log_mpidump("calc sig frame (elg): ", frame);
 
84
    elg_sign( sig->d.elg.a, sig->d.elg.b, frame, &skc->d.elg );
 
85
    mpi_free(frame);
 
86
    if( opt.verbose ) {
 
87
        char *ustr = get_user_id_string( sig->keyid );
 
88
        log_info("ElGamal signature from: %s\n", ustr );
 
89
        m_free(ustr);
 
90
    }
 
91
}
 
92