streebog

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2020 License: MIT Imports: 4 Imported by: 0

README

Streebog hash function

PkgGoDev Go Report Card

Streebog is a russian standard cryptographic hash function described in GOST. There are 2 versions of the hash - 256 and 512 bit. This implementation is based on lookup table and thus well-optimized (see benchmarks).

Note

Hash function starts encoding from the end. Thus, it cannot have state and hash sum must be calculated entirely every time Sum() is called. Moreover, marshalling hasher, which only state is consumed data, is useless.

Its memory consumption is linear to provided data until Reset() is called. Usually reset is called after each message unit processing.

Tests

Most of the tests for the cipher are taken from GOST. The other tests check interface contracts for hash - hash.Hash.

Test coverage for initial version is 100%

Benchmarks

// 512 bit hash. Only Sum() function is heavy - it does most of work
BenchmarkSum512-4  14275  84178 ns/op  76.03 MB/s  64 B/op  1 allocs/op

// 256 bit hash
BenchmarkSum256-4  13179  83928 ns/op  76.26 MB/s  32 B/op  1 allocs/op

// Lookup table is initialized once with the first New... call
// BenchmarkInitLPSTable-4  102705  11036 ns/op  185.57 MB/s  0 B/op  0 allocs/op

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New256

func New256() hash.Hash

New256 creates 256bit output hash.

func New512

func New512() hash.Hash

New512 creates 512bit output hash.

Types

type Streebog

type Streebog struct {
	// contains filtered or unexported fields
}

Streebog is a russian standard hash function described in GOST.

func (*Streebog) BlockSize

func (s *Streebog) BlockSize() int

BlockSize returns the hash's underlying block size. There is no performance difference how much data to provide to Write.

func (*Streebog) Reset

func (s *Streebog) Reset()

Reset resets the Hash to its initial state.

func (*Streebog) Size

func (s *Streebog) Size() int

Size returns the number of bytes Sum will return.

func (*Streebog) Sum

func (s *Streebog) Sum(buf []byte) []byte

Sum appends the current hash to b and returns the resulting slice. It does not change the underlying hash state (i.e. sequential calls produce the same results).

func (*Streebog) Write

func (s *Streebog) Write(buf []byte) (int, error)

Write adds more data to the running hash. It never returns an error.

Jump to

Keyboard shortcuts

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