crypto

package
v0.0.0-...-c187892 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2016 License: GPL-3.0, GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddressFromPub

func AddressFromPub(addrType AddrType, pub []byte) (addr []byte)

func GetAllAddresses

func GetAllAddresses(keysDirPath string) (addresses [][]byte, err error)

func GetKeyFile

func GetKeyFile(keysDirPath string, keyAddr []byte) (fileContent []byte, err error)

func IsEncryptedKey

func IsEncryptedKey(ks KeyStore, keyAddr []byte) (bool, error)

func IsValidKeyJson

func IsValidKeyJson(j []byte) []byte

returns the address if valid, nil otherwise

func PKCS7Unpad

func PKCS7Unpad(in []byte) []byte

func Ripemd160

func Ripemd160(data ...[]byte) []byte

func Sha256

func Sha256(data ...[]byte) []byte

func Sha3

func Sha3(data ...[]byte) []byte

func Verify

func Verify(curveType CurveType, hash, sig, pub []byte) (bool, error)

func WriteKeyFile

func WriteKeyFile(addr []byte, keysDirPath string, content []byte) (err error)

Types

type AddrType

type AddrType uint8
const (
	AddrTypeRipemd160 AddrType = iota
	AddrTypeRipemd160Sha256
	AddrTypeSha3
)

func AddrTypeFromString

func AddrTypeFromString(s string) (AddrType, error)

func (AddrType) String

func (a AddrType) String() string

type CurveType

type CurveType uint8
const (
	CurveTypeSecp256k1 CurveType = iota
	CurveTypeEd25519
)

func CurveTypeFromString

func CurveTypeFromString(s string) (CurveType, error)

func (CurveType) String

func (k CurveType) String() string

type InvalidCurveErr

type InvalidCurveErr string

func (InvalidCurveErr) Error

func (err InvalidCurveErr) Error() string

type Key

type Key struct {
	Id         uuid.UUID // Version 4 "random" for unique id not derived from key data
	Type       KeyType   // contains curve and addr types
	Address    []byte    // reference id
	PrivateKey []byte    // we don't store pub
}

func DecryptKey

func DecryptKey(ks keyStorePassphrase, keyAddr []byte, auth string) (*Key, error)

func GenerateNewKeyDefault

func GenerateNewKeyDefault(ks KeyStore, typ KeyType, auth string) (key *Key, err error)

func NewKey

func NewKey(typ KeyType) (*Key, error)

func NewKeyFromPriv

func NewKeyFromPriv(typ KeyType, priv []byte) (*Key, error)

func (*Key) MarshalJSON

func (k *Key) MarshalJSON() (j []byte, err error)

func (*Key) Pubkey

func (k *Key) Pubkey() ([]byte, error)

func (*Key) Sign

func (k *Key) Sign(hash []byte) ([]byte, error)

func (*Key) UnmarshalJSON

func (k *Key) UnmarshalJSON(j []byte) (err error)

type KeyStore

type KeyStore interface {
	GenerateNewKey(tpy KeyType, auth string) (*Key, error)
	GetKey(addr []byte, auth string) (*Key, error)
	GetAllAddresses() ([][]byte, error)
	StoreKey(key *Key, auth string) error
	DeleteKey(addr []byte, auth string) error
}

func NewKeyStorePassphrase

func NewKeyStorePassphrase(path string) KeyStore

func NewKeyStorePlain

func NewKeyStorePlain(path string) KeyStore

type KeyType

type KeyType struct {
	CurveType CurveType
	AddrType  AddrType
}

func KeyTypeFromString

func KeyTypeFromString(s string) (k KeyType, err error)

func (KeyType) String

func (typ KeyType) String() string

type NoPrivateKeyErr

type NoPrivateKeyErr string

func (NoPrivateKeyErr) Error

func (err NoPrivateKeyErr) Error() string

Directories

Path Synopsis
Package ed25519 implements the Ed25519 signature algorithm.
Package ed25519 implements the Ed25519 signature algorithm.
edwards25519
Package edwards25519 implements operations in GF(2**255-19) and on an Edwards curve that is isomorphic to curve25519.
Package edwards25519 implements operations in GF(2**255-19) and on an Edwards curve that is isomorphic to curve25519.
Package sha3 implements the SHA3 hash algorithm (formerly called Keccak) chosen by NIST in 2012.
Package sha3 implements the SHA3 hash algorithm (formerly called Keccak) chosen by NIST in 2012.

Jump to

Keyboard shortcuts

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