Skip to content

Commit bca4e13

Browse files
committed
Adding HMAC and nonce example
1 parent a36a841 commit bca4e13

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

examples/ECCX08HMAC/ECCX08HMAC.ino

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
ECCX08 HMAC functionality example
3+
4+
This sketch uses the ECC608 to generate an hmac on some data.
5+
Stores key using nonce.
6+
7+
Used the Arduino Nano RP2040.
8+
9+
created 10 October 2022
10+
by Raul Leclair
11+
*/
12+
13+
#include <ArduinoECCX08.h>
14+
15+
byte nonceKey[] = {
16+
0x10, 0x10, 0x10, 0x10
17+
};
18+
byte data[] = {
19+
0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
20+
0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
21+
0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
22+
0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
23+
0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
24+
0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
25+
0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10
26+
};
27+
int dataLength = 56;
28+
29+
void setup() {
30+
Serial.begin(115200);
31+
while (!Serial);
32+
33+
if (!ECCX08.begin()) {
34+
Serial.println("Failed to initialize ECC608 board.");
35+
while (1);
36+
}
37+
38+
// Perform nonce
39+
if (!ECCX08.nonce(nonceKey))
40+
{
41+
Serial.println("Failed to do nonce.");
42+
while (1);
43+
}
44+
45+
// Starting HMAC operation on tempkey slot
46+
if (!ECCX08.beginHMAC(0xFFFF)) {
47+
Serial.println("Failed to start HMAC operation.");
48+
while (1);
49+
}
50+
51+
if (!ECCX08.updateHMAC(data, dataLength)) {
52+
Serial.println("Failed to update HMAC operation.");
53+
while (1);
54+
}
55+
56+
byte resultHMAC[32];
57+
if (!ECCX08.endHMAC(resultHMAC)) {
58+
Serial.println("Failed to end HMAC operation");
59+
while (1);
60+
}
61+
62+
Serial.println("HMAC Result: ");
63+
for (int i = 0; i<sizeof(resultHMAC); i++) {
64+
char hexChar[2];
65+
sprintf(hexChar, "%02X", resultHMAC[i]);
66+
Serial.print(hexChar);
67+
Serial.print(" ");
68+
}
69+
}
70+
71+
void loop() {
72+
}

0 commit comments

Comments
 (0)