Skip to content

Commit 75da699

Browse files
Merge pull request #7369 from dgarske/infineon_modustoolbox
Support for Infineon Modus Toolbox with wolfSSL
2 parents 04ebc96 + 83dc3df commit 75da699

8 files changed

Lines changed: 287 additions & 1 deletion

File tree

.cyignore

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# wolfSSL folders
2+
$(SEARCH_wolfssl)/IDE
3+
$(SEARCH_wolfssl)/examples
4+
$(SEARCH_wolfssl)/linuxkm
5+
$(SEARCH_wolfssl)/mcapi
6+
$(SEARCH_wolfssl)/mplabx
7+
$(SEARCH_wolfssl)/mqx
8+
$(SEARCH_wolfssl)/tirtos
9+
$(SEARCH_wolfssl)/tests
10+
$(SEARCH_wolfssl)/testsuite
11+
$(SEARCH_wolfssl)/wolfcrypt/src/port/autosar
12+
$(SEARCH_wolfssl)/zephyr
13+
14+
# wolfSSL files
15+
$(SEARCH_wolfssl)/wolfcrypt/src/aes_asm.S
16+
$(SEARCH_wolfssl)/wolfcrypt/src/aes_xts_asm.S
17+
$(SEARCH_wolfssl)/wolfcrypt/src/aes_gcm_asm.S
18+
$(SEARCH_wolfssl)/wolfcrypt/src/aes_gcm_x86_asm.S
19+
$(SEARCH_wolfssl)/wolfcrypt/src/chacha_asm.S
20+
$(SEARCH_wolfssl)/wolfcrypt/src/fe_x25519_asm.S
21+
$(SEARCH_wolfssl)/wolfcrypt/src/poly1305_asm.S
22+
$(SEARCH_wolfssl)/wolfcrypt/src/sha256_asm.S
23+
$(SEARCH_wolfssl)/wolfcrypt/src/sha512_asm.S
24+
$(SEARCH_wolfssl)/wolfcrypt/src/sha3_asm.S
25+
$(SEARCH_wolfssl)/wolfcrypt/src/sm3_asm.S
26+
$(SEARCH_wolfssl)/wolfcrypt/src/sp_x86_64_asm.S
27+
$(SEARCH_wolfssl)/wolfcrypt/src/sp_sm2_x86_64_asm.S
28+
$(SEARCH_wolfssl)/wolfcrypt/src/wc_kyber_asm.S
29+
30+
$(SEARCH_wolfssl)/wolfcrypt/src/port/arm/armv8-32-aes-asm.S
31+
$(SEARCH_wolfssl)/wolfcrypt/src/port/arm/armv8-32-curve25519.S
32+
$(SEARCH_wolfssl)/wolfcrypt/src/port/arm/armv8-32-sha256-asm.S
33+
$(SEARCH_wolfssl)/wolfcrypt/src/port/arm/armv8-32-sha512-asm.S
34+
$(SEARCH_wolfssl)/wolfcrypt/src/port/arm/armv8-curve25519.S
35+
$(SEARCH_wolfssl)/wolfcrypt/src/port/arm/armv8-sha3-asm.S
36+
$(SEARCH_wolfssl)/wolfcrypt/src/port/arm/armv8-sha512-asm.S
37+
$(SEARCH_wolfssl)/wolfcrypt/src/port/arm/thumb2-aes-asm.S
38+
$(SEARCH_wolfssl)/wolfcrypt/src/port/arm/thumb2-curve25519.S
39+
$(SEARCH_wolfssl)/wolfcrypt/src/port/arm/thumb2-sha256-asm.S
40+
$(SEARCH_wolfssl)/wolfcrypt/src/port/arm/thumb2-sha512-asm.S

IDE/Infineon/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Infineon Modus Toolbox
2+
3+
Steps for building wolfSSL/wolfTPM with the Infineon Modus Toolbox examples:
4+
5+
1) Add Dependency:
6+
7+
In "deps" folder add wolfssl.mtb containing:
8+
9+
```
10+
https://github.com/wolfssl/wolfssl#v5.7.0-stable#$$ASSET_REPO$$/wolfssl/wolfssl-stable
11+
```
12+
13+
For wolfTPM add wolftpm.mtb containing:
14+
15+
```
16+
https://github.com/wolfssl/wolftpm#master#$$ASSET_REPO$$/wolftpm/wolftpm-stable
17+
```
18+
19+
2) Add components:
20+
In `Makefile` under `COMPONENTS` add `WOLFSSL` and `WOLFTPM`.
21+
22+
3) Add defines:
23+
24+
Add `DEFINES+=WOLFSSL_USER_SETTINGS WOLFTPM_USER_SETTINGS` in Makefile.
25+
26+
4) Build settings:
27+
28+
Add a `user_settings.h` file for wolfSSL/wolfTPM build settings into `config` directory.
29+
A template is provided here in `IDE/Infineon/user_settings.h`.
30+
31+
5) Ignores:
32+
33+
The required library ignores are found in the `.cyignore` file in the wolfSSL and wolfTPM root.

IDE/Infineon/include.am

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# vim:ft=automake
2+
# included from Top Level Makefile.am
3+
# All paths should be given relative to the root
4+
5+
EXTRA_DIST += \
6+
IDE/Infineon/README.md \
7+
IDE/Infineon/user_settings.h

IDE/Infineon/user_settings.h

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
/* user_settings.h
2+
*
3+
* Copyright (C) 2006-2024 wolfSSL Inc.
4+
*
5+
* This file is part of wolfSSL.
6+
*
7+
* wolfSSL is free software; you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation; either version 2 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* wolfSSL is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
20+
*/
21+
22+
/* Example build settings for Infineon Modus Toolbox */
23+
/* Enables wolfSSL TLS v1.2-v1.3 and TPM support */
24+
/* SHA-1, SHA-2, AES CBC/GCM, ECDHE, ECDSA, RSA, HMAC, HKDF */
25+
26+
#ifndef WOLF_USER_SETTINGS_TPM_H
27+
#define WOLF_USER_SETTINGS_TPM_H
28+
29+
#ifdef __cplusplus
30+
extern "C" {
31+
#endif
32+
33+
/* Platform / Porting */
34+
#define NO_FILESYSTEM /* File system disable */
35+
#define SINGLE_THREADED /* No threading */
36+
#define WOLFSSL_USER_IO /* user recv/send callbacks for network IO */
37+
#define NO_WRITEV
38+
#define NO_MAIN_DRIVER
39+
#define WOLFSSL_IGNORE_FILE_WARN /* ignore file include warnings */
40+
#define WOLFSSL_SMALL_STACK /* limit stack usage */
41+
#define BENCH_EMBEDDED
42+
43+
/* TLS (allow TLS v1.3 or v1.2) */
44+
#define WOLFSSL_TLS13
45+
//#define WOLFSSL_NO_TLS12
46+
#define NO_OLD_TLS
47+
#define WOLFSSL_EITHER_SIDE /* allow context to be created for either server or client */
48+
49+
#define HAVE_TLS_EXTENSIONS
50+
#define HAVE_SUPPORTED_CURVES
51+
#define HAVE_SERVER_RENEGOTIATION_INFO
52+
#define HAVE_ENCRYPT_THEN_MAC
53+
54+
#ifdef WOLFSSL_TLS13
55+
#define HAVE_HKDF
56+
#define WC_RSA_PSS
57+
#define WOLFSSL_PSS_LONG_SALT
58+
#endif
59+
60+
/* Enable crypto callbacks - for TPM offloading */
61+
#define WOLF_CRYPTO_CB
62+
63+
/* Enable SP math all (sp_int.c) with multi-precision support */
64+
#define WOLFSSL_SP_MATH_ALL
65+
66+
#if 1
67+
/* Single Precision math for ECC 256 and RSA 2048 */
68+
#define WOLFSSL_HAVE_SP_RSA
69+
#define WOLFSSL_HAVE_SP_ECC
70+
#define WOLFSSL_SP_SMALL
71+
#endif
72+
73+
#if 0
74+
/* only single precision math */
75+
#define WOLFSSL_SP_MATH
76+
#endif
77+
78+
/* Enable hardening (timing resistance) */
79+
#define TFM_TIMING_RESISTANT
80+
#define ECC_TIMING_RESISTANT
81+
#define WC_RSA_BLINDING
82+
83+
/* Enable PRNG (SHA2-256) */
84+
#define HAVE_HASHDRBG
85+
86+
/* Asymmetric */
87+
#if 1 /* RSA - needed to encrypt salt */
88+
#undef NO_RSA
89+
#ifdef USE_LOW_RESOURCE
90+
#define WOLFSSL_RSA_PUBLIC_ONLY
91+
#define WOLFSSL_RSA_VERIFY_INLINE
92+
#define NO_CHECK_PRIVATE_KEY
93+
#endif
94+
#else
95+
#define NO_RSA
96+
#endif
97+
98+
#if 1 /* ECC - needed for encrypt ECC salt */
99+
#define HAVE_ECC
100+
#define ECC_USER_CURVES /* default to only SECP256R1 */
101+
#endif
102+
103+
#if 0 /* DH - TPM doesn't support it */
104+
#undef NO_DH
105+
#define HAVE_FFDHE_2048
106+
#define HAVE_DH_DEFAULT_PARAMS
107+
#else
108+
#define NO_DH
109+
#endif
110+
111+
/* Symmetric Hash */
112+
#undef NO_SHA /* allow SHA-1 */
113+
#undef NO_SHA256 /* allow SHA2-256 */
114+
#define WOLFSSL_SHA384
115+
#define WOLFSSL_SHA512
116+
117+
/* Symmetric Cipher */
118+
#define WOLFSSL_AES_CFB
119+
#define HAVE_AES_DECRYPT
120+
121+
#define HAVE_AES_KEYWRAP
122+
#define WOLFSSL_AES_DIRECT
123+
#define HAVE_AESGCM
124+
#define GCM_TABLE_4BIT
125+
126+
/* Features */
127+
#define WOLFSSL_ASN_TEMPLATE
128+
129+
#define WOLFSSL_CERT_GEN
130+
#define WOLFSSL_CERT_REQ
131+
#define WOLFSSL_CERT_EXT
132+
133+
#define HAVE_PKCS7
134+
#define HAVE_X963_KDF
135+
#define WOLFSSL_BASE64_ENCODE
136+
137+
#if 1
138+
#define HAVE_SESSION_TICKETS
139+
#define SMALL_SESSION_CACHE
140+
#else
141+
#define NO_SESSION_CACHE
142+
#endif
143+
144+
/* Disables */
145+
#define NO_PKCS8
146+
#define NO_PKCS12
147+
#define NO_PWDBASED
148+
#define NO_DSA
149+
#define NO_DES3
150+
#define NO_RC4
151+
#define NO_PSK
152+
#define NO_MD4
153+
#define NO_MD5
154+
#define WOLFSSL_NO_SHAKE128
155+
#define WOLFSSL_NO_SHAKE256
156+
157+
/* Logging */
158+
#ifdef ENABLE_SECURE_SOCKETS_LOGS
159+
#define DEBUG_WOLFSSL
160+
#else
161+
#define NO_ERROR_STRINGS
162+
#endif
163+
164+
#ifdef __cplusplus
165+
}
166+
#endif
167+
168+
#endif /* WOLF_USER_SETTINGS_TPM_H */

IDE/include.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ include IDE/apple-universal/include.am
6060
include IDE/MPLABX16/include.am
6161
include IDE/MPLABX16/wolfssl.X/nbproject/include.am
6262
include IDE/MPLABX16/wolfcrypt_test.X/nbproject/include.am
63+
include IDE/Infineon/include.am
6364

6465
EXTRA_DIST+= IDE/IAR-EWARM IDE/MDK-ARM IDE/MYSQL IDE/LPCXPRESSO IDE/HEXIWEAR IDE/Espressif
6566
EXTRA_DIST+= IDE/OPENSTM32/README.md

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ dist_example_DATA=
138138

139139
ACLOCAL_AMFLAGS= -I m4
140140

141+
EXTRA_DIST+= .cyignore
141142
EXTRA_DIST+= wolfssl.vcproj
142143
EXTRA_DIST+= wolfssl.vcxproj
143144
EXTRA_DIST+= wolfssl64.sln

examples/configs/user_settings_wolftpm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ extern "C" {
131131
#else
132132
#define NO_RSA
133133
#endif
134-
#ifndef USE_LOW_RESOURCE /* ECC */
134+
#if 1 /* ECC - needed for encrypt ECC salt */
135135
#define HAVE_ECC
136136
#define ECC_USER_CURVES /* default to only SECP256R1 */
137137
#endif

wolfcrypt/src/random.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ This library contains implementation for the random number generator.
128128
#elif defined(WOLFSSL_TELIT_M2MB)
129129
#elif defined(WOLFSSL_SCE) && !defined(WOLFSSL_SCE_NO_TRNG)
130130
#elif defined(WOLFSSL_IMXRT1170_CAAM)
131+
#elif defined(CY_USING_HAL) && defined(COMPONENT_WOLFSSL)
132+
#include "cyhal_trng.h" /* Infineon/Cypress HAL RNG implementation */
131133
#elif defined(WOLFSSL_GETRANDOM)
132134
#include <errno.h>
133135
#include <sys/random.h>
@@ -3832,6 +3834,40 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
38323834
return ret;
38333835
}
38343836

3837+
#elif defined(CY_USING_HAL) && defined(COMPONENT_WOLFSSL)
3838+
3839+
/* Infineon/Cypress HAL RNG implementation */
3840+
int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
3841+
{
3842+
cyhal_trng_t obj;
3843+
cy_rslt_t result;
3844+
uint32_t val;
3845+
word32 i = 0;
3846+
3847+
(void)os;
3848+
3849+
result = cyhal_trng_init(&obj);
3850+
if (result == CY_RSLT_SUCCESS) {
3851+
while (i < sz) {
3852+
/* If not aligned or there is odd/remainder add single byte */
3853+
if( (i + sizeof(word32)) > sz ||
3854+
((wc_ptr_t)&output[i] % sizeof(word32)) != 0
3855+
) {
3856+
val = cyhal_trng_generate(&obj);
3857+
output[i++] = (byte)val;
3858+
}
3859+
else {
3860+
/* Use native 32 instruction */
3861+
val = cyhal_trng_generate(&obj);
3862+
*((uint32_t*)&output[i]) = val;
3863+
i += sizeof(word32);
3864+
}
3865+
}
3866+
cyhal_trng_free(&obj);
3867+
}
3868+
return 0;
3869+
}
3870+
38353871
#elif defined(WOLFSSL_SAFERTOS) || defined(WOLFSSL_LEANPSK) || \
38363872
defined(WOLFSSL_IAR_ARM) || defined(WOLFSSL_MDK_ARM) || \
38373873
defined(WOLFSSL_uITRON4) || defined(WOLFSSL_uTKERNEL2) || \

0 commit comments

Comments
 (0)