mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-07-30 18:57:27 +02:00
Add public decrypt and private encrypt. Cleanups.
This commit is contained in:
@ -715,7 +715,7 @@ static int tsip_rsa_test(int prnt, int keySize)
|
|||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
RsaKey *key = (RsaKey *)XMALLOC(sizeof *key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
RsaKey *key = NULL;
|
||||||
WC_RNG rng;
|
WC_RNG rng;
|
||||||
const char inStr [] = TEST_STRING;
|
const char inStr [] = TEST_STRING;
|
||||||
const char inStr2[] = TEST_STRING2;
|
const char inStr2[] = TEST_STRING2;
|
||||||
@ -726,10 +726,15 @@ static int tsip_rsa_test(int prnt, int keySize)
|
|||||||
byte *in2 = NULL;
|
byte *in2 = NULL;
|
||||||
byte *out= NULL;
|
byte *out= NULL;
|
||||||
byte *out2 = NULL;
|
byte *out2 = NULL;
|
||||||
|
int initRsa = 0;
|
||||||
|
int devId = 7890; /* fixed devid for TSIP/SCE */
|
||||||
|
|
||||||
|
XMEMSET(&rng, 0, sizeof(rng));
|
||||||
|
|
||||||
|
key = (RsaKey *)XMALLOC(sizeof *key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
in = (byte*)XMALLOC(inLen, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
in = (byte*)XMALLOC(inLen, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
in2 = (byte*)XMALLOC(inLen, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
in2 = (byte*)XMALLOC(inLen, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
out= (byte*)XMALLOC(outSz, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
out = (byte*)XMALLOC(outSz, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
out2 = (byte*)XMALLOC(outSz, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
out2 = (byte*)XMALLOC(outSz, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
|
|
||||||
if (key == NULL || in == NULL || out == NULL ||
|
if (key == NULL || in == NULL || out == NULL ||
|
||||||
@ -738,17 +743,17 @@ static int tsip_rsa_test(int prnt, int keySize)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
XMEMSET(&rng, 0, sizeof(rng));
|
|
||||||
XMEMSET(key, 0, sizeof *key);
|
XMEMSET(key, 0, sizeof *key);
|
||||||
XMEMCPY(in, inStr, inLen);
|
XMEMCPY(in, inStr, inLen);
|
||||||
XMEMCPY(in2, inStr2, inLen);
|
XMEMCPY(in2, inStr2, inLen);
|
||||||
XMEMSET(out, 0, outSz);
|
XMEMSET(out, 0, outSz);
|
||||||
XMEMSET(out2, 0, outSz);
|
XMEMSET(out2, 0, outSz);
|
||||||
|
|
||||||
ret = wc_InitRsaKey_ex(key, NULL, 7890/* fixed devid for TSIP/SCE*/);
|
ret = wc_InitRsaKey_ex(key, NULL, devId);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
initRsa = 1;
|
||||||
|
|
||||||
if ((ret = wc_InitRng(&rng)) != 0)
|
if ((ret = wc_InitRng(&rng)) != 0)
|
||||||
goto out;
|
goto out;
|
||||||
@ -779,8 +784,11 @@ static int tsip_rsa_test(int prnt, int keySize)
|
|||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
out:
|
out:
|
||||||
|
|
||||||
|
wc_FreeRng(&rng);
|
||||||
if (key != NULL) {
|
if (key != NULL) {
|
||||||
wc_FreeRsaKey(key);
|
if (initRsa)
|
||||||
|
wc_FreeRsaKey(key);
|
||||||
XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
}
|
}
|
||||||
XFREE(in, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
XFREE(in, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
@ -797,37 +805,41 @@ static int tsip_rsa_SignVerify_test(int prnt, int keySize)
|
|||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
RsaKey *key = (RsaKey *)XMALLOC(sizeof *key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
RsaKey *key = NULL;
|
||||||
WC_RNG rng;
|
WC_RNG rng;
|
||||||
const char inStr [] = TEST_STRING;
|
const char inStr [] = TEST_STRING;
|
||||||
const char inStr2[] = TEST_STRING2;
|
const char inStr2[] = TEST_STRING2;
|
||||||
const word32 inLen = (word32)TEST_STRING_SZ;
|
const word32 inLen = (word32)TEST_STRING_SZ;
|
||||||
const word32 outSz = RSA_TEST_BYTES;
|
const word32 outSz = RSA_TEST_BYTES;
|
||||||
|
|
||||||
byte *in = NULL;
|
byte *in = NULL;
|
||||||
byte *in2 = NULL;
|
byte *in2 = NULL;
|
||||||
byte *out= NULL;
|
byte *out= NULL;
|
||||||
|
int initRsa = 0;
|
||||||
|
int devId = 7890; /* fixed devid for TSIP/SCE */
|
||||||
|
|
||||||
|
XMEMSET(&rng, 0, sizeof(rng));
|
||||||
|
|
||||||
|
key = (RsaKey *)XMALLOC(sizeof *key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
in = (byte*)XMALLOC(inLen, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
in = (byte*)XMALLOC(inLen, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
in2 = (byte*)XMALLOC(inLen, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
in2 = (byte*)XMALLOC(inLen, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
out= (byte*)XMALLOC(outSz, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
out = (byte*)XMALLOC(outSz, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
|
|
||||||
(void) prnt;
|
(void)prnt;
|
||||||
|
|
||||||
if (key == NULL || in == NULL || out == NULL) {
|
if (key == NULL || in == NULL || out == NULL) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
XMEMSET(&rng, 0, sizeof(rng));
|
|
||||||
XMEMSET(key, 0, sizeof *key);
|
XMEMSET(key, 0, sizeof *key);
|
||||||
XMEMCPY(in, inStr, inLen);
|
XMEMCPY(in, inStr, inLen);
|
||||||
XMEMCPY(in2, inStr2, inLen);
|
XMEMCPY(in2, inStr2, inLen);
|
||||||
|
|
||||||
ret = wc_InitRsaKey_ex(key, NULL, 7890/* fixed devid for TSIP/SCE*/);
|
ret = wc_InitRsaKey_ex(key, NULL, devId);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
initRsa = 1;
|
||||||
|
|
||||||
if ((ret = wc_InitRng(&rng)) != 0)
|
if ((ret = wc_InitRng(&rng)) != 0)
|
||||||
goto out;
|
goto out;
|
||||||
@ -858,9 +870,13 @@ static int tsip_rsa_SignVerify_test(int prnt, int keySize)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
|
||||||
|
wc_FreeRng(&rng);
|
||||||
if (key != NULL) {
|
if (key != NULL) {
|
||||||
wc_FreeRsaKey(key);
|
if (initRsa)
|
||||||
|
wc_FreeRsaKey(key);
|
||||||
XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
}
|
}
|
||||||
XFREE(in, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
XFREE(in, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
|
@ -213,7 +213,7 @@ static int tsip_RsakeyImport(TsipUserCtx* tuc)
|
|||||||
* tuc struct pointer of TsipUserCtx including TSIP key info
|
* tuc struct pointer of TsipUserCtx including TSIP key info
|
||||||
* return FSP_SUCCESS(0) on Success, otherwise negative value
|
* return FSP_SUCCESS(0) on Success, otherwise negative value
|
||||||
*/
|
*/
|
||||||
WOLFSSL_LOCAL int wc_tsip_RsaFunction(wc_CryptoInfo* info, TsipUserCtx* tuc)
|
int wc_tsip_RsaFunction(wc_CryptoInfo* info, TsipUserCtx* tuc)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
int keySize;
|
int keySize;
|
||||||
@ -225,12 +225,12 @@ WOLFSSL_LOCAL int wc_tsip_RsaFunction(wc_CryptoInfo* info, TsipUserCtx* tuc)
|
|||||||
return BAD_FUNC_ARG;
|
return BAD_FUNC_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(tsip_RsakeyImport(tuc) == 0) {
|
if (tsip_RsakeyImport(tuc) == 0) {
|
||||||
type = info->pk.rsa.type;
|
type = info->pk.rsa.type;
|
||||||
keySize = (int)tuc->wrappedKeyType;
|
keySize = (int)tuc->wrappedKeyType;
|
||||||
|
|
||||||
if ((ret = tsip_hw_lock()) == 0) {
|
if ((ret = tsip_hw_lock()) == 0) {
|
||||||
if (type == RSA_PUBLIC_ENCRYPT) {
|
if (type == RSA_PUBLIC_ENCRYPT || type == RSA_PUBLIC_DECRYPT) {
|
||||||
plain.pdata = (uint8_t*)info->pk.rsa.in;
|
plain.pdata = (uint8_t*)info->pk.rsa.in;
|
||||||
plain.data_length = info->pk.rsa.inLen;
|
plain.data_length = info->pk.rsa.inLen;
|
||||||
cipher.pdata = (uint8_t*)info->pk.rsa.out;
|
cipher.pdata = (uint8_t*)info->pk.rsa.out;
|
||||||
@ -250,7 +250,8 @@ WOLFSSL_LOCAL int wc_tsip_RsaFunction(wc_CryptoInfo* info, TsipUserCtx* tuc)
|
|||||||
return BAD_FUNC_ARG;
|
return BAD_FUNC_ARG;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (type == RSA_PRIVATE_DECRYPT) {
|
else if (type == RSA_PRIVATE_DECRYPT || type == RSA_PRIVATE_ENCRYPT)
|
||||||
|
{
|
||||||
plain.pdata = (uint8_t*)info->pk.rsa.out;
|
plain.pdata = (uint8_t*)info->pk.rsa.out;
|
||||||
plain.data_length = info->pk.rsa.outLen;
|
plain.data_length = info->pk.rsa.outLen;
|
||||||
cipher.pdata = (uint8_t*)info->pk.rsa.in;
|
cipher.pdata = (uint8_t*)info->pk.rsa.in;
|
||||||
@ -283,7 +284,7 @@ WOLFSSL_LOCAL int wc_tsip_RsaFunction(wc_CryptoInfo* info, TsipUserCtx* tuc)
|
|||||||
* return FSP_SUCCESS(0) on Success, otherwise negative value
|
* return FSP_SUCCESS(0) on Success, otherwise negative value
|
||||||
*/
|
*/
|
||||||
|
|
||||||
WOLFSSL_LOCAL int wc_tsip_RsaVerifyPkcs(wc_CryptoInfo* info, TsipUserCtx* tuc)
|
int wc_tsip_RsaVerifyPkcs(wc_CryptoInfo* info, TsipUserCtx* tuc)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
e_tsip_err_t err = TSIP_SUCCESS;
|
e_tsip_err_t err = TSIP_SUCCESS;
|
||||||
|
@ -437,9 +437,12 @@ WOLFSSL_LOCAL int tsip_SignRsaPkcs(struct wc_CryptoInfo* info,
|
|||||||
WOLFSSL_LOCAL int wc_tsip_RsaVerifyPkcs(struct wc_CryptoInfo* info,
|
WOLFSSL_LOCAL int wc_tsip_RsaVerifyPkcs(struct wc_CryptoInfo* info,
|
||||||
TsipUserCtx* tuc);
|
TsipUserCtx* tuc);
|
||||||
|
|
||||||
|
WOLFSSL_LOCAL int wc_tsip_RsaFunction(wc_CryptoInfo* info, TsipUserCtx* tuc);
|
||||||
|
|
||||||
WOLFSSL_LOCAL int tsip_SignEcdsa(struct wc_CryptoInfo* info, TsipUserCtx* tuc);
|
WOLFSSL_LOCAL int tsip_SignEcdsa(struct wc_CryptoInfo* info, TsipUserCtx* tuc);
|
||||||
|
|
||||||
WOLFSSL_LOCAL int tsip_VerifyEcdsa(struct wc_CryptoInfo* info, TsipUserCtx* tuc);
|
WOLFSSL_LOCAL int tsip_VerifyEcdsa(struct wc_CryptoInfo* info,
|
||||||
|
TsipUserCtx* tuc);
|
||||||
|
|
||||||
WOLFSSL_LOCAL int tsip_TlsCleanup(struct WOLFSSL* ssl);
|
WOLFSSL_LOCAL int tsip_TlsCleanup(struct WOLFSSL* ssl);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user