From d8a26e2b8b7ef7dfe4411cb5e069c2730d177941 Mon Sep 17 00:00:00 2001 From: Denis Bodor Date: Tue, 19 Nov 2019 10:55:17 +0100 Subject: [PATCH] switch from lua CRC16/ARC to CRC RevEng --- CHANGELOG.md | 1 + client/luascripts/luxeodump.lua | 38 +++------------------------------ 2 files changed, 4 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 89a04d651..16354bcac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -372,6 +372,7 @@ This project uses the changelog in accordance with [keepchangelog](http://keepac - Added `hf fido` `assert` and `make` commands from fido2 protocol (authenticatorMakeCredential and authenticatorGetAssertion) (@merlokk) - Added trailer block decoding to `hf mf rdbl` and `hf mf cgetbl` (@merlokk) - Added `hf mf mad` and `hf mfp mad` MAD decode, check and print commands (@merlokk) + - Add `script run luxeodump` (@0xdrrb) ### Fixed diff --git a/client/luascripts/luxeodump.lua b/client/luascripts/luxeodump.lua index 182af67d4..6b7254801 100644 --- a/client/luascripts/luxeodump.lua +++ b/client/luascripts/luxeodump.lua @@ -121,38 +121,6 @@ local function createxteakey(mfuid) return xteakey end --- CRC16/ARC from core.reveng_runmodel() does not seem to return the right values. --- So here is an implementation in Lua. -local function bitreflect(data, nbits) - local output = 0 - for i = 0, nbits-1 do - if bit.band(data,1) ~= 0 then - output = bit32.bor(output, bit32.lshift(1,((nbits - 1) - i))) - else - end - data = bit32.rshift(data,1) - end - return output -end - -local function crc16arc(s) - assert(type(s) == 'string') - local crc = 0x0000 - for i = 1, #s do - local c = s:byte(i) - dbyte = bitreflect(c, 8) - crc = bit32.bxor(crc, bit32.lshift(dbyte,8)) - for j = 0, 7 do - local mix = bit32.band(crc, 0x8000) - crc = bit32.lshift(crc,1) - if mix ~= 0 then - crc = bit32.bxor(crc, 0x8005) - end - end - end - return bitreflect(crc, 16) -end - local function getblockdata(response) if not response then return nil, 'No response from device' @@ -253,9 +221,9 @@ local function main(args) end -- compute CRC for each segment - crcH = crc16arc(utils.ConvertHexToAscii(cdata[1]..cdata[2]..cdata[3]:sub(1,28))) - crcA = crc16arc(utils.ConvertHexToAscii(cdata[4]..cdata[5]..cdata[6]..cdata[7]:sub(1,28))) - crcB = crc16arc(utils.ConvertHexToAscii(cdata[8]..cdata[9]..cdata[10]..cdata[11]:sub(1,28))) + crcH = utils.SwapEndianness(core.reveng_runmodel("CRC-16/ARC", cdata[1]..cdata[2]..cdata[3]:sub(1,28), false, '0'),16) + crcA = utils.SwapEndianness(core.reveng_runmodel("CRC-16/ARC", cdata[4]..cdata[5]..cdata[6]..cdata[7]:sub(1,28), false, '0'),16) + crcB = utils.SwapEndianness(core.reveng_runmodel("CRC-16/ARC", cdata[8]..cdata[9]..cdata[10]..cdata[11]:sub(1,28), false, '0'),16) print("\nHeader:") for key,value in ipairs(cdata) do