comparison rsa_verify_hash.c @ 15:6362d3854bb4 libtomcrypt-orig

0.96 release of LibTomCrypt
author Matt Johnston <matt@ucc.asn.au>
date Tue, 15 Jun 2004 14:07:21 +0000
parents
children 5d99163f7e32
comparison
equal deleted inserted replaced
3:7faae8f46238 15:6362d3854bb4
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
12 #include "mycrypt.h"
13
14 #ifdef MRSA
15
16 /* design 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 /* valid hash ? */
33 if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) {
34 return err;
35 }
36
37 if ((err = prng_is_valid(prng_idx)) != CRYPT_OK) {
38 return err;
39 }
40
41 /* get modulus len in bits */
42 modulus_bitlen = mp_count_bits(&(key->N));
43
44 /* outlen must be at least the size of the modulus */
45 modulus_bytelen = mp_unsigned_bin_size(&(key->N));
46 if (modulus_bytelen != siglen) {
47 return CRYPT_INVALID_PACKET;
48 }
49
50 /* allocate temp buffer for decoded sig */
51 tmpbuf = XCALLOC(1, modulus_bytelen + 1);
52 if (tmpbuf == NULL) {
53 return CRYPT_MEM;
54 }
55
56 /* RSA decode it */
57 x = siglen;
58 if ((err = rsa_exptmod(sig, siglen, tmpbuf, &x, PK_PUBLIC, prng, prng_idx, key)) != CRYPT_OK) {
59 XFREE(tmpbuf);
60 return err;
61 }
62
63 /* PSS decode it */
64 err = pkcs_1_pss_decode(msghash, msghashlen, tmpbuf, x, saltlen, hash_idx, modulus_bitlen, stat);
65 XFREE(tmpbuf);
66 return err;
67 }
68
69 #endif /* MRSA */