cipher

package
v0.0.0-...-9802667 Latest Latest
Warning

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

Go to latest
Published: May 27, 2018 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// DebugLevel1 debug level one
	DebugLevel1 = true //checks for extremely unlikely conditions (10e-40)
	// DebugLevel2 debug level two
	DebugLevel2 = true //enable checks for impossible conditions
)

Functions

func BitcoinAddressFromPubkey

func BitcoinAddressFromPubkey(pubkey PubKey) string

BitcoinAddressFromPubkey prints the bitcoin address for a seckey

func BitcoinWalletImportFormatFromSeckey

func BitcoinWalletImportFormatFromSeckey(seckey SecKey) string

BitcoinWalletImportFormatFromSeckey exports seckey in wallet import format key must be compressed

func ChkSig

func ChkSig(address Address, hash SHA256, sig Sig) error

ChkSig checks whether PubKey corresponding to address hash signed hash - recovers the PubKey from sig and hash - fail if PubKey cannot be be recovered - computes the address from the PubKey - fail if recovered address does not match PubKey hash - verify that signature is valid for hash for PubKey

func DeterministicKeyPairIterator

func DeterministicKeyPairIterator(seed []byte) ([]byte, PubKey, SecKey)

DeterministicKeyPairIterator takes SHA256 value, returns a new SHA256 value and publickey and private key. Apply multiple times feeding the SHA256 value back into generate sequence of keys

func ECDH

func ECDH(pub PubKey, sec SecKey) []byte

ECDH generates a shared secret A: pub1,sec1 B: pub2,sec2 person A sends their public key pub1 person B sends an emphameral pubkey pub2 person A computes cipher.ECDH(pub2, sec1) person B computes cipher.ECDH(pub1, sec2) cipher.ECDH(pub2, sec1) equals cipher.ECDH(pub1, sec2) This is their shared secret

func GenerateDeterministicKeyPair

func GenerateDeterministicKeyPair(seed []byte) (PubKey, SecKey)

GenerateDeterministicKeyPair generates deterministic key pair

func GenerateKeyPair

func GenerateKeyPair() (PubKey, SecKey)

GenerateKeyPair creates key pair

func RandByte

func RandByte(n int) []byte

RandByte returns rand N bytes

func TestSecKey

func TestSecKey(seckey SecKey) error

TestSecKey test seckey hash

func TestSecKeyHash

func TestSecKeyHash(seckey SecKey, hash SHA256) error

TestSecKeyHash performs a series of tests to determine if a seckey is valid. All generated keys and keys loaded from disc must pass the TestSecKey suite. TestPrivKey returns error if a key fails any test in the test suite.

func VerifySignature

func VerifySignature(pubkey PubKey, sig Sig, hash SHA256) error

VerifySignature verifies that hash was signed by PubKey

func VerifySignedHash

func VerifySignedHash(sig Sig, hash SHA256) error

VerifySignedHash this only checks that the signature can be converted to a public key Since there is no pubkey or address argument, it cannot check that the signature is valid in that context.

Types

type Address

type Address struct {
	Version byte      //1 byte
	Key     Ripemd160 //20 byte pubkey hash
}

Address version is after Key to enable better vanity address generation Address stuct is a 25 byte with a 20 byte publickey hash, 1 byte address type and 4 byte checksum.

func AddressFromPubKey

func AddressFromPubKey(pubKey PubKey) Address

AddressFromPubKey creates Address from PubKey as ripemd160(sha256(sha256(pubkey)))

func AddressFromSecKey

func AddressFromSecKey(secKey SecKey) Address

AddressFromSecKey generates address from secret key

func BitcoinAddressFromBytes

func BitcoinAddressFromBytes(b []byte) (Address, error)

BitcoinAddressFromBytes Returns an address given an Address.Bytes()

func BitcoinDecodeBase58Address

func BitcoinDecodeBase58Address(addr string) (Address, error)

BitcoinDecodeBase58Address decode bitcoin address from string

func BitcoinMustDecodeBase58Address

func BitcoinMustDecodeBase58Address(addr string) Address

BitcoinMustDecodeBase58Address must decodes bitcoin address from string

func DecodeBase58Address

func DecodeBase58Address(addr string) (Address, error)

DecodeBase58Address creates an Address from its base58 encoding

func MustDecodeBase58Address

func MustDecodeBase58Address(addr string) Address

MustDecodeBase58Address creates an Address from its base58 encoding. Will panic if the addr is invalid

func (*Address) BitcoinBytes

func (addr *Address) BitcoinBytes() []byte

BitcoinBytes returns bitcoin address as byte slice

func (*Address) BitcoinChecksum

func (addr *Address) BitcoinChecksum() Checksum

BitcoinChecksum bitcoin checksum

func (Address) BitcoinString

func (addr Address) BitcoinString() string

BitcoinString convert bitcoin address to hex string

func (*Address) Bytes

func (addr *Address) Bytes() []byte

Bytes return address as a byte slice

func (*Address) Checksum

func (addr *Address) Checksum() Checksum

Checksum returns Address Checksum which is the first 4 bytes of sha256(key+version)

func (Address) Null

func (addr Address) Null() bool

Null returns true if the address is null (0x0000....)

func (Address) String

func (addr Address) String() string

String address as Base58 encoded string Returns address as printable version is first byte in binary format in printed address its key, version, checksum

func (Address) Verify

func (addr Address) Verify(key PubKey) error

Verify checks that the address appears valid for the public key

type Checksum

type Checksum [4]byte

Checksum 4 bytes

type PubKey

type PubKey [33]byte

PubKey public key

func MustPubKeyFromHex

func MustPubKeyFromHex(s string) PubKey

MustPubKeyFromHex decodes a hex encoded PubKey, or panics

func NewPubKey

func NewPubKey(b []byte) PubKey

NewPubKey converts []byte to a PubKey. Panics is []byte is not the exact size

func PubKeyFromHex

func PubKeyFromHex(s string) (PubKey, error)

PubKeyFromHex generates PubKey from hex string

func PubKeyFromSecKey

func PubKeyFromSecKey(seckey SecKey) PubKey

PubKeyFromSecKey recovers the public key for a secret key

func PubKeyFromSig

func PubKeyFromSig(sig Sig, hash SHA256) (PubKey, error)

PubKeyFromSig recovers the public key from a signed hash

func (PubKey) Hex

func (pk PubKey) Hex() string

Hex returns a hex encoded PubKey string

func (*PubKey) ToAddressHash

func (pk *PubKey) ToAddressHash() Ripemd160

ToAddressHash returns the public key as ripemd160(sha256(sha256(key)))

func (PubKey) Verify

func (pk PubKey) Verify() error

Verify attempts to determine if pubkey is valid. Returns nil on success

type PubKeySlice

type PubKeySlice []PubKey

PubKeySlice PubKey slice

func (PubKeySlice) Len

func (slice PubKeySlice) Len() int

Len returns length for sorting

func (PubKeySlice) Less

func (slice PubKeySlice) Less(i, j int) bool

Less for sorting

func (PubKeySlice) Swap

func (slice PubKeySlice) Swap(i, j int)

Swap for sorting

type Ripemd160

type Ripemd160 [20]byte

Ripemd160 ripemd160

func HashRipemd160

func HashRipemd160(data []byte) Ripemd160

HashRipemd160 hash data to Ripemd160

func (*Ripemd160) Set

func (rd *Ripemd160) Set(b []byte)

Set sets value

type SHA256

type SHA256 [32]byte

SHA256 32 bytes

func AddSHA256

func AddSHA256(a SHA256, b SHA256) SHA256

AddSHA256 returns the SHA256 hash of to two concatenated hashes

func DoubleSHA256

func DoubleSHA256(b []byte) SHA256

DoubleSHA256 double SHA256

func Merkle

func Merkle(h0 []SHA256) SHA256

Merkle computes the merkle root of a hash array Array of hashes is padded with 0 hashes until next power of 2

func MustSHA256FromHex

func MustSHA256FromHex(hs string) SHA256

MustSHA256FromHex same as SHA256FromHex, except will panic when detect error

func MustSumSHA256

func MustSumSHA256(b []byte, n int) SHA256

MustSumSHA256 like SumSHA256, but len(b) must equal n, or panic

func SHA256FromHex

func SHA256FromHex(hs string) (SHA256, error)

SHA256FromHex decodes a hex encoded SHA256 hash to bytes. If invalid, will return error. Does not panic.

func SumSHA256

func SumSHA256(b []byte) SHA256

SumSHA256 sum sha256

func (SHA256) Hex

func (g SHA256) Hex() string

Hex encode sha256 to hex string

func (SHA256) Null

func (g SHA256) Null() bool

Null returns true if the hash is null (0x0000..)

func (*SHA256) Set

func (g *SHA256) Set(b []byte)

Set sets value

func (*SHA256) Xor

func (g *SHA256) Xor(b SHA256) SHA256

Xor xor

type SecKey

type SecKey [32]byte

SecKey secret key

func GenerateDeterministicKeyPairs

func GenerateDeterministicKeyPairs(seed []byte, n int) []SecKey

GenerateDeterministicKeyPairs returns sequence of n private keys from initial seed

func GenerateDeterministicKeyPairsSeed

func GenerateDeterministicKeyPairsSeed(seed []byte, n int) ([]byte, []SecKey)

GenerateDeterministicKeyPairsSeed returns sequence of n private keys from initial seed, and return the new seed

func MustSecKeyFromHex

func MustSecKeyFromHex(s string) SecKey

MustSecKeyFromHex decodes a hex encoded SecKey, or panics

func MustSecKeyFromWalletImportFormat

func MustSecKeyFromWalletImportFormat(input string) SecKey

MustSecKeyFromWalletImportFormat SecKeyFromWalletImportFormat or panic

func NewSecKey

func NewSecKey(b []byte) SecKey

NewSecKey converts []byte to a SecKey. Panics is []byte is not the exact size

func SecKeyFromHex

func SecKeyFromHex(s string) (SecKey, error)

SecKeyFromHex decodes a hex encoded SecKey, or panics

func SecKeyFromWalletImportFormat

func SecKeyFromWalletImportFormat(input string) (SecKey, error)

SecKeyFromWalletImportFormat extracts a seckey from wallet import format

func (SecKey) Hex

func (sk SecKey) Hex() string

Hex returns a hex encoded SecKey string

func (SecKey) Verify

func (sk SecKey) Verify() error

Verify attempts to determine if SecKey is valid. Returns nil on success. If DebugLevel2, will do additional sanity checking

type Sig

type Sig [64 + 1]byte //64 byte signature with 1 byte for key recovery

Sig signature

func MustSigFromHex

func MustSigFromHex(s string) Sig

MustSigFromHex decodes a hex-encoded Sig, panicing if invalid

func NewSig

func NewSig(b []byte) Sig

NewSig converts []byte to a Sig. Panics is []byte is not the exact size

func SigFromHex

func SigFromHex(s string) (Sig, error)

SigFromHex generates signature from hex string

func SignHash

func SignHash(hash SHA256, sec SecKey) Sig

SignHash sign hash

func (Sig) Hex

func (s Sig) Hex() string

Hex converts signature to hex string

Directories

Path Synopsis
Package chacha20poly1305 implements the ChaCha20-Poly1305 AEAD as specified in RFC 7539.
Package chacha20poly1305 implements the ChaCha20-Poly1305 AEAD as specified in RFC 7539.
internal/chacha20
Package chacha20 implements the core ChaCha20 function as specified in https://tools.ietf.org/html/rfc7539#section-2.3.
Package chacha20 implements the core ChaCha20 function as specified in https://tools.ietf.org/html/rfc7539#section-2.3.
Package encoder binary implements translation between numbers and byte sequences and encoding and decoding of varints.
Package encoder binary implements translation between numbers and byte sequences and encoding and decoding of varints.
Package pbkdf2 implements the key derivation function PBKDF2 as defined in RFC 2898 / PKCS #5 v2.0.
Package pbkdf2 implements the key derivation function PBKDF2 as defined in RFC 2898 / PKCS #5 v2.0.
Package poly1305 implements Poly1305 one-time message authentication code as specified in http://cr.yp.to/mac/poly1305-20050329.pdf.
Package poly1305 implements Poly1305 one-time message authentication code as specified in http://cr.yp.to/mac/poly1305-20050329.pdf.
Package ripemd160 implements the RIPEMD-160 hash algorithm.
Package ripemd160 implements the RIPEMD-160 hash algorithm.
Package scrypt implements the scrypt key derivation function as defined in Colin Percival's paper "Stronger Key Derivation via Sequential Memory-Hard Functions" (http://www.tarsnap.com/scrypt/scrypt.pdf).
Package scrypt implements the scrypt key derivation function as defined in Colin Percival's paper "Stronger Key Derivation via Sequential Memory-Hard Functions" (http://www.tarsnap.com/scrypt/scrypt.pdf).
nolint: golint
nolint: golint

Jump to

Keyboard shortcuts

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