comparison cutils/crcmod/python3/predefined.py @ 182:31d478ff4e09

Syced with latest additions to crcmod2: new predefined CRC-64 models
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 13 Jan 2025 15:52:26 +0100
parents d038f0a9ba49
children 5c5c0c5a7402
comparison
equal deleted inserted replaced
181:c4f737ec368c 182:31d478ff4e09
5 # of this software and associated documentation files (the "Software"), to deal 5 # of this software and associated documentation files (the "Software"), to deal
6 # in the Software without restriction, including without limitation the rights 6 # in the Software without restriction, including without limitation the rights
7 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 # copies of the Software, and to permit persons to whom the Software is 8 # copies of the Software, and to permit persons to whom the Software is
9 # furnished to do so, subject to the following conditions: 9 # furnished to do so, subject to the following conditions:
10 # 10 #
11 # The above copyright notice and this permission notice shall be included in 11 # The above copyright notice and this permission notice shall be included in
12 # all copies or substantial portions of the Software. 12 # all copies or substantial portions of the Software.
13 # 13 #
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 ''' 22 '''
23 crcmod.predefined defines some well-known CRC algorithms. 23 crcmod.predefined defines some well-known CRC algorithms.
24 24
25 To use it, e.g.: 25 To use it, e.g.:
26 import crcmod.predefined 26 import crcmod.predefined
27 27
28 crc32func = crcmod.predefined.mkPredefinedCrcFun("crc-32") 28 crc32func = crcmod.predefined.mkPredefinedCrcFun("crc-32")
29 crc32class = crcmod.predefined.PredefinedCrc("crc-32") 29 crc32class = crcmod.predefined.PredefinedCrc("crc-32")
30 30
31 crcmod.predefined.Crc is an alias for crcmod.predefined.PredefinedCrc 31 crcmod.predefined.Crc is an alias for crcmod.predefined.PredefinedCrc
32 But if doing 'from crc.predefined import *', only PredefinedCrc is imported. 32 But if doing 'from crc.predefined import *', only PredefinedCrc is imported.
41 ] 41 ]
42 42
43 REVERSE = True 43 REVERSE = True
44 NON_REVERSE = False 44 NON_REVERSE = False
45 45
46 #
46 # The following table defines the parameters of well-known CRC algorithms. 47 # The following table defines the parameters of well-known CRC algorithms.
47 # The "Check" value is the CRC for the ASCII byte sequence b"123456789". It 48 # The "Check" value is the CRC for the ASCII byte sequence b"123456789". It
48 # can be used for unit tests. 49 # can be used for unit tests.
50 #
51 # See also:
52 # - https://en.wikipedia.org/wiki/Cyclic_redundancy_check
53 # - https://reveng.sourceforge.io/crc-catalogue/all.htm
54 # - http://users.ece.cmu.edu/~koopman/crc/index.html
55 # - https://pycrc.org/models.html
56 # - https://github.com/marzooqy/anycrc
57 #
49 _crc_definitions_table = [ 58 _crc_definitions_table = [
50 # Name Identifier-name, Poly Reverse Init-value XOR-out Check 59 # Name Identifier-name, Poly Reverse Init-value XOR-out Check
51 [ 'crc-8', 'Crc8', 0x107, NON_REVERSE, 0x00, 0x00, 0xF4, ], 60 [ 'crc-8', 'Crc8', 0x107, NON_REVERSE, 0x00, 0x00, 0xF4, ],
52 [ 'crc-8-darc', 'Crc8Darc', 0x139, REVERSE, 0x00, 0x00, 0x15, ], 61 [ 'crc-8-darc', 'Crc8Darc', 0x139, REVERSE, 0x00, 0x00, 0x15, ],
53 [ 'crc-8-i-code', 'Crc8ICode', 0x11D, NON_REVERSE, 0xFD, 0x00, 0x7E, ], 62 [ 'crc-8-i-code', 'Crc8ICode', 0x11D, NON_REVERSE, 0xFD, 0x00, 0x7E, ],
94 [ 'jamcrc', 'CrcJamCrc', 0x104C11DB7, REVERSE, 0xFFFFFFFF, 0x00000000, 0x340BC6D9, ], 103 [ 'jamcrc', 'CrcJamCrc', 0x104C11DB7, REVERSE, 0xFFFFFFFF, 0x00000000, 0x340BC6D9, ],
95 [ 'xfer', 'CrcXfer', 0x1000000AF, NON_REVERSE, 0x00000000, 0x00000000, 0xBD0BE338, ], 104 [ 'xfer', 'CrcXfer', 0x1000000AF, NON_REVERSE, 0x00000000, 0x00000000, 0xBD0BE338, ],
96 105
97 # 64-bit 106 # 64-bit
98 # Name Identifier-name, Poly Reverse Init-value XOR-out Check 107 # Name Identifier-name, Poly Reverse Init-value XOR-out Check
99 [ 'crc-64', 'Crc64', 0x1000000000000001B, REVERSE, 0x0000000000000000, 0x0000000000000000, 0x46A5A9388A5BEFFE, ], 108 [ 'crc-64', 'Crc64', 0x1000000000000001B, REVERSE, 0x0000000000000000, 0x0000000000000000, 0x46A5A9388A5BEFFE, ], # ISO POLY
109 # See https://lwn.net/Articles/976030/ (MCRC64, used as CRC-64 in the Linux kernel)
110 [ 'crc-64-2', 'Crc64_2', 0x1000000000000001B, NON_REVERSE, 0x0000000000000000, 0x0000000000000000, 0xE4FFBEA588933790, ], # fag, ISO POLY
111 [ 'crc-64-go', 'Crc64Go', 0x1000000000000001B, REVERSE, 0x0000000000000000, 0xFFFFFFFFFFFFFFFF, 0xB90956C775A41001, ], # fag, ISO POLY
112 [ 'crc-64-ecma', 'Crc64Ecma', 0x142F0E1EBA9EA3693, NON_REVERSE, 0x0000000000000000, 0x0000000000000000, 0x6C40DF5F0B497347, ], # fag
100 [ 'crc-64-we', 'Crc64We', 0x142F0E1EBA9EA3693, NON_REVERSE, 0x0000000000000000, 0xFFFFFFFFFFFFFFFF, 0x62EC59E3F1A4F00A, ], 113 [ 'crc-64-we', 'Crc64We', 0x142F0E1EBA9EA3693, NON_REVERSE, 0x0000000000000000, 0xFFFFFFFFFFFFFFFF, 0x62EC59E3F1A4F00A, ],
101 [ 'crc-64-jones', 'Crc64Jones', 0x1AD93D23594C935A9, REVERSE, 0xFFFFFFFFFFFFFFFF, 0x0000000000000000, 0xCAA717168609F281, ], 114 [ 'crc-64-jones', 'Crc64Jones', 0x1AD93D23594C935A9, REVERSE, 0xFFFFFFFFFFFFFFFF, 0x0000000000000000, 0xCAA717168609F281, ],
115 [ 'crc-64-xz', 'Crc64Xz', 0x142F0E1EBA9EA3693, REVERSE, 0x0000000000000000, 0xFFFFFFFFFFFFFFFF, 0x995DC9BBDF1939FA, ], # fag, ECMA POLY
116 [ 'crc-64-redis', 'Crc64Redis', 0x1AD93D23594C935A9, REVERSE, 0x0000000000000000, 0x0000000000000000, 0xE9C6D914C4b8D9CA, ], # fag
102 ] 117 ]
103 118
104 119
105 def _simplify_name(name): 120 def _simplify_name(name):
106 """ 121 """