Skip to content

Commit 5f6fefe

Browse files
Enable hardware acceleration for SHA algorithms on PSoC6.
- Introduced conditional compilation for PSoC6 crypto support across SHA1, SHA2, SHA3 implementations. - Ensured proper mutex locking for concurrent access to hardware resources during hash operations. - Added public key creation functionality if only private key is provided in ECDSA verify function (psoc6_ecc_verify_hash_ex). - Updated ECC parameter size handling to fix incorrect endianness conversions in psoc6_ecc_verify_hash_ex(). - Added README for PSOC6 port.
1 parent dc421a0 commit 5f6fefe

File tree

15 files changed

+1541
-142
lines changed

15 files changed

+1541
-142
lines changed

.wolfssl_known_macro_extras

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,6 @@ WOLFSSL_PSK_IDENTITY_ALERT
830830
WOLFSSL_PSK_ID_PROTECTION
831831
WOLFSSL_PSK_MULTI_ID_PER_CS
832832
WOLFSSL_PSK_TLS13_CB
833-
WOLFSSL_PSOC6_CRYPTO
834833
WOLFSSL_PYTHON
835834
WOLFSSL_RENESAS_FSPSM_CRYPT_ONLY
836835
WOLFSSL_RENESAS_RA6M3

wolfcrypt/src/ecc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@ ECC Curve Sizes:
232232
#if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
233233
!defined(WOLFSSL_CRYPTOCELL) && !defined(WOLFSSL_SILABS_SE_ACCEL) && \
234234
!defined(WOLFSSL_KCAPI_ECC) && !defined(WOLFSSL_SE050) && \
235-
!defined(WOLFSSL_XILINX_CRYPT_VERSAL) && !defined(WOLFSSL_STM32_PKA)
235+
!defined(WOLFSSL_XILINX_CRYPT_VERSAL) && !defined(WOLFSSL_STM32_PKA) && \
236+
!defined(WOLFSSL_PSOC6_CRYPTO)
236237
#undef HAVE_ECC_VERIFY_HELPER
237238
#define HAVE_ECC_VERIFY_HELPER
238239
#endif

wolfcrypt/src/include.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ EXTRA_DIST += wolfcrypt/src/port/ti/ti-aes.c \
149149
wolfcrypt/src/port/Renesas/renesas_rx64_hw_sha.c \
150150
wolfcrypt/src/port/Renesas/renesas_rx64_hw_util.c \
151151
wolfcrypt/src/port/Renesas/README.md \
152+
wolfcrypt/src/port/cypress/README.md \
152153
wolfcrypt/src/port/cypress/psoc6_crypto.c \
153154
wolfcrypt/src/port/liboqs/liboqs.c \
154155
wolfcrypt/src/port/maxim/max3266x.c \
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# PSoC6 Hardware Crypto Port for wolfSSL
2+
3+
This directory provides a hardware-accelerated cryptography port for Cypress PSoC6 devices, integrating the PSoC6 hardware crypto block with the wolfSSL cryptography library. The implementation leverages the PSoC6 hardware to accelerate various cryptographic hash and ECC operations, improving performance and reducing CPU load.
4+
5+
## Implemented Features
6+
7+
### 1. Hardware-Accelerated Hash Functions
8+
9+
The following hash algorithms are implemented using the PSoC6 hardware crypto block:
10+
11+
- **SHA-1, SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224, SHA-512/256**
12+
- All handled by the function `wc_Psoc6_Sha1_Sha2_Init`, which initializes the hardware for the selected hash mode.
13+
- The macros `PSOC6_HASH_SHA1` and `PSOC6_HASH_SHA2` (defined in `psoc6_crypto.h`) control which SHA-1 and SHA-2 family algorithms are available for hardware acceleration.
14+
- The corresponding wolfSSL macros (e.g., `WOLFSSL_SHA224`, `WOLFSSL_SHA384`, `WOLFSSL_SHA512`) must also be defined to enable the algorithm in the library.
15+
16+
- **SHA-3 Family**
17+
- Supported if `PSOC6_HASH_SHA3` (defined in `psoc6_crypto.h`) and `WOLFSSL_SHA3` are both defined.
18+
- Functions: `wc_Psoc6_Sha3_Init`, `wc_Psoc6_Sha3_Update`, `wc_Psoc6_Sha3_Final`
19+
- SHAKE support: `wc_Psoc6_Shake_SqueezeBlocks`
20+
- To enable SHAKE support (and use wc_Psoc6_Shake_SqueezeBlocks), you must define either `WOLFSSL_SHAKE128` or `WOLFSSL_SHAKE256` in addition to `WOLFSSL_SHA3` and hardware acceleration macros.
21+
22+
All hash operations are offloaded to the PSoC6 hardware, with mutex protection for thread safety.
23+
24+
### 2. Hardware-Accelerated ECDSA Verification
25+
26+
- **ECDSA Signature Verification**
27+
- Function: `psoc6_ecc_verify_hash_ex`
28+
- Uses PSoC6 hardware to verify ECDSA signatures for supported curves (up to secp521r1).
29+
- Enabled when `HAVE_ECC` is defined.
30+
31+
### 3. Crypto Block Initialization and Resource Management
32+
33+
- **Initialization**
34+
- Function: `psoc6_crypto_port_init`
35+
- Enables the PSoC6 crypto hardware block.
36+
- **Resource Cleanup**
37+
- Function: `wc_Psoc6_Sha_Free`
38+
- Clears and synchronizes the hardware register buffer.
39+
40+
## Enable Hardware Acceleration
41+
42+
To enable PSoC6 hardware crypto acceleration for hash and ECC algorithms, ensure the following macros are defined:
43+
44+
- `WOLFSSL_PSOC6_CRYPTO` — Enables the PSoC6 hardware crypto port.
45+
- The following are defined in `psoc6_crypto.h` and control which hardware hash accelerations are available:
46+
- `PSOC6_HASH_SHA1` — Enables SHA-1 hardware acceleration.
47+
- `PSOC6_HASH_SHA2` — Enables SHA-2 family (SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224, SHA-512/256) hardware acceleration.
48+
- `PSOC6_HASH_SHA3` — Enables SHA-3 family hardware acceleration.
49+
- To enable the corresponding algorithms in wolfSSL, define the following macros as needed (typically in your `wolfssl/wolfcrypt/settings.h` or build system):
50+
- `WOLFSSL_SHA224` — Enable SHA-224 support.
51+
- `WOLFSSL_SHA384` — Enable SHA-384 support.
52+
- `WOLFSSL_SHA512` — Enable SHA-512, SHA-512/224, SHA-512/256 support.
53+
- `WOLFSSL_SHA3` — Enable SHA-3 support.
54+
- `WOLFSSL_SHAKE128`, `WOLFSSL_SHAKE256` — Enable SHAKE support.
55+
- `HAVE_ECC` — Enable ECC and ECDSA support.
56+
57+
**Example: Enabling SHA-1, SHA-2, and SHA-3 Hardware Acceleration**
58+
59+
In your build configuration or `wolfssl/wolfcrypt/settings.h`:
60+
```c
61+
#define WOLFSSL_PSOC6_CRYPTO
62+
#define WOLFSSL_SHA224
63+
#define WOLFSSL_SHA384
64+
#define WOLFSSL_SHA512
65+
#define WOLFSSL_SHA3
66+
#define WOLFSSL_SHAKE128
67+
#define WOLFSSL_SHAKE256
68+
#define HAVE_ECC
69+
```
70+
- No need to define `PSOC6_HASH_SHA1`, `PSOC6_HASH_SHA2`, or `PSOC6_HASH_SHA3` yourself; they are defined in `psoc6_crypto.h`.
71+
72+
## File Overview
73+
74+
- `psoc6_crypto.h`
75+
Header file declaring the hardware crypto interface and configuration macros.
76+
- `psoc6_crypto.c`
77+
Implementation of the hardware-accelerated hash and ECC functions for PSoC6.
78+
79+
## Integration Notes
80+
81+
- The port expects the PSoC6 PDL (Peripheral Driver Library) to be available and included in your project.
82+
- The hardware crypto block is initialized on first use; no manual initialization is required unless you wish to call `psoc6_crypto_port_init` directly.
83+
- Hash operations are mutex-protected for thread safety.
84+
- ECC hardware operations are not mutex-protected; if you use ECC functions from multiple threads, you must provide your own synchronization.
85+
- The implementation is designed to be compatible with the wolfSSL API, so existing code using wolfSSL hash/ECC functions will automatically benefit from hardware acceleration when enabled.
86+
87+
---
88+
89+
For further details, refer to the comments in [`psoc6_crypto.h`](wolfssl/wolfssl-master/wolfcrypt/port/cypress/psoc6_crypto.h) and [`psoc6_crypto.c`](wolfssl/wolfssl-master/wolfcrypt/src/port/cypress/psoc6_crypto.c)

0 commit comments

Comments
 (0)