gpu

package
v1.17.28 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2025 License: BSD-3-Clause Imports: 5 Imported by: 0

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

View Source
const (
	BLSSecretKeySize = 32
	BLSPublicKeySize = 48
	BLSSignatureSize = 96
	BLSMessageSize   = 32

	MLDSASecretKeySize = 4032
	MLDSAPublicKeySize = 1952
	MLDSASignatureSize = 3309
)

Sizes

View Source
const (
	HashTypeSHA3_256 = 0
	HashTypeSHA3_512 = 1
	HashTypeBLAKE3   = 2
)

Hash types for batch hashing

Variables

View Source
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 BLAKE3

func BLAKE3(data []byte) []byte

BLAKE3 computes BLAKE3 hash.

func BLSAggregatePublicKeys

func BLSAggregatePublicKeys(pks [][]byte) ([]byte, error)

BLSAggregatePublicKeys aggregates multiple BLS public keys.

func BLSAggregateSignatures

func BLSAggregateSignatures(sigs [][]byte) ([]byte, error)

BLSAggregateSignatures aggregates multiple BLS signatures.

func BLSBatchVerify

func BLSBatchVerify(sigs, pks, msgs [][]byte) ([]bool, error)

BLSBatchVerify verifies multiple BLS signatures in parallel (GPU-accelerated). Returns a slice of verification results (true=valid, false=invalid).

func BLSKeygen

func BLSKeygen(seed []byte) ([]byte, error)

BLSKeygen generates a BLS secret key. If seed is nil, uses system entropy.

func BLSSecretKeyToPublicKey

func BLSSecretKeyToPublicKey(sk []byte) ([]byte, error)

BLSSecretKeyToPublicKey derives a BLS public key from a secret key.

func BLSSign

func BLSSign(sk, msg []byte) ([]byte, error)

BLSSign signs a message hash with a BLS secret key.

func BLSVerify

func BLSVerify(sig, pk, msg []byte) bool

BLSVerify verifies a BLS signature. Returns true if valid, false if invalid.

func BLSVerifyAggregated

func BLSVerifyAggregated(aggSig, aggPK, msg []byte) bool

BLSVerifyAggregated verifies an aggregated signature against an aggregated public key.

func BatchHash

func BatchHash(inputs [][]byte, hashType int) ([][]byte, error)

BatchHash computes multiple hashes in parallel (GPU-accelerated).

func ClearCache

func ClearCache()

ClearCache clears internal caches.

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

func MLDSABatchVerify(sigs, msgs [][]byte, pks [][]byte) ([]bool, error)

MLDSABatchVerify verifies multiple ML-DSA signatures in parallel (GPU-accelerated).

func MLDSAKeygen

func MLDSAKeygen(seed []byte) (pk, sk []byte, err error)

MLDSAKeygen generates an ML-DSA key pair.

func MLDSASign

func MLDSASign(sk, msg []byte) ([]byte, error)

MLDSASign signs a message with ML-DSA.

func MLDSAVerify

func MLDSAVerify(sig, msg, pk []byte) bool

MLDSAVerify verifies an ML-DSA signature.

func SHA3_256

func SHA3_256(data []byte) []byte

SHA3_256 computes SHA3-256 hash.

func SHA3_512

func SHA3_512(data []byte) []byte

SHA3_512 computes SHA3-512 hash.

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.

Jump to

Keyboard shortcuts

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