summaryrefslogtreecommitdiff
path: root/dht/cbits
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2020-01-09 12:10:10 -0500
committerJoe Crayne <joe@jerkface.net>2020-01-09 12:10:10 -0500
commit5e2f6f9f8b78b90f0becb60e735abbd62bac6ca6 (patch)
tree9d7398a42a2925fe4f7e760e7d5ee9ae0a0a75fe /dht/cbits
parentb9194d4637ddfc3b9f762d2e4e29a318087e02db (diff)
Moved Codec.AsciiKey256 to tox-crypto.
Diffstat (limited to 'dht/cbits')
-rw-r--r--dht/cbits/crc4_itu.c44
1 files changed, 0 insertions, 44 deletions
diff --git a/dht/cbits/crc4_itu.c b/dht/cbits/crc4_itu.c
deleted file mode 100644
index 8e3b0489..00000000
--- a/dht/cbits/crc4_itu.c
+++ /dev/null
@@ -1,44 +0,0 @@
1/*-----------------------------------------------------------------
2| crc4_itu.c
3|
4| CRC4-ITU library using lookup table method.
5|
6*-------------------------------------------------------------------*/
7
8#include <stddef.h>
9
10static unsigned char const crc4itu_bbox[256] = {
11 0x0, 0x7, 0xe, 0x9, 0x5, 0x2, 0xb, 0xc, 0xa, 0xd, 0x4, 0x3, 0xf, 0x8, 0x1, 0x6,
12 0xd, 0xa, 0x3, 0x4, 0x8, 0xf, 0x6, 0x1, 0x7, 0x0, 0x9, 0xe, 0x2, 0x5, 0xc, 0xb,
13 0x3, 0x4, 0xd, 0xa, 0x6, 0x1, 0x8, 0xf, 0x9, 0xe, 0x7, 0x0, 0xc, 0xb, 0x2, 0x5,
14 0xe, 0x9, 0x0, 0x7, 0xb, 0xc, 0x5, 0x2, 0x4, 0x3, 0xa, 0xd, 0x1, 0x6, 0xf, 0x8,
15 0x6, 0x1, 0x8, 0xf, 0x3, 0x4, 0xd, 0xa, 0xc, 0xb, 0x2, 0x5, 0x9, 0xe, 0x7, 0x0,
16 0xb, 0xc, 0x5, 0x2, 0xe, 0x9, 0x0, 0x7, 0x1, 0x6, 0xf, 0x8, 0x4, 0x3, 0xa, 0xd,
17 0x5, 0x2, 0xb, 0xc, 0x0, 0x7, 0xe, 0x9, 0xf, 0x8, 0x1, 0x6, 0xa, 0xd, 0x4, 0x3,
18 0x8, 0xf, 0x6, 0x1, 0xd, 0xa, 0x3, 0x4, 0x2, 0x5, 0xc, 0xb, 0x7, 0x0, 0x9, 0xe,
19 0xc, 0xb, 0x2, 0x5, 0x9, 0xe, 0x7, 0x0, 0x6, 0x1, 0x8, 0xf, 0x3, 0x4, 0xd, 0xa,
20 0x1, 0x6, 0xf, 0x8, 0x4, 0x3, 0xa, 0xd, 0xb, 0xc, 0x5, 0x2, 0xe, 0x9, 0x0, 0x7,
21 0xf, 0x8, 0x1, 0x6, 0xa, 0xd, 0x4, 0x3, 0x5, 0x2, 0xb, 0xc, 0x0, 0x7, 0xe, 0x9,
22 0x2, 0x5, 0xc, 0xb, 0x7, 0x0, 0x9, 0xe, 0x8, 0xf, 0x6, 0x1, 0xd, 0xa, 0x3, 0x4,
23 0xa, 0xd, 0x4, 0x3, 0xf, 0x8, 0x1, 0x6, 0x0, 0x7, 0xe, 0x9, 0x5, 0x2, 0xb, 0xc,
24 0x7, 0x0, 0x9, 0xe, 0x2, 0x5, 0xc, 0xb, 0xd, 0xa, 0x3, 0x4, 0x8, 0xf, 0x6, 0x1,
25 0x9, 0xe, 0x7, 0x0, 0xc, 0xb, 0x2, 0x5, 0x3, 0x4, 0xd, 0xa, 0x6, 0x1, 0x8, 0xf,
26 0x4, 0x3, 0xa, 0xd, 0x1, 0x6, 0xf, 0x8, 0xe, 0x9, 0x0, 0x7, 0xb, 0xc, 0x5, 0x2
27};
28
29/**
30 * CRC4-ITU function
31 *
32 * Parameters:
33 * crc Existing CRC value (usually 0x00) before process a new one.
34 * data Pointer to data to be hashed with CRC
35 * len Size of data
36 *
37 * Returns: CRC value in lowest 4 bits.
38 */
39unsigned char crc4itu(unsigned char crc, unsigned char *data, unsigned int len) {
40 if (data == NULL) return 0;
41 crc &= 0xf;
42 while (len--) crc = crc4itu_bbox[crc ^ *data++];
43 return crc;
44}