Skip to content

Commit 210fff5

Browse files
authored
Merge pull request #6849 from miyazakh/rnd_gen_updates
Update random generation on RZ RSIP
2 parents d83f2fa + 8d5df6f commit 210fff5

9 files changed

Lines changed: 105 additions & 81 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,6 @@
113113
#if defined(WOLFSSL_RENESAS_SCEPROTECT_CRYPTONLY)
114114
#define WOLFSSL_KEY_GEN
115115
#endif
116+
117+
#define CUSTOM_RAND_GENERATE_BLOCK wc_fspsm_GenerateRandBlock
118+

IDE/Renesas/e2studio/RZN2L/README.md

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -482,52 +482,52 @@ Test complete
482482

483483
Sample Output
484484
```
485-
Started Serial I/O interface. Start wolfCrypt Benchmark
485+
Started Serial I/O interface. Start wolfCrypt Benchmark
486486
wolfCrypt Benchmark (block bytes 1024, min 1.0 sec each)
487-
RNG 525.0 KiB took 1.038 seconds, 505.780 KiB/s
488-
AES-128-CBC-enc 2.0 MiB took 1.011 seconds, 2.028 MiB/s
489-
AES-128-CBC-dec 1.1 MiB took 1.003 seconds, 1.972 MiB/s
490-
AES-192-CBC-enc 1.1 MiB took 1.007 seconds, 1.721 MiB/s
491-
AES-192-CBC-dec 1.1 MiB took 1.004 seconds, 1.678 MiB/s
492-
AES-256-CBC-enc 1.1 MiB took 1.015 seconds, 1.515 MiB/s
493-
AES-256-CBC-dec 1.0 MiB took 1.008 seconds, 1.477 MiB/s
494-
AES-128-GCM-enc 575.0 KiB took 1.014 seconds, 567.061 KiB/s
495-
AES-128-GCM-dec 575.0 KiB took 1.013 seconds, 567.621 KiB/s
496-
AES-192-GCM-enc 550.0 KiB took 1.017 seconds, 540.806 KiB/s
497-
AES-192-GCM-dec 550.0 KiB took 1.017 seconds, 540.806 KiB/s
498-
AES-256-GCM-enc 525.0 KiB took 1.012 seconds, 518.775 KiB/s
499-
AES-256-GCM-dec 525.0 KiB took 1.011 seconds, 519.288 KiB/s
500-
AES-128-GCM-enc-no_AAD 575.0 KiB took 1.003 seconds, 573.280 KiB/s
501-
AES-128-GCM-dec-no_AAD 575.0 KiB took 1.003 seconds, 573.280 KiB/s
502-
AES-192-GCM-enc-no_AAD 550.0 KiB took 1.006 seconds, 546.720 KiB/s
503-
AES-192-GCM-dec-no_AAD 550.0 KiB took 1.006 seconds, 546.720 KiB/s
504-
AES-256-GCM-enc-no_AAD 525.0 KiB took 1.001 seconds, 524.476 KiB/s
505-
AES-256-GCM-dec-no_AAD 525.0 KiB took 1.000 seconds, 525.000 KiB/s
506-
GMAC Default 791.0 KiB took 1.001 seconds, 790.210 KiB/s
507-
3DES 425.0 KiB took 1.025 seconds, 414.634 KiB/s
508-
MD5 12.0 MiB took 1.001 seconds, 12.439 MiB/s
509-
SHA 21.1 MiB took 1.000 seconds, 21.558 MiB/s
510-
SHA-224 21.0 MiB took 1.000 seconds, 21.362 MiB/s
511-
SHA-256 21.0 MiB took 1.000 seconds, 21.216 MiB/s
512-
SHA-384 19.1 MiB took 1.000 seconds, 19.897 MiB/s
513-
SHA-512 19.1 MiB took 1.000 seconds, 19.824 MiB/s
514-
SHA-512/224 20.0 MiB took 1.000 seconds, 20.117 MiB/s
515-
SHA-512/256 19.1 MiB took 1.000 seconds, 19.946 MiB/s
516-
HMAC-MD5 12.0 MiB took 1.000 seconds, 12.329 MiB/s
517-
HMAC-SHA 20.0 MiB took 1.000 seconds, 20.093 MiB/s
518-
HMAC-SHA224 19.1 MiB took 1.000 seconds, 19.922 MiB/s
519-
HMAC-SHA256 19.1 MiB took 1.000 seconds, 19.751 MiB/s
520-
HMAC-SHA384 18.0 MiB took 1.000 seconds, 18.457 MiB/s
521-
HMAC-SHA512 18.0 MiB took 1.000 seconds, 18.384 MiB/s
522-
PBKDF2 288.0 bytes took 1.082 seconds, 266.174 bytes/s
523-
RSA 2048 public 56 ops took 1.007 sec, avg 17.982 ms, 55.611 ops/sec
524-
RSA 2048 private 2 ops took 2.391 sec, avg 1195.500 ms, 0.836 ops/sec
525-
ECC [ SECP256R1] 256 key gen 2 ops took 1.213 sec, avg 606.500 ms, 1.649 ops/sec
526-
ECDHE [ SECP256R1] 256 agree 2 ops took 1.211 sec, avg 605.500 ms, 1.652 ops/sec
527-
ECDSA [ SECP256R1] 256 sign 2 ops took 1.224 sec, avg 612.000 ms, 1.634 ops/sec
528-
ECDSA [ SECP256R1] 256 verify 2 ops took 2.312 sec, avg 1155.1000 ms, 0.865 ops/sec
529-
CURVE 25519 key gen 2 ops took 1.061 sec, avg 530.500 ms, 1.885 ops/sec
530-
CURVE 25519 agree 2 ops took 1.060 sec, avg 530.000 ms, 1.887 ops/sec
487+
RNG 2.0 MiB took 1.000 seconds, 2.393 MiB/s
488+
AES-128-CBC-enc 2.0 MiB took 1.009 seconds, 2.032 MiB/s
489+
AES-128-CBC-dec 2.0 MiB took 1.002 seconds, 2.022 MiB/s
490+
AES-192-CBC-enc 1.1 MiB took 1.001 seconds, 1.732 MiB/s
491+
AES-192-CBC-dec 1.1 MiB took 1.008 seconds, 1.720 MiB/s
492+
AES-256-CBC-enc 1.1 MiB took 1.014 seconds, 1.517 MiB/s
493+
AES-256-CBC-dec 1.1 MiB took 1.008 seconds, 1.502 MiB/s
494+
AES-128-GCM-enc 675.0 KiB took 1.023 seconds, 659.824 KiB/s
495+
AES-128-GCM-dec 675.0 KiB took 1.022 seconds, 660.470 KiB/s
496+
AES-192-GCM-enc 625.0 KiB took 1.000 seconds, 625.000 KiB/s
497+
AES-192-GCM-dec 650.0 KiB took 1.039 seconds, 625.602 KiB/s
498+
AES-256-GCM-enc 600.0 KiB took 1.008 seconds, 595.238 KiB/s
499+
AES-256-GCM-dec 600.0 KiB took 1.007 seconds, 595.829 KiB/s
500+
AES-128-GCM-enc-no_AAD 675.0 KiB took 1.012 seconds, 666.996 KiB/s
501+
AES-128-GCM-dec-no_AAD 675.0 KiB took 1.011 seconds, 667.656 KiB/s
502+
AES-192-GCM-enc-no_AAD 650.0 KiB took 1.029 seconds, 631.681 KiB/s
503+
AES-192-GCM-dec-no_AAD 650.0 KiB took 1.028 seconds, 632.296 KiB/s
504+
AES-256-GCM-enc-no_AAD 625.0 KiB took 1.040 seconds, 600.962 KiB/s
505+
AES-256-GCM-dec-no_AAD 625.0 KiB took 1.039 seconds, 601.540 KiB/s
506+
GMAC Default 977.0 KiB took 1.000 seconds, 977.000 KiB/s
507+
3DES 450.0 KiB took 1.022 seconds, 440.313 KiB/s
508+
MD5 12.1 MiB took 1.001 seconds, 12.756 MiB/s
509+
SHA 21.0 MiB took 1.000 seconds, 21.240 MiB/s
510+
SHA-224 21.0 MiB took 1.000 seconds, 21.069 MiB/s
511+
SHA-256 20.1 MiB took 1.000 seconds, 20.923 MiB/s
512+
SHA-384 19.1 MiB took 1.000 seconds, 19.604 MiB/s
513+
SHA-512 19.1 MiB took 1.001 seconds, 19.561 MiB/s
514+
SHA-512/224 19.1 MiB took 1.000 seconds, 19.873 MiB/s
515+
SHA-512/256 19.1 MiB took 1.000 seconds, 19.751 MiB/s
516+
HMAC-MD5 12.0 MiB took 1.000 seconds, 12.451 MiB/s
517+
HMAC-SHA 19.1 MiB took 1.001 seconds, 19.512 MiB/s
518+
HMAC-SHA224 19.0 MiB took 1.000 seconds, 19.385 MiB/s
519+
HMAC-SHA256 19.0 MiB took 1.001 seconds, 19.219 MiB/s
520+
HMAC-SHA384 18.0 MiB took 1.000 seconds, 18.018 MiB/s
521+
HMAC-SHA512 17.1 MiB took 1.000 seconds, 17.944 MiB/s
522+
PBKDF2 224.0 bytes took 1.044 seconds, 214.559 bytes/s
523+
RSA 2048 public 40 ops took 1.020 sec, avg 25.500 ms, 39.216 ops/sec
524+
RSA 2048 private 2 ops took 3.196 sec, avg 1598.000 ms, 0.626 ops/sec
525+
ECC [ SECP256R1] 256 key gen 2 ops took 2.196 sec, avg 1097.1000 ms, 0.911 ops/sec
526+
ECDHE [ SECP256R1] 256 agree 2 ops took 2.186 sec, avg 1093.000 ms, 0.915 ops/sec
527+
ECDSA [ SECP256R1] 256 sign 2 ops took 2.215 sec, avg 1107.500 ms, 0.903 ops/sec
528+
ECDSA [ SECP256R1] 256 verify 2 ops took 4.210 sec, avg 2105.000 ms, 0.475 ops/sec
529+
CURVE 25519 key gen 3 ops took 1.255 sec, avg 418.333 ms, 2.390 ops/sec
530+
CURVE 25519 agree 4 ops took 1.672 sec, avg 418.000 ms, 2.392 ops/sec
531531
Benchmark complete
532532
End wolfCrypt Benchmark
533533
```

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,6 @@
110110
int uart_printf (const char *__restrict format, ...);
111111
#undef printf
112112
#define printf uart_printf
113+
114+
#define TEST_SLEEP() vTaskDelay(50)
115+
#define CUSTOM_RAND_GENERATE_BLOCK wc_fspsm_GenerateRandBlock

wolfcrypt/src/port/Renesas/renesas_fspsm_util.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,33 @@ WOLFSSL_LOCAL void wc_fspsm_Close()
183183
}
184184
}
185185

186+
#define RANDGEN_WORDS 4
187+
WOLFSSL_LOCAL int wc_fspsm_GenerateRandBlock(byte* output, word32 sz)
188+
{
189+
/* Generate PRNG based on NIST SP800-90A AES CTR-DRBG */
190+
int ret = 0;
191+
word32 buffer[RANDGEN_WORDS];
192+
193+
while (sz > 0) {
194+
word32 len = sizeof(buffer);
195+
196+
if (sz < len) {
197+
len = sz;
198+
}
199+
/* return 4 words random number*/
200+
ret = R_RANDOM_GEN(buffer);
201+
if(ret == FSP_SUCCESS) {
202+
XMEMCPY(output, &buffer, len);
203+
output += len;
204+
sz -= len;
205+
} else {
206+
WOLFSSL_MSG_EX("FSP SM Rnd Generate() Returned 0x%08x", ret);
207+
return WC_HW_E;
208+
}
209+
}
210+
return ret;
211+
}
212+
186213
#if defined(WOLFSSL_RENESAS_FSPSM) && \
187214
defined(WOLFSSL_RENESAS_FSPSM_TLS)
188215

wolfcrypt/src/random.c

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3474,41 +3474,6 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
34743474
}
34753475
return ret;
34763476
}
3477-
#elif defined(WOLFSSL_RENESAS_FSPSM) || \
3478-
defined(WOLFSSL_RENESAS_FSPSM_CRYPTONLY)
3479-
3480-
#if defined(WOLFSSL_RENESAS_SCEPROTECT)
3481-
#include "r_sce.h"
3482-
#define R_RANDOM_GEN(b) R_SCE_RandomNumberGenerate(b)
3483-
#elif defined(WOLFSSL_RENESAS_RSIP)
3484-
#include "r_rsip.h"
3485-
3486-
extern rsip_ctrl_t rsip_ctrl;
3487-
#define R_RANDOM_GEN(b) R_RSIP_RandomNumberGenerate(&rsip_ctrl,b)
3488-
#endif
3489-
3490-
int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
3491-
{
3492-
int ret = 0;
3493-
word32 buffer[4];
3494-
3495-
while (sz > 0) {
3496-
word32 len = sizeof(buffer);
3497-
3498-
if (sz < len) {
3499-
len = sz;
3500-
}
3501-
/* return 4 words random number*/
3502-
ret = R_RANDOM_GEN(buffer);
3503-
if(ret == FSP_SUCCESS) {
3504-
XMEMCPY(output, &buffer, len);
3505-
output += len;
3506-
sz -= len;
3507-
} else
3508-
return ret;
3509-
}
3510-
return ret;
3511-
}
35123477

35133478
#elif defined(WOLFSSL_SCE) && !defined(WOLFSSL_SCE_NO_TRNG)
35143479
#include "hal_data.h"

wolfcrypt/test/test.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,23 @@ const byte const_byte_array[] = "A+Gd\0\0\0";
198198
#include <printx.h>
199199
#undef printf
200200
#define printf printx
201+
#elif defined(WOLFSSL_RENESAS_RSIP)
202+
#ifndef TEST_SLEEP
203+
#define TEST_SLEEP() vTaskDelay(50)
204+
#endif
205+
#undef vprintf
206+
#define vprintf rsip_vprintf
207+
#include <stdarg.h> /* for var args */
208+
int rsip_vprintf(const char* restrict format, va_list args)
209+
{
210+
int ret;
211+
char tmpBuf[80];
212+
213+
ret = XSNPRINTF(tmpBuf, sizeof(tmpBuf), format, args);
214+
printf(tmpBuf);
215+
216+
return ret;
217+
}
201218
#else
202219
#ifdef XMALLOC_USER
203220
#include <stdlib.h> /* we're using malloc / free direct here */

wolfssl/wolfcrypt/aes.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ WOLFSSL_LOCAL void GHASH(Gcm* gcm, const byte* a, word32 aSz, const byte* c,
138138
#include <wolfssl/wolfcrypt/port/Renesas/renesas_tsip_types.h>
139139
#endif
140140

141+
#if defined(WOLFSSL_RENESAS_FSPSM)
142+
#include <wolfssl/wolfcrypt/port/Renesas/renesas-fspsm-crypt.h>
143+
#endif
144+
141145
#ifdef WOLFSSL_MAXQ10XX_CRYPTO
142146
#include <wolfssl/wolfcrypt/port/maxim/maxq10xx.h>
143147
#endif

wolfssl/wolfcrypt/port/Renesas/renesas-fspsm-crypt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,5 +341,5 @@ WOLFSSL_LOCAL int wc_fspsm_RsaSign(const byte* in, word32 inLen, byte* out,
341341
word32* outLen, struct RsaKey* key, void* ctx);
342342
WOLFSSL_LOCAL int wc_fspsm_RsaVerify(const byte* in, word32 inLen, byte* out,
343343
word32* outLen,struct RsaKey* key, void* ctx);
344-
344+
WOLFSSL_LOCAL int wc_fspsm_GenerateRandBlock(byte* output, word32 size);
345345
#endif /* __RENESAS_FSPSM_CRYPT_H__ */

wolfssl/wolfcrypt/port/Renesas/renesas-fspsm-types.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
#define FSPSM_OPEN R_SCE_Open
4646
#define FSPSM_CLOSE R_SCE_Close
4747

48+
/* rand generation func */
49+
#define R_RANDOM_GEN(b) R_SCE_RandomNumberGenerate(b)
50+
4851
#define FSPSM_ROOTCA_RSA2048 \
4952
R_SCE_TLS_RootCertificateRSA2048PublicKeyInstall
5053
#define FSPSM_TLS_SVRKEYExVfy R_SCE_TLS_ServerKeyExchangeVerify
@@ -182,6 +185,8 @@
182185
#define FSPSM_OPEN R_RSIP_Open
183186
#define FSPSM_CLOSE R_RSIP_Close
184187

188+
/* rnd generation func */
189+
#define R_RANDOM_GEN(b) R_RSIP_RandomNumberGenerate(&gFSPSM_ctrl,b)
185190
/* sha 1*/
186191
#define FSPSM_SHA_HANDLE rsip_sha_handle_t
187192
#define FSPSM_SHA1_Init _R_RSIP_SHA1_GenerateInit

0 commit comments

Comments
 (0)