From 868469db0dae4f1eb6465419a2a3915924d5b747 Mon Sep 17 00:00:00 2001 From: Victor Date: Wed, 10 Jul 2019 23:22:51 +0100 Subject: [PATCH 1/4] Fix comment alignment --- armsrc/hitag2.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/armsrc/hitag2.c b/armsrc/hitag2.c index 6a70f59e9..e25fbd91a 100644 --- a/armsrc/hitag2.c +++ b/armsrc/hitag2.c @@ -697,7 +697,7 @@ void SniffHitag(void) { StopTicks(); -// int frame_count; + // int frame_count; int response; int overflow; bool rising_edge; @@ -755,7 +755,7 @@ void SniffHitag(void) { // Reset the received frame, frame count and timing info memset(rx, 0x00, sizeof(rx)); -// frame_count = 0; + // frame_count = 0; response = 0; overflow = 0; reader_frame = false; @@ -862,7 +862,7 @@ void SniffHitag(void) { // Check if frame was captured if (rxlen > 0) { -// frame_count++; + // frame_count++; LogTrace(rx, nbytes(rxlen), response, 0, NULL, reader_frame); // Check if we recognize a valid authentication attempt @@ -912,7 +912,7 @@ void SimulateHitagTag(bool tag_mem_supplied, uint8_t *data) { StopTicks(); -// int frame_count = 0; + // int frame_count = 0; int response = 0, overflow = 0; uint8_t rx[HITAG_FRAME_LEN]; size_t rxlen = 0; @@ -1030,7 +1030,7 @@ void SimulateHitagTag(bool tag_mem_supplied, uint8_t *data) { // Check if frame was captured if (rxlen > 4) { -// frame_count++; + // frame_count++; LogTrace(rx, nbytes(rxlen), response, response, NULL, true); // Disable timer 1 with external trigger to avoid triggers during our own modulation @@ -1086,7 +1086,7 @@ void ReaderHitag(hitag_function htf, hitag_data *htd) { StopTicks(); -// int frame_count = 0; + // int frame_count = 0; int response = 0; uint8_t rx[HITAG_FRAME_LEN]; size_t rxlen = 0; @@ -1222,7 +1222,7 @@ void ReaderHitag(hitag_function htf, hitag_data *htd) { // Check if frame was captured and store it if (rxlen > 0) { -// frame_count++; + // frame_count++; LogTrace(rx, nbytes(rxlen), response, response, NULL, false); } @@ -1278,7 +1278,7 @@ void ReaderHitag(hitag_function htf, hitag_data *htd) { // Add transmitted frame to total count if (txlen > 0) { -// frame_count++; + // frame_count++; LogTrace(tx, nbytes(txlen), HITAG_T_WAIT_2, HITAG_T_WAIT_2, NULL, true); } @@ -1372,7 +1372,7 @@ void WriterHitag(hitag_function htf, hitag_data *htd, int page) { StopTicks(); -// int frame_count = 0; + // int frame_count = 0; int response = 0; uint8_t rx[HITAG_FRAME_LEN]; size_t rxlen = 0; @@ -1493,7 +1493,7 @@ void WriterHitag(hitag_function htf, hitag_data *htd, int page) { // Check if frame was captured and store it if (rxlen > 0) { -// frame_count++; + // frame_count++; LogTrace(rx, nbytes(rxlen), response, response, NULL, false); } @@ -1534,7 +1534,7 @@ void WriterHitag(hitag_function htf, hitag_data *htd, int page) { // Add transmitted frame to total count if (txlen > 0) { -// frame_count++; + // frame_count++; LogTrace(tx, nbytes(txlen), HITAG_T_WAIT_2, HITAG_T_WAIT_2, NULL, true); } From 4bd03bb920c47ad6601c6e8cbad7319802c041b7 Mon Sep 17 00:00:00 2001 From: Victor Date: Wed, 10 Jul 2019 23:23:50 +0100 Subject: [PATCH 2/4] Fix more comment alignment --- armsrc/hitag2.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/armsrc/hitag2.c b/armsrc/hitag2.c index e25fbd91a..7ae3a2cf2 100644 --- a/armsrc/hitag2.c +++ b/armsrc/hitag2.c @@ -272,8 +272,8 @@ static void hitag2_handle_reader_command(uint8_t *rx, const size_t rxlen, uint8_ break; } -// LogTrace(rx, nbytes(rxlen), 0, 0, NULL, false); -// LogTrace(tx, nbytes(txlen), 0, 0, NULL, true); + // LogTrace(rx, nbytes(rxlen), 0, 0, NULL, false); + // LogTrace(tx, nbytes(txlen), 0, 0, NULL, true); if (tag.crypto_active) { hitag2_cipher_transcrypt(&(tag.cs), tx, *txlen / 8, *txlen % 8); From 835a8a3b03859aa1f9e47b26a5bafc4d6cea19a9 Mon Sep 17 00:00:00 2001 From: Victor Date: Wed, 10 Jul 2019 23:49:08 +0100 Subject: [PATCH 3/4] Add state comments --- armsrc/hitag2.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/armsrc/hitag2.c b/armsrc/hitag2.c index 7ae3a2cf2..dd3ff3d79 100644 --- a/armsrc/hitag2.c +++ b/armsrc/hitag2.c @@ -27,8 +27,11 @@ #include "string.h" #include "BigBuf.h" +// Successful crypto auth static bool bCrypto; +// Is in auth stage static bool bAuthenticating; +// Successful password auth static bool bPwd; static bool bSuccessful; From 5913ee670a9f688c2ef5580c6715c40e7bd1b75a Mon Sep 17 00:00:00 2001 From: Victor Date: Sat, 3 Aug 2019 15:49:19 +0100 Subject: [PATCH 4/4] Add auth comments --- armsrc/hitag2.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/armsrc/hitag2.c b/armsrc/hitag2.c index dd3ff3d79..c541e57ae 100644 --- a/armsrc/hitag2.c +++ b/armsrc/hitag2.c @@ -401,6 +401,7 @@ static bool hitag2_password(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t // Received UID, tag password case 32: { + // stage 1, got UID if (!bPwd) { bPwd = true; bAuthenticating = true; @@ -408,6 +409,7 @@ static bool hitag2_password(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *txlen = 32; } else { + // stage 2, got config byte+password TAG, discard as will read later if (bAuthenticating) { bAuthenticating = false; if (write) { @@ -417,6 +419,7 @@ static bool hitag2_password(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t break; } } + // stage 2+, got data block else { memcpy(tag.sectors[blocknr], rx, 4); blocknr++; @@ -496,19 +499,22 @@ static bool hitag2_crypto(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t * } // Received UID, crypto tag answer case 32: { + // stage 1, got UID if (!bCrypto) { uint64_t ui64key = key[0] | ((uint64_t)key[1]) << 8 | ((uint64_t)key[2]) << 16 | ((uint64_t)key[3]) << 24 | ((uint64_t)key[4]) << 32 | ((uint64_t)key[5]) << 40; uint32_t ui32uid = rx[0] | ((uint32_t)rx[1]) << 8 | ((uint32_t)rx[2]) << 16 | ((uint32_t)rx[3]) << 24; Dbprintf("hitag2_crypto: key=0x%x%x uid=0x%x", (uint32_t)((REV64(ui64key)) >> 32), (uint32_t)((REV64(ui64key)) & 0xffffffff), REV32(ui32uid)); cipher_state = _hitag2_init(REV64(ui64key), REV32(ui32uid), 0); + // PRN memset(tx, 0x00, 4); + // Secret data memset(tx + 4, 0xff, 4); hitag2_cipher_transcrypt(&cipher_state, tx + 4, 4, 0); *txlen = 64; bCrypto = true; bAuthenticating = true; } else { - // Check if we received answer tag (at) + // stage 2, got config byte+password TAG, discard as will read later if (bAuthenticating) { bAuthenticating = false; if (write) { @@ -517,7 +523,9 @@ static bool hitag2_crypto(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t * } break; } - } else { + } + // stage 2+, got data block + else { // Store the received block memcpy(tag.sectors[blocknr], rx, 4); blocknr++;