Documentation
¶
Overview ¶
Package crypto ...
Index ¶
- Constants
- Variables
- func BLSThresholdKeyGen(size int, threshold int, seed []byte) ([]PrivateKey, []PublicKey, PublicKey, error)
- func BLSVerifyPOP(pk PublicKey, s Signature) (bool, error)
- func BatchVerifyBLSSignaturesOneMessage(pks []PublicKey, sigs []Signature, message []byte, kmac hash.Hasher) ([]bool, error)
- func EnoughShares(threshold int, sharesNumber int) (bool, error)
- func IsBLSAggregateEmptyListError(err error) bool
- func IsBLSSignatureIdentity(s Signature) bool
- func IsDKGFailureError(err error) bool
- func IsDKGInvalidStateTransitionError(err error) bool
- func IsDuplicatedSignerError(err error) bool
- func IsInvalidHasherSizeError(err error) bool
- func IsInvalidInputsError(err error) bool
- func IsInvalidSignatureError(err error) bool
- func IsNilHasherError(err error) bool
- func IsNotBLSKeyError(err error) bool
- func IsNotEnoughSharesError(err error) bool
- func NewExpandMsgXOFKMAC128(tag string) hash.Hasher
- func SPOCKVerify(pk1 PublicKey, proof1 Signature, pk2 PublicKey, proof2 Signature) (bool, error)
- func SPOCKVerifyAgainstData(pk PublicKey, proof Signature, data []byte, kmac hash.Hasher) (bool, error)
- func SignatureFormatCheck(algo SigningAlgorithm, s Signature) (bool, error)
- func TestHasherErrors(t *testing.T)
- func TestKeyGenErrors(t *testing.T)
- func VerifyBLSSignatureManyMessages(pks []PublicKey, s Signature, messages [][]byte, kmac []hash.Hasher) (bool, error)
- func VerifyBLSSignatureOneMessage(pks []PublicKey, s Signature, message []byte, kmac hash.Hasher) (bool, error)
- type DKGProcessor
- type DKGState
- func NewFeldmanVSS(size int, threshold int, myIndex int, processor DKGProcessor, dealerIndex int) (DKGState, error)
- func NewFeldmanVSSQual(size int, threshold int, myIndex int, processor DKGProcessor, dealerIndex int) (DKGState, error)
- func NewJointFeldman(size int, threshold int, myIndex int, processor DKGProcessor) (DKGState, error)
- type PrivateKey
- type PublicKey
- func AggregateBLSPublicKeys(keys []PublicKey) (PublicKey, error)
- func DecodePublicKey(algo SigningAlgorithm, data []byte) (PublicKey, error)
- func DecodePublicKeyCompressed(algo SigningAlgorithm, data []byte) (PublicKey, error)
- func IdentityBLSPublicKey() PublicKey
- func RemoveBLSPublicKeys(aggKey PublicKey, keysToRemove []PublicKey) (PublicKey, error)
- type Signature
- func AggregateBLSSignatures(sigs []Signature) (Signature, error)
- func BLSGeneratePOP(sk PrivateKey) (Signature, error)
- func BLSInvalidSignature() Signature
- func BLSReconstructThresholdSignature(size int, threshold int, shares []Signature, signers []int) (Signature, error)
- func SPOCKProve(sk PrivateKey, data []byte, kmac hash.Hasher) (Signature, error)
- type SigningAlgorithm
- type ThresholdSignatureInspector
- type ThresholdSignatureParticipant
Constants ¶
const ( // keygen seed length conditions // enforce seed to be at least double the security bits and have enough entropy. // it is still recommened that seed is generated using a secure RNG. KeyGenSeedMinLen = 2 * (securityBits / 8) KeyGenSeedMaxLen = 256 )
const ( // MinimumThreshold is the minimum value of the threshold parameter in all threshold-based protocols. MinimumThreshold = 1 // DKGMinSize is the minimum size of a group participating in a DKG protocol DKGMinSize int = MinimumThreshold + 1 // DKGMaxSize is the maximum size of a group participating in a DKG protocol DKGMaxSize int = 254 // SeedMinLenDKG is the minumum seed length required to participate in a DKG protocol SeedMinLenDKG = securityBits / 8 SeedMaxLenDKG = maxRelicPrgSeed )
const ( // NIST P256 SignatureLenECDSAP256 = 64 PrKeyLenECDSAP256 = 32 // PubKeyLenECDSAP256 is the size of uncompressed points on P256 PubKeyLenECDSAP256 = 64 // SECG secp256k1 SignatureLenECDSASecp256k1 = 64 PrKeyLenECDSASecp256k1 = 32 // PubKeyLenECDSASecp256k1 is the size of uncompressed points on secp256k1 PubKeyLenECDSASecp256k1 = 64 )
const ( // ThresholdSignMinSize is the minimum size of a group participating in a threshold signature protocol ThresholdSignMinSize = MinimumThreshold + 1 // ThresholdSignMaxSize is the maximum size of a group participating in a threshold signature protocol ThresholdSignMaxSize = DKGMaxSize )
const (
SignatureLenBLSBLS12381 = 48
)
Variables ¶
var BLS12381Order = []byte{0x73, 0xED, 0xA7, 0x53, 0x29, 0x9D, 0x7D, 0x48, 0x33, 0x39,
0xD8, 0x08, 0x09, 0xA1, 0xD8, 0x05, 0x53, 0xBD, 0xA4, 0x02, 0xFF, 0xFE,
0x5B, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01}
Functions ¶
func BLSThresholdKeyGen ¶
func IsBLSSignatureIdentity ¶
func IsDKGFailureError ¶
IsDKGFailureError checks if the input error is of a dkgFailureError type. dkgFailureError is an error returned when a participant detects a failure in the protocol and is not able to compute output keys.
func IsDKGInvalidStateTransitionError ¶
IsDkgInvalidStateTransitionError checks if the input error is of a dkgInvalidStateTransition type. invalidStateTransition is returned when a caller triggers an invalid state transition in the local DKG instance. Such a failure can only happen if the API is misued by not respecting the state machine conditions.
func IsDuplicatedSignerError ¶
IsDuplicatedSignerError checks if the input error is a duplicatedSignerError
func IsInvalidHasherSizeError ¶
IsInvalidHasherSizeError checks if the input error is of an invalidHasherSizeError type. invalidHasherSizeError is an error returned when a crypto API is called with a hasher with an output size not suited with the cryptographic operation.
func IsInvalidInputsError ¶
IsInvalidInputsError checks if the input error is of an invalidInputsError type invalidInputsError is returned when the API is provided invalid inputs. Some specific errors are assigned specific sentinel errors for a simpler error check while the remaining input errors trigger an invalidInputsError.
func IsInvalidSignatureError ¶
func IsNilHasherError ¶
IsNilHasherError checks if the input error wraps a nilHasherError. nilHasherError is returned when a nil hasher is used.
func IsNotBLSKeyError ¶
func IsNotEnoughSharesError ¶
IsNotEnoughSharesError checks if the input error is a notEnoughSharesError
func SPOCKVerify ¶
func SPOCKVerifyAgainstData ¶
func SignatureFormatCheck ¶
func SignatureFormatCheck(algo SigningAlgorithm, s Signature) (bool, error)
SignatureFormatCheck verifies the format of a serialized signature, regardless of messages or public keys.
This function is only defined for ECDSA algos for now.
If SignatureFormatCheck returns false then the input is not a valid signature and will fail a verification against any message and public key.
func TestHasherErrors ¶
func TestKeyGenErrors ¶
Types ¶
type DKGProcessor ¶
type DKGProcessor interface { // PrivateSend sends a message to a destination over // a private channel. The channel must preserve the // confidentiality of the message and should authenticate // the sender. // It is recommended that the private channel is unique per // protocol instance. This can be achieved by prepending all // messages by a unique instance ID. PrivateSend(dest int, data []byte) // Broadcast broadcasts a message to all participants. // This function assumes all participants have received the same message, // failing to do so, the protocol can be broken. // The broadcasted message is public and not confidential. // The broadcasting channel should authenticate the sender. // It is recommended that the broadcasting channel is unique per // protocol instance. This can be achieved by prepending all // messages by a unique instance ID. Broadcast(data []byte) // Disqualify flags that a participant is misbehaving and that it got // disqualified from the protocol. Such behavior deserves // disqualifying as it is flagged to all honest participants in // the protocol. // log describes the disqualification reason. Disqualify(participant int, log string) // FlagMisbehavior warns that a participant is misbehaving. // Such behavior is not necessarily flagged to all participants and therefore // the participant is not disqualified from the protocol. Other mechanisms // outside DKG could be implemented to synchronize slashing the misbehaving // participant by all participating participants, using the api `ForceDisqualify`. Failing to // do so, the protocol can be broken. // log describes the misbehavior. FlagMisbehavior(participant int, log string) }
DKGProcessor is an interface that implements the DKG output actions.
An instance of a DKGProcessor is needed for each participant in order to particpate in a DKG protocol
type DKGState ¶
type DKGState interface { // Size returns the size of the DKG group n Size() int // Threshold returns the threshold value t Threshold() int // Start starts running a DKG in the current participant Start(seed []byte) error // HandleBroadcastMsg processes a new broadcasted message received by the current participant. // orig is the message origin index HandleBroadcastMsg(orig int, msg []byte) error // HandlePrivateMsg processes a new private message received by the current participant. // orig is the message origin index HandlePrivateMsg(orig int, msg []byte) error // End ends a DKG protocol in the current participant. // It returns the finalized public data and participant private key share. // - the group public key corresponding to the group secret key // - all the public key shares corresponding to the participants private // key shares // - the finalized private key which is the current participant's own private key share End() (PrivateKey, PublicKey, []PublicKey, error) // NextTimeout set the next timeout of the protocol if any timeout applies. // Some protocols could require more than one timeout NextTimeout() error // Running returns the running state of the DKG protocol Running() bool // ForceDisqualify forces a participant to get disqualified // for a reason outside of the DKG protocol. // The caller should make sure all honest participants call this function, // otherwise, the protocol can be broken. ForceDisqualify(participant int) error }
func NewFeldmanVSS ¶
func NewFeldmanVSS(size int, threshold int, myIndex int, processor DKGProcessor, dealerIndex int) (DKGState, error)
dkg.go functions
func NewFeldmanVSSQual ¶
func NewJointFeldman ¶
type PrivateKey ¶
type PrivateKey interface { // Algorithm returns the signing algorithm related to the private key. Algorithm() SigningAlgorithm // Size return the key size in bytes. Size() int // String return a hex representation of the key String() string // Sign generates a signature using the provided hasher. Sign([]byte, hash.Hasher) (Signature, error) // PublicKey returns the public key. PublicKey() PublicKey // Encode returns a bytes representation of the private key Encode() []byte // Equals returns true if the given PrivateKeys are equal. Keys are considered unequal if their algorithms are // unequal or if their encoded representations are unequal. If the encoding of either key fails, they are considered // unequal as well. Equals(PrivateKey) bool }
PrivateKey is an unspecified signature scheme private key
func AggregateBLSPrivateKeys ¶
func AggregateBLSPrivateKeys(keys []PrivateKey) (PrivateKey, error)
func DecodePrivateKey ¶
func DecodePrivateKey(algo SigningAlgorithm, data []byte) (PrivateKey, error)
DecodePrivateKey decodes an array of bytes into a private key of the given algorithm
The function returns:
- (nil, invalidInputsErrors) if the signing algorithm is not supported
- (nil, invalidInputsErrors) if the input does not serialize a valid private key:
- ECDSA: bytes(x) where bytes() is the big-endian encoding padded to the curve order.
- BLS: bytes(x) where bytes() is the big-endian encoding padded to the order of BLS12-381. for all algorithms supported, input is big-endian encoding of a the private scalar less than the curve order and left-padded to 32 bytes
- (nil, error) if an unexpected error occurs
- (sk, nil) otherwise
func GeneratePrivateKey ¶
func GeneratePrivateKey(algo SigningAlgorithm, seed []byte) (PrivateKey, error)
GeneratePrivateKey generates a private key of the algorithm using the entropy of the given seed.
The seed minimum length is 32 bytes and it should have enough entropy. It is recommended to use a secure crypto RNG to generate the seed.
The function returns:
- (false, invalidInputsErrors) if the signing algorithm is not supported or if the seed length is not valid (less than 32 bytes or larger than 256 bytes)
- (false, error) if an unexpected error occurs
- (sk, nil) if key generation was successful
type PublicKey ¶
type PublicKey interface { // Algorithm returns the signing algorithm related to the public key. Algorithm() SigningAlgorithm // Size() return the key size in bytes. Size() int // String return a hex representation of the key String() string // Verify verifies a signature of an input message using the provided hasher. Verify(Signature, []byte, hash.Hasher) (bool, error) // Encode returns a bytes representation of the public key. Encode() []byte // EncodeCompressed returns a compressed byte representation of the public key. // The compressed serialization concept is generic to elliptic curves, // but we refer to individual curve parameters for details of the compressed format EncodeCompressed() []byte // Equals returns true if the given PublicKeys are equal. Keys are considered unequal if their algorithms are // unequal or if their encoded representations are unequal. If the encoding of either key fails, they are considered // unequal as well. Equals(PublicKey) bool }
PublicKey is an unspecified signature scheme public key.
func AggregateBLSPublicKeys ¶
func DecodePublicKey ¶
func DecodePublicKey(algo SigningAlgorithm, data []byte) (PublicKey, error)
DecodePublicKey decodes an array of bytes into a public key of the given algorithm
The function returns:
- (nil, invalidInputsErrors) if the signing algorithm is not supported
- (nil, invalidInputsErrors) if the input does not serialize a valid public key:
- ECDSA: bytes(x)||bytes(y) where bytes() is the big-endian encoding padded to the field size.
- BLS: compressed serialization of a G2 point following https://www.ietf.org/archive/id/draft-irtf-cfrg-pairing-friendly-curves-08.html#name-zcash-serialization-format-
- (nil, error) if an unexpected error occurs
- (sk, nil) otherwise
func DecodePublicKeyCompressed ¶
func DecodePublicKeyCompressed(algo SigningAlgorithm, data []byte) (PublicKey, error)
DecodePublicKeyCompressed decodes an array of bytes given in a compressed representation into a public key of the given algorithm Only ECDSA is supported (BLS uses the compressed serialzation by default).
The function returns:
- (nil, invalidInputsErrors) if the signing algorithm is not supported (is not ECDSA)
- (nil, invalidInputsErrors) if the input does not serialize a valid public key:
- ECDSA: sign_byte||bytes(x) according to X9.62 section 4.3.6.
- (nil, error) if an unexpected error occurs
- (sk, nil) otherwise
func IdentityBLSPublicKey ¶
func IdentityBLSPublicKey() PublicKey
type Signature ¶
type Signature []byte
Signature is a generic type, regardless of the signature scheme
func AggregateBLSSignatures ¶
func BLSGeneratePOP ¶
func BLSGeneratePOP(sk PrivateKey) (Signature, error)
bls_multisig.go functions
func BLSInvalidSignature ¶
func BLSInvalidSignature() Signature
func SPOCKProve ¶
type SigningAlgorithm ¶
type SigningAlgorithm int
SigningAlgorithm is an identifier for a signing algorithm (and parameters if applicable)
const ( // Supported signing algorithms UnknownSigningAlgorithm SigningAlgorithm = iota // BLSBLS12381 is BLS on BLS 12-381 curve BLSBLS12381 // ECDSAP256 is ECDSA on NIST P-256 curve ECDSAP256 // ECDSASecp256k1 is ECDSA on secp256k1 curve ECDSASecp256k1 )
func (SigningAlgorithm) String ¶
func (f SigningAlgorithm) String() string
String returns the string representation of this signing algorithm.
type ThresholdSignatureInspector ¶
type ThresholdSignatureInspector interface { // key at the input index. This function does not update the internal state. // The function is thread-safe. // Returns: // - (true, nil) if the signature is valid // - (false, nil) if `orig` is a valid index but the signature share is invalid // - (false, InvalidInputsError) if `orig` is an invalid index value // - (false, error) for all other unexpected errors VerifyShare(orig int, share Signature) (bool, error) // VerifyThresholdSignature verifies the input signature against the stored // message and stored group public key. It does not update the internal state. // The function is thread-safe. // Returns: // - (true, nil) if the signature is valid // - (false, nil) if the signature is invalid // - (false, error) for all other unexpected errors VerifyThresholdSignature(thresholdSignature Signature) (bool, error) // a group signature. This function is thread safe and locks the internal state. // Returns: // - true if and only if at least (threshold+1) shares were added EnoughShares() bool // TrustedAdd adds a signature share to the internal pool of shares // without verifying the signature against the message and the participant's // public key. This function is thread safe and locks the internal state. // // The share is only added if the signer index is valid and has not been // added yet. Moreover, the share is added only if not enough shares were collected. // The function returns: // - (true, nil) if enough signature shares were already collected and no error occurred // - (false, nil) if not enough shares were collected and no error occurred // - (false, InvalidInputsError) if index is invalid // - (false, duplicatedSignerError) if a signature for the index was previously added TrustedAdd(orig int, share Signature) (bool, error) // VerifyAndAdd verifies a signature share (same as `VerifyShare`), // and may or may not add the share to the local pool of shares. // This function is thread safe and locks the internal state. // // The share is only added if the signature is valid, the signer index is valid and has not been // added yet. Moreover, the share is added only if not enough shares were collected. // Boolean returns: // - First boolean output is true if the share is valid and no error is returned, and false otherwise. // - Second boolean output is true if enough shares were collected and no error is returned, and false otherwise. // Error returns: // - invalidInputsError if input index is invalid. A signature that doesn't verify against the signer's // public key is not considered an invalid input. // - duplicatedSignerError if signer was already added. // - other errors if an unexpected exception occurred. VerifyAndAdd(orig int, share Signature) (bool, bool, error) // This function is thread safe. // The function errors with InvalidInputsError if the index is invalid. HasShare(orig int) (bool, error) // ThresholdSignature returns the threshold signature if the threshold was reached. // The threshold signature is reconstructed only once and is cached for subsequent calls. // // Returns: // - (signature, nil) if no error occurred // - (nil, notEnoughSharesError) if not enough shares were collected // - (nil, invalidSignatureError) if at least one collected share does not serialize to a valid BLS signature. // - (nil, invalidInputsError) if the constructed signature failed to verify against the group public key and stored message. This post-verification // is required for safety, as `TrustedAdd` allows adding invalid signatures. // - (nil, error) for any other unexpected error. ThresholdSignature() (Signature, error) }
ThresholdSignatureInspector is an inspector of the threshold signature protocol. The interface only allows inspecting the threshold signing protocol without taking part in it.
type ThresholdSignatureParticipant ¶
type ThresholdSignatureParticipant interface { ThresholdSignatureInspector // // The function does not add the share to the internal pool of shares and do // not update the internal state. // This function is thread safe // No error is expected unless an unexpected exception occurs SignShare() (Signature, error) }
ThresholdSignatureParticipant is a participant in a threshold signature protocol. A participant is able to participate in a threshold signing protocol as well as inspecting the protocol.
func NewBLSThresholdSignatureParticipant ¶
func NewBLSThresholdSignatureParticipant( groupPublicKey PublicKey, sharePublicKeys []PublicKey, threshold int, myIndex int, myPrivateKey PrivateKey, message []byte, dsTag string, ) (ThresholdSignatureParticipant, error)
bls_threshold.go functions