/// <summary> /// Initialize this class /// </summary> /// /// <param name="OId">OId - Unique identifier; <c>Family</c>, <c>Set</c>, <c>SubSet</c>, and <c>Designator</c>. The McEliece family must be <c>1</c> corresponding with the <see cref="AsymmetricEngines"/> enumeration.</param> /// <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="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="CryptoAsymmetricException">Thrown if the OId is invalid or; <c>t < 0</c>, <c>t > n</c>, or <c>poly</c> is not an irreducible field polynomial</exception> public MPKCParameters(byte[] OId, int M, int T, int FieldPoly, CCA2Ciphers CCA2Engine = CCA2Ciphers.Fujisaki, Digests Digest = Digests.SHA256, Prngs Prng = Prngs.CTRPrng) { if (OId.Length != OID_SIZE) { throw new CryptoAsymmetricException("MPKCParameters:Ctor", string.Format("The OId is invalid, the OId length must be {0} bytes!", OID_SIZE, new ArgumentException())); } if (OId[0] != (byte)AsymmetricEngines.McEliece) { throw new CryptoAsymmetricException("MPKCParameters:Ctor", string.Format("The OId is invalid, first byte must be family designator ({0})!", AsymmetricEngines.McEliece, new ArgumentException())); } if (M < 1) { throw new CryptoAsymmetricException("MPKCParameters:Ctor", "M must be positive!", new ArgumentException()); } if (M > 32) { throw new CryptoAsymmetricException("MPKCParameters:Ctor", "M is too large!", new ArgumentOutOfRangeException()); } m_M = M; this.Digest = Digest; this.CCA2Engine = CCA2Engine; this.RandomEngine = Prng; Array.Copy(OId, this.OId, Math.Min(OId.Length, OID_SIZE)); m_N = 1 << M; m_T = T; if (T < 0) { throw new CryptoAsymmetricException("MPKCParameters:Ctor", "T must be positive!", new ArgumentException()); } if (T > N) { throw new CryptoAsymmetricException("MPKCParameters:Ctor", "T must be less than n = 2^m!", new ArgumentOutOfRangeException()); } if ((PolynomialRingGF2.Degree(FieldPoly) == M) && (PolynomialRingGF2.IsIrreducible(FieldPoly))) { m_fieldPoly = FieldPoly; } else { throw new CryptoAsymmetricException("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()); } }