Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

Python wrapper around poly1305_donna by floodberry

Project description


Fork of poly1305-donna by floodberry ( adding a Python wrapper as an extension module

What is a HMAC (Hash-based Message Authentication Code)?

From wikipedia (

In cryptography, a keyed-hash message authentication code (HMAC) is a specific construction for calculating a message authentication code (MAC) involving a cryptographic hash function in combination with a secret cryptographic key. As with any MAC, it may be used to simultaneously verify both the data integrity and the authentication of a message. Any cryptographic hash function, such as MD5 or SHA-1, may be used in the calculation of an HMAC; the resulting MAC algorithm is termed HMAC-MD5 or HMAC-SHA1 accordingly. The cryptographic strength of the HMAC depends upon the cryptographic strength of the underlying hash function, the size of its hash output, and on the size and quality of the key.

What is poly1305?


Poly1305-AES is a state-of-the-art secret-key message-authentication code suitable for a wide variety of applications. Poly1305-AES computes a 16-byte authenticator of a message of any length, using a 16-byte nonce (unique message number) and a 32-byte secret key. Attackers can’t modify or forge messages if the message sender transmits an authenticator along with each message and the message receiver checks each authenticator.


Following floodberry’s code license, this code is also released into the public domain. See LICENSE file.

The ‘floodberry.poly1305_donna’ directory contains the unmodified source code forked from poly1305-donna from


from poly1305_donna import (
    self_test, get_key, authenticate, verify,
print('Power-On Self Test result: ' + str(self_test()))
msg = 'Hello world'
print('\nTest class methods - authenticate, verify')
kr = get_key()
auth = authenticate(kr, msg)

bad_kr = get_key()
bad_msg = msg + '1'
bad_auth = authenticate(kr, bad_msg)

print('Good: %s\nBad auth: %s\nBad kr: %s\nBad msg: %s' % (
    str(verify(auth, kr, msg)),
    str(verify(bad_auth, kr, msg)),
    str(verify(auth, bad_kr, msg)),
    str(verify(auth, kr, bad_msg))

Alternately, run the test script that is shipped:

python -m poly1305_donna.test

To run a simple benchmark:

python -m poly1305_donna.benchmark


Using pip:

pip install 'git+'


python install



  • Python Tested on 2.7.6, 3.4.3, pypy 2.7.10 (pypy 4.0.1)
  • cffi >= 1.0.0
  • six
  • Python.h (libpython-dev on Debian-like systems)
  • gcc (build-essential on Debian-like systems)


py_poly1305_donna does not offer an API for incremental update and HMAC calculation.

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 poly1305_donna, version 0.11.15
Filename, size File type Python version Upload date Hashes
Filename, size poly1305_donna-0.11.15.tar.gz (16.3 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page