// Lattice-based cryptographic parameter sets. package hamcrypto import "git.smesh.lol/gnarl-hamadryad/moxie/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 int32 Q ratio.Ratio SmoothingParam ratio.Ratio NoiseWidth ratio.Ratio MaxWalkSteps int32 DissolutionPasses int32 } // DefaultParams returns parameters for a given security level. func DefaultParams(level SecurityLevel) (p 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, DissolutionPasses: 3, } case Security256: return Params{ N: 512, Q: ratio.FromInt(509), SmoothingParam: ratio.New(2, 10), NoiseWidth: ratio.New(3, 10), MaxWalkSteps: 2000, DissolutionPasses: 4, } default: return Params{ N: 256, Q: ratio.FromInt(127), SmoothingParam: ratio.New(2, 10), NoiseWidth: ratio.New(3, 10), MaxWalkSteps: 1024, DissolutionPasses: 2, } } } // Valid reports whether the parameters are internally consistent. func (p *Params) Valid() (ok bool) { if p.N <= 0 { return false } if !p.Q.IsPositive() || p.Q.Denom != 1 { return false } if !p.SmoothingParam.IsPositive() { return false } if !p.NoiseWidth.IsPositive() { return false } 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 }