comparison libtomcrypt/src/pk/rsa/rsa_export.c @ 435:337c45621e81

merge of 'a9b0496634cdd25647b65e585cc3240f3fa699ee' and 'c22be8b8f570b48e9662dac32c7b3e7148a42206'
author Matt Johnston <matt@ucc.asn.au>
date Thu, 22 Feb 2007 14:53:49 +0000
parents 0cbe8f6dbf9e
children f849a5ca2efc
comparison
equal deleted inserted replaced
434:0aaaf68e97dc 435:337c45621e81
4 * algorithms in a highly modular and flexible manner. 4 * algorithms in a highly modular and flexible manner.
5 * 5 *
6 * The library is free for all purposes without any express 6 * The library is free for all purposes without any express
7 * guarantee it works. 7 * guarantee it works.
8 * 8 *
9 * Tom St Denis, [email protected], http://libtomcrypt.org 9 * Tom St Denis, [email protected], http://libtomcrypt.com
10 */ 10 */
11 #include "tomcrypt.h" 11 #include "tomcrypt.h"
12 12
13 /** 13 /**
14 @file rsa_export.c 14 @file rsa_export.c
25 @param key The RSA key to export 25 @param key The RSA key to export
26 @return CRYPT_OK if successful 26 @return CRYPT_OK if successful
27 */ 27 */
28 int rsa_export(unsigned char *out, unsigned long *outlen, int type, rsa_key *key) 28 int rsa_export(unsigned char *out, unsigned long *outlen, int type, rsa_key *key)
29 { 29 {
30 int err;
31 unsigned long zero=0; 30 unsigned long zero=0;
32
33 LTC_ARGCHK(out != NULL); 31 LTC_ARGCHK(out != NULL);
34 LTC_ARGCHK(outlen != NULL); 32 LTC_ARGCHK(outlen != NULL);
35 LTC_ARGCHK(key != NULL); 33 LTC_ARGCHK(key != NULL);
36 34
37 /* type valid? */ 35 /* type valid? */
42 if (type == PK_PRIVATE) { 40 if (type == PK_PRIVATE) {
43 /* private key */ 41 /* private key */
44 /* output is 42 /* output is
45 Version, n, e, d, p, q, d mod (p-1), d mod (q - 1), 1/q mod p 43 Version, n, e, d, p, q, d mod (p-1), d mod (q - 1), 1/q mod p
46 */ 44 */
47 if ((err = der_encode_sequence_multi(out, outlen, 45 return der_encode_sequence_multi(out, outlen,
48 LTC_ASN1_SHORT_INTEGER, 1UL, &zero, 46 LTC_ASN1_SHORT_INTEGER, 1UL, &zero,
49 LTC_ASN1_INTEGER, 1UL, &key->N, 47 LTC_ASN1_INTEGER, 1UL, key->N,
50 LTC_ASN1_INTEGER, 1UL, &key->e, 48 LTC_ASN1_INTEGER, 1UL, key->e,
51 LTC_ASN1_INTEGER, 1UL, &key->d, 49 LTC_ASN1_INTEGER, 1UL, key->d,
52 LTC_ASN1_INTEGER, 1UL, &key->p, 50 LTC_ASN1_INTEGER, 1UL, key->p,
53 LTC_ASN1_INTEGER, 1UL, &key->q, 51 LTC_ASN1_INTEGER, 1UL, key->q,
54 LTC_ASN1_INTEGER, 1UL, &key->dP, 52 LTC_ASN1_INTEGER, 1UL, key->dP,
55 LTC_ASN1_INTEGER, 1UL, &key->dQ, 53 LTC_ASN1_INTEGER, 1UL, key->dQ,
56 LTC_ASN1_INTEGER, 1UL, &key->qP, 54 LTC_ASN1_INTEGER, 1UL, key->qP,
57 LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) { 55 LTC_ASN1_EOL, 0UL, NULL);
58 return err;
59 }
60
61 /* clear zero and return */
62 return CRYPT_OK;
63 } else { 56 } else {
64 /* public key */ 57 /* public key */
65 return der_encode_sequence_multi(out, outlen, 58 return der_encode_sequence_multi(out, outlen,
66 LTC_ASN1_INTEGER, 1UL, &key->N, 59 LTC_ASN1_INTEGER, 1UL, key->N,
67 LTC_ASN1_INTEGER, 1UL, &key->e, 60 LTC_ASN1_INTEGER, 1UL, key->e,
68 LTC_ASN1_EOL, 0UL, NULL); 61 LTC_ASN1_EOL, 0UL, NULL);
69 } 62 }
70 } 63 }
71 64
72 #endif /* MRSA */ 65 #endif /* MRSA */
73 66
74 /* $Source: /cvs/libtom/libtomcrypt/src/pk/rsa/rsa_export.c,v $ */ 67 /* $Source: /cvs/libtom/libtomcrypt/src/pk/rsa/rsa_export.c,v $ */
75 /* $Revision: 1.11 $ */ 68 /* $Revision: 1.15 $ */
76 /* $Date: 2005/06/04 01:42:48 $ */ 69 /* $Date: 2006/03/31 14:15:35 $ */