Skip to content

Commit 026f415

Browse files
committed
ensure device goes into idle even on error
1 parent 9971d60 commit 026f415

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

Diff for: src/ECCX08.cpp

+22-23
Original file line numberDiff line numberDiff line change
@@ -173,48 +173,47 @@ int ECCX08Class::random(byte data[], size_t length)
173173

174174
int ECCX08Class::generatePrivateKey(int slot, byte publicKey[])
175175
{
176+
int result = 0;
177+
176178
if (!wakeup()) {
177179
return 0;
178180
}
179181

180-
if (!sendCommand(0x40, 0x04, slot)) {
181-
return 0;
182-
}
183-
184-
delay(115);
182+
if (sendCommand(0x40, 0x04, slot)) {
183+
delay(115);
185184

186-
if (!receiveResponse(publicKey, 64)) {
187-
return 0;
185+
if (receiveResponse(publicKey, 64)) {
186+
delay(1);
187+
result = 1;
188+
}
188189
}
189190

190-
delay(1);
191-
192191
idle();
193-
194-
return 1;
192+
return result;
195193
}
196194

197195
int ECCX08Class::generatePublicKey(int slot, byte publicKey[])
198196
{
199-
if (!wakeup()) {
200-
return 0;
201-
}
202-
203-
if (!sendCommand(0x40, 0x00, slot)) {
197+
int result = 0;
198+
199+
if (!wakeup())
200+
{
204201
return 0;
205202
}
206203

207-
delay(115);
204+
if (sendCommand(0x40, 0x00, slot))
205+
{
206+
delay(115);
208207

209-
if (!receiveResponse(publicKey, 64)) {
210-
return 0;
208+
if (receiveResponse(publicKey, 64))
209+
{
210+
delay(1);
211+
result = 1;
212+
}
211213
}
212214

213-
delay(1);
214-
215215
idle();
216-
217-
return 1;
216+
return result;
218217
}
219218

220219
int ECCX08Class::ecdsaVerify(const byte message[], const byte signature[], const byte pubkey[])

0 commit comments

Comments
 (0)