Base class for an elliptic curve.
コード例 #1
0
ファイル: X9ECParameters.cs プロジェクト: woutersmit/NBitcoin
 public X9ECParameters(
     ECCurve		curve,
     ECPoint		g,
     BigInteger	n)
     : this(curve, g, n, BigInteger.One, null)
 {
 }
コード例 #2
0
ファイル: ECCurve.cs プロジェクト: woutersmit/NBitcoin
 internal Config(ECCurve outer, int coord, ECEndomorphism endomorphism, ECMultiplier multiplier)
 {
     this.outer = outer;
     this.coord = coord;
     this.endomorphism = endomorphism;
     this.multiplier = multiplier;
 }
コード例 #3
0
 public ECDomainParameters(
     ECCurve     curve,
     ECPoint     g,
     BigInteger  n)
     : this(curve, g, n, BigInteger.One)
 {
 }
コード例 #4
0
ファイル: ECPoint.cs プロジェクト: woutersmit/NBitcoin
        protected static ECFieldElement[] GetInitialZCoords(ECCurve curve)
        {
            // Cope with null curve, most commonly used by implicitlyCa
            int coord = null == curve ? ECCurve.COORD_AFFINE : curve.CoordinateSystem;

            switch (coord)
            {
                case ECCurve.COORD_AFFINE:
                case ECCurve.COORD_LAMBDA_AFFINE:
                    return EMPTY_ZS;
                default:
                    break;
            }

            ECFieldElement one = curve.FromBigInteger(BigInteger.One);

            switch (coord)
            {
                case ECCurve.COORD_HOMOGENEOUS:
                case ECCurve.COORD_JACOBIAN:
                case ECCurve.COORD_LAMBDA_PROJECTIVE:
                    return new ECFieldElement[] { one };
                case ECCurve.COORD_JACOBIAN_CHUDNOVSKY:
                    return new ECFieldElement[] { one, one, one };
                case ECCurve.COORD_JACOBIAN_MODIFIED:
                    return new ECFieldElement[] { one, curve.A };
                default:
                    throw new ArgumentException("unknown coordinate system");
            }
        }
コード例 #5
0
ファイル: ECPoint.cs プロジェクト: woutersmit/NBitcoin
 internal ECPoint(ECCurve curve, ECFieldElement x, ECFieldElement y, ECFieldElement[] zs, bool withCompression)
 {
     this.m_curve = curve;
     this.m_x = x;
     this.m_y = y;
     this.m_zs = zs;
     this.m_withCompression = withCompression;
 }
コード例 #6
0
ファイル: X9ECParameters.cs プロジェクト: Nethereum/Nethereum
		public X9ECParameters(
			ECCurve curve,
			X9ECPoint g,
			BigInteger n,
			BigInteger h)
			: this(curve, g, n, h, null)
		{
		}
コード例 #7
0
 public ECDomainParameters(
     ECCurve     curve,
     ECPoint     g,
     BigInteger  n,
     BigInteger  h)
     : this(curve, g, n, h, null)
 {
 }
コード例 #8
0
ファイル: X9ECParameters.cs プロジェクト: Nethereum/Nethereum
		public X9ECParameters(
			ECCurve curve,
			ECPoint g,
			BigInteger n,
			BigInteger h,
			byte[] seed)
			: this(curve, new X9ECPoint(g), n, h, seed)
		{
		}
コード例 #9
0
ファイル: X9Curve.cs プロジェクト: woutersmit/NBitcoin
        public X9Curve(
            X9FieldID		fieldID,
            Asn1Sequence	seq)
        {
            if (fieldID == null)
                throw new ArgumentNullException("fieldID");
            if (seq == null)
                throw new ArgumentNullException("seq");

            this.fieldIdentifier = fieldID.Identifier;

            if (fieldIdentifier.Equals(X9ObjectIdentifiers.PrimeField))
            {
                BigInteger q = ((DerInteger) fieldID.Parameters).Value;
                X9FieldElement x9A = new X9FieldElement(q, (Asn1OctetString) seq[0]);
                X9FieldElement x9B = new X9FieldElement(q, (Asn1OctetString) seq[1]);
                curve = new FpCurve(q, x9A.Value.ToBigInteger(), x9B.Value.ToBigInteger());
            }
            else
            {
                if (fieldIdentifier.Equals(X9ObjectIdentifiers.CharacteristicTwoField)) 
                {
                    // Characteristic two field
                    DerSequence parameters = (DerSequence)fieldID.Parameters;
                    int m = ((DerInteger)parameters[0]).Value.IntValue;
                    DerObjectIdentifier representation
                        = (DerObjectIdentifier)parameters[1];

                    int k1 = 0;
                    int k2 = 0;
                    int k3 = 0;
                    if (representation.Equals(X9ObjectIdentifiers.TPBasis)) 
                    {
                        // Trinomial basis representation
                        k1 = ((DerInteger)parameters[2]).Value.IntValue;
                    }
                    else 
                    {
                        // Pentanomial basis representation
                        DerSequence pentanomial = (DerSequence) parameters[2];
                        k1 = ((DerInteger) pentanomial[0]).Value.IntValue;
                        k2 = ((DerInteger) pentanomial[1]).Value.IntValue;
                        k3 = ((DerInteger) pentanomial[2]).Value.IntValue;
                    }
                    X9FieldElement x9A = new X9FieldElement(m, k1, k2, k3, (Asn1OctetString)seq[0]);
                    X9FieldElement x9B = new X9FieldElement(m, k1, k2, k3, (Asn1OctetString)seq[1]);
                    // TODO Is it possible to get the order (n) and cofactor(h) too?
                    curve = new F2mCurve(m, k1, k2, k3, x9A.Value.ToBigInteger(), x9B.Value.ToBigInteger());
                }
            }

            if (seq.Count == 3)
            {
                seed = ((DerBitString) seq[2]).GetBytes();
            }
        }
コード例 #10
0
ファイル: X9ECParameters.cs プロジェクト: woutersmit/NBitcoin
        public X9ECParameters(
            Asn1Sequence seq)
        {
            if (!(seq[0] is DerInteger)
               || !((DerInteger) seq[0]).Value.Equals(BigInteger.One))
            {
                throw new ArgumentException("bad version in X9ECParameters");
            }

            X9Curve x9c = null;
            if (seq[2] is X9Curve)
            {
                x9c = (X9Curve) seq[2];
            }
            else
            {
                x9c = new X9Curve(
                    new X9FieldID(
                        (Asn1Sequence) seq[1]),
                        (Asn1Sequence) seq[2]);
            }

            this.curve = x9c.Curve;

            if (seq[3] is X9ECPoint)
            {
                this.g = ((X9ECPoint) seq[3]).Point;
            }
            else
            {
                this.g = new X9ECPoint(curve, (Asn1OctetString) seq[3]).Point;
            }

            this.n = ((DerInteger) seq[4]).Value;
            this.seed = x9c.GetSeed();

            if (seq.Count == 6)
            {
                this.h = ((DerInteger) seq[5]).Value;
            }
        }
コード例 #11
0
ファイル: X9ECParameters.cs プロジェクト: woutersmit/NBitcoin
        public X9ECParameters(
            ECCurve		curve,
            ECPoint		g,
            BigInteger	n,
            BigInteger	h,
            byte[]		seed)
        {
            this.curve = curve;
            this.g = g.Normalize();
            this.n = n;
            this.h = h;
            this.seed = seed;

            if (ECAlgorithms.IsFpCurve(curve))
            {
                this.fieldID = new X9FieldID(curve.Field.Characteristic);
            }
            else if (ECAlgorithms.IsF2mCurve(curve))
            {
                IPolynomialExtensionField field = (IPolynomialExtensionField)curve.Field;
                int[] exponents = field.MinimalPolynomial.GetExponentsPresent();
                if (exponents.Length == 3)
                {
                    this.fieldID = new X9FieldID(exponents[2], exponents[1]);
                }
                else if (exponents.Length == 5)
                {
                    this.fieldID = new X9FieldID(exponents[4], exponents[1], exponents[2], exponents[3]);
                }
                else
                {
                    throw new ArgumentException("Only trinomial and pentomial curves are supported");
                }
            }
            else
            {
                throw new ArgumentException("'curve' is of an unsupported type");
            }
        }
コード例 #12
0
        public ECDomainParameters(
            ECCurve     curve,
            ECPoint     g,
            BigInteger  n,
            BigInteger  h,
            byte[]      seed)
        {
            if (curve == null)
                throw new ArgumentNullException("curve");
            if (g == null)
                throw new ArgumentNullException("g");
            if (n == null)
                throw new ArgumentNullException("n");
            if (h == null)
                throw new ArgumentNullException("h");

            this.curve = curve;
            this.g = g.Normalize();
            this.n = n;
            this.h = h;
            this.seed = Arrays.Clone(seed);
        }
コード例 #13
0
ファイル: X9Curve.cs プロジェクト: Nethereum/Nethereum
		public X9Curve(
			ECCurve curve,
			byte[] seed)
		{
			if(curve == null)
				throw new ArgumentNullException("curve");

			this.curve = curve;
			this.seed = Arrays.Clone(seed);

			if(ECAlgorithms.IsFpCurve(curve))
			{
				this.fieldIdentifier = X9ObjectIdentifiers.PrimeField;
			}
			else if(ECAlgorithms.IsF2mCurve(curve))
			{
				this.fieldIdentifier = X9ObjectIdentifiers.CharacteristicTwoField;
			}
			else
			{
				throw new ArgumentException("This type of ECCurve is not implemented");
			}
		}
コード例 #14
0
ファイル: X9Curve.cs プロジェクト: Nethereum/Nethereum
		public X9Curve(
			ECCurve curve)
			: this(curve, null)
		{
		}
コード例 #15
0
ファイル: ECPoint.cs プロジェクト: woutersmit/NBitcoin
 protected ECPoint(ECCurve curve, ECFieldElement	x, ECFieldElement y, bool withCompression)
     : this(curve, x, y, GetInitialZCoords(curve), withCompression)
 {
 }
コード例 #16
0
ファイル: ECCurve.cs プロジェクト: woutersmit/NBitcoin
 public virtual bool Equals(ECCurve other)
 {
     if (this == other)
         return true;
     if (null == other)
         return false;
     return Field.Equals(other.Field)
         && A.ToBigInteger().Equals(other.A.ToBigInteger())
         && B.ToBigInteger().Equals(other.B.ToBigInteger());
 }
コード例 #17
0
 public static bool IsF2mCurve(ECCurve c)
 {
     return(IsF2mField(c.Field));
 }
コード例 #18
0
ファイル: ECPoint.cs プロジェクト: woutersmit/NBitcoin
 protected AbstractFpPoint(ECCurve curve, ECFieldElement x, ECFieldElement y, ECFieldElement[] zs, bool withCompression)
     : base(curve, x, y, zs, withCompression)
 {
 }
コード例 #19
0
ファイル: SECNamedCurves.cs プロジェクト: Nethereum/Nethereum
		private static ECCurve ConfigureCurve(ECCurve curve)
		{
			return curve;
		}
コード例 #20
0
 public static int GetByteLength(ECCurve c)
 {
     return (c.FieldSize + 7) / 8;
 }
コード例 #21
0
ファイル: ECPoint.cs プロジェクト: woutersmit/NBitcoin
 /**
  * Create a point that encodes with or without point compression.
  *
  * @param curve the curve to use
  * @param x affine x co-ordinate
  * @param y affine y co-ordinate
  * @param withCompression if true encode with point compression
  */
 public FpPoint(ECCurve curve, ECFieldElement x, ECFieldElement y, bool withCompression)
     : base(curve, x, y, withCompression)
 {
     if ((x == null) != (y == null))
         throw new ArgumentException("Exactly one of the field elements is null");
 }
コード例 #22
0
ファイル: ECAlgorithms.cs プロジェクト: woutersmit/NBitcoin
 public static bool IsF2mCurve(ECCurve c)
 {
     IFiniteField field = c.Field;
     return field.Dimension > 1 && field.Characteristic.Equals(BigInteger.Two)
         && field is IPolynomialExtensionField;
 }
コード例 #23
0
ファイル: X9ECPoint.cs プロジェクト: woutersmit/NBitcoin
 public X9ECPoint(
     ECCurve			c,
     Asn1OctetString	s)
 {
     this.p = c.DecodePoint(s.GetOctets());
 }
コード例 #24
0
ファイル: ECAlgorithms.cs プロジェクト: crowar/NBitcoin
		public static bool IsFpCurve(ECCurve c)
		{
			return IsFpField(c.Field);
		}
コード例 #25
0
ファイル: X9ECPoint.cs プロジェクト: Nethereum/Nethereum
		public X9ECPoint(ECCurve c, byte[] encoding)
		{
			this.c = c;
			this.encoding = new DerOctetString(Arrays.Clone(encoding));
		}
コード例 #26
0
ファイル: X9ECPoint.cs プロジェクト: Nethereum/Nethereum
		public X9ECPoint(ECCurve c, Asn1OctetString s)
			: this(c, s.GetOctets())
		{
		}
コード例 #27
0
ファイル: ECPoint.cs プロジェクト: woutersmit/NBitcoin
 /**
  * Create a point which encodes without point compression.
  *
  * @param curve the curve to use
  * @param x affine x co-ordinate
  * @param y affine y co-ordinate
  */
 public FpPoint(ECCurve curve, ECFieldElement x, ECFieldElement y)
     : this(curve, x, y, false)
 {
 }
コード例 #28
0
ファイル: ECAlgorithms.cs プロジェクト: woutersmit/NBitcoin
        public static ECPoint ImportPoint(ECCurve c, ECPoint p)
        {
            ECCurve cp = p.Curve;
            if (!c.Equals(cp))
                throw new ArgumentException("Point must be on the same curve");

            return c.ImportPoint(p);
        }
コード例 #29
0
ファイル: ECPoint.cs プロジェクト: woutersmit/NBitcoin
 internal FpPoint(ECCurve curve, ECFieldElement x, ECFieldElement y, ECFieldElement[] zs, bool withCompression)
     : base(curve, x, y, zs, withCompression)
 {
 }
コード例 #30
0
		private static ECCurve ConfigureCurveGlv(ECCurve c, GlvTypeBParameters p)
		{
			return c.Configure().SetEndomorphism(new GlvTypeBEndomorphism(c, p)).Create();
		}
コード例 #31
0
ファイル: ECAlgorithms.cs プロジェクト: woutersmit/NBitcoin
 public static bool IsFpCurve(ECCurve c)
 {
     return c.Field.Dimension == 1;
 }