./security/py-cryptodome, Cryptographic and hash functions for Python

[ CVSweb ] [ Homepage ] [ RSS ] [ Required by ]


Branch: CURRENT, Version: 4.6.0, Package name: py314-cryptodome-4.6.0, Maintainer: pkgsrc-users

PyCryptodome is a self-contained Python package of low-level cryptographic
primitives.


Required to run:
[devel/gmp] [devel/py-setuptools] [lang/python37]

Required to build:
[pkgtools/cwrappers]

Master sites:

Filesize: 1929.82 KB

Version history: (Expand)


CVS history: (Expand)


   2026-11-22 20:22:20 by Thomas Klausner | Files touched by this commit (5) | Package updated
Log message:
py-cryptodome: update to 4.6.0.

Guess PLIST* where some new .so files belong, please fix them if I
guessed incorrectly.

New features

    New module Crypto.PublicKey.SLHDSA, for SLH-DSA keys (FIPS
    205), with all twelve parameter sets (SHA2 and SHAKE, categories
    1, 3 and 5, small or fast). The algorithms of FIPS 205 are in
    Python; the functions that compute most of the hashes (WOTS+
    chains, XMSS and FORS tree nodes) are in C, on top of the SHA-2
    and Keccak code of PyCryptodome. The C functions compute several
    hashes at once where the CPU allows it: 4 SHA-256 hashes with
    the Intel SHA extensions (interleaved) or the ARMv8 SHA-256
    instructions, 8 SHA-256 hashes with AVX2 (when there are no
    SHA extensions), and 4 SHAKE256 hashes with AVX2 and BMI2 (4-way
    Keccak). The WOTS+ chains of a key pair are computed in one
    call to C.

    SLH-DSA keys can be exported and imported as defined in RFC
    9909 (pure SLH-DSA): public keys as X.509 SubjectPublicKeyInfo
    (also from certificates), private keys as PKCS#8 OneAsymmetricKey
    (also encrypted), in DER or PEM.

    New module Crypto.Signature.slhdsa, for SLH-DSA and HashSLH-DSA
    signatures (FIPS 205), hedged (default) or deterministic, with
    an optional context.

    SLH-DSA signing, key generation and construct() (which checks
    the private key) accept a parameter threads, to compute the
    XMSS and FORS trees on several threads. With 8 threads, signing
    with the s parameter sets is 3.5x to 5x faster.

    Crypto.PublicKey.SLHDSA also supports the six parameter sets
    of the initial public draft of NIST SP 800-230 (April 2026),
    such as SLH_DSA_SHA2_128_24: smaller signatures and faster
    verification, but each key must sign at most 2^24 messages,
    and key generation and signing take minutes (use threads). The
    draft may still change: their support is experimental, and they
    must not be used in production.

    New self-test option --include-very-slow-tests, for the tests
    marked very_slow (like key generation and signing with the SP
    800-230 parameter sets, which take about half an hour): they
    do not run otherwise.

    New module Crypto.Cipher.AEGIS, for the authenticated ciphers
    AEGIS-128L and AEGIS-256 (RFC 10032), with 16- or 32-byte tags.
    They use the AES instructions of the CPU (AES-NI or the ARMv8
    Cryptography Extensions): AEGIS-128L is then 3 to 5 times faster
    than AES-GCM. Without them, the AES round is bitsliced (constant
    time), with NEON on ARM and SSE2 on x86; on 64-bit ARM, AEGIS-128L
    is then still faster than ChaCha20-Poly1305.

Breaking changes

    In Crypto.Signature.mldsa.new(), the context can only be passed
    as a keyword argument (context=), as for Crypto.Signature.slhdsa.new().

Resolved issues

    Security, GH#968: ECC.construct(), and so ECC.import_key(),
    accepted the point at infinity as a public key on the NIST P
    curves and secp256k1 (for instance, 04 followed by zero bytes
    in a SubjectPublicKeyInfo). ECDSA signatures for such a key
    can be forged without any secret. It is now rejected with
    ValueError. Thanks to Zulfareen Shaikh.

    Security, GH#969: DSA.construct(), and so DSA.import_key(),
    accepted public keys equal to 1 or outside the subgroup of
    order q (for instance, p - 1). For y = 1, a signature can be
    forged on any message without any secret. They are now rejected
    with ValueError (NIST SP 800-89, 5.3.1). Thanks to Zulfareen
    Shaikh.

    GH#966: in the decrypt_and_verify() method of GCM, CCM, EAX
    and SIV, the output buffer is filled with zeroes if the MAC
    tag is not valid, so that no unauthenticated plaintext is left
    in it (as GCM-SIV already did). Thanks to Zulfareen Shaikh.

    Security: decoding a DER INTEGER took time quadratic in its
    length, so a crafted key of a few hundred KB (for instance,
    for RSA.import_key) kept the CPU busy for minutes. It now takes
    linear time. Decoding an OBJECT IDENTIFIER had the same problem:
    its subidentifiers are now limited to 128 bytes. Thanks to
    netherportal3.

    GH#965: DSA key import now rejects non-integer domain parameters
    with ValueError. Thanks to Mrmaxmeier.

    GH#963: Fixed the build on the x32 ABI (ILP32 on x86-64). Thanks
    to Kenny Cheng.

    GH#864: The type hints of the scalar multiplication of EC points
    accept Integer objects. Thanks to danrr and hakarrr.
   2026-11-22 20:14:34 by Thomas Klausner | Files touched by this commit (3) | Package updated
Log message:
py-cryptodome: update to 4.5.0.

4.5.0 (15 November 2026)

New features

    Added the mode MODE_GCM_SIV to Crypto.Cipher.AES (AES-GCM-SIV,
    RFC 8452), for authenticated encryption that is resistant to
    the reuse of a nonce.

    Added the mode MODE_XTS to Crypto.Cipher.AES (IEEE 1619, NIST
    SP 800-38E), for the encryption of storage.

    CTR mode is about 35% faster on short bytes messages.

Breaking changes

    export_key of RSA and DSA keys raises ValueError for a private
    key in the 'OpenSSH' format, like ECC keys. It used to silently
    return the public key, ignoring any passphrase. To export the
    public key, use key.public_key().export_key('OpenSSH').

Resolved issues

    Security: the base64 body of a PEM block (for instance, a
    private key that is not encrypted) was decoded with
    binascii.a2b_base64, which looks up each character in a table,
    and could leak the key through a cache side channel. The body
    is now decoded in constant time, and it is no longer processed
    by Python string functions that look up characters in a table.
    Thanks to Li-Chung Chiang.
   2026-11-09 12:29:59 by Thomas Klausner | Files touched by this commit (1)
Log message:
py-cryptodome: remove comment

SunOS line is indeed needed.
   2026-11-08 18:41:36 by Thomas Klausner | Files touched by this commit (3) | Package updated
Log message:
py-cryptodome: update to 4.4.0.

4.4.0 (7 November 2026)

New features

    Added the elliptic curve secp256k1 to Crypto.PublicKey.ECC: key generation, \ 
import and export, ECDSA with Crypto.Signature.DSS, and ECDH with \ 
Crypto.Protocol.DH.

    Added the mode 'sec1' to Crypto.Signature.DSS.new, for randomized \ 
ECDSA on all Weierstrass curves. Mode 'fips-186-3' does not accept \ 
secp256k1, which is not a curve of that standard.

    GH#759: Added the parameter low_s to Crypto.Signature.DSS.new, for ECDSA \ 
signatures in the low-S form (for all curves): signing normalizes s, and \ 
verifying rejects a high s.

    ECDSA signatures in DER encoding are about 5-8x faster.

Resolved issues

    ECC.import_key raised TypeError instead of ValueError for an OpenSSH public \ 
key with an unsupported curve or key type, or with a malformed body.

    ECC.import_key accepted an OpenSSH key (public or private) whose curve did \ 
not match its key type.

    GH#960: In HPKE, a message rejected by unseal() consumed a sequence number, \ 
so all later messages of that context failed too. The sequence number now only \ 
advances when unseal() succeeds (RFC 9180, Section 5.2). Thanks to Zulfareen \ 
Shaikh.

    In HPKE, a seal() that raised an exception also consumed a sequence number, \ 
so the receiver could not unseal the messages that followed.

4.3.0 (2 November 2026)
New features

    CTR mode is 2.5-3.5x faster on large data (and GCM about 2x), on all platforms.

    On 64-bit ARM CPUs (Linux, macOS and Windows), AES and GHASH use the \ 
instructions of the ARMv8 Cryptography Extensions (AES and PMULL), when \ 
available. On a Graviton3, AES-ECB is about 35x faster, GCM 7x, OCB 10-12x, and \ 
CTR, CBC, CFB and OFB 3-6x.

    Integer.random_range() is about 2x faster when the bounds are public, with \ 
the same output: ECDSA signatures are about 13% faster (P-256), DSA signatures \ 
about 4%, and ECC key generation about 35%. The RSA modulus and the DSA subgroup \ 
order are now public Integer objects.

    Faster RSA: on x86-64, signatures and decryption are 35-40% faster (RSA-2048 \ 
to RSA-4096), verification and encryption 2-2.7x. Modular exponentiation with a \ 
public exponent (like the RSA public exponent) no longer uses the slower \ 
constant-time algorithm, which is only needed for secret exponents, and the \ 
Montgomery context of a modulus is kept with it. The RSA blinding factor is \ 
squared between uses (a new one every 32 uses, and after a fork).

    The Montgomery multiplication for x86-64 CPUs with BMI2 and ADX is about 20% \ 
faster: DSA signatures and verification are about 25% faster.

    ECDSA signatures are 3-6% faster for P-256 and P-384: the field inversion \ 
uses the faster power for public exponents (the exponent p - 2 is public).

    On 64-bit ARM CPUs, SHA-224 and SHA-256 use the SHA-256 instructions of the \ 
ARMv8 Cryptography Extensions, and SHA-384 and SHA-512 the SHA-512 instructions \ 
of ARMv8.2, when available. On a Graviton3, SHA-256 is about 3.8x faster, and \ 
SHA-512 2x.

    On 64-bit ARM CPUs, KangarooTwelve, ML-KEM and ML-DSA compute 4 Keccak \ 
states at once (2 with scalar code and 2 with NEON). On a Graviton3, \ 
KangarooTwelve is 1.9x faster, ML-DSA 7-20% and ML-KEM 7-8%.

    PKCS#1 v1.5 decryption (Crypto.Cipher.PKCS1_v1_5) performs implicit \ 
rejection, as defined in section 7.2 of draft-irtf-cfrg-rsa-guidance, when \ 
decrypt() is called without a sentinel (which is now optional): when the padding \ 
of a ciphertext is not correct, it returns a pseudo-random message, which only \ 
depends on the private key and on the ciphertext. With a sentinel, decrypt() \ 
behaves as before.

Other changes

    Updated the Wycheproof test vectors (new Ed25519 tests and the new \ 
chacha20_counter_test.json). XChaCha20 keeps the construction of \ 
draft-irtf-cfrg-xchacha (HChaCha20 and the ChaCha20 of RFC 8439), with a 32-bit \ 
block counter: the key stream ends after 256 GiB, whereas libsodium and \ 
Wycheproof use a 64-bit counter.

Resolved issues

    GH#481: PKCS#1 v1.5 decryption could be used as a Bleichenbacher oracle, \ 
through the sentinel returned for ciphertexts with incorrect padding. Calling \ 
decrypt() without sentinel (implicit rejection) is now recommended. Thanks to \ 
tomato42 and eslerm.

    PKCS#1 v1.5 decrypt() never returned a sentinel that is not a byte string \ 
(such as None), and it returned an empty byte string instead.

    GH#954: Crypto.Util.asn1.DerObjectId accepted an ASN.1 OBJECT IDENTIFIER \ 
where an arc is encoded with the initial octet 0x80 (invalid, as that would \ 
violate the minimal encoding rule for BER) or where the last octet encoding the \ 
last arc has bit 7 set (invalid, and that arc would also be dropped). In those \ 
cases, decoding now fails. Thanks to Zulfareen Shaikh.
   2026-10-31 07:35:39 by Adam Ciarcinski | Files touched by this commit (1)
Log message:
py-cryptodome: fix PLIST.i386
   2026-10-30 19:49:36 by Adam Ciarcinski | Files touched by this commit (2)
Log message:
py-cryptodome: fix PLIST for non-x86_64 systems
   2026-10-27 12:57:59 by Thomas Klausner | Files touched by this commit (3) | Package updated
Log message:
py-cryptodome: update to 4.2.0.

4.2.0 (24 October 2026)
++++++++++++++++++++++++++

New features
------------
* New module ``Crypto.PublicKey.MLKEM``, for ML-KEM keys (FIPS 203).
  It is based on the portable C code of
  `mlkem-native <https://github.com/pq-code-package/mlkem-native>`_ (v2.0.0),
  with the Keccak code of PyCryptodome, also compiled for AVX2 and BMI2 (with \ 
4-way SHA-3).
  The keys can be exported and imported as PKCS#8 DER or PEM files.
* New module ``Crypto.PublicKey.Hybrid``, to model hybrid keys (post-quantum + \ 
traditional).
  It supports the hybrid KEM MLKEM768-X25519 (X-Wing), which combines ML-KEM-768 \ 
and X25519.
  For now, hybrid keys can only be generated and used with HPKE: they cannot be \ 
exported or imported.
* ``Crypto.Protocol.HPKE`` accepts ML-KEM keys and X-Wing keys,
  for post-quantum HPKE (draft-ietf-hpke-pq), in the Base and PSK modes.

4.1.0 (19 October 2026)
++++++++++++++++++++++++++

New features
------------
* New module ``Crypto.PublicKey.MLDSA``, for ML-DSA keys (FIPS 204).
  It is based on the portable C code of `mldsa-native \ 
<https://github.com/pq-code-package/mldsa-native>`_
  (v2.0.0), with the Keccak code of PyCryptodome. On CPUs with AVX2 and BMI2, a \ 
version
  compiled for them and with 4-way SHA-3 is used: compared to the portable version,
  key generation and verification are 30-45% faster, signing 15-30%.
* New module ``Crypto.Signature.mldsa``, for ML-DSA and HashML-DSA signatures \ 
(FIPS 204),
  hedged (default) or deterministic, with an optional context.
  The new ``MLDSAMuHash`` computes the message representative mu (external mu),
  to sign or verify a large message in pieces.
* New function ``digest()`` in the modules of the SHA-2 and SHA-3 hashes,
  to hash a whole message with a single call,
  like ``Crypto.Hash.KangarooTwelve.digest()``. For messages up to 1 KiB,
  it is 1.5x to 3.4x faster than ``new()`` followed by ``digest()``.
* ``Crypto.IO.PKCS8.wrap()`` has a new parameter ``public_key``, to create a \ 
``OneAsymmetricKey``
  version 2 (RFC 5958) with the field ``publicKey``.
  ``Crypto.IO.PKCS8.unwrap()`` returns an ``UnwrappedKey``: still a tuple \ 
``(oid, private_key, params)``,
  with the same items as attributes, plus ``public_key`` (the field \ 
``publicKey``, if present).
* The scalar Keccak permutation (used by SHA-3, SHAKE, cSHAKE, KMAC, TupleHash, \ 
TurboSHAKE
  and KangarooTwelve) processes the state one plane at a time, two rounds per \ 
iteration,
  which needs fewer registers: SHA-3 and SHAKE are 5-10% faster.

Resolved issues
---------------
* ``Crypto.PublicKey.ECC.import_key()`` checks that the field ``publicKey`` of a \ 
PKCS#8
  ``OneAsymmetricKey`` version 2 (RFC 5958), if present, matches the private key.
  Before, it was ignored.

4.0.1 (17 October 2026)
++++++++++++++++++++++++++

New features
------------
* The Windows wheels for x86-64 are built with ``clang-cl`` (compatible with \ 
MSVC), so the
  code for CPUs with AVX2, BMI2 and ADX is also used on Windows: SHA-3 and the other
  Keccak-based functions, KangarooTwelve, ChaCha20, Salsa20, and the big \ 
integers of RSA,
  DSA and the NIST curves. To build from source with ``clang-cl``, set the \ 
environment
  variable ``PYCRYPTODOME_CLANG_CL`` (see the installation instructions).

4.0.0 (14 October 2026)
++++++++++++++++++++++++++

Breaking changes
----------------
* Remove support for Python 2.7 and 3.8. The minimum supported version is now \ 
Python 3.9.
* The ``pycryptodomex`` package (``Cryptodome`` namespace) is no longer released
  (except for important security patches, but still on the 3.x branch).
  The library is only available as ``pycryptodome``, under the ``Crypto`` namespace.
* The self-tests are now run by ``pytest``, which must be installed for
  ``python -m Crypto.SelfTest`` to work. The ``test`` command of ``setup.py`` is \ 
removed:
  install the package (e.g. with ``pip install -e .``) and run ``python -m \ 
Crypto.SelfTest`` instead.
* In ``Crypto.Protocol.KDF.SP800_108_Counter()``, the ``label`` can no longer
  contain zero bytes, while the ``context`` now can (for instance, a binary nonce).
  The zero byte between them still separates the two unambiguously,
  as required by NIST SP 800-108r1 (GH#896).
* The coordinates of ``EccPoint`` and ``EccXPoint`` (``x``, ``y`` and ``xy``),
  ``EccKey.d`` and the components of ElGamal keys (``p``, ``g``, ``y`` and ``x``)
  are now Python ``int`` objects, not ``Crypto.Math.Numbers.Integer``.
  The ElGamal components can no longer be assigned.
* The GMP library is no longer used, and the environment variable
  ``PYCRYPTODOME_DISABLE_GMP`` has no effect. Big integers are handled by the
  new constant-time code (see below). ``Crypto.Math.Numbers.Integer``
  (an internal class) no longer supports negative values.
* Elliptic curve points are decoded more strictly. Importing a NIST curve public key
  (SEC1, DER, PEM or OpenSSH) fails if a coordinate of the point is equal to or
  larger than the modulus ``p``, as required by SEC1 (such coordinates were reduced
  modulo ``p`` before; ``EccPoint`` and ``ECC.construct()`` still reduce them).
  Ed25519 and Ed448 points (public keys, and ``R`` in signatures) are decoded
  as in RFC 8032: an encoding with x = 0 and the sign bit of x set,
  or (for Ed448) with any of the 7 low bits of the last byte set, is now rejected.
* RSA keys are limited to a modulus of 16384 bits: ``RSA.generate()``,
  ``RSA.construct()`` and ``RSA.import_key()`` raise ``ValueError`` for
  larger ones. The constant-time arithmetic is slower than GMP, and a large
  public key from an untrusted source could take minutes to import or use.
* ``Crypto.Protocol.KDF.bcrypt_check()`` rejects (with \ 
``Crypto.KdfIterationLimitError``,
  a ``ValueError``) a bcrypt hash whose cost
  is above 20, which takes about one minute: a hash from an untrusted source, \ 
which states
  its own cost, could otherwise tie up the CPU for a day. Use the new parameter \ 
``max_cost``
  to accept costs up to 31, as before (0 for no limit).
* ChaCha20-Poly1305 with an 8-byte nonce follows RFC 8439 (the nonce is prefixed
  by 4 zero bytes, and the block counter has 32 bits): a single message longer than
  about 256 GiB is now rejected with ``MessageTooLongError``. Before, the counter
  overflowed into the 4 zero bytes, which no specification defines. The ciphertext
  and the tag of shorter messages are unchanged.
* Exporting a private key with a passphrase uses PKCS#8 with
  ``'PBKDF2WithHMAC-SHA256AndAES256-CBC'`` and 600 000 iterations by \ 
default,
  instead of weak schemes. With RSA keys, ``export_key(passphrase=...)`` returned
  a PKCS#1 key with the obsolete PEM encryption (one round of MD5 and 3DES, easy \ 
to brute force),
  and now returns an ``ENCRYPTED PRIVATE KEY``: the parameter ``pkcs`` of \ 
``RsaKey.export_key()``
  is now ``None`` by default (PKCS#1 for a key in the clear, as before, PKCS#8 \ 
with a passphrase).
  Without ``protection``, ``export_key()`` of RSA and DSA keys and \ 
``Crypto.IO.PKCS8.wrap()``
  used ``'PBKDF2WithHMAC-SHA1AndDES-EDE3-CBC'``, and ECC keys raised \ 
``ValueError``.
  When ``prot_params`` does not specify them, the iteration count of PBKDF2 is \ 
now 600 000 (it was 1000)
  and the cost N of scrypt 131 072 (it was 16 384), which meet the OWASP \ 
recommendations.
  The obsolete PEM encryption is only used with an explicit ``pkcs=1`` (RSA), \ 
``pkcs8=False`` (DSA)
  or ``use_pkcs8=False`` (ECC); with RSA and DSA, ``protection`` and ``prot_params``
  are then rejected, instead of being silently ignored.
  Also, ``protection`` or ``prot_params`` without a passphrase raise ``ValueError``,
  for RSA, DSA and ECC keys: before, the key was exported in the clear.
* Removed ``Crypto.Util.number.long2str()`` and ``str2long()``, aliases of
  ``long_to_bytes()`` and ``bytes_to_long()`` deprecated since PyCrypto.

Deprecations
------------
* ``Crypto.Hash.HMAC.new()`` without ``digestmod`` (which then uses MD5) emits a
  ``DeprecationWarning``. The default will be removed: always pass the hash
  (for instance, ``digestmod=SHA256``), as with Python's ``hmac`` module.
* ``Crypto.Protocol.KDF.PBKDF2()`` without ``count`` (which then uses 1000 \ 
iterations)
  or without ``hmac_hash_module`` and ``prf`` (which then uses HMAC-SHA1) emits a
  ``DeprecationWarning``. These weak defaults will be removed: always pass them
  (for instance, ``count=600000, hmac_hash_module=SHA256``).

Resolved issues
---------------
* ``Crypto.Util.number.long_to_bytes()`` took quadratic time on large integers:
  now it uses ``int.to_bytes()``, and ``bytes_to_long()`` uses ``int.from_bytes()``.
* The ``verify()`` methods of MACs and AEAD modes, and ``bcrypt_check()``, compare
  the tags with ``hmac.compare_digest()``, instead of two BLAKE2s MACs with a \ 
random key.
* Updated the references to superseded RFCs (PKCS#1 to RFC 8017, PKCS#5 to RFC 8018,
  PKCS#8 to RFC 5958), and fixed typos in error messages.
* Exporting a private key with an empty passphrase of type ``bytes`` returned the key
  in the clear, instead of raising ``ValueError``: for ECC keys in all formats,
  and for RSA (``pkcs=1``) and DSA (``pkcs8=False``) keys in DER format.
* ``RsaKey.export_key()`` with ``format='PEM'``, ``pkcs=8``, a \ 
``protection`` but no passphrase
  labeled the key in the clear as ``ENCRYPTED PRIVATE KEY`` (now it raises \ 
``ValueError``).
* Importing a private key in clear PKCS#8 format failed if a passphrase was
  also given; now the passphrase is ignored, as for the other formats.
* ``Crypto.Math.Primality``: the trial division by small primes in \ 
``test_probable_prime()``
  never ran (only the Miller-Rabin and Lucas tests did), which made the generation
  of RSA, DSA and ElGamal keys slower; and the primality tests reported 1 as a \ 
probable prime.
* Key comparison: ElGamal key objects could not be compared for equality, two \ 
DSA keys
  always compared as equal if both were public or both private, and comparing an RSA,
  DSA or ElGamal key with an object of a different type raised ``AttributeError``
  instead of returning ``False``.
* EdDSA signatures with ``S`` equal to the order of the curve are now rejected, \ 
as required by RFC 8032.
* A few valid Ed25519 points (those where one side of the curve equation is very \ 
small,
  for instance with y = 3) were rejected as not on the curve.
* Ed25519 and X25519: the final reduction modulo the prime (when
  converting a point to bytes, including the X25519 shared secret) could
  branch on secret data, depending on the compiler and the target
  (for instance, gcc -O3 on 32-bit x86, and the code without SSE2 built with clang).
  It is now constant time, checked with Valgrind like the rest of the elliptic \ 
curves.
* The legacy ``can_decrypt()`` method of PKCS#1 ciphers raised ``AttributeError``
  and not a boolean.
* The ``update()`` method for SIV encryption objects now returns the cipher object,
  like for other AEAD modes.
* Fixed the method ``new()`` of KMAC256 and TupleHash256 objects:
  it created a KMAC128 or TupleHash128 object instead (for KMAC, also accepting
  keys shorter than the 32 bytes required for KMAC256).
* Added the missing documentation for ``Crypto.Hash.MD4``.
* Salsa20 never returned when encrypting or decrypting 4 GiB or more in a single \ 
call.
* The package metadata declares the license as an SPDX expression
  (``BSD-2-Clause AND Unlicense``, PEP 639), which tools can process.
* ``Crypto.Protocol.HPKE.new()`` raised ``TypeError`` with Python 3.9 to 3.11
  when ``aead_id`` was a plain integer, and not an ``HPKE.AEAD`` member.
* GH#937: Importing a malformed PEM key could take quadratic time. Thanks to \ 
Brian Willows.
* Importing an encrypted OpenSSH private key (with ``RSA.import_key()`` or
  ``ECC.import_key()``) had no limit on the number of rounds of bcrypt_pbkdf,
  which the key states: a malicious key could tie up the CPU for months.
  Now ``max_iteration_count`` limits it (by default, 16,384 rounds, about one \ 
minute),
  and a key with less than one round is rejected.
* PKCS#8 keys: ``Crypto.PublicKey.RSA.import_key()`` accepted a PKCS#8 key whose \ 
private key
  was not an ``RSAPrivateKey`` (PKCS#1), including another, possibly encrypted, \ 
PKCS#8 key:
  now such a key is rejected. An encrypted PKCS#8 key with an iteration count \ 
lower than 1,
  or with invalid scrypt parameters (*N* not a power of 2 larger than 1, *r* or \ 
*p* not
  positive), raised other exceptions than ``ValueError`` (like \ 
``ZeroDivisionError``):
  now it is rejected with ``ValueError``, before any key derivation.
* Encrypted PKCS#8 keys protected with PBKDF2 (PBES2) were exported and imported
  with the slow Python implementation of PBKDF2-HMAC, and not with the C one:
  now they are about 50x-150x faster (SHA-1 and SHA-2).
* GH#794, GH#795: the C tests failed to link on Debian armel (where the gcc
  sanitizers need ``libatomic``) and mips64el (where gcc has no sanitizers);
  now ``libatomic`` is linked when needed, and the tests run without the
  sanitizers if they cannot be linked at all.

New features
------------
* GH#320: importing an encrypted private key (PEM, PKCS#8 or OpenSSH) without
  a passphrase raises ``Crypto.PassphraseRequiredError``, and with
  an incorrect passphrase ``Crypto.IncorrectPassphraseError``.
  Both are subclasses of ``ValueError``, like before; the messages are also clearer.
  This applies to ``import_key()`` of RSA, DSA and ECC, to \ 
``Crypto.IO.PKCS8.unwrap()``
  and to ``Crypto.IO.PEM.decode()``.
  A new page of the documentation lists the dedicated exceptions of the library.
* New exception ``Crypto.MessageTooLongError``, raised when a cipher would process
  more data than allowed with the same key and nonce: CCM (it replaces
  ``CCMMessageTooLongError``, still available as an alias), GCM, CTR, ChaCha20,
  ChaCha20-Poly1305, Salsa20, KW and KWP. It is a subclass of both ``ValueError``
  and ``OverflowError``, which those ciphers used to raise. GCM now checks the
  limits before processing the data, also when decrypting; and its limit on the
  associated data is now 2\ :sup:`64` - 1 bits (it was bytes).
* All the big integer arithmetic for RSA, DSA, ElGamal and ECC runs in a new
  C library (``Crypto.Math._nat``), in constant time: the time and the memory
  accesses do not depend on the values of the numbers, only on their (public)
  size. This includes modular exponentiation and inversion, GCD, Jacobi symbol,
  and the Miller-Rabin and Lucas tests used to generate primes.
  It replaces GMP, the previous C code for modular exponentiation
  (``IntegerCustom``) and Python integers, which leak timing information;
  Python integers remain only as a fallback, if the C extensions are not available.
  The C extensions no longer depend on GMP at runtime.
  For now, RSA and DSA private key operations and key generation are slower
  than with GMP. On x86-64 CPUs with BMI2 and ADX (gcc and clang only),
  a build that uses those instructions is about 15-25% faster.
* The NIST curves (P-192, P-224, P-256, P-384 and P-521) run on the same
  constant-time library (new module ``Crypto.PublicKey._ec_nat``). Every scalar
  multiplication processes the full (blinded) scalar length, scans its tables in full
  and randomizes the coordinates, and its result is checked to be on the curve.
  This fixes timing leaks of the previous code, including one on the length
  of ECDSA nonces. It is also faster: the multiplication of the generator
  (signing, key generation) is up to 10x faster for P-192 and P-224, which now
  have precomputed tables too, and ECDH is about 1.5x-2x faster on P-192,
  P-224, P-256 and P-384. Multiplying the generator by a scalar of any length
  no longer fails.
* Ed448 and X448 (Curve448) run on the same library and module, with the same
  countermeasures: for Ed448, a blinded scalar (by a multiple of the order of
  the whole group, so that it also works for points with a small-order component),
  signed windows with full table scans, randomized coordinates and a check of the
  result; for X448, the Montgomery ladder with randomized coordinates.
  Ed448 key generation and signing are about 10x faster (precomputed tables),
  verification about 2.5x, and X448 about 1.3x.
* Ed25519 scalar multiplications are blinded (by a random 32-bit multiple of
  the order of the whole group) and randomize the coordinates. Signing is about
  10% slower.
* Faster signature verification. ECDSA and EdDSA verification no longer applies the
  side-channel countermeasures, which are useless for its public values:
  about 22-28% faster for P-256, P-384, P-521 and Ed448 (for the NIST curves,
  it also uses faster, not constant-time, formulas). Ed25519 and Ed448 points are
  decoded in C (RFC 8032), and copying a point no longer goes through its affine
  coordinates: EdDSA verification is about 2x faster for Ed25519 and 1.8x for Ed448,
  importing an Ed25519 public key 7x-11x faster (Ed448 2.5x-3x), and ECDSA
  verification on P-256 1.4x faster.
* The field arithmetic of the elliptic curves has unrolled code for each curve size:
  scalar multiplications are 1.4x-1.7x faster for P-192, P-224 and P-256, and
  1.1x-1.5x for the larger curves (more with clang than with gcc).
* New function ``Crypto.Hash.KangarooTwelve.digest()``, to hash a whole message
  with a single call. For messages up to 8 KiB, it is 1.3x to 3x faster than
  ``new()`` followed by ``read()``.
* Faster hashes on x86 CPUs. With AVX2 and BMI2 (x86-64, gcc and clang only),
  the Keccak-based hashes use a build that takes advantage of those instructions:
  SHA-3, SHAKE, cSHAKE, KMAC, TupleHash and TurboSHAKE are about 1.25x-1.4x faster
  on long messages, and KangarooTwelve hashes 4 leaves in parallel
  (2x to 2.3x faster for messages of 1 MiB or more). With the SHA extensions \ 
(SHA-NI),
  SHA-224 and SHA-256 hash long messages about 4x faster.
* New parameter ``threads``, to run on several CPU cores (``threads=0`` for all \ 
of them);
  the output does not depend on the number of threads. It is accepted by the CTR mode
  (all block ciphers), the GCM and OCB modes and ChaCha20 (also XChaCha20),
  to encrypt and decrypt long data;
  by ``Crypto.Protocol.KDF.scrypt()``, to compute the ``p`` independent flows
  (each thread uses its own ``128 * r * N`` bytes of memory at the same time);
  and by ``Crypto.IO.PKCS8.wrap()`` and ``unwrap()``, ``import_key()`` of RSA, \ 
DSA and
  ECC keys and ``export_key()`` of RSA and ECC keys, for a private key protected with
  scrypt (PBES2) and a parallelization parameter larger than 1.
* GCM mode is about 1.5x faster on long messages, as it does not copy the data
  before authenticating it. The portable GHASH (for CPUs without PCLMULQDQ) no longer
  uses key-dependent tables: it is now constant-time, with the technique described
  by Thomas Pornin for BearSSL, and about 2.8x faster on 64-bit and 3.2x on \ 
32-bit systems.
* On CPython, the ``encrypt()`` and ``decrypt()`` methods of most ciphers
  (block cipher modes ECB, CBC, CFB, OFB, CTR, GCM and OCB, plus ChaCha20, Salsa20
  and ARC4) write their result directly into the returned ``bytes`` object,
  without copying it (for 64 KiB or more). For long data, this is 1.3x to 1.8x \ 
faster,
  and up to 3x with threads. The same applies to the ``read()`` method of SHAKE128,
  SHAKE256, cSHAKE, TurboSHAKE and KangarooTwelve, to
  ``Crypto.Hash.KangarooTwelve.digest()``, and to ``Crypto.Util.strxor.strxor()``
  and ``strxor_c()`` (up to 3.6x faster).
* The Salsa20 and ChaCha20 (also XChaCha20) stream ciphers are faster on long \ 
messages:
  about 4.8x and 4.7x on x86-64 CPUs with AVX2 and BMI2 (gcc and clang only;
  8 blocks of key stream at a time), 2.6x and 2.3x with SSE2 (4 blocks at a time),
  and 1.3x and 1.1x otherwise. ChaCha20-Poly1305 is about 2x faster.
* New parameter ``prot_params`` for ``DsaKey.export_key()``, as for RSA and ECC keys.
* GH#911: New method ``export()`` for HPKE contexts, to derive secrets
  (RFC 9180, Section 5.3). With the new ``HPKE.AEAD.EXPORT_ONLY``,
  a context can only export secrets. Thanks to sebastian.
* GH#906: New module ``Crypto.Cipher.oaep`` for RSA-OAEP encryption.
  It replaces ``Crypto.Cipher.PKCS1_OAEP``. The hash function (``hashmod``)
  must always be specified, and all parameters after the key are keyword-only.
* Faster key derivation functions. ``Crypto.Protocol.KDF.PBKDF2()`` is about \ 
1.25x-1.35x
  faster with HMAC based on SHA-1, SHA-224, SHA-256, SHA-384 and SHA-512 (about \ 
3.5x with
  HMAC-SHA256 on CPUs with SHA-NI), and about 25x-35x faster with HMAC based on \ 
SHA-3,
  as it now runs its inner loop in C. ``PBKDF1()`` with MD5 and SHA-1 (also used \ 
to import
  keys protected with the legacy PBES1 algorithms) runs its inner loop in C too:
  it is about 15x faster. ``scrypt()`` is about 1.15x-1.3x faster for ``p=1``,
  and up to 1.7x faster for small ``N`` and large ``p``; on Linux, its memory is
  backed by transparent huge pages where available. Encrypted OpenSSH private keys
  are imported about 1.9x faster: the two bcrypt hashes of each round of
  bcrypt_pbkdf run interleaved, in C.
* Limits when decrypting PKCS#8 private keys (see the new page "Limits when \ 
decrypting
  private keys" in the documentation). New parameter ``max_iteration_count`` for
  ``import_key()`` of RSA, DSA and ECC keys, like the one of \ 
``Crypto.IO.PKCS8.unwrap()``:
  the maximum iteration count accepted for an encrypted PKCS#8 key.
  When a key is above the limit, ``import_key()`` and ``PKCS8.unwrap()`` now raise
  ``Crypto.KdfIterationLimitError`` (a ``ValueError``), whose message
  says which value is too high and how to accept it, instead of a generic error
  about the key format. For scrypt, ``max_iteration_count`` now limits *N·r·p/8*
  (that is, *N* for the usual *r=8* and *p=1*), and not only *N*: before, a key with
  a large *r* or *p* could require any amount of time and memory. By default, the
  limit is 2\ :sup:`25`. Since scrypt also does some work in proportion to \ 
*r·p* only,
  *N* counts as at least 1024 in the cost. New parameter ``max_memory`` for
  ``PKCS8.unwrap()`` and for ``import_key()`` of RSA, DSA and ECC keys: the maximum
  memory for the scrypt key derivation, as a total for all threads together, not for
  each thread (and including the memory for the input and the output of all the \ 
flows).
  The default is 256 MiB. Fewer threads are used if needed; if even one thread
  does not fit, ``Crypto.KdfMemoryLimitError`` is raised.
  Both are subclasses of ``Crypto.KdfLimitError``; ``bcrypt_check()`` also raises
  ``Crypto.KdfIterationLimitError`` when the cost of the hash is above ``max_cost``.
* Set the environment variable ``PYCRYPTODOME_NO_SELFTEST`` when building
  from source to leave out the self-tests (``Crypto.SelfTest``), whose test keys
  and certificates may be reported by security scanners.
* DES and Triple DES are reimplemented from scratch, in constant time
  (no table lookups at secret addresses), and no longer use LibTomCrypt.
  They are about 3.5x slower than before.
* GH#908: New method ``seek()`` for Salsa20 cipher objects, to move to any
  position in the key stream (for instance, to start from a given block counter).
* Salsa20 raises ``OverflowError`` instead of silently reusing the key stream,
  when the data goes beyond its end (2\ :sup:`70` bytes per nonce).
   2026-10-27 12:52:53 by Thomas Klausner | Files touched by this commit (2)
Log message:
py-dns1: switch to py27-cryptodome, bump PKGREVISION