crypto

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2020 License: MIT Imports: 16 Imported by: 0

README

Testing Notes

  • We must get close to 100% coverage and stay there for all functions in this important package

Documentation

Overview

Package crypto provides funcs and types used by other packages to perform crypto related ops

Index

Constants

This section is empty.

Variables

View Source
var DefaultCypherParams = KDParams{N: 262144, R: 8, P: 1, SaltLen: 16, DKLen: 32}

DefaultCypherParams used for key derivation by the app.

Functions

func AddPKCSPadding

func AddPKCSPadding(src []byte) []byte

AddPKCSPadding Adds padding to a block of data.

func AesCTRXOR

func AesCTRXOR(key, input, nonce []byte) ([]byte, error)

AesCTRXOR is an AES cipher following https://leanpub.com/gocrypto/read#leanpub-auto-aes-cbc .

func DeriveKeyFromPassword

func DeriveKeyFromPassword(password string, p KDParams) ([]byte, error)

DeriveKeyFromPassword derives a key from password using the provided KDParams params.

func GenerateKeyPair

func GenerateKeyPair() (PrivateKey, PublicKey, error)

GenerateKeyPair generates a private and public key pair.

func GenerateVRFKeys

func GenerateVRFKeys() (publicKey, privateKey []byte, err error)

func GetRandomBytes

func GetRandomBytes(n int) ([]byte, error)

GetRandomBytes returns n random bytes. It returns an error if the system's pgn fails.

func GetRandomBytesToBuffer

func GetRandomBytesToBuffer(n int, buff []byte) error

GetRandomBytesToBuffer puts n random bytes using go crypto.rand into provided buff slice. buff: a slice allocated by called to hold n bytes.

func GetRandomUInt32

func GetRandomUInt32(max uint32) uint32

GetRandomUInt32 returns a uint32 in the range [0 - max).

func Keccak256

func Keccak256(data ...[]byte) []byte

Keccak256 calculates and returns the Keccak256 hash of the input data.

func Keccak256Hash

func Keccak256Hash(data ...[]byte) (h types.Hash32)

Keccak256Hash calculates and returns the Keccak256 hash of the input data, converting it to an internal Hash data structure.

func MinInt

func MinInt(x, y int) int

MinInt returns x if x < y and y otherwise.

func MinInt32

func MinInt32(x, y int32) int32

MinInt32 returns x if x < y and y otherwise.

func MinInt64

func MinInt64(x, y int64) int64

MinInt64 returns x if x < y and y otherwise.

func NewUUID

func NewUUID() [16]byte

NewUUID returns a new random type-4 UUID raw bytes.

func Pkcs7Pad

func Pkcs7Pad(in []byte) []byte

Pkcs7Pad returns input with padding using the pkcs7 padding spec.

func Pkcs7Unpad

func Pkcs7Unpad(in []byte) []byte

Pkcs7Unpad returned in without padded data using pkcs7 padding spec.

func RemovePKCSPadding

func RemovePKCSPadding(src []byte) ([]byte, error)

RemovePKCSPadding Removes padding from data that was added using AddPKCSPadding.

func Sha256

func Sha256(data ...[]byte) []byte

Sha256 is a SHA-3-256 (not sha-256) hasher. It returns a 32 bytes (256 bits) hash of data. data: arbitrary length bytes slice

func UUIDString

func UUIDString() string

UUIDString returns a new random type-4 UUID string.

func ValidateVRF

func ValidateVRF(message, signature, publicKey []byte) error

Types

type KDParams

type KDParams struct {
	N       int    `json:"n"`
	R       int    `json:"r"`
	P       int    `json:"p"`
	SaltLen int    `json:"saltLen"`
	DKLen   int    `json:"dkLen"`
	Salt    string `json:"salt"` // hex encoded
}

KDParams defines key derivation scheme params.

type Key

type Key interface {
	String() string // this is a base58 encoded of Bytes()
	Bytes() []byte  // raw key binary data
	Pretty() string // pretty print key id
}

Key defines basic key caps.

type PrivateKey

type PrivateKey interface {
	Key

	GetPublicKey() PublicKey // get the pub key corresponding to this priv key
	Sign([]byte) ([]byte, error)

	// Decrypt binary data encrypted with the public key of this private key
	Decrypt(in []byte) ([]byte, error)

	InternalKey() *btcec.PrivateKey
}

PrivateKey defines a private encryption key.

func NewPrivateKey

func NewPrivateKey(data []byte) (PrivateKey, error)

NewPrivateKey creates a new private key from data

func NewPrivateKeyFromString

func NewPrivateKeyFromString(s string) (PrivateKey, error)

NewPrivateKeyFromString creates a new private key a base58 encoded string.

type PublicKey

type PublicKey interface {
	Key
	Verify(data []byte, sig []byte) (bool, error)
	VerifyString(data []byte, sig string) (bool, error)

	// encrypt data so it is only decryptable w the private key of this key
	Encrypt(in []byte) ([]byte, error)

	InternalKey() *btcec.PublicKey
}

PublicKey defines a public encryption key.

func NewPublicKey

func NewPublicKey(data []byte) (PublicKey, error)

NewPublicKey creates a new public key from provided binary key data.

func NewPublicKeyFromString

func NewPublicKeyFromString(s string) (PublicKey, error)

NewPublicKeyFromString creates a new public key from a base58 encoded string data.

type UUID

type UUID [16]byte

UUID is a 16-len byte array represnting a UUID

type VRFSigner

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

func NewVRFSigner

func NewVRFSigner(privateKey []byte) *VRFSigner

func (*VRFSigner) Sign

func (s *VRFSigner) Sign(message []byte) []byte

Directories

Path Synopsis
Package sha3 implements the SHA-3 fixed-output-length hash functions and the SHAKE variable-output-length hash functions defined by FIPS-202.
Package sha3 implements the SHA-3 fixed-output-length hash functions and the SHAKE variable-output-length hash functions defined by FIPS-202.

Jump to

Keyboard shortcuts

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