Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

AEAD cipher based on ChaCha20 stream cipher and Poly1305 MAC

License

NotificationsYou must be signed in to change notification settings

AntonKueltz/rfc7539

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyPITravis

About

RFC7539 is an IETF specification for an authenticated encryption algorithm that will beincorporated into TLSv1.3. It is comprised of a stream cipher (ChaCha20) and a MAC (Poly1305), bothwritten by Daniel J. Bernstein. The C implementations for both of these primitives are taken fromthe NSS library (the reason being that openSSL has license incompatibilities and also requires theopenSSL 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 counterspecified in the RFC.

Installation

Method 1

pip install rfc7539

Method 2

git clone https://github.com/AntonKueltz/rfc7539.gitcd rfc7539python setup.py install

Basic API

aead.encrypt_and_tag

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

defencrypt_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.

defverify_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 primitivesby itself:

fromrfc7539importaeadfromosimporturandomkey=urandom(32)# key is 32 bytesnonce=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# encryptionciphertext,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 stringsbefore passing them as arguments.


[8]ページ先頭

©2009-2025 Movatter.jp