crypto

package
v0.0.0-...-6fdbc3c Latest Latest
Warning

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

Go to latest
Published: May 23, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// BlockSize for aes256-gcm is 32 bytes
	BlockSize = (1 << 5)

	// ScryptN is the CPU/memory cost parameter for Scrypt
	ScryptN = (1 << 18)

	// ScryptR is the blocksize parameter for Scrypt
	ScryptR = (1 << 3)

	// ScryptP is the parallelization parameter for Scrypt
	ScryptP = 1
)
View Source
const (
	// EdDSA is used to generate ed25519 keys
	EdDSA = 1
)
View Source
const (
	// PublicKeySize is 32 bytes (compressed)
	PublicKeySize = ed25519.PublicKeySize
)

Variables

View Source
var (
	// ErrKeyLen is thrown on an invalid key length
	ErrKeyLen = errors.New("invalid key length")

	// ErrKeyType is thrown on an invalid key type
	ErrKeyType = errors.New("invalid key type")
)

Functions

func Decrypt

func Decrypt(data, password []byte) ([]byte, error)

Decrypt a byte slice

func Encrypt

func Encrypt(data, password []byte) ([]byte, error)

Encrypt a byte slice

func ValidEdDSA

func ValidEdDSA(pubkey []byte) bool

ValidEdDSA checks for a valid ed25519 pubkey

Types

type Cipher

type Cipher struct {
	Payload []byte `json:"payload"`
	IV      []byte `json:"iv"`
	Salt    []byte `json:"salt"`
	Nonce   []byte `json:"nonce"`
	N       int    `json:"n"`
	R       int    `json:"r"`
	P       int    `json:"p"`
}

Cipher wraps an aes256-gcm block cipher with scrypt for key derivation

func (*Cipher) Decrypt

func (c *Cipher) Decrypt(password []byte) ([]byte, error)

Decrypt a byte slice with aes256-gcm

func (*Cipher) Encrypt

func (c *Cipher) Encrypt(data, password []byte) error

Encrypt a byte slice with aes256-gcm

func (*Cipher) KDF

func (c *Cipher) KDF(password []byte) (dk []byte, err error)

KDF runs Scrypt with standard params by default See https://www.tarsnap.com/scrypt/scrypt.pdf

type KeyPair

type KeyPair struct {
	T    KeyType `json:"type"`
	Pub  []byte  `json:"pub"`
	Priv []byte  `json:"priv"`
}

KeyPair represents a generic key pair

func EdDSAGen

func EdDSAGen() (*KeyPair, error)

EdDSAGen generates an ed25519 key pair

func (*KeyPair) Decrypt

func (k *KeyPair) Decrypt(payload, password []byte) (err error)

Decrypt an encrypted key pair

func (*KeyPair) Encrypt

func (k *KeyPair) Encrypt(password []byte) ([]byte, error)

Encrypt a key pair

func (*KeyPair) FromSeed

func (k *KeyPair) FromSeed(priv []byte) (err error)

FromSeed initializes a key pair from a 32 byte seed

func (*KeyPair) Gen

func (k *KeyPair) Gen() (err error)

Gen generates a fresh key pair

type KeyType

type KeyType uint16

KeyType is used to specify a signing algorithm

Jump to

Keyboard shortcuts

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