Skip to content

Commit fdf5ba6

Browse files
Release 4 - 20180329: Added command polling
1 parent c6da335 commit fdf5ba6

File tree

976 files changed

+42465
-52491
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

976 files changed

+42465
-52491
lines changed

README.md

+14-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CryptoAuthLib - Microchip CryptoAuthentication Library {#mainpage}
1+
CryptoAuthLib - Microchip CryptoAuthentication Library
22
====================================================
33

44
Introduction
@@ -46,6 +46,15 @@ Examples
4646

4747
Release notes
4848
-----------
49+
03/29/2018
50+
- Added support for response polling by default, which will make commands.
51+
return faster (define ATCA_NO_POLL to use old delay method).
52+
- Removed atcatls related files as they were of limited value.
53+
- Test framework generates a prompt before locking test configuration.
54+
- Test framework puts device to sleep between tests.
55+
- Fixed mode parameter issue in atcah_gen_key_msg().
56+
- ATECC608A health test error code added.
57+
4958
01/15/2018
5059
- Added AES-128 CBC implementation using AES command
5160
- Added AES-128 CMAC implementation using AES command
@@ -175,7 +184,7 @@ The library is structured to support portability to:
175184
All platform dependencies are contained within the HAL (hardware abstraction
176185
layer).
177186

178-
![CryptoAuthLib Architecture](../CryptoAuthLib-Architecture.png "CryptoAuthLib Architecture" )
187+
![CryptoAuthLib Architecture](./docs/CryptoAuthLib-Architecture.png "CryptoAuthLib Architecture" )
179188

180189
There are three primary object types in CryptoAuthLib:
181190
- Device (ATCADevice)
@@ -184,9 +193,9 @@ There are three primary object types in CryptoAuthLib:
184193

185194
ATCADevice is a composite object made up of ATCACommand ATCAIface.
186195

187-
![ATCADevice](../cryptoauthlib-uml/ATCADevice.png "ATCADevice and ATCACommand object" )
188-
![ATCAIface](../cryptoauthlib-uml/ATCAIFace.png "ATCAIface object" )
189-
![Hardware abstraction layer](../cryptoauthlib-uml/ATCAHal.png "CryptoAuth hardware abstraction layer" )
196+
![ATCADevice](./docs/cryptoauthlib-uml/ATCADevice.png "ATCADevice and ATCACommand object" )
197+
![ATCAIface](./docs/cryptoauthlib-uml/ATCAIFace.png "ATCAIface object" )
198+
![Hardware abstraction layer](./docs/cryptoauthlib-uml/ATCAHal.png "CryptoAuth hardware abstraction layer" )
190199

191200
Currently, the vast majority of testing has been performed on:
192201

app/secure_boot/crypto_device_app.c

+217
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
/**
2+
* \file
3+
*
4+
* \brief Provides required interface between boot loader and secure boot.
5+
*
6+
* \copyright (c) 2017 Microchip Technology Inc. and its subsidiaries.
7+
* You may use this software and any derivatives exclusively with
8+
* Microchip products.
9+
*
10+
* \page License
11+
*
12+
* (c) 2017 Microchip Technology Inc. and its subsidiaries. You may use this
13+
* software and any derivatives exclusively with Microchip products.
14+
*
15+
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
16+
* EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
17+
* WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
18+
* PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
19+
* WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
20+
*
21+
* IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
22+
* INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
23+
* WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
24+
* BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
25+
* FULLEST EXTENT ALLOWED BY LAW, MICROCHIPS TOTAL LIABILITY ON ALL CLAIMS IN
26+
* ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
27+
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
28+
*
29+
* MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
30+
* TERMS.
31+
*/
32+
#include <stdlib.h>
33+
#include <stdio.h>
34+
#include "cryptoauthlib.h"
35+
#include "secure_boot.h"
36+
#include "io_protection_key.h"
37+
#include "crypto_device_app.h"
38+
39+
/** \brief Takes care interface with secure boot and provides status about user
40+
* application. This also takes care of device configuration if enabled.
41+
* \return ATCA_SUCCESS on success, otherwise an error code.
42+
*/
43+
ATCA_STATUS crypto_device_verify_app(void)
44+
{
45+
ATCA_STATUS status = ATCA_SUCCESS;
46+
/*Creating interface instance for 608A*/
47+
ATCAIfaceCfg cfg_atecc608a_i2c_default = {
48+
.iface_type = ATCA_I2C_IFACE,
49+
.devtype = ATECC608A,
50+
.atcai2c.slave_address = 0xC0,
51+
.atcai2c.bus = 2,
52+
.atcai2c.baud = 400000,
53+
//.atcai2c.baud = 100000,
54+
.wake_delay = 1500,
55+
.rx_retries = 20
56+
};
57+
58+
do
59+
{
60+
#if CRYPTO_DEVICE_ENABLE_SECURE_BOOT
61+
bool is_locked;
62+
63+
/*Initialize interface on enabling any crypto operation */
64+
if ((status = atcab_init(&cfg_atecc608a_i2c_default)) != ATCA_SUCCESS)
65+
{
66+
break;
67+
}
68+
69+
/*Check current status of Public Key Slot lock status */
70+
if ((status = atcab_is_slot_locked(SECURE_BOOT_PUBLIC_KEY_SLOT, &is_locked)) != ATCA_SUCCESS)
71+
{
72+
break;
73+
}
74+
75+
/*Before doing secure boot it is expected configuration zone is locked */
76+
if (!is_locked)
77+
{
78+
/*Trigger crypto device configuration */
79+
#if CRYPTO_DEVICE_LOAD_CONFIG_ENABLED
80+
if ((status = crypto_device_load_configuration()) != ATCA_SUCCESS)
81+
{
82+
break;
83+
}
84+
#else
85+
status = ATCA_GEN_FAIL;
86+
break;
87+
#endif
88+
}
89+
90+
/*Initiate secure boot operation */
91+
if ((status = secure_boot_process()) != ATCA_SUCCESS)
92+
{
93+
break;
94+
}
95+
#endif //CRYPTO_DEVICE_ENABLE_SECURE_BOOT
96+
97+
}
98+
while (0);
99+
100+
101+
return status;
102+
}
103+
104+
#if CRYPTO_DEVICE_LOAD_CONFIG_ENABLED
105+
/** \brief Checks whether configuration is locked or not. if not, it writes
106+
* default configuration to device and locks it.
107+
* \return ATCA_SUCCESS on success, otherwise an error code.
108+
*/
109+
ATCA_STATUS crypto_device_load_configuration(void)
110+
{
111+
ATCA_STATUS status;
112+
bool is_locked = false;
113+
114+
uint8_t test_ecc608_configdata[ATCA_ECC_CONFIG_SIZE] = {
115+
0x01, 0x23, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x04, 0x05, 0x06, 0x07, 0xEE, 0x01, 0x01, 0x00, //15
116+
0xC0, 0x00, 0xA1, 0x00, 0xAF, 0x2F, 0xC4, 0x44, 0x87, 0x20, 0xC4, 0xF4, 0x8F, 0x0F, 0x0F, 0x0F, //31, 5
117+
0x9F, 0x8F, 0x83, 0x64, 0xC4, 0x44, 0xC4, 0x64, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, //47
118+
0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, //63
119+
0x00, 0x00, 0x00, 0x00, 0xFF, 0x84, 0x03, 0xBC, 0x09, 0x69, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, //79
120+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x06, 0x40, 0x00, 0x00, 0x00, 0x00, //95
121+
0x33, 0x00, 0x1C, 0x00, 0x13, 0x00, 0x1C, 0x00, 0x3C, 0x00, 0x3E, 0x00, 0x1C, 0x00, 0x33, 0x00, //111
122+
0x1C, 0x00, 0x1C, 0x00, 0x38, 0x10, 0x30, 0x00, 0x3C, 0x00, 0x3C, 0x00, 0x32, 0x00, 0x30, 0x00 //127
123+
};
124+
125+
uint8_t public_key_slot_data[72];
126+
uint8_t public_key_read[ATCA_PUB_KEY_SIZE];
127+
uint8_t public_key[] = {
128+
0x21, 0x67, 0x64, 0x1c, 0x9f, 0xc4, 0x13, 0x6c, 0xb4, 0xa9, 0x1a, 0x4f, 0x56, 0xd4, 0x8b, 0x83,
129+
0x76, 0x9e, 0x3a, 0xd8, 0x1e, 0x0e, 0x01, 0xb7, 0x59, 0xc7, 0xc7, 0x94, 0x74, 0x3f, 0x1a, 0xa6,
130+
0x30, 0xcc, 0xb7, 0xec, 0xfc, 0xa8, 0x2e, 0xf0, 0x5b, 0xa1, 0x3d, 0x5b, 0x34, 0x53, 0x11, 0x18,
131+
0xa0, 0x67, 0x73, 0x7b, 0xdb, 0x1e, 0x3d, 0x1b, 0xbc, 0xdd, 0x10, 0x5a, 0x39, 0x23, 0x25, 0x3e
132+
};
133+
134+
do
135+
{
136+
/*Check current status of configuration lock status */
137+
if ((status = atcab_is_locked(LOCK_ZONE_CONFIG, &is_locked)) != ATCA_SUCCESS)
138+
{
139+
break;
140+
}
141+
142+
/*Write configuration if it is not already locked */
143+
if (!is_locked)
144+
{
145+
/*Trigger Configuration write... ignore first 16 bytes*/
146+
if ((status = atcab_write_bytes_zone(ATCA_ZONE_CONFIG, 0, 16, &test_ecc608_configdata[16], (sizeof(test_ecc608_configdata) - 16))) != ATCA_SUCCESS)
147+
{
148+
break;
149+
}
150+
151+
/*Lock Configuration Zone on completing configuration*/
152+
if ((status = atcab_lock(LOCK_ZONE_NO_CRC | LOCK_ZONE_CONFIG, 0)) != ATCA_SUCCESS)
153+
{
154+
break;
155+
}
156+
}
157+
158+
/*Check current status of Public Key Slot lock status */
159+
if ((status = atcab_is_slot_locked(SECURE_BOOT_PUBLIC_KEY_SLOT, &is_locked)) != ATCA_SUCCESS)
160+
{
161+
break;
162+
}
163+
164+
/*Write Slot Data, if it is not already locked */
165+
if (!is_locked)
166+
{
167+
/*Check current status of Data zone lock status */
168+
if ((status = atcab_is_locked(LOCK_ZONE_DATA, &is_locked)) != ATCA_SUCCESS)
169+
{
170+
break;
171+
}
172+
173+
if (!is_locked)
174+
{
175+
/*Lock Data Zone if it is not */
176+
if ((status = atcab_lock(LOCK_ZONE_NO_CRC | LOCK_ZONE_DATA, 0)) != ATCA_SUCCESS)
177+
{
178+
break;
179+
}
180+
}
181+
182+
/*Write Pub Key to Slot... Reformat public key into padded format */
183+
memmove(&public_key_slot_data[40], &public_key[32], 32); // Move Y to padded position
184+
memset(&public_key_slot_data[36], 0, 4); // Add Y padding bytes
185+
memmove(&public_key_slot_data[4], &public_key[0], 32); // Move X to padded position
186+
memset(&public_key_slot_data[0], 0, 4); // Add X padding bytes
187+
188+
/*Write Public Key to SecureBootPubKey slot*/
189+
if ((status = atcab_write_bytes_zone(ATCA_ZONE_DATA, SECURE_BOOT_PUBLIC_KEY_SLOT, 0, public_key_slot_data, 72)) != ATCA_SUCCESS)
190+
{
191+
break;
192+
}
193+
194+
/*Read Public Key*/
195+
if ((status = atcab_read_pubkey(SECURE_BOOT_PUBLIC_KEY_SLOT, public_key_read)) != ATCA_SUCCESS)
196+
{
197+
break;
198+
}
199+
200+
if ((status = memcmp(public_key, public_key_read, sizeof(public_key_read))) != ATCA_SUCCESS)
201+
{
202+
break;
203+
}
204+
205+
/*Lock IO protection key slot */
206+
if ((status = atcab_lock_data_slot(SECURE_BOOT_PUBLIC_KEY_SLOT)) != ATCA_SUCCESS)
207+
{
208+
break;
209+
}
210+
}
211+
}
212+
while (0);
213+
214+
return status;
215+
}
216+
#endif //#if CRYPTO_DEVICE_CONFIG_ENABLED
217+
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/**
22
* \file
33
*
4+
* \brief Provides required interface between boot loader and secure boot.
5+
*
46
* \copyright (c) 2017 Microchip Technology Inc. and its subsidiaries.
57
* You may use this software and any derivatives exclusively with
68
* Microchip products.
@@ -28,41 +30,31 @@
2830
* TERMS.
2931
*/
3032

33+
#ifndef CRYPTO_DEVICE_CONFIG_H
34+
#define CRYPTO_DEVICE_CONFIG_H
3135

32-
#ifndef ATCA_TLS_TESTS_H_
33-
#define ATCA_TLS_TESTS_H_
34-
36+
#ifdef __cplusplus
37+
extern "C" {
38+
#endif
3539

36-
#include "test/unity.h"
40+
#include "atca_status.h"
41+
#include "atca_command.h"
42+
#include "host/atca_host.h"
3743

38-
void atcatls_test_runner(ATCAIfaceCfg* pCfg);
44+
#define CRYPTO_DEVICE_ENABLE_SECURE_BOOT true
45+
#define CRYPTO_DEVICE_LOAD_CONFIG_ENABLED false
46+
#define IO_PROTECTION_KEY_SLOT 4
47+
#define SECURE_BOOT_PUBLIC_KEY_SLOT 11
48+
#define SECURE_BOOT_SIGN_DIGEST_SLOT 12
3949

40-
// TLS API Init/finish
41-
void test_atcatls_config_default(void);
42-
void test_atcatls_init_finish(void);
50+
ATCA_STATUS crypto_device_verify_app(void);
51+
ATCA_STATUS crypto_device_load_configuration(void);
4352

44-
// Core TLS definitions
45-
void test_atcatls_create_key(void);
46-
void test_atcatls_sign(void);
47-
void test_atcatls_verify(void);
48-
void test_atcatls_ecdh(void);
49-
void test_atcatls_ecdhe(void);
50-
void test_atcatls_calc_pubkey(void);
51-
void test_atcatls_read_pubkey(void);
52-
void test_atcatls_random(void);
53-
void test_atcatls_get_sn(void);
53+
#ifdef __cplusplus
54+
}
55+
#endif
5456

55-
// Certificate Handling
56-
void test_atcatls_verify_cert_chain(void);
57-
void test_atcatls_verify_default_certs(void);
58-
void test_atcatls_ca_pubkey_write_read(void);
59-
void test_atcatls_get_ca_cert(void);
60-
void test_atcatls_create_csr(void);
57+
#endif
6158

62-
// Encrypted Read/Write
63-
void test_atcatls_init_enc_key(void);
64-
void test_atcatls_enc_write_read(void);
65-
void test_atcatls_enc_rsakey_write_read(void);
6659

6760

68-
#endif /* ATCA_TLS_TESTS_H_ */

app/secure_boot/io_protection_key.h

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* \file
3+
*
4+
* \brief Provides required interface to access IO protection key.
5+
*
6+
* \copyright (c) 2017 Microchip Technology Inc. and its subsidiaries.
7+
* You may use this software and any derivatives exclusively with
8+
* Microchip products.
9+
*
10+
* \page License
11+
*
12+
* (c) 2017 Microchip Technology Inc. and its subsidiaries. You may use this
13+
* software and any derivatives exclusively with Microchip products.
14+
*
15+
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
16+
* EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
17+
* WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
18+
* PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
19+
* WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
20+
*
21+
* IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
22+
* INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
23+
* WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
24+
* BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
25+
* FULLEST EXTENT ALLOWED BY LAW, MICROCHIPS TOTAL LIABILITY ON ALL CLAIMS IN
26+
* ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
27+
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
28+
*
29+
* MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
30+
* TERMS.
31+
*/
32+
33+
#ifndef IO_PROTECTION_H
34+
#define IO_PROTECTION_H
35+
36+
#ifdef __cplusplus
37+
extern "C" {
38+
#endif
39+
40+
#include "atca_status.h"
41+
42+
extern ATCA_STATUS io_protection_get_key(uint8_t* io_key);
43+
extern ATCA_STATUS io_protection_set_key(uint8_t* io_key);
44+
45+
#ifdef __cplusplus
46+
}
47+
#endif
48+
/** @} */
49+
#endif
50+
51+
52+

0 commit comments

Comments
 (0)