Skip to content

Commit d109f38

Browse files
committed
Fixes for RSA TSIP RSA Sign/Verify. Tested on RX72N EnvisionKit. Added THREADX threading support.
``` Start wolf tsip crypt Test simple crypt test by using TSIP sha_test() passed sha256_test() passed tsip_aes_cbc_test() passed tsip_aes256_test() passed tsip_rsa_test(2048) passed tsip_rsa_SignVerify_test(2048) passed End wolf tsip crypt Test ```
1 parent 42825e8 commit d109f38

4 files changed

Lines changed: 39 additions & 19 deletions

File tree

IDE/Renesas/e2studio/RX72N/EnvisionKit/wolfssl_demo/wolfssl_tsip_unit_test.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ static void tskAes256_Gcm_Test(void *pvParam)
523523
#endif /* FREERTOS */
524524
#endif
525525

526-
#if defined(WOLFSSL_AES_128)
526+
#if defined(WOLFSSL_AES_128) && defined(HAVE_AESGCM)
527527

528528
static int tsip_aesgcm128_test(int prnt, tsip_aes_key_index_t* aes128_key)
529529
{
@@ -805,6 +805,7 @@ static int tsip_rsa_SignVerify_test(int prnt, int keySize)
805805
const char inStr2[] = TEST_STRING2;
806806
const word32 inLen = (word32)TEST_STRING_SZ;
807807
const word32 outSz = RSA_TEST_BYTES;
808+
word32 signSz = 0;
808809
byte *in = NULL;
809810
byte *in2 = NULL;
810811
byte *out= NULL;
@@ -848,15 +849,16 @@ static int tsip_rsa_SignVerify_test(int prnt, int keySize)
848849
if (ret < 0) {
849850
goto out;
850851
}
852+
signSz = ret;
851853

852854
/* this should fail */
853-
ret = wc_RsaSSL_Verify(in2, inLen, out, keySize/8, key);
855+
ret = wc_RsaSSL_Verify(out, signSz, in2, inLen, key);
854856
if (ret != SIG_VERIFY_E) {
855857
ret = -1;
856858
goto out;
857859
}
858860
/* this should succeed */
859-
ret = wc_RsaSSL_Verify(in, inLen, out, keySize/8, key);
861+
ret = wc_RsaSSL_Verify(out, signSz, in, inLen, key);
860862
if (ret < 0) {
861863
ret = -1;
862864
goto out;
@@ -1223,6 +1225,7 @@ int tsip_crypt_test(void)
12231225

12241226
}
12251227

1228+
#ifdef HAVE_AESGCM
12261229
if (ret == 0) {
12271230

12281231
ret = tsip_aesgcm128_test(1, &g_user_aes128_key_index1);
@@ -1234,8 +1237,10 @@ int tsip_crypt_test(void)
12341237
ret = tsip_aesgcm256_test(1, &g_user_aes256_key_index1);
12351238

12361239
}
1237-
#if defined(WOLFSSL_KEY_GEN) && \
1238-
defined(WOLFSSL_RENESAS_TSIP_CRYPTONLY)
1240+
#endif
1241+
1242+
#if defined(WOLFSSL_KEY_GEN) && \
1243+
defined(WOLFSSL_RENESAS_TSIP_CRYPTONLY)
12391244

12401245
if (ret == 0) {
12411246
Clr_CallbackCtx(&userContext);
@@ -1248,20 +1253,21 @@ int tsip_crypt_test(void)
12481253

12491254
#if RSA_MIN_SIZE <= 1024
12501255
if (ret == 0) {
1251-
userContext.wrappedKeyType = TSIP_KEY_TYPE_RSA1024;
1256+
userContext.wrappedKeyType = TSIP_KEY_TYPE_RSA1024;
12521257
printf(" tsip_rsa_test(1024)");
12531258
ret = tsip_rsa_test(1, 1024);
12541259
RESULT_STR(ret)
12551260
}
12561261
#endif
12571262
if (ret == 0) {
1258-
userContext.wrappedKeyType = TSIP_KEY_TYPE_RSA2048;
1263+
userContext.wrappedKeyType = TSIP_KEY_TYPE_RSA2048;
12591264
printf(" tsip_rsa_test(2048)");
12601265
ret = tsip_rsa_test(1, 2048);
12611266
RESULT_STR(ret)
12621267
}
12631268

12641269

1270+
#if RSA_MIN_SIZE <= 1024
12651271
if (ret == 0) {
12661272
printf(" tsip_rsa_SignVerify_test(1024)");
12671273

@@ -1274,6 +1280,7 @@ int tsip_crypt_test(void)
12741280
}
12751281

12761282
Clr_CallbackCtx(&userContext);
1283+
#endif
12771284

12781285
if (ret == 0) {
12791286
printf(" tsip_rsa_SignVerify_test(2048)");
@@ -1287,12 +1294,11 @@ int tsip_crypt_test(void)
12871294
}
12881295

12891296
Clr_CallbackCtx(&userContext);
1290-
#endif
1297+
#endif /* WOLFSSL_KEY_GEN && WOLFSSL_RENESAS_TSIP_CRYPTONLY */
12911298
}
1292-
else
1299+
else {
12931300
ret = -1;
1294-
1295-
1301+
}
12961302
return ret;
12971303
}
12981304

wolfcrypt/src/port/Renesas/renesas_common.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,16 @@ static int Renesas_cmn_CryptoDevCb(int devIdArg, wc_CryptoInfo* info, void* ctx)
279279
}
280280
#endif
281281
}
282+
if (info->pk.type == WC_PK_TYPE_RSA_GET_SIZE) {
283+
if (cbInfo->wrappedKeyType == TSIP_KEY_TYPE_RSA2048) {
284+
*info->pk.rsa_get_size.keySize = 256;
285+
ret = 0;
286+
}
287+
else if (cbInfo->wrappedKeyType == TSIP_KEY_TYPE_RSA1024) {
288+
*info->pk.rsa_get_size.keySize = 128;
289+
ret = 0;
290+
}
291+
}
282292
#endif /* !NO_RSA */
283293
#if defined(HAVE_ECC)
284294
#if defined(WOLFSSL_RENESAS_TSIP_TLS)

wolfcrypt/src/port/Renesas/renesas_tsip_rsa.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ int wc_tsip_RsaFunction(wc_CryptoInfo* info, TsipUserCtx* tuc)
234234
plain.pdata = (uint8_t*)info->pk.rsa.in;
235235
plain.data_length = info->pk.rsa.inLen;
236236
cipher.pdata = (uint8_t*)info->pk.rsa.out;
237-
cipher.data_length = info->pk.rsa.outLen;
237+
cipher.data_length = *(info->pk.rsa.outLen);
238238

239239
if (keySize == TSIP_KEY_TYPE_RSA1024) {
240240
ret = R_TSIP_RsaesPkcs1024Encrypt(&plain, &cipher,
@@ -250,13 +250,13 @@ int wc_tsip_RsaFunction(wc_CryptoInfo* info, TsipUserCtx* tuc)
250250
return BAD_FUNC_ARG;
251251
}
252252
if (ret == 0) {
253-
info->pk.rsa.outLen = cipher.data_length;
253+
*(info->pk.rsa.outLen) = cipher.data_length;
254254
}
255255
}
256256
else if (type == RSA_PRIVATE_DECRYPT || type == RSA_PRIVATE_ENCRYPT)
257257
{
258258
plain.pdata = (uint8_t*)info->pk.rsa.out;
259-
plain.data_length = info->pk.rsa.outLen;
259+
plain.data_length = *(info->pk.rsa.outLen);
260260
cipher.pdata = (uint8_t*)info->pk.rsa.in;
261261
cipher.data_length = info->pk.rsa.inLen;
262262

@@ -274,7 +274,7 @@ int wc_tsip_RsaFunction(wc_CryptoInfo* info, TsipUserCtx* tuc)
274274
return BAD_FUNC_ARG;
275275
}
276276
if (ret == 0) {
277-
info->pk.rsa.outLen = plain.data_length;
277+
*(info->pk.rsa.outLen) = plain.data_length;
278278
}
279279
}
280280
tsip_hw_unlock();
@@ -314,13 +314,13 @@ int wc_tsip_RsaVerifyPkcs(wc_CryptoInfo* info, TsipUserCtx* tuc)
314314
}
315315

316316
if (tsip_RsakeyImport(tuc) == 0) {
317-
hashData.pdata = (uint8_t*)info->pk.rsa.in;
318-
hashData.data_length = info->pk.rsa.inLen;
317+
hashData.pdata = (uint8_t*)info->pk.rsa.out;
318+
hashData.data_length = *(info->pk.rsa.outLen);
319319
hashData.data_type =
320320
tuc->keyflgs_crypt.bits.message_type;/* message 0, hash 1 */
321321

322-
sigData.pdata = (uint8_t*)info->pk.rsa.out;
323-
sigData.data_length = info->pk.rsa.outLen;
322+
sigData.pdata = (uint8_t*)info->pk.rsa.in;
323+
sigData.data_length = info->pk.rsa.inLen;
324324

325325
if ((ret = tsip_hw_lock()) == 0) {
326326
switch (tuc->wrappedKeyType) {

wolfssl/wolfcrypt/types.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,6 +1497,10 @@ typedef struct w64wrapper {
14971497
#if !defined(__MINGW32__)
14981498
#define WOLFSSL_THREAD_NO_JOIN __cdecl
14991499
#endif
1500+
#elif defined(THREADX)
1501+
typedef unsigned int THREAD_RETURN;
1502+
typedef TX_THREAD THREAD_TYPE;
1503+
#define WOLFSSL_THREAD
15001504
#else
15011505
typedef unsigned int THREAD_RETURN;
15021506
typedef size_t THREAD_TYPE;

0 commit comments

Comments
 (0)