1
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
3
* LibTomCrypt is a library that provides various cryptographic
4
* algorithms in a highly modular and flexible manner.
6
* The library is free for all purposes without any express
9
* Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
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)
23
unsigned long modulus_bitlen, modulus_bytelen, x;
25
unsigned char *tmpbuf;
27
_ARGCHK(msghash != NULL);
29
_ARGCHK(stat != NULL);
32
/* default to invalid */
36
if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) {
40
if ((err = prng_is_valid(prng_idx)) != CRYPT_OK) {
44
/* get modulus len in bits */
45
modulus_bitlen = mp_count_bits(&(key->N));
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;
53
/* allocate temp buffer for decoded sig */
54
tmpbuf = XMALLOC(siglen);
61
if ((err = rsa_exptmod(sig, siglen, tmpbuf, &x, PK_PUBLIC, prng, prng_idx, key)) != CRYPT_OK) {
67
err = pkcs_1_pss_decode(msghash, msghashlen, tmpbuf, x, saltlen, hash_idx, modulus_bitlen, stat);