GithubHelp home page GithubHelp logo

dkruchinin / pysiphash Goto Github PK

View Code? Open in Web Editor NEW

This project forked from majek/pysiphash

1.0 1.0 0.0 7 KB

SipHash in Python

Home Page: https://github.com/majek/pysiphash

License: Other

Python 100.00%

pysiphash's Introduction

pysiphash

A Python implementation of SipHash-2-4, a fast short-input PRF with a 128-bit key and 64-bit output.

Extract from the description:

SipHash is a family of pseudorandom functions (a.k.a. keyed hash
functions) optimized for speed on short messages.

Target applications include network traffic authentication and defense
against hash-flooding DoS attacks.

SipHash is secure, fast, and simple (for real):
* SipHash is simpler and faster than previous cryptographic algorithms
  (e.g. MACs based on universal hashing)
* SipHash is competitive in performance with insecure
  non-cryptographic algorithms (e.g. MurmurHash)
* We propose that hash tables switch to SipHash as a hash
  function. Users of SipHash already include OpenDNS, Perl 5, Ruby, or
  Rust.

Pysiphash is tested on Python 2.7 and Python 3.2.

Introductory blog post: https://idea.popcount.org/2013-01-24-siphash/

installation

Released pysiphash versions are available on pypi. To install it use easy_install or pip:

$ pip install siphash

or

$ easy_install siphash

usage

Pysiphash tries to follow the hashlib API. You can add data to the hash by calling an update method, or feed data directly to the constructor:

>>> import siphash
>>> key = '0123456789ABCDEF'
>>> sip = siphash.SipHash_2_4(key)
>>> sip.update('a')
>>> sip.hash()
12398370950267227270L

>>> siphash.SipHash_2_4(key, 'a').hash()
12398370950267227270L

To extract the hash as a numeric value call hash():

>>> siphash.SipHash_2_4(key, 'a').hash()
12398370950267227270L

Or digest() to get a raw 8-bytes string:

>>> siphash.SipHash_2_4(key, 'a').digest()
'\x86L3\x9c\xb0\xdc\x0f\xac'

Or hexdigest() for a 16-bytes hex encoding:

>>> siphash.SipHash_2_4(key, 'a').hexdigest()
'864c339cb0dc0fac'

testing

A series of sanity checks are present inline the main pysiphash code, to run it type:

$ python siphash/__init__.py
all tests ok

speed

Currently pysiphash is a pure-python code, so don't expect blazing speed. On my machine computing a hash from a ten byte string takes around 0.31 ms, and hashing 1MiB blob takes 770 ms.

pysiphash's People

Contributors

majek avatar

Stargazers

 avatar

Watchers

 avatar

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.