util

package
v0.0.0-...-df1f2e6 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2018 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

*Utility functions needed by calcpass.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByteSequence

func ByteSequence(start byte, count int) []byte

*Create an array of increasing byte values.

func Erase

func Erase(sensitive []byte)

*Fill given slice with zeros.

func HmacSha256

func HmacSha256(key, message []byte) []byte

func SecureShuffleBytes

func SecureShuffleBytes(array []byte, rng ByteSource) error

func UnbiasedSmallInt

func UnbiasedSmallInt(source ByteSource, n int) (int, error)

*Create a random integer from [0, n) where n is <= 256. This function returns uniformly distributed numbers (no modulo bias).

I am not using math/rand because Intn() consumes bits too quickly (64 at a time).

Returns error if the random source is exhausted or n exceeds 256.

Types

type BitReader

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

func NewBitReader

func NewBitReader(source io.Reader) *BitReader

func (*BitReader) ReadBits

func (br *BitReader) ReadBits(nBits int) (uint32, error)

Read up to 32bits from the source. When the source Reader returns io.EOF this function adds in zeros until the requested number of bits is achieved and then returns io.EOF. Other errors from the source reader return 0.

type ByteSource

type ByteSource interface {
	NextByte() (byte, error)
}

*Request a single byte at a time from some abstract source.

type ByteSourceReader

type ByteSourceReader struct {
	Source ByteSource
}

Convert a ByteSource to a Reader

func (*ByteSourceReader) Read

func (self *ByteSourceReader) Read(dest []byte) (int, error)

type FixedByteSource

type FixedByteSource struct {
	//The bytes
	Bytes []byte

	//Index of the next byte which will be returned
	Index int
}

*Implement ByteSource using a fixed-length slice of bytes. It returns io.EOF once all bytes have been consumed.

func (*FixedByteSource) NextByte

func (self *FixedByteSource) NextByte() (byte, error)

type HmacCounterByteSource

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

A pseudo-random stream bytes obtained from HMAC-SHA256 with a secret key and an incrementing 32bit counter.

func NewHmacCounterByteSource

func NewHmacCounterByteSource(key []byte, maxCounter uint32) *HmacCounterByteSource

After maxCounter invokations of HMAC-SHA256 the NextByte() function will return io.EOF. Each invokation yields 32 bytes.

func (*HmacCounterByteSource) NextByte

func (self *HmacCounterByteSource) NextByte() (byte, error)

Jump to

Keyboard shortcuts

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