diff options
author | Thorsten Behrens <sbehrens@gmx.li> | 2010-12-30 07:15:35 -0500 |
---|---|---|
committer | Thorsten Behrens <sbehrens@gmx.li> | 2010-12-30 07:15:35 -0500 |
commit | 4082de9a483d63f49746b1a96d988b5423aa44b6 (patch) | |
tree | b2c1b5bdbfd32f5fe12970daf16597e4dc14f8aa | |
parent | cb48387f66a7fe9c2450b740a84c3c5af3712895 (diff) | |
download | pycrypto-4082de9a483d63f49746b1a96d988b5423aa44b6.tar.gz |
Add Ron Rivet Test
o Add Ron Rivet DES test to test_DES.py
o Started on API documentation for 3.x
-rw-r--r-- | ACKS | 1 | ||||
-rw-r--r-- | Doc/pycrypt.rst | 23 | ||||
-rw-r--r-- | lib/Crypto/SelfTest/Cipher/test_DES.py | 42 | ||||
-rw-r--r-- | lib/Crypto/SelfTest/PublicKey/test_DSA.py | 2 | ||||
-rw-r--r-- | lib/Crypto/SelfTest/PublicKey/test_RSA.py | 1 | ||||
-rw-r--r--[-rwxr-xr-x] | lib/Crypto/Util/py21compat.py | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | lib/Crypto/Util/py3compat.py | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | python-3-changes.txt | 9 | ||||
-rw-r--r-- | setup.py | 26 | ||||
-rw-r--r--[-rwxr-xr-x] | src/_fastmath.c | 0 | ||||
-rw-r--r-- | src/inc-msvc/stdint.h | 6 |
11 files changed, 78 insertions, 32 deletions
@@ -14,6 +14,7 @@ Please let me know if your name isn't here and should be! Nevins Bartolomeo +Thorsten E. Behrens Tim Berners-Lee Ian Bicking Joris Bontje diff --git a/Doc/pycrypt.rst b/Doc/pycrypt.rst index f6d068d..d6ae967 100644 --- a/Doc/pycrypt.rst +++ b/Doc/pycrypt.rst @@ -346,10 +346,13 @@ available. **new(key, mode[, IV])**: Returns a ciphering object, using ``key`` and feedback mode -``mode``. If ``mode`` is ``MODE_CBC`` or ``MODE_CFB``, ``IV`` must be provided, -and must be a string of the same length as the block size. Some -algorithms support additional keyword arguments to this function; see +``mode``. +If ``mode`` is ``MODE_CBC`` or ``MODE_CFB``, ``IV`` must be provided, + and must be a string of the same length as the block size. +Some algorithms support additional keyword arguments to this function; see the "Algorithm-specific Notes for Encryption Algorithms" section below for the details. +Python 3.x: ```mode`` is a string object; ```key``` and ```IV``` must be +objects interpretable as a buffer of bytes. **block_size**: An integer value; the size of the blocks encrypted by this module. @@ -375,7 +378,7 @@ Contains the initial value which will be used to start a cipher feedback mode. After encrypting or decrypting a string, this value will reflect the modified feedback text; it will always be one block in length. It is read-only, and cannot be assigned a new value. - +Python 3.x: ```IV``` is a bytes object. **key_size**: An integer value equal to the size of the keys used by this object. If @@ -391,6 +394,7 @@ Decrypts ``string``, using the key-dependent data in the object, and with the appropriate feedback mode. The string's length must be an exact multiple of the algorithm's block size. Returns a string containing the plaintext. +Python 3.x: decrypt() will return a bytes object. **encrypt(string)**: @@ -399,7 +403,8 @@ object, and with the appropriate feedback mode. The string's length must be an exact multiple of the algorithm's block size; for stream ciphers, the string can be of any length. Returns a string containing the ciphertext. - +Python 3.x: ```string``` must be an object interpretable as a buffer of bytes. +encrypt() will return a bytes object. Algorithm-specific Notes for Encryption Algorithms @@ -630,10 +635,10 @@ following table: ============= ========================================== Algorithm Capabilities ============= ========================================== -RSA Encryption, authentication/signatures -ElGamal Encryption, authentication/signatures -DSA Authentication/signatures -qNEW Authentication/signatures +RSA Encryption, authentication/signatures +ElGamal Encryption, authentication/signatures +DSA Authentication/signatures +qNEW Authentication/signatures ============= ========================================== Many of these algorithms are patented. Before using any of them in a diff --git a/lib/Crypto/SelfTest/Cipher/test_DES.py b/lib/Crypto/SelfTest/Cipher/test_DES.py index 69697c1..416af43 100644 --- a/lib/Crypto/SelfTest/Cipher/test_DES.py +++ b/lib/Crypto/SelfTest/Cipher/test_DES.py @@ -28,6 +28,7 @@ __revision__ = "$Id$" from common import dict # For compatibility with Python 2.1 and 2.2 from Crypto.Util.py3compat import * +import unittest # This is a list of (plaintext, ciphertext, key, description) tuples. SP800_17_B1_KEY = b("01") * 8 @@ -286,10 +287,49 @@ test_data = [ 'NIST SP800-17 B.2 #55'), ] +class RonRivetTest(unittest.TestCase): + """ Ronald L. Rivet's DES test, see + http://people.csail.mit.edu/rivest/Destest.txt + ABSTRACT + -------- + + We present a simple way to test the correctness of a DES implementation: + Use the recurrence relation: + + X0 = 9474B8E8C73BCA7D (hexadecimal) + + X(i+1) = IF (i is even) THEN E(Xi,Xi) ELSE D(Xi,Xi) + + to compute a sequence of 64-bit values: X0, X1, X2, ..., X16. Here + E(X,K) denotes the DES encryption of X using key K, and D(X,K) denotes + the DES decryption of X using key K. If you obtain + + X16 = 1B1A2DDB4C642438 + + your implementation does not have any of the 36,568 possible single-fault + errors described herein. + """ + def runTest(self): + from Crypto.Cipher import DES + from binascii import b2a_hex + + X = [] + X[0:] = [b('\x94\x74\xB8\xE8\xC7\x3B\xCA\x7D')] + + for i in range(16): + c = DES.new(X[i],DES.MODE_ECB) + if not (i&1): # (num&1) returns 1 for odd numbers + X[i+1:] = [c.encrypt(X[i])] # even + else: + X[i+1:] = [c.decrypt(X[i])] # odd + + self.assertEqual(b2a_hex(X[16]), + b2a_hex(b('\x1B\x1A\x2D\xDB\x4C\x64\x24\x38'))) + def get_tests(config={}): from Crypto.Cipher import DES from common import make_block_tests - return make_block_tests(DES, "DES", test_data) + return make_block_tests(DES, "DES", test_data) + [RonRivetTest()] if __name__ == '__main__': import unittest diff --git a/lib/Crypto/SelfTest/PublicKey/test_DSA.py b/lib/Crypto/SelfTest/PublicKey/test_DSA.py index 1186664..3bbf481 100644 --- a/lib/Crypto/SelfTest/PublicKey/test_DSA.py +++ b/lib/Crypto/SelfTest/PublicKey/test_DSA.py @@ -27,10 +27,10 @@ __revision__ = "$Id$" import sys +import os if sys.version_info[0] == 2 and sys.version_info[1] == 1: from Crypto.Util.py21compat import * from Crypto.Util.py3compat import * -import os import unittest from Crypto.SelfTest.st_common import list_test_cases, a2b_hex, b2a_hex diff --git a/lib/Crypto/SelfTest/PublicKey/test_RSA.py b/lib/Crypto/SelfTest/PublicKey/test_RSA.py index a93d752..e99ca39 100644 --- a/lib/Crypto/SelfTest/PublicKey/test_RSA.py +++ b/lib/Crypto/SelfTest/PublicKey/test_RSA.py @@ -27,6 +27,7 @@ __revision__ = "$Id$" import sys +import os if sys.version_info[0] == 2 and sys.version_info[1] == 1: from Crypto.Util.py21compat import * from Crypto.Util.py3compat import * diff --git a/lib/Crypto/Util/py21compat.py b/lib/Crypto/Util/py21compat.py index 624408b..624408b 100755..100644 --- a/lib/Crypto/Util/py21compat.py +++ b/lib/Crypto/Util/py21compat.py diff --git a/lib/Crypto/Util/py3compat.py b/lib/Crypto/Util/py3compat.py index 7c90de2..7c90de2 100755..100644 --- a/lib/Crypto/Util/py3compat.py +++ b/lib/Crypto/Util/py3compat.py diff --git a/python-3-changes.txt b/python-3-changes.txt index 2b7b164..bd524aa 100755..100644 --- a/python-3-changes.txt +++ b/python-3-changes.txt @@ -105,8 +105,9 @@ TODO: text string.
hexdigest() returns a text string
digest() returns a byte-string.
-- Look into LIBPATH/%LIB% and /NODEFAULTLIB:LIBCMT in setup.py for libgmp/libmpir
-- Go through test cases and see which modules are not covered
-- Make sure DerSequence slicing is tested, since I took the explicit slice functions
- away in 3.x
+- Need additional unit tests for Protocol/AllOrNothing, PublicKey/ElGamal,
+ random/random
+- Make sure DerSequence slicing is tested, since I took the explicit slice
+ functions away in 3.x
+- PublicKey/qNEW will not be unit-tested. Is it time to do away with it?
- Test install on all tested Python versions
@@ -77,9 +77,11 @@ if sys.version_info[0] == 2: EXCLUDE_PY = [] else: EXCLUDE_PY = [ -# We don't want Py3k to choke on the 2.x compat code + # We don't want Py3k to choke on the 2.x compat code ('Crypto.Util', 'py21compat'), ] + if sys.platform != "win32": # Avoid nt.py, as 2to3 can't fix it w/o winrandom + EXCLUDE_PY += [('Crypto.Random.OSRNG','nt')] # Work around the print / print() issue with Python 2.x and 3.x. We only need # to print at one point of the code, which makes this easy @@ -184,7 +186,7 @@ class PCTBuildExt (build_ext): self.compiler.include_dirs.insert(0, "src/inc-msvc/") # Detect libgmp or libmpir and don't build _fastmath if both are missing. - lib_dirs = self.compiler.library_dirs + ['/lib', '/usr/lib'] + lib_dirs = self.compiler.library_dirs + ['/lib', '/usr/lib', '/usr/local/lib'] if not (self.compiler.find_library_file(lib_dirs, 'gmp') or self.compiler.find_library_file(lib_dirs, 'mpir')): PrintErr ("warning: GMP or MPIR library not found; Not building "+ @@ -379,14 +381,6 @@ kw = {'name':"pycrypto", sources=['src/_counter.c']), ] } -def touch(path): - import os, time - now = time.time() - try: - # assume it's there - os.utime(path, (now, now)) - except os.error: - PrintErr("Failed to update timestamp of "+path) # If we're running Python 2.3, add extra information if hasattr(core, 'setup_keywords'): @@ -405,7 +399,17 @@ if hasattr(core, 'setup_keywords'): '%s-%s.tar.gz' % (kw['name'], kw['version']) ) core.setup(**kw) -#PY3K: Workaround for winrandom.pyd not existing during the first pass. + +def touch(path): + import os, time + now = time.time() + try: + # assume it's there + os.utime(path, (now, now)) + except os.error: + PrintErr("Failed to update timestamp of "+path) + +# PY3K: Workaround for winrandom.pyd not existing during the first pass. # It needs to be there for 2to3 to fix the import in nt.py if (sys.platform == 'win32' and sys.version_info[0] == 3 and 'build' in sys.argv[1:]): diff --git a/src/_fastmath.c b/src/_fastmath.c index fe3fde3..fe3fde3 100755..100644 --- a/src/_fastmath.c +++ b/src/_fastmath.c diff --git a/src/inc-msvc/stdint.h b/src/inc-msvc/stdint.h index 8b7a52f..971c9d7 100644 --- a/src/inc-msvc/stdint.h +++ b/src/inc-msvc/stdint.h @@ -34,11 +34,5 @@ typedef unsigned __int16 uint16_t; typedef unsigned __int32 uint32_t; typedef unsigned __int64 uint64_t; -/* Define the "inline" keyword */ -#ifndef inline -# define inline __inline -#endif /* inline */ - - #endif /* PYCRYPTO_MSVC_STDINT_H */ /* vim:set ts=4 sw=4 sts=4 expandtab: */ |