scapy.libs.crc

Configurable CRC computation and detection.

See CRC computation.

class scapy.libs.crc.CRC(msg: bytes)[source]

Bases: object

Base class for CRC algorithms.

finish() int[source]
init() None[source]
name = 'CRC'
param = None
update(msg: bytes) None[source]
class scapy.libs.crc.CRCParam(**args: Any)[source]

Bases: object

CRC algorithm parameters.

FMT = {'reflect_input': '', 'reflect_output': '', 'size': ''}
MISC = ['name', 'test_vectors']
OPTIONS = ['header', 'trailer']
PARAMETERS = ['poly', 'size', 'init_crc', 'xor', 'reflect_input', 'reflect_output']
copy() CRCParam[source]
param_repr() str[source]
signature() str[source]
class scapy.libs.crc.CRC_16(msg: bytes)[source]

Bases: CRC

init_crc = 0
mask = 65535
name = 'CRC-16'
param = <Param for CRC-16 poly= 0x8005, size= 16, init_crc= 0x0, xor= 0x0, reflect_input= 1, reflect_output= 1>
poly = 32773
reflect_input = True
reflect_output = True
size = 16
table = [0, 49345, 49537, 320, 49921, 960, 640, 49729, 50689, 1728, 1920, 51009, 1280, 50625, 50305, 1088, 52225, 3264, 3456, 52545, 3840, 53185, 52865, 3648, 2560, 51905, 52097, 2880, 51457, 2496, 2176, 51265, 55297, 6336, 6528, 55617, 6912, 56257, 55937, 6720, 7680, 57025, 57217, 8000, 56577, 7616, 7296, 56385, 5120, 54465, 54657, 5440, 55041, 6080, 5760, 54849, 53761, 4800, 4992, 54081, 4352, 53697, 53377, 4160, 61441, 12480, 12672, 61761, 13056, 62401, 62081, 12864, 13824, 63169, 63361, 14144, 62721, 13760, 13440, 62529, 15360, 64705, 64897, 15680, 65281, 16320, 16000, 65089, 64001, 15040, 15232, 64321, 14592, 63937, 63617, 14400, 10240, 59585, 59777, 10560, 60161, 11200, 10880, 59969, 60929, 11968, 12160, 61249, 11520, 60865, 60545, 11328, 58369, 9408, 9600, 58689, 9984, 59329, 59009, 9792, 8704, 58049, 58241, 9024, 57601, 8640, 8320, 57409, 40961, 24768, 24960, 41281, 25344, 41921, 41601, 25152, 26112, 42689, 42881, 26432, 42241, 26048, 25728, 42049, 27648, 44225, 44417, 27968, 44801, 28608, 28288, 44609, 43521, 27328, 27520, 43841, 26880, 43457, 43137, 26688, 30720, 47297, 47489, 31040, 47873, 31680, 31360, 47681, 48641, 32448, 32640, 48961, 32000, 48577, 48257, 31808, 46081, 29888, 30080, 46401, 30464, 47041, 46721, 30272, 29184, 45761, 45953, 29504, 45313, 29120, 28800, 45121, 20480, 37057, 37249, 20800, 37633, 21440, 21120, 37441, 38401, 22208, 22400, 38721, 21760, 38337, 38017, 21568, 39937, 23744, 23936, 40257, 24320, 40897, 40577, 24128, 23040, 39617, 39809, 23360, 39169, 22976, 22656, 38977, 34817, 18624, 18816, 35137, 19200, 35777, 35457, 19008, 19968, 36545, 36737, 20288, 36097, 19904, 19584, 35905, 17408, 33985, 34177, 17728, 34561, 18368, 18048, 34369, 33281, 17088, 17280, 33601, 16640, 33217, 32897, 16448]
test_vectors = [(b'123456789', 47933)]
xor = 0
class scapy.libs.crc.CRC_16_CCITT(msg: bytes)[source]

Bases: CRC

aka KERMIT CRC

init_crc = 0
mask = 65535
name = 'CRC16 CCITT'
param = <Param for CRC16 CCITT poly= 0x1021, size= 16, init_crc= 0x0, xor= 0x0, reflect_input= 1, reflect_output= 1>
poly = 4129
reflect_input = True
reflect_output = True
size = 16
table = [0, 4489, 8978, 12955, 17956, 22445, 25910, 29887, 35912, 40385, 44890, 48851, 51820, 56293, 59774, 63735, 4225, 264, 13203, 8730, 22181, 18220, 30135, 25662, 40137, 36160, 49115, 44626, 56045, 52068, 63999, 59510, 8450, 12427, 528, 5017, 26406, 30383, 17460, 21949, 44362, 48323, 36440, 40913, 60270, 64231, 51324, 55797, 12675, 8202, 4753, 792, 30631, 26158, 21685, 17724, 48587, 44098, 40665, 36688, 64495, 60006, 55549, 51572, 16900, 21389, 24854, 28831, 1056, 5545, 10034, 14011, 52812, 57285, 60766, 64727, 34920, 39393, 43898, 47859, 21125, 17164, 29079, 24606, 5281, 1320, 14259, 9786, 57037, 53060, 64991, 60502, 39145, 35168, 48123, 43634, 25350, 29327, 16404, 20893, 9506, 13483, 1584, 6073, 61262, 65223, 52316, 56789, 43370, 47331, 35448, 39921, 29575, 25102, 20629, 16668, 13731, 9258, 5809, 1848, 65487, 60998, 56541, 52564, 47595, 43106, 39673, 35696, 33800, 38273, 42778, 46739, 49708, 54181, 57662, 61623, 2112, 6601, 11090, 15067, 20068, 24557, 28022, 31999, 38025, 34048, 47003, 42514, 53933, 49956, 61887, 57398, 6337, 2376, 15315, 10842, 24293, 20332, 32247, 27774, 42250, 46211, 34328, 38801, 58158, 62119, 49212, 53685, 10562, 14539, 2640, 7129, 28518, 32495, 19572, 24061, 46475, 41986, 38553, 34576, 62383, 57894, 53437, 49460, 14787, 10314, 6865, 2904, 32743, 28270, 23797, 19836, 50700, 55173, 58654, 62615, 32808, 37281, 41786, 45747, 19012, 23501, 26966, 30943, 3168, 7657, 12146, 16123, 54925, 50948, 62879, 58390, 37033, 33056, 46011, 41522, 23237, 19276, 31191, 26718, 7393, 3432, 16371, 11898, 59150, 63111, 50204, 54677, 41258, 45219, 33336, 37809, 27462, 31439, 18516, 23005, 11618, 15595, 3696, 8185, 63375, 58886, 54429, 50452, 45483, 40994, 37561, 33584, 31687, 27214, 22741, 18780, 15843, 11370, 7921, 3960]
test_vectors = [(b'\xcb7', 27454)]
xor = 0
class scapy.libs.crc.CRC_32(msg: bytes)[source]

Bases: CRC

init_crc = 4294967295
mask = 4294967295
name = 'CRC-32'
param = <Param for CRC-32 poly= 0x4c11db7, size= 32, init_crc= 0xffffffff, xor= 0xffffffff, reflect_input= 1, reflect_output= 1>
poly = 79764919
reflect_input = True
reflect_output = True
size = 32
table = [0, 1996959894, 3993919788, 2567524794, 124634137, 1886057615, 3915621685, 2657392035, 249268274, 2044508324, 3772115230, 2547177864, 162941995, 2125561021, 3887607047, 2428444049, 498536548, 1789927666, 4089016648, 2227061214, 450548861, 1843258603, 4107580753, 2211677639, 325883990, 1684777152, 4251122042, 2321926636, 335633487, 1661365465, 4195302755, 2366115317, 997073096, 1281953886, 3579855332, 2724688242, 1006888145, 1258607687, 3524101629, 2768942443, 901097722, 1119000684, 3686517206, 2898065728, 853044451, 1172266101, 3705015759, 2882616665, 651767980, 1373503546, 3369554304, 3218104598, 565507253, 1454621731, 3485111705, 3099436303, 671266974, 1594198024, 3322730930, 2970347812, 795835527, 1483230225, 3244367275, 3060149565, 1994146192, 31158534, 2563907772, 4023717930, 1907459465, 112637215, 2680153253, 3904427059, 2013776290, 251722036, 2517215374, 3775830040, 2137656763, 141376813, 2439277719, 3865271297, 1802195444, 476864866, 2238001368, 4066508878, 1812370925, 453092731, 2181625025, 4111451223, 1706088902, 314042704, 2344532202, 4240017532, 1658658271, 366619977, 2362670323, 4224994405, 1303535960, 984961486, 2747007092, 3569037538, 1256170817, 1037604311, 2765210733, 3554079995, 1131014506, 879679996, 2909243462, 3663771856, 1141124467, 855842277, 2852801631, 3708648649, 1342533948, 654459306, 3188396048, 3373015174, 1466479909, 544179635, 3110523913, 3462522015, 1591671054, 702138776, 2966460450, 3352799412, 1504918807, 783551873, 3082640443, 3233442989, 3988292384, 2596254646, 62317068, 1957810842, 3939845945, 2647816111, 81470997, 1943803523, 3814918930, 2489596804, 225274430, 2053790376, 3826175755, 2466906013, 167816743, 2097651377, 4027552580, 2265490386, 503444072, 1762050814, 4150417245, 2154129355, 426522225, 1852507879, 4275313526, 2312317920, 282753626, 1742555852, 4189708143, 2394877945, 397917763, 1622183637, 3604390888, 2714866558, 953729732, 1340076626, 3518719985, 2797360999, 1068828381, 1219638859, 3624741850, 2936675148, 906185462, 1090812512, 3747672003, 2825379669, 829329135, 1181335161, 3412177804, 3160834842, 628085408, 1382605366, 3423369109, 3138078467, 570562233, 1426400815, 3317316542, 2998733608, 733239954, 1555261956, 3268935591, 3050360625, 752459403, 1541320221, 2607071920, 3965973030, 1969922972, 40735498, 2617837225, 3943577151, 1913087877, 83908371, 2512341634, 3803740692, 2075208622, 213261112, 2463272603, 3855990285, 2094854071, 198958881, 2262029012, 4057260610, 1759359992, 534414190, 2176718541, 4139329115, 1873836001, 414664567, 2282248934, 4279200368, 1711684554, 285281116, 2405801727, 4167216745, 1634467795, 376229701, 2685067896, 3608007406, 1308918612, 956543938, 2808555105, 3495958263, 1231636301, 1047427035, 2932959818, 3654703836, 1088359270, 936918000, 2847714899, 3736837829, 1202900863, 817233897, 3183342108, 3401237130, 1404277552, 615818150, 3134207493, 3453421203, 1423857449, 601450431, 3009837614, 3294710456, 1567103746, 711928724, 3020668471, 3272380065, 1510334235, 755167117]
test_vectors = [(b'123456789', 3421780262)]
xor = 4294967295
class scapy.libs.crc.CRC_32_AUTOSAR(msg: bytes)[source]

Bases: CRC

init_crc = 4294967295
mask = 4294967295
name = 'CRC32 AUTOSAR'
param = <Param for CRC32 AUTOSAR poly= 0xf4acfb13, size= 32, init_crc= 0xffffffff, xor= 0xffffffff, reflect_input= 1, reflect_output= 1>
poly = 4104977171
reflect_input = True
reflect_output = True
size = 32
table = [0, 814026741, 1628053482, 1368330271, 3256106964, 4069601313, 2736660542, 2476421067, 362157559, 622008834, 1956383261, 1142490600, 3615631907, 3876005334, 3062379977, 2249013820, 724315118, 464069659, 1244017668, 2057518065, 3912766522, 3653049295, 2284981200, 3099001893, 1052392985, 239022572, 1605378547, 1865756166, 4239262157, 3425373752, 2644778535, 2904625618, 1448630236, 1725782057, 928139318, 131549123, 2488035336, 2764662781, 4115036130, 3317921815, 1137590827, 1934314974, 583294401, 306270772, 2178579967, 2975822346, 3771752981, 3495259616, 2104785970, 1307669447, 478045144, 754674733, 3210757094, 2414169107, 3731512332, 4008662009, 1759668677, 1483171376, 166229551, 963475930, 2868270609, 2591250916, 3422308859, 4219029006, 2897260472, 2620760141, 3451564114, 4248813479, 1856278636, 1579261849, 263098246, 1059815539, 3106323023, 2309207482, 3626804645, 3903433296, 2066908571, 1270319726, 439917169, 717067652, 2275181654, 3071904675, 3868629948, 3591607369, 1166588802, 1963832439, 612541544, 336047005, 2450166177, 2727321172, 4076899915, 3280306622, 1344188021, 1620812160, 823439775, 26328682, 4209571940, 3396204433, 2615338894, 2875713659, 956090288, 142198853, 1509349466, 1769199535, 4018072979, 3757826662, 2390028921, 3203530124, 761975367, 502259122, 1281412525, 2095432280, 3519337354, 3779189887, 2966342752, 2152448917, 332459102, 592831403, 1926951860, 1113586753, 3293759101, 4107782536, 2774063511, 2514343522, 105314729, 918812252, 1733092931, 1472850358, 3370071343, 4166662874, 2849319621, 2572166448, 181078779, 978191630, 1807815953, 1531189988, 3712557272, 3989581613, 3158523698, 2361798855, 526196492, 802689273, 2119631078, 1322389267, 3824361153, 3547730228, 2197356843, 2994474718, 568795413, 291647200, 1089289983, 1885876490, 4133817142, 3336570051, 2540639452, 2817137449, 879834338, 83114775, 1434135304, 1711154429, 2659672819, 2919394566, 4287462681, 3473437420, 1553161511, 1813402322, 1033454285, 219958584, 2333177604, 3147069681, 3927664878, 3667814171, 1225083088, 2038449957, 672094010, 411719887, 3047901469, 2234402536, 3567343351, 3827587330, 2009036489, 1195014460, 380987683, 640706262, 2688376042, 2427999007, 3241624320, 4054994165, 1646879550, 1387031755, 52657364, 866546465, 1685035671, 1424659810, 90539389, 903907976, 2793121091, 2533272246, 3346119337, 4160009564, 1912180576, 1098678421, 284397706, 544644991, 3018698932, 2204680001, 3538399070, 3798114475, 1329836409, 2143731340, 776580755, 516727142, 2371325613, 3184689496, 3965555015, 3705183922, 1523950734, 1783671675, 1004518244, 190493841, 2562825050, 2823066799, 4190864560, 3377367877, 842517835, 45269694, 1396560545, 1673059668, 4028887711, 3232169322, 2435444085, 2712461952, 664918204, 388290377, 1185662806, 1982777507, 3853903720, 3576752285, 2227173506, 3023763319, 421258917, 698280272, 2014443855, 1217722042, 3675249009, 3951744644, 3120940699, 2323695982, 210629458, 1007221927, 1837624504, 1560470349, 3466185862, 4263297907, 2945700716, 2669075609]
test_vectors = [(b'\x00\x00\x00\x00', 1874010688), (b'3"U\xaa\xbb\xcc\xdd\xee\xff', 2790929469)]
xor = 4294967295