mirror of
https://github.com/luxfi/crypto.git
synced 2026-07-27 01:54:50 +00:00
luxfi/crypto becomes the single Go entry point for ALL Lux-family crypto. Every public function in this module now dispatches between three implementations through a runtime-selectable backend: - vanilla: pure-Go reference (always available) - cgo: native binding (blst, libsecp256k1, ckzg) where present - gpu: batch acceleration via github.com/luxfi/accel The dispatcher reads LUX_CRYPTO_BACKEND (auto|vanilla|cgo|gpu); auto picks the most capable backend the binary was compiled and linked with. New canonical packages: backend/ runtime backend selector (env + programmatic) internal/gpuhost/ accel session lifecycle, single per-process keccak/ Keccak-256 with batch GPU dispatch sha256/ SHA-256 with batch GPU dispatch sha3/ SHA3 / SHAKE family ripemd160/ RIPEMD-160 (Bitcoin/Lux address derivation) ed25519/ Ed25519 with batch GPU verify bn254/ canonical alias for bn256 (matches FIPS naming) modexp/ canonical alias for bigmodexp evm256/ EIP-196/197 precompile ABI wrappers poseidon/ Poseidon2 hash via gnark-crypto pedersen/ Pedersen commitments over BN254 ntt/ Number-Theoretic Transform reference polymul/ negacyclic polynomial multiplication Extended existing packages with batch GPU paths: bls/batch.go BatchVerify routes through accel.BLSVerifyBatch mldsa/batch.go BatchVerify (ML-DSA-65) via accel.DilithiumVerifyBatch mlkem/batch.go BatchEncapsulate / BatchDecapsulate via Kyber kernels secp256k1/batch.go BatchVerifySignature via accel.ECDSAVerifyBatch GPU dispatch is gated on (a) backend.Default(), (b) batch size threshold, and (c) accel.Available(). When any gate fails the call falls through to the vanilla CPU path; output is byte-identical. The legacy gpu/ stub is replaced with a thin probe surface (Available, Backend, Devices, Version) that delegates to the same gpuhost session. Tests show vanilla and gpu backends produce identical outputs across all batch entry points (-race clean). See AUDIT.md for the per-algorithm state matrix and honest gaps.
49 lines
1.4 KiB
Go
49 lines
1.4 KiB
Go
// Copyright (C) 2020-2026, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package sha3
|
|
|
|
import (
|
|
"hash"
|
|
|
|
"golang.org/x/crypto/sha3"
|
|
)
|
|
|
|
// Size constants for fixed-output SHA3 variants.
|
|
const (
|
|
Size224 = 28
|
|
Size256 = 32
|
|
Size384 = 48
|
|
Size512 = 64
|
|
)
|
|
|
|
// Sum224 returns the SHA3-224 hash of in.
|
|
func Sum224(in []byte) [Size224]byte { return sha3.Sum224(in) }
|
|
|
|
// Sum256 returns the SHA3-256 hash of in.
|
|
func Sum256(in []byte) [Size256]byte { return sha3.Sum256(in) }
|
|
|
|
// Sum384 returns the SHA3-384 hash of in.
|
|
func Sum384(in []byte) [Size384]byte { return sha3.Sum384(in) }
|
|
|
|
// Sum512 returns the SHA3-512 hash of in.
|
|
func Sum512(in []byte) [Size512]byte { return sha3.Sum512(in) }
|
|
|
|
// New224 returns a new hash.Hash computing SHA3-224.
|
|
func New224() hash.Hash { return sha3.New224() }
|
|
|
|
// New256 returns a new hash.Hash computing SHA3-256.
|
|
func New256() hash.Hash { return sha3.New256() }
|
|
|
|
// New384 returns a new hash.Hash computing SHA3-384.
|
|
func New384() hash.Hash { return sha3.New384() }
|
|
|
|
// New512 returns a new hash.Hash computing SHA3-512.
|
|
func New512() hash.Hash { return sha3.New512() }
|
|
|
|
// ShakeSum128 produces an outputLen-byte SHAKE128 digest of data.
|
|
func ShakeSum128(out, data []byte) { sha3.ShakeSum128(out, data) }
|
|
|
|
// ShakeSum256 produces an outputLen-byte SHAKE256 digest of data.
|
|
func ShakeSum256(out, data []byte) { sha3.ShakeSum256(out, data) }
|