Documentation ¶
Overview ¶
Package sumhash implements the subset-sum hash function.
Index ¶
Constants ¶
const Sumhash512DigestBlockSize = 64
Sumhash512DigestBlockSize is the block size, in bytes, of the sumhash hash function
const Sumhash512DigestSize = 64
Sumhash512DigestSize The size in bytes of the sumhash checksum
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New(c Compressor, salt []byte) hash.Hash
New returns a new hash.Hash computing a sumhash checksum. If salt is nil, then hash.Hash computes a hash output in unsalted mode. Otherwise, salt should be BlockSize(c) bytes, and the hash is computed in salted mode. the context returned by this function reference the salt argument. any changes might affect the hash calculation
func New512 ¶
New512 creates a new sumhash512 context that computes a sumhash checksum. The output of the hash function is 64 bytes (512 bits). If salt is nil, then hash.Hash computes a hash output in unsalted mode. Otherwise, salt should be 64 bytes, and the hash is computed in salted mode. the context returned by this function reference the salt argument. any changes might affect the hash calculation
Types ¶
type Compressor ¶
type Compressor interface { Compress(dst []byte, input []byte) InputLen() int // len(input) OutputLen() int // len(dst) }
Compressor represents the compression function which is performed on a message
var SumhashCompressor Compressor
SumhashCompressor is a matrix derived from a seed which is used by the sumhash512 interface. In order the gain speed, this matrix can be used to compress input which have exactly size of InputLen()
type LookupTable ¶
type LookupTable [][][256]uint64
LookupTable is the precomputed sums from a matrix for every possible byte of input. Its dimensions are [n]m/8[256]uint64.
func (LookupTable) Compress ¶
func (A LookupTable) Compress(dst []byte, msg []byte)
Compress performs the compression algorithm on a message and output into dst
func (LookupTable) InputLen ¶
func (A LookupTable) InputLen() int
InputLen returns the valid length of a message in bytes
func (LookupTable) OutputLen ¶
func (A LookupTable) OutputLen() int
OutputLen returns the output len in bytes of the compression function
type Matrix ¶
type Matrix [][]uint64
Matrix is the n-by-m sumhash matrix A with elements in Z_q where q=2^64
func RandomMatrix ¶
RandomMatrix generates a random sumhash matrix by reading from rand. n is the number of rows in the matrix and m is the number of bits in the input message. m must be a multiple of 8.
func RandomMatrixFromSeed ¶
RandomMatrixFromSeed creates a random-looking matrix to be used for the sumhash function using the seed bytes. n and m are the rows and columns of the matrix respectively
func (Matrix) Compress ¶
Compress performs the compression algorithm on a message and output into dst
func (Matrix) LookupTable ¶
func (A Matrix) LookupTable() LookupTable
LookupTable generates a lookuptable used to increase hash calculation performance