Difference between revisions of "PyCryptoPlus"
Jump to navigation
Jump to search
m (→Python) |
|||
Line 383: | Line 383: | ||
== Various info == |
== Various info == |
||
− | === Python === |
+ | === [[Python]] === |
− | *absolute relative imports: links with some info |
||
− | ** http://bugs.python.org/issue1510172 |
||
− | ** http://www.python.org/dev/peps/pep-0366/ |
||
− | ** http://www.python.org/dev/peps/pep-0328/ |
||
− | ** http://groups.google.com/group/comp.lang.python/msg/e35b1746b425b4c1 |
||
− | * collect all doctests |
||
− | ** http://docs.python.org/lib/doctest-unittest-api.html |
||
− | * making a package |
||
− | ** http://docs.python.org/dist/ |
||
− | |||
− | ==== Setup Script ==== |
||
− | ===== distutils vs setuptools ===== |
||
− | Dependencies checking on install: some info [http://blog.doughellmann.com/2007/11/requiring-packages-with-distutils.html here]. |
||
− | :It seems that the 'requires' keyword in distutils has only a purpose of documentation, but 'install_requires' in setuptools really takes care of dependencies: availability of dependencies will be checked. If a package is not available, it will be checked for on [http://pypi.python.org/pypi pypi] and installed automatically. |
||
− | ===== distutils ===== |
||
− | * setup.py |
||
− | ** creating a distribution tar.gz: "python setup.py sdist" |
||
− | ** installing the source distribution (sdist):<br>- untar .tar.gz: "cd dist && tar zxfv CryptoPlus-1.0.tar.gz -C ~/"<br>- "cd ~/CryptoPlus-1.0 && python setup.py install" |
||
− | ** "egg way":<br>$ python setup.py bdist_egg<br>$ sudo easy_install dist/CryptoPlus-1.0-py2.5.egg |
||
− | |||
− | ===== setuptools ===== |
||
− | * http://pypi.python.org/pypi/setuptools/ |
||
− | * manual: http://peak.telecommunity.com/DevCenter/setuptools |
||
− | * it isn't installed by default on debian |
||
− | ** apt-get install python-setuptools |
||
− | ** sage-python has setuptools by default |
Revision as of 22:16, 15 October 2008
Back to SAGE & cryptology
Info
Differences with pycrypto
CryptoPlus | PyCrypto | ||||||
Block Ciphers | |||||||
---|---|---|---|---|---|---|---|
Block cipher algorithms | |||||||
Serpent | Py | ||||||
Blowfish | Py | C | |||||
Twofish | Py | ||||||
Idea | C | ||||||
DES | Py | C | |||||
3DES | Py | C | |||||
AES | Py | C | |||||
Rijndael | Py | ||||||
Present | Py | ||||||
Modes of operation | |||||||
CMAC | Py | ||||||
XCBC | |||||||
CBC-MAC | |||||||
CCM | |||||||
GCM | |||||||
ECB | Py | C | |||||
CBC | Py | C | |||||
CTR | Py | C | |||||
LRW | |||||||
XTS | Py | ||||||
MDC-2 | |||||||
Paddings | |||||||
bit padding | Py | ||||||
zeros | Py | ||||||
PKCS7 | Py | ||||||
PKCS12 | Py | ||||||
ISO 10126 | Py | ||||||
ANSI X.923 | Py |
- ciphers from pycrypto are being used with the python chaining modes and not the original pycrypto ones
=> plaintext can be supplied in arbitrary sizes instead of multiples of the blocksize like in pycrypto: the new chaining modes keep a cache to encrypt/decrypt data once the cachesize holds at least a blocksize of data - new possibilities:
- Rijndael, Serpent, Twofish
- Rijndael is limited to blocksizes of 128, 192 and 256 bits
- CMAC, XTS, CTR
- XTS is usable for ciphers with blocksizes of 16 bytes => XTS-AES, Serpent, Twofish
- XTS encrypts the given input at once while all other chain modes encrypt only when a block plaintext is available in the cache
- CMAC is usable for blocksizes of 8 and 16 bytes
- OFB,CFB and CTR can be accessed as a stream cipher (you get the encrypted message immediately, you don't have to wait until a complete block of plaintext has been provided to the cipher)
- Rijndael, Serpent, Twofish
- test functions are available via doctests and extensive tests that loop through dictionary of test vectors
- new pycrypto version will have it's own test bench for ciphers, this is not implemented yet
source structure
root of CryptoPlus package | |
---|---|
src/Hash.py | make all Crypto.Hash modules available under CryptoPlus.Hash |
src/Protocol.py | make all Crypto.Protocol modules available under CryptoPlus.Protocol |
src/PublicKey.py | make all Crypto.PublicKey modules available under CryptoPlus.PublicKey |
src/__init__.py | make the following modules available under the CryptoPlus package:
|
src/testvectors.py |
|
CryptoPlus.Cipher subpackage | |
src/Cipher/__init__.py | specify all the ciphers in the CryptoPlus.Cipher package + import of the streamcipher ARC4 and XOR |
src/Cipher/blockcipher.py |
|
Wrappers for pycrypto | |
src/Cipher/AES.py |
|
src/Cipher/ARC2.py |
|
src/Cipher/Blowfish.py |
|
src/Cipher/CAST.py |
|
src/Cipher/DES.py |
|
src/Cipher/DES3.py |
|
src/Cipher/IDEA.py |
|
src/Cipher/RC5.py |
|
Wrappers for pure python implementations | |
src/Cipher/python_AES.py |
|
src/Cipher/python_Blowfish.py |
|
src/Cipher/python_DES.py |
|
src/Cipher/python_DES3.py |
|
src/Cipher/python_Rijndael.py |
|
src/Cipher/python_Serpent.py |
|
src/Cipher/python_Twofish.py |
|
src/Cipher/python_PRESENT.py |
|
Pure python implementations for blockciphers | |
src/Cipher/pyDes.py |
|
src/Cipher/pyblowfish.py |
|
src/Cipher/pyserpent.py |
|
src/Cipher/pytwofish.py |
|
src/Cipher/rijndael.py |
|
src/Cipher/pypresent.py |
|
CryptoPlus.Random subpackage (only used if pycrypto version > 2.0.1) | |
src/Util/__init__.py |
|
src/Util/Fortuna.py |
|
src/Util/OSRNG.py |
|
CryptoPlus.Util subpackage | |
src/Util/__init__.py |
|
src/Util/number.py src/Util/randpool.py src/Util/RFC1751.py |
|
src/Util/python_compat.py |
|
src/Util/padding.py |
|
src/Util/util.py |
|
Test scripts | |
test/test.py | runs extensive test with verified test vectors for: CBC, CFB, OFB and CTR with AES, DES,TDES2/3, Serpent128/192/256, CMAC-AES128/192/256, CMAC-TDES2/3, XTS-AES, PRESENT (80 and 128 bit key), Twofish (128/192/256bits keys) |
test/test_doctests.py | script to run all doctest available in every cipher wrapper (pure python and pycrypto wrapper) |
TODO
- check other implementation of Blowfish
- use unittest for test functions
- check development of pycrypto:
- Util.Counter & Util._counter
- SelfTest: usable to perform the test for python algo's in CryptoPlus if testvectors are in right format?
Licenses
Used by others
- used from python truecrypt implementation
all original code is under MIT license (much freedom according to [1])- pyTwofish (untouched)
python truecrypt author isn't the original author = > extra copyright notice that should be left in place - pyserpent (untouched)
python truecrypt author isn't the original author = > extra copyright notice that should be left in place - XTS (modified)
python truecrypt author is the original author => only MIT License - GF2n.py(untouched)
python truecrypt author is the original author => only MIT License
- pyTwofish (untouched)
- pyblowfish (untouched)
gpl or artistic license
To not affect the rest of the distribution we've to redistribute it only under Artistic license terms - rijndael.py (untouched)
using tls lite (public domain) implementation which uses code from Bram Cohen (public domain) - pyDes (untouched)
public domain according to its homepage - blockciphers CBC, ECB, CTR from [2] (modified)
keep copyright notice in place? - CMAC: omac.py
GPL but not really used it, just used as a starting point
Used in CryptoPlus
- pypresent.py
- MIT license
Cipher module
Test Vectors
- Collection of test vectors for a broad group of ciphers
- AES, DES, 3DES: http://csrc.nist.gov/groups/STM/cavp/standards.html
- AES in CBC, CTR, OFB, CFB: html version of pdf
- CMAC test vectors in Special Publication 800-38B are faulty, use the corrected ones from here
- Rijndael: http://fp.gladman.plus.com/cryptography_technology/rijndael/
- zip file contains a full set of round values for each of the 25 block and key length combinations from 128, 160, 192, 224 and 256 bits for one input block and one key value
- DES (enkel ECB): http://www.skepticfiles.org/faq/testdes.htm
- Blowfish: http://www.schneier.com/code/vectors.txt
- Serpent: http://www.cs.technion.ac.il/~biham/Reports/Serpent/
- Twofish: http://www.schneier.com/code/ecb_ival.txt
- AES, DES: http://svn.python.org/projects/external/openssl-0.9.8a/test/evptests.txt
- CMAC
- AES & TDES: http://www.nuee.nagoya-u.ac.jp/labs/tiwata/omac/omac.html
- AES, TDES2 & TDES3: http://csrc.nist.gov/groups/STM/cavp/documents/mac/cmactestvectors.zip
- fax folder contains usefull stuff: generation and verification tests with results
generation test: generate a correct mac
verification test: verify if provided mac for plaintext is correct
- fax folder contains usefull stuff: generation and verification tests with results
- XTS-AES: IEEE P1619TM/D16: Standard for Cryptographic Protection of Data on Block-Oriented Storage Devices
- ARC2: http://www.ietf.org/rfc/rfc2268.txt
- will be available in pycrypto >2.0.1
- CAST: http://www.rfc-editor.org/rfc/rfc2144.txt
Chaining Modes
- Wikipedia
- NIST
- XTS:
- https://siswg.net/index.php?option=com_content&task=view&id=38&Itemid=73
- http://blog.bjrn.se/2008/02/truecrypt-explained-truecrypt-5-update.html
- http://en.wikipedia.org/wiki/IEEE_P1619 = XTS-AES
- XTS-AES: IEEE P1619TM/D16: Standard for Cryptographic Protection of Data on Block-Oriented Storage Devices
- Comments: [3]
- "It should be mentioned explicitly in the description that when enciphering many blocks, successive T values can and should be computed from prior ones via multiplication by alpha (providing that i remains fixed). This optimization, which is one of the best features of XEX, should be explicitly recommended in the standard."
- CMAC = OMAC1:
- AES-CMAC: http://tools.ietf.org/html/rfc4493#page-2
- NIST:
Recommendation for Block Cipher Modes of Operation: The CMAC Mode for Authentication:SP 800-38B.pdf
Updated CMAC Examples - OMAC.py: http://github.com/jlhutch/jac/tree/master/omac.py
- OMAC page: http://www.nuee.nagoya-u.ac.jp/labs/tiwata/omac/omac.html
Ciphers
- Serpent
- http://www.cl.cam.ac.uk/~rja14/serpent.html
- python implementation used
at the momentin earlier versions: http://psionicist.online.fr/code/ - alternative python implementation (used in current version): http://www.cl.cam.ac.uk/~fms27/serpent/
- more info on this python implementation: http://www.cl.cam.ac.uk/~fms27/serpent/serpent-abstract.html
- Present
- Article: PRESENT: An Ultra-Lightweight Block Cipher
- Test Vector generator + ANSI-C implementation of present: [4]
- own implementation
- ARC2
- http://www.ietf.org/rfc/rfc2268.txt: publication + testvectors
- current pycrypto implementation fails all testvectors because of not correctly handling the "effective keylength". Fixed in upcoming release (+2.0.1) bugreportbugfix
- CAST
- RC5
Hash Module
Current Situation
- MD5
- good implementation in pypy (MIT License)
- SHA family
- SHA-1 available in pypy (MIT License)
- can be modified for other SHA's
- uses standard python hash api
- SHA256 implementation: https://vcs.slash-me.net/snippets/sha256/sha256.py
- short code but less readable than the one from pypy
- SHA-1 available in pypy (MIT License)
- Whirlpool
- available here: python truecrypt implementation
- RipeMD
- available as pure python implementation in current pycrypto development
=>RipeMD and python_RipeMD will point to the same pycrypto ripemd implementation
- available as pure python implementation in current pycrypto development
- RadioGatun
- http://radiogatun.noekeon.org/
- reference C-code
- testvectors
- http://radiogatun.noekeon.org/
- HMAC
- available in python and pypy as pure python -> same implementation used in pycrypto
- PBKDF2
- implementation from new pycrypto developer: http://www.dlitz.net/software/python-pbkdf2/