comparison cutils/crcmod/python2/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.
43 ] 43 ]
44 44
45 REVERSE = True 45 REVERSE = True
46 NON_REVERSE = False 46 NON_REVERSE = False
47 47
48 #
48 # The following table defines the parameters of well-known CRC algorithms. 49 # The following table defines the parameters of well-known CRC algorithms.
49 # The "Check" value is the CRC for the ASCII byte sequence "123456789". It 50 # The "Check" value is the CRC for the ASCII byte sequence "123456789". It
50 # can be used for unit tests. 51 # can be used for unit tests.
52 #
53 # See also:
54 # - https://en.wikipedia.org/wiki/Cyclic_redundancy_check
55 # - https://reveng.sourceforge.io/crc-catalogue/all.htm
56 # - http://users.ece.cmu.edu/~koopman/crc/index.html
57 # - https://pycrc.org/models.html
58 # - https://github.com/marzooqy/anycrc
59 #
51 _crc_definitions_table = [ 60 _crc_definitions_table = [
52 # Name Identifier-name, Poly Reverse Init-value XOR-out Check 61 # Name Identifier-name, Poly Reverse Init-value XOR-out Check
53 [ 'crc-8', 'Crc8', 0x107, NON_REVERSE, 0x00, 0x00, 0xF4, ], 62 [ 'crc-8', 'Crc8', 0x107, NON_REVERSE, 0x00, 0x00, 0xF4, ],
54 [ 'crc-8-darc', 'Crc8Darc', 0x139, REVERSE, 0x00, 0x00, 0x15, ], 63 [ 'crc-8-darc', 'Crc8Darc', 0x139, REVERSE, 0x00, 0x00, 0x15, ],
55 [ 'crc-8-i-code', 'Crc8ICode', 0x11D, NON_REVERSE, 0xFD, 0x00, 0x7E, ], 64 [ 'crc-8-i-code', 'Crc8ICode', 0x11D, NON_REVERSE, 0xFD, 0x00, 0x7E, ],
96 [ 'jamcrc', 'CrcJamCrc', 0x104C11DB7, REVERSE, 0xFFFFFFFF, 0x00000000, 0x340BC6D9, ], 105 [ 'jamcrc', 'CrcJamCrc', 0x104C11DB7, REVERSE, 0xFFFFFFFF, 0x00000000, 0x340BC6D9, ],
97 [ 'xfer', 'CrcXfer', 0x1000000AF, NON_REVERSE, 0x00000000, 0x00000000, 0xBD0BE338, ], 106 [ 'xfer', 'CrcXfer', 0x1000000AF, NON_REVERSE, 0x00000000, 0x00000000, 0xBD0BE338, ],
98 107
99 # 64-bit 108 # 64-bit
100 # Name Identifier-name, Poly Reverse Init-value XOR-out Check 109 # Name Identifier-name, Poly Reverse Init-value XOR-out Check
101 [ 'crc-64', 'Crc64', 0x1000000000000001B, REVERSE, 0x0000000000000000, 0x0000000000000000, 0x46A5A9388A5BEFFE, ], 110 [ 'crc-64', 'Crc64', 0x1000000000000001B, REVERSE, 0x0000000000000000, 0x0000000000000000, 0x46A5A9388A5BEFFE, ], # ISO POLY
111 # See https://lwn.net/Articles/976030/ (MCRC64, used as CRC-64 in the Linux kernel)
112 [ 'crc-64-2', 'Crc64_2', 0x1000000000000001B, NON_REVERSE, 0x0000000000000000, 0x0000000000000000, 0xE4FFBEA588933790, ], # fag, ISO POLY
113 [ 'crc-64-go', 'Crc64Go', 0x1000000000000001B, REVERSE, 0x0000000000000000, 0xFFFFFFFFFFFFFFFF, 0xB90956C775A41001, ], # fag, ISO POLY
114 [ 'crc-64-ecma', 'Crc64Ecma', 0x142F0E1EBA9EA3693, NON_REVERSE, 0x0000000000000000, 0x0000000000000000, 0x6C40DF5F0B497347, ], # fag
102 [ 'crc-64-we', 'Crc64We', 0x142F0E1EBA9EA3693, NON_REVERSE, 0x0000000000000000, 0xFFFFFFFFFFFFFFFF, 0x62EC59E3F1A4F00A, ], 115 [ 'crc-64-we', 'Crc64We', 0x142F0E1EBA9EA3693, NON_REVERSE, 0x0000000000000000, 0xFFFFFFFFFFFFFFFF, 0x62EC59E3F1A4F00A, ],
103 [ 'crc-64-jones', 'Crc64Jones', 0x1AD93D23594C935A9, REVERSE, 0xFFFFFFFFFFFFFFFF, 0x0000000000000000, 0xCAA717168609F281, ], 116 [ 'crc-64-jones', 'Crc64Jones', 0x1AD93D23594C935A9, REVERSE, 0xFFFFFFFFFFFFFFFF, 0x0000000000000000, 0xCAA717168609F281, ],
117 [ 'crc-64-xz', 'Crc64Xz', 0x142F0E1EBA9EA3693, REVERSE, 0x0000000000000000, 0xFFFFFFFFFFFFFFFF, 0x995DC9BBDF1939FA, ], # fag, ECMA POLY
118 [ 'crc-64-redis', 'Crc64Redis', 0x1AD93D23594C935A9, REVERSE, 0x0000000000000000, 0x0000000000000000, 0xE9C6D914C4b8D9CA, ], # fag
104 ] 119 ]
105 120
106 121
107 def _simplify_name(name): 122 def _simplify_name(name):
108 """ 123 """