~ubuntu-branches/ubuntu/precise/dropbear/precise

« back to all changes in this revision

Viewing changes to libtomcrypt/src/pk/rsa/rsa_decrypt_key.c

  • Committer: Bazaar Package Importer
  • Author(s): Gerrit Pape
  • Date: 2007-03-02 20:48:18 UTC
  • mfrom: (1.3.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20070302204818-ozmbou2sbyj7dus5
Tags: 0.49-1
* new upstream release, fixes
  * CVE-2007-1099: dropbear dbclient insufficient warning on hostkey
    mismatch (closes: #412899).
  * dbclient uses static "Password:" prompt instead of using the server's
    prompt (closes: #394996).
* debian/control: Suggests: openssh-client, not ssh (closes: #405686);
  Standards-Version: 3.7.2.2.
* debian/README.Debian: ssh -> openssh-server, openssh-client; remove
  'Replacing OpenSSH "sshd" with Dropbear' part, this is simply done by not
  installing the openssh-server package.
* debian/README.runit: runsvstat -> sv status.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
 * The library is free for all purposes without any express
7
7
 * guarantee it works.
8
8
 *
9
 
 * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
 
9
 * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
10
10
 */
11
11
#include "tomcrypt.h"
12
12
 
13
13
/**
14
14
  @file rsa_decrypt_key.c
15
 
  RSA PKCS #1 OAEP Decryption, Tom St Denis
16
 
*/  
 
15
  RSA PKCS #1 Decryption, Tom St Denis and Andreas Lange
 
16
*/
17
17
 
18
18
#ifdef MRSA
19
19
 
20
20
/**
21
 
   (PKCS #1 v2.0) decrypt then OAEP depad  
 
21
   PKCS #1 decrypt then v1.5 or OAEP depad
22
22
   @param in          The ciphertext
23
23
   @param inlen       The length of the ciphertext (octets)
24
24
   @param out         [out] The plaintext
26
26
   @param lparam      The system "lparam" value
27
27
   @param lparamlen   The length of the lparam value (octets)
28
28
   @param hash_idx    The index of the hash desired
 
29
   @param padding     Type of padding (LTC_PKCS_1_OAEP or LTC_PKCS_1_V1_5)
29
30
   @param stat        [out] Result of the decryption, 1==valid, 0==invalid
30
31
   @param key         The corresponding private RSA key
31
32
   @return CRYPT_OK if succcessul (even if invalid)
32
33
*/
33
 
int rsa_decrypt_key(const unsigned char *in,       unsigned long  inlen,
34
 
                          unsigned char *out,      unsigned long *outlen, 
35
 
                    const unsigned char *lparam,   unsigned long  lparamlen,
36
 
                          int            hash_idx, int           *stat,
37
 
                          rsa_key       *key)
 
34
int rsa_decrypt_key_ex(const unsigned char *in,       unsigned long  inlen,
 
35
                             unsigned char *out,      unsigned long *outlen,
 
36
                       const unsigned char *lparam,   unsigned long  lparamlen,
 
37
                             int            hash_idx, int            padding,
 
38
                             int           *stat,     rsa_key       *key)
38
39
{
39
40
  unsigned long modulus_bitlen, modulus_bytelen, x;
40
41
  int           err;
41
42
  unsigned char *tmp;
42
 
  
 
43
 
43
44
  LTC_ARGCHK(out    != NULL);
44
45
  LTC_ARGCHK(outlen != NULL);
45
46
  LTC_ARGCHK(key    != NULL);
48
49
  /* default to invalid */
49
50
  *stat = 0;
50
51
 
51
 
  /* valid hash ? */
52
 
  if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) {
53
 
     return err;
54
 
  }
55
 
  
 
52
  /* valid padding? */
 
53
 
 
54
  if ((padding != LTC_PKCS_1_V1_5) &&
 
55
      (padding != LTC_PKCS_1_OAEP)) {
 
56
    return CRYPT_PK_INVALID_PADDING;
 
57
  }
 
58
 
 
59
  if (padding == LTC_PKCS_1_OAEP) {
 
60
    /* valid hash ? */
 
61
    if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) {
 
62
       return err;
 
63
    }
 
64
  }
 
65
 
56
66
  /* get modulus len in bits */
57
 
  modulus_bitlen = mp_count_bits(&(key->N));
 
67
  modulus_bitlen = mp_count_bits( (key->N));
58
68
 
59
69
  /* outlen must be at least the size of the modulus */
60
 
  modulus_bytelen = mp_unsigned_bin_size(&(key->N));
 
70
  modulus_bytelen = mp_unsigned_bin_size( (key->N));
61
71
  if (modulus_bytelen != inlen) {
62
72
     return CRYPT_INVALID_PACKET;
63
73
  }
70
80
 
71
81
  /* rsa decode the packet */
72
82
  x = inlen;
73
 
  if ((err = rsa_exptmod(in, inlen, tmp, &x, PK_PRIVATE, key)) != CRYPT_OK) {
 
83
  if ((err = ltc_mp.rsa_me(in, inlen, tmp, &x, PK_PRIVATE, key)) != CRYPT_OK) {
74
84
     XFREE(tmp);
75
85
     return err;
76
86
  }
77
87
 
78
 
  /* now OAEP decode the packet */
79
 
  err = pkcs_1_oaep_decode(tmp, x, lparam, lparamlen, modulus_bitlen, hash_idx,
80
 
                           out, outlen, stat);
 
88
  if (padding == LTC_PKCS_1_OAEP) {
 
89
    /* now OAEP decode the packet */
 
90
    err = pkcs_1_oaep_decode(tmp, x, lparam, lparamlen, modulus_bitlen, hash_idx,
 
91
                             out, outlen, stat);
 
92
  } else {
 
93
    /* now PKCS #1 v1.5 depad the packet */
 
94
    err = pkcs_1_v1_5_decode(tmp, x, LTC_PKCS_1_EME, modulus_bitlen, out, outlen, stat);
 
95
  }
 
96
 
81
97
  XFREE(tmp);
82
98
  return err;
83
99
}
84
100
 
85
101
#endif /* MRSA */
86
102
 
87
 
 
88
 
 
89
 
 
90
 
 
91
103
/* $Source: /cvs/libtom/libtomcrypt/src/pk/rsa/rsa_decrypt_key.c,v $ */
92
 
/* $Revision: 1.3 $ */
93
 
/* $Date: 2005/05/05 14:35:59 $ */
 
104
/* $Revision: 1.8 $ */
 
105
/* $Date: 2006/11/01 09:18:22 $ */