An AEAD construction per RFC7539
Project description
RFC7539
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
Clone the repo and run either $ pip install -e .
or $ python setup.py install
.
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 = 'thisisanonce' # nonce is 12 bytes (DO NOT REUSE A NONCE WITH THE SAME KEY)
message = 'Some message to be encrypted'
additional_data = '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)
Notes on Python 2 vs 3
In python2 encryption and decryption and tagging will return str
data while in python3 they will return
bytes
data. This is consistent with how much of the python library operates between the two versions (e.g.
see binascii.unhexlify
). This can lead to some strange behavior if e.g. you encrypt a str
value in
python3 and, after decrypting, your decrypted value does not match your original value because you got bytes
back from the decryption. If the returned type is undesirable it is of course always possible to convert between
bytes
and str
as needed.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for rfc7539-1.1.0-cp37-cp37m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d0b1d8fc62208c7408599c1b69fd9a7de9b7e97770bdf599546426a5b7a065c |
|
MD5 | d7ebc35bec30ceef5826079d0ba80003 |
|
BLAKE2b-256 | 8481b77bb2170afac8a6b384a4623ee092e985cb144f984ebed958232b134437 |
Hashes for rfc7539-1.1.0-cp27-cp27m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66228f16cac6c47305791bee0eeee1a84ba32a7b812bcd28f675d99fb2c1f030 |
|
MD5 | 6771bb6024a80fef4c915a64816ac351 |
|
BLAKE2b-256 | aa1144eb7143285481f73afc80d6ff1b224d4984186751855d22c1d451828319 |