|
21 | 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA |
22 | 22 | */ |
23 | 23 |
|
24 | | -#include <stdio.h> |
25 | | -#include <stdlib.h> |
26 | 24 | #include <stdint.h> |
27 | | -#include <string.h> |
28 | 25 | #include "system.h" |
29 | 26 | #include "hal.h" |
30 | 27 | #include "uart_drv.h" |
|
33 | 30 | #include "target.h" |
34 | 31 |
|
35 | 32 | #ifdef SECURE_PKCS11 |
| 33 | +#include "test_pkcs11.h" |
36 | 34 | #include "wcs/user_settings.h" |
37 | 35 | #include <wolfssl/wolfcrypt/settings.h> |
38 | | -#include <wolfssl/wolfcrypt/wc_pkcs11.h> |
39 | | -#include <wolfssl/wolfcrypt/random.h> |
40 | | -extern const char pkcs11_library_name[]; |
41 | | -extern const CK_FUNCTION_LIST wolfpkcs11nsFunctionList; |
42 | 36 | #endif |
43 | 37 |
|
44 | 38 | #define LED_BOOT_PIN (9) /* PA9 - Nucleo - Red Led */ |
@@ -134,84 +128,15 @@ void extra_led_off(void) |
134 | 128 | GPIOB_BSRR |= (1 << (LED_EXTRA_PIN + 16)); |
135 | 129 | } |
136 | 130 |
|
137 | | - |
138 | | -extern int ecdsa_sign_verify(int devId); |
139 | | - |
140 | | - |
141 | 131 | void main(void) |
142 | 132 | { |
143 | | - int ret; |
144 | | - uint32_t rand; |
145 | | - uint32_t i; |
146 | | - uint32_t klen = 200; |
147 | | - int otherkey_slot; |
148 | | - unsigned int devId = 0; |
149 | | - |
150 | 133 | #ifdef SECURE_PKCS11 |
151 | | - WC_RNG rng; |
152 | | - Pkcs11Token token; |
153 | | - Pkcs11Dev PKCS11_d; |
154 | | - unsigned long session; |
155 | | - char TokenPin[] = "0123456789ABCDEF"; |
156 | | - char UserPin[] = "ABCDEF0123456789"; |
157 | | - char SoPinName[] = "SO-PIN"; |
| 134 | + int ret; |
158 | 135 |
|
159 | 136 | boot_led_on(); |
160 | | - |
161 | | - wolfCrypt_Init(); |
162 | | - |
163 | | - PKCS11_d.heap = NULL, |
164 | | - PKCS11_d.func = (CK_FUNCTION_LIST *)&wolfpkcs11nsFunctionList; |
165 | | - |
166 | | - ret = wc_Pkcs11Token_Init(&token, &PKCS11_d, 1, "EccKey", |
167 | | - (const byte*)TokenPin, strlen(TokenPin)); |
168 | | - |
169 | | - if (ret == 0) { |
170 | | - ret = wolfpkcs11nsFunctionList.C_OpenSession(1, |
171 | | - CKF_SERIAL_SESSION | CKF_RW_SESSION, |
172 | | - NULL, NULL, &session); |
173 | | - } |
174 | | - if (ret == 0) { |
175 | | - ret = wolfpkcs11nsFunctionList.C_InitToken(1, |
176 | | - (byte *)TokenPin, strlen(TokenPin), (byte *)SoPinName); |
177 | | - } |
178 | | - |
179 | | - if (ret == 0) { |
180 | | - extra_led_on(); |
181 | | - ret = wolfpkcs11nsFunctionList.C_Login(session, CKU_SO, |
182 | | - (byte *)TokenPin, |
183 | | - strlen(TokenPin)); |
184 | | - } |
185 | | - if (ret == 0) { |
186 | | - ret = wolfpkcs11nsFunctionList.C_InitPIN(session, |
187 | | - (byte *)TokenPin, |
188 | | - strlen(TokenPin)); |
189 | | - } |
190 | | - if (ret == 0) { |
191 | | - ret = wolfpkcs11nsFunctionList.C_Logout(session); |
192 | | - } |
193 | | - if (ret != 0) { |
194 | | - while(1) |
195 | | - ; |
196 | | - } |
197 | | - if (ret == 0) { |
198 | | - ret = wc_CryptoDev_RegisterDevice(devId, wc_Pkcs11_CryptoDevCb, |
199 | | - &token); |
200 | | - if (ret != 0) { |
201 | | - while(1) |
202 | | - ; |
203 | | - } |
204 | | - if (ret == 0) { |
205 | | -#ifdef HAVE_ECC |
206 | | - ret = ecdsa_sign_verify(devId); |
207 | | - if (ret != 0) |
208 | | - ret = 1; |
209 | | - else |
210 | | - usr_led_on(); |
211 | | -#endif |
212 | | - } |
213 | | - wc_Pkcs11Token_Final(&token); |
214 | | - } |
| 137 | + ret = test_pkcs11_start(); |
| 138 | + if (ret != PKCS11_TEST_FAIL) |
| 139 | + usr_led_on(); |
215 | 140 | #endif |
216 | 141 | while(1) |
217 | 142 | ; |
|
0 commit comments