From f402d7eed9618195211fc2eb66cab5ae85f027d9 Mon Sep 17 00:00:00 2001 From: toddouska Date: Tue, 29 Oct 2013 16:44:33 -0700 Subject: [PATCH] add ecc export pirvate only --- ctaocrypt/src/ecc.c | 25 +++++++++++++++++++++++++ ctaocrypt/test/test.c | 5 +++++ cyassl/ctaocrypt/ecc.h | 2 ++ 3 files changed, 32 insertions(+) diff --git a/ctaocrypt/src/ecc.c b/ctaocrypt/src/ecc.c index 0e6591b95..9b6cb1aa8 100644 --- a/ctaocrypt/src/ecc.c +++ b/ctaocrypt/src/ecc.c @@ -2043,6 +2043,31 @@ int ecc_import_x963(const byte* in, word32 inLen, ecc_key* key) } +/* export ecc private key only raw, outLen is in/out size + return MP_OKAY on success */ +int ecc_export_private_only(ecc_key* key, byte* out, word32* outLen) +{ + word32 numlen; + + if (key == NULL || out == NULL || outLen == NULL) + return ECC_BAD_ARG_E; + + if (ecc_is_valid_idx(key->idx) == 0) { + return ECC_BAD_ARG_E; + } + numlen = key->dp->size; + + if (*outLen < numlen) { + *outLen = numlen; + return BUFFER_E; + } + *outLen = numlen; + XMEMSET(out, 0, *outLen); + return mp_to_unsigned_bin(&key->k, out + (numlen - + mp_unsigned_bin_size(&key->k))); +} + + /* ecc private key import, public key in ANSI X9.63 format, private raw */ int ecc_import_private_key(const byte* priv, word32 privSz, const byte* pub, word32 pubSz, ecc_key* key) diff --git a/ctaocrypt/test/test.c b/ctaocrypt/test/test.c index da922c979..cde9b2b77 100644 --- a/ctaocrypt/test/test.c +++ b/ctaocrypt/test/test.c @@ -3482,6 +3482,11 @@ int ecc_test(void) if (verify != 1) return -1012; + x = sizeof(exportBuf); + ret = ecc_export_private_only(&userA, exportBuf, &x); + if (ret != 0) + return -1013; + ecc_free(&pubKey); ecc_free(&userB); ecc_free(&userA); diff --git a/cyassl/ctaocrypt/ecc.h b/cyassl/ctaocrypt/ecc.h index 9f3cf7cf5..e88c10ab4 100644 --- a/cyassl/ctaocrypt/ecc.h +++ b/cyassl/ctaocrypt/ecc.h @@ -109,6 +109,8 @@ int ecc_import_x963(const byte* in, word32 inLen, ecc_key* key); CYASSL_API int ecc_import_private_key(const byte* priv, word32 privSz, const byte* pub, word32 pubSz, ecc_key* key); +CYASSL_API +int ecc_export_private_only(ecc_key* key, byte* out, word32* outLen); /* size helper */ CYASSL_API