Documentation
¶
Overview ¶
Package gpu provides GPU-accelerated cryptographic operations via libcrypto. This bridges the luxcpp/crypto C++ library to Go, enabling: - BLS12-381 signatures for validator consensus - ML-DSA post-quantum signatures - Threshold cryptography operations - Hash functions (SHA3, BLAKE3)
GPU acceleration uses MLX (Metal on macOS, CUDA on Linux, CPU fallback).
Index ¶
- Constants
- Variables
- func BLAKE3(data []byte) []byte
- func BLSAggregatePublicKeys(pks [][]byte) ([]byte, error)
- func BLSAggregateSignatures(sigs [][]byte) ([]byte, error)
- func BLSBatchVerify(sigs, pks, msgs [][]byte) ([]bool, error)
- func BLSKeygen(seed []byte) ([]byte, error)
- func BLSSecretKeyToPublicKey(sk []byte) ([]byte, error)
- func BLSSign(sk, msg []byte) ([]byte, error)
- func BLSVerify(sig, pk, msg []byte) bool
- func BLSVerifyAggregated(aggSig, aggPK, msg []byte) bool
- func BatchHash(inputs [][]byte, hashType int) ([][]byte, error)
- func ClearCache()
- func ConsensusVerifyBlock(blsSigs, blsPKs [][]byte, thresholdSig, thresholdPK, blockHash []byte) bool
- func GPUAvailable() bool
- func GetBackend() string
- func MLDSABatchVerify(sigs, msgs [][]byte, pks [][]byte) ([]bool, error)
- func MLDSAKeygen(seed []byte) (pk, sk []byte, err error)
- func MLDSASign(sk, msg []byte) ([]byte, error)
- func MLDSAVerify(sig, msg, pk []byte) bool
- func SHA3_256(data []byte) []byte
- func SHA3_512(data []byte) []byte
- type ThresholdContext
- func (tc *ThresholdContext) Close()
- func (tc *ThresholdContext) Combine(partialSigs [][]byte, indices []uint32) ([]byte, error)
- func (tc *ThresholdContext) Keygen(seed []byte) (shares [][]byte, pk []byte, err error)
- func (tc *ThresholdContext) PartialSign(shareIndex uint32, share, msg []byte) ([]byte, error)
- func (tc *ThresholdContext) Verify(sig, pk, msg []byte) bool
Constants ¶
const ( BLSSecretKeySize = 32 BLSPublicKeySize = 48 BLSSignatureSize = 96 BLSMessageSize = 32 MLDSASecretKeySize = 4032 MLDSAPublicKeySize = 1952 MLDSASignatureSize = 3309 )
Sizes
const ( HashTypeSHA3_256 = 0 HashTypeSHA3_512 = 1 HashTypeBLAKE3 = 2 )
Hash types for batch hashing
Variables ¶
var ( ErrInvalidKey = errors.New("invalid key") ErrInvalidSig = errors.New("invalid signature") ErrNullPointer = errors.New("null pointer") ErrGPU = errors.New("GPU error") ErrThreshold = errors.New("threshold error") ErrHash = errors.New("hash error") ErrCGORequired = errors.New("CGO required for GPU acceleration") )
Error codes
Functions ¶
func BLSAggregatePublicKeys ¶
BLSAggregatePublicKeys aggregates multiple BLS public keys.
func BLSAggregateSignatures ¶
BLSAggregateSignatures aggregates multiple BLS signatures.
func BLSBatchVerify ¶
BLSBatchVerify verifies multiple BLS signatures in parallel (GPU-accelerated). Returns a slice of verification results (true=valid, false=invalid).
func BLSSecretKeyToPublicKey ¶
BLSSecretKeyToPublicKey derives a BLS public key from a secret key.
func BLSVerifyAggregated ¶
BLSVerifyAggregated verifies an aggregated signature against an aggregated public key.
func ConsensusVerifyBlock ¶
func ConsensusVerifyBlock(blsSigs, blsPKs [][]byte, thresholdSig, thresholdPK, blockHash []byte) bool
ConsensusVerifyBlock verifies a block's signatures using GPU-accelerated batch operations.
func GPUAvailable ¶
func GPUAvailable() bool
GPUAvailable returns true if GPU acceleration is available.
func GetBackend ¶
func GetBackend() string
GetBackend returns the name of the active backend: "Metal", "CUDA", or "CPU".
func MLDSABatchVerify ¶
MLDSABatchVerify verifies multiple ML-DSA signatures in parallel (GPU-accelerated).
func MLDSAKeygen ¶
MLDSAKeygen generates an ML-DSA key pair.
func MLDSAVerify ¶
MLDSAVerify verifies an ML-DSA signature.
Types ¶
type ThresholdContext ¶
type ThresholdContext struct {
// contains filtered or unexported fields
}
ThresholdContext manages threshold cryptography operations.
func NewThresholdContext ¶
func NewThresholdContext(t, n uint32) (*ThresholdContext, error)
NewThresholdContext creates a new threshold context for t-of-n signatures.
func (*ThresholdContext) Close ¶
func (tc *ThresholdContext) Close()
Close releases the threshold context resources.
func (*ThresholdContext) Combine ¶
func (tc *ThresholdContext) Combine(partialSigs [][]byte, indices []uint32) ([]byte, error)
Combine combines partial signatures into a final signature. Uses Lagrange interpolation (GPU-accelerated).
func (*ThresholdContext) Keygen ¶
func (tc *ThresholdContext) Keygen(seed []byte) (shares [][]byte, pk []byte, err error)
Keygen generates threshold key shares. Returns n shares and the combined public key.
func (*ThresholdContext) PartialSign ¶
func (tc *ThresholdContext) PartialSign(shareIndex uint32, share, msg []byte) ([]byte, error)
PartialSign creates a partial signature share.
func (*ThresholdContext) Verify ¶
func (tc *ThresholdContext) Verify(sig, pk, msg []byte) bool
Verify verifies a threshold signature.