diff --git a/ctaocrypt/src/asn.c b/ctaocrypt/src/asn.c index 20d816264..96a06b937 100644 --- a/ctaocrypt/src/asn.c +++ b/ctaocrypt/src/asn.c @@ -1237,6 +1237,36 @@ int RsaPublicKeyDecode(const byte* input, word32* inOutIdx, RsaKey* key, return 0; } +int RsaPublicKeyDecodeRaw(const byte* n, word32 nSz, const byte* e, word32 eSz, + RsaKey* key) +{ + if (n == NULL || e == NULL || key == NULL) + return BAD_FUNC_ARG; + + key->type = RSA_PUBLIC; + + if (mp_init(&key->n) != MP_OKAY) + return MP_INIT_E; + + if (mp_read_unsigned_bin(&key->n, n, nSz) != 0) { + mp_clear(&key->n); + return ASN_GETINT_E; + } + + if (mp_init(&key->e) != MP_OKAY) { + mp_clear(&key->n); + return MP_INIT_E; + } + + if (mp_read_unsigned_bin(&key->e, e, eSz) != 0) { + mp_clear(&key->n); + mp_clear(&key->e); + return ASN_GETINT_E; + } + + return 0; +} + #endif #ifndef NO_DH diff --git a/cyassl/ctaocrypt/rsa.h b/cyassl/ctaocrypt/rsa.h index 3fee36207..d9bb2a12a 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 RsaPublicKeyDecodeRaw(const byte* n, word32 nSz, const byte* e, + word32 eSz, RsaKey* key); CYASSL_API int RsaFlattenPublicKey(RsaKey*, byte*, word32*, byte*, word32*); #ifdef CYASSL_KEY_GEN