summaryrefslogtreecommitdiff
path: root/rsa/key.py
Commit message (Collapse)AuthorAgeFilesLines
* language correction and speed-upHEADmainmyheroyuki2023-04-251-13/+0
|
* 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.
* 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
|
* Fix typosKian-Meng, Ang2021-11-241-1/+1
|
* 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-291-98/+117
| | | | No functional changes.
* Fix exception causes all over the codebaseRam Rachum2021-02-241-3/+3
| | | | | | | | | | | | | | | | | | | | | | 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.
* 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.
* 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.
* 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
* Add more type hintsAndrey Semakin2020-06-031-12/+16
|
* Drop character encoding markers for Python 2.xAndrey Semakin2020-06-031-2/+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.
* Added flake8 as development dependency and fixed reported issuesSybren A. Stüvel2019-08-041-1/+2
|
* Added type annotations + some fixes to get them correctSybren A. Stüvel2019-08-041-46/+49
| | | | | | 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.
* Removed compatibility code for Python 2.7 and 3.4Sybren A. Stüvel2019-08-041-1/+0
|
* speedupyjqiang2018-09-161-1/+1
| | | "if A and B" if mostly A is True then we should judge B at first
* Use iterative zip in Python 2 (#85)Michael Manganiello2017-01-171-1/+1
| | | Good catch, thanks!
* Remove custom PrivateKey exponents/coefficient (#71)Michael Manganiello2017-01-051-32/+25
| | | Thanks for the improvements!
* Fixes a typo in docstrings (#83)Alexandr2016-11-081-2/+2
|
* Drop byte_literal in favour of b''adamantike2016-05-081-3/+3
|
* xrange compatibility optimization for Python 2 (#69)Michael Manganiello2016-05-081-1/+1
|
* Implemented __hash__ function for key objects.Sybren A. Stüvel2016-03-291-0/+6
| | | | | | Overriding __eq__ blocks inheritance of __hash__ in Python 3. Fixes issue #55
* Introduced NotRelativePrimeError exception.Sybren A. Stüvel2016-03-291-3/+5
| | | | | | This makes catching exceptions slightly stronger, as it is now possible to check for this specific exception. Furthermore, information about the not-prime numbers is included in the exception object.
* PEP8 formattingSybren A. Stüvel2016-03-291-9/+9
|
* More CLI tests & clearer bytes stuffSybren A. Stüvel2016-03-171-7/+58
| | | | | Ensuring that bytes are written correctly on all supported Python versions, including when writing to stdout.
* Updated documentation, mostly http -> https changesSybren A. Stüvel2016-02-051-1/+1
| | | | | | Also: - changed http to https in the code - changed header underlines in the documentation to match the header length
* Fixed PEP8 style issuesSybren A. Stüvel2016-01-271-3/+3
|
* Fix #18: Add an 'exponent' argument to key.newkeys()Sybren A. Stüvel2016-01-271-15/+41
| | | | | | | | Adds the possibility to create a new key using a custom exponent. Mostly for compatibility. Also removed the unused parameter nbits from calculate_keys(). I added a new function calculate_keys_custom_exponent() so that people still passing a value to nbits don't accidentally use it as the exponent.
* Removed unused importSybren A. Stüvel2016-01-271-1/+1
|
* Removed code duplicationSybren A. Stüvel2016-01-271-11/+13
|
* Fixed bug where PrivateKey.exp2 wasn't correctly processed in the constructor.Sybren A. Stüvel2016-01-271-5/+5
| | | | | If exp1 was not given and exp2 was, it would still recompute exp2 instead of using the passed value.
* Fix #12 Allow pickling of keys.Sybren A. Stüvel2016-01-221-0/+24
| | | | | Pickling is now possible, with the added note that one should never unpickle from an untrusted or unauthenticated source.
* Removed doctest for blinding, as it is not suitable as an example for end users.Sybren A. Stüvel2016-01-221-8/+0
|
* Another pass at blinding.Sybren A. Stüvel2016-01-221-17/+18
|
* Use random number when blinding, and also blind when verifying signatures.Sybren A. Stüvel2016-01-221-36/+72
|
* Fixed some docstrings to use Sphinx-compatible notationSybren A. Stüvel2016-01-221-14/+15
|
* Fix #19: Implemented blinding when decrypting.Sybren A. Stüvel2016-01-221-0/+36
| | | | | This prevents side-channel (such as timing) attacks, see: https://en.wikipedia.org/wiki/Blinding_%28cryptography%29
* Fix #30, removed use of deprecated `base64.decodestring` from docstringsSybren A. Stüvel2016-01-221-2/+2
|
* Big refactor to become more PEP8 compliant.Sybren A. Stüvel2016-01-221-84/+83
| | | | | Mostly focused on docstrings (''' → """), indentation, empty lines, and superfluous parenthesis.
* Primes regeneration in RSA keys generationMichael Manganiello2016-01-211-3/+11
|
* Corrected accurate mode of 'newkeys' functionMichael Manganiello2016-01-211-2/+4
|
* Explicitly cast ASN.1 integer type to Python intSybren A. Stüvel2012-10-121-1/+1
|
* Added support for loading public keys from OpenSSLSybren A. Stüvel2012-10-111-18/+49
|
* Reverts docstring quoting syntax.Yesudeep Mangalapilly2011-08-241-37/+37
|
* Parellelized testing. Caught a lot of bugs.Yesudeep Mangalapilly2011-08-161-31/+31
|
* Porting to Python 3 complete. All tests except pyasn1 stuff pass.Yesudeep Mangalapilly2011-08-111-2/+3
|
* Tests are now functional (only running without syntax errors) on Python 3 too.Yesudeep Mangalapilly2011-08-111-5/+5
|