diff options
-rw-r--r-- | epan/crc16-tvb.c | 10 | ||||
-rw-r--r-- | epan/crc16-tvb.h | 7 | ||||
-rw-r--r-- | wsutil/crc16.c | 8 | ||||
-rw-r--r-- | wsutil/crc16.h | 6 |
4 files changed, 31 insertions, 0 deletions
diff --git a/epan/crc16-tvb.c b/epan/crc16-tvb.c index b20d759c50..bea77bdff2 100644 --- a/epan/crc16-tvb.c +++ b/epan/crc16-tvb.c @@ -98,6 +98,16 @@ guint16 crc16_ccitt_tvb_offset_seed(tvbuff_t *tvb, guint offset, guint len, guin return crc16_ccitt_seed(buf, len, seed); } +guint16 crc16_iso14443a_tvb_offset(tvbuff_t *tvb, guint offset, guint len) +{ + const guint8 *buf; + + tvb_ensure_bytes_exist(tvb, offset, len); /* len == -1 not allowed */ + buf = tvb_get_ptr(tvb, offset, len); + + return crc16_iso14443a(buf, len); +} + guint16 crc16_plain_tvb_offset(tvbuff_t *tvb, guint offset, guint len) { guint16 crc = crc16_plain_init(); diff --git a/epan/crc16-tvb.h b/epan/crc16-tvb.h index c8a699f98a..1a18f1fba3 100644 --- a/epan/crc16-tvb.h +++ b/epan/crc16-tvb.h @@ -77,6 +77,13 @@ WS_DLL_PUBLIC guint16 crc16_ccitt_tvb_seed(tvbuff_t *tvb, guint len, guint16 see WS_DLL_PUBLIC guint16 crc16_ccitt_tvb_offset_seed(tvbuff_t *tvb, guint offset, guint len, guint16 seed); +/** Compute the 16bit CRC_A value of a tv buffer as defined in ISO14443-3. + @param tvb The tv buffer containing the data. + @param offset The offset into the tv buffer. + @param len The number of bytes to include in the computation. + @return The calculated CRC_A. */ +WS_DLL_PUBLIC guint16 crc16_iso14443a_tvb_offset(tvbuff_t *tvb, guint offset, guint len); + /** Compute the "plain" CRC16 checksum of a tv buffer using the following * parameters: * Width = 16 diff --git a/wsutil/crc16.c b/wsutil/crc16.c index 8febfa1c66..2ff576c200 100644 --- a/wsutil/crc16.c +++ b/wsutil/crc16.c @@ -346,6 +346,14 @@ guint16 crc16_ccitt_seed(const guint8 *buf, guint len, guint16 seed) ^ crc16_ccitt_xorout; } +/* ISO14443-3, section 6.2.4: For ISO14443-A, the polynomial 0x1021 is + used, the initial register value shall be 0x6363, the final register + value is not XORed with anything. */ +guint16 crc16_iso14443a(const guint8 *buf, guint len) +{ + return crc16_reflected(buf,len, 0x6363 ,crc16_ccitt_table_reverse); +} + guint16 crc16_0x5935(const guint8 *buf, guint32 len, guint16 seed) { return crc16_unreflected(buf, len, seed, crc16_precompiled_5935); diff --git a/wsutil/crc16.h b/wsutil/crc16.h index 151b3f210d..11616089cc 100644 --- a/wsutil/crc16.h +++ b/wsutil/crc16.h @@ -61,6 +61,12 @@ WS_DLL_PUBLIC guint16 crc16_x25_ccitt_seed(const guint8 *buf, guint len, guint16 @return The CRC16 CCITT checksum (using the given seed). */ WS_DLL_PUBLIC guint16 crc16_ccitt_seed(const guint8 *buf, guint len, guint16 seed); +/** Compute the 16bit CRC_A value of a buffer as defined in ISO14443-3. + @param buf The buffer containing the data. + @param len The number of bytes to include in the computation. + @return the CRC16 checksum for the buffer */ +WS_DLL_PUBLIC guint16 crc16_iso14443a(const guint8 *buf, guint len); + /** Calculates a CRC16 checksum for the given buffer with the polynom * 0x5935 using a precompiled CRC table * @param buf a pointer to a buffer of the given length |