have explicit Rsa Padding error

This commit is contained in:
toddouska
2014-07-16 13:52:31 -07:00
parent e76c5cc59e
commit 99f6fd8450
3 changed files with 20 additions and 21 deletions

View File

@ -280,6 +280,9 @@ const char* CTaoCryptGetErrorString(int error)
case HMAC_MIN_KEYLEN_E: case HMAC_MIN_KEYLEN_E:
return "FIPS Mode HMAC Minimum Key Length error"; return "FIPS Mode HMAC Minimum Key Length error";
case RSA_PAD_E:
return "Rsa Padding error";
default: default:
return "unknown error number"; return "unknown error number";

View File

@ -157,7 +157,9 @@ static int RsaPad(const byte* input, word32 inputLen, byte* pkcsBlock,
} }
static word32 RsaUnPad(const byte *pkcsBlock, unsigned int pkcsBlockLen, /* UnPad plaintext, set start to *output, return length of plaintext,
* < 0 on error */
static int RsaUnPad(const byte *pkcsBlock, unsigned int pkcsBlockLen,
byte **output, byte padValue) byte **output, byte padValue)
{ {
word32 maxOutputLen = (pkcsBlockLen > 10) ? (pkcsBlockLen - 10) : 0, word32 maxOutputLen = (pkcsBlockLen > 10) ? (pkcsBlockLen - 10) : 0,
@ -177,7 +179,7 @@ static word32 RsaUnPad(const byte *pkcsBlock, unsigned int pkcsBlockLen,
} }
if(!(i==pkcsBlockLen || pkcsBlock[i-1]==0)) { if(!(i==pkcsBlockLen || pkcsBlock[i-1]==0)) {
CYASSL_MSG("RsaUnPad error, bad formatting"); CYASSL_MSG("RsaUnPad error, bad formatting");
return 0; return RSA_PAD_E;
} }
outputLen = pkcsBlockLen - i; outputLen = pkcsBlockLen - i;
@ -185,7 +187,7 @@ static word32 RsaUnPad(const byte *pkcsBlock, unsigned int pkcsBlockLen,
if (invalid) { if (invalid) {
CYASSL_MSG("RsaUnPad error, bad formatting"); CYASSL_MSG("RsaUnPad error, bad formatting");
return 0; return RSA_PAD_E;
} }
*output = (byte *)(pkcsBlock + i); *output = (byte *)(pkcsBlock + i);
@ -316,7 +318,7 @@ int RsaPublicEncrypt(const byte* in, word32 inLen, byte* out, word32 outLen,
int RsaPrivateDecryptInline(byte* in, word32 inLen, byte** out, RsaKey* key) int RsaPrivateDecryptInline(byte* in, word32 inLen, byte** out, RsaKey* key)
{ {
int plainLen, ret; int ret;
#ifdef HAVE_CAVIUM #ifdef HAVE_CAVIUM
if (key->magic == CYASSL_RSA_CAVIUM_MAGIC) { if (key->magic == CYASSL_RSA_CAVIUM_MAGIC) {
@ -332,16 +334,14 @@ int RsaPrivateDecryptInline(byte* in, word32 inLen, byte** out, RsaKey* key)
return ret; return ret;
} }
plainLen = RsaUnPad(in, inLen, out, RSA_BLOCK_TYPE_2); return RsaUnPad(in, inLen, out, RSA_BLOCK_TYPE_2);
return plainLen;
} }
int RsaPrivateDecrypt(const byte* in, word32 inLen, byte* out, word32 outLen, int RsaPrivateDecrypt(const byte* in, word32 inLen, byte* out, word32 outLen,
RsaKey* key) RsaKey* key)
{ {
int plainLen, ret; int plainLen;
byte* tmp; byte* tmp;
byte* pad = 0; byte* pad = 0;
@ -357,10 +357,9 @@ int RsaPrivateDecrypt(const byte* in, word32 inLen, byte* out, word32 outLen,
XMEMCPY(tmp, in, inLen); XMEMCPY(tmp, in, inLen);
if ((ret = plainLen = RsaPrivateDecryptInline(tmp, inLen, &pad, key)) if ( (plainLen = RsaPrivateDecryptInline(tmp, inLen, &pad, key) ) < 0) {
< 0) {
XFREE(tmp, key->heap, DYNAMIC_TYPE_RSA); XFREE(tmp, key->heap, DYNAMIC_TYPE_RSA);
return ret; return plainLen;
} }
if (plainLen > (int)outLen) if (plainLen > (int)outLen)
plainLen = BAD_FUNC_ARG; plainLen = BAD_FUNC_ARG;
@ -376,7 +375,7 @@ int RsaPrivateDecrypt(const byte* in, word32 inLen, byte* out, word32 outLen,
/* for Rsa Verify */ /* for Rsa Verify */
int RsaSSL_VerifyInline(byte* in, word32 inLen, byte** out, RsaKey* key) int RsaSSL_VerifyInline(byte* in, word32 inLen, byte** out, RsaKey* key)
{ {
int plainLen, ret; int ret;
#ifdef HAVE_CAVIUM #ifdef HAVE_CAVIUM
if (key->magic == CYASSL_RSA_CAVIUM_MAGIC) { if (key->magic == CYASSL_RSA_CAVIUM_MAGIC) {
@ -392,16 +391,14 @@ int RsaSSL_VerifyInline(byte* in, word32 inLen, byte** out, RsaKey* key)
return ret; return ret;
} }
plainLen = RsaUnPad(in, inLen, out, RSA_BLOCK_TYPE_1); return RsaUnPad(in, inLen, out, RSA_BLOCK_TYPE_1);
return plainLen;
} }
int RsaSSL_Verify(const byte* in, word32 inLen, byte* out, word32 outLen, int RsaSSL_Verify(const byte* in, word32 inLen, byte* out, word32 outLen,
RsaKey* key) RsaKey* key)
{ {
int plainLen, ret; int plainLen;
byte* tmp; byte* tmp;
byte* pad = 0; byte* pad = 0;
@ -417,10 +414,9 @@ int RsaSSL_Verify(const byte* in, word32 inLen, byte* out, word32 outLen,
XMEMCPY(tmp, in, inLen); XMEMCPY(tmp, in, inLen);
if ((ret = plainLen = RsaSSL_VerifyInline(tmp, inLen, &pad, key)) if ( (plainLen = RsaSSL_VerifyInline(tmp, inLen, &pad, key) ) < 0) {
< 0) {
XFREE(tmp, key->heap, DYNAMIC_TYPE_RSA); XFREE(tmp, key->heap, DYNAMIC_TYPE_RSA);
return ret; return plainLen;
} }
if (plainLen > (int)outLen) if (plainLen > (int)outLen)

View File

@ -126,10 +126,10 @@ enum {
ASN_NAME_INVALID_E = -198, /* ASN name constraint error */ ASN_NAME_INVALID_E = -198, /* ASN name constraint error */
RNG_FAILURE_E = -199, /* RNG Failed, Reinitialize */ RNG_FAILURE_E = -199, /* RNG Failed, Reinitialize */
HMAC_MIN_KEYLEN_E = -200, /* FIPS Mode HMAC Minimum Key Length error */ HMAC_MIN_KEYLEN_E = -200, /* FIPS Mode HMAC Minimum Key Length error */
RSA_PAD_E = -201, /* RSA Padding Error */
MIN_CODE_E = -300 /* errors -101 - -299 */ MIN_CODE_E = -300 /* errors -101 - -299 */
}; };