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@gmail.com, http://libtomcrypt.org
14
@file rsa_verify_hash.c
15
RSA PKCS v2 PSS signature verification, Tom St Denis
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)
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)
37
unsigned long modulus_bitlen, modulus_bytelen, x;
39
unsigned char *tmpbuf;
41
LTC_ARGCHK(hash != NULL);
42
LTC_ARGCHK(sig != NULL);
43
LTC_ARGCHK(stat != NULL);
44
LTC_ARGCHK(key != NULL);
46
/* default to invalid */
50
if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) {
54
/* get modulus len in bits */
55
modulus_bitlen = mp_count_bits(&(key->N));
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;
63
/* allocate temp buffer for decoded sig */
64
tmpbuf = XMALLOC(siglen);
71
if ((err = rsa_exptmod(sig, siglen, tmpbuf, &x, PK_PUBLIC, key)) != CRYPT_OK) {
77
err = pkcs_1_pss_decode(hash, hashlen, tmpbuf, x, saltlen, hash_idx, modulus_bitlen, stat);
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 $ */