crypto

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2024 License: GPL-3.0 Imports: 3 Imported by: 8

README

drt-chain-crypto-go

drt-chain crypto packages and high level definitions

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAggSigNotValid = errors.New("aggregate signature is invalid")

ErrAggSigNotValid is raised when an aggregate signature is invalid

View Source
var ErrBLSInvalidSignature = errors.New("bls12-381: invalid signature")

ErrBLSInvalidSignature will be returned when the provided BLS signature is invalid

View Source
var ErrEd25519InvalidSignature = errors.New("ed25519: invalid signature")

ErrEd25519InvalidSignature will be returned when ed25519 signature verification fails

View Source
var ErrEmptyPubKey = errors.New("public key is empty")

ErrEmptyPubKey is raised when an empty public key is used

View Source
var ErrFailedAuthentication = errors.New("failed authentication for given ciphertext")

ErrFailedAuthentication is returned when a ciphertext could not be decrypted by a given private key

View Source
var ErrGeneratingPubFromPriv = errors.New("unable to generate PublicKey from provided private key")

ErrGeneratingPubFromPriv signals that there was an error generating a public key corresponding to a provided private key

View Source
var ErrInvalidParam = errors.New("parameter is invalid")

ErrInvalidParam is raised for invalid parameters

View Source
var ErrInvalidPoint = errors.New("point is invalid")

ErrInvalidPoint is raised when an invalid point is used

View Source
var ErrInvalidPrivateKey = errors.New("private key is invalid")

ErrInvalidPrivateKey is raised when an invalid private key is used

View Source
var ErrInvalidPublicKey = errors.New("public key is invalid")

ErrInvalidPublicKey is raised when an invalid public key is used

View Source
var ErrInvalidScalar = errors.New("scalar is invalid")

ErrInvalidScalar is raised when an invalid scalar is used

View Source
var ErrInvalidSuite = errors.New("crypto suite is invalid")

ErrInvalidSuite is raised when an invalid crypto suite is used

View Source
var ErrNilHasher = errors.New("hasher is nil")

ErrNilHasher is raised when a valid hasher is expected but used nil

View Source
var ErrNilKeyGenerator = errors.New("key generator is nil")

ErrNilKeyGenerator is raised when a valid key generator is expected but nil used

View Source
var ErrNilLowLevelSigner = errors.New("nil low level signer")

ErrNilLowLevelSigner signals a nil low level signer

View Source
var ErrNilMessage = errors.New("message to be signed or to be verified is nil")

ErrNilMessage is raised when trying to verify a nil signed message or trying to sign a nil message

View Source
var ErrNilParam = errors.New("nil parameter")

ErrNilParam is raised for nil parameters

View Source
var ErrNilPrivateKey = errors.New("private key is nil")

ErrNilPrivateKey is raised when a private key was expected but received nil

View Source
var ErrNilPrivateKeyScalar = errors.New("private key holds a nil scalar")

ErrNilPrivateKeyScalar is raised when a private key with nil scalar is used

View Source
var ErrNilPublicKey = errors.New("public key is nil")

ErrNilPublicKey is raised when public key is expected but received nil

View Source
var ErrNilPublicKeyPoint = errors.New("public key holds a nil point")

ErrNilPublicKeyPoint is raised when a public key with nil point is used

View Source
var ErrNilPublicKeys = errors.New("public keys are nil")

ErrNilPublicKeys is raised when public keys are expected but received nil

View Source
var ErrNilSignature = errors.New("signature is nil")

ErrNilSignature is raised for a nil signature

View Source
var ErrNilSignaturesList = errors.New("signature list is nil")

ErrNilSignaturesList is raised when a nil list of signatures is provided

View Source
var ErrNilSuite = errors.New("crypto suite is nil")

ErrNilSuite is raised when a nil crypto suite is used

View Source
var ErrNotImplemented = errors.New("not implemented")

ErrNotImplemented signals that a method is not implemented for an interface implementation

View Source
var ErrSigNotValid = errors.New("signature is invalid")

ErrSigNotValid is raised when a signature verification fails due to invalid signature

View Source
var ErrWrongPrivateKeySize = errors.New("wrong private key size")

ErrWrongPrivateKeySize signals that the length of the provided private key is not the expected one

View Source
var ErrWrongPrivateKeyStructure = errors.New("wrong private key structure")

ErrWrongPrivateKeyStructure signals that the structure of the private key is incorrect

View Source
var ErrWrongSizeHasher = errors.New("wrong size hasher")

ErrWrongSizeHasher is raised when a hasher with a wrong output size is used

Functions

This section is empty.

Types

type Group

type Group interface {
	// String returns the string for the group
	String() string
	// ScalarLen returns the maximum length of scalars in bytes
	ScalarLen() int
	// CreateScalar creates a new Scalar
	CreateScalar() Scalar
	// PointLen returns the max length of point in nb of bytes
	PointLen() int
	// CreatePoint creates a new point
	CreatePoint() Point
	// CreatePointForScalar creates a new point corresponding to the given scalar
	CreatePointForScalar(scalar Scalar) (Point, error)
	// IsInterfaceNil returns true if there is no value under the interface
	IsInterfaceNil() bool
}

Group defines a mathematical group used for Diffie-Hellmann operations

type Key

type Key interface {
	// ToByteArray returns the byte array representation of the key
	ToByteArray() ([]byte, error)
	// Suite returns the suite used by this key
	Suite() Suite
	// IsInterfaceNil returns true if there is no value under the interface
	IsInterfaceNil() bool
}

Key represents a crypto key - can be either private or public

type KeyGenerator

type KeyGenerator interface {
	// GeneratePair creates a (crypto.PrivateKey, crypto.PublicKey) pair to be used for asymmetric cryptography
	GeneratePair() (PrivateKey, PublicKey)
	// PrivateKeyFromByteArray creates a crypto.PrivateKey from a byte array
	PrivateKeyFromByteArray(b []byte) (PrivateKey, error)
	// PublicKeyFromByteArray creates a crypto.PublicKey from a byte array
	PublicKeyFromByteArray(b []byte) (PublicKey, error)
	//CheckPublicKeyValid verifies the validity of the public key
	CheckPublicKeyValid(b []byte) error
	// Suite returns the crypto.Suite used by the KeyGenerator
	Suite() Suite
	// IsInterfaceNil returns true if there is no value under the interface
	IsInterfaceNil() bool
}

KeyGenerator is an interface for generating different types of cryptographic keys

type LowLevelSignerBLS

type LowLevelSignerBLS interface {
	// VerifySigShare verifies a BLS single signature
	VerifySigShare(pubKey PublicKey, message []byte, sig []byte) error
	// SignShare creates a BLS single signature over a given message
	SignShare(privKey PrivateKey, message []byte) ([]byte, error)
	// VerifySigBytes verifies if a byte array represents a BLS signature
	VerifySigBytes(suite Suite, sig []byte) error
	// AggregateSignatures aggregates BLS single signatures given as byte arrays
	AggregateSignatures(suite Suite, signatures [][]byte, pubKeysSigners []PublicKey) ([]byte, error)
	// VerifyAggregatedSig verifies the validity of an aggregated signature over a given message
	VerifyAggregatedSig(suite Suite, pubKeys []PublicKey, aggSigBytes []byte, msg []byte) error
	// IsInterfaceNil returns true if there is no value under the interface
	IsInterfaceNil() bool
}

LowLevelSignerBLS provides functionality to sign and verify BLS single/multi-signatures Implementations act as a wrapper over a specific crypto library, such that changing the library requires only writing a new implementation of this LowLevelSigner

type MultiSigVerifier

type MultiSigVerifier interface {
	// VerifyAggregatedSig verifies the aggregated signature
	VerifyAggregatedSig(pubKeysSigners [][]byte, message []byte, aggSig []byte) error
	// IsInterfaceNil returns true if there is no value under the interface
	IsInterfaceNil() bool
}

MultiSigVerifier provides functionality for verifying a multi-signature

type MultiSigner

type MultiSigner interface {
	// MultiSigVerifier Provides functionality for verifying a multi-signature
	MultiSigVerifier
	// CreateSignatureShare creates a partial signature
	CreateSignatureShare(privateKeyBytes []byte, message []byte) ([]byte, error)
	// VerifySignatureShare verifies the partial signature of the signer with specified position
	VerifySignatureShare(publicKey []byte, message []byte, sig []byte) error
	// AggregateSigs aggregates all collected partial signatures
	AggregateSigs(pubKeysSigners [][]byte, signatures [][]byte) ([]byte, error)
}

MultiSigner provides functionality for multi-signing a message and verifying a multi-signed message

type PeerSignatureHandler

type PeerSignatureHandler interface {
	VerifyPeerSignature(pk []byte, pid core.PeerID, signature []byte) error
	GetPeerSignature(key PrivateKey, pid []byte) ([]byte, error)
	IsInterfaceNil() bool
}

PeerSignatureHandler is a wrapper over SingleSigner that buffers the peer signatures. When it needs to sign or to verify a signature, it searches the buffer first.

type Point

type Point interface {
	// MarshalBinary transforms the Point into a byte array
	MarshalBinary() ([]byte, error)
	// UnmarshalBinary recreates the Point from a byte array
	UnmarshalBinary([]byte) error
	// Equal tests if receiver is equal with the Point p given as parameter.
	// Both Points need to be derived from the same Group
	Equal(p Point) (bool, error)
	// Null returns the neutral identity element.
	Null() Point
	// Set sets the receiver equal to another Point p.
	Set(p Point) error
	// Clone returns a clone of the receiver.
	Clone() Point
	// Add returns the result of adding receiver with Point p given as parameter,
	// so that their scalars add homomorphically
	Add(p Point) (Point, error)
	// Sub returns the result of subtracting from receiver the Point p given as parameter,
	// so that their scalars subtract homomorphically
	Sub(p Point) (Point, error)
	// Neg returns the negation of receiver
	Neg() Point
	// Mul returns the result of multiplying receiver by the scalar s.
	Mul(s Scalar) (Point, error)
	// Pick returns a fresh random or pseudo-random Point.
	Pick() (Point, error)
	// GetUnderlyingObj returns the object the implementation wraps
	GetUnderlyingObj() interface{}
	// IsInterfaceNil returns true if there is no value under the interface
	IsInterfaceNil() bool
}

Point represents an element of a public-key cryptographic Group.

type PrivateKey

type PrivateKey interface {
	Key
	// GeneratePublic builds a public key for the current private key
	GeneratePublic() PublicKey
	// Scalar returns the Scalar corresponding to this Private Key
	Scalar() Scalar
}

PrivateKey represents a private key that can sign data or decrypt messages encrypted with a public key

type PublicKey

type PublicKey interface {
	Key
	// Point returns the Point corresponding to this Public Key
	Point() Point
}

PublicKey can be used to encrypt messages

type Random

type Random interface {
	// RandomStream returns a cipher.Stream that produces a
	// cryptographically random key stream. The stream must
	// tolerate being used in multiple goroutines.
	RandomStream() cipher.Stream
}

Random is an interface that can be mixed in to local suite definitions.

type Scalar

type Scalar interface {
	// MarshalBinary transforms the Scalar into a byte array
	MarshalBinary() ([]byte, error)
	// UnmarshalBinary recreates the Scalar from a byte array
	UnmarshalBinary([]byte) error
	// Equal tests if receiver is equal with the scalar s given as parameter.
	// Both scalars need to be derived from the same Group
	Equal(s Scalar) (bool, error)
	// Set sets the receiver to Scalar s given as parameter
	Set(s Scalar) error
	// Clone creates a new Scalar with same value as receiver
	Clone() Scalar
	// SetInt64 sets the receiver to a small integer value v given as parameter
	SetInt64(v int64)
	// Zero returns the the additive identity (0)
	Zero() Scalar
	// Add returns the modular sum of receiver with scalar s given as parameter
	Add(s Scalar) (Scalar, error)
	// Sub returns the modular difference between receiver and scalar s given as parameter
	Sub(s Scalar) (Scalar, error)
	// Neg returns the modular negation of receiver
	Neg() Scalar
	// One returns the multiplicative identity (1)
	One() Scalar
	// Mul returns the modular product of receiver with scalar s given as parameter
	Mul(s Scalar) (Scalar, error)
	// Div returns the modular division between receiver and scalar s given as parameter
	Div(s Scalar) (Scalar, error)
	// Inv returns the modular inverse of scalar s given as parameter
	Inv(s Scalar) (Scalar, error)
	// Pick returns a fresh random or pseudo-random scalar
	Pick() (Scalar, error)
	// SetBytes sets the scalar from a byte-slice,
	// reducing if necessary to the appropriate modulus.
	SetBytes([]byte) (Scalar, error)
	// GetUnderlyingObj returns the object the implementation wraps
	GetUnderlyingObj() interface{}
	// IsInterfaceNil returns true if there is no value under the interface
	IsInterfaceNil() bool
}

A Scalar represents a scalar value by which a Point (group element) may be encrypted to produce another Point.

type SingleSigner

type SingleSigner interface {
	// Sign is used to sign a message
	Sign(private PrivateKey, msg []byte) ([]byte, error)
	// Verify is used to verify a signed message
	Verify(public PublicKey, msg []byte, sig []byte) error
	// IsInterfaceNil returns true if there is no value under the interface
	IsInterfaceNil() bool
}

SingleSigner provides functionality for signing a message and verifying a single signed message

type Suite

type Suite interface {
	Group
	Random
	// CreateKeyPair creates a scalar and a point pair that can be used in asymmetric cryptography
	CreateKeyPair() (Scalar, Point)
	// CheckPointValid returns nil if point is valid otherwise error. Zero is reported also as invalid
	CheckPointValid(pointBytes []byte) error
	// GetUnderlyingSuite returns the library suite that crypto.Suite wraps
	GetUnderlyingSuite() interface{}
}

Suite represents the list of functionalities needed by this package.

Jump to

Keyboard shortcuts

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