mirror of
https://github.com/luxfi/fhe.git
synced 2026-07-26 23:16:08 +00:00
LP-137-FHE-TYPING. New package github.com/luxfi/fhe/types wrapping every FHE buffer with the metadata required for safe dispatch: - FHEScheme (uint32 enum): TFHE, FHEW, CKKS, BFV, BGV. - FHECiphertextHeader (144-byte struct): ParamsHash, KeyID, CircuitID, Scheme, Level, N, ModulusCount, Domain, Reserved. Digest() returns SHA-256 of canonical 144-byte little-endian encoding; deterministic across runs. MatchesContext() rejects N + Domain mismatch. - FHEPrecompileArtifact (232-byte struct): seven 32-byte digest fields (ParamsHash, KeyRoot, InputCiphertextRoot, OutputCiphertextRoot, CircuitRoot, ThresholdTranscriptRoot, AttestationRoot) + OpCount + FailedCount. Digest() is the contribution to fchain_fhe_root. IsThreshold / IsAttested flag-helpers on the *Root fields. Layout byte-stable with the C++ mirror at luxcpp/fhe/include/lux/fhe/types. Cross-language byte image tests verify both struct types. 14 Go tests pass.
54 lines
1.5 KiB
Go
54 lines
1.5 KiB
Go
// Package types defines the FHE-GPU ciphertext header and precompile artifact
|
|
// types. These wrap every FHE buffer with the minimal metadata required to
|
|
// reject domain mismatches, parameter mismatches, and key/circuit drift at
|
|
// the kernel boundary.
|
|
//
|
|
// Reference: LP-137-FHE-TYPING.md.
|
|
//
|
|
// Copyright (c) 2026, Lux Industries Inc.
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
package types
|
|
|
|
// FHEScheme identifies which FHE scheme produced or consumes a ciphertext.
|
|
//
|
|
// Wire stable: enum values are fixed and MUST NOT be reordered. Add new
|
|
// schemes by appending.
|
|
type FHEScheme uint32
|
|
|
|
const (
|
|
// FHESchemeTFHE is the TFHE/FHEW boolean-circuit family with blind
|
|
// rotation bootstrap, as implemented by luxfi/fhe over luxfi/lattice.
|
|
FHESchemeTFHE FHEScheme = 0
|
|
|
|
// FHESchemeFHEW is the FHEW variant (kept distinct from TFHE for
|
|
// parameter-set hashing even though the kernel path can be shared).
|
|
FHESchemeFHEW FHEScheme = 1
|
|
|
|
// FHESchemeCKKS is approximate-arithmetic CKKS (real/complex).
|
|
FHESchemeCKKS FHEScheme = 2
|
|
|
|
// FHESchemeBFV is exact-arithmetic BFV (integer).
|
|
FHESchemeBFV FHEScheme = 3
|
|
|
|
// FHESchemeBGV is exact-arithmetic BGV (integer).
|
|
FHESchemeBGV FHEScheme = 4
|
|
)
|
|
|
|
// String returns a stable, human-readable name for the scheme.
|
|
func (s FHEScheme) String() string {
|
|
switch s {
|
|
case FHESchemeTFHE:
|
|
return "TFHE"
|
|
case FHESchemeFHEW:
|
|
return "FHEW"
|
|
case FHESchemeCKKS:
|
|
return "CKKS"
|
|
case FHESchemeBFV:
|
|
return "BFV"
|
|
case FHESchemeBGV:
|
|
return "BGV"
|
|
default:
|
|
return "Unknown"
|
|
}
|
|
}
|