Installation¶
You install PyCryptodome with:
pip install pycryptodome
All modules are installed under the Crypto package.
You can test everything is right with:
pip install pytest pycryptodome-test-vectors
python -m Crypto.SelfTest
This runs the complete test suite, which takes a few minutes.
Add --skip-slow-tests for a quicker check that skips the most
time-consuming test vectors.
One must avoid having both PyCrypto and PyCryptodome installed
at the same time, as they will interfere with each other.
This is not a problem if your application is deployed in a virtualenv.
Note
Starting with version 4.0, the pycryptodomex project
(Cryptodome package) is no longer released.
The procedures below go a bit more in detail, by explaining how to setup the environment for compiling the C extensions for each OS.
Compiling in Linux Ubuntu¶
For Python 3.x:
$ sudo apt-get install build-essential python3-dev
$ pip install pycryptodome
$ pip install pytest pycryptodome-test-vectors
$ python3 -m Crypto.SelfTest
For PyPy:
$ sudo apt-get install build-essential pypy-dev
$ pip install pycryptodome
$ pip install pytest pycryptodome-test-vectors
$ pypy -m Crypto.SelfTest
Compiling in Linux Fedora¶
For Python 3.x:
$ sudo yum install gcc python3-devel
$ pip install pycryptodome
$ pip install pytest pycryptodome-test-vectors
$ python3 -m Crypto.SelfTest
For PyPy:
$ sudo yum install gcc pypy-devel
$ pip install pycryptodome
$ pip install pytest pycryptodome-test-vectors
$ pypy -m Crypto.SelfTest
Windows (from sources)¶
Windows does not come with a C compiler like most Unix systems. The simplest way to compile the PyCryptodome extensions from source code is to install the minimum set of Visual Studio components freely made available by Microsoft.
[Once only] Download Build Tools for Visual Studio 2019. In the installer, select the C++ build tools, the Windows 10 SDK, and the latest version of MSVC v142 x64/x86 build tools.
Compile and install PyCryptodome:
> pip install pycryptodome --no-binary :all:
To make sure everything work fine, run the test suite:
> pip install pytest pycryptodome-test-vectors > python -m Crypto.SelfTest
Installing without the self-tests¶
The package includes its self-tests (Crypto.SelfTest).
To build it without them, set the environment variable
PYCRYPTODOME_NO_SELFTEST when compiling from source:
$ PYCRYPTODOME_NO_SELFTEST=1 pip install pycryptodome --no-binary pycryptodome
or, to build a wheel from a source checkout:
$ PYCRYPTODOME_NO_SELFTEST=1 python -m build
The rest of the library is unchanged,
but python -m Crypto.SelfTest is no longer available.
Note
If you build with pip install . or pip wheel . instead,
first remove any build/ directory left by previous builds:
setuptools copies all files in it into the wheel, including the old self-tests.
python -m build is not affected, as it builds the wheel from a fresh sdist.
Installing without the precomputed tables of the elliptic curves¶
To multiply the generator of a curve faster, the library uses precomputed tables: for Ed25519, 36 KB in the binary module; for Ed448 and the NIST curves, from 39 KB (P-192) to 266 KB (P-521) of memory for each curve in use, computed when the curve is first loaded.
To save that space, set the environment variable PYCRYPTODOME_NO_EC_TABLES
when compiling from source:
$ PYCRYPTODOME_NO_EC_TABLES=1 pip install pycryptodome --no-binary pycryptodome
or, to build a wheel from a source checkout:
$ PYCRYPTODOME_NO_EC_TABLES=1 python -m build
The generator is then multiplied like any other point, about 4x to 6x slower: this affects key generation and signing (ECDSA and EdDSA), and in part the verification of signatures. ECDH is not affected.
Note
The variable only changes the compiled code. If you build with
pip install . or pip wheel . instead, first remove any build/
directory left by previous builds, so that its object files are not reused.
Documentation¶
Project documentation is written in reStructuredText and it is stored under Doc/src.
To publish it as HTML files, you need to install sphinx and
use:
> make -C Doc/ html
It will then be available under Doc/_build/html/.
PGP verification¶
All source packages and wheels on PyPI are cryptographically signed. They can be verified with the following PGP key:
-----BEGIN PGP PUBLIC KEY BLOCK-----
mQINBFTXjPgBEADc3j7vnma9MXRshBPPXXenVpthQD6lrF/3XaBT2RptSf/viOD+
tz85du5XVp+r0SYYGeMNJCQ9NsztxblN/lnKgkfWRmSrB+V6QGS+e3bR5d9OIxzN
7haPxBnyRj//hCT/kKis6fa7N9wtwKBBjbaSX+9vpt7Rrt203sKfcChA4iR3EG89
TNQoc/kGGmwk/gyjfU38726v0NOhMKJp2154iQQVZ76hTDk6GkOYHTcPxdkAj4jS
Dd74M9sOtoOlyDLHOLcWNnlWGgZjtz0z0qSyFXRSuOfggTxrepWQgKWXXzgVB4Jo
0bhmXPAV8vkX5BoG6zGkYb47NGGvknax6jCvFYTCp1sOmVtf5UT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