Skip to content

Commit

Permalink
ensure device goes into idle even on error
Browse files Browse the repository at this point in the history
  • Loading branch information
bobo committed Dec 4, 2024
1 parent 9971d60 commit 026f415
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions src/ECCX08.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,48 +173,47 @@ int ECCX08Class::random(byte data[], size_t length)

int ECCX08Class::generatePrivateKey(int slot, byte publicKey[])
{
int result = 0;

if (!wakeup()) {
return 0;
}

if (!sendCommand(0x40, 0x04, slot)) {
return 0;
}

delay(115);
if (sendCommand(0x40, 0x04, slot)) {
delay(115);

if (!receiveResponse(publicKey, 64)) {
return 0;
if (receiveResponse(publicKey, 64)) {
delay(1);
result = 1;
}
}

delay(1);

idle();

return 1;
return result;
}

int ECCX08Class::generatePublicKey(int slot, byte publicKey[])
{
if (!wakeup()) {
return 0;
}

if (!sendCommand(0x40, 0x00, slot)) {
int result = 0;

if (!wakeup())
{
return 0;
}

delay(115);
if (sendCommand(0x40, 0x00, slot))
{
delay(115);

if (!receiveResponse(publicKey, 64)) {
return 0;
if (receiveResponse(publicKey, 64))
{
delay(1);
result = 1;
}
}

delay(1);

idle();

return 1;
return result;
}

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

0 comments on commit 026f415

Please sign in to comment.