crypto

package
v0.0.0-...-77dcbbd Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package crypto provides crypto related utility functions.

It supports ed25519, BLS for signature scheme, sha256 for hash, argon2id and pbkdf2 for encryption.

Index

Constants

View Source
const (
	BLSPublicKeyLength = 48
	BLSSignatureLength = 96
)
View Source
const (
	// PBKDF2Iterations is default iteration for KDF.
	PBKDF2Iterations = 1000000
	// PBKDF2Iterations is default key length.
	PBKDF2KeyLen       = 32
	HashLengh          = 32
	EdPublicKeyLength  = 32
	EdPrivateKeyLength = 64
	EdSignatureLength  = 64
)
View Source
const (
	CipherAES256GCM = "aes-256-gcm"
	KDFArgon2ID     = "argon2id"
)

Variables

This section is empty.

Functions

func BLSCreateAggSig

func BLSCreateAggSig(keysList [][]byte, pubKeySignaturePairs []*BLSPublicKeySignaturePair) ([]byte, []byte)

func BLSPopProve

func BLSPopProve(privateKey []byte) []byte

func BLSPopVerify

func BLSPopVerify(publicKey, proof []byte) bool

func BLSSKToPK

func BLSSKToPK(privateKey []byte) []byte

func BLSSign

func BLSSign(msg []byte, privateKey []byte) []byte

func BLSVerify

func BLSVerify(msg, signature, publicKey []byte) bool

func BLSVerifyAggSig

func BLSVerifyAggSig(keysList [][]byte, aggregationBits []byte, signature []byte, message []byte) bool

func BLSVerifyWeightedAggSig

func BLSVerifyWeightedAggSig(keysList [][]byte, aggregationBits []byte, signature []byte, weights []uint64, threshold uint64, message []byte) bool

func DecryptMessageWithPassword

func DecryptMessageWithPassword(encryptedMessage *EncryptedMessage, password string) ([]byte, error)

func DecryptPassphraseWithPassword

func DecryptPassphraseWithPassword(encryptedPassphrase *EncryptedPassphrase, password string) (string, error)

func DeriveBLSKey

func DeriveBLSKey(recoveryPhrase, path string) ([]byte, error)

func DeriveEd25519Key

func DeriveEd25519Key(recoveryPhrase, path string) ([]byte, error)

func GetAddress

func GetAddress(publicKey []byte) []byte

func GetEdPublicKey

func GetEdPublicKey(privateKey []byte) []byte

func GetHashOnionSeed

func GetHashOnionSeed() []byte

func GetKeys

func GetKeys(passphrase string) ([]byte, []byte, error)

func Hash

func Hash(key []byte) []byte

func HashOnion

func HashOnion(seed []byte, count int, distance int) [][]byte

func RandomBytes

func RandomBytes(size int) []byte

func Sign

func Sign(privateKey []byte, message []byte) []byte

func VerifySignature

func VerifySignature(publicKey, signature []byte, message []byte) error

Types

type BLSAggregatePublicKey

type BLSAggregatePublicKey = blst.P1Aggregate

type BLSAggregateSignature

type BLSAggregateSignature = blst.P2Aggregate

type BLSKeyPair

type BLSKeyPair struct {
	PublicKey  []byte
	PrivateKey []byte
}

BLSKeyPair is a container for a BLS Keypair.

func BLSKeyGen

func BLSKeyGen(passphrase []byte) *BLSKeyPair

BLSKeyGen generates a BLSKeyPair from the passphrase provided.

func BLSRandomKeyGen

func BLSRandomKeyGen() *BLSKeyPair

BLSRandomKeyGen returns a random BLSKeyPair.

type BLSPublicKey

type BLSPublicKey = blst.P1Affine

type BLSPublicKeySignaturePair

type BLSPublicKeySignaturePair struct {
	PublicKey []byte
	Signature []byte
}

type BLSSecretKey

type BLSSecretKey = blst.SecretKey

type BLSSignature

type BLSSignature = blst.P2Affine

type Bits

type Bits []byte

type CipherParams

type CipherParams struct {
	IV  codec.Hex `json:"iv" fieldNumber:"1"`
	Tag codec.Hex `json:"tag" fieldNumber:"2"`
}

func (*CipherParams) Decode

func (e *CipherParams) Decode(data []byte) error

func (*CipherParams) DecodeFromReader

func (e *CipherParams) DecodeFromReader(reader *codec.Reader) error

func (*CipherParams) DecodeStrict

func (e *CipherParams) DecodeStrict(data []byte) error

func (*CipherParams) DecodeStrictFromReader

func (e *CipherParams) DecodeStrictFromReader(reader *codec.Reader) error

func (*CipherParams) Encode

func (e *CipherParams) Encode() []byte

func (*CipherParams) MustDecode

func (e *CipherParams) MustDecode(data []byte)

func (CipherParams) String

func (e CipherParams) String() string

func (CipherParams) Validate

func (e CipherParams) Validate() error

type EncryptOptions

type EncryptOptions struct {
	KDF         string
	Parallelism uint8
	Iterations  uint32
	MemorySize  uint32
}

func DefaultEncryptOptions

func DefaultEncryptOptions() *EncryptOptions

type EncryptedMessage

type EncryptedMessage struct {
	Version      string        `json:"version" fieldNumber:"1"`
	CipherText   codec.Hex     `json:"cipherText" fieldNumber:"2"`
	Mac          codec.Hex     `json:"mac" fieldNumber:"3"`
	KDF          string        `json:"kdf" fieldNumber:"4"`
	KDFParams    *KDFParams    `json:"kdfparams" fieldNumber:"5"`
	Cipher       string        `json:"cipher" fieldNumber:"6"`
	CipherParams *CipherParams `json:"cipherparams" fieldNumber:"7"`
}

func EncryptMessageWithPassword

func EncryptMessageWithPassword(message []byte, password string, options *EncryptOptions) (*EncryptedMessage, error)

func (*EncryptedMessage) Decode

func (e *EncryptedMessage) Decode(data []byte) error

func (*EncryptedMessage) DecodeFromReader

func (e *EncryptedMessage) DecodeFromReader(reader *codec.Reader) error

func (*EncryptedMessage) DecodeStrict

func (e *EncryptedMessage) DecodeStrict(data []byte) error

func (*EncryptedMessage) DecodeStrictFromReader

func (e *EncryptedMessage) DecodeStrictFromReader(reader *codec.Reader) error

func (*EncryptedMessage) Encode

func (e *EncryptedMessage) Encode() []byte

func (*EncryptedMessage) MustDecode

func (e *EncryptedMessage) MustDecode(data []byte)

func (EncryptedMessage) String

func (e EncryptedMessage) String() string

func (EncryptedMessage) Validate

func (e EncryptedMessage) Validate() error

type EncryptedPassphrase

type EncryptedPassphrase struct {
	Iterations int
	Salt       string
	CipherText string
	IV         string
	Tag        string
	Version    string
}

func EncryptPassphraseWithPassword

func EncryptPassphraseWithPassword(passphrase, password string, iteration int) (*EncryptedPassphrase, error)

func ParseEncryptedPassphrase

func ParseEncryptedPassphrase(encryptedPassphrase string) (*EncryptedPassphrase, error)

func (EncryptedPassphrase) String

func (ep EncryptedPassphrase) String() string

type KDFParams

type KDFParams struct {
	Parallelism uint32    `json:"parallelism" fieldNumber:"1"`
	Iterations  uint32    `json:"iterations" fieldNumber:"2"`
	MemorySize  uint32    `json:"memorySize" fieldNumber:"3"`
	Salt        codec.Hex `json:"salt" fieldNumber:"4"`
}

func (*KDFParams) Decode

func (e *KDFParams) Decode(data []byte) error

func (*KDFParams) DecodeFromReader

func (e *KDFParams) DecodeFromReader(reader *codec.Reader) error

func (*KDFParams) DecodeStrict

func (e *KDFParams) DecodeStrict(data []byte) error

func (*KDFParams) DecodeStrictFromReader

func (e *KDFParams) DecodeStrictFromReader(reader *codec.Reader) error

func (*KDFParams) Encode

func (e *KDFParams) Encode() []byte

func (*KDFParams) MustDecode

func (e *KDFParams) MustDecode(data []byte)

func (KDFParams) String

func (e KDFParams) String() string

func (KDFParams) Validate

func (e KDFParams) Validate() error

Jump to

Keyboard shortcuts

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