Documentation ¶
Overview ¶
Ripemd160
sum := crypto.Ripemd160([]byte("This is blockchain")) fmt.Printf("%x\n", sum)
Index ¶
- Constants
- func CRandBytes(numBytes int) []byte
- func CRandHex(numDigits int) string
- func CReader() io.Reader
- func CheckPriKey(pubKey, priKey string) (bool, error)
- func CompressPubkey(pubkey *ecdsa.PublicKey) []byte
- func CreateAddress(b common.Address, nonce uint64, payload []byte) common.Address
- func CreateAddress2(b common.Address, salt [32]byte, inithash []byte) common.Address
- func DecodeArmor(armorStr string) (blockType string, headers map[string]string, data []byte, err error)
- func DecompressPubkey(pubkey []byte) (*ecdsa.PublicKey, error)
- func DecryptSymmetric(ciphertext []byte, secret []byte) (plaintext []byte, err error)
- func Ecrecover(hash, sig []byte) ([]byte, error)
- func EncodeArmor(blockType string, headers map[string]string, data []byte) string
- func EncryptSymmetric(plaintext []byte, secret []byte) (ciphertext []byte)
- func FromECDSA(priv *ecdsa.PrivateKey) []byte
- func FromECDSAPub(pub *ecdsa.PublicKey) []byte
- func GenerateKey() (*ecdsa.PrivateKey, error)
- func HexToECDSA(hexkey string) (*ecdsa.PrivateKey, error)
- func Keccak256(data ...[]byte) []byte
- func Keccak256Hash(data ...[]byte) (h common.Hash)
- func Keccak512(data ...[]byte) []byte
- func LoadECDSA(file string) (*ecdsa.PrivateKey, error)
- func MixEntropy(seedBytes []byte)
- func PubkeyToAddress(p ecdsa.PublicKey) common.Address
- func RegisterAmino()
- func Ripemd160(bytes []byte) []byte
- func S256() elliptic.Curve
- func SaveECDSA(file string, key *ecdsa.PrivateKey) error
- func Sha256(bytes []byte) []byte
- func SigToPub(hash, sig []byte) (*ecdsa.PublicKey, error)
- func Sign(hash []byte, prv *ecdsa.PrivateKey) (sig []byte, err error)
- func ToECDSA(d []byte) (*ecdsa.PrivateKey, error)
- func ToECDSAUnsafe(d []byte) *ecdsa.PrivateKey
- func UnmarshalPubkey(pub []byte) (*ecdsa.PublicKey, error)
- func ValidateSignatureValues(v byte, r, s *big.Int, homestead bool) bool
- func VerifySignature(pubkey, hash, signature []byte) bool
- 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) MarshalJSON() ([]byte, error)
- func (privKey PrivKeyEd25519) PubKey() PubKey
- func (privKey PrivKeyEd25519) Sign(msg []byte) (Signature, error)
- func (privKey *PrivKeyEd25519) UnmarshalJSON(input []byte) error
- 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) MarshalJSON() ([]byte, error)
- func (pubKey PubKeyEd25519) String() string
- func (pubKey *PubKeyEd25519) UnmarshalJSON(input []byte) error
- 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 CheckPriKey ¶
func CompressPubkey ¶
CompressPubkey encodes a public key to the 33-byte compressed format.
func CreateAddress ¶
CreateAddress creates an ethereum address given the bytes and the nonce
func CreateAddress2 ¶
CreateAddress2 creates an ethereum address given the address bytes, initial contract code hash and a salt.
func DecodeArmor ¶
func DecompressPubkey ¶
DecompressPubkey parses a public key in the 33-byte compressed format.
func DecryptSymmetric ¶
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 ¶
func EncryptSymmetric ¶
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 FromECDSA ¶
func FromECDSA(priv *ecdsa.PrivateKey) []byte
FromECDSA exports a private key into a binary dump.
func FromECDSAPub ¶
func GenerateKey ¶
func GenerateKey() (*ecdsa.PrivateKey, error)
func HexToECDSA ¶
func HexToECDSA(hexkey string) (*ecdsa.PrivateKey, error)
HexToECDSA parses a secp256k1 private key.
func Keccak256Hash ¶
Keccak256Hash calculates and returns the Keccak256 hash of the input data, converting it to an internal Hash data structure.
func LoadECDSA ¶
func LoadECDSA(file string) (*ecdsa.PrivateKey, error)
LoadECDSA loads a secp256k1 private key from the given file.
func MixEntropy ¶
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 ¶
func RegisterAmino()
RegisterAmino registers all crypto related types in the given (amino) codec.
func Ripemd160 ¶
Example ¶
sum := Ripemd160([]byte("This is blockchain")) fmt.Printf("%x\n", sum)
Output: fe3a9bddf46bc0c7a304d9e46a1f1886cebcfc64
func SaveECDSA ¶
func SaveECDSA(file string, key *ecdsa.PrivateKey) error
SaveECDSA saves a secp256k1 private key to the given file with restrictive permissions. The key data is saved hex-encoded.
func Sha256 ¶
Example ¶
sum := Sha256([]byte("This is blockchain")) fmt.Printf("%x\n", sum)
Output: 725e310f23c4ade6bbd2e042140ca3669b9a6db3d25681724ca139fcc91ca5f4
func Sign ¶
func Sign(hash []byte, prv *ecdsa.PrivateKey) (sig []byte, err error)
Sign calculates an ECDSA signature.
This function is susceptible to chosen plaintext attacks that can leak information about the private key that is used for signing. Callers must be aware that the given hash cannot be chosen by an adversery. Common solution is to hash any input before calculating the signature.
The produced signature is in the [R || S || V] format where V is 0 or 1.
func ToECDSA ¶
func ToECDSA(d []byte) (*ecdsa.PrivateKey, error)
ToECDSA creates a private key with the given D value.
func ToECDSAUnsafe ¶
func ToECDSAUnsafe(d []byte) *ecdsa.PrivateKey
ToECDSAUnsafe blindly converts a binary blob to a private key. It should almost never be used unless you are sure the input is valid and want to avoid hitting errors due to bad origin encoding (0 prefixes cut off).
func UnmarshalPubkey ¶
UnmarshalPubkey converts bytes to a secp256k1 public key.
func ValidateSignatureValues ¶
ValidateSignatureValues verifies whether the signature values are valid with the given chain rules. The v value is assumed to be either 0 or 1.
func VerifySignature ¶
VerifySignature checks that the given public key created signature over hash. The public key should be in compressed (33 bytes) or uncompressed (65 bytes) format. The signature should have the 64 byte [R || S] format.
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 HexToPrivkey ¶
func PrivKeyFromBytes ¶
type PrivKeyEd25519 ¶
type PrivKeyEd25519 [64]byte
Implements PrivKey
func GenPrivKeyEd25519 ¶
func GenPrivKeyEd25519() PrivKeyEd25519
func GenPrivKeyEd25519FromSecret ¶
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 ¶
func (privKey PrivKeyEd25519) Bytes() []byte
func (PrivKeyEd25519) Equals ¶
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 ¶
func (privKey PrivKeyEd25519) Generate(index int) PrivKeyEd25519
Deterministically generates new priv-key bytes from key.
func (PrivKeyEd25519) MarshalJSON ¶
func (privKey PrivKeyEd25519) MarshalJSON() ([]byte, error)
func (PrivKeyEd25519) PubKey ¶
func (privKey PrivKeyEd25519) PubKey() PubKey
func (*PrivKeyEd25519) UnmarshalJSON ¶
func (privKey *PrivKeyEd25519) UnmarshalJSON(input []byte) error
type PrivKeySecp256k1 ¶
type PrivKeySecp256k1 [32]byte
Implements PrivKey
func GenPrivKeySecp256k1 ¶
func GenPrivKeySecp256k1() PrivKeySecp256k1
func GenPrivKeySecp256k1FromSecret ¶
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 ¶
func (privKey PrivKeySecp256k1) Bytes() []byte
func (PrivKeySecp256k1) Equals ¶
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 ¶
func (privKey PrivKeySecp256k1) PubKey() PubKey
type PubKey ¶
type PubKey interface { Address() Address Bytes() []byte VerifyBytes(msg []byte, sig Signature) bool Equals(PubKey) bool }
func HexToPubkey ¶
func PubKeyFromBytes ¶
type PubKeyEd25519 ¶
type PubKeyEd25519 [PubKeyEd25519Size]byte
Implements PubKeyInner
func (PubKeyEd25519) Address ¶
func (pubKey PubKeyEd25519) Address() Address
Address is the Ripemd160 of the raw pubkey bytes.
func (PubKeyEd25519) Bytes ¶
func (pubKey PubKeyEd25519) Bytes() []byte
func (PubKeyEd25519) Equals ¶
func (pubKey PubKeyEd25519) Equals(other PubKey) bool
func (PubKeyEd25519) MarshalJSON ¶
func (pubKey PubKeyEd25519) MarshalJSON() ([]byte, error)
func (PubKeyEd25519) String ¶
func (pubKey PubKeyEd25519) String() string
func (*PubKeyEd25519) UnmarshalJSON ¶
func (pubKey *PubKeyEd25519) UnmarshalJSON(input []byte) error
func (PubKeyEd25519) VerifyBytes ¶
func (pubKey PubKeyEd25519) VerifyBytes(msg []byte, sig_ Signature) bool
type PubKeySecp256k1 ¶
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 ¶
func (pubKey PubKeySecp256k1) Address() Address
Implements Bitcoin style addresses: RIPEMD160(SHA256(pubkey))
func (PubKeySecp256k1) Bytes ¶
func (pubKey PubKeySecp256k1) Bytes() []byte
func (PubKeySecp256k1) Equals ¶
func (pubKey PubKeySecp256k1) Equals(other PubKey) bool
func (PubKeySecp256k1) String ¶
func (pubKey PubKeySecp256k1) String() string
func (PubKeySecp256k1) VerifyBytes ¶
func (pubKey PubKeySecp256k1) VerifyBytes(msg []byte, sig_ Signature) bool
type Signature ¶
func SignatureFromBytes ¶
type SignatureEd25519 ¶
type SignatureEd25519 [SignatureEd25519Size]byte
Implements Signature
func (SignatureEd25519) Bytes ¶
func (sig SignatureEd25519) Bytes() []byte
func (SignatureEd25519) Equals ¶
func (sig SignatureEd25519) Equals(other Signature) bool
func (SignatureEd25519) IsZero ¶
func (sig SignatureEd25519) IsZero() bool
func (SignatureEd25519) String ¶
func (sig SignatureEd25519) String() string
type SignatureSecp256k1 ¶
type SignatureSecp256k1 []byte
Implements Signature
func (SignatureSecp256k1) Bytes ¶
func (sig SignatureSecp256k1) Bytes() []byte
func (SignatureSecp256k1) Equals ¶
func (sig SignatureSecp256k1) Equals(other Signature) bool
func (SignatureSecp256k1) IsZero ¶
func (sig SignatureSecp256k1) IsZero() bool
func (SignatureSecp256k1) String ¶
func (sig SignatureSecp256k1) String() string
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package bn256 implements the Optimal Ate pairing over a 256-bit Barreto-Naehrig curve.
|
Package bn256 implements the Optimal Ate pairing over a 256-bit Barreto-Naehrig curve. |
cloudflare
Package bn256 implements a particular bilinear group at the 128-bit security level.
|
Package bn256 implements a particular bilinear group at the 128-bit security level. |
google
Package bn256 implements a particular bilinear group.
|
Package bn256 implements a particular bilinear group. |
Package merkle computes a deterministic minimal height Merkle tree hash.
|
Package merkle computes a deterministic minimal height Merkle tree hash. |
Package secp256k1 wraps the bitcoin secp256k1 C library.
|
Package secp256k1 wraps the bitcoin secp256k1 C library. |