Commit Graph
91 Commits
Author SHA1 Message Date
Zach Kelling 527004fe2d refactor(hash): remove duplicate hashing package, use hash
- Remove hashing/ directory (duplicate of hash/)
- Update imports in cb58, secp256k1 to use crypto/hash
- Follows Go stdlib naming convention (hash vs hashing)
2025-12-26 17:28:18 -08:00
Zach Kelling f41ac722b2 refactor(hash): add hash package and alias hashing for backwards compat
The hash package is the canonical implementation.
The hashing package now re-exports from hash for backwards compatibility.

New code should import github.com/luxfi/crypto/hash directly.
2025-12-26 17:02:15 -08:00
Fuma Nama 898b7f84c0 feat(bls): implement proper proof of possession with domain separation
Add domain separation tags (DST) to BLS proof of possession signing and
verification to prevent cross-protocol attacks:
- dstSignature for standard BLS signatures
- dstPoP for proof of possession

This ensures signatures cannot be replayed across different contexts.
2025-12-26 16:36:13 -08:00
Zach Kelling 706f762ea6 feat(gpu): add NTT cache, worker pools, and BLS batch verification
- Add NTT cache with LRU eviction for twiddle factors
- Add worker pool for parallel GPU operations
- Add BLS batch signature verification
- Improve element operations for Bandersnatch
- Add comprehensive tests for GPU crypto operations
2025-12-26 16:10:11 -08:00
Zach Kelling 19e22adbcc refactor(gpu): self-contained CGO with runtime backend detection
- CGO_ENABLED=1: Auto-detects Metal (macOS) / CUDA (Linux) / CPU fallback
- CGO_ENABLED=0: Pure Go stubs (no C dependencies)
- Bundled include/gpu_crypto.h header (no external deps for build)
- Runtime GPU detection via gpu_available() and gpu_backend_name()
- Placeholder implementations for BLS, ML-DSA, hashing
- Threshold signatures stub (ErrNotSupported)

Build: go build ./...
Test:  go test ./...
2025-12-26 15:44:09 -08:00
Zach Kelling abaf7655f9 fix(gpu): use luxgpu build tag for CGO bindings
The gpu package requires C++ headers that only exist locally.
Using 'cgo' build tag caused CI failures when CGO was enabled but
headers weren't present.

Now uses 'luxgpu' custom build tag:
- Default: stub implementation (no dependencies)
- With -tags luxgpu: full CGO acceleration

Build locally with GPU: go build -tags luxgpu ./...
2025-12-26 15:18:06 -08:00
Zach Kelling cfb775419b feat(gpu): add GPU-accelerated cryptographic operations via CGO
- 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).
2025-12-26 14:52:04 -08:00
Zach Kelling 168492cbac chore: add grpc-server.log to gitignore 2025-12-26 14:26:02 -08:00
Zach Kelling 18f88f19da Updates for warp, docs 2025-12-26 14:00:00 -08:00
Zach Kelling a67025abb7 style: fix gofmt formatting issues in threshold and aggregated packages 2025-12-20 22:43:34 -08:00
Zach Kelling 642c8bc0d6 ci: update Go version to 1.25.5 2025-12-20 21:42:40 -08:00
Zach Kelling 37bd49c508 feat: add ring signatures for anonymous group signing 2025-12-20 14:02:56 -08:00
Zach Kelling a3d4cd1b71 fix: exclude broken geth v1.16.1 module path mismatch
The Go proxy still serves v1.16.1 which has wrong module path
(github.com/ethereum/go-ethereum instead of github.com/luxfi/geth).
Add exclude directive to prevent this version from being selected.
2025-12-20 13:56:20 -08:00
Zach Kelling fef62f9f4e feat(threshold): add generic threshold signature framework with BLS support
- Add threshold package with generic interfaces for threshold signatures
- Implement BLS threshold signatures with proper Shamir secret sharing
  and Lagrange interpolation (polynomial degree t-1 for t-of-n)
- Add threshold scheme registry for multiple signature schemes
- Add session management for coordinated signing
- Add signer package with unified interface
- Remove obsolete corona/corona.go (moved to threshold repo)
- Remove obsolete unified/signer_simple.go (replaced by signer package)
- Update aggregated package for threshold integration
2025-12-17 14:33:12 -08:00
Zach Kelling 0ee940111e fix(bn256/gnark): fix inverted TestBytes logic in G1/G2 Unmarshal
The TestBytes function returns true when all bytes are zero (point at infinity).
The condition was inverted, causing non-zero points to be treated as infinity.
2025-12-14 21:24:02 -08:00
Zach Kelling 6fe11f3e77 chore: remove local cache/utils, use external luxfi/cache package
- Remove cache/ and utils/ directories (originally copied from luxfi/node)
- Update secp256k1 imports to use github.com/luxfi/cache/lru
- Update sig_fuzz_test.go to use local crypto/hashing instead of node/utils
- Clean up go.mod: remove unused node/geth dependencies
- crypto package is now fully standalone
2025-12-14 21:18:31 -08:00
Zach Kelling deca5e6954 Update dependencies to latest versions 2025-12-13 10:48:20 +00:00
Zach Kelling 29d5bbb311 Fix imports and fuzz tests for proper integration with geth
- Add crypto/common imports instead of geth/common for type independence
- Add HexToAddress wrapper function for address parsing
- Fix secp256k1 fuzz tests to check IsOnCurve before CompressPubkey
2025-12-12 22:06:09 -08:00
Zach Kelling a9769373ca fix: resolve build errors and ensure crypto independence from geth
- Fix bn256/gnark imports to use crypto/bitutil instead of standalone bitutil
- Remove unused secp256k1 import from crypto.go
- Fix mlkem test files to use correct API (GenerateKeyPair returns pub,priv,err)
- Fix mlkem constant names (MLKEM512SharedKeySize not SharedSecretSize)
- Restore crypto/common types as standalone (not aliases to geth/common)
- Update crypto.go and keccak.go to use crypto/common instead of geth/common
- Fix secp256k1 fuzz tests to use correct DecompressPubkey/CompressPubkey API
- Remove stale test files and go.work files

crypto package is now fully independent of geth (geth -> crypto, not reverse)
2025-12-12 21:51:02 -08:00
Zach Kelling 1ae6627f4a Update tests, remove old status files 2025-12-12 19:49:59 -08:00
Zach Kelling 78d37550c9 Sync with geth 2025-12-12 19:49:01 -08:00
Zach Kelling d3c8fb2fe2 Add EthAddress method for Ethereum-compatible address derivation
Adds EthAddress() methods to both PrivateKey and PublicKey types
to compute Ethereum addresses from secp256k1 keys using Keccak256.
2025-12-13 03:05:25 +00:00
Zach Kelling 78e922fa7a fix(bls): reject zero bytes in SecretKeyFromBytes for security
Zero is not a valid BLS12-381 scalar and should be rejected
when deserializing secret keys. This matches the expected
behavior tested in the node package.
2025-12-12 13:02:13 -08:00
Zach Kelling 786bfd7b8c feat(bls): add CGO-optimized blst implementation with circl fallback
- bls.go: pure Go implementation using cloudflare/circl (!cgo)
- bls_cgo.go: CGO-optimized implementation using supranational/blst (cgo)
- types.go: shared constants and errors
- Simplified bls12381 build tags (cgo vs !cgo)
- Removed duplicate implementations (bls_new.go, internal.go)
- Fixed tests to work with both implementations
2025-12-12 12:54:42 -08:00
Zach Kelling a3d151e310 fix: update circl to latest main for SLH-DSA support
Update cloudflare/circl pseudo-version to latest main branch
which includes complete package structure for all imports.
2025-12-11 22:37:40 -08:00
Zach Kelling 5c6b503aa4 docs: add comment to PubkeyBytesToAddress 2025-12-11 22:29:10 -08:00
Zach Kelling 4e657ff030 Fix duplicate import in ulimit_unix.go
Remove duplicate github.com/luxfi/log import and fix alias
2025-12-11 06:00:09 +00:00
Zach Kelling 558e4e40e3 fix: make CellProofsPerBlob a const for use in const expressions
Required for geth to use luxfi/crypto/kzg4844 as the kzg4844 package.
2025-12-11 04:52:56 +00:00
Zach Kelling 5ba390d1b0 fix: use Go 1.25.5 2025-12-10 19:37:53 -08:00
Zach Kelling ca11f7e242 fix: downgrade Go version to 1.23.4 for compatibility 2025-12-10 19:25:58 -08:00
Zach Kelling c6cdc0efb3 fix: implement sliding window EtaTracker for proper ETA estimation
- Track samples in sliding window of size minSamples
- Return nil ETA until sufficient samples collected
- Reject bogus samples (time warp, no progress)
- Calculate rate from window edges for accurate ETA
2025-12-10 19:16:25 -08:00
Zach Kelling 95100198c8 fix: apply gofmt -s formatting 2025-12-11 03:04:56 +00:00
Zach Kelling 6f62fb8301 fix(aggregated): use log package-level field functions
Use log.Uint8, log.Bool, etc. as package-level field constructors
instead of calling them as methods on the Logger instance.
2025-12-10 18:59:17 -08:00
Zach Kelling 1760ba5f50 feat(pqc): add VerifySignature simplified API
- Add VerifySignature method to ML-DSA and SLH-DSA public keys
- Keep Verify method for crypto.Signer compatibility
- Add documentation clarifying opts parameter is ignored
2025-12-11 02:33:54 +00:00
Zach Kelling bc658139cf Add threshold signature and ring signature packages
- cggmp21: CGGMP21 threshold ECDSA protocol implementation
- mpc: Multi-party computation account management
- aggregated: Signature aggregation managers for BLS, Corona, CGGMP21
- corona: Linkable ring signature implementation

These packages were previously in node/crypto and are now properly
located in the dedicated crypto repository.
2025-12-10 03:03:35 +00:00
Hanzo Dev 62fd298312 crypto: implement SLH-DSA (FIPS 205) with circl
- Implement all 12 SLH-DSA parameter sets using cloudflare/circl
  * SHA2_128s/f, SHA2_192s/f, SHA2_256s/f (SHA-2 based)
  * SHAKE_128s/f, SHAKE_192s/f, SHAKE_256s/f (SHAKE based)
  * s = small signature, f = fast signing

- Performance on M1 Max:
  * SHA2-128s: Sign ~309ms, Verify ~286μs, KeyGen ~35ms
  * SHA2-256s: Sign ~603ms, Verify ~593μs

- Signature sizes (FIPS 205):
  * 128-bit small: 7,856 bytes
  * 128-bit fast: 17,088 bytes
  * 192-bit small: 16,224 bytes
  * 192-bit fast: 35,664 bytes
  * 256-bit small: 29,792 bytes
  * 256-bit fast: 49,856 bytes

- Public key sizes:
  * 128-bit: 32 bytes
  * 192-bit: 48 bytes
  * 256-bit: 64 bytes

- All 15 tests passing
- Deterministic signing for reproducibility
- FIPS 205 compliant (Stateless Hash-Based Signatures)

SLH-DSA (SPHINCS+) provides quantum-resistant signatures based on hash functions,
offering stateless operation and well-understood security based on minimal
assumptions (collision-resistant hash functions).
2025-11-22 16:44:42 -08:00
Hanzo Dev 0be2fe8f6c crypto: implement post-quantum primitives with circl
- Implement ML-DSA-65 (FIPS 204) using cloudflare/circl
  * Single implementation with automatic CGO optimization
  * Sign ~440μs, Verify ~130μs, KeyGen ~165μs on M1 Max
  * All 11 tests passing

- Simplify ML-KEM implementation
  * Remove redundant optimized versions
  * Use circl ML-KEM-768 directly

- Simplify SLH-DSA implementation
  * Remove premature optimizations
  * Clean stub for future circl support (FIPS 205)

- Add comprehensive cache package
  * LRU cache from luxfi/node
  * Metercacher for metrics integration
  * Test utilities

- Add crypto utils
  * Atomic operations
  * Bytes utilities
  * Complete utils package from luxfi/node

- Update secp256k1 and BLS
  * All BLS tests passing (23 tests)
  * secp256k1 fuzz test added

All post-quantum implementations now use cloudflare/circl as single source
of truth, following DRY principle and ensuring FIPS compliance.
2025-11-22 16:37:21 -08:00
Hanzo Dev 6c7cfd95bc crypto: fix PrivateKey UnmarshalText
Refactored PrivateKey unmarshaling to properly handle both JSON and text
formats:
1. Created shared unmarshalText() helper for core unmarshaling logic
2. Fixed UnmarshalJSON to strip quotes then call helper
3. Fixed UnmarshalText to call helper directly without quote stripping
4. Added 6 new tests covering:
   - Direct text unmarshaling (no quotes)
   - JSON unmarshaling (with quotes)
   - Invalid prefix handling
   - Null value handling

All tests pass (19/19).
2025-11-11 10:34:17 -08:00
Hanzo Dev 3aeb406487 bls: validate secret key size in SecretKeyFromBytes
Add length validation to reject secret keys that aren't exactly 32 bytes.
CIRCL's UnmarshalBinary accepts variable-length inputs, so we add this
check to ensure strict validation matching BLST's behavior.
2025-11-04 17:40:22 -08:00
Hanzo Dev 32a00ff2bc bls: reject signatures with all identical bytes
Enhance SignatureFromBytes validation to reject signatures where all
bytes are identical (e.g., all 0xFF, all 0x00). This prevents obviously
invalid signatures from being accepted during deserialization.

With the CIRCL migration, Signature is just a []byte wrapper, so we add
this sanity check to catch malformed data early, matching the stricter
validation behavior from the previous BLST implementation.
2025-11-04 15:54:47 -08:00
Hanzo Dev be4f2e16cf Clean up documentation and update dependencies 2025-11-04 15:54:47 -08:00
Zach Kelling 9f5ad36c0d Fix v1.17.2 CI failures: syntax errors and ML-DSA panic
- Fix 18 missing if conditions in ipa/bandersnatch/fr/element_test.go
- Fix missing if condition in ipa/bandersnatch/multiexp_test.go
- Fix missing if condition in slhdsa/optimization_test.go
- Fix ML-DSA nil pointer panic by adding default SignerOpts
- Fix ML-DSA test to properly validate randomized signing behavior

All syntax errors resolved. All ML-DSA tests passing.
Resolves panic in TestAllCryptoImplementations/ML-DSA/ML-DSA-44.
2025-09-26 03:29:30 +00:00
Zach Kelling 055a2576ce chore: update copyright years to 2025 and Go version
- Update copyright headers to 2025
- Standardize Go version to 1.25.1
- Remove toolchain directive
2025-09-26 02:20:31 +00:00
Zach Kelling e45ad8e942 Update go.mod dependencies 2025-09-24 02:37:31 +00:00
Zach Kelling ffc78a07f8 Fix: Update BLS and crypto test signatures for latest API
- Update BLS Sign() calls to handle (signature, error) return values
- Fix MLKEM GenerateKeyPair() to handle 3 return values
- Update batch verification to use individual signature verification
- Fix duplicate test function names in comprehensive PQ tests
2025-09-22 07:23:20 +00:00
Zach Kelling dbef0ef262 fix: achieve ZERO TOLERANCE - all gosec G115 violations destroyed
- Fixed all integer conversions in crypto primitives
- Added proper bounds validation for all operations
- Secured BLS, KZG, and post-quantum implementations
- ZERO violations remaining - complete security achieved
2025-09-20 23:08:21 +00:00
Zach Kelling bcbc691734 chore: remove local replace directive for corona 2025-09-15 21:11:29 +00:00
Zach Kelling 248450a875 fix: update SLHDSA optimization implementation, fix API compatibility 2025-09-15 19:33:42 +00:00
Zach Kelling fe456561f1 fix: update test APIs for SLHDSA optimization tests 2025-09-15 12:08:32 +00:00
Zach Kelling a696862eb0 fix: update SLH-DSA test to use new GenerateKey API 2025-09-15 04:35:34 +00:00