nogil-crcmod 1.7a1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nogil_crcmod-1.7a1/LICENSE +22 -0
- nogil_crcmod-1.7a1/MANIFEST.in +9 -0
- nogil_crcmod-1.7a1/PKG-INFO +88 -0
- nogil_crcmod-1.7a1/README +124 -0
- nogil_crcmod-1.7a1/changelog +38 -0
- nogil_crcmod-1.7a1/docs/html/.buildinfo +4 -0
- nogil_crcmod-1.7a1/docs/html/_sources/crcmod.predefined.txt +164 -0
- nogil_crcmod-1.7a1/docs/html/_sources/crcmod.txt +219 -0
- nogil_crcmod-1.7a1/docs/html/_sources/index.txt +20 -0
- nogil_crcmod-1.7a1/docs/html/_sources/intro.txt +149 -0
- nogil_crcmod-1.7a1/docs/html/_static/basic.css +417 -0
- nogil_crcmod-1.7a1/docs/html/_static/default.css +218 -0
- nogil_crcmod-1.7a1/docs/html/_static/doctools.js +232 -0
- nogil_crcmod-1.7a1/docs/html/_static/file.png +0 -0
- nogil_crcmod-1.7a1/docs/html/_static/jquery.js +32 -0
- nogil_crcmod-1.7a1/docs/html/_static/minus.png +0 -0
- nogil_crcmod-1.7a1/docs/html/_static/plus.png +0 -0
- nogil_crcmod-1.7a1/docs/html/_static/pygments.css +61 -0
- nogil_crcmod-1.7a1/docs/html/_static/searchtools.js +467 -0
- nogil_crcmod-1.7a1/docs/html/crcmod.html +385 -0
- nogil_crcmod-1.7a1/docs/html/crcmod.predefined.html +567 -0
- nogil_crcmod-1.7a1/docs/html/genindex.html +173 -0
- nogil_crcmod-1.7a1/docs/html/index.html +131 -0
- nogil_crcmod-1.7a1/docs/html/intro.html +246 -0
- nogil_crcmod-1.7a1/docs/html/modindex.html +104 -0
- nogil_crcmod-1.7a1/docs/html/objects.inv +21 -0
- nogil_crcmod-1.7a1/docs/html/search.html +97 -0
- nogil_crcmod-1.7a1/docs/html/searchindex.js +1 -0
- nogil_crcmod-1.7a1/docs/source/Makefile +118 -0
- nogil_crcmod-1.7a1/docs/source/conf.py +237 -0
- nogil_crcmod-1.7a1/docs/source/crcmod.predefined.rst +164 -0
- nogil_crcmod-1.7a1/docs/source/crcmod.rst +219 -0
- nogil_crcmod-1.7a1/docs/source/index.rst +20 -0
- nogil_crcmod-1.7a1/docs/source/intro.rst +149 -0
- nogil_crcmod-1.7a1/docs/source/make.bat +137 -0
- nogil_crcmod-1.7a1/docs/source/make_predefined_table.py +45 -0
- nogil_crcmod-1.7a1/nogil_crcmod.egg-info/PKG-INFO +88 -0
- nogil_crcmod-1.7a1/nogil_crcmod.egg-info/SOURCES.txt +61 -0
- nogil_crcmod-1.7a1/nogil_crcmod.egg-info/dependency_links.txt +1 -0
- nogil_crcmod-1.7a1/nogil_crcmod.egg-info/top_level.txt +1 -0
- nogil_crcmod-1.7a1/python2/crcmod/__init__.py +8 -0
- nogil_crcmod-1.7a1/python2/crcmod/_crcfunpy.py +87 -0
- nogil_crcmod-1.7a1/python2/crcmod/crcmod.py +472 -0
- nogil_crcmod-1.7a1/python2/crcmod/predefined.py +162 -0
- nogil_crcmod-1.7a1/python2/crcmod/test.py +500 -0
- nogil_crcmod-1.7a1/python2/src/_crcfunext.c +501 -0
- nogil_crcmod-1.7a1/python3/crcmod/__init__.py +8 -0
- nogil_crcmod-1.7a1/python3/crcmod/__pycache__/__init__.cpython-314.pyc +0 -0
- nogil_crcmod-1.7a1/python3/crcmod/__pycache__/crcmod.cpython-314.pyc +0 -0
- nogil_crcmod-1.7a1/python3/crcmod/__pycache__/predefined.cpython-314.pyc +0 -0
- nogil_crcmod-1.7a1/python3/crcmod/__pycache__/test.cpython-314.pyc +0 -0
- nogil_crcmod-1.7a1/python3/crcmod/_crcfunext.cpython-314-x86_64-linux-gnu.so +0 -0
- nogil_crcmod-1.7a1/python3/crcmod/_crcfunext.cpython-314t-x86_64-linux-gnu.so +0 -0
- nogil_crcmod-1.7a1/python3/crcmod/_crcfunpy.py +107 -0
- nogil_crcmod-1.7a1/python3/crcmod/crcmod.py +457 -0
- nogil_crcmod-1.7a1/python3/crcmod/predefined.py +162 -0
- nogil_crcmod-1.7a1/python3/crcmod/test.py +540 -0
- nogil_crcmod-1.7a1/python3/src/_crcfunext.c +615 -0
- nogil_crcmod-1.7a1/setup.cfg +4 -0
- nogil_crcmod-1.7a1/setup.py +67 -0
- nogil_crcmod-1.7a1/test/__pycache__/test_crcmod.cpython-314-pytest-9.2.0.pyc +0 -0
- nogil_crcmod-1.7a1/test/examples.py +49 -0
- nogil_crcmod-1.7a1/test/test_crcmod.py +6 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
----------------------------------------------------------------------------
|
|
2
|
+
Copyright (c) 2010 Raymond L. Buvel
|
|
3
|
+
Copyright (c) 2010 Craig McQueen
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
----------------------------------------------------------------------------
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: nogil-crcmod
|
|
3
|
+
Version: 1.7a1
|
|
4
|
+
Summary: Experimental free-threaded/no-GIL build of crcmod - not production ready
|
|
5
|
+
Home-page: http://crcmod.sourceforge.net/
|
|
6
|
+
Download-URL: http://sourceforge.net/projects/crcmod
|
|
7
|
+
Author: Ray Buvel
|
|
8
|
+
Author-email: rlbuvel@gmail.com
|
|
9
|
+
License: MIT
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Intended Audience :: Education
|
|
13
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
14
|
+
Classifier: Intended Audience :: Information Technology
|
|
15
|
+
Classifier: Intended Audience :: Science/Research
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: C
|
|
19
|
+
Classifier: Programming Language :: C++
|
|
20
|
+
Classifier: Programming Language :: Python
|
|
21
|
+
Classifier: Programming Language :: Python :: 2
|
|
22
|
+
Classifier: Programming Language :: Python :: 2.4
|
|
23
|
+
Classifier: Programming Language :: Python :: 2.5
|
|
24
|
+
Classifier: Programming Language :: Python :: 2.6
|
|
25
|
+
Classifier: Programming Language :: Python :: 2.7
|
|
26
|
+
Classifier: Programming Language :: Python :: 3
|
|
27
|
+
Classifier: Programming Language :: Python :: 3.1
|
|
28
|
+
Classifier: Topic :: Communications
|
|
29
|
+
Classifier: Topic :: Scientific/Engineering :: Interface Engine/Protocol Translator
|
|
30
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
31
|
+
Classifier: Topic :: Utilities
|
|
32
|
+
Description-Content-Type: text/markdown
|
|
33
|
+
License-File: LICENSE
|
|
34
|
+
Dynamic: author
|
|
35
|
+
Dynamic: author-email
|
|
36
|
+
Dynamic: classifier
|
|
37
|
+
Dynamic: description
|
|
38
|
+
Dynamic: description-content-type
|
|
39
|
+
Dynamic: download-url
|
|
40
|
+
Dynamic: home-page
|
|
41
|
+
Dynamic: license
|
|
42
|
+
Dynamic: license-file
|
|
43
|
+
Dynamic: summary
|
|
44
|
+
|
|
45
|
+
# nogil-crcmod — experimental free-threaded build
|
|
46
|
+
|
|
47
|
+
> **EXPERIMENTAL / NOT PRODUCTION READY**
|
|
48
|
+
>
|
|
49
|
+
> This is an unofficial experimental free-threaded (no-GIL) build of
|
|
50
|
+
> `crcmod`. It is not affiliated with, endorsed by, or supported by the
|
|
51
|
+
> upstream maintainers. Do not deploy it in production without your own review
|
|
52
|
+
> and testing.
|
|
53
|
+
|
|
54
|
+
## 中文说明
|
|
55
|
+
|
|
56
|
+
`nogil-crcmod` 是 `crcmod` 的**非官方实验性 free-threaded/no-GIL 构建**,
|
|
57
|
+
仅用于 CPython 3.14t 上的评估、测试和迁移研究。
|
|
58
|
+
|
|
59
|
+
- **不是生产版本**,不提供可用性、兼容性或安全性保证;
|
|
60
|
+
- 与上游项目无隶属或背书关系;
|
|
61
|
+
- 可能存在平台限制、线程契约变化、已知 debug 构建失败或外部库依赖;
|
|
62
|
+
- 使用前请阅读本包的 `NOGIL.md` / 迁移报告并自行测试;
|
|
63
|
+
- 问题请记录在本项目的私有 Gitee 仓库,不要当作上游问题。
|
|
64
|
+
|
|
65
|
+
## English
|
|
66
|
+
|
|
67
|
+
`nogil-crcmod` is an **unofficial experimental free-threaded/no-GIL build** of
|
|
68
|
+
`crcmod`, intended only for evaluation, testing, and migration research on
|
|
69
|
+
CPython 3.14t.
|
|
70
|
+
|
|
71
|
+
- **Not production-ready**; no availability, compatibility, or security warranty;
|
|
72
|
+
- Not affiliated with or endorsed by upstream;
|
|
73
|
+
- May have platform restrictions, changed threading contracts, known debug-build
|
|
74
|
+
failures, or external library dependencies;
|
|
75
|
+
- Read `NOGIL.md` / the migration report and test it yourself before use;
|
|
76
|
+
- Report issues in this project's private Gitee repository, not upstream.
|
|
77
|
+
|
|
78
|
+
## Scope and limitations
|
|
79
|
+
|
|
80
|
+
- Primary target: CPython 3.14t, Linux x86_64.
|
|
81
|
+
- Experimental `cp314t` ABI; no stable-ABI promise.
|
|
82
|
+
- ARM64/3.13t/3.15t are not covered unless explicitly tested.
|
|
83
|
+
- External native libraries may be required and are not bundled.
|
|
84
|
+
- See `known-issues.md` and the independent review for exact per-package status.
|
|
85
|
+
|
|
86
|
+
## License
|
|
87
|
+
|
|
88
|
+
MIT. The upstream license text is preserved in `LICENSE` / `COPYING`.
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
===========================
|
|
2
|
+
crcmod for Calculating CRCs
|
|
3
|
+
===========================
|
|
4
|
+
|
|
5
|
+
The software in this package is a Python module for generating objects that
|
|
6
|
+
compute the Cyclic Redundancy Check (CRC). There is no attempt in this package
|
|
7
|
+
to explain how the CRC works. There are a number of resources on the web that
|
|
8
|
+
give a good explanation of the algorithms. Just do a Google search for "crc
|
|
9
|
+
calculation" and browse till you find what you need. Another resource can be
|
|
10
|
+
found in chapter 20 of the book "Numerical Recipes in C" by Press et. al.
|
|
11
|
+
|
|
12
|
+
This package allows the use of any 8, 16, 24, 32, or 64 bit CRC. You can
|
|
13
|
+
generate a Python function for the selected polynomial or an instance of the
|
|
14
|
+
Crc class which provides the same interface as the ``md5`` and ``sha`` modules
|
|
15
|
+
from the Python standard library. A ``Crc`` class instance can also generate
|
|
16
|
+
C/C++ source code that can be used in another application.
|
|
17
|
+
|
|
18
|
+
----------
|
|
19
|
+
Guidelines
|
|
20
|
+
----------
|
|
21
|
+
|
|
22
|
+
Documentation is available from the doc strings. It is up to you to decide
|
|
23
|
+
what polynomials to use in your application. If someone has not specified the
|
|
24
|
+
polynomials to use, you will need to do some research to find one suitable for
|
|
25
|
+
your application. Examples are available in the unit test script ``test.py``.
|
|
26
|
+
You may also use the ``predefined`` module to select one of the standard
|
|
27
|
+
polynomials.
|
|
28
|
+
|
|
29
|
+
If you need to generate code for another language, I suggest you subclass the
|
|
30
|
+
``Crc`` class and replace the method ``generateCode``. Use ``generateCode`` as
|
|
31
|
+
a model for the new version.
|
|
32
|
+
|
|
33
|
+
------------
|
|
34
|
+
Dependencies
|
|
35
|
+
------------
|
|
36
|
+
|
|
37
|
+
Python Version
|
|
38
|
+
^^^^^^^^^^^^^^
|
|
39
|
+
|
|
40
|
+
The package has separate code to support the 2.x and 3.x Python series.
|
|
41
|
+
|
|
42
|
+
For the 2.x versions of Python, these versions have been tested:
|
|
43
|
+
|
|
44
|
+
* 2.4
|
|
45
|
+
* 2.5
|
|
46
|
+
* 2.6
|
|
47
|
+
* 2.7
|
|
48
|
+
|
|
49
|
+
It may still work on earlier versions of Python 2.x, but these have not been
|
|
50
|
+
recently tested.
|
|
51
|
+
|
|
52
|
+
For the 3.x versions of Python, these versions have been tested:
|
|
53
|
+
|
|
54
|
+
* 3.1
|
|
55
|
+
|
|
56
|
+
Building C extension
|
|
57
|
+
^^^^^^^^^^^^^^^^^^^^
|
|
58
|
+
|
|
59
|
+
To build the C extension, the appropriate compiler tools for your platform must
|
|
60
|
+
be installed. Refer to the Python documentation for building C extensions for
|
|
61
|
+
details.
|
|
62
|
+
|
|
63
|
+
------------
|
|
64
|
+
Installation
|
|
65
|
+
------------
|
|
66
|
+
|
|
67
|
+
The crcmod package is installed using ``distutils``.
|
|
68
|
+
Run the following command::
|
|
69
|
+
|
|
70
|
+
python setup.py install
|
|
71
|
+
|
|
72
|
+
If the extension module builds, it will be installed. Otherwise, the
|
|
73
|
+
installation will include the pure Python version. This will run significantly
|
|
74
|
+
slower than the extension module but will allow the package to be used.
|
|
75
|
+
|
|
76
|
+
For Windows users who want to use the mingw32 compiler, run this command::
|
|
77
|
+
|
|
78
|
+
python setup.py build --compiler=mingw32 install
|
|
79
|
+
|
|
80
|
+
For Python 3.x, the install process is the same but you need to use the 3.x
|
|
81
|
+
interpreter.
|
|
82
|
+
|
|
83
|
+
------------
|
|
84
|
+
Unit Testing
|
|
85
|
+
------------
|
|
86
|
+
|
|
87
|
+
The ``crcmod`` package has a module ``crcmod.test``, which contains unit
|
|
88
|
+
tests for both ``crcmod`` and ``crcmod.predefined``.
|
|
89
|
+
|
|
90
|
+
When you first install ``crcmod``, you should run the unit tests to make sure
|
|
91
|
+
everything is installed properly. The test script performs a number of tests
|
|
92
|
+
including a comparison to the direct method which uses a class implementing
|
|
93
|
+
polynomials over the integers mod 2.
|
|
94
|
+
|
|
95
|
+
To run the unit tests on Python >=2.5::
|
|
96
|
+
|
|
97
|
+
python -m crcmod.test
|
|
98
|
+
|
|
99
|
+
Alternatively, in the ``test`` directory run::
|
|
100
|
+
|
|
101
|
+
python test_crcmod.py
|
|
102
|
+
|
|
103
|
+
---------------
|
|
104
|
+
Code Generation
|
|
105
|
+
---------------
|
|
106
|
+
|
|
107
|
+
The crcmod package is capable of generating C functions that can be compiled
|
|
108
|
+
with a C or C++ compiler. In the test directory, there is an examples.py
|
|
109
|
+
script that demonstrates how to use the code generator. The result of this is
|
|
110
|
+
written out to the file ``examples.c``. The generated code was checked to make
|
|
111
|
+
sure it compiles with the GCC compiler.
|
|
112
|
+
|
|
113
|
+
-------
|
|
114
|
+
License
|
|
115
|
+
-------
|
|
116
|
+
|
|
117
|
+
The ``crcmod`` package is released under the MIT license. See the ``LICENSE``
|
|
118
|
+
file for details.
|
|
119
|
+
|
|
120
|
+
------------
|
|
121
|
+
Contributors
|
|
122
|
+
------------
|
|
123
|
+
|
|
124
|
+
Craig McQueen
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
1.7 Enhancement Release - Jun 27, 2010
|
|
2
|
+
|
|
3
|
+
* Improve the installation process.
|
|
4
|
+
* For Python3 don't allow unicode and require an object that supports the
|
|
5
|
+
buffer interface.
|
|
6
|
+
* Added Sphinx documentation.
|
|
7
|
+
* Added LICENSE file.
|
|
8
|
+
|
|
9
|
+
1.6.1 Enhancement Release - Mar 7, 2010
|
|
10
|
+
|
|
11
|
+
Enhancements made by Craig McQueen
|
|
12
|
+
|
|
13
|
+
* Code cleanup
|
|
14
|
+
* Updated database of pre-defined CRC algorithms
|
|
15
|
+
|
|
16
|
+
1.6 Enhancement Release - Jan 24, 2010
|
|
17
|
+
|
|
18
|
+
Enhancements made by Craig McQueen
|
|
19
|
+
|
|
20
|
+
* Added XOR out feature to allow creation of standard CRC algorithms
|
|
21
|
+
* Added a database of pre-defined CRC algorithms
|
|
22
|
+
|
|
23
|
+
1.5 Enhancement Release - Mar 7, 2009
|
|
24
|
+
|
|
25
|
+
* Added Python 3.x version.
|
|
26
|
+
* Upgraded some unit tests.
|
|
27
|
+
|
|
28
|
+
1.4 Enhancement Release - Jul 28, 2007
|
|
29
|
+
|
|
30
|
+
* Add 24-bit CRCs as one of the options.
|
|
31
|
+
|
|
32
|
+
1.3 Enhancement Release - Apr 22, 2006
|
|
33
|
+
|
|
34
|
+
* Make compatible with Python 2.5 on 64-bit platforms.
|
|
35
|
+
* Improve the install procedure.
|
|
36
|
+
|
|
37
|
+
1.2 Initial Public Release - Jul 10, 2004
|
|
38
|
+
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
|
|
2
|
+
:mod:`crcmod.predefined` -- CRC calculation using predefined algorithms
|
|
3
|
+
=======================================================================
|
|
4
|
+
|
|
5
|
+
.. module:: crcmod.predefined
|
|
6
|
+
:synopsis: CRC calculation using predefined algorithms
|
|
7
|
+
.. moduleauthor:: Craig McQueen
|
|
8
|
+
.. sectionauthor:: Craig McQueen
|
|
9
|
+
|
|
10
|
+
This module provides a function factory :func:`mkPredefinedCrcFun` and a class :class:`PredefinedCrc`
|
|
11
|
+
for calculating CRCs of byte strings using common predefined CRC algorithms.
|
|
12
|
+
|
|
13
|
+
The function factory and the class are very similar to those defined in :mod:`crcmod`,
|
|
14
|
+
except that the CRC algorithm is specified by a predefined name, rather than the
|
|
15
|
+
individual polynomial, reflection, and initial and final-XOR parameters.
|
|
16
|
+
|
|
17
|
+
Predefined CRC algorithms
|
|
18
|
+
-------------------------
|
|
19
|
+
|
|
20
|
+
The :mod:`crcmod.predefined` module offers the following predefined algorithms:
|
|
21
|
+
|
|
22
|
+
================================ ====================== ========== ==================== ==================== ====================
|
|
23
|
+
Name Polynomial Reversed? Init-value XOR-out Check
|
|
24
|
+
================================ ====================== ========== ==================== ==================== ====================
|
|
25
|
+
``crc-8`` 0x107 False 0x00 0x00 0xF4
|
|
26
|
+
``crc-8-darc`` 0x139 True 0x00 0x00 0x15
|
|
27
|
+
``crc-8-i-code`` 0x11D False 0xFD 0x00 0x7E
|
|
28
|
+
``crc-8-itu`` 0x107 False 0x55 0x55 0xA1
|
|
29
|
+
``crc-8-maxim`` 0x131 True 0x00 0x00 0xA1
|
|
30
|
+
``crc-8-rohc`` 0x107 True 0xFF 0x00 0xD0
|
|
31
|
+
``crc-8-wcdma`` 0x19B True 0x00 0x00 0x25
|
|
32
|
+
``crc-16`` 0x18005 True 0x0000 0x0000 0xBB3D
|
|
33
|
+
``crc-16-buypass`` 0x18005 False 0x0000 0x0000 0xFEE8
|
|
34
|
+
``crc-16-dds-110`` 0x18005 False 0x800D 0x0000 0x9ECF
|
|
35
|
+
``crc-16-dect`` 0x10589 False 0x0001 0x0001 0x007E
|
|
36
|
+
``crc-16-dnp`` 0x13D65 True 0xFFFF 0xFFFF 0xEA82
|
|
37
|
+
``crc-16-en-13757`` 0x13D65 False 0xFFFF 0xFFFF 0xC2B7
|
|
38
|
+
``crc-16-genibus`` 0x11021 False 0x0000 0xFFFF 0xD64E
|
|
39
|
+
``crc-16-maxim`` 0x18005 True 0xFFFF 0xFFFF 0x44C2
|
|
40
|
+
``crc-16-mcrf4xx`` 0x11021 True 0xFFFF 0x0000 0x6F91
|
|
41
|
+
``crc-16-riello`` 0x11021 True 0x554D 0x0000 0x63D0
|
|
42
|
+
``crc-16-t10-dif`` 0x18BB7 False 0x0000 0x0000 0xD0DB
|
|
43
|
+
``crc-16-teledisk`` 0x1A097 False 0x0000 0x0000 0x0FB3
|
|
44
|
+
``crc-16-usb`` 0x18005 True 0x0000 0xFFFF 0xB4C8
|
|
45
|
+
``x-25`` 0x11021 True 0x0000 0xFFFF 0x906E
|
|
46
|
+
``xmodem`` 0x11021 False 0x0000 0x0000 0x31C3
|
|
47
|
+
``modbus`` 0x18005 True 0xFFFF 0x0000 0x4B37
|
|
48
|
+
``kermit`` [#ccitt]_ 0x11021 True 0x0000 0x0000 0x2189
|
|
49
|
+
``crc-ccitt-false`` [#ccitt]_ 0x11021 False 0xFFFF 0x0000 0x29B1
|
|
50
|
+
``crc-aug-ccitt`` [#ccitt]_ 0x11021 False 0x1D0F 0x0000 0xE5CC
|
|
51
|
+
``crc-24`` 0x1864CFB False 0xB704CE 0x000000 0x21CF02
|
|
52
|
+
``crc-24-flexray-a`` 0x15D6DCB False 0xFEDCBA 0x000000 0x7979BD
|
|
53
|
+
``crc-24-flexray-b`` 0x15D6DCB False 0xABCDEF 0x000000 0x1F23B8
|
|
54
|
+
``crc-32`` 0x104C11DB7 True 0x00000000 0xFFFFFFFF 0xCBF43926
|
|
55
|
+
``crc-32-bzip2`` 0x104C11DB7 False 0x00000000 0xFFFFFFFF 0xFC891918
|
|
56
|
+
``crc-32c`` 0x11EDC6F41 True 0x00000000 0xFFFFFFFF 0xE3069283
|
|
57
|
+
``crc-32d`` 0x1A833982B True 0x00000000 0xFFFFFFFF 0x87315576
|
|
58
|
+
``crc-32-mpeg`` 0x104C11DB7 False 0xFFFFFFFF 0x00000000 0x0376E6E7
|
|
59
|
+
``posix`` 0x104C11DB7 False 0xFFFFFFFF 0xFFFFFFFF 0x765E7680
|
|
60
|
+
``crc-32q`` 0x1814141AB False 0x00000000 0x00000000 0x3010BF7F
|
|
61
|
+
``jamcrc`` 0x104C11DB7 True 0xFFFFFFFF 0x00000000 0x340BC6D9
|
|
62
|
+
``xfer`` 0x1000000AF False 0x00000000 0x00000000 0xBD0BE338
|
|
63
|
+
``crc-64`` 0x1000000000000001B True 0x0000000000000000 0x0000000000000000 0x46A5A9388A5BEFFE
|
|
64
|
+
``crc-64-we`` 0x142F0E1EBA9EA3693 False 0x0000000000000000 0xFFFFFFFFFFFFFFFF 0x62EC59E3F1A4F00A
|
|
65
|
+
``crc-64-jones`` 0x1AD93D23594C935A9 True 0xFFFFFFFFFFFFFFFF 0x0000000000000000 0xCAA717168609F281
|
|
66
|
+
================================ ====================== ========== ==================== ==================== ====================
|
|
67
|
+
|
|
68
|
+
.. rubric:: Notes
|
|
69
|
+
|
|
70
|
+
.. [#ccitt] Definitions of CCITT are disputable. See:
|
|
71
|
+
|
|
72
|
+
* http://homepages.tesco.net/~rainstorm/crc-catalogue.htm
|
|
73
|
+
* http://web.archive.org/web/20071229021252/http://www.joegeluso.com/software/articles/ccitt.htm
|
|
74
|
+
|
|
75
|
+
:func:`mkPredefinedCrcFun` -- CRC function factory
|
|
76
|
+
--------------------------------------------------
|
|
77
|
+
|
|
78
|
+
The function factory provides a simple interface for CRC calculation. It is similar
|
|
79
|
+
to :func:`crcmod.mkCrcFun`, except that it specifies a CRC algorithm by name rather
|
|
80
|
+
than its parameters.
|
|
81
|
+
|
|
82
|
+
.. function:: mkPredefinedCrcFun(crc_name)
|
|
83
|
+
|
|
84
|
+
Function factory that returns a new function for calculating CRCs
|
|
85
|
+
using a specified CRC algorithm.
|
|
86
|
+
|
|
87
|
+
:param crc_name: The name of the predefined CRC algorithm to use.
|
|
88
|
+
:type crc_name: string
|
|
89
|
+
|
|
90
|
+
:return: CRC calculation function
|
|
91
|
+
:rtype: function
|
|
92
|
+
|
|
93
|
+
The function that is returned is the same as that returned by :func:`crcmod.mkCrcFun`:
|
|
94
|
+
|
|
95
|
+
.. function:: .crc_function(data[, crc=initCrc])
|
|
96
|
+
|
|
97
|
+
:param data: Data for which to calculate the CRC.
|
|
98
|
+
:type data: byte string
|
|
99
|
+
|
|
100
|
+
:param crc: Initial CRC value.
|
|
101
|
+
|
|
102
|
+
:return: Calculated CRC value.
|
|
103
|
+
:rtype: integer
|
|
104
|
+
|
|
105
|
+
.. function:: mkCrcFun(crc_name)
|
|
106
|
+
|
|
107
|
+
This is an alias for :func:`crcmod.predefined.mkPredefinedCrcFun`. However, it is not defined when
|
|
108
|
+
:mod:`crcmod.predefined` is imported using the form::
|
|
109
|
+
|
|
110
|
+
>>> from crcmod.predefined import *
|
|
111
|
+
|
|
112
|
+
Examples
|
|
113
|
+
^^^^^^^^
|
|
114
|
+
|
|
115
|
+
**CRC-32** example::
|
|
116
|
+
|
|
117
|
+
>>> import crcmod.predefined
|
|
118
|
+
|
|
119
|
+
>>> crc32_func = crcmod.predefined.mkCrcFun('crc-32')
|
|
120
|
+
>>> hex(crc32_func('123456789'))
|
|
121
|
+
'0xcbf43926L'
|
|
122
|
+
|
|
123
|
+
**XMODEM** example::
|
|
124
|
+
|
|
125
|
+
>>> xmodem_crc_func = crcmod.predefined.mkCrcFun('xmodem')
|
|
126
|
+
>>> hex(xmodem_crc_func('123456789'))
|
|
127
|
+
'0x31c3'
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
Class :class:`PredefinedCrc`
|
|
131
|
+
----------------------------
|
|
132
|
+
|
|
133
|
+
This class is inherited from the :class:`crcmod.Crc` class, and is the same except for the
|
|
134
|
+
initialization. It specifies a CRC algorithm by name rather than its parameters.
|
|
135
|
+
|
|
136
|
+
.. class:: PredefinedCrc(crc_name)
|
|
137
|
+
|
|
138
|
+
Returns a new :class:`Crc` object for calculating CRCs using a specified CRC algorithm.
|
|
139
|
+
|
|
140
|
+
The parameter is the same as that for the factory function :func:`crcmod.predefined.mkPredefinedCrcFun`.
|
|
141
|
+
|
|
142
|
+
:param crc_name: The name of the predefined CRC algorithm to use.
|
|
143
|
+
:type crc_name: string
|
|
144
|
+
|
|
145
|
+
.. class:: Crc(poly[, initCrc, rev, xorOut])
|
|
146
|
+
|
|
147
|
+
This is an alias for :class:`crcmod.predefined.PredefinedCrc`. However, it is not defined when
|
|
148
|
+
:mod:`crcmod.predefined` is imported using the form::
|
|
149
|
+
|
|
150
|
+
>>> from crcmod.predefined import *
|
|
151
|
+
|
|
152
|
+
Examples
|
|
153
|
+
^^^^^^^^
|
|
154
|
+
|
|
155
|
+
**CRC-32** Example::
|
|
156
|
+
|
|
157
|
+
>>> import crcmod.predefined
|
|
158
|
+
|
|
159
|
+
>>> crc32 = crcmod.predefined.Crc('crc-32')
|
|
160
|
+
>>> crc32.update('123456789')
|
|
161
|
+
>>> hex(crc32.crcValue)
|
|
162
|
+
'0xcbf43926L'
|
|
163
|
+
>>> crc32.hexdigest()
|
|
164
|
+
'CBF43926'
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
|
|
2
|
+
:mod:`crcmod` -- CRC calculation
|
|
3
|
+
================================
|
|
4
|
+
|
|
5
|
+
.. module:: crcmod
|
|
6
|
+
:synopsis: CRC calculation
|
|
7
|
+
.. moduleauthor:: Raymond L Buvel
|
|
8
|
+
.. sectionauthor:: Craig McQueen
|
|
9
|
+
|
|
10
|
+
This module provides a function factory :func:`mkCrcFun` and a class :class:`Crc`
|
|
11
|
+
for calculating CRCs of byte strings using common CRC algorithms.
|
|
12
|
+
|
|
13
|
+
.. note:: This documentation normally shows Python 2.x usage. Python 3.x usage is very similar,
|
|
14
|
+
with the main difference that input strings must be explicitly defined as
|
|
15
|
+
:keyword:`bytes` type, or an object that supports the buffer protocol. E.g.::
|
|
16
|
+
|
|
17
|
+
>>> crc_value = crc_function(b'123456789')
|
|
18
|
+
|
|
19
|
+
>>> crc_value = crc_function(bytearray((49, 50, 51, 52, 53, 54, 55, 56, 57)))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
:func:`mkCrcFun` -- CRC function factory
|
|
23
|
+
----------------------------------------
|
|
24
|
+
|
|
25
|
+
The function factory provides a simple interface for CRC calculation.
|
|
26
|
+
|
|
27
|
+
.. function:: mkCrcFun(poly[, initCrc, rev, xorOut])
|
|
28
|
+
|
|
29
|
+
Function factory that returns a new function for calculating CRCs
|
|
30
|
+
using a specified CRC algorithm.
|
|
31
|
+
|
|
32
|
+
:param poly: The generator polynomial to use in calculating the CRC. The value
|
|
33
|
+
is specified as a Python integer or long integer. The bits in this integer
|
|
34
|
+
are the coefficients of the polynomial. The only polynomials allowed are
|
|
35
|
+
those that generate 8, 16, 24, 32, or 64 bit CRCs.
|
|
36
|
+
|
|
37
|
+
:param initCrc: Initial value used to start the CRC calculation. This initial
|
|
38
|
+
value should be the initial shift register value, reversed if it uses a
|
|
39
|
+
reversed algorithm, and then XORed with the final XOR value. That is
|
|
40
|
+
equivalent to the CRC result the algorithm should return for a
|
|
41
|
+
zero-length string. Defaults to all bits set because that starting value
|
|
42
|
+
will take leading zero bytes into account. Starting with zero will ignore
|
|
43
|
+
all leading zero bytes.
|
|
44
|
+
|
|
45
|
+
:param rev: A flag that selects a bit reversed algorithm when :keyword:`True`. Defaults to
|
|
46
|
+
:keyword:`True` because the bit reversed algorithms are more efficient.
|
|
47
|
+
|
|
48
|
+
:param xorOut: Final value to XOR with the calculated CRC value. Used by some
|
|
49
|
+
CRC algorithms. Defaults to zero.
|
|
50
|
+
|
|
51
|
+
:return: CRC calculation function
|
|
52
|
+
:rtype: function
|
|
53
|
+
|
|
54
|
+
The function that is returned is as follows:
|
|
55
|
+
|
|
56
|
+
.. function:: .crc_function(data[, crc=initCrc])
|
|
57
|
+
|
|
58
|
+
:param data: Data for which to calculate the CRC.
|
|
59
|
+
:type data: byte string
|
|
60
|
+
|
|
61
|
+
:param crc: Initial CRC value.
|
|
62
|
+
|
|
63
|
+
:return: Calculated CRC value.
|
|
64
|
+
:rtype: integer
|
|
65
|
+
|
|
66
|
+
Examples
|
|
67
|
+
^^^^^^^^
|
|
68
|
+
|
|
69
|
+
**CRC-32** Example::
|
|
70
|
+
|
|
71
|
+
>>> import crcmod
|
|
72
|
+
|
|
73
|
+
>>> crc32_func = crcmod.mkCrcFun(0x104c11db7, initCrc=0, xorOut=0xFFFFFFFF)
|
|
74
|
+
>>> hex(crc32_func('123456789'))
|
|
75
|
+
'0xcbf43926L'
|
|
76
|
+
|
|
77
|
+
The CRC-32 uses a "reversed" algorithm, used for many common CRC algorithms.
|
|
78
|
+
Less common is the non-reversed algorithm, as used by the 16-bit **XMODEM** CRC::
|
|
79
|
+
|
|
80
|
+
>>> xmodem_crc_func = crcmod.mkCrcFun(0x11021, rev=False, initCrc=0x0000, xorOut=0x0000)
|
|
81
|
+
>>> hex(xmodem_crc_func('123456789'))
|
|
82
|
+
'0x31c3'
|
|
83
|
+
|
|
84
|
+
The CRC function can be called multiple times. On subsequent calls, pass the
|
|
85
|
+
CRC value previously calculated as a second parameter::
|
|
86
|
+
|
|
87
|
+
>>> crc_value = crc32_func('1234')
|
|
88
|
+
>>> crc_value = crc32_func('56789', crc_value)
|
|
89
|
+
>>> hex(crc_value)
|
|
90
|
+
'0xcbf43926L'
|
|
91
|
+
|
|
92
|
+
Python 3.x example: Unicode strings are not accepted as input. Byte strings are acceptable.
|
|
93
|
+
You may calculate a CRC for an object that implements the buffer protocol::
|
|
94
|
+
|
|
95
|
+
>>> import crcmod
|
|
96
|
+
>>> crc32_func = crcmod.mkCrcFun(0x104c11db7, initCrc=0, xorOut=0xFFFFFFFF)
|
|
97
|
+
>>> hex(crc32_func('123456789'))
|
|
98
|
+
...
|
|
99
|
+
TypeError: Unicode-objects must be encoded before calculating a CRC
|
|
100
|
+
>>> hex(crc32_func(b'123456789'))
|
|
101
|
+
'0xcbf43926'
|
|
102
|
+
>>> hex(crc32_func(bytearray((49, 50, 51, 52, 53, 54, 55, 56, 57))))
|
|
103
|
+
'0xcbf43926'
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
Class :class:`Crc`
|
|
107
|
+
------------------
|
|
108
|
+
|
|
109
|
+
The class provides an interface similar to the Python :mod:`hashlib`, :mod:`md5` and :mod:`sha` modules.
|
|
110
|
+
|
|
111
|
+
.. class:: Crc(poly[, initCrc, rev, xorOut])
|
|
112
|
+
|
|
113
|
+
Returns a new :class:`Crc` object for calculating CRCs using a specified CRC algorithm.
|
|
114
|
+
|
|
115
|
+
The parameters are the same as those for the factory function :func:`mkCrcFun`.
|
|
116
|
+
|
|
117
|
+
:param poly: The generator polynomial to use in calculating the CRC. The value
|
|
118
|
+
is specified as a Python integer or long integer. The bits in this integer
|
|
119
|
+
are the coefficients of the polynomial. The only polynomials allowed are
|
|
120
|
+
those that generate 8, 16, 24, 32, or 64 bit CRCs.
|
|
121
|
+
|
|
122
|
+
:param initCrc: Initial value used to start the CRC calculation. This initial
|
|
123
|
+
value should be the initial shift register value, reversed if it uses a
|
|
124
|
+
reversed algorithm, and then XORed with the final XOR value. That is
|
|
125
|
+
equivalent to the CRC result the algorithm should return for a
|
|
126
|
+
zero-length string. Defaults to all bits set because that starting value
|
|
127
|
+
will take leading zero bytes into account. Starting with zero will ignore
|
|
128
|
+
all leading zero bytes.
|
|
129
|
+
|
|
130
|
+
:param rev: A flag that selects a bit reversed algorithm when :keyword:`True`. Defaults to
|
|
131
|
+
:keyword:`True` because the bit reversed algorithms are more efficient.
|
|
132
|
+
|
|
133
|
+
:param xorOut: Final value to XOR with the calculated CRC value. Used by some
|
|
134
|
+
CRC algorithms. Defaults to zero.
|
|
135
|
+
|
|
136
|
+
:class:`Crc` objects contain the following constant values:
|
|
137
|
+
|
|
138
|
+
.. attribute:: digest_size
|
|
139
|
+
|
|
140
|
+
The size of the resulting digest in bytes. This depends on the width of the CRC polynomial.
|
|
141
|
+
E.g. for a 32-bit CRC, :data:`digest_size` will be ``4``.
|
|
142
|
+
|
|
143
|
+
.. attribute:: crcValue
|
|
144
|
+
|
|
145
|
+
The calculated CRC value, as an integer, for the data that has been input
|
|
146
|
+
using :meth:`update`. This value is updated after each call to :meth:`update`.
|
|
147
|
+
|
|
148
|
+
:class:`Crc` objects support the following methods:
|
|
149
|
+
|
|
150
|
+
.. method:: new([arg])
|
|
151
|
+
|
|
152
|
+
Create a new instance of the :class:`Crc` class initialized to the same
|
|
153
|
+
values as the original instance. The CRC value is set to the initial
|
|
154
|
+
value. If a string is provided in the optional ``arg`` parameter, it is
|
|
155
|
+
passed to the :meth:`update` method.
|
|
156
|
+
|
|
157
|
+
.. method:: copy()
|
|
158
|
+
|
|
159
|
+
Create a new instance of the :class:`Crc` class initialized to the same
|
|
160
|
+
values as the original instance. The CRC value is copied from the current
|
|
161
|
+
value. This allows multiple CRC calculations using a common initial
|
|
162
|
+
string.
|
|
163
|
+
|
|
164
|
+
.. method:: update(data)
|
|
165
|
+
|
|
166
|
+
:param data: Data for which to calculate the CRC
|
|
167
|
+
:type data: byte string
|
|
168
|
+
|
|
169
|
+
Update the calculated CRC value for the specified input data.
|
|
170
|
+
|
|
171
|
+
.. method:: digest()
|
|
172
|
+
|
|
173
|
+
Return the current CRC value as a string of bytes. The length of
|
|
174
|
+
this string is specified in the :attr:`digest_size` attribute.
|
|
175
|
+
|
|
176
|
+
.. method:: hexdigest()
|
|
177
|
+
|
|
178
|
+
Return the current CRC value as a string of hex digits. The length
|
|
179
|
+
of this string is twice the :attr:`digest_size` attribute.
|
|
180
|
+
|
|
181
|
+
.. method:: generateCode(functionName, out, [dataType, crcType])
|
|
182
|
+
|
|
183
|
+
Generate a C/C++ function.
|
|
184
|
+
|
|
185
|
+
:param functionName: String specifying the name of the function.
|
|
186
|
+
|
|
187
|
+
:param out: An open file-like object with a write method.
|
|
188
|
+
This specifies where the generated code is written.
|
|
189
|
+
|
|
190
|
+
:param dataType: An optional parameter specifying the data type of the input
|
|
191
|
+
data to the function. Defaults to ``UINT8``.
|
|
192
|
+
|
|
193
|
+
:param crcType: An optional parameter specifying the data type of the CRC value.
|
|
194
|
+
Defaults to one of ``UINT8``, ``UINT16``, ``UINT32``, or ``UINT64`` depending
|
|
195
|
+
on the size of the CRC value.
|
|
196
|
+
|
|
197
|
+
Examples
|
|
198
|
+
^^^^^^^^
|
|
199
|
+
|
|
200
|
+
**CRC-32** Example::
|
|
201
|
+
|
|
202
|
+
>>> import crcmod
|
|
203
|
+
|
|
204
|
+
>>> crc32 = crcmod.Crc(0x104c11db7, initCrc=0, xorOut=0xFFFFFFFF)
|
|
205
|
+
>>> crc32.update('123456789')
|
|
206
|
+
>>> hex(crc32.crcValue)
|
|
207
|
+
'0xcbf43926L'
|
|
208
|
+
>>> crc32.hexdigest()
|
|
209
|
+
'CBF43926'
|
|
210
|
+
|
|
211
|
+
The :meth:`Crc.update` method can be called multiple times, and the CRC value is updated with each call::
|
|
212
|
+
|
|
213
|
+
>>> crc32new = crc32.new()
|
|
214
|
+
>>> crc32new.update('1234')
|
|
215
|
+
>>> crc32new.hexdigest()
|
|
216
|
+
'9BE3E0A3'
|
|
217
|
+
>>> crc32new.update('56789')
|
|
218
|
+
>>> crc32new.hexdigest()
|
|
219
|
+
'CBF43926'
|