~ubuntu-branches/ubuntu/utopic/dropbear/utopic-proposed

« back to all changes in this revision

Viewing changes to libtomcrypt/rsa_verify_hash.c

  • Committer: Bazaar Package Importer
  • Author(s): Matt Johnston
  • Date: 2005-12-08 19:20:21 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051208192021-nyp9rwnt77nsg6ty
Tags: 0.47-1
* New upstream release.
* SECURITY: Fix incorrect buffer sizing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
2
 
 *
3
 
 * LibTomCrypt is a library that provides various cryptographic
4
 
 * algorithms in a highly modular and flexible manner.
5
 
 *
6
 
 * The library is free for all purposes without any express
7
 
 * guarantee it works.
8
 
 *
9
 
 * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
10
 
 */
11
 
 
12
 
#include "mycrypt.h"
13
 
 
14
 
#ifdef MRSA
15
 
 
16
 
/* (PKCS #1, v2.0) de-sign then PSS depad */
17
 
int rsa_verify_hash(const unsigned char *sig,      unsigned long siglen,
18
 
                    const unsigned char *msghash,  unsigned long msghashlen,
19
 
                          prng_state    *prng,     int           prng_idx,
20
 
                          int            hash_idx, unsigned long saltlen,
21
 
                          int           *stat,     rsa_key      *key)
22
 
{
23
 
   unsigned long modulus_bitlen, modulus_bytelen, x;
24
 
   int           err;
25
 
   unsigned char *tmpbuf;
26
 
   
27
 
  _ARGCHK(msghash  != NULL);
28
 
  _ARGCHK(sig      != NULL);
29
 
  _ARGCHK(stat     != NULL);
30
 
  _ARGCHK(key      != NULL);
31
 
 
32
 
  /* default to invalid */
33
 
  *stat = 0;
34
 
  
35
 
  /* valid hash ? */
36
 
  if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) {
37
 
     return err;
38
 
  }
39
 
 
40
 
  if ((err = prng_is_valid(prng_idx)) != CRYPT_OK) {
41
 
     return err;
42
 
  }
43
 
  
44
 
  /* get modulus len in bits */
45
 
  modulus_bitlen = mp_count_bits(&(key->N));
46
 
 
47
 
  /* outlen must be at least the size of the modulus */
48
 
  modulus_bytelen = mp_unsigned_bin_size(&(key->N));
49
 
  if (modulus_bytelen != siglen) {
50
 
     return CRYPT_INVALID_PACKET;
51
 
  }
52
 
  
53
 
  /* allocate temp buffer for decoded sig */
54
 
  tmpbuf = XMALLOC(siglen);
55
 
  if (tmpbuf == NULL) {
56
 
     return CRYPT_MEM;
57
 
  }
58
 
      
59
 
  /* RSA decode it  */
60
 
  x = siglen;
61
 
  if ((err = rsa_exptmod(sig, siglen, tmpbuf, &x, PK_PUBLIC, prng, prng_idx, key)) != CRYPT_OK) {
62
 
     XFREE(tmpbuf);
63
 
     return err;
64
 
  }
65
 
  
66
 
  /* PSS decode it */
67
 
  err = pkcs_1_pss_decode(msghash, msghashlen, tmpbuf, x, saltlen, hash_idx, modulus_bitlen, stat);
68
 
  XFREE(tmpbuf);
69
 
  return err;
70
 
}
71
 
 
72
 
#endif /* MRSA */