Mercurial > dropbear
comparison src/pk/rsa/rsa_sign_hash.c @ 191:1c15b283127b libtomcrypt-orig
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Fri, 06 May 2005 13:23:02 +0000 |
parents | |
children | 39d5d58461d6 |
comparison
equal
deleted
inserted
replaced
143:5d99163f7e32 | 191:1c15b283127b |
---|---|
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_sign_hash.c | |
15 RSA PKCS v2 PSS sign hash, Tom St Denis | |
16 */ | |
17 | |
18 #ifdef MRSA | |
19 | |
20 /** | |
21 (PKCS #1, v2.0) PSS pad then sign | |
22 @param in The hash to sign | |
23 @param inlen The length of the hash to sign (octets) | |
24 @param out [out] The signature | |
25 @param outlen [in/out] The max size and resulting size of the signature | |
26 @param prng An active PRNG state | |
27 @param prng_idx The index of the PRNG desired | |
28 @param hash_idx The index of the hash desired | |
29 @param saltlen The length of the salt desired (octets) | |
30 @param key The private RSA key to use | |
31 @return CRYPT_OK if successful | |
32 */ | |
33 int rsa_sign_hash(const unsigned char *in, unsigned long inlen, | |
34 unsigned char *out, unsigned long *outlen, | |
35 prng_state *prng, int prng_idx, | |
36 int hash_idx, unsigned long saltlen, | |
37 rsa_key *key) | |
38 { | |
39 unsigned long modulus_bitlen, modulus_bytelen, x; | |
40 int err; | |
41 | |
42 LTC_ARGCHK(in != NULL); | |
43 LTC_ARGCHK(out != NULL); | |
44 LTC_ARGCHK(outlen != NULL); | |
45 LTC_ARGCHK(key != NULL); | |
46 | |
47 /* valid prng and hash ? */ | |
48 if ((err = prng_is_valid(prng_idx)) != CRYPT_OK) { | |
49 return err; | |
50 } | |
51 if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) { | |
52 return err; | |
53 } | |
54 | |
55 /* get modulus len in bits */ | |
56 modulus_bitlen = mp_count_bits(&(key->N)); | |
57 | |
58 /* outlen must be at least the size of the modulus */ | |
59 modulus_bytelen = mp_unsigned_bin_size(&(key->N)); | |
60 if (modulus_bytelen > *outlen) { | |
61 return CRYPT_BUFFER_OVERFLOW; | |
62 } | |
63 | |
64 /* PSS pad the key */ | |
65 x = *outlen; | |
66 if ((err = pkcs_1_pss_encode(in, inlen, saltlen, prng, prng_idx, | |
67 hash_idx, modulus_bitlen, out, &x)) != CRYPT_OK) { | |
68 return err; | |
69 } | |
70 | |
71 /* RSA encode it */ | |
72 return rsa_exptmod(out, x, out, outlen, PK_PRIVATE, key); | |
73 } | |
74 | |
75 #endif /* MRSA */ |