Mercurial > dropbear
comparison src/pk/rsa/rsa_v15_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 |
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_v15_sign_hash.c | |
15 RSA PKCS v1.5 Signature, Tom St Denis | |
16 */ | |
17 | |
18 #ifdef MRSA | |
19 | |
20 /** | |
21 PKCS #1 v1.5 pad then sign | |
22 @param in The hash to sign | |
23 @param inlen The length of the message hash (octets) | |
24 @param out [out] The signature | |
25 @param siglen [in/out] The max size and resulting size of the signature | |
26 @param hash_idx The index of the hash desired | |
27 @param key The private RSA key to perform the signature with | |
28 @return CRYPT_OK if successful | |
29 */ | |
30 int rsa_v15_sign_hash(const unsigned char *in, unsigned long inlen, | |
31 unsigned char *out, unsigned long *siglen, | |
32 int hash_idx, rsa_key *key) | |
33 { | |
34 unsigned long modulus_bitlen, modulus_bytelen, x; | |
35 int err; | |
36 | |
37 LTC_ARGCHK(in != NULL); | |
38 LTC_ARGCHK(out != NULL); | |
39 LTC_ARGCHK(siglen != NULL); | |
40 LTC_ARGCHK(key != NULL); | |
41 | |
42 /* valid hash ? */ | |
43 if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) { | |
44 return err; | |
45 } | |
46 | |
47 /* get modulus len in bits */ | |
48 modulus_bitlen = mp_count_bits(&(key->N)); | |
49 | |
50 /* outlen must be at least the size of the modulus */ | |
51 modulus_bytelen = mp_unsigned_bin_size(&(key->N)); | |
52 if (modulus_bytelen > *siglen) { | |
53 return CRYPT_BUFFER_OVERFLOW; | |
54 } | |
55 | |
56 /* PKCS #1 v1.5 pad the key */ | |
57 x = *siglen; | |
58 if ((err = pkcs_1_v15_sa_encode(in, inlen, hash_idx, modulus_bitlen, out, &x)) != CRYPT_OK) { | |
59 return err; | |
60 } | |
61 | |
62 /* RSA encode it */ | |
63 return rsa_exptmod(out, x, out, siglen, PK_PRIVATE, key); | |
64 } | |
65 | |
66 #endif |