Skip to main content
PyPI Travis

About

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.

Installation

Method 1

pip install rfc7539

Method 2

git clone https://github.com/AntonKueltz/rfc7539.git
cd rfc7539
python setup.py install

Basic API

aead.encrypt_and_tag

Takes a key, nonce, plaintext and additional data and returns a ciphertext and MAC.

def encrypt_and_tag(
    key: bytes,
    nonce: bytes,
    plaintext: bytes,
    aad: bytes
) -> (bytes, bytes)

aead.verify_and_decrypt

Takes a key, nonce, ciphertext, MAC and additional data and returns a plaintext.

def verify_and_decrypt(
    key: bytes,
    nonce: bytes,
    ciphertext: bytes,
    mac: bytes,
    aad: bytes
) -> bytes

Example Usage

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.

Release files for rfc7539 2.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rfc7539 2.1.0
File Size Uploaded
rfc7539-2.1.0.tar.gz 23.7 kB Details

Release files / rfc7539-2.1.0.tar.gz

Download URL rfc7539-2.1.0.tar.gz
Size 23.7 kB
Tags Source
SHA-256 checksum
How to use checksums
49f40a6077480aef117d3f0197ee93363317b3fd2ff60314916c62f4b31dc085
BLAKE2b-256 checksum
How to use checksums
57cf3520943c17387aa901604ee6e04edc11d89dc46b8b04367fec67995a8c76
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10

Release history Release notifications | RSS feed

This release

2.1.0 This release

1 release file

2.0.1

5 release files

2.0.0

5 release files

1.2.1

3 release files

1.2.0

3 release files

1.1.0

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page