Documentation ¶
Overview ¶
Ripemd160
sum := crypto.Ripemd160([]byte("This is consensus")) fmt.Printf("%x\n", sum)
Index ¶
- Constants
- func CRandBytes(numBytes int) []byte
- func CRandHex(numDigits int) string
- func CReader() io.Reader
- func DecodeArmor(armorStr string) (blockType string, headers map[string]string, data []byte, err error)
- func DecryptSymmetric(ciphertext []byte, secret []byte) (plaintext []byte, err error)
- func EncodeArmor(blockType string, headers map[string]string, data []byte) string
- func EncryptSymmetric(plaintext []byte, secret []byte) (ciphertext []byte)
- func MixEntropy(seedBytes []byte)
- func RegisterAmino(cdc *amino.Codec)
- func Ripemd160(bytes []byte) []byte
- func Sha256(bytes []byte) []byte
- type Address
- type PrivKey
- type PrivKeyEd25519
- func (privKey PrivKeyEd25519) Bytes() []byte
- func (privKey PrivKeyEd25519) Equals(other PrivKey) bool
- func (privKey PrivKeyEd25519) Generate(index int) PrivKeyEd25519
- func (privKey PrivKeyEd25519) PubKey() PubKey
- func (privKey PrivKeyEd25519) Sign(msg []byte) (Signature, error)
- func (privKey PrivKeyEd25519) ToCurve25519() *[32]byte
- type PrivKeySecp256k1
- type PubKey
- type PubKeyEd25519
- func (pubKey PubKeyEd25519) Address() Address
- func (pubKey PubKeyEd25519) Bytes() []byte
- func (pubKey PubKeyEd25519) Equals(other PubKey) bool
- func (pubKey PubKeyEd25519) String() string
- func (pubKey PubKeyEd25519) ToCurve25519() *[PubKeyEd25519Size]byte
- func (pubKey PubKeyEd25519) VerifyBytes(msg []byte, sig_ Signature) bool
- type PubKeySecp256k1
- type Signature
- type SignatureEd25519
- type SignatureSecp256k1
Examples ¶
Constants ¶
const PubKeyEd25519Size = 32
const PubKeySecp256k1Size = 33
const SignatureEd25519Size = 64
const Version = "0.9.0-dev"
Variables ¶
This section is empty.
Functions ¶
func CRandHex ¶
CRandHex returns a hex encoded string that's floor(numDigits/2) * 2 long.
Note: CRandHex(24) gives 96 bits of randomness that are usually strong enough for most purposes.
func DecodeArmor ¶ added in v0.22.0
func DecryptSymmetric ¶ added in v0.22.0
secret must be 32 bytes long. Use something like Sha256(Bcrypt(passphrase)) The ciphertext is (secretbox.Overhead + 24) bytes longer than the plaintext.
func EncodeArmor ¶ added in v0.22.0
func EncryptSymmetric ¶ added in v0.22.0
secret must be 32 bytes long. Use something like Sha256(Bcrypt(passphrase)) The ciphertext is (secretbox.Overhead + 24) bytes longer than the plaintext. NOTE: call crypto.MixEntropy() first.
func MixEntropy ¶ added in v0.22.0
func MixEntropy(seedBytes []byte)
Mix additional bytes of randomness, e.g. from hardware, user-input, etc. It is OK to call it multiple times. It does not diminish security.
func RegisterAmino ¶ added in v0.22.0
RegisterAmino registers all crypto related types in the given (amino) codec.
Types ¶
type Address ¶
An address is a []byte, but hex-encoded even in JSON. []byte leaves us the option to change the address length. Use an alias so Unmarshal methods (with ptr receivers) are available too.
type PrivKey ¶
type PrivKey interface { Bytes() []byte Sign(msg []byte) (Signature, error) PubKey() PubKey Equals(PrivKey) bool }
func PrivKeyFromBytes ¶ added in v0.22.0
type PrivKeyEd25519 ¶ added in v0.22.0
type PrivKeyEd25519 [64]byte
Implements PrivKey
func GenPrivKeyEd25519 ¶ added in v0.22.0
func GenPrivKeyEd25519() PrivKeyEd25519
func GenPrivKeyEd25519FromSecret ¶ added in v0.22.0
func GenPrivKeyEd25519FromSecret(secret []byte) PrivKeyEd25519
NOTE: secret should be the output of a KDF like bcrypt, if it's derived from user input.
func (PrivKeyEd25519) Bytes ¶ added in v0.22.0
func (privKey PrivKeyEd25519) Bytes() []byte
func (PrivKeyEd25519) Equals ¶ added in v0.22.0
func (privKey PrivKeyEd25519) Equals(other PrivKey) bool
Equals - you probably don't need to use this. Runs in constant time based on length of the keys.
func (PrivKeyEd25519) Generate ¶ added in v0.22.0
func (privKey PrivKeyEd25519) Generate(index int) PrivKeyEd25519
Deterministically generates new priv-key bytes from key.
func (PrivKeyEd25519) PubKey ¶ added in v0.22.0
func (privKey PrivKeyEd25519) PubKey() PubKey
func (PrivKeyEd25519) Sign ¶ added in v0.22.0
func (privKey PrivKeyEd25519) Sign(msg []byte) (Signature, error)
func (PrivKeyEd25519) ToCurve25519 ¶ added in v0.22.0
func (privKey PrivKeyEd25519) ToCurve25519() *[32]byte
type PrivKeySecp256k1 ¶ added in v0.22.0
type PrivKeySecp256k1 [32]byte
Implements PrivKey
func GenPrivKeySecp256k1 ¶ added in v0.22.0
func GenPrivKeySecp256k1() PrivKeySecp256k1
func GenPrivKeySecp256k1FromSecret ¶ added in v0.22.0
func GenPrivKeySecp256k1FromSecret(secret []byte) PrivKeySecp256k1
NOTE: secret should be the output of a KDF like bcrypt, if it's derived from user input.
func (PrivKeySecp256k1) Bytes ¶ added in v0.22.0
func (privKey PrivKeySecp256k1) Bytes() []byte
func (PrivKeySecp256k1) Equals ¶ added in v0.22.0
func (privKey PrivKeySecp256k1) Equals(other PrivKey) bool
Equals - you probably don't need to use this. Runs in constant time based on length of the keys.
func (PrivKeySecp256k1) PubKey ¶ added in v0.22.0
func (privKey PrivKeySecp256k1) PubKey() PubKey
type PubKey ¶
type PubKey interface { Address() Address Bytes() []byte VerifyBytes(msg []byte, sig Signature) bool Equals(PubKey) bool }
func PubKeyFromBytes ¶ added in v0.22.0
type PubKeyEd25519 ¶ added in v0.22.0
type PubKeyEd25519 [PubKeyEd25519Size]byte
Implements PubKeyInner
func (PubKeyEd25519) Address ¶ added in v0.22.0
func (pubKey PubKeyEd25519) Address() Address
Address is the SHA256-20 of the raw pubkey bytes.
func (PubKeyEd25519) Bytes ¶ added in v0.22.0
func (pubKey PubKeyEd25519) Bytes() []byte
func (PubKeyEd25519) Equals ¶ added in v0.22.0
func (pubKey PubKeyEd25519) Equals(other PubKey) bool
func (PubKeyEd25519) String ¶ added in v0.22.0
func (pubKey PubKeyEd25519) String() string
func (PubKeyEd25519) ToCurve25519 ¶ added in v0.22.0
func (pubKey PubKeyEd25519) ToCurve25519() *[PubKeyEd25519Size]byte
For use with golang/crypto/nacl/box If error, returns nil.
func (PubKeyEd25519) VerifyBytes ¶ added in v0.22.0
func (pubKey PubKeyEd25519) VerifyBytes(msg []byte, sig_ Signature) bool
type PubKeySecp256k1 ¶ added in v0.22.0
type PubKeySecp256k1 [PubKeySecp256k1Size]byte
Implements PubKey. Compressed pubkey (just the x-cord), prefixed with 0x02 or 0x03, depending on the y-cord.
func (PubKeySecp256k1) Address ¶ added in v0.22.0
func (pubKey PubKeySecp256k1) Address() Address
Implements Bitcoin style addresses: RIPEMD160(SHA256(pubkey))
func (PubKeySecp256k1) Bytes ¶ added in v0.22.0
func (pubKey PubKeySecp256k1) Bytes() []byte
func (PubKeySecp256k1) Equals ¶ added in v0.22.0
func (pubKey PubKeySecp256k1) Equals(other PubKey) bool
func (PubKeySecp256k1) String ¶ added in v0.22.0
func (pubKey PubKeySecp256k1) String() string
func (PubKeySecp256k1) VerifyBytes ¶ added in v0.22.0
func (pubKey PubKeySecp256k1) VerifyBytes(msg []byte, sig_ Signature) bool
type Signature ¶ added in v0.22.0
func SignatureEd25519FromBytes ¶ added in v0.22.0
func SignatureFromBytes ¶ added in v0.22.0
func SignatureSecp256k1FromBytes ¶ added in v0.22.0
type SignatureEd25519 ¶ added in v0.22.0
type SignatureEd25519 [SignatureEd25519Size]byte
Implements Signature
func (SignatureEd25519) Bytes ¶ added in v0.22.0
func (sig SignatureEd25519) Bytes() []byte
func (SignatureEd25519) Equals ¶ added in v0.22.0
func (sig SignatureEd25519) Equals(other Signature) bool
func (SignatureEd25519) IsZero ¶ added in v0.22.0
func (sig SignatureEd25519) IsZero() bool
func (SignatureEd25519) String ¶ added in v0.22.0
func (sig SignatureEd25519) String() string
type SignatureSecp256k1 ¶ added in v0.22.0
type SignatureSecp256k1 []byte
Implements Signature
func (SignatureSecp256k1) Bytes ¶ added in v0.22.0
func (sig SignatureSecp256k1) Bytes() []byte
func (SignatureSecp256k1) Equals ¶ added in v0.22.0
func (sig SignatureSecp256k1) Equals(other Signature) bool
func (SignatureSecp256k1) IsZero ¶ added in v0.22.0
func (sig SignatureSecp256k1) IsZero() bool
func (SignatureSecp256k1) String ¶ added in v0.22.0
func (sig SignatureSecp256k1) String() string
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package hkdfchacha20poly1305 creates an AEAD using hkdf, chacha20, and poly1305 When sealing and opening, the hkdf is used to obtain the nonce and subkey for chacha20.
|
Package hkdfchacha20poly1305 creates an AEAD using hkdf, chacha20, and poly1305 When sealing and opening, the hkdf is used to obtain the nonce and subkey for chacha20. |
Package merkle computes a deterministic minimal height Merkle tree hash.
|
Package merkle computes a deterministic minimal height Merkle tree hash. |