New features
- Argon2 (RFC 9106) in
Crypto.Protocol.KDF:argon2()derives keys, andargon2_hash()
andargon2_check()store and check passwords as PHC strings ($argon2id$v=19$...),
compatible with most other implementations. Argon2id, Argon2i and Argon2d are supported,
the lanes run on as many threads as the CPU cores by default (threads), the blocks are computed with SSE2
or AVX2 on x86, andArgon2Profileoffers
the recommended parameters of RFC 9106, OWASP and libsodium.
argon2_check()rejects hashes that need too much memory (max_memory) or time (max_cost). - GH#843:
import_key()of RSA, DSA and ECC accepts an OpenSSH certificate
(such asssh-rsa-cert-v01@openssh.com) and returns the certified public key.
The certificate is not verified. - GH#402:
Shamir.split()andShamir.combine()accept 32-byte secrets and shares, in GF(2^256).
Withssss=True, the shares are compatible withssss -s 256 -D.
Resolved issues
ECC.import_key()showed binary data (as the curve name) in the error
for an unsupported OpenSSH key type starting withecdsa-sha2-.DSA.construct(),DSA.import_key()andDSA.generate()(withdomain) raiseValueError
(instead ofZeroDivisionError) whenqorpis 0.- DSA keys are limited to
pandqof 16384 bits, as RSA keys:
DSA.construct()andDSA.import_key()raiseValueErrorfor larger ones,
and for aqthat is not smaller thanp, before the primality tests.
A large public key from an untrusted source could take minutes to import. RSA.import_key()andDSA.import_key()raiseValueError(instead ofIndexError)
for an OpenSSH public key with missing components.- GH#493:
DSSin mode'fips-186-3'with a DSA key raisesValueError(instead ofAttributeError)
for an object that is not a hash, for instance an HMAC. Thanks to koolfy. - GH#493: An
HMACobject created with a hash module (for instance,digestmod=SHA256) now has the attributeoid,
as one created with a hash object (digestmod=SHA256.new()). Thanks to koolfy. - GH#974:
ECC.import_key()accepts an OpenSSH public key with spaces in its comment.
Thanks to mottopanikeiku. - With the parameter
threads, a function no longer fails withRuntimeErrorwhen the system
cannot create all the threads (for instance, because of a limit on the number of processes):
the calling thread does their work. - GH#973: A
DerSequenceinitialized with a tuple can now be modified like one initialized with a list.
Thanks to mottopanikeiku. - GH#535:
RSA.import_key()rejects a PKCS#1 private key (also inside PKCS#8)
whose CRT components (exponent1,exponent2,coefficient) do not match the key.
They were ignored and recomputed. Thanks to sfluhrer. - GH#535:
RSA.generate()rejects a public exponent of2^256or more (the upper bound of FIPS 186).
Thanks to Bl4omArchie. - GH#535:
RSA.construct()no longer requires the private exponent to be coprime to the modulus.
That check was redundant, and would have rejected (with negligible probability) a valid key.
Thanks to sfluhrer. - GH#976: In deterministic mode (RFC 6979),
DSSraisedAssertionErrorwhen signing
a hash that is 0 modulo the order (for instance, equal to the order). Thanks to Anton Efimow. - GH#972:
Crypto.Util.asn1.DerNullaccepted a NULL with non-empty contents (X.690, 8.8.2),
so an RSA, EdDSA or XDH key (SubjectPublicKeyInfoor PKCS#8) whose NULL parameters
carried extra bytes was imported as the same key. A PKCS#8 RSA key with parameters
other than NULL is also rejected (RFC 8017, Appendix C). Thanks to Zulfareen Shaikh.
Other changes
- Added the Wycheproof test vectors for PBKDF2 (with HMAC-SHA1, SHA-224, SHA-256, SHA-384 and SHA-512).
- Faster imports, which matters for short scripts. With
cffi, the declarations of the native modules
are precompiled (cffi's out-of-line ABI mode), so neither thecffipackage norpycparseris imported.
Withctypes,ctypes.util,platformandsubprocessare no longer imported (about 20 ms less). - With Python 3.15+, more modules are imported only when they are first used (PEP 810).
- GH#228: With
-OO, PyCryptodome usescffitoo (instead of falling back toctypes).