Giter Site home page Giter Site logo

hxsiphash's Introduction

Siphash-2-4 for Haxe

See the SipHash home page for info.

Usage

Stream interface

You need to create a state object of class siphash.SipHash:

var sh = new siphash.SipHash();

Then you need to specify a key. This operation also resets the internal state, so you can use it to start a new authentication without creating new state:

sh.reset(key);

Next you feed it buffers of data you want authenticated. Note, that each next block of data adds to stream, not replaces it. If you feed it blocks that aren't multiples of 8 bytes, remainder of data will be stored inside and used with the begining of next block:

sh.update(buffer, 10 /* offset */, len - 10 /* length */);
sh.update(buffer, 10); // same as above
sh.update(buffer); // use th whole buffer

Finally you make the authentication tag:

var tag : haxe.Int64 = sh.complete();

Fast interface

Or if you just need to hash one buffer:

var sh = new siphash.SipHash(); // do this once

var result = sh.reset(key).fast(buffer, 10, 25); // do this for every buffer

This interface is slightly faster as it doesn't save intermediate state while reading the buffer.

Class reference

class siphash.SipHash

public function reset(k : haxe.io.Int32Array, mode128 : Bool = false)

Resets internal state and initializes it with provided key. Allows more than one plaintext to be processed with a single SipHash object.

public function update(k : haxe.io.Bytes, pos : Int = 0, ?len : Int)

Updates internal state with provided buffer. If len is unspecified, uses k.length - pos bytes from buffer.

public function complete() : Int64

Completes the final transform and outputs authentication tag.

public function fast(buf : haxe.io.Bytes, pos : Int = 0, ? len : Int) : Int64

Does update and complete in one call. Faster, but supports only one buffer.

hxsiphash's People

Contributors

ntrf avatar

Stargazers

 avatar  avatar

Watchers

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