crypto

package
v0.0.0-...-42befb5 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2018 License: MIT Imports: 14 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 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 GetRandomUserPort

func GetRandomUserPort() uint32

GetRandomUserPort returns a random port number in the range of [1024-49151).

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 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 UUID

func UUID() []byte

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

func UUIDString

func UUIDString() string

UUIDString returns a new random type-4 UUID string.

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.

Jump to

Keyboard shortcuts

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