diff options
Diffstat (limited to 'libtomcrypt/pk/rsa/rsa_export.c')
-rw-r--r-- | libtomcrypt/pk/rsa/rsa_export.c | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/libtomcrypt/pk/rsa/rsa_export.c b/libtomcrypt/pk/rsa/rsa_export.c index 04e59d8..33c222d 100644 --- a/libtomcrypt/pk/rsa/rsa_export.c +++ b/libtomcrypt/pk/rsa/rsa_export.c @@ -9,7 +9,7 @@ * Tom St Denis, tomstdenis@gmail.com, http://libtom.org */ #include "tomcrypt.h" - +#include <ncr_int.h> /** @file rsa_export.c Export RSA LTC_PKCS keys, Tom St Denis @@ -28,6 +28,7 @@ int rsa_export(unsigned char *out, unsigned long *outlen, int type, rsa_key *key) { unsigned long zero=0; + int err; LTC_ARGCHK(out != NULL); LTC_ARGCHK(outlen != NULL); LTC_ARGCHK(key != NULL); @@ -54,11 +55,27 @@ int rsa_export(unsigned char *out, unsigned long *outlen, int type, rsa_key *key LTC_ASN1_INTEGER, 1UL, &key->qP, LTC_ASN1_EOL, 0UL, NULL); } else { - /* public key */ - return der_encode_sequence_multi(out, outlen, + unsigned long tmplen = (mp_count_bits(&key->N)/8)*2+8; + unsigned char* tmp = XMALLOC(tmplen); + + if (tmp == NULL) { + return CRYPT_MEM; + } + + err = der_encode_sequence_multi(tmp, &tmplen, LTC_ASN1_INTEGER, 1UL, &key->N, LTC_ASN1_INTEGER, 1UL, &key->e, LTC_ASN1_EOL, 0UL, NULL); + if (err != CRYPT_OK) { + goto error; + } + + err = der_encode_subject_public_key_info(out, outlen, + PKA_RSA, tmp, tmplen, LTC_ASN1_NULL, NULL, 0); + +error: + XFREE(tmp); + return err; } } |