Skip to main content

An AEAD construction per RFC7539

Project description

PyPI Travis


RFC7539 is an IETF specification for an authenticated encryption algorithm that will be incorporated into TLSv1.3. It is comprised of a stream cipher (ChaCha20) and a MAC (Poly1305), both written by Daniel J. Bernstein. The C implementations for both of these primitives are taken from the NSS library (the reason being that openSSL has license incompatibilities and also requires the openSSL headers which is more overhead than we need to implement these fairly basic primitives). The NSS code has been slightly modified to account for the 96 bit nonce and 32 bit counter specified in the RFC.


Method 1

pip install rfc7539

Method 2

git clone
cd rfc7539
python install


You should use the authenticated encryption mode unless you really need to use one of the primitives by itself:

from rfc7539 import aead
from os import urandom

key = urandom(32)  # key is 32 bytes
nonce = b'thisisanonce'  # nonce is 12 bytes (DO NOT REUSE A NONCE WITH THE SAME KEY)
message = b'Some message to be encrypted'
additional_data = b'Some additional data'  # this will not be encrypted but will be verified for integrity

# encryption
ciphertext, mac = aead.encrypt_and_tag(key, nonce, message, additional_data)

# decryption (which yields plaintext == message)
plaintext = aead.verify_and_decrypt(key, nonce, ciphertext, mac, additional_data)

Note that all operations in this package work on bytes. You’ll need to call e.g. encode() on strings before passing them as arguments.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for rfc7539, version 2.0.1
Filename, size File type Python version Upload date Hashes
Filename, size rfc7539-2.0.1-cp35-cp35m-macosx_10_14_x86_64.whl (26.5 kB) File type Wheel Python version cp35 Upload date Hashes View
Filename, size rfc7539-2.0.1-cp36-cp36m-macosx_10_14_x86_64.whl (26.5 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size rfc7539-2.0.1-cp37-cp37m-macosx_10_14_x86_64.whl (26.5 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size rfc7539-2.0.1-cp38-cp38-macosx_10_14_x86_64.whl (26.5 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size rfc7539-2.0.1.tar.gz (22.9 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page