/** * Constructs a new private key from an input stream * @param is an input stream * @throws NtruException if an {@link IOException} occurs */ public SignaturePrivateKey(MemoryStream ins) { bases = new List<Basis>(); BinaryReader dataStream = new BinaryReader(ins); try { N = dataStream.ReadInt16(); q = dataStream.ReadInt16(); byte flags = dataStream.ReadByte(); sparse = (flags & 1) != 0; polyType = (flags & 4) == 0 ? TernaryPolynomialType.SIMPLE : TernaryPolynomialType.PRODUCT; basisType = ((flags & 8) == 0) ? BasisType.STANDARD : BasisType.TRANSPOSE; keyNormBoundSq = (float)dataStream.ReadInt32(); int numBases = dataStream.ReadByte(); for (int i = 0; i < numBases; i++) // include a public key h[i] in all bases except for the first one add(new Basis(ins, N, q, sparse, polyType, basisType, keyNormBoundSq, i != 0)); } catch (IOException e) { throw new NtruException(e.Message); } }
/** * Reads a basis from an input stream and constructs a new basis. * @param is an input stream * @param params NtruSign parameters * @param include_h whether to read the polynomial <code>h</code> (<code>true</code>) or only <code>f</code> and <code>f'</code> (<code>false</code>) * @throws IOException */ public Basis(MemoryStream ins, int N, int q, bool sparse, TernaryPolynomialType polyType, BasisType basisType, double keyNormBoundSq, bool include_h) { this.N = N; this.q = q; this.polyType = polyType; this.basisType = basisType; this.keyNormBoundSq = keyNormBoundSq; if (polyType == TernaryPolynomialType.PRODUCT) f = ProductFormPolynomial.FromBinary(ins, N); else { IntegerPolynomial fInt = IntegerPolynomial.FromBinary3Tight(ins, N); if (sparse) f = new SparseTernaryPolynomial(fInt); else f = new DenseTernaryPolynomial(fInt); } if (basisType == BasisType.STANDARD) { IntegerPolynomial fPrimeInt = IntegerPolynomial.FromBinary(ins, N, q); for (int i = 0; i < fPrimeInt.Coeffs.Length; i++) fPrimeInt.Coeffs[i] -= q / 2; fPrime = fPrimeInt; } else if (polyType == TernaryPolynomialType.PRODUCT) fPrime = ProductFormPolynomial.FromBinary(ins, N); else fPrime = IntegerPolynomial.FromBinary3Tight(ins, N); if (include_h) h = IntegerPolynomial.FromBinary(ins, N, q); }
public ImplicitFractal(FractalType fractalType, BasisType basisType, InterpolationType interpolationType) { this.Octaves = 8; this.Frequency = 1.00; this.Lacunarity = 2.00; this.Type = fractalType; this.SetAllSourceTypes(basisType, interpolationType); this.ResetAllSources(); }
public ImplicitFractal(FractalType fractalType, BasisType basisType, InterpolationType interpolationType, Int32 octaves, double frequency, Int32 seed) { this.seed = seed; this.Octaves = octaves; this.Frequency = frequency; this.Lacunarity = 2.00; this.Type = fractalType; this.SetAllSourceTypes(basisType, interpolationType); this.ResetAllSources(); }
/** * Constructs a new basis from polynomials <code>f, f', h</code>. * @param f * @param fPrime * @param h * @param params NtruSign parameters */ public Basis(IPolynomial f, IPolynomial fPrime, IntegerPolynomial h, int q, TernaryPolynomialType polyType, BasisType basisType, double keyNormBoundSq) { this.f = f; this.fPrime = fPrime; this.h = h; this.N = h.Coeffs.Length; this.q = q; this.polyType = polyType; this.basisType = basisType; this.keyNormBoundSq = keyNormBoundSq; }
/** * Constructs a private key that contains no bases */ public SignaturePrivateKey(SignatureParameters param) { N = param.N; q = param.q; sparse = param.sparse; polyType = param.polyType; basisType = param.basisType; keyNormBoundSq = param.keyNormBoundSq; bases = new List<Basis>(); }
/** * Constructs a parameter set that uses ternary private keys (i.e. </code>polyType=SIMPLE</code>). * @param N number of polynomial coefficients * @param q modulus * @param d number of -1's in the private polynomials <code>f</code> and <code>g</code> * @param B number of perturbations * @param basisType whether to use the standard or transpose lattice * @param beta balancing factor for the transpose lattice * @param normBound maximum norm for valid signatures * @param keyNormBound maximum norm for the polynomials <code>F</code> and <code>G</code> * @param primeCheck whether <code>2N+1</code> is prime * @param sparse whether to treat ternary polynomials as sparsely populated ({@link SparseTernaryPolynomial} vs {@link DenseTernaryPolynomial}) * @param keyGenAlg <code>RESULTANT</code> produces better bases, <code>FLOAT</code> is slightly faster. <code>RESULTANT</code> follows the EESS standard while <code>FLOAT</code> is described in Hoffstein et al: An Introduction to Mathematical Cryptography. * @param hashAlg a valid identifier for a <code>java.security.MessageDigest</code> instance such as <code>SHA-256</code>. The <code>MessageDigest</code> must support the <code>getDigestLength()</code> method. */ public SignatureParameters(int N, int q, int d, int B, BasisType basisType, float beta, float normBound, float keyNormBound, bool primeCheck, bool sparse, KeyGenAlg keyGenAlg, String hashAlg) { this.N = N; this.q = q; this.d = d; this.B = B; this.basisType = basisType; this.beta = beta; this.normBound = normBound; this.keyNormBound = keyNormBound; this.primeCheck = primeCheck; this.sparse = sparse; this.keyGenAlg = keyGenAlg; this.hashAlg = hashAlg; polyType = TernaryPolynomialType.SIMPLE; init(); }
public ImplicitBasisFunction(BasisType basisType = BasisType.Gradient, InterpolationType interpolationType = InterpolationType.Quintic) { BasisType = basisType; InterpolationType = interpolationType; Seed = (int)DateTime.Now.Ticks; }
public FGBasis(IPolynomial f, IPolynomial fPrime, IntegerPolynomial h, IntegerPolynomial F, IntegerPolynomial G, int q, TernaryPolynomialType polyType, BasisType basisType, double keyNormBoundSq) : base(f, fPrime, h, q, polyType, basisType, keyNormBoundSq) { ; this.F = F; this.G = G; this.q = q; this.keyNormBoundSq = keyNormBoundSq; }
public ImplicitBasisFunction(BasisType basisType, InterpolationType interpolationType, int seed) { this.BasisType = basisType; this.InterpolationType = interpolationType; this.Seed = seed; }
private void SetMagicNumbers(BasisType type) { // This function is a damned hack. // The underlying noise functions don't return values in the range [-1,1] cleanly, and the ranges vary depending // on basis type and dimensionality. There's probably a better way to correct the ranges, but for now I'm just // setting he magic numbers scale and offset manually to empirically determined magic numbers. switch (type) { case BasisType.VALUE: this.scale[0] = 1.0; this.offset[0] = 0.0; this.scale[1] = 1.0; this.offset[1] = 0.0; this.scale[2] = 1.0; this.offset[2] = 0.0; this.scale[3] = 1.0; this.offset[3] = 0.0; break; case BasisType.GRADIENT: this.scale[0] = 1.86848; this.offset[0] = -0.000118; this.scale[1] = 1.85148; this.offset[1] = -0.008272; this.scale[2] = 1.64127; this.offset[2] = -0.01527; this.scale[3] = 1.92517; this.offset[3] = 0.03393; break; case BasisType.GRADIENTVALUE: this.scale[0] = 0.6769; this.offset[0] = -0.00151; this.scale[1] = 0.6957; this.offset[1] = -0.133; this.scale[2] = 0.74622; this.offset[2] = 0.01916; this.scale[3] = 0.7961; this.offset[3] = -0.0352; break; case BasisType.WHITE: this.scale[0] = 1.0; this.offset[0] = 0.0; this.scale[1] = 1.0; this.offset[1] = 0.0; this.scale[2] = 1.0; this.offset[2] = 0.0; this.scale[3] = 1.0; this.offset[3] = 0.0; break; default: this.scale[0] = 1.0; this.offset[0] = 0.0; this.scale[1] = 1.0; this.offset[1] = 0.0; this.scale[2] = 1.0; this.offset[2] = 0.0; this.scale[3] = 1.0; this.offset[3] = 0.0; break; } }
private void button1_Click(object sender, EventArgs e) { switch (comboBox1.Text.ToLower()) { case "line": TargetBasis = BasisType.Line; break; case "parabolic": TargetBasis = BasisType.Parabolic; break; case "cubic": TargetBasis = BasisType.Cubic; break; case "gaussian": TargetBasis = BasisType.Gaussian; break; case "cubic/parabolic": TargetBasis = BasisType.CubicParabolic; break; } CreateNewTargetSurface(); }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { switch (comboBox1.Text.ToLower()) { case "line": Basis = BasisType.Line; break; case "parabolic": Basis = BasisType.Parabolic; break; case "cubic": Basis = BasisType.Cubic; break; case "gaussian": Basis = BasisType.Gaussian; break; case "cubic/parabolic": Basis = BasisType.CubicParabolic; break; } }
/** * Reads a parameter set from an input stream. * @param is an input stream * @throws IOException */ public SignatureParameters(MemoryStream ins) { BinaryReader dis = new BinaryReader(ins); N = dis.ReadInt32(); q = dis.ReadInt32(); d = dis.ReadInt32(); d1 = dis.ReadInt32(); d2 = dis.ReadInt32(); d3 = dis.ReadInt32(); B = dis.ReadInt32(); basisType = (BasisType)dis.ReadInt32(); beta = dis.ReadSingle(); normBound = dis.ReadSingle(); keyNormBound = dis.ReadSingle(); signFailTolerance = dis.ReadInt32(); primeCheck = dis.ReadBoolean(); sparse = dis.ReadBoolean(); bitsF = dis.ReadInt32(); keyGenAlg = (KeyGenAlg)dis.ReadInt32(); hashAlg = dis.ReadString(); polyType = (TernaryPolynomialType)dis.ReadInt32(); init(); }
public void SetAllSourceTypes(BasisType newBasisType, InterpolationType newInterpolationType) { for (var i = 0; i < Noise.MAX_SOURCES; ++i) { this.basisFunctions[i] = new ImplicitBasisFunction(newBasisType, newInterpolationType); } }
/** * Reads a basis from an input stream and constructs a new basis. * @param is an input stream * @param params NtruSign parameters * @param include_h whether to read the polynomial <code>h</code> (<code>true</code>) or only <code>f</code> and <code>f'</code> (<code>false</code>) * @throws IOException */ public Basis(MemoryStream ins, int N, int q, bool sparse, TernaryPolynomialType polyType, BasisType basisType, double keyNormBoundSq, bool include_h) { this.N = N; this.q = q; this.polyType = polyType; this.basisType = basisType; this.keyNormBoundSq = keyNormBoundSq; if (polyType == TernaryPolynomialType.PRODUCT) { f = ProductFormPolynomial.FromBinary(ins, N); } else { IntegerPolynomial fInt = IntegerPolynomial.FromBinary3Tight(ins, N); if (sparse) { f = new SparseTernaryPolynomial(fInt); } else { f = new DenseTernaryPolynomial(fInt); } } if (basisType == BasisType.STANDARD) { IntegerPolynomial fPrimeInt = IntegerPolynomial.FromBinary(ins, N, q); for (int i = 0; i < fPrimeInt.Coeffs.Length; i++) { fPrimeInt.Coeffs[i] -= q / 2; } fPrime = fPrimeInt; } else if (polyType == TernaryPolynomialType.PRODUCT) { fPrime = ProductFormPolynomial.FromBinary(ins, N); } else { fPrime = IntegerPolynomial.FromBinary3Tight(ins, N); } if (include_h) { h = IntegerPolynomial.FromBinary(ins, N, q); } }
public ImplicitBasisFunction(BasisType basisType = BasisType.Gradient, InterpolationType interpolationType = InterpolationType.Quintic) { this.BasisType = basisType; this.InterpolationType = interpolationType; this.Seed = (Int32)DateTime.Now.Ticks; }
private void SetMagicNumbers(BasisType type) { // This function is a damned hack. // The underlying noise functions don't return values in the range [-1,1] cleanly, and the ranges vary depending // on basis type and dimensionality. There's probably a better way to correct the ranges, but for now I'm just // setting he magic numbers scale and offset manually to empirically determined magic numbers. switch (type) { case BasisType.Value: this.scale[0] = 1.0; this.offset[0] = 0.0; this.scale[1] = 1.0; this.offset[1] = 0.0; this.scale[2] = 1.0; this.offset[2] = 0.0; this.scale[3] = 1.0; this.offset[3] = 0.0; break; case BasisType.Gradient: this.scale[0] = 1.86848; this.offset[0] = -0.000118; this.scale[1] = 1.85148; this.offset[1] = -0.008272; this.scale[2] = 1.64127; this.offset[2] = -0.01527; this.scale[3] = 1.92517; this.offset[3] = 0.03393; break; case BasisType.GradientValue: this.scale[0] = 0.6769; this.offset[0] = -0.00151; this.scale[1] = 0.6957; this.offset[1] = -0.133; this.scale[2] = 0.74622; this.offset[2] = 0.01916; this.scale[3] = 0.7961; this.offset[3] = -0.0352; break; case BasisType.White: this.scale[0] = 1.0; this.offset[0] = 0.0; this.scale[1] = 1.0; this.offset[1] = 0.0; this.scale[2] = 1.0; this.offset[2] = 0.0; this.scale[3] = 1.0; this.offset[3] = 0.0; break; default: this.scale[0] = 1.0; this.offset[0] = 0.0; this.scale[1] = 1.0; this.offset[1] = 0.0; this.scale[2] = 1.0; this.offset[2] = 0.0; this.scale[3] = 1.0; this.offset[3] = 0.0; break; } }
public void SetSourceType(Int32 which, BasisType newBasisType, InterpolationType newInterpolationType) { if (which >= Noise.MAX_SOURCES || which < 0) return; this.basisFunctions[which].BasisType = newBasisType; this.basisFunctions[which].InterpolationType = newInterpolationType; }