/// <summary> /// Initialize this class /// </summary> /// /// <param name="Keysize">The length of a Goppa code</param> /// <param name="OId">Three bytes that uniquely identify the parameter set</param> /// <param name="CCA2Engine">The McEliece CCA2 cipher engine</param> /// <param name="Digest">The digest used by the cipher engine</param> /// <param name="Prng">The Prng used by the cipher</param> /// /// <exception cref="MPKCException">Thrown if <c>keysize < 1</c></exception> public MPKCParameters(int Keysize, byte[] OId, McElieceCiphers CCA2Engine = McElieceCiphers.Fujisaki, Digests Digest = Digests.SHA256, Prngs Prng = Prngs.CTRPrng) { if (Keysize < 1) { throw new MPKCException("MPKCParameters:Ctor", "The key size must be positive!", new ArgumentException()); } this.Digest = Digest; this.CCA2Engine = CCA2Engine; this.RandomEngine = Prng; Array.Copy(OId, this.OId, Math.Min(OId.Length, 3)); _M = 0; _N = 1; while (_N < Keysize) { _N <<= 1; _M++; } _T = _N >> 1; _T /= _M; _fieldPoly = PolynomialRingGF2.GetIrreduciblePolynomial(_M); }
/// <summary> /// Initialize this class /// </summary> /// /// <param name="M">The degree of the finite field GF(2^m)</param> /// <param name="T">The error correction capability of the code</param> /// <param name="OId">Three bytes that uniquely identify the parameter set</param> /// <param name="CCA2Engine">The McEliece CCA2 cipher engine</param> /// <param name="Digest">The digest used by the cipher engine</param> /// <param name="Prng">The Prng used by the cipher</param> /// /// <exception cref="MPKCException">Thrown if; <c>m < 1</c>, <c>m > 32</c>, <c>t < 0</c> or <c>t > n</c></exception> public MPKCParameters(int M, int T, byte[] OId, McElieceCiphers CCA2Engine = McElieceCiphers.Fujisaki, Digests Digest = Digests.SHA256, Prngs Prng = Prngs.CTRPrng) { if (M < 1) { throw new MPKCException("MPKCParameters:Ctor", "M must be positive!", new ArgumentException()); } if (M > 32) { throw new MPKCException("MPKCParameters:Ctor", "M is too large!", new ArgumentOutOfRangeException()); } this.Digest = Digest; this.CCA2Engine = CCA2Engine; this.RandomEngine = Prng; Array.Copy(OId, this.OId, Math.Min(OId.Length, 3)); _M = M; _N = 1 << M; if (T < 0) { throw new MPKCException("MPKCParameters:Ctor", "T must be positive!", new ArgumentException()); } if (T > N) { throw new MPKCException("MPKCParameters:Ctor", "T must be less than n = 2^m!", new ArgumentOutOfRangeException()); } _T = T; _fieldPoly = PolynomialRingGF2.GetIrreduciblePolynomial(M); }
/// <summary> /// Set the default parameters: extension degree /// </summary> /// /// <param name="OId">Three bytes that uniquely identify the parameter set</param> /// <param name="CCA2Engine">The McEliece CCA2 cipher engine</param> /// <param name="Digest">The digest used by the cipher engine</param> /// <param name="Prng">The prng used by the cipher engine</param> public MPKCParameters(byte[] OId, McElieceCiphers CCA2Engine = McElieceCiphers.Fujisaki, Digests Digest = Digests.SHA256, Prngs Prng = Prngs.CTRPrng) : this(DEFAULT_M, DEFAULT_T, OId) { this.Digest = Digest; this.CCA2Engine = CCA2Engine; this.RandomEngine = Prng; }
/// <summary> /// Read a Parameters file from a byte array. /// </summary> /// /// <param name="ParamStream">The byte array containing the params</param> /// /// <returns>An initialized MPKCParameters class</returns> public static MPKCParameters From(Stream ParamStream) { try { BinaryReader reader = new BinaryReader(ParamStream); McElieceCiphers eng = (McElieceCiphers)reader.ReadInt32(); Digests dgt = (Digests)reader.ReadInt32(); Prngs rnd = (Prngs)reader.ReadInt32(); int m = reader.ReadInt32(); int t = reader.ReadInt32(); int fp = reader.ReadInt32(); byte[] oid = reader.ReadBytes(3); return(new MPKCParameters(m, t, fp, oid, eng, dgt, rnd)); } catch { throw; } }
/// <summary> /// Initialize this class /// </summary> /// /// <param name="M">The degree of the finite field GF(2^m)</param> /// <param name="T">The error correction capability of the code</param> /// <param name="FieldPoly">The field polynomial</param> /// <param name="OId">Three bytes that uniquely identify the parameter set</param> /// <param name="CCA2Engine">The McEliece CCA2 cipher engine</param> /// <param name="Digest">The digest used by the cipher engine</param> /// <param name="Prng">The Prng used by the cipher</param> /// /// <exception cref="MPKCException">Thrown if; <c>t < 0</c>, <c>t > n</c>, or <c>poly</c> is not an irreducible field polynomial</exception> public MPKCParameters(int M, int T, int FieldPoly, byte[] OId, McElieceCiphers CCA2Engine = McElieceCiphers.Fujisaki, Digests Digest = Digests.SHA256, Prngs Prng = Prngs.CTRPrng) { if (M < 1) { throw new MPKCException("MPKCParameters:Ctor", "M must be positive!", new ArgumentException()); } if (M > 32) { throw new MPKCException("MPKCParameters:Ctor", "M is too large!", new ArgumentOutOfRangeException()); } _M = M; this.Digest = Digest; this.CCA2Engine = CCA2Engine; this.RandomEngine = Prng; Array.Copy(OId, this.OId, Math.Min(OId.Length, 3)); _N = 1 << M; _T = T; if (T < 0) { throw new MPKCException("MPKCParameters:Ctor", "T must be positive!", new ArgumentException()); } if (T > N) { throw new MPKCException("MPKCParameters:Ctor", "T must be less than n = 2^m!", new ArgumentOutOfRangeException()); } if ((PolynomialRingGF2.Degree(FieldPoly) == M) && (PolynomialRingGF2.IsIrreducible(FieldPoly))) { _fieldPoly = FieldPoly; } else { throw new MPKCException("MPKCParameters:Ctor", "Polynomial is not a field polynomial for GF(2^m)", new InvalidDataException()); } }
/// <summary> /// Initialize this class /// </summary> /// /// <param name="M">The degree of the finite field GF(2^m)</param> /// <param name="T">The error correction capability of the code</param> /// <param name="FieldPoly">The field polynomial</param> /// <param name="OId">Three bytes that uniquely identify the parameter set</param> /// <param name="CCA2Engine">The McEliece CCA2 cipher engine</param> /// <param name="Digest">The digest used by the cipher engine</param> /// <param name="Prng">The Prng used by the cipher</param> /// /// <exception cref="MPKCException">Thrown if; <c>t < 0</c>, <c>t > n</c>, or <c>poly</c> is not an irreducible field polynomial</exception> public MPKCParameters(int M, int T, int FieldPoly, byte[] OId, McElieceCiphers CCA2Engine = McElieceCiphers.Fujisaki, Digests Digest = Digests.SHA256, Prngs Prng = Prngs.CTRPrng) { if (M < 1) throw new MPKCException("MPKCParameters:Ctor", "M must be positive!", new ArgumentException()); if (M > 32) throw new MPKCException("MPKCParameters:Ctor", "M is too large!", new ArgumentOutOfRangeException()); _M = M; this.Digest = Digest; this.CCA2Engine = CCA2Engine; this.RandomEngine = Prng; Array.Copy(OId, this.OId, Math.Min(OId.Length, 3)); _N = 1 << M; _T = T; if (T < 0) throw new MPKCException("MPKCParameters:Ctor", "T must be positive!", new ArgumentException()); if (T > N) throw new MPKCException("MPKCParameters:Ctor", "T must be less than n = 2^m!", new ArgumentOutOfRangeException()); if ((PolynomialRingGF2.Degree(FieldPoly) == M) && (PolynomialRingGF2.IsIrreducible(FieldPoly))) _fieldPoly = FieldPoly; else throw new MPKCException("MPKCParameters:Ctor", "Polynomial is not a field polynomial for GF(2^m)", new InvalidDataException()); }
/// <summary> /// Initialize this class /// </summary> /// /// <param name="M">The degree of the finite field GF(2^m)</param> /// <param name="T">The error correction capability of the code</param> /// <param name="OId">Three bytes that uniquely identify the parameter set</param> /// <param name="CCA2Engine">The McEliece CCA2 cipher engine</param> /// <param name="Digest">The digest used by the cipher engine</param> /// <param name="Prng">The Prng used by the cipher</param> /// /// <exception cref="MPKCException">Thrown if; <c>m < 1</c>, <c>m > 32</c>, <c>t < 0</c> or <c>t > n</c></exception> public MPKCParameters(int M, int T, byte[] OId, McElieceCiphers CCA2Engine = McElieceCiphers.Fujisaki, Digests Digest = Digests.SHA256, Prngs Prng = Prngs.CTRPrng) { if (M < 1) throw new MPKCException("MPKCParameters:Ctor", "M must be positive!", new ArgumentException()); if (M > 32) throw new MPKCException("MPKCParameters:Ctor", "M is too large!", new ArgumentOutOfRangeException()); this.Digest = Digest; this.CCA2Engine = CCA2Engine; this.RandomEngine = Prng; Array.Copy(OId, this.OId, Math.Min(OId.Length, 3)); _M = M; _N = 1 << M; if (T < 0) throw new MPKCException("MPKCParameters:Ctor", "T must be positive!", new ArgumentException()); if (T > N) throw new MPKCException("MPKCParameters:Ctor", "T must be less than n = 2^m!", new ArgumentOutOfRangeException()); _T = T; _fieldPoly = PolynomialRingGF2.GetIrreduciblePolynomial(M); }
/// <summary> /// Initialize this class /// </summary> /// /// <param name="Keysize">The length of a Goppa code</param> /// <param name="OId">Three bytes that uniquely identify the parameter set</param> /// <param name="CCA2Engine">The McEliece CCA2 cipher engine</param> /// <param name="Digest">The digest used by the cipher engine</param> /// <param name="Prng">The Prng used by the cipher</param> /// /// <exception cref="MPKCException">Thrown if <c>keysize < 1</c></exception> public MPKCParameters(int Keysize, byte[] OId, McElieceCiphers CCA2Engine = McElieceCiphers.Fujisaki, Digests Digest = Digests.SHA256, Prngs Prng = Prngs.CTRPrng) { if (Keysize < 1) throw new MPKCException("MPKCParameters:Ctor", "The key size must be positive!", new ArgumentException()); this.Digest = Digest; this.CCA2Engine = CCA2Engine; this.RandomEngine = Prng; Array.Copy(OId, this.OId, Math.Min(OId.Length, 3)); _M = 0; _N = 1; while (_N < Keysize) { _N <<= 1; _M++; } _T = _N >> 1; _T /= _M; _fieldPoly = PolynomialRingGF2.GetIrreduciblePolynomial(_M); }