Mercurial > dropbear
comparison libtomcrypt/src/pk/rsa/rsa_encrypt_key.c @ 285:1b9e69c058d2
propagate from branch 'au.asn.ucc.matt.ltc.dropbear' (head 20dccfc09627970a312d77fb41dc2970b62689c3)
to branch 'au.asn.ucc.matt.dropbear' (head fdf4a7a3b97ae5046139915de7e40399cceb2c01)
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 08 Mar 2006 13:23:58 +0000 |
parents | |
children | 0cbe8f6dbf9e |
comparison
equal
deleted
inserted
replaced
281:997e6f7dc01e | 285:1b9e69c058d2 |
---|---|
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_encrypt_key.c | |
15 RSA PKCS OAEP encryption, Tom St Denis | |
16 */ | |
17 | |
18 #ifdef MRSA | |
19 | |
20 /** | |
21 (PKCS #1 v2.0) OAEP pad then encrypt | |
22 @param in The plaintext | |
23 @param inlen The length of the plaintext (octets) | |
24 @param out [out] The ciphertext | |
25 @param outlen [in/out] The max size and resulting size of the ciphertext | |
26 @param lparam The system "lparam" for the encryption | |
27 @param lparamlen The length of lparam (octets) | |
28 @param prng An active PRNG | |
29 @param prng_idx The index of the desired prng | |
30 @param hash_idx The index of the desired hash | |
31 @param key The RSA key to encrypt to | |
32 @return CRYPT_OK if successful | |
33 */ | |
34 int rsa_encrypt_key(const unsigned char *in, unsigned long inlen, | |
35 unsigned char *out, unsigned long *outlen, | |
36 const unsigned char *lparam, unsigned long lparamlen, | |
37 prng_state *prng, int prng_idx, int hash_idx, 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 /* OAEP pad the key */ | |
65 x = *outlen; | |
66 if ((err = pkcs_1_oaep_encode(in, inlen, lparam, | |
67 lparamlen, modulus_bitlen, prng, prng_idx, hash_idx, | |
68 out, &x)) != CRYPT_OK) { | |
69 return err; | |
70 } | |
71 | |
72 /* rsa exptmod the OAEP pad */ | |
73 return rsa_exptmod(out, x, out, outlen, PK_PUBLIC, key); | |
74 } | |
75 | |
76 #endif /* MRSA */ | |
77 | |
78 /* $Source: /cvs/libtom/libtomcrypt/src/pk/rsa/rsa_encrypt_key.c,v $ */ | |
79 /* $Revision: 1.3 $ */ | |
80 /* $Date: 2005/05/05 14:35:59 $ */ |