aes

package
v0.0.0-...-5c8f3ac Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2018 License: GPL-3.0 Imports: 24 Imported by: 2

Documentation

Index

Constants

View Source
const (
	HashLength = 32
	UUIDLength = 20
)
View Source
const (

	// StandardScryptN is the N parameter of Scrypt encryption algorithm, using 256MB
	// memory and taking approximately 1s CPU time on a modern processor.
	StandardScryptN = 1 << 18

	// StandardScryptP is the P parameter of Scrypt encryption algorithm, using 256MB
	// memory and taking approximately 1s CPU time on a modern processor.
	StandardScryptP = 1

	// LightScryptN is the N parameter of Scrypt encryption algorithm, using 4MB
	// memory and taking approximately 100ms CPU time on a modern processor.
	LightScryptN = 1 << 12

	// LightScryptP is the P parameter of Scrypt encryption algorithm, using 4MB
	// memory and taking approximately 100ms CPU time on a modern processor.
	LightScryptP = 6
)

Variables

View Source
var (
	Big1   = big.NewInt(1)
	Big2   = big.NewInt(2)
	Big3   = big.NewInt(3)
	Big0   = big.NewInt(0)
	Big32  = big.NewInt(32)
	Big256 = big.NewInt(256)
	Big257 = big.NewInt(257)
)
View Source
var (
	ErrLocked  = NewAuthNeededError("password or unlock")
	ErrNoMatch = errors.New("no key for given address or file")
	ErrDecrypt = errors.New("could not decrypt key with given passphrase")
)
View Source
var Pubkeytmp ecdsa.PublicKey
View Source
var Reader io.Reader = &randEntropy{}

Functions

func EncryptKey

func EncryptKey(OptionalInfo string, key *Key, auth string, scryptN, scryptP int) ([]byte, error)

EncryptKey encrypts a key using the specified scrypt parameters into a json blob that can be decrypted later on.

func Fatalf

func Fatalf(format string, args ...interface{})

func FromECDSACRYPTO

func FromECDSACRYPTO(priv *ecdsa.PrivateKey) []byte

FromECDSACRYPTO exports a private key into a binary dump.

func FromECDSACRYPTOPub

func FromECDSACRYPTOPub(pub *ecdsa.PublicKey) []byte

func FromPriECDSACRYPTOPub

func FromPriECDSACRYPTOPub(priv *ecdsa.PrivateKey) []byte

FromECDSACRYPTOPub exports a private key into a binary dump.

func GenerateKey_ZL

func GenerateKey_ZL() (pubkey, seckey []byte)

func GetEntropyCSPRNG

func GetEntropyCSPRNG(n int) []byte

func Keccak256

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

Keccak256 calculates and returns the Keccak256 hash of the input data.

func NewAuthNeededError

func NewAuthNeededError(needed string) error

NewAuthNeededError creates a new authentication error with the extra details about the needed fields set.

func NewKeccak256

func NewKeccak256() hash.Hash

NewKeccak256 creates a new Keccak-256 hash.

func PaddedBigBytes

func PaddedBigBytes(bigint *big.Int, n int) []byte

func ReadBits

func ReadBits(bigint *big.Int, buf []byte)

func S256

func S256() elliptic.Curve

func ToECDSACRYPTO

func ToECDSACRYPTO(d []byte) (*ecdsa.PrivateKey, error)

ToECDSACRYPTO creates a private key with the given D value.

func ToECDSACRYPTOPub

func ToECDSACRYPTOPub(pub []byte) *ecdsa.PublicKey

func ToECDSACRYPTOUnsafe

func ToECDSACRYPTOUnsafe(d []byte) *ecdsa.PrivateKey

ToECDSACRYPTOUnsafe 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 WriteKeyFile

func WriteKeyFile(file string, content []byte) error

Types

type AuthNeededError

type AuthNeededError struct {
	Needed string // Extra authentication the user needs to provide
}

func (*AuthNeededError) Error

func (err *AuthNeededError) Error() string

Error implements the standard error interface.

type Key

type Key struct {
	Id uuid.UUID // Version 4 "random" for unique id not derived from key data
	// to simplify lookups we also store the address
	UUID UUID
	// we only store privkey as pubkey/address can be derived from it
	// privkey in this struct is always in plaintext
	PrivateKey *ecdsa.PrivateKey
}

func DecryptKey

func DecryptKey(keyjson []byte, auth string) (*Key, string, error)

DecryptKey decrypts a key from a json blob, returning the private key itself.

func KeyDecrypt

func KeyDecrypt(filename string, UserPassword string) (*Key, string, error)

Tests that a json key file can be decrypted and encrypted in multiple rounds.

func NewKey

func NewKey(rand io.Reader) (*Key, error)

func NewKeyByPri

func NewKeyByPri(priKey string) *Key

type UUID

type UUID [UUIDLength]byte

func BytesToUUID

func BytesToUUID(b []byte) UUID

func PubkeyToUUID

func PubkeyToUUID(p ecdsa.PublicKey) UUID

func (UUID) Bytes

func (a UUID) Bytes() []byte

func (*UUID) SetBytes

func (a *UUID) SetBytes(b []byte)

Jump to

Keyboard shortcuts

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