summaryrefslogtreecommitdiff
path: root/lib/Crypto/SelfTest/Util
Commit message (Collapse)AuthorAgeFilesLines
* Fix tests when running under "python -OO" (PYTHONOPTIMIZE set to 1 or 2)Dwayne Litzenberger2014-06-221-2/+4
|
* Refactor 3 places handling fastmath ImportErrorMarc Abramowitz2014-02-221-10/+2
| | | | | so that they call `Crypto.SelfTest.st_common.handle_fastmath_import_error`, thereby eliminiating duplicate code.
* Use different method for getting ext_suffixMarc Abramowitz2014-02-221-1/+2
| | | | | | | | | | | | | ``` ext_suffix = get_config_var("EXT_SUFFIX") or get_config_var("SO") ``` because `get_config_var("SO")` returns None in Python 3.4.0a4 because the "SO" variable is deprecated and "EXT_SUFFIX" is the new way to get this information (see: http://bugs.python.org/issue19555) This fixes `TypeError: Can't convert 'NoneType' object to str implicitly` errors when running the tests on Python 3.4.0a4.
* Removed most 'import *' statementsLegrandin2013-10-202-2/+6
| | | | | | | | | | | | [dlitz@dlitz.net: Re-ordered commits; so don't import S2V yet] [dlitz@dlitz.net: Included an additional 'import *' change from the following commit:] commit 4ec64d8eaaa4965889eb8e3b801fc77aa84e0a4e Author: Legrandin <helderijs@gmail.com> Date: Tue Sep 10 07:28:08 2013 +0200 Removed last references to ApiUsageError [dlitz@dlitz.net: Removed unrelated whitespace changes]
* whitespace changes (pre-AEAD)Legrandin2013-10-201-10/+10
| | | | | | | [dlitz@dlitz.net: Whitespace changes extracted from the author's pull request:] - [9c13f9c] Rename 'IV' parameter to 'nonce' for AEAD modes. - [4ec64d8] Removed last references to ApiUsageError - [ee46922] Removed most 'import *' statements
* Fix unhexlify in Python 3.2Dwayne Litzenberger2013-07-141-32/+32
| | | | | | | | Under Python 3.2, unhexlify expects to receive a `bytes` object. Passing it a (unicodr) `str` object causes it to raise the following exception: TypeError: 'str' does not support the buffer interface
* Added support for PKCS#8-encrypted private keys.Legrandin2013-07-142-0/+141
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The patch contains the following changes: - Private RSA keys can be imported/exported in encrypted form, protected according to PKCS#8 and: * PBKDF2WithHMAC-SHA1AndDES-EDE3-CBC. * PBKDF2WithHMAC-SHA1AndAES128-CBC * PBKDF2WithHMAC-SHA1AndAES192-CBC * PBKDF2WithHMAC-SHA1AndAES256-CBC In addition to that, it is possible to import keys i the following weak formats: * pbeWithMD5AndDES-CBC * pbeWithSHA1AndRC2-CBC * pbeWithMD5AndRC2-CBC * pbeWithSHA1AndDES-CBC - The following new module (and 1 new package) are added: * Crypto.Util.Padding for simple padding/unpadding logic * Crypto.IO._PBES for PBE-related PKCS#5 logic * Crypto.IO.PEM for PEM wrapping/unwrapping * Crypto.IO.PKCS8 for PKCS#8 wrapping/unwrapping - All Object ID (OIDs) are now in dotted form to increase readability. - Add AES support to PEM format (decode only). The PEM module can decrypt messages protected with AES-CBC. - Update RSA import test cases. - Updated to PKCS8 test cases
* Refactoring of the asn1 moduleLegrandin2013-07-141-244/+604
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The following changes are included: - Decoding is a much simpler operation. The internal logic is based on stream of binary data, and not on string indexing anymore. Additionally, decoding used to look like this: bitmap = DerObject() bitmap.decode(input_buffer, True) if bitmap.isType('BIT STRING'): ... proceed with parsing ... else: ... error ... Whereas now, it is cleaner and more compact: bitmap = DerBitString() bitmap.decode(input_buffer) Any error condition will lead to an exception. - isType() method has been removed because of the above. - Added examples and documentation - Added support IMPLICIT tags - Added support for negative INTEGERs - Added DerSetOf ASN.1 class - DerObjectID can be initialized from the dotted representation of the Object ID. - DerBitString has a new member 'value' to hold the binary string. The member 'payload' should not be accessed anymore. - DerObjectID has a new member 'value' to hold the dotted representation of the Object ID string. The member 'payload' should not be accessed anymore. - Added operator += to DER SEQUENCE. Now it is possible to do: my_str = DerOctetString(b'ZYZ') seq = DerSequence() seq += 0 seq += my_str.encode() - Update to test cases
* Counter: Deprecate disable_shortcut; Remove __PCT_CTR_SHORTCUT__ entirelyDwayne Litzenberger2013-07-141-15/+5
| | | | | | | | | | | | The `disable_shortcut` option served as a workaround in case `__PCT_CTR_SHORTCUT__` leaked through a wrapper object, but I don't think anyone actually used it, and it was a bad idea to expose it as part of the public API. Now that we do strong type checking inside block_template.c, there shoujld be no need to ever use this option. It's now a no-op, retained for backward compatibility only. It will be removed in some future version of PyCrypto.
* Add tests for error propagation in _fastmathDwayne C. Litzenberger2012-07-031-0/+29
| | | | | | | Affects isPrime and getStrongPrime. See https://github.com/dlitz/pycrypto/pull/23 ("Store result of rabinMillerTest in an int.") for the bug report.
* Run test_negative_number_roundtrip_mpzToLongObj_longObjToMPZ only if _fastmathSebastian Ramacher2012-06-281-1/+20
| | | | is available.
* Reenable redefined tests.Sebastian Ramacher2012-05-281-1/+1
| | | | | | | | The test suite contains tests that are disabled because they have the same name as other tests. Renaming them enables them again. PKCS1_OAEP_Tests.testEncryptDecrypt1 is updated to work with the new interface of PKCS1_OAEP.
* _fastmath: Convert negative numbers properlyDwayne C. Litzenberger2012-04-251-0/+11
|
* _fastmath: missing Py_BLOCK_THREADS on isPrime(1)Dwayne C. Litzenberger2012-04-251-0/+1
| | | | | | | | | | When _fastmath is present, the following code caused the Python interpreter to abort with a fatal error: from Crypto.Util.number import isPrime isPrime(1) # Fatal Python error: PyEval_SaveThread: NULL tstate Bug report: https://bugs.launchpad.net/pycrypto/+bug/988431
* Merge from upstreamLegrandin2011-12-221-3/+3
|\
| * Python 3.x fixes:Dwayne C. Litzenberger2011-10-221-3/+3
| | | | | | | | | | - Use absolute imports - Fix StringIO import so that 2to3 can translate it
* | Further fixed for python 3Legrandin2011-10-191-0/+4
| |
* | Merged from upstream (py3k support) and modified so that all unit tests pass.Legrandin2011-10-183-115/+119
|\ \ | |/
| * PY3K _fastmath supportThorsten Behrens2010-12-292-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | o _fastmath now builds and runs on PY3K o Changes to setup.py to allow /usr/include for gmp.h o Changes to setup.py to allow linking fastmath w/ static mpir on Windows without warning messages o Changes to test_DSA/test_RSA to throw an exception if _fastmath is present but cannot be imported (due to an issue building _fastmath or the shared gmp/mpir libraries not being reachable) o number.py has the code to flag a failing _fastmath, but that code is commented out for a better runtime experience o Clean up the if for py21compat import - should have been == not is o Clean up some '== None' occurences, now 'is None' instead
| * PY3K support for _fastmath.c; removed floordiv(a,b) hack and replaced with ↵Thorsten Behrens2010-12-291-6/+6
| | | | | | | | divmod(a,b)[0]; move to assertEqual throughout the test suite to prep for assert_ and failIf being removed in 3.3/3.4
| * Changes to allow pycrpyto to work on Python 3.x as well as 2.1 through 2.7Thorsten Behrens2010-12-283-109/+110
| |
* | Added test case for size()Legrandin2011-02-061-0/+6
|/
* Support for older versions of pythonLegrandin2010-08-021-5/+8
| | | | | | This patch add support for older python 2.1/2.2 to the previous one (DER/PEM). Committer: Legrandin <gooksankoo@hoiptorrow.mailexpire.com>
* Add ability to export and import RSA keys in DER and PEM format.Legrandin2010-08-021-0/+287
| | | | | | | | | | | | | | | | | | | | | | Typical usage for importing an RSA key: f = file("ssl.pem") key = RSA.importKey(f.read()) f.close() key.verify(hash, signature) Typical usage for exporting an RSA public key: key = RSA.generate(512, randfunc) f = file("ssl.der","w") f.write(key.publickey.exportKey('DER')) f.close() I confirm I am eligible for submitting code to pycrypto according to http://www.dlitz.net/software/pycrypto/submission-requirements/ fetched on 27 December 2009. Committer: Legrandin <gooksankoo@hoiptorrow.mailexpire.com>
* Fix backward compatibility with PyCrypto 2.1 through 2.5:Dwayne C. Litzenberger2010-06-101-12/+12
| | | | | | | | | | | | | | | | | | | | | | | | | - Replaced things like (1 << bits) with (1L << bits). See PEP 237: - In Python < 2.4, (1<<31) evaluates as -2147483648 - In Python >= 2.4, it becomes 2147483648L - Replaced things like (bits/2) with the equivalent (bits>>1). This makes PyCrypto work when floating-point division is enabled (e.g. in Python 2.6 with -Qnew) - In Python < 2.2, expressions like 2**1279, 1007119*2014237, and 3153640933 raise OverflowError. Replaced them with it with 2L**1279, 1007119L*2014237L, and 3153640933, respectively. - The "//" and "//=" integer division operators are a syntax error in Python 2.1 and below. Replaced things like (m //= 2) with the equivalent (m >>= 1). - Where integer division can't be replaced by bit shifting, replace (a/b) with (divmod(a, b)[0]). - math.log takes exactly 1 argument in Python < 2.3, so replaced things like "-math.log(false_positive_prob, 4)" with "-math.log(false_positive_prob)/math.log(4)".
* getStrongPrime() implementationLorenz Quack2010-06-101-0/+38
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | From http://lists.dlitz.net/pipermail/pycrypto/2009q4/000167.html, with the following explanation included in the email: === snip === Hi there! Here comes my monster patch. It includes a python and C version of getStrongPrime, rabinMillerTest and isPrime. there are also two small unit tests and some helper functions. They all take a randfunc and propagate them (or so I hope). The Rabin-Miller-Test uses random bases (non-deterministic). getStrongPrime and isPrime take an optional parameter "false_positive_prob" where one can specify the maximum probability that the prime is actually composite. Internally the functions calculate the Rabin-Miller rounds from this. It defaults to 1e-6 (1:1000000) which results in 10 rounds of Rabin-Miller testing. Please review this carefully. Even though I tried hard to get things right some bugs always slip through. maybe you could also review the way I acquire and release the GIL. It felt kind of ugly the way I did it but I don't see a better way just now. Concerning the public exponent e: I now know why it needs to be coprime to p-1 and q-1. The private exponent d is the inverse of e mod ((p-1)(q-1)). If e is not coprime to ((p-1)(q-1)) then the inverse does not exist [1]. The getStrongPrime take an optional argument e. if provided the function will make sure p-1 and e are coprime. if e is even (p-1)/2 will be coprime. if e is even then there is a additional constraint: p =/= q mod 8. I can't check for that in getStrongPrime of course but since we hardcoded e to be odd in _RSA.py this should pose no problem. The Baillie-PSW-Test is not included. I tried hard not to use any functionality new than 2.1 but if you find anything feel free to criticize. Also if I didn't get the coding style right either tell me or feel free to correct it yourself. have fun. //Lorenz [1] http://mathworld.wolfram.com/ModularInverse.html === snip ===
* SelfTest: Test new Counter anti-wraparound behaviourDwayne C. Litzenberger2009-10-121-11/+25
|
* SelfTest: Add tests for Counter wraparound behaviour and for the 'carry' ↵Dwayne C. Litzenberger2009-10-121-0/+45
| | | | attribute
* SelfTest: Add tests for Crypto.Util.CounterDwayne C. Litzenberger2009-10-122-0/+104
|
* Legal: Dedicate my files to the public domain.Dwayne C. Litzenberger2009-03-013-63/+51
| | | | | | | | | | | | | In an attempt to simplify the copyright status of PyCrypto, I'm placing my code into the public domain, and encouraging other contributors to do the same. I have used a public domain dedication that was recommended in a book on FOSS legal issues[1], followed by the warranty disclaimer boilerplate from the MIT license. [1] _Intellectual Property and Open Source: A Practical Guide to Protecting Code_, a book written by Van Lindberg and published by O'Reilly Media. (ISBN 978-0-596-51796-0)
* cleanup: Move modules to "lib/Crypto" subdirectory.Dwayne C. Litzenberger2009-02-283-0/+340
This will avoid the previous situation where scripts like the old "test.py" get included accidentally in a release. It also frees us to put additional build scripts in the top-level directory of the source tree.