crypto

package
v0.0.0-...-b00a37c Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2021 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// HashStrategy is the hash strategy for SHA3-384.
	HashStrategy func() hash.Hash = sha3.New384
)

Functions

func AddrFromPubKey

func AddrFromPubKey(pubkey []byte) string

AddrFromPubKey generates an address the same way it's generated for Bitcoin.

func Base58Decode

func Base58Decode(str string) []byte

Base58Decode decodes a base58 encoded string.

func Base58Encode

func Base58Encode(payload []byte) string

Base58Encode encodes a series of bytes into a base58 string.

func ByteArrayToHex

func ByteArrayToHex(payload []byte) string

ByteArrayToHex converts a set of bytes to a hex encoded string.

func CreateAEAD

func CreateAEAD(key []byte) (cipher.AEAD, error)

CreateAEAD creates a new authenticated encryption with associated data.

func DecryptGCM

func DecryptGCM(ciphertext []byte, key []byte) ([]byte, error)

DecryptGCM decrypts an AES/GCM encrypted ciphertext.

func DoubleSHA256

func DoubleSHA256(b []byte) []byte

DoubleSHA256 generates the double SHA256 hash of the input.

func EncryptGCM

func EncryptGCM(plaintext []byte, key []byte) ([]byte, error)

EncryptGCM encrypts the plaintext with AES/GCM.

func GetSHA256Hash

func GetSHA256Hash(b []byte) []byte

GetSHA256Hash returns the SHA256 hash.

func GetSHA3384Hash

func GetSHA3384Hash(str []byte) ([]byte, error)

GetSHA3384Hash returns the SHA3-512 hash of a given string.

func PadKey

func PadKey(key []byte) []byte

PadKey compensates for a key that is smaller than 32 bytes.

func PubKeyFromAddress

func PubKeyFromAddress(address string) (*secp256k1.PublicKey, error)

PubKeyFromAddress decodes an address and returns the public key.

func VerifySchnorrSignature

func VerifySchnorrSignature(pubKey *secp256k1.PublicKey, sig []byte, data []byte) bool

VerifySchnorrSignature verifies the given Schnorr signature.

func VerifySignature

func VerifySignature(pub *secp256k1.PublicKey, sig []byte, msg []byte) bool

VerifySignature verifies a DER signature.

Types

type KeyPair

type KeyPair struct {
	Public  *secp256k1.PublicKey
	Private *secp256k1.PrivateKey
}

KeyPair represents a structure for managing encryption keys.

func ParsePubKey

func ParsePubKey(pub []byte) (*KeyPair, error)

ParsePubKey parses a pubic key.

func PrivKeyFromBytes

func PrivKeyFromBytes(priv []byte) *KeyPair

PrivKeyFromBytes gets the private key from bytes.

func (*KeyPair) Encrypt

func (k *KeyPair) Encrypt(message []byte, recepientPubKey *secp256k1.PublicKey) ([]byte, error)

Encrypt a message with a temporary key and a shared secret derived from AEAD AES GCM.

func (*KeyPair) Generate

func (k *KeyPair) Generate() error

Generate generates a new set of secp256k1 keys.

func (*KeyPair) GetAddr

func (k *KeyPair) GetAddr() string

GetAddr gets the address version of the public key.

func (*KeyPair) GetPrivKey

func (k *KeyPair) GetPrivKey() string

GetPrivKey returns the private key.

func (*KeyPair) GetPubKey

func (k *KeyPair) GetPubKey() string

GetPubKey returns the public key.

func (*KeyPair) GetPubKeyHashFromAddr

func (k *KeyPair) GetPubKeyHashFromAddr(str string) ([]byte, error)

GetPubKeyHashFromAddr gets the public key hash from the address.

func (*KeyPair) GetPubKeyUncompressed

func (k *KeyPair) GetPubKeyUncompressed() string

GetPubKeyUncompressed gets the uncompressed version of the public key.

func (*KeyPair) SchnorrSign

func (k *KeyPair) SchnorrSign(data []byte) ([]byte, error)

SchnorrSign creates a Schnorr signature of the given data.

func (*KeyPair) Sign

func (k *KeyPair) Sign(message []byte) (*ecdsa.Signature, error)

Sign simply signs a message.

type PRBG

type PRBG struct {
	Seed []byte
	// contains filtered or unexported fields
}

PRBG is the struct representing our pseud-random byte generator object.

func (*PRBG) Next

func (p *PRBG) Next(n int) []byte

Next gets the next set of random bytes.

func (*PRBG) NextUInt64

func (p *PRBG) NextUInt64(n int) uint64

NextUInt64 gets the next set of random integer.

Jump to

Keyboard shortcuts

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