comparison libtomcrypt/src/pk/rsa/rsa_verify_hash.c @ 302:973fccb59ea4 ucc-axis-hack

propagate from branch 'au.asn.ucc.matt.dropbear' (head 11034278bd1917bebcbdc69cf53b1891ce9db121) to branch 'au.asn.ucc.matt.dropbear.ucc-axis-hack' (head 10a1f614fec73d0820c3f61160d9db409b9beb46)
author Matt Johnston <matt@ucc.asn.au>
date Sat, 25 Mar 2006 12:59:58 +0000
parents 1b9e69c058d2
children 0cbe8f6dbf9e
comparison
equal deleted inserted replaced
299:740e782679be 302:973fccb59ea4
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, [email protected], http://libtomcrypt.org
10 */
11 #include "tomcrypt.h"
12
13 /**
14 @file rsa_verify_hash.c
15 RSA PKCS v2 PSS signature verification, Tom St Denis
16 */
17
18 #ifdef MRSA
19
20 /**
21 (PKCS #1, v2.0) de-sign then PSS depad
22 @param sig The signature data
23 @param siglen The length of the signature data (octets)
24 @param hash The hash of the message that was signed
25 @param hashlen The length of the hash of the message that was signed (octets)
26 @param hash_idx The index of the desired hash
27 @param saltlen The length of the salt used during signature
28 @param stat [out] The result of the signature comparison, 1==valid, 0==invalid
29 @param key The public RSA key corresponding to the key that performed the signature
30 @return CRYPT_OK on success (even if the signature is invalid)
31 */
32 int rsa_verify_hash(const unsigned char *sig, unsigned long siglen,
33 const unsigned char *hash, unsigned long hashlen,
34 int hash_idx, unsigned long saltlen,
35 int *stat, rsa_key *key)
36 {
37 unsigned long modulus_bitlen, modulus_bytelen, x;
38 int err;
39 unsigned char *tmpbuf;
40
41 LTC_ARGCHK(hash != NULL);
42 LTC_ARGCHK(sig != NULL);
43 LTC_ARGCHK(stat != NULL);
44 LTC_ARGCHK(key != NULL);
45
46 /* default to invalid */
47 *stat = 0;
48
49 /* valid hash ? */
50 if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) {
51 return err;
52 }
53
54 /* get modulus len in bits */
55 modulus_bitlen = mp_count_bits(&(key->N));
56
57 /* outlen must be at least the size of the modulus */
58 modulus_bytelen = mp_unsigned_bin_size(&(key->N));
59 if (modulus_bytelen != siglen) {
60 return CRYPT_INVALID_PACKET;
61 }
62
63 /* allocate temp buffer for decoded sig */
64 tmpbuf = XMALLOC(siglen);
65 if (tmpbuf == NULL) {
66 return CRYPT_MEM;
67 }
68
69 /* RSA decode it */
70 x = siglen;
71 if ((err = rsa_exptmod(sig, siglen, tmpbuf, &x, PK_PUBLIC, key)) != CRYPT_OK) {
72 XFREE(tmpbuf);
73 return err;
74 }
75
76 /* PSS decode it */
77 err = pkcs_1_pss_decode(hash, hashlen, tmpbuf, x, saltlen, hash_idx, modulus_bitlen, stat);
78 XFREE(tmpbuf);
79 return err;
80 }
81
82 #endif /* MRSA */
83
84 /* $Source: /cvs/libtom/libtomcrypt/src/pk/rsa/rsa_verify_hash.c,v $ */
85 /* $Revision: 1.3 $ */
86 /* $Date: 2005/05/05 14:35:59 $ */