summaryrefslogtreecommitdiff
path: root/rsa
Commit message (Collapse)AuthorAgeFilesLines
* language correction and speed-upHEADmainmyheroyuki2023-04-252-18/+5
|
* rsa/pkcs1.py: Clarify functionality of sign_hash()Moritz Fischer2023-04-231-2/+2
| | | | | | | Clarify functionality that a hash is not computed, rather a precomputed (given) hash is being signed. Signed-off-by: Moritz Fischer <moritzf@google.com>
* modified: Fixed a bug in rsa/core.py where the message should not be ↵Shengkai Sun2023-04-231-1/+1
| | | | | | equals to the modulus modified: Added test cases in tests/test_integers.py
* Bumped version to 4.10-dev0Sybren A. Stüvel2023-04-231-2/+2
|
* Make `AbstractKey` an actual abstract classSybren A. Stüvel2023-04-231-1/+6
| | | | | | | | | Decorate functions that subclassess should implement with `@abc.abstractmethod`. This is to fix a mypy error that'll show up when upgrading mypy. That upgrade will follow shortly -- I just wanted to make sure things keep working.
* Bumped version to 4.9Sybren A. Stüvel2022-07-201-2/+2
|
* Fix #199: Sphinx warnings reference target not foundSybren A. Stüvel2022-07-201-1/+2
| | | | | | | | | | | | | | | Fix the documentation by adding referenced-but-not-included functions and some other small fixes. The only warnings left are: ``` python-rsa/rsa/key.py:docstring of rsa.key.AbstractKey.load_pkcs1:: WARNING: py:class reference target not found: rsa.key.T python-rsa/rsa/key.py:docstring of rsa.key.AbstractKey.load_pkcs1:: WARNING: py:class reference target not found: rsa.key.T ``` These are due to Sphynx not really understanding `typing` type references. Not sure how to fix those.
* Fix #133: Remove rsa/_compat.pySybren A. Stüvel2022-03-131-48/+0
| | | | | There were very few functions in there, and none of them were actually used by the RSA library (just by the test code).
* Bumped version to 4.9-dev0Sybren A. Stüvel2022-03-131-2/+2
|
* Remove overlapping slots from AbstractKey subclassesArie Bovenberg2022-03-131-2/+2
| | | | | | | | | | | | | | | | | | | | | | | `PublicKey` and `PrivateKey` both define the `n` and `e` slots, which are already present in their base class. This reduces the benefits of having slots. ```shell $ slotscheck -m rsa -v ERROR: 'rsa.key:PrivateKey' defines overlapping slots. - e (rsa.key:AbstractKey) - n (rsa.key:AbstractKey) ERROR: 'rsa.key:PublicKey' defines overlapping slots. - e (rsa.key:AbstractKey) - n (rsa.key:AbstractKey) ``` The Python docs say: > If a class defines a slot also defined in a base class, the instance > variable defined by the base class slot is inaccessible (except by > retrieving its descriptor directly from the base class). This renders > the meaning of the program undefined.
* Fix #194: Remove debug logging from `rsa/key.py`Sybren A. Stüvel2022-03-131-4/+0
|
* Tiny fix to Incompatible types in assignmentikeikeikeike / ikedat / Tatsuo Ikeda2022-01-111-3/+6
|
* More version bump to 4.8version-4.8Sybren A. Stüvel2021-11-241-2/+2
|
* Fix typosKian-Meng, Ang2021-11-245-6/+6
|
* Use Chinese Remainder Theorem when decrypting with private keySybren A. Stüvel2021-03-291-1/+10
| | | | | | | Use the Chinese Remainder Theorem when decrypting with private key, as that makes the decryption 2-4x faster. This fixes #163.
* Reformatting with BlackSybren A. Stüvel2021-03-2914-335/+434
| | | | No functional changes.
* Fix hashlib mypy types for Python 3.xSaif Hakim2021-03-241-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As captured in https://github.com/python/typeshed/pull/1663, the types for SHA-1 and SHA-2 family of functions are callables that return a Hash instance, whilst the SHA-3 family of functions are Hash `type`s (at least in Python 3.6). Mixing the two kinds of functions together in a dictionary confuses mypy's type inference as noted in #153, so we instead add an annotation as a hint. Also, update test_my.py to match the python version set by tox.ini in CI instead of always targeting Python 3.7 (as configured in setup.cfg) to validate the types in all supported Python 3.x versions. This fix also avoids the issue with the older mypy releases for Python 3.6 / Python 3.7 found in distro repos... ... for Ubuntu: ``` docker run \ -v $(pwd):/tmp/rsa \ -w /tmp/rsa ubuntu:18.04 \ /bin/bash -c 'apt-get update -qqy \ && apt-get install -qqy python3-pyasn1 python3-setuptools python3-mypy \ && python3 setup.py test' ``` ... and for Fedora: ``` docker run \ -v $(pwd):/tmp/rsa \ -w /tmp/rsa docker.io/fedora \ /bin/bash -c 'dnf -y install wget python3-devel python3-pyasn1 python3-setuptools python3-mypy \ && python3 setup.py test' ``` Fixes #153
* Add py.typed marker file for PEP 561 complianceAndrey Semakin2021-02-241-0/+1
|
* Fix exception causes all over the codebaseRam Rachum2021-02-243-9/+9
| | | | | | | | | | | | | | | | | | | | | | The mistake is this: In some parts of the code, an exception is being caught and replaced with a more user-friendly error. In these cases the syntax `raise new_error from old_error` needs to be used. Python's exception chaining means it shows not only the traceback of the current exception, but that of the original exception (and possibly more.) This is regardless of `raise from`. The usage of `raise from` tells Python to put a more accurate message between the tracebacks. Instead of this: During handling of the above exception, another exception occurred: You'll get this: The above exception was the direct cause of the following exception: The first is inaccurate, because it signifies a bug in the exception-handling code itself, which is a separate situation than wrapping an exception.
* Bumped version to 4.8-dev0Sybren A. Stüvel2021-02-241-1/+1
|
* Bumped version to 4.7.2version-4.7.2Sybren A. Stüvel2021-02-241-2/+2
|
* Fix #173: unpickling doesn't restore full objectBu Sun Kim2021-02-241-0/+2
| | | | | When a `PrivateKey` or `PublicKey` is unpickled `AbstractKey.__init__()` should be called so `self.mutex` and `self.blindfac` are created.
* Bumped version to 4.7.1Sybren A. Stüvel2021-02-151-2/+2
|
* Fix threading issue introduced in 4.7Sybren A. Stüvel2021-02-151-30/+44
| | | | | | | | | Computing the blinding factor and its inverse was done in a thread-unsafe manner. Locking the computation & update of the blinding factors, and passing these around in frame- and stack-bound data, solves this. This fixes part of the issues reported in sybrenstuvel/python-rsa#173, but there is more going on in that particular report.
* Bumped version to 4.7.1-dev0Sybren A. Stüvel2021-02-141-2/+2
|
* Bumped version to 4.7version-4.7Sybren A. Stüvel2021-01-101-2/+2
|
* Fix #162: Blinding uses slow algorithmSybren A. Stüvel2020-11-151-20/+32
| | | | | | | | | Store blinding factor + its inverse, so that they can be reused & updated on every blinding operation. This avoids expensive computations. The reuse of the previous blinding factor is done via squaring (mod n), as per section 9 of 'A Timing Attack against RSA with the Chinese Remainder Theorem' by Werner Schindler, https://tls.mbed.org/public/WSchindler-RSA_Timing_Attack.pdf
* Directly raise `DecryptionError` when crypto length is badSybren A. Stüvel2020-11-151-2/+4
| | | | | Crypto length and blocksize are public info, so don't need side-channel free comparison.
* Use `bytes.find()` instead of `bytes.index()`Sybren A. Stüvel2020-11-151-4/+2
| | | | | Use `bytes.find()` instead of `bytes.index()`, as the former doesn't raise an exception when the to-be-found byte doesn't exist.
* Fix #164: Add padding length check as described by PKCS#1 v1.5Sybren A. Stüvel2020-11-151-1/+6
| | | | | According to PKCS#1 v1.5, the padding should be at least 8 bytes long. See https://tools.ietf.org/html/rfc8017#section-7.2.2 step 3 for more info.
* Fix #165: CVE-2020-25658 - Bleichenbacher-style timing oracleSybren A. Stüvel2020-11-151-4/+8
| | | | | | | | | | | | | Use as many constant-time comparisons as practical in the `rsa.pkcs1.decrypt` function. `cleartext.index(b'\x00', 2)` will still be non-constant-time. The alternative would be to iterate over all the data byte by byte in Python, which is several orders of magnitude slower. Given that a perfect constant-time implementation is very hard or even impossible to do in Python [1], I chose the more performant option here. [1]: https://securitypitfalls.wordpress.com/2018/08/03/constant-time-compare-in-python/
* Fix exception cause in common.pyRam Rachum2020-06-141-2/+2
|
* Bumped version to 4.7-dev0Sybren A. Stüvel2020-06-121-1/+1
|
* Retagged 4.4 as 4.6 and added bit of an explanation to CHANGELOG.mdversion-4.6Sybren A. Stüvel2020-06-121-1/+1
|
* Bumped version to 4.4.1version-4.4.1Sybren A. Stüvel2020-06-121-1/+1
|
* Bumped version to 4.4version-4.4Sybren A. Stüvel2020-06-121-2/+2
|
* Bumped version to 4.2version-4.2Sybren A. Stüvel2020-06-111-2/+2
|
* Limit SHA3 support to Python 3.6+Sybren A. Stüvel2020-06-111-12/+15
| | | | | | | The third-party library that adds support for this to Python 3.5 is a binary package, and thus breaks the pure-Python nature of Python-RSA. This should fix [#147](https://github.com/sybrenstuvel/python-rsa/issues/147).
* Bumped version to 4.2-dev0Sybren A. Stüvel2020-06-101-1/+1
|
* Bumped version to 4.1version-4.1Sybren A. Stüvel2020-06-101-2/+2
|
* Fix CVE-2020-13757: detect cyphertext modifications by prepending zero bytesSybren A. Stüvel2020-06-031-0/+9
| | | | | | | | | | Reject cyphertexts that have been modified by prepending zero bytes, by checking the cyphertext length against the expected size (given the decryption key). This resolves CVE-2020-13757. The same approach is used when verifying a signature. Thanks Carnil for pointing this out on https://github.com/sybrenstuvel/python-rsa/issues/146
* Add more type hintsAndrey Semakin2020-06-039-26/+31
|
* Drop character encoding markers for Python 2.xAndrey Semakin2020-06-0315-30/+0
|
* Choose blinding factor relatively prime to NSybren A. Stüvel2020-04-141-2/+9
| | | | This is a requirement for RSA blinding, but wasn't implemented yet.
* Configured flask8 to use max_complexity=10Sybren A. Stüvel2019-08-041-23/+29
| | | | Also reorganised the only function that had a higher complexity.
* Added flake8 as development dependency and fixed reported issuesSybren A. Stüvel2019-08-046-14/+12
|
* Add support for SHA3 hashingSybren A. Stüvel2019-08-041-0/+14
| | | | | | | | | | This is based on https://github.com/sybrenstuvel/python-rsa/pull/96, with a few improvements: - The minimum of one use of SHA3 in a unit test, to at least touch it at some point. - Documented the support of SHA3. - Only install the third-party library required by Python 3.5 when we're running on Python 3.5. Newer Python versions support SHA3 natively.
* Added type annotations + some fixes to get them correctSybren A. Stüvel2019-08-0412-116/+129
| | | | | | One functional change: `CryptoOperation.read_infile()` now reads bytes from `sys.stdin` instead of text. This is necessary to be consistent with the rest of the code, which all deals with bytes.
* Added mypy for static type checkingSybren A. Stüvel2019-08-041-5/+5
|
* Removed compatibility code for Python 2.7 and 3.4Sybren A. Stüvel2019-08-0414-359/+20
|