Skip to content

Commit 2044ad9

Browse files
Added GCM functions
1 parent c6b176e commit 2044ad9

File tree

907 files changed

+47026
-35656
lines changed

Some content is hidden

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

907 files changed

+47026
-35656
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ Examples
6060

6161
Release notes
6262
-----------
63+
01/04/2019
64+
- Added GCM functions
65+
- Split AES modes into separate files
66+
- Bug fix in SWI START driver
67+
6368
10/25/2018
6469
- Added basic certificate functions to the python wrapper.
6570
- Added Espressif ESP32 I2C driver.

app/ip_protection/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
IP Protection with Symmetric Authentication
2+
------------------------
3+
The IP protection can be easily integrated to the existing projects.The user project should include symmetric_authentication.c & symmetric_authentication.h files which contains the api
4+
- **symmetric_authenticate()** - For Performing the authentication between host & device.
5+
6+
User Considerations
7+
-----------
8+
- The user should take care on how the master key should be stored on the MCU side.
9+
- The api's in the file doesn't do the provisioning of the chip and user should take care of the provisioning.
10+
11+
With the provisioned cryptoauthentication device and after doing the cryptoauthlib initialisation,user should only be calling the function symmetric_authenticate() with its necessary parameters for the authentication. The returned authentication status should be used in the application.
12+
13+
Examples
14+
-----------
15+
For more information about IP protection and its example project refer [Microchip github](https://github.com/MicrochipTech)
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/**
2+
* \file
3+
* \brief Contains API for performing the symmetric Authentication between the Host and the device
4+
*
5+
* \copyright (c) 2015-2018 Microchip Technology Inc. and its subsidiaries.
6+
*
7+
* \page License
8+
*
9+
* Subject to your compliance with these terms, you may use Microchip software
10+
* and any derivatives exclusively with Microchip products. It is your
11+
* responsibility to comply with third party license terms applicable to your
12+
* use of third party software (including open source software) that may
13+
* accompany Microchip software.
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. IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT,
19+
* SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE
20+
* OF ANY KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
21+
* MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
22+
* FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL
23+
* LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED
24+
* THE AMOUNT OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR
25+
* THIS SOFTWARE.
26+
*/
27+
28+
29+
#include "cryptoauthlib.h"
30+
#include "host/atca_host.h"
31+
#include "symmetric_authentication.h"
32+
33+
34+
35+
36+
/** \brief Function which does the authentication between the host and device.
37+
* \param[in] slot The slot number used for the symmetric authentication.
38+
* \param[in] master_key The master key used for the calculating the symmetric key.
39+
* \param[in] rand_number The 20 byte rand_number from the host.
40+
* \return ATCA_SUCCESS on successful authentication, otherwise an error code.
41+
*/
42+
43+
ATCA_STATUS symmetric_authenticate(uint8_t slot, const uint8_t *master_key, const uint8_t *rand_number)
44+
{
45+
ATCA_STATUS status;
46+
uint8_t sn[ATCA_SERIAL_NUM_SIZE];
47+
uint8_t symmetric_key[ATCA_KEY_SIZE];
48+
atca_temp_key_t temp_key, temp_key_derive;
49+
uint8_t rand_out[RANDOM_NUM_SIZE];
50+
atca_nonce_in_out_t nonce_params;
51+
atca_mac_in_out_t mac_params;
52+
uint8_t host_mac[MAC_SIZE];
53+
uint8_t device_mac[MAC_SIZE];
54+
struct atca_derive_key_in_out derivekey_params;
55+
56+
do
57+
{
58+
// Read serial number for host-side MAC calculations
59+
if ((status = atcab_read_serial_number(sn)) != ATCA_SUCCESS)
60+
{
61+
break;
62+
}
63+
64+
// Setup nonce command
65+
memset(&temp_key, 0, sizeof(temp_key));
66+
memset(&nonce_params, 0, sizeof(nonce_params));
67+
nonce_params.mode = NONCE_MODE_SEED_UPDATE;
68+
nonce_params.zero = 0;
69+
nonce_params.num_in = rand_number;
70+
nonce_params.rand_out = rand_out;
71+
nonce_params.temp_key = &temp_key;
72+
73+
// Create random nonce
74+
if ((status = atcab_nonce_rand(nonce_params.num_in, rand_out)) != ATCA_SUCCESS)
75+
{
76+
break;
77+
}
78+
79+
// Calculate nonce in host
80+
if ((status = atcah_nonce(&nonce_params)) != ATCA_SUCCESS)
81+
{
82+
break;
83+
}
84+
85+
memset(&temp_key_derive, 0, sizeof(temp_key_derive));
86+
temp_key_derive.valid = 1;
87+
memcpy(temp_key_derive.value, sn, sizeof(sn)); // 32 bytes TempKey ( SN[0:8] with padded 23 zeros used in symmetric key calculation)
88+
89+
// Parameters used deriving the symmetric key
90+
derivekey_params.mode = 0;
91+
derivekey_params.target_key_id = slot;
92+
derivekey_params.parent_key = master_key;
93+
derivekey_params.sn = sn;
94+
derivekey_params.target_key = symmetric_key;
95+
derivekey_params.temp_key = &temp_key_derive;
96+
97+
// calculate the symmetric_diversified_key
98+
if ((status = atcah_derive_key(&derivekey_params)) != ATCA_SUCCESS)
99+
{
100+
break;
101+
}
102+
103+
// Setup MAC command
104+
memset(&mac_params, 0, sizeof(mac_params));
105+
mac_params.mode = MAC_MODE_BLOCK2_TEMPKEY | MAC_MODE_INCLUDE_SN; // Block 1 is a key, block 2 is TempKey
106+
mac_params.key_id = slot;
107+
mac_params.challenge = NULL;
108+
mac_params.key = symmetric_key;
109+
mac_params.otp = NULL;
110+
mac_params.sn = sn;
111+
mac_params.response = host_mac;
112+
mac_params.temp_key = &temp_key;
113+
114+
// Generate the MAC command from the device
115+
if ((status = atcab_mac(mac_params.mode, mac_params.key_id, mac_params.challenge, device_mac)) != ATCA_SUCCESS)
116+
{
117+
break;
118+
}
119+
120+
// Calculate the MAC on the host side
121+
if (( status = atcah_mac(&mac_params)) != ATCA_SUCCESS)
122+
{
123+
break;
124+
}
125+
126+
//Check whether the MAC calculated on host is same as that generated from the device
127+
if (memcmp(device_mac, host_mac, 32) != 0)
128+
{
129+
status = ATCA_CHECKMAC_VERIFY_FAILED;
130+
}
131+
132+
}
133+
while (0);
134+
135+
return status;
136+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* \file
3+
* \brief Contains API for performing the symmetric Authentication between the Host and the device
4+
*
5+
* \copyright (c) 2015-2018 Microchip Technology Inc. and its subsidiaries.
6+
*
7+
* \page License
8+
*
9+
* Subject to your compliance with these terms, you may use Microchip software
10+
* and any derivatives exclusively with Microchip products. It is your
11+
* responsibility to comply with third party license terms applicable to your
12+
* use of third party software (including open source software) that may
13+
* accompany Microchip software.
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. IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT,
19+
* SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE
20+
* OF ANY KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
21+
* MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
22+
* FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL
23+
* LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED
24+
* THE AMOUNT OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR
25+
* THIS SOFTWARE.
26+
*/
27+
28+
29+
#ifndef SYMMETRIC_AUTHENTICATION_H_
30+
#define SYMMETRIC_AUTHENTICATION_H_
31+
32+
#include "cryptoauthlib.h"
33+
34+
#ifdef __cplusplus
35+
extern "C" {
36+
#endif
37+
38+
ATCA_STATUS symmetric_authenticate(uint8_t slot, const uint8_t *master_key, const uint8_t *rand_number);
39+
40+
41+
42+
#ifdef __cplusplus
43+
}
44+
#endif
45+
46+
47+
#endif /* SYMMETRIC_AUTHENTICATION_H_ */

docs/html/a00011.html

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
66
<meta name="generator" content="Doxygen 1.8.14"/>
77
<meta name="viewport" content="width=device-width, initial-scale=1"/>
8-
<title>CryptoAuthLib: crypto_device_app.c File Reference</title>
8+
<title>CryptoAuthLib: symmetric_authentication.c File Reference</title>
99
<link href="tabs.css" rel="stylesheet" type="text/css"/>
1010
<script type="text/javascript" src="jquery.js"></script>
1111
<script type="text/javascript" src="dynsections.js"></script>
@@ -89,47 +89,68 @@
8989
<div class="summary">
9090
<a href="#func-members">Functions</a> </div>
9191
<div class="headertitle">
92-
<div class="title">crypto_device_app.c File Reference</div> </div>
92+
<div class="title">symmetric_authentication.c File Reference</div> </div>
9393
</div><!--header-->
9494
<div class="contents">
9595

96-
<p>Provides required interface between boot loader and secure boot.
96+
<p>Contains API for performing the symmetric Authentication between the Host and the device.
9797
<a href="#details">More...</a></p>
98-
<div class="textblock"><code>#include &lt;stdlib.h&gt;</code><br />
99-
<code>#include &lt;stdio.h&gt;</code><br />
100-
<code>#include &quot;<a class="el" href="a00299_source.html">cryptoauthlib.h</a>&quot;</code><br />
101-
<code>#include &quot;<a class="el" href="a00023_source.html">secure_boot.h</a>&quot;</code><br />
102-
<code>#include &quot;<a class="el" href="a00017_source.html">io_protection_key.h</a>&quot;</code><br />
103-
<code>#include &quot;<a class="el" href="a00014_source.html">crypto_device_app.h</a>&quot;</code><br />
98+
<div class="textblock"><code>#include &quot;<a class="el" href="a00320_source.html">cryptoauthlib.h</a>&quot;</code><br />
99+
<code>#include &quot;<a class="el" href="a00545_source.html">host/atca_host.h</a>&quot;</code><br />
100+
<code>#include &quot;<a class="el" href="a00014_source.html">symmetric_authentication.h</a>&quot;</code><br />
104101
</div><table class="memberdecls">
105102
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
106103
Functions</h2></td></tr>
107-
<tr class="memitem:a19617ea9c26833614201b9695ec7a1ca"><td class="memItemLeft" align="right" valign="top"><a class="el" href="a00128.html#a22bd6643f31f1d75dc3e7ea939f468cd">ATCA_STATUS</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00011.html#a19617ea9c26833614201b9695ec7a1ca">crypto_device_verify_app</a> (void)</td></tr>
108-
<tr class="memdesc:a19617ea9c26833614201b9695ec7a1ca"><td class="mdescLeft">&#160;</td><td class="mdescRight">Takes care interface with secure boot and provides status about user application. This also takes care of device configuration if enabled. <a href="#a19617ea9c26833614201b9695ec7a1ca">More...</a><br /></td></tr>
109-
<tr class="separator:a19617ea9c26833614201b9695ec7a1ca"><td class="memSeparator" colspan="2">&#160;</td></tr>
104+
<tr class="memitem:a9a41d1600ffd22de067ded50447d359b"><td class="memItemLeft" align="right" valign="top"><a class="el" href="a00134.html#a22bd6643f31f1d75dc3e7ea939f468cd">ATCA_STATUS</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00011.html#a9a41d1600ffd22de067ded50447d359b">symmetric_authenticate</a> (uint8_t slot, const uint8_t *master_key, const uint8_t *rand_number)</td></tr>
105+
<tr class="memdesc:a9a41d1600ffd22de067ded50447d359b"><td class="mdescLeft">&#160;</td><td class="mdescRight">Function which does the authentication between the host and device. <a href="#a9a41d1600ffd22de067ded50447d359b">More...</a><br /></td></tr>
106+
<tr class="separator:a9a41d1600ffd22de067ded50447d359b"><td class="memSeparator" colspan="2">&#160;</td></tr>
110107
</table>
111108
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
112-
<div class="textblock"><p>Provides required interface between boot loader and secure boot. </p>
109+
<div class="textblock"><p>Contains API for performing the symmetric Authentication between the Host and the device. </p>
113110
<dl class="section copyright"><dt>Copyright</dt><dd>(c) 2015-2018 Microchip Technology Inc. and its subsidiaries. </dd></dl>
114111
</div><h2 class="groupheader">Function Documentation</h2>
115-
<a id="a19617ea9c26833614201b9695ec7a1ca"></a>
116-
<h2 class="memtitle"><span class="permalink"><a href="#a19617ea9c26833614201b9695ec7a1ca">&#9670;&nbsp;</a></span>crypto_device_verify_app()</h2>
112+
<a id="a9a41d1600ffd22de067ded50447d359b"></a>
113+
<h2 class="memtitle"><span class="permalink"><a href="#a9a41d1600ffd22de067ded50447d359b">&#9670;&nbsp;</a></span>symmetric_authenticate()</h2>
117114

118115
<div class="memitem">
119116
<div class="memproto">
120117
<table class="memname">
121118
<tr>
122-
<td class="memname"><a class="el" href="a00128.html#a22bd6643f31f1d75dc3e7ea939f468cd">ATCA_STATUS</a> crypto_device_verify_app </td>
119+
<td class="memname"><a class="el" href="a00134.html#a22bd6643f31f1d75dc3e7ea939f468cd">ATCA_STATUS</a> symmetric_authenticate </td>
123120
<td>(</td>
124-
<td class="paramtype">void&#160;</td>
125-
<td class="paramname"></td><td>)</td>
121+
<td class="paramtype">uint8_t&#160;</td>
122+
<td class="paramname"><em>slot</em>, </td>
123+
</tr>
124+
<tr>
125+
<td class="paramkey"></td>
126+
<td></td>
127+
<td class="paramtype">const uint8_t *&#160;</td>
128+
<td class="paramname"><em>master_key</em>, </td>
129+
</tr>
130+
<tr>
131+
<td class="paramkey"></td>
132+
<td></td>
133+
<td class="paramtype">const uint8_t *&#160;</td>
134+
<td class="paramname"><em>rand_number</em>&#160;</td>
135+
</tr>
136+
<tr>
126137
<td></td>
138+
<td>)</td>
139+
<td></td><td></td>
127140
</tr>
128141
</table>
129142
</div><div class="memdoc">
130143

131-
<p>Takes care interface with secure boot and provides status about user application. This also takes care of device configuration if enabled. </p>
132-
<dl class="section return"><dt>Returns</dt><dd>ATCA_SUCCESS on success, otherwise an error code. </dd></dl>
144+
<p>Function which does the authentication between the host and device. </p>
145+
<dl class="params"><dt>Parameters</dt><dd>
146+
<table class="params">
147+
<tr><td class="paramdir">[in]</td><td class="paramname">slot</td><td>The slot number used for the symmetric authentication. </td></tr>
148+
<tr><td class="paramdir">[in]</td><td class="paramname">master_key</td><td>The master key used for the calculating the symmetric key. </td></tr>
149+
<tr><td class="paramdir">[in]</td><td class="paramname">rand_number</td><td>The 20 byte rand_number from the host. </td></tr>
150+
</table>
151+
</dd>
152+
</dl>
153+
<dl class="section return"><dt>Returns</dt><dd>ATCA_SUCCESS on successful authentication, otherwise an error code. </dd></dl>
133154

134155
</div>
135156
</div>
@@ -138,7 +159,7 @@ <h2 class="memtitle"><span class="permalink"><a href="#a19617ea9c26833614201b969
138159
<!-- start footer part -->
139160
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
140161
<ul>
141-
<li class="navelem"><a class="el" href="dir_d422163b96683743ed3963d4aac17747.html">app</a></li><li class="navelem"><a class="el" href="dir_0680cb466dcc0d680630f5d267d4b7d1.html">secure_boot</a></li><li class="navelem"><a class="el" href="a00011.html">crypto_device_app.c</a></li>
162+
<li class="navelem"><a class="el" href="dir_d422163b96683743ed3963d4aac17747.html">app</a></li><li class="navelem"><a class="el" href="dir_87abda79916a436a3f9fdf465608c5f5.html">ip_protection</a></li><li class="navelem"><a class="el" href="a00011.html">symmetric_authentication.c</a></li>
142163
<li class="footer">Generated by
143164
<a href="http://www.doxygen.org/index.html">
144165
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.14 </li>

docs/html/a00011.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
var a00011 =
22
[
3-
[ "crypto_device_verify_app", "a00011.html#a19617ea9c26833614201b9695ec7a1ca", null ]
3+
[ "symmetric_authenticate", "a00011.html#a9a41d1600ffd22de067ded50447d359b", null ]
44
];

0 commit comments

Comments
 (0)