Skip to content

Commit 8c271d0

Browse files
authored
Merge pull request #253 from pennam/soft_se
Add software AT secure element support
2 parents 1a63e16 + bcfbba2 commit 8c271d0

File tree

10 files changed

+684
-0
lines changed

10 files changed

+684
-0
lines changed

Diff for: .github/workflows/compile-examples.yml

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ jobs:
9595
- libraries/WiFiS3
9696
- libraries/OTAUpdate
9797
- libraries/OPAMP
98+
- libraries/SoftwareATSE
9899
- libraries/Preferences
99100
- board:
100101
fqbn: "arduino-git:renesas:minima"

Diff for: libraries/SoftwareATSE/.unor4_only

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
Software Secure Element Certificate
3+
4+
This sketch uses the Software Secure Element to store device certificate and read it back.
5+
6+
Circuit:
7+
- UNO R4 WiFi
8+
*/
9+
10+
#include <SoftwareATSE.h>
11+
12+
const byte certificate[410] = {
13+
0x30 ,0x82 ,0x01 ,0x96 ,0x30 ,0x82 ,0x01 ,0x3D ,0xA0 ,0x03 ,0x02 ,0x01 ,0x02 ,0x02 ,0x10 ,0x37,
14+
0xFE ,0x48 ,0x92 ,0xE6 ,0xC0 ,0xA0 ,0x64 ,0x68 ,0x91 ,0x66 ,0x5F ,0x7D ,0xE3 ,0x02 ,0xDE ,0x30,
15+
0x0A ,0x06 ,0x08 ,0x2A ,0x86 ,0x48 ,0xCE ,0x3D ,0x04 ,0x03 ,0x02 ,0x30 ,0x45 ,0x31 ,0x0B ,0x30,
16+
0x09 ,0x06 ,0x03 ,0x55 ,0x04 ,0x06 ,0x13 ,0x02 ,0x55 ,0x53 ,0x31 ,0x17 ,0x30 ,0x15 ,0x06 ,0x03,
17+
0x55 ,0x04 ,0x0A ,0x13 ,0x0E ,0x41 ,0x72 ,0x64 ,0x75 ,0x69 ,0x6E ,0x6F ,0x20 ,0x4C ,0x4C ,0x43,
18+
0x20 ,0x55 ,0x53 ,0x31 ,0x0B ,0x30 ,0x09 ,0x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(const byte input[], size_t inputLength) {
42+
Serial.println(inputLength);
43+
for (size_t i = 0; i < inputLength; i++) {
44+
Serial.print(input[i] >> 4, HEX);
45+
Serial.print(input[i] & 0x0f, HEX);
46+
}
47+
Serial.println();
48+
}
49+
50+
void setup() {
51+
Serial.begin(9600);
52+
while (!Serial);
53+
54+
if (!SATSE.begin()) {
55+
Serial.println("Failed to communicate with Software Secure Element!");
56+
Serial.println("Make sure your WiFi firmware version is greater than 0.3.0");
57+
while (1);
58+
}
59+
60+
const int certId = 799;
61+
62+
if(SATSE.writeSlot(certId, certificate, sizeof(certificate))) {
63+
Serial.println("Data stored");
64+
} else {
65+
Serial.println("Failed to store data");
66+
return;
67+
}
68+
69+
byte buf[512];
70+
int ret = 0;
71+
72+
if((ret = SATSE.readSlot(certId, buf, sizeof(buf))) > 0) {
73+
Serial.print("Readback data is: ");
74+
int len = (buf[2] << 8) + buf[3] + 4;
75+
printBufferHex(buf, len);
76+
} else {
77+
Serial.println("Failed to read data");
78+
return;
79+
}
80+
81+
}
82+
83+
void loop() {
84+
85+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
Software Secure Element Private Key
3+
4+
This sketch uses the Software Secure Element to generate a new EC NIST P-256 keypair
5+
and store it with id 999, then the public key is printed in raw format.
6+
7+
Circuit:
8+
- UNO R4 WiFi
9+
*/
10+
11+
#include <SoftwareATSE.h>
12+
#include <Wire.h>
13+
14+
const int KeyId = 999;
15+
byte rawBuf[64];
16+
17+
void printBufferHex(const byte input[], size_t inputLength) {
18+
for (size_t i = 0; i < inputLength; i++) {
19+
Serial.print(input[i] >> 4, HEX);
20+
Serial.print(input[i] & 0x0f, HEX);
21+
}
22+
Serial.println();
23+
}
24+
25+
void setup() {
26+
Serial.begin(9600);
27+
while (!Serial);
28+
29+
if (!SATSE.begin()) {
30+
Serial.println("Failed to communicate with Software Secure Element!");
31+
Serial.println("Make sure your WiFi firmware version is greater than 0.3.0");
32+
while (1);
33+
}
34+
35+
SATSE.generatePrivateKey(KeyId, rawBuf);
36+
printBufferHex(rawBuf, sizeof(rawBuf));
37+
38+
}
39+
40+
void loop() {
41+
SATSE.generatePublicKey(KeyId, rawBuf);
42+
printBufferHex(rawBuf, sizeof(rawBuf));
43+
delay(5000);
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
Software Secure Element Random Number
3+
4+
This sketch uses the Software Secure Element to generate a random number
5+
every second and print it to the Serial monitor
6+
7+
Circuit:
8+
- UNO R4 WiFi
9+
*/
10+
11+
#include <SoftwareATSE.h>
12+
13+
void setup() {
14+
Serial.begin(9600);
15+
while (!Serial);
16+
17+
if (!SATSE.begin()) {
18+
Serial.println("Failed to communicate with Software Secure Element!");
19+
Serial.println("Make sure your WiFi firmware version is greater than 0.3.0");
20+
while (1);
21+
}
22+
}
23+
24+
void loop() {
25+
Serial.print("Random number = ");
26+
Serial.println(SATSE.random(65535));
27+
28+
delay(1000);
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
Software Secure Element serial number
3+
4+
This sketch prints the Software Secure Element serial number:
5+
ESP32-S3-MINI-1 efuse mac address
6+
7+
Circuit:
8+
- UNO R4 WiFi
9+
*/
10+
11+
#include <SoftwareATSE.h>
12+
13+
void setup() {
14+
Serial.begin(9600);
15+
while (!Serial);
16+
17+
if (!SATSE.begin()) {
18+
Serial.println("Failed to communicate with Software Secure Element!");
19+
Serial.println("Make sure your WiFi firmware version is greater than 0.3.0");
20+
while (1);
21+
}
22+
}
23+
24+
void loop() {
25+
Serial.print("S/N = ");
26+
Serial.println(SATSE.serialNumber());
27+
28+
delay(1000);
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
Software Secure Element SignAndVerify
3+
4+
This sketch uses the Software Secure Element to generate a new EC NIST P-256 keypair
5+
and store it with id 999, then input buffer SHA256 is signed with the private
6+
key and verified with the public key.
7+
8+
Circuit:
9+
- UNO R4 WiFi
10+
*/
11+
12+
#include <SoftwareATSE.h>
13+
14+
const byte input[64] = {
15+
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
16+
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
17+
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
18+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f
19+
};
20+
21+
void printBufferHex(const byte input[], size_t inputLength) {
22+
for (size_t i = 0; i < inputLength; i++) {
23+
Serial.print(input[i] >> 4, HEX);
24+
Serial.print(input[i] & 0x0f, HEX);
25+
}
26+
Serial.println();
27+
}
28+
29+
void setup() {
30+
Serial.begin(9600);
31+
while (!Serial);
32+
33+
if (!SATSE.begin()) {
34+
Serial.println("Failed to communicate with Software Secure Element!");
35+
Serial.println("Make sure your WiFi firmware version is greater than 0.3.0");
36+
while (1);
37+
}
38+
39+
const int KeyId = 999;
40+
byte pubKey[256];
41+
42+
SATSE.generatePrivateKey(KeyId, pubKey);
43+
44+
// print the public key
45+
Serial.print("Public key is: ");
46+
printBufferHex(pubKey, 64);
47+
48+
// print the input
49+
Serial.print("Input is: ");
50+
printBufferHex(input, sizeof(input));
51+
52+
// calculate the input SHA256
53+
byte sha256[256];
54+
size_t sha256Len;
55+
SATSE.SHA256(input, sizeof(input), sha256);
56+
Serial.print("Input SHA256 is: ");
57+
printBufferHex(sha256, 32);
58+
59+
// calculate the signature, input MUST be SHA256
60+
byte signature[256];
61+
SATSE.ecSign(KeyId, sha256, signature);
62+
63+
// print the signature
64+
Serial.print("Signature using KeyId ");
65+
Serial.print(KeyId);
66+
Serial.print(" is: ");
67+
printBufferHex(signature, 64);
68+
69+
Serial.println();
70+
71+
// To make the signature verifcation fail, uncomment the next line:
72+
// signature[0] = 0x00;
73+
74+
// validate the signature
75+
if (SATSE.ecdsaVerify(sha256, signature, pubKey)) {
76+
Serial.println("Verified signature successfully :D");
77+
} else {
78+
Serial.println("oh no! failed to verify signature :(");
79+
}
80+
}
81+
82+
void loop() {
83+
84+
}

Diff for: libraries/SoftwareATSE/library.properties

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=SoftwareATSE
2+
version=0.0.1
3+
author=Arduino
4+
maintainer=Arduino <[email protected]>
5+
sentence=Arduino Library implementing base secure element functions in software
6+
paragraph=
7+
category=Communication
8+
url=
9+
architectures=renesas,renesas_uno

0 commit comments

Comments
 (0)