siphash

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2018 License: MIT Imports: 3 Imported by: 221 modules, 206 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Godoc Reference Build Status

The SipHash pseudo-random function

SipHash is a family of pseudo-random functions (a.k.a. keyed hash functions) optimized for speed on short messages.
SipHash computes a 64-bit or 128 bit message authentication code from a variable-length message and 128-bit secret key. This implementation uses the recommended parameters c=2 and d=4.

Installation

Install in your GOPATH: go get -u github.com/aead/siphash

Performance

AMD64
Hardware: Intel i7-6500U 2.50GHz x 2
System: Linux Ubuntu 16.04 - kernel: 4.4.0-67-generic
Go version: 1.8.0

name         speed           cpb
Write_8-4     688MB/s ± 0%   3.47
Write_1K-4   2.09GB/s ± 5%   1.11
Sum64_8-4     244MB/s ± 1%   9.77
Sum64_1K-4   2.06GB/s ± 0%   1.13
Sum128_8-4    189MB/s ± 0%  12.62
Sum128_1K-4  2.03GB/s ± 0%   1.15

386
Hardware: Intel i7-6500U 2.50GHz x 2 - SSE2 SIMD
System: Linux Ubuntu 16.04 - kernel: 4.4.0-67-generic
Go version: 1.8.0

name         speed           cpb
Write_8-4     434MB/s ± 2%   5.44
Write_1K-4   1.24GB/s ± 1%   1.88
Sum64_8-4    92.6MB/s ± 4%  25.92
Sum64_1K-4   1.15GB/s ± 1%   2.03
Sum128_8-4   61.5MB/s ± 5%  39.09
Sum128_1K-4  1.10GB/s ± 0%   2.12

ARM
Hardware: ARM-Cortex-A7 (ARMv7) 1GHz (912MHz) x 2
System: Linux Ubuntu 14.04.1 - kernel: 3.4.112-sun7i
Go version: 1.7.4

name         speed           cpb
Write_8-2    43.4MB/s ± 2%  21.97
Write_1K-2    125MB/s ± 1%   7.63
Sum64_8-2    6.51MB/s ± 1% 146.49
Sum64_1K-2    111MB/s ± 1%   8.59 
Sum128_8-2   3.82MB/s ± 2% 249.65
Sum128_1K-2   101MB/s ± 1%   9.44

Documentation

Overview

Package siphash implements the SipHash-64 and SipHash-128 pseudo-random-functions - with the recommended parameters: c = 2 and d = 4. SipHash computes a message authentication code (MAC) from a variable-length message and a 128 bit secret key. SipHash was designed to be efficient, even for short inputs, with performance comparable to non-cryptographic hash functions.

Security

SipHash cannot be used as a cryptographic hash function. Neither SipHash-64 nor SipHash-128 are strong collision resistant.

Recommendations

SipHash was designed to defend hash flooding DoS attacks. SipHash-64 can be used as hashing scheme within hash maps or other key-value data structures. SipHash-128 can be used to compute a 128 bit authentication tag for messages.

Index

Constants

View Source
const (
	// KeySize is the size of the SipHash secret key in bytes.
	KeySize = 16
	// BlockSize is the block size of SipHash in bytes.
	BlockSize = 8
)

Variables

This section is empty.

Functions

func New64

func New64(key []byte) (hash.Hash64, error)

New64 returns a hash.Hash64 computing the SipHash-64 checksum. This function returns a non-nil error if len(key) != 16.

func New128

func New128(key []byte) (hash.Hash, error)

New128 returns a hash.Hash computing the SipHash-128 checksum. This function returns a non-nil error if len(key) != 16.

func Sum64

func Sum64(msg []byte, key *[KeySize]byte) uint64

Sum64 returns the 64 bit authenticator for msg using a 128 bit secret key.

func Sum128

func Sum128(msg []byte, key *[KeySize]byte) [16]byte

Sum128 returns the 128 bit authenticator for msg using a 128 bit secret key.

Types

type KeySizeError

type KeySizeError uint

func (KeySizeError) Error

func (k KeySizeError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址