add RsaPublicKeyDecodeRaw() to load key from existing n, e

This commit is contained in:
Chris Conlon
2014-11-07 15:24:02 -07:00
parent b36f823da5
commit 233bca3346
2 changed files with 32 additions and 0 deletions

View File

@ -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

View File

@ -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