From a74ac2b22c1c1a2c78e4d9b255c190570509a84d Mon Sep 17 00:00:00 2001 From: John Safranek Date: Thu, 11 Apr 2013 14:03:18 -0700 Subject: [PATCH] added case to DerToPem() to add EC header and footer to the PEM output --- ctaocrypt/src/asn.c | 11 ++++++++++- cyassl/ctaocrypt/asn_public.h | 3 ++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ctaocrypt/src/asn.c b/ctaocrypt/src/asn.c index 3e8ad3d00..fda23853d 100644 --- a/ctaocrypt/src/asn.c +++ b/ctaocrypt/src/asn.c @@ -2800,10 +2800,19 @@ int DerToPem(const byte* der, word32 derSz, byte* output, word32 outSz, if (type == CERT_TYPE) { XSTRNCPY(header, "-----BEGIN CERTIFICATE-----\n", sizeof(header)); XSTRNCPY(footer, "-----END CERTIFICATE-----\n", sizeof(footer)); - } else { + } + else if (type == PRIVATEKEY_TYPE) { XSTRNCPY(header, "-----BEGIN RSA PRIVATE KEY-----\n", sizeof(header)); XSTRNCPY(footer, "-----END RSA PRIVATE KEY-----\n", sizeof(footer)); } + #ifdef HAVE_ECC + else if (type == ECC_PRIVATEKEY_TYPE) { + XSTRNCPY(header, "-----BEGIN EC PRIVATE KEY-----\n", sizeof(header)); + XSTRNCPY(footer, "-----END EC PRIVATE KEY-----\n", sizeof(footer)); + } + #endif + else + return BAD_FUNC_ARG; headerLen = (int)XSTRLEN(header); footerLen = (int)XSTRLEN(footer); diff --git a/cyassl/ctaocrypt/asn_public.h b/cyassl/ctaocrypt/asn_public.h index a1b05bcd5..f824fbb36 100644 --- a/cyassl/ctaocrypt/asn_public.h +++ b/cyassl/ctaocrypt/asn_public.h @@ -40,7 +40,8 @@ enum CertType { PRIVATEKEY_TYPE, DH_PARAM_TYPE, CRL_TYPE, - CA_TYPE + CA_TYPE, + ECC_PRIVATEKEY_TYPE };