| Commit message (Collapse) | Author | Age | Files | Lines |
| |
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
`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.
|
| |
|
| |
|
| |
|
|
|
|
|
|
|
| |
Use the Chinese Remainder Theorem when decrypting with private key, as that
makes the decryption 2-4x faster.
This fixes #163.
|
|
|
|
| |
No functional changes.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
| |
When a `PrivateKey` or `PublicKey` is unpickled `AbstractKey.__init__()`
should be called so `self.mutex` and `self.blindfac` are created.
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
|
| |
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
|
| |
|
| |
|
|
|
|
| |
This is a requirement for RSA blinding, but wasn't implemented yet.
|
| |
|
|
|
|
|
|
| |
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.
|
| |
|
|
|
| |
"if A and B" if mostly A is True then we should judge B at first
|
|
|
| |
Good catch, thanks!
|
|
|
| |
Thanks for the improvements!
|
| |
|
| |
|
| |
|
|
|
|
|
|
| |
Overriding __eq__ blocks inheritance of __hash__ in Python 3.
Fixes issue #55
|
|
|
|
|
|
| |
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.
|
| |
|
|
|
|
|
| |
Ensuring that bytes are written correctly on all supported Python
versions, including when writing to stdout.
|
|
|
|
|
|
| |
Also:
- changed http to https in the code
- changed header underlines in the documentation to match the header length
|
| |
|
|
|
|
|
|
|
|
| |
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.
|
| |
|
| |
|
|
|
|
|
| |
If exp1 was not given and exp2 was, it would still recompute exp2
instead of using the passed value.
|
|
|
|
|
| |
Pickling is now possible, with the added note that one should never
unpickle from an untrusted or unauthenticated source.
|
| |
|
| |
|
| |
|
| |
|
|
|
|
|
| |
This prevents side-channel (such as timing) attacks, see:
https://en.wikipedia.org/wiki/Blinding_%28cryptography%29
|
| |
|
|
|
|
|
| |
Mostly focused on docstrings (''' → """), indentation, empty lines,
and superfluous parenthesis.
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|