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