crypto

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: May 22, 2026 License: BSD-3-Clause Imports: 7 Imported by: 2

Documentation

Overview

Package crypto provides GPU-accelerated cryptographic operations.

All operations use the unified accel backend selection and fallback to CPU. Backend is selected at runtime via GPU_BACKEND env or auto-detection.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidInput = errors.New("crypto: invalid input")
	ErrBatchEmpty   = errors.New("crypto: empty batch")
	ErrVerifyFailed = errors.New("crypto: verification failed")
	ErrUnsupported  = errors.New("crypto: unsupported curve")
)

Functions

func AggregatePublicKeys

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

AggregatePublicKeys aggregates BLS public keys.

func AggregateSignatures

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

AggregateSignatures aggregates BLS signatures.

func BatchVerify

func BatchVerify(sigType SigType, sigs, msgs, pubkeys [][]byte) ([]bool, error)

BatchVerify verifies multiple signatures in parallel. Returns a slice of bools indicating which signatures are valid. Uses GPU acceleration when available, falls back to CPU.

func Hash

func Hash(hashType HashType, inputs [][]byte) ([][32]byte, error)

Hash computes hashes for multiple inputs in parallel.

func MSM

func MSM(curve Curve, scalars, points [][]byte) ([]byte, error)

MSM performs multi-scalar multiplication on the given curve.

result = sum_{i=0..n-1}  scalars[i] * points[i]

scalars[i] is 32-byte LE canonical; points[i] is the curve's wire-encoded affine form (see Curve doc). The result is the same wire format as a single point on the curve.

Routes through the GPU when available; falls back to a CPU implementation (luxcpp/crypto via cgo when built with -tags=lux_crypto_native, otherwise a pure-Go gnark-crypto path).

Types

type Curve added in v1.0.8

type Curve uint32

Curve identifies the elliptic curve for MSM (multi-scalar multiplication).

Wire encoding for MSM(curve, scalars, points):

secp256k1 / bn254 g1 / banderwagon : 32-byte BE x || 32-byte BE y per point (64 bytes total)
bls12_381 g1                       : 48-byte BE x || 48-byte BE y per point (96 bytes total)
scalars                            : 32-byte LE canonical (all curves)

Identity (point at infinity) is wire-encoded as all-zero point bytes.

The numeric values match GPUKIT_CURVE_* in luxcpp/crypto so the cgo bridge passes them through unchanged.

const (
	CurveSecp256k1   Curve = 0
	CurveBN254       Curve = 1 // BN254 G1
	CurveBLS12_381   Curve = 2 // BLS12-381 G1
	CurveBanderwagon Curve = 3
)

type HashType

type HashType uint8

HashType identifies the hash algorithm.

const (
	HashSHA256 HashType = iota
	HashKeccak256
	HashBlake3
	HashPoseidon
)

type SigType

type SigType uint8

SigType identifies the signature algorithm.

const (
	SigECDSA   SigType = iota // secp256k1
	SigEd25519                // Ed25519
	SigBLS                    // BLS12-381
	SigMLDSA65                // Post-quantum ML-DSA-65
)

Jump to

Keyboard shortcuts

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