mirror of
https://github.com/bitlair/bitlair_doorduino.git
synced 2025-05-13 12:20:07 +02:00
refactor
This commit is contained in:
parent
a2e62b8ef0
commit
6d5478b21f
1 changed files with 6 additions and 7 deletions
|
@ -190,10 +190,7 @@ bool AuthenticateButton(uint8_t* addr, uint8_t* secret)
|
||||||
nonce[i] = Entropy.randomByte();
|
nonce[i] = Entropy.randomByte();
|
||||||
|
|
||||||
if (!ibutton.ReadAuthWithChallenge(addr, 0, nonce, data, mac_from_ibutton))
|
if (!ibutton.ReadAuthWithChallenge(addr, 0, nonce, data, mac_from_ibutton))
|
||||||
{
|
|
||||||
Serial.println("Button authentication failed");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
sha1::sha1nfo sha1data = {};
|
sha1::sha1nfo sha1data = {};
|
||||||
sha1::sha1_init(&sha1data);
|
sha1::sha1_init(&sha1data);
|
||||||
|
@ -217,9 +214,6 @@ bool AuthenticateButton(uint8_t* addr, uint8_t* secret)
|
||||||
((uint32_t*)mac_computed)[3] = htonl(ntohl(*(uint32_t *)(sha_computed+12)) - 0x10325476);
|
((uint32_t*)mac_computed)[3] = htonl(ntohl(*(uint32_t *)(sha_computed+12)) - 0x10325476);
|
||||||
((uint32_t*)mac_computed)[4] = htonl(ntohl(*(uint32_t *)(sha_computed+16)) - 0xc3d2e1f0);
|
((uint32_t*)mac_computed)[4] = htonl(ntohl(*(uint32_t *)(sha_computed+16)) - 0xc3d2e1f0);
|
||||||
|
|
||||||
for (uint8_t i = 0; i < SHA1SIZE; i++)
|
|
||||||
Serialprintf("%02x %02x\n", ((uint8_t*)mac_from_ibutton)[i], ((uint8_t*)mac_computed)[SHA1SIZE - 1 - i]);
|
|
||||||
|
|
||||||
for (uint8_t i = 0; i < SHA1SIZE; i++)
|
for (uint8_t i = 0; i < SHA1SIZE; i++)
|
||||||
{
|
{
|
||||||
if (mac_from_ibutton[i] != mac_computed[SHA1SIZE - 1 - i])
|
if (mac_from_ibutton[i] != mac_computed[SHA1SIZE - 1 - i])
|
||||||
|
@ -403,7 +397,6 @@ void loop()
|
||||||
ds.reset_search();
|
ds.reset_search();
|
||||||
if (ds.search(addr) && OneWire::crc8(addr, 7) == addr[7])
|
if (ds.search(addr) && OneWire::crc8(addr, 7) == addr[7])
|
||||||
{
|
{
|
||||||
SetLEDState(LEDState_Authorized);
|
|
||||||
Serial.print("DEBUG: Found iButton with address: ");
|
Serial.print("DEBUG: Found iButton with address: ");
|
||||||
for (uint8_t i = 0; i < sizeof(addr); i++)
|
for (uint8_t i = 0; i < sizeof(addr); i++)
|
||||||
Serialprintf("%02x", addr[i]);
|
Serialprintf("%02x", addr[i]);
|
||||||
|
@ -414,9 +407,15 @@ void loop()
|
||||||
for (uint8_t i = 0; i < SECRETSIZE; i++)
|
for (uint8_t i = 0; i < SECRETSIZE; i++)
|
||||||
|
|
||||||
if (AuthenticateButton(addr, secret))
|
if (AuthenticateButton(addr, secret))
|
||||||
|
{
|
||||||
|
SetLEDState(LEDState_Authorized);
|
||||||
|
Serial.print("iButton authenticated\n");
|
||||||
delay(1000);
|
delay(1000);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
SetLEDState(LEDState_Busy);
|
SetLEDState(LEDState_Busy);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue