skein

package module
v0.0.0-...-d7f1022 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2017 License: BSD-2-Clause Imports: 4 Imported by: 1

README

Go implementation of Skein-512 hash function, MAC, and stream cipher.

Usage:
	
	$ go get github.com/dchest/skein

Import:

	import "github.com/dchest/skein"

Docs:

	http://go.pkgdoc.org/github.com/dchest/skein

Documentation

Overview

Package skein implements the Skein-512 hash function, MAC, and stream cipher as defined in "The Skein Hash Function Family, v1.3".

Index

Constants

View Source
const BlockSize = 64

BlockSize is the block size of Skein-512 in bytes.

Variables

This section is empty.

Functions

func NewHash

func NewHash(outLen uint64) hash.Hash

NewHash returns hash.Hash calculating checksum of the given length in bytes (for example, to calculate 256-bit hash, outLen must be set to 32).

func NewMAC

func NewMAC(outLen uint64, key []byte) hash.Hash

NewMAC returns hash.Hash calculating Skein Message Authentication Code of the given length in bytes. A MAC is a cryptographic hash that uses a key to authenticate a message. The receiver verifies the hash by recomputing it using the same key.

func NewStream

func NewStream(key []byte, nonce []byte) cipher.Stream

NewStream returns a cipher.Stream for encrypting a message with the given key and nonce. The same key-nonce combination must not be used to encrypt more than one message. There are no limits on the length of key or nonce.

Types

type Args

type Args struct {
	// Key is a secret key for MAC, KDF, or stream cipher
	Key []byte
	// Person is a personalization string
	Person []byte
	// PublicKey is a public key for signature hashing
	PublicKey []byte
	// KeyId is a key identifier for KDF
	KeyId []byte
	// Nonce for stream cipher or randomized hashing
	Nonce []byte
	// NoMsg indicates whether message input is used by the function.
	//
	// If false (default), message input it used, and thus if zero-length
	// message is supplied to Write or if Write was not called, it will be
	// assumed that the message input is zero-length, and thus will be
	// processed as such (padded with zeroes). This is the normal way Skein
	// hash and MAC are used.
	//
	// If true, message input is not used, so any call to Write will
	// return an error. This is useful for constructions such as a
	// that skip message input, such as a stream cipher.
	//
	// The name is negative to preserve backward compatibility.
	NoMsg bool
}

Args can be used to configure hash function for different purposes. All fields are optional: if a field is nil, it will not be used.

type Hash

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

Hash represents a state of Skein hash function. It implements hash.Hash interface.

func New

func New(outLen uint64, args *Args) *Hash

New returns a new skein.Hash configured with the given arguments. The final output length of hash function in bytes is outLen (for example, 64 when calculating 512-bit hash). Configuration arguments may be nil.

func (*Hash) BlockSize

func (h *Hash) BlockSize() int

BlockSize returns the hash's underlying block size.

func (*Hash) OutputReader

func (h *Hash) OutputReader() io.Reader

OutputReader returns an io.Reader that can be used to read arbitrary-length output of the hash. Reading from it doesn't change the underlying hash state.

func (*Hash) Reset

func (h *Hash) Reset()

Reset resets hash to its state after initialization. If hash was initialized with arguments, such as key, these arguments are preserved.

func (*Hash) Size

func (h *Hash) Size() int

Size returns the number of bytes Sum will return. If the hash was created with output size greater than the maximum size of int, the result is undefined.

func (*Hash) Sum

func (h0 *Hash) Sum(in []byte) []byte

Sum appends the current hash to in and returns the resulting slice. It does not change the underlying hash state.

func (*Hash) Write

func (h *Hash) Write(b []byte) (n int, err 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