mirror of
https://github.com/luxfi/crypto.git
synced 2026-07-27 01:54:50 +00:00
Domain separation tags and identifiers in cryptographic code must be
readable in a scientific paper without product context. Strip the Lux
brand from in-code crypto identifiers; algorithm names ARE the namespace.
DSTs (golden vectors regenerated):
pedersen NewGenerators: LUX_PEDERSEN_{G,H} -> PEDERSEN_{G,H}_V1
pedersen NewGeneratorsFromSeed: LUX_PEDERSEN_SEEDED_GEN_V1 -> PEDERSEN_SEEDED_GEN_V1
pedersen golden G/H test vectors recomputed for the new DST.
Env vars (one canonical name only — no deprecated alias):
backend.envBackend: drop LUX_CRYPTO_BACKEND fallback, CRYPTO_BACKEND only
rust/build.rs: drop LUX_CRYPTO_DIR / LUX_CRYPTO_BUILD_DIR fallbacks
Rust c-abi link names:
lux-crypto-keccak: extern "C" name keccak256 (was lux_keccak256)
lux-crypto-secp256k1: secp256k1_ecrecover{,_batch} (was lux_*)
lux-crypto umbrella: drop all #[link_name = "lux_*"] attrs;
the canonical luxcpp/crypto C-ABI exports brand-neutral symbols
directly, the Rust function names mirror them one-for-one.
Go cgo aliases:
hash/blake3/blake3_c.go: drop the four #define aliases that mapped
crypto_* -> lux_crypto_*; the C header now declares brand-neutral
names directly.
Tests passing:
lux/crypto: 50 packages ok, 0 fail (GOWORK=off go test ./... -short)
rust workspace: 18 tests across 3 crates (CRYPTO_BUILD_DIR=... cargo test --release)
106 lines
2.6 KiB
Go
106 lines
2.6 KiB
Go
package backend
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func TestParse(t *testing.T) {
|
|
cases := []struct {
|
|
in string
|
|
want Backend
|
|
ok bool
|
|
}{
|
|
{"", Auto, true},
|
|
{"auto", Auto, true},
|
|
{"AUTO", Auto, true},
|
|
{"vanilla", Vanilla, true},
|
|
{"go", Vanilla, true},
|
|
{"pure", Vanilla, true},
|
|
{"cgo", CGo, true},
|
|
{"c", CGo, true},
|
|
{"native", CGo, true},
|
|
{"gpu", GPU, true},
|
|
{"accel", GPU, true},
|
|
{"banana", Auto, false},
|
|
}
|
|
for _, tc := range cases {
|
|
got, ok := Parse(tc.in)
|
|
if got != tc.want || ok != tc.ok {
|
|
t.Errorf("Parse(%q) = (%v, %v); want (%v, %v)", tc.in, got, ok, tc.want, tc.ok)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestDefaultAndSetDefault(t *testing.T) {
|
|
t.Cleanup(func() { SetDefault(Auto) })
|
|
for _, b := range []Backend{Auto, Vanilla, CGo, GPU} {
|
|
SetDefault(b)
|
|
if got := Default(); got != b {
|
|
t.Errorf("after SetDefault(%v) Default() = %v", b, got)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestResolveVanillaAlwaysAvailable(t *testing.T) {
|
|
t.Cleanup(func() { SetDefault(Auto) })
|
|
SetDefault(Auto)
|
|
if got := Resolve(false, false); got != Vanilla {
|
|
t.Fatalf("Resolve(false, false) = %v; want Vanilla", got)
|
|
}
|
|
}
|
|
|
|
func TestResolveAutoPrefersGPU(t *testing.T) {
|
|
t.Cleanup(func() { SetDefault(Auto) })
|
|
SetDefault(Auto)
|
|
if got := Resolve(true, true); got != GPU {
|
|
t.Fatalf("Resolve(true, true) auto = %v; want GPU", got)
|
|
}
|
|
if got := Resolve(false, true); got != CGo {
|
|
t.Fatalf("Resolve(false, true) auto = %v; want CGo", got)
|
|
}
|
|
}
|
|
|
|
func TestResolveExplicitForcesFallback(t *testing.T) {
|
|
t.Cleanup(func() { SetDefault(Auto) })
|
|
SetDefault(GPU)
|
|
if got := Resolve(false, true); got != CGo {
|
|
t.Fatalf("Resolve(false, true) gpu-forced = %v; want CGo (fallback)", got)
|
|
}
|
|
if got := Resolve(false, false); got != Vanilla {
|
|
t.Fatalf("Resolve(false, false) gpu-forced = %v; want Vanilla (fallback)", got)
|
|
}
|
|
SetDefault(CGo)
|
|
if got := Resolve(true, false); got != Vanilla {
|
|
t.Fatalf("Resolve(true, false) cgo-forced = %v; want Vanilla (fallback)", got)
|
|
}
|
|
}
|
|
|
|
func TestStringRoundTrip(t *testing.T) {
|
|
for _, b := range []Backend{Auto, Vanilla, CGo, GPU} {
|
|
got, ok := Parse(b.String())
|
|
if !ok || got != b {
|
|
t.Errorf("round-trip %v: Parse(%q) = (%v, %v)", b, b.String(), got, ok)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestEnvOverride(t *testing.T) {
|
|
// Saved current state.
|
|
prev := Default()
|
|
t.Cleanup(func() { SetDefault(prev) })
|
|
|
|
// We cannot re-trigger init() without process restart; emulate by
|
|
// re-parsing here just like init does.
|
|
t.Setenv("CRYPTO_BACKEND", "vanilla")
|
|
if v, ok := os.LookupEnv("CRYPTO_BACKEND"); ok {
|
|
if b, parsed := Parse(v); parsed {
|
|
SetDefault(b)
|
|
}
|
|
}
|
|
if got := Default(); got != Vanilla {
|
|
t.Errorf("env override: Default() = %v; want Vanilla", got)
|
|
}
|
|
}
|
|
|