Skip to content

Commit a06268f

Browse files
authored
Merge pull request #9010 from miyazakh/sce_tlsproperties_uc
Make properties related to Renesas FSP Security Module TLS hidden for FSP SM context
2 parents 2db1669 + 5e77253 commit a06268f

File tree

16 files changed

+545
-436
lines changed

16 files changed

+545
-436
lines changed

IDE/Renesas/e2studio/RA6M4/common/user_settings.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@
108108
#define WC_USE_DEVID 7890
109109
#define NO_AES_192
110110
#define NO_SW_BENCH
111-
#endif
112-
113-
#if defined(WOLFSSL_RENESAS_SCEPROTECT_CRYPTONLY)
111+
/* Use SCE RSAES-PKCS1-V1_5 RSA Function */
112+
#define WOLF_CRYPTO_CB_RSA_PAD
114113
#define WOLFSSL_KEY_GEN
114+
#define RSA_MIN_SIZE 512
115115
#endif
116116

117117
#define CUSTOM_RAND_GENERATE_BLOCK wc_fspsm_GenerateRandBlock

IDE/Renesas/e2studio/RA6M4/test/src/wolf_client.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "wolfssl/wolfcrypt/settings.h"
2929
#include "wolfssl/ssl.h"
3030
#include "wolfssl/certs_test.h"
31+
#include "wolfssl/wolfcrypt/port/Renesas/renesas-fspsm-crypt.h"
3132

3233
uint32_t g_encrypted_root_public_key[140];
3334
WOLFSSL_CTX *client_ctx = NULL;
@@ -198,7 +199,6 @@ int wolfSSL_TLS_client_do(void *pvParam)
198199
#if !defined(TLS_MULTITHREAD_TEST)
199200

200201
XMEMSET(&guser_PKCbInfo, 0, sizeof(FSPSM_ST));
201-
guser_PKCbInfo.devId = 0;
202202
wc_sce_set_callback_ctx(ssl, (void*)&guser_PKCbInfo);
203203

204204
#else

IDE/Renesas/e2studio/RA6M4/test/src/wolfssl_sce_unit_test.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -798,22 +798,17 @@ int sce_crypt_test()
798798
/* sets wrapped rsa 1024 bits key */
799799
gCbInfo.wrapped_key_rsapri1024 =
800800
&g_wrapped_pair_1024key.priv_key;
801-
gCbInfo.keyflgs_crypt.bits.rsapri1024_installedkey_set = 1;
802801
gCbInfo.wrapped_key_rsapub1024 =
803802
&g_wrapped_pair_1024key.pub_key;
804-
gCbInfo.keyflgs_crypt.bits.rsapub1024_installedkey_set = 1;
805803
}
806804

807805
err = R_SCE_RSA2048_WrappedKeyPairGenerate(&g_wrapped_pair_2048key);
808806
if (err == FSP_SUCCESS) {
809807
/* sets wrapped rsa 1024 bits key */
810808
gCbInfo.wrapped_key_rsapri2048 =
811809
&g_wrapped_pair_2048key.priv_key;
812-
gCbInfo.keyflgs_crypt.bits.rsapri2048_installedkey_set = 1;
813-
814810
gCbInfo.wrapped_key_rsapub2048 =
815811
&g_wrapped_pair_2048key.pub_key;
816-
gCbInfo.keyflgs_crypt.bits.rsapub2048_installedkey_set = 1;
817812
}
818813

819814
/* Key generation for multi testing */
@@ -834,6 +829,10 @@ int sce_crypt_test()
834829

835830
if (ret == 0) {
836831
printf(" sce_rsa_test(1024)");
832+
gCbInfo.keyflgs_crypt.bits.rsapri1024_installedkey_set = 1;
833+
gCbInfo.keyflgs_crypt.bits.rsapub1024_installedkey_set = 1;
834+
gCbInfo.keyflgs_crypt.bits.rsapri2048_installedkey_set = 0;
835+
gCbInfo.keyflgs_crypt.bits.rsapub2048_installedkey_set = 0;
837836
ret = sce_rsa_test(1, 1024);
838837
RESULT_STR(ret)
839838
}
@@ -846,6 +845,10 @@ int sce_crypt_test()
846845

847846
if (ret == 0) {
848847
printf(" sce_rsa_test(2048)");
848+
gCbInfo.keyflgs_crypt.bits.rsapri1024_installedkey_set = 0;
849+
gCbInfo.keyflgs_crypt.bits.rsapub1024_installedkey_set = 0;
850+
gCbInfo.keyflgs_crypt.bits.rsapri2048_installedkey_set = 1;
851+
gCbInfo.keyflgs_crypt.bits.rsapub2048_installedkey_set = 1;
849852
ret = sce_rsa_test(1, 2048);
850853
RESULT_STR(ret)
851854
}

src/keys.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3556,7 +3556,7 @@ int SetKeysSide(WOLFSSL* ssl, enum encrypt_side side)
35563556
void* ctx = wolfSSL_GetEncryptKeysCtx(ssl);
35573557
#if defined(WOLFSSL_RENESAS_FSPSM_TLS)
35583558
FSPSM_ST* cbInfo = (FSPSM_ST*)ctx;
3559-
cbInfo->side = side;
3559+
cbInfo->internal->side = side;
35603560
#elif defined(WOLFSSL_RENESAS_TSIP_TLS)
35613561
TsipUserCtx* cbInfo = (TsipUserCtx*)ctx;
35623562
cbInfo->internal->key_side = side;

wolfcrypt/src/port/Renesas/renesas_common.c

Lines changed: 10 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#if defined(WOLFSSL_RENESAS_FSPSM_TLS) || \
3434
defined(WOLFSSL_RENESAS_FSPSM_CRYPTONLY)
3535

36-
#include <wolfssl/wolfcrypt/port/Renesas/renesas-fspsm-crypt.h>
36+
#include <wolfssl/wolfcrypt/port/Renesas/renesas_fspsm_internal.h>
3737
#define cmn_hw_lock wc_fspsm_hw_lock
3838
#define cmn_hw_unlock wc_fspsm_hw_unlock
3939

@@ -87,6 +87,8 @@ WOLFSSL_LOCAL int Renesas_cmn_Cleanup(struct WOLFSSL* ssl)
8787

8888
#if defined(WOLFSSL_RENESAS_TSIP_TLS)
8989
ret = tsip_TlsCleanup(ssl);
90+
#elif defined(WOLFSSL_RENESAS_FSPSM_TLS)
91+
ret = wc_fspsm_TlsCleanup(ssl);
9092
#endif
9193

9294
WOLFSSL_LEAVE("Renesas_cmn_Cleanup", ret);
@@ -166,6 +168,7 @@ static int Renesas_cmn_CryptoDevCb(int devIdArg, wc_CryptoInfo* info, void* ctx)
166168
#elif defined(WOLFSSL_RENESAS_FSPSM_TLS) || \
167169
defined(WOLFSSL_RENESAS_FSPSM_CRYPTONLY)
168170
FSPSM_ST* cbInfo = (FSPSM_ST*)ctx;
171+
(void)cbInfo;
169172
#endif
170173

171174
if (info == NULL || ctx == NULL)
@@ -276,88 +279,19 @@ static int Renesas_cmn_CryptoDevCb(int devIdArg, wc_CryptoInfo* info, void* ctx)
276279

277280
if (info->algo_type == WC_ALGO_TYPE_CIPHER) {
278281
#if !defined(NO_AES)
279-
#ifdef HAVE_AESGCM
280-
if (info->cipher.type == WC_CIPHER_AES_GCM) {
281-
282-
if (info->cipher.enc &&
283-
(cbInfo->keyflgs_tls.bits.session_key_set == 1 ||
284-
(cbInfo->keyflgs_crypt.bits.aes256_installedkey_set == 1 &&
285-
info->cipher.aesgcm_enc.aes->keylen == 32) ||
286-
(cbInfo->keyflgs_crypt.bits.aes128_installedkey_set == 1 &&
287-
info->cipher.aesgcm_enc.aes->keylen == 16))) {
288-
289-
ret = wc_fspsm_AesGcmEncrypt(
290-
info->cipher.aesgcm_enc.aes,
291-
(byte*)info->cipher.aesgcm_enc.out,
292-
(byte*)info->cipher.aesgcm_enc.in,
293-
info->cipher.aesgcm_enc.sz,
294-
(byte*)info->cipher.aesgcm_enc.iv,
295-
info->cipher.aesgcm_enc.ivSz,
296-
(byte*)info->cipher.aesgcm_enc.authTag,
297-
info->cipher.aesgcm_enc.authTagSz,
298-
(byte*)info->cipher.aesgcm_enc.authIn,
299-
info->cipher.aesgcm_enc.authInSz,
300-
(void*)ctx);
301-
302-
}
303-
else if (cbInfo->keyflgs_tls.bits.session_key_set == 1 ||
304-
(cbInfo->keyflgs_crypt.bits.aes256_installedkey_set == 1 &&
305-
info->cipher.aesgcm_dec.aes->keylen == 32) ||
306-
(cbInfo->keyflgs_crypt.bits.aes128_installedkey_set == 1 &&
307-
info->cipher.aesgcm_dec.aes->keylen == 16)) {
308-
309-
ret = wc_fspsm_AesGcmDecrypt(
310-
info->cipher.aesgcm_dec.aes,
311-
(byte*)info->cipher.aesgcm_dec.out,
312-
(byte*)info->cipher.aesgcm_dec.in,
313-
info->cipher.aesgcm_dec.sz,
314-
(byte*)info->cipher.aesgcm_dec.iv,
315-
info->cipher.aesgcm_dec.ivSz,
316-
(byte*)info->cipher.aesgcm_dec.authTag,
317-
info->cipher.aesgcm_dec.authTagSz,
318-
(byte*)info->cipher.aesgcm_dec.authIn,
319-
info->cipher.aesgcm_dec.authInSz,
320-
(void*)ctx);
321-
}
322-
}
323-
#endif /* HAVE_AESGCM */
324-
#ifdef HAVE_AES_CBC
325-
if ((info->cipher.type == WC_CIPHER_AES_CBC) &&
326-
(cbInfo->keyflgs_tls.bits.session_key_set == 1 ||
327-
(cbInfo->keyflgs_crypt.bits.aes256_installedkey_set == 1 &&
328-
info->cipher.aescbc.aes->keylen == 32) ||
329-
(cbInfo->keyflgs_crypt.bits.aes128_installedkey_set == 1 &&
330-
info->cipher.aescbc.aes->keylen == 16))) {
331-
if (info->cipher.enc) {
332-
ret = wc_fspsm_AesCbcEncrypt(
333-
info->cipher.aescbc.aes,
334-
(byte*)info->cipher.aescbc.out,
335-
(byte*)info->cipher.aescbc.in,
336-
info->cipher.aescbc.sz);
337-
}
338-
else {
339-
ret = wc_fspsm_AesCbcDecrypt(
340-
info->cipher.aescbc.aes,
341-
(byte*)info->cipher.aescbc.out,
342-
(byte*)info->cipher.aescbc.in,
343-
info->cipher.aescbc.sz);
344-
}
345-
}
346-
#endif /* HAVE_AES_CBC */
282+
ret = wc_fspsm_AesCipher(devIdArg, info, ctx);
347283
#endif /* !NO_AES */
348284
}
349285

350286
#if !defined(NO_RSA) && defined(WOLFSSL_RENESAS_FSPSM_CRYPTONLY)
351287
else if (info->algo_type == WC_ALGO_TYPE_PK) {
352288
#if defined(WOLFSSL_KEY_GEN)
353-
if (info->pk.type == WC_PK_TYPE_RSA_KEYGEN &&
354-
(info->pk.rsakg.size == 1024 ||
355-
info->pk.rsakg.size == 2048)) {
289+
if (info->pk.type == WC_PK_TYPE_RSA_KEYGEN) {
356290
ret = wc_fspsm_MakeRsaKey(info->pk.rsakg.key,
357291
info->pk.rsakg.size, (void*)ctx);
358292
}
359293
#endif
360-
if (info->pk.type == WC_PK_TYPE_RSA) {
294+
if (info->pk.type == WC_PK_TYPE_RSA_PKCS) {
361295
/* to perform RSA on SCE, wrapped keys should be installed
362296
* in advance. SCE supports 1024 or 2048 bits key size.
363297
* otherwise, falls-through happens.
@@ -367,10 +301,6 @@ static int Renesas_cmn_CryptoDevCb(int devIdArg, wc_CryptoInfo* info, void* ctx)
367301
cbInfo->keyflgs_crypt.bits.rsapri1024_installedkey_set ||
368302
cbInfo->keyflgs_crypt.bits.rsapub1024_installedkey_set ) {
369303

370-
ret = wc_fspsm_MakeRsaKey(info->pk.rsa.key, 0, cbInfo);
371-
if (ret == WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE))
372-
return ret;
373-
374304
if (info->pk.rsa.type == RSA_PRIVATE_DECRYPT ||
375305
info->pk.rsa.type == RSA_PUBLIC_ENCRYPT )
376306
{
@@ -769,8 +699,9 @@ static int Renesas_cmn_EncryptKeys(WOLFSSL* ssl, void* ctx)
769699
#elif defined(WOLFSSL_RENESAS_FSPSM_TLS)
770700
FSPSM_ST* cbInfo = (FSPSM_ST*)ctx;
771701

772-
if (cbInfo->keyflgs_tls.bits.session_key_set == 1) {
773-
switch(cbInfo->side) {
702+
if (cbInfo != NULL && cbInfo->internal != NULL &&
703+
cbInfo->internal->keyflgs_tls.bits.session_key_set == 1) {
704+
switch(cbInfo->internal->side) {
774705
#endif
775706
case 1:/* ENCRYPT_SIDE_ONLY */
776707
ssl->encrypt.setup = 1;

0 commit comments

Comments
 (0)