Skip to content

Commit a5f6c91

Browse files
Merge pull request #382 from dgarske/ns350
Tested support for Nations NS350 and added simple capabilities example
2 parents 5e87595 + 78457be commit a5f6c91

File tree

4 files changed

+202
-9
lines changed

4 files changed

+202
-9
lines changed

README.md

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Portable TPM 2.0 project designed for embedded use.
77

88
* This implementation provides all TPM 2.0 API's in compliance with the specification.
99
* Wrappers provided to simplify Key Generation/Loading, RSA encrypt/decrypt, ECC sign/verify, ECDH, NV, Hashing/HACM, AES, Sealing/Unsealing, Attestation, PCR Extend/Quote and Secure Root of Trust.
10-
* Testing done using TPM 2.0 modules from STMicro ST33 (SPI/I2C), Infineon OPTIGA SLB9670/SLB9672, Microchip ATTPM20, Nations Tech Z32H330TC and Nuvoton NPCT650/NPCT750.
10+
* Testing done using TPM 2.0 modules from STMicro ST33 (SPI/I2C), Infineon OPTIGA SLB9670/SLB9672, Microchip ATTPM20, Nations Tech Z32H330TC/NS350 and Nuvoton NPCT650/NPCT750.
1111
* wolfTPM uses the TPM Interface Specification (TIS) to communicate either over SPI, or using a memory mapped I/O range.
1212
* wolfTPM can also use the Linux TPM kernel interface (`/dev/tpmX`) to talk with any physical TPM on SPI, I2C and even LPC bus.
1313
* Platform support for Raspberry Pi (Linux), MMIO, STM32 with CubeMX, Atmel ASF, Xilinx, QNX Infineon TriCore and Barebox.
@@ -27,10 +27,11 @@ Portable TPM 2.0 project designed for embedded use.
2727
* Attestation (activate and make credential)
2828
* Benchmarking TPM algorithms and TLS
2929
* Key Generation (primary, RSA/ECC and symmetric), loading and storing to flash (NV memory)
30-
* Sealing and Unsealing data with an RSA key
30+
* Sealing and Unsealing data with an RSA key or externally signed policy.
3131
* Time signed or set
3232
* PCR read/reset
3333
* GPIO configure, read and write.
34+
* Endrosement Key/Cert retreival and validation.
3435
* Parameter encryption support using AES-CFB or XOR.
3536
* Support for salted unbound authenticated sessions.
3637
* Support for HMAC Sessions.
@@ -99,8 +100,8 @@ Tested with:
99100
- LetsTrust: Vendor for TPM development boards [http://letstrust.de](http://letstrust.de).
100101
* STMicro STSAFE-TPM, ST33TPHF2XSPI/2XI2C and ST33KTPM2X (SPI and I2C)
101102
* Microchip ATTPM20 module
102-
* Nuvoton NPCT65X or NPCT75x TPM2.0 module
103-
* Nations Technologies Z32H330 TPM 2.0 module
103+
* Nuvoton NPCT65X or NPCT75x TPM2.0 modules
104+
* Nations Technologies Z32H330 or NS350 TPM 2.0 modules
104105

105106
#### Device Identification
106107

@@ -132,9 +133,13 @@ Microchip ATTPM20
132133
TPM2: Caps 0x30000695, Did 0x3205, Vid 0x1114, Rid 0x 1
133134
Mfg MCHP (3), Vendor , Fw 512.20481 (0), FIPS 140-2 0, CC-EAL4 0
134135

135-
Nations Technologies Inc. TPM 2.0 module
136+
Nations Technologies Inc. Z32H330 TPM 2.0 module
136137
Mfg NTZ (0), Vendor Z32H330, Fw 7.51 (419631892), FIPS 140-2 0, CC-EAL4 0
137138

139+
Nations Technologies Inc. NS350 TPM 2.0 module
140+
TPM2: Caps 0x30000615, Did 0x0701, Vid 0x9999, Rid 0x 1
141+
Mfg NSG (0), Vendor NS350, Fw 30.30 (0x24042510), FIPS 140-2 1, CC-EAL4 0
142+
138143
Nuvoton NPCT650 TPM2.0
139144
Mfg NTC (0), Vendor rlsNPCT , Fw 1.3 (65536), FIPS 140-2 0, CC-EAL4 0
140145

@@ -253,6 +258,11 @@ Build wolfTPM:
253258
make
254259
```
255260

261+
### Building Nations Tech
262+
263+
Use `./configure` with defaults. All TPM 2.0 modules are compatible.
264+
The Nations NS350 Raspberry Pi TPM 2.0 module uses `/dev/spidev0.0`. The TPM wait states are required (on by default with WOLFTPM_CHECK_WAIT_STATE).
265+
256266
### Building Espressif ESP-IDF
257267

258268
See the wolfTPM-specific settings in the wolfSSL `user_settings.h` file, typically found in `[project]/components/wolfssl/include`.
@@ -334,6 +344,18 @@ cmake --build .
334344

335345
These examples demonstrate features of a TPM 2.0 module. The examples create RSA and ECC keys in NV for testing using handles defined in `./hal/tpm_io.h`. The PKCS #7 and TLS examples require generating CSR's and signing them using a test script. See `examples/README.md` for details on using the examples. To run the TLS sever and client on same machine you must build with `WOLFTPM_TIS_LOCK` to enable concurrent access protection.
336346

347+
### TPM2 Capabilities
348+
349+
Simple test that gets TPM capabilities and search for any persistent handles.
350+
351+
```
352+
./examples/wrap/caps
353+
TPM2 Get Capabilities
354+
wolfSSL Entering wolfCrypt_Init
355+
Mfg NSG (0), Vendor NS350, Fw 30.30 (0x24042510), FIPS 140-2 1, CC-EAL4 0
356+
Found 2 persistent handles
357+
```
358+
337359
### TPM2 Wrapper Tests
338360

339361
```
@@ -556,7 +578,7 @@ ECDSA 256 verify 24 ops took 1.031 sec, avg 42.970 ms, 23.272 ops/sec
556578
ECDHE 256 agree 16 ops took 1.023 sec, avg 63.934 ms, 15.641 ops/sec
557579
```
558580

559-
Run on Nations Technologies Inc. TPM 2.0 module at 33MHz:
581+
Run on Nations Technologies Inc. Z32H330 TPM 2.0 module at 33MHz:
560582

561583
```
562584
./examples/bench/bench
@@ -588,6 +610,43 @@ ECDSA 256 verify 28 ops took 1.030 sec, avg 36.785 ms, 27.185 ops/sec
588610
ECDHE 256 agree 26 ops took 1.010 sec, avg 38.847 ms, 25.742 ops/sec
589611
```
590612

613+
Run on Nations Technologies Inc. NS350 TPM 2.0 module at 33MHz:
614+
615+
```
616+
./examples/bench/bench
617+
TPM2 Benchmark using Wrapper API's
618+
Use Parameter Encryption: NULL
619+
RNG 6 KB took 1.052 seconds, 5.703 KB/s
620+
Benchmark symmetric AES-128-CBC-enc not supported!
621+
Benchmark symmetric AES-128-CBC-dec not supported!
622+
Benchmark symmetric AES-256-CBC-enc not supported!
623+
Benchmark symmetric AES-256-CBC-dec not supported!
624+
Benchmark symmetric AES-128-CTR-enc not supported!
625+
Benchmark symmetric AES-128-CTR-dec not supported!
626+
Benchmark symmetric AES-256-CTR-enc not supported!
627+
Benchmark symmetric AES-256-CTR-dec not supported!
628+
Encrypt/Decrypt unavailable
629+
AES-128-CFB-enc 0 bytes took 0.005 seconds, 0.000 bytes/s
630+
Encrypt/Decrypt unavailable
631+
AES-128-CFB-dec 0 bytes took 0.006 seconds, 0.000 bytes/s
632+
Encrypt/Decrypt unavailable
633+
AES-256-CFB-enc 0 bytes took 0.006 seconds, 0.000 bytes/s
634+
Encrypt/Decrypt unavailable
635+
AES-256-CFB-dec 0 bytes took 0.005 seconds, 0.000 bytes/s
636+
SHA1 68 KB took 1.003 seconds, 67.772 KB/s
637+
SHA256 68 KB took 1.002 seconds, 67.871 KB/s
638+
SHA384 66 KB took 1.007 seconds, 65.548 KB/s
639+
RSA 2048 key gen 7 ops took 16.652 sec, avg 2378.893 ms, 0.420 ops/sec
640+
RSA 2048 Public 126 ops took 1.005 sec, avg 7.980 ms, 125.321 ops/sec
641+
RSA 2048 Private 20 ops took 1.035 sec, avg 51.735 ms, 19.329 ops/sec
642+
RSA 2048 Pub OAEP 81 ops took 1.008 sec, avg 12.443 ms, 80.366 ops/sec
643+
RSA 2048 Priv OAEP 19 ops took 1.027 sec, avg 54.033 ms, 18.507 ops/sec
644+
ECC 256 key gen 20 ops took 1.042 sec, avg 52.095 ms, 19.196 ops/sec
645+
ECDSA 256 sign 60 ops took 1.009 sec, avg 16.816 ms, 59.466 ops/sec
646+
ECDSA 256 verify 46 ops took 1.008 sec, avg 21.921 ms, 45.618 ops/sec
647+
ECDHE 256 agree 38 ops took 1.008 sec, avg 26.532 ms, 37.691 ops/sec
648+
```
649+
591650
Run on Nuvoton NPCT650:
592651

593652
```

examples/wrap/caps.c

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/* caps.
2+
*
3+
* Copyright (C) 2006-2024 wolfSSL Inc.
4+
*
5+
* This file is part of wolfTPM.
6+
*
7+
* wolfTPM 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+
* wolfTPM 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+
/* Simple test to get capabilities from TPM */
23+
24+
#ifdef HAVE_CONFIG_H
25+
#include <config.h>
26+
#endif
27+
28+
#include <wolftpm/tpm2.h>
29+
#include <wolftpm/tpm2_wrap.h>
30+
31+
#include <stdio.h>
32+
33+
#ifndef WOLFTPM2_NO_WRAPPER
34+
35+
#include <hal/tpm_io.h>
36+
#include <examples/tpm_test.h>
37+
#include <examples/wrap/wrap_test.h>
38+
39+
40+
/******************************************************************************/
41+
/* --- BEGIN Capabilities API example -- */
42+
/******************************************************************************/
43+
44+
static void usage(void)
45+
{
46+
printf("Expected Usage:\n");
47+
printf("./examples/wrap/caps\n");
48+
49+
}
50+
51+
int TPM2_Wrapper_Caps(void* userCtx)
52+
{
53+
return TPM2_Wrapper_CapsArgs(userCtx, 0, NULL);
54+
}
55+
int TPM2_Wrapper_CapsArgs(void* userCtx, int argc, char *argv[])
56+
{
57+
int rc;
58+
WOLFTPM2_DEV dev;
59+
WOLFTPM2_CAPS caps;
60+
61+
if (argc > 1) {
62+
if (XSTRCMP(argv[1], "-?") == 0 ||
63+
XSTRCMP(argv[1], "-h") == 0 ||
64+
XSTRCMP(argv[1], "--help") == 0) {
65+
usage();
66+
return 0;
67+
}
68+
}
69+
70+
printf("TPM2 Get Capabilities\n");
71+
72+
/* Init the TPM2 device */
73+
rc = wolfTPM2_Init(&dev, TPM2_IoCb, userCtx);
74+
if (rc != 0) return rc;
75+
76+
rc = wolfTPM2_GetCapabilities(&dev, &caps);
77+
if (rc != 0) goto exit;
78+
79+
printf("Mfg %s (%d), Vendor %s, Fw %u.%u (0x%x), "
80+
"FIPS 140-2 %d, CC-EAL4 %d\n",
81+
caps.mfgStr, caps.mfg, caps.vendorStr, caps.fwVerMajor,
82+
caps.fwVerMinor, caps.fwVerVendor, caps.fips140_2, caps.cc_eal4);
83+
#if defined(WOLFTPM_SLB9672) || defined(WOLFTPM_SLB9673)
84+
printf("\tKeyGroupId 0x%x, Operational Mode 0x%x, FwCounter %d (%d same)\n",
85+
caps.keyGroupId, caps.opMode, caps.fwCounter, caps.fwCounterSame);
86+
#endif
87+
88+
/* List the active persistent handles */
89+
rc = wolfTPM2_GetHandles(PERSISTENT_FIRST, NULL);
90+
if (rc >= 0) {
91+
printf("Found %d persistent handles\n", rc);
92+
}
93+
94+
exit:
95+
wolfTPM2_Shutdown(&dev, 0); /* 0=just shutdown, no startup */
96+
97+
wolfTPM2_Cleanup(&dev);
98+
99+
return rc;
100+
}
101+
102+
/******************************************************************************/
103+
/* --- END Capabilities API example -- */
104+
/******************************************************************************/
105+
106+
#endif /* !WOLFTPM2_NO_WRAPPER */
107+
108+
#ifndef NO_MAIN_DRIVER
109+
int main(int argc, char *argv[])
110+
{
111+
int rc = -1;
112+
113+
(void)argc;
114+
(void)argv;
115+
116+
#ifndef WOLFTPM2_NO_WRAPPER
117+
rc = TPM2_Wrapper_CapsArgs(NULL, argc, argv);
118+
#else
119+
printf("Wrapper code not compiled in\n");
120+
#endif
121+
122+
return rc;
123+
}
124+
#endif /* !NO_MAIN_DRIVER */

examples/wrap/include.am

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,21 @@
22
# All paths should be given relative to the root
33

44
if BUILD_EXAMPLES
5-
noinst_PROGRAMS += examples/wrap/wrap_test
5+
noinst_PROGRAMS += examples/wrap/wrap_test \
6+
examples/wrap/caps
67
noinst_HEADERS += examples/wrap/wrap_test.h
78
examples_wrap_wrap_test_SOURCES = examples/wrap/wrap_test.c
89
examples_wrap_wrap_test_LDADD = src/libwolftpm.la $(LIB_STATIC_ADD)
910
examples_wrap_wrap_test_DEPENDENCIES = src/libwolftpm.la
11+
12+
examples_wrap_caps_SOURCES = examples/wrap/caps.c
13+
examples_wrap_caps_LDADD = src/libwolftpm.la $(LIB_STATIC_ADD)
14+
examples_wrap_caps_DEPENDENCIES = src/libwolftpm.la
1015
endif
1116

1217
example_wrapdir = $(exampledir)/wrap
13-
dist_example_wrap_DATA = examples/wrap/wrap_test.c
18+
dist_example_wrap_DATA = examples/wrap/wrap_test.c \
19+
examples/wrap/caps.c
1420

15-
DISTCLEANFILES+= examples/wrap/.libs/wrap_test
21+
DISTCLEANFILES+= examples/wrap/.libs/wrap_test \
22+
examples/wrap/.libs/caps

examples/wrap/wrap_test.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ void TPM2_Wrapper_SetReset(int reset);
3030
int TPM2_Wrapper_Test(void* userCtx);
3131
int TPM2_Wrapper_TestArgs(void* userCtx, int argc, char *argv[]);
3232

33+
int TPM2_Wrapper_Caps(void* userCtx);
34+
int TPM2_Wrapper_CapsArgs(void* userCtx, int argc, char *argv[]);
35+
3336
#ifdef __cplusplus
3437
} /* extern "C" */
3538
#endif

0 commit comments

Comments
 (0)