Add RSA to unit test.

This commit is contained in:
jrblixt
2017-06-05 15:04:56 -06:00
parent f8c0a52170
commit 00724c95a9
6 changed files with 1188 additions and 12 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1861,6 +1861,9 @@ int wc_RsaPrivateKeyDecode(const byte* input, word32* inOutIdx, RsaKey* key,
{
int version, length;
if (inOutIdx == NULL) {
return BAD_FUNC_ARG;
}
if (GetSequence(input, inOutIdx, &length, inSz) < 0)
return ASN_PARSE_E;
@@ -6996,8 +6999,12 @@ int wc_RsaKeyToPublicDer(RsaKey* key, byte* output, word32 inLen)
selfSigned = 1 (true) use subject as issuer
subject = blank
*/
void wc_InitCert(Cert* cert)
int wc_InitCert(Cert* cert)
{
if (cert == NULL) {
return BAD_FUNC_ARG;
}
cert->version = 2; /* version 3 is hex 2 */
cert->sigType = CTC_SHAwRSA;
cert->daysValid = 500;
@@ -7061,6 +7068,8 @@ void wc_InitCert(Cert* cert)
#else
cert->heap = NULL;
#endif
return 0;
}

View File

@@ -25,6 +25,7 @@
#endif
#include <wolfssl/wolfcrypt/settings.h>
#include <wolfssl/wolfcrypt/error-crypt.h>
#ifndef NO_RSA
@@ -52,12 +53,19 @@ RSA Key Size Configuration:
#ifdef HAVE_FIPS
int wc_InitRsaKey(RsaKey* key, void* ptr)
{
if (key == NULL) {
return BAD_FUNC_ARG;
}
return InitRsaKey_fips(key, ptr);
}
int wc_InitRsaKey_ex(RsaKey* key, void* ptr, int devId)
{
(void)devId;
if (key == NULL) {
return BAD_FUNC_ARG;
}
return InitRsaKey_fips(key, ptr);
}
@@ -70,6 +78,9 @@ int wc_FreeRsaKey(RsaKey* key)
int wc_RsaPublicEncrypt(const byte* in, word32 inLen, byte* out,
word32 outLen, RsaKey* key, WC_RNG* rng)
{
if (in == NULL || out == NULL || key == NULL || rng == NULL) {
return BAD_FUNC_ARG;
}
return RsaPublicEncrypt_fips(in, inLen, out, outLen, key, rng);
}
@@ -77,6 +88,9 @@ int wc_RsaPublicEncrypt(const byte* in, word32 inLen, byte* out,
int wc_RsaPrivateDecryptInline(byte* in, word32 inLen, byte** out,
RsaKey* key)
{
if (in == NULL || out == NULL || key == NULL) {
return BAD_FUNC_ARG;
}
return RsaPrivateDecryptInline_fips(in, inLen, out, key);
}
@@ -84,6 +98,9 @@ int wc_RsaPrivateDecryptInline(byte* in, word32 inLen, byte** out,
int wc_RsaPrivateDecrypt(const byte* in, word32 inLen, byte* out,
word32 outLen, RsaKey* key)
{
if (in == NULL || out == NULL || key == NULL) {
return BAD_FUNC_ARG;
}
return RsaPrivateDecrypt_fips(in, inLen, out, outLen, key);
}
@@ -91,12 +108,18 @@ int wc_RsaPrivateDecrypt(const byte* in, word32 inLen, byte* out,
int wc_RsaSSL_Sign(const byte* in, word32 inLen, byte* out,
word32 outLen, RsaKey* key, WC_RNG* rng)
{
if (in == NULL || out == NULL || key == NULL || inLen == 0) {
return BAD_FUNC_ARG;
}
return RsaSSL_Sign_fips(in, inLen, out, outLen, key, rng);
}
int wc_RsaSSL_VerifyInline(byte* in, word32 inLen, byte** out, RsaKey* key)
{
if (in == NULL || out == NULL || key == NULL) {
return BAD_FUNC_ARG;
}
return RsaSSL_VerifyInline_fips(in, inLen, out, key);
}
@@ -104,12 +127,18 @@ int wc_RsaSSL_VerifyInline(byte* in, word32 inLen, byte** out, RsaKey* key)
int wc_RsaSSL_Verify(const byte* in, word32 inLen, byte* out,
word32 outLen, RsaKey* key)
{
if (in == NULL || out == NULL || key == NULL || inLen == 0) {
return BAD_FUNC_ARG;
}
return RsaSSL_Verify_fips(in, inLen, out, outLen, key);
}
int wc_RsaEncryptSize(RsaKey* key)
{
if (key == NULL) {
return BAD_FUNC_ARG;
}
return RsaEncryptSize_fips(key);
}
@@ -117,12 +146,22 @@ int wc_RsaEncryptSize(RsaKey* key)
int wc_RsaFlattenPublicKey(RsaKey* key, byte* a, word32* aSz, byte* b,
word32* bSz)
{
/* not specified as fips so not needing _fips */
return RsaFlattenPublicKey(key, a, aSz, b, bSz);
}
#ifdef WOLFSSL_KEY_GEN
int wc_MakeRsaKey(RsaKey* key, int size, long e, WC_RNG* rng)
{
if (key == NULL || rng == NULL) {
return BAD_FUNC_ARG;
}
if (size < RSA_MIN_SIZE || size > RSA_MAX_SIZE) {
return BAD_FUNC_ARG;
}
if (e < 3 || (e & 1) == 0) {
return BAD_FUNC_ARG;
}
return MakeRsaKey(key, size, e, rng);
}
#endif
@@ -136,7 +175,6 @@ int wc_RsaFlattenPublicKey(RsaKey* key, byte* a, word32* aSz, byte* b,
#else /* else build without fips */
#include <wolfssl/wolfcrypt/random.h>
#include <wolfssl/wolfcrypt/error-crypt.h>
#include <wolfssl/wolfcrypt/logging.h>
#ifdef NO_INLINE
#include <wolfssl/wolfcrypt/misc.h>
@@ -1568,7 +1606,13 @@ int wc_RsaSSL_VerifyInline(byte* in, word32 inLen, byte** out, RsaKey* key)
int wc_RsaSSL_Verify(const byte* in, word32 inLen, byte* out, word32 outLen,
RsaKey* key)
{
WC_RNG* rng = NULL;
WC_RNG* rng;
if (key == NULL) {
return BAD_FUNC_ARG;
}
rng = NULL;
#ifdef WC_RSA_BLINDING
rng = key->rng;
#endif
@@ -1637,6 +1681,9 @@ int wc_RsaPSS_Sign(const byte* in, word32 inLen, byte* out, word32 outLen,
int wc_RsaEncryptSize(RsaKey* key)
{
if (key == NULL) {
return BAD_FUNC_ARG;
}
return mp_unsigned_bin_size(&key->n);
}

View File

@@ -7198,7 +7198,9 @@ int rsa_test(void)
ERROR_OUT(-5571, exit_rsa);
}
wc_InitCert(&myCert);
if (wc_InitCert(&myCert)) {
ERROR_OUT(-5582, exit_rsa);
}
strncpy(myCert.subject.country, "US", CTC_NAME_SIZE);
strncpy(myCert.subject.state, "OR", CTC_NAME_SIZE);
@@ -7344,7 +7346,9 @@ int rsa_test(void)
ERROR_OUT(-5604, exit_rsa);
}
wc_InitCert(&myCert);
if (wc_InitCert(&myCert)) {
ERROR_OUT(-5617, exit_rsa);
}
#ifdef NO_SHA
myCert.sigType = CTC_SHA256wRSA;
@@ -7518,7 +7522,9 @@ int rsa_test(void)
ERROR_OUT(-5624, exit_rsa);
}
wc_InitCert(&myCert);
if (wc_InitCert(&myCert)) {
ERROR_OUT(-5640, exit_rsa);
}
myCert.sigType = CTC_SHA256wECDSA;
strncpy(myCert.subject.country, "US", CTC_NAME_SIZE);
@@ -7738,7 +7744,9 @@ int rsa_test(void)
ERROR_OUT(-5658, exit_rsa);
}
wc_InitCert(&myCert);
if (wc_InitCert(&myCert)) {
ERROR_OUT(-5573, exit_rsa);
}
strncpy(myCert.subject.country, "US", CTC_NAME_SIZE);
strncpy(myCert.subject.state, "OR", CTC_NAME_SIZE);
@@ -7885,7 +7893,9 @@ int rsa_test(void)
ERROR_OUT(-5681, exit_rsa);
}
wc_InitCert(&req);
if (wc_InitCert(&req)) {
ERROR_OUT(-5691, exit_rsa);
}
req.version = 0;
req.isCA = 1;

View File

@@ -928,6 +928,10 @@ int wc_RsaPrivateKeyDecode(const byte* input, word32* inOutIdx, RsaKey* key,
int ctxSz, pSz, qSz;
IppStatus ret;
if (input == NULL || inOutIdx == NULL || key == NULL) {
return USER_CRYPTO_ERROR;
}
USER_DEBUG(("Entering wc_RsaPrivateKeyDecode\n"));
/* read in key information */
@@ -1066,6 +1070,10 @@ int wc_RsaPublicKeyDecode(const byte* input, word32* inOutIdx, RsaKey* key,
byte b;
#endif
if (input == NULL || inOutIdx == NULL || key == NULL) {
return USER_CRYPTO_ERROR;
}
USER_DEBUG(("Entering wc_RsaPublicKeyDecode\n"));
if (GetSequence(input, inOutIdx, &length, inSz) < 0)
@@ -1246,7 +1254,7 @@ int wc_RsaPublicKeyDecodeRaw(const byte* n, word32 nSz, const byte* e,
key->eSz = eSz;
key->type = RSA_PUBLIC;
return USER_CRYPTO_ERROR;
return 0;
}
@@ -1636,13 +1644,14 @@ int wc_RsaSSL_Sign(const byte* in, word32 inLen, byte* out, word32 outLen,
USER_DEBUG(("Entering wc_RsaSSL_Sign\n"));
sz = key->sz;
if (in == NULL || out == NULL || key == NULL || rng == NULL) {
USER_DEBUG(("Bad argument to wc_RsaSSL_Sign\n"));
return USER_CRYPTO_ERROR;
}
sz = key->sz;
/* sanity check on key being used */
if (key->pipp == NULL || key->qipp == NULL || key->uipp == NULL ||
key->dPipp == NULL || key->dQipp == NULL) {

View File

@@ -180,7 +180,7 @@ typedef struct Cert {
isCA = 0 (false)
keyType = RSA_KEY (default)
*/
WOLFSSL_API void wc_InitCert(Cert*);
WOLFSSL_API int wc_InitCert(Cert*);
WOLFSSL_API int wc_MakeCert_ex(Cert* cert, byte* derBuffer, word32 derSz,
int keyType, void* key, WC_RNG* rng);
WOLFSSL_API int wc_MakeCert(Cert*, byte* derBuffer, word32 derSz, RsaKey*,