crypto

package
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2021 License: GPL-3.0 Imports: 3 Imported by: 0

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 ErrBitmapMismatch = errors.New("multi signer reported a mismatch in used bitmap")

ErrBitmapMismatch is raised when an invalid bitmap is passed to the multisigner

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

ErrEd25519InvalidSignature will be returned when ed25519 signature verification fails

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

ErrEmptyPubKeyString is raised when an empty public key string is used

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 ErrIndexNotSelected = errors.New("index is not selected")

ErrIndexNotSelected is raised when a not selected index is used for multi-signing

View Source
var ErrIndexOutOfBounds = errors.New("index is out of bounds")

ErrIndexOutOfBounds is raised when an out of bound index is used

View Source
var ErrInvalidPID = errors.New("invalid PID")

ErrInvalidPID signals that given PID is invalid

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 ErrInvalidPublicKeyString = errors.New("invalid public key string")

ErrInvalidPublicKeyString is raised when an invalid serialization for a 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 ErrInvalidSignature = errors.New("invalid signature")

ErrInvalidSignature signals that the given signature is invalid

View Source
var ErrInvalidSigner = errors.New("signer is invalid")

ErrInvalidSigner is raised when the signer is invalid

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

ErrInvalidSuite is raised when an invalid crypto suite is used

View Source
var ErrNilBitmap = errors.New("bitmap is nil")

ErrNilBitmap is raised when a nil bitmap is used

View Source
var ErrNilCacher = errors.New("nil cacher")

ErrNilCacher signals that a nil cacher has been provided

View Source
var ErrNilElement = errors.New("element is nil")

ErrNilElement is raised when searching for a specific element but found nil

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 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 ErrNilSingleSigner = errors.New("singleSigner is nil")

ErrNilSingleSigner is raised when a valid singleSigner is expected but nil used

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

ErrNilSuite is raised when a nil crypto suite is used

View Source
var ErrNoPublicKeySet = errors.New("no public key was set")

ErrNoPublicKeySet is raised when no public key was set for a multisignature

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

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

View Source
var ErrPIDMismatch = errors.New("pid mismatch")

ErrPIDMismatch signals that the pid from the message is different from the cached pid associated to a certain pk

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

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

View Source
var ErrSignatureMismatch = errors.New("signature mismatch")

ErrSignatureMismatch signals that the signature from the message is different from the cached signature associated to a certain pk

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

View Source
var ErrWrongTypeAssertion = errors.New("wrong type assertion")

ErrWrongTypeAssertion signals wrong type assertion

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
}

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 {
	// Create resets the multisigner and initializes to the new params
	Create(pubKeys []string, index uint16) (MultiSigner, error)
	// SetAggregatedSig sets the aggregated signature
	SetAggregatedSig([]byte) error
	// Verify verifies the aggregated signature
	Verify(msg []byte, bitmap []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
	// Reset resets the data holder inside the multiSigner
	Reset(pubKeys []string, index uint16) error
	// CreateSignatureShare creates a partial signature
	CreateSignatureShare(msg []byte, bitmap []byte) ([]byte, error)
	// StoreSignatureShare adds the partial signature of the signer with specified position
	StoreSignatureShare(index uint16, sig []byte) error
	// SignatureShare returns the partial signature set for given index
	SignatureShare(index uint16) ([]byte, error)
	// VerifySignatureShare verifies the partial signature of the signer with specified position
	VerifySignatureShare(index uint16, sig []byte, msg []byte, bitmap []byte) error
	// AggregateSigs aggregates all collected partial signatures
	AggregateSigs(bitmap []byte) ([]byte, error)
}

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

type PeerSignatureHandler added in v1.0.138

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