mirror of
https://github.com/luxfi/accel.git
synced 2026-10-30 17:03:45 +00:00
The !cgo path returned ErrNotSupported for any input, but the cgo path (and TestNoopBehavior) require shape validation first: a wrong-length poly must be ErrShapeMismatch regardless of build. This was failing the 'Test without CGO (fallback)' CI job (pre-existing, since the op was implemented). Now CGO=0 and CGO=1 agree. EOF Co-authored-by: Hanzo Dev <[email protected]>
115 lines
3.4 KiB
Go
115 lines
3.4 KiB
Go
//go:build !cgo
|
|
|
|
// Copyright (C) 2025, Lux Industries, Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package accel
|
|
|
|
// Noop implementations for non-CGO builds.
|
|
// These are trivial functions that return immediately, allowing
|
|
// the compiler to inline and eliminate calls when callers check for ErrNotSupported.
|
|
|
|
// DefaultSession returns ErrNoBackends in non-CGO builds.
|
|
func DefaultSession() (*Session, error) {
|
|
return nil, ErrNoBackends
|
|
}
|
|
|
|
// closeDefaultSession is a noop in non-CGO builds.
|
|
func closeDefaultSession() {}
|
|
|
|
// MetalAvailable always returns false in non-CGO builds.
|
|
func MetalAvailable() bool { return false }
|
|
|
|
// CUDAAvailable always returns false in non-CGO builds.
|
|
func CUDAAvailable() bool { return false }
|
|
|
|
// WebGPUAvailable always returns false in non-CGO builds.
|
|
func WebGPUAvailable() bool { return false }
|
|
|
|
// BLSBatchVerify returns ErrNotSupported in non-CGO builds.
|
|
func BLSBatchVerify(_, _, _ [][]byte) ([]bool, error) {
|
|
return nil, ErrNotSupported
|
|
}
|
|
|
|
// SHA256Batch returns ErrNotSupported in non-CGO builds.
|
|
func SHA256Batch(_ [][]byte) ([][]byte, error) {
|
|
return nil, ErrNotSupported
|
|
}
|
|
|
|
// Keccak256Batch returns ErrNotSupported in non-CGO builds.
|
|
func Keccak256Batch(_ [][]byte) ([][]byte, error) {
|
|
return nil, ErrNotSupported
|
|
}
|
|
|
|
// MerkleRoot returns ErrNotSupported in non-CGO builds.
|
|
func MerkleRoot(_ [][]byte) ([]byte, error) {
|
|
return nil, ErrNotSupported
|
|
}
|
|
|
|
// KyberKeyGen returns ErrNotSupported in non-CGO builds.
|
|
func KyberKeyGen() (pk, sk []byte, err error) {
|
|
return nil, nil, ErrNotSupported
|
|
}
|
|
|
|
// KyberEncaps returns ErrNotSupported in non-CGO builds.
|
|
func KyberEncaps(_ []byte) (ct, ss []byte, err error) {
|
|
return nil, nil, ErrNotSupported
|
|
}
|
|
|
|
// KyberDecaps returns ErrNotSupported in non-CGO builds.
|
|
func KyberDecaps(_, _ []byte) ([]byte, error) {
|
|
return nil, ErrNotSupported
|
|
}
|
|
|
|
// DilithiumSign returns ErrNotSupported in non-CGO builds.
|
|
func DilithiumSign(_, _ []byte) ([]byte, error) {
|
|
return nil, ErrNotSupported
|
|
}
|
|
|
|
// DilithiumVerify returns ErrNotSupported in non-CGO builds.
|
|
func DilithiumVerify(_, _, _ []byte) (bool, error) {
|
|
return false, ErrNotSupported
|
|
}
|
|
|
|
// NTTForward returns ErrNotSupported in non-CGO builds.
|
|
func NTTForward(_, _ []uint64, _ uint64) error {
|
|
return ErrNotSupported
|
|
}
|
|
|
|
// NTTInverse returns ErrNotSupported in non-CGO builds.
|
|
func NTTInverse(_, _ []uint64, _ uint64) error {
|
|
return ErrNotSupported
|
|
}
|
|
|
|
// MSM returns ErrNotSupported in non-CGO builds.
|
|
func MSM(_, _ [][]byte) ([]byte, error) {
|
|
return nil, ErrNotSupported
|
|
}
|
|
|
|
// MLDSAVerifyBatch returns ErrNotSupported in non-CGO builds.
|
|
func MLDSAVerifyBatch(_ int, _, _, _ [][]byte, _ int) ([]bool, error) {
|
|
return nil, ErrNotSupported
|
|
}
|
|
|
|
// MLDSASignBatch returns ErrNotSupported in non-CGO builds.
|
|
func MLDSASignBatch(_ int, _, _ [][]byte, _ int) ([][]byte, error) {
|
|
return nil, ErrNotSupported
|
|
}
|
|
|
|
// LatticeNTTMLDSABatch returns ErrNotSupported in non-CGO builds.
|
|
func LatticeNTTMLDSABatch(polys [][]int32, _ bool) error {
|
|
// Validate the batch shape before the (absent) GPU dispatch decision,
|
|
// matching the cgo path so callers get the same error regardless of
|
|
// build: a wrong-length poly is ErrShapeMismatch, empty is
|
|
// ErrBatchSizeMismatch; otherwise no backend → ErrNotSupported.
|
|
if len(polys) == 0 {
|
|
return ErrBatchSizeMismatch
|
|
}
|
|
for _, p := range polys {
|
|
if len(p) != MLDSANTTPolyLen {
|
|
return ErrShapeMismatch
|
|
}
|
|
}
|
|
return ErrNotSupported
|
|
}
|