Giter Club home page Giter Club logo

py-chacha20poly1305's Introduction

Chacha20poly1305

Simple pure-python chacha20-poly1305 implementation based on tlslite-ng code. Designed to be compatible with Cryptography API.

import os
from chacha20poly1305 import ChaCha20Poly1305

key = os.urandom(32)
cip = ChaCha20Poly1305(key)

nonce = os.urandom(12)
ciphertext = cip.encrypt(nonce, b'test')

plaintext = cip.decrypt(nonce, ciphertext)
print(plaintext)

Pip

pip install chacha20poly1305

Note

Please note the pure python implementation probably suffers form side-channels leakage (timing, memory access). For constant time implementations use compiled versions:

py-chacha20poly1305's People

Contributors

ph4r05 avatar rage-proof avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

py-chacha20poly1305's Issues

Why isn't the ciphertext at least as long as the ~key~ plaintext?

Given that ChaCha20 is a stream cipher that operates on each bit, I've read the ciphertext should be at least as long as the key (comparable to properties of the one-time-pad). However, using the 'test' bytearray python string in the example in this repositories Read me file, the resulting ciphertext is not as long as the key. I am wondering why is this and whether this is an error?

example code and output:

import os
from chacha20poly1305 import ChaCha20Poly1305

key = os.urandom(32)
cip = ChaCha20Poly1305(key)

nonce = os.urandom(12)
ciphertext = cip.encrypt(nonce, b'test')

plaintext = cip.decrypt(nonce, ciphertext)
print('plaintex:',plaintext)
print('ciphertext:',ciphertext)
print('nonce:',nonce)
print('secret key:',key)

Example output:

plain bytearray(b'test')
cip bytearray(b'G|W\xbbX\x15#\x94\x12\xff\xd6U\x8d\xb5T-m\xd0p$')
non b'\xce\xf6\xdb\xf2\xc47\xcc&\xc3b\xc9\x83'
key b'\x06\xb0\xbar\x89\xc3\xd7\xe66\x86h\xf0B\x81B\xbf\xbe\x11\xd3\x9e\xda\x9b\xf4\x90\xd0\xb2\x87\xc9S\x10\x1eM'
>>> 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.