Skip to content

Commit cbdacc4

Browse files
committed
Add ECC508 private and public key generation support
1 parent 7339b0c commit cbdacc4

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

src/utility/ECC508.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,52 @@ int ECC508Class::random(byte data[], size_t length)
6262
return 1;
6363
}
6464

65+
int ECC508Class::generatePrivateKey(int slot, byte publicKey[])
66+
{
67+
if (!wakeup()) {
68+
return 0;
69+
}
70+
71+
if (!sendCommand(0x40, 0x04, slot)) {
72+
return 0;
73+
}
74+
75+
delay(115);
76+
77+
if (!receiveResponse(publicKey, 64)) {
78+
return 0;
79+
}
80+
81+
delay(1);
82+
83+
idle();
84+
85+
return 1;
86+
}
87+
88+
int ECC508Class::generatePublicKey(int slot, byte publicKey[])
89+
{
90+
if (!wakeup()) {
91+
return 0;
92+
}
93+
94+
if (!sendCommand(0x40, 0x00, slot)) {
95+
return 0;
96+
}
97+
98+
delay(115);
99+
100+
if (!receiveResponse(publicKey, 64)) {
101+
return 0;
102+
}
103+
104+
delay(1);
105+
106+
idle();
107+
108+
return 1;
109+
}
110+
65111
int ECC508Class::ecdsaVerify(const byte message[], const byte signature[], const byte pubkey[])
66112
{
67113
if (!challenge(message)) {

src/utility/ECC508.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ class ECC508Class
1515

1616
int random(byte data[], size_t length);
1717

18+
int generatePrivateKey(int slot, byte publicKey[]);
19+
int generatePublicKey(int slot, byte publicKey[]);
20+
1821
int ecdsaVerify(const byte message[], const byte signature[], const byte pubkey[]);
1922
int ecSign(int slot, const byte message[], byte signature[]);
2023

0 commit comments

Comments
 (0)