diff --git a/ctaocrypt/src/rsa.c b/ctaocrypt/src/rsa.c index af56f9bac..a0ff196aa 100644 --- a/ctaocrypt/src/rsa.c +++ b/ctaocrypt/src/rsa.c @@ -469,6 +469,33 @@ int RsaEncryptSize(RsaKey* key) } +int RsaFlattenPublicKey(RsaKey* key, byte* e, word32* eSz, byte* n, word32* nSz) +{ + int sz, ret; + + if (key == NULL || e == NULL || eSz == NULL || n == NULL || nSz == NULL) + return BAD_FUNC_ARG; + + sz = mp_unsigned_bin_size(&key->e); + if ((word32)sz > *nSz) + return RSA_BUFFER_E; + ret = mp_to_unsigned_bin(&key->e, e); + if (ret != MP_OKAY) + return ret; + *eSz = (word32)sz; + + sz = mp_unsigned_bin_size(&key->n); + if ((word32)sz > *nSz) + return RSA_BUFFER_E; + ret = mp_to_unsigned_bin(&key->n, n); + if (ret != MP_OKAY) + return ret; + *nSz = (word32)sz; + + return 0; +} + + #ifdef CYASSL_KEY_GEN static const int USE_BBS = 1; diff --git a/cyassl/ctaocrypt/rsa.h b/cyassl/ctaocrypt/rsa.h index 1f94742a8..3fee36207 100644 --- a/cyassl/ctaocrypt/rsa.h +++ b/cyassl/ctaocrypt/rsa.h @@ -82,6 +82,8 @@ CYASSL_API int RsaPrivateKeyDecode(const byte* input, word32* inOutIdx, RsaKey*, word32); CYASSL_API int RsaPublicKeyDecode(const byte* input, word32* inOutIdx, RsaKey*, word32); +CYASSL_API int RsaFlattenPublicKey(RsaKey*, byte*, word32*, byte*, word32*); + #ifdef CYASSL_KEY_GEN CYASSL_API int MakeRsaKey(RsaKey* key, int size, long e, RNG* rng); CYASSL_API int RsaKeyToDer(RsaKey*, byte* output, word32 inLen);