// Lattice-based cryptographic parameter sets. // // Security rests on the hardness of the Shortest Vector Problem (SVP) // on ideal lattices. Parameter dimensions are chosen to resist both // classical and quantum lattice reduction (BKZ + Grover). package crypto import "git.smesh.lol/gnarl-hamadryad/ratio" // SecurityLevel specifies cryptographic strength. type SecurityLevel uint8 const ( Security128 SecurityLevel = iota Security192 Security256 ) // Params holds the parameters for a lattice-based cryptographic instance. type Params struct { // N is the lattice dimension — number of constraint sites. // Higher N = harder CVP = more security. N int // Q is the modulus for arithmetic operations. // Integer-valued ratio (Denom == 1). Q ratio.Ratio // SmoothingParam is the dissolution threshold below which // the lattice structure disappears into noise. This is eta_eps. SmoothingParam ratio.Ratio // NoiseWidth controls the spread of the discrete Gaussian. // More noise = more security, less noise = more reliable decryption. // Must satisfy: SmoothingParam < NoiseWidth < 1. NoiseWidth ratio.Ratio // MaxWalkSteps limits Brownian walk length during encryption. MaxWalkSteps int // DissolutionPasses is how many dissolution scans to run // after bonding, to add the LWE noise term. DissolutionPasses int } // DefaultParams returns parameters for a given security level. // // 128-bit: N=256, Q=127/1, noise=3/10, smoothing=2/10 // 192-bit: N=384, Q=251/1, noise=3/10, smoothing=2/10 // 256-bit: N=512, Q=509/1, noise=3/10, smoothing=2/10 func DefaultParams(level SecurityLevel) Params { switch level { case Security192: return Params{ N: 384, Q: ratio.FromInt(251), SmoothingParam: ratio.New(2, 10), NoiseWidth: ratio.New(3, 10), MaxWalkSteps: 1600, // 10^2 x 2^4 -- epoch-aligned DissolutionPasses: 3, } case Security256: return Params{ N: 512, Q: ratio.FromInt(509), SmoothingParam: ratio.New(2, 10), NoiseWidth: ratio.New(3, 10), MaxWalkSteps: 2000, // 10^3 x 2^1 -- epoch-aligned DissolutionPasses: 4, } default: // Security128 return Params{ N: 256, Q: ratio.FromInt(127), SmoothingParam: ratio.New(2, 10), NoiseWidth: ratio.New(3, 10), MaxWalkSteps: 1024, // 2^10 -- epoch-aligned with N=256=2^8 DissolutionPasses: 2, } } } // Valid reports whether the parameters are internally consistent. func (p Params) Valid() bool { if p.N <= 0 { return false } if !p.Q.IsPositive() || p.Q.Denom != 1 { return false // Q must be a positive integer } if !p.SmoothingParam.IsPositive() { return false } if !p.NoiseWidth.IsPositive() { return false } // SmoothingParam < NoiseWidth < 1 if !p.SmoothingParam.Less(p.NoiseWidth) { return false } if !p.NoiseWidth.Less(ratio.One) { return false } if p.MaxWalkSteps <= 0 { return false } if p.DissolutionPasses <= 0 { return false } return true }