mod.rs
Overview
This file defines the primary traits and module structure for a Boneh–Lynn–Shacham (BLS) signature scheme implementation. It declares a generic trait BLSSignatureScheme that abstracts the signing, verification, and signature aggregation operations typical in BLS cryptography. The file also organizes submodules that provide concrete implementations and utilities related to the BLS scheme.
Modules
create_signed: Presumably contains logic to create signed messages or data structures using the BLS scheme.envelope: Likely manages message envelopes or wrappers for signed data, facilitating transport or storage.gosh_bls: Contains theGoshBLSstruct, a concrete implementation of the BLS signature scheme.
The GoshBLS type is publicly re-exported from the gosh_bls module for external use.
BLSSignatureScheme Trait
The BLSSignatureScheme trait defines the interface required for any BLS signature scheme implementation. It is designed to be:
'static: The trait implementors must have a static lifetime.Clone: The types implementing the trait must be cloneable.
Associated Types
PubKey: Represents the public key type. Must implementCloneand Debug.Secret: Represents the secret/private key type. Must implementClone.Signature: Represents the signature type. Must implement:CloneSerializeand Deserialize (from Serde) for serialization support.
Methods
sign
fn sign<TData: Serialize>(
secret: &Self::Secret,
data: &TData,
) -> anyhow::Result<Self::Signature>;
Purpose: Signs arbitrary serializable data with the provided secret key, outputting a BLS signature.
Parameters:
secret: A reference to the secret/private key used for signing.data: A reference to the data to be signed. The data must implementSerialize.
Returns: A
Resultwrapping the generated signature or an error.Usage: This method serializes the data and produces a signature bound to the secret key.
verify
fn verify<TData: Serialize>(
signature: &Self::Signature,
pubkeys_occurrences: &mut dyn Iterator<Item = &(Self::PubKey, usize)>,
data: &TData,
) -> anyhow::Result<bool>;
Purpose: Verifies the validity of a given signature against an iterator of public keys and their multiplicities.
Parameters:
signature: Reference to the signature to verify.pubkeys_occurrences: A mutable iterator over tuples of(PublicKey, usize)whereusizerepresents how many times the public key should be counted (occurrences), useful in threshold or aggregated signature schemes.data: Reference to the data that was signed, must implementSerialize.
Returns: A
Resultcontaining a boolean indicating signature validity or an error.Usage: Supports verification in aggregated signature scenarios where multiple public keys correspond to an aggregated signature.
merge
fn merge(one: &Self::Signature, another: &Self::Signature) -> anyhow::Result<Self::Signature>;
Purpose: Aggregates or merges two signatures into a single valid signature.
Parameters:
one: First signature reference.another: Second signature reference.
Returns: A
Resultwith the merged signature or an error.Usage: Enables signature aggregation, a key feature of BLS schemes allowing multiple signatures to be combined efficiently into one.
Implementation Details
The trait requires serialization and deserialization for signatures to facilitate storage, transmission, and interoperability.
The verification method accepts multiple public keys with associated occurrence counts, indicating support for multi-signatures or threshold schemes.
The
mergefunction embodies the BLS scheme's ability to aggregate signatures, enabling scalability and efficiency in systems requiring multiple signatures.
Interaction With Other Parts
The
gosh_blsmodule provides a concrete implementation (GoshBLS), which likely implements this trait.The
create_signedandenvelopemodules probably use this trait to create signed data structures and manage their encapsulation or transport.External components can use the
BLSSignatureSchemetrait to implement or interact with any BLS signature scheme conforming to this interface, enhancing modularity and extensibility.
Diagram: Structure of mod.rs
classDiagram
class BLSSignatureScheme {
<<trait>>
+sign()
+verify()
+merge()
+PubKey
+Secret
+Signature
}
BLSSignatureScheme <|.. GoshBLS
class GoshBLS {
+PubKey
+Secret
+Signature
+sign()
+verify()
+merge()
}
class create_signed
class envelope
class gosh_bls
mod.rs --> create_signed
mod.rs --> envelope
mod.rs --> gosh_bls
mod.rs ..> BLSSignatureScheme
gosh_bls ..> GoshBLS
The diagram illustrates the main trait BLSSignatureScheme with its core methods and associated types, the GoshBLS concrete implementation, and the submodules included in the file. The trait is implemented by GoshBLS, and the file exposes these components through its module structure.