Questions about the usage of the PyCryptodome Python package in programming. PyCryptodome is a self-contained Python package of low-level cryptographic primitives. It is a fork of of the PyCrypto project and it is designed to replace it, since PyCrypto is not being maintained anymore. The package contains a wide collection of secure hash functions and various encryption algorithms, and it also provides support for random generation.
About PyCryptodome
PyCryptodome is a self-contained Python package of low-level cryptographic primitives, created as a fork of PyCrypto.
PyCryptodome exposes almost the same API as the old PyCrypto so that most applications will run unmodified. See this page from the official website for more details.
It supports Python 2.6 or newer, all Python 3 versions and PyPy.
Official resources
- PyCryptodome homepage
- PyCryptodome official documentation
- PyCryptodome PyPi page
- PyCryptodome GitHub repository
Installation
From the PyCryptodome repository:
The installation procedure depends on the package you want the library to be in.
PyCryptodome can be used as:
an almost drop-in replacement for the old PyCrypto library.
You install it with:pip install pycryptodome
In this case, all modules are installed under the
Crypto
package. One must avoid having both PyCrypto and PyCryptodome installed at the same time, as they will interfere with each other.This option is therefore recommended only when you are sure that
the whole application is deployed in avirtualenv
.a library independent of the old PyCrypto. You install it with::
pip install pycryptodomex
In this case, all modules are installed under the
Cryptodome
package. PyCrypto and PyCryptodome can coexist.For faster public key operations in Unix, you should install
GMP
in your system.
Differences from PyCrypto
From the PyCryptodome repository:
It brings the following enhancements with respect to the last official version of PyCrypto (2.6.1):
- Authenticated encryption modes (GCM, CCM, EAX, SIV, OCB)
- Accelerated AES on Intel platforms via AES-NI
- First class support for PyPy
- Elliptic curves cryptography (NIST P-256 curve only)
- Better and more compact API (
nonce
andiv
attributes for ciphers, automatic generation of random nonces and IVs, simplified CTR cipher mode, and more)- SHA-3 (including SHAKE XOFs), SHA-512/t and BLAKE2 hash algorithms
- Salsa20 and ChaCha20 stream ciphers
- scrypt and HKDF
- Deterministic (EC)DSA
- Password-protected PKCS#8 key containers
- Shamir's Secret Sharing scheme
- Random numbers get sourced directly from the OS (and not from a CSPRNG in userspace)
- Simplified install process, including better support for Windows
- Cleaner RSA and DSA key generation (largely based on FIPS 186-4)
- Major clean ups and simplification of the code base
PyCryptodome is not a wrapper to a separate C library like OpenSSL. To the largest possible extent, algorithms are implemented in pure Python. Only the pieces that are extremely critical to performance (e.g. block ciphers) are implemented as C extensions.