示例#1
0
        static ECDomainParameters Create(Number a, Number b, Number gX, Number gY, Number order, uint h, IFiniteField ff, Uri uri)
        {
            ECGroup group     = new ECGroup(ff.ToElement(a), ff.ToElement(b), ff.Modulus, ff);
            ECPoint basePoint = new ECPoint(group, ff.ToElement(gX), ff.ToElement(gY), ff.ToElement(Number.One));

            return(new ECDomainParameters(group, basePoint, order, h, (uint)ff.Modulus.BitCount(), new Classical(order), uri));
        }
示例#2
0
		public ECPoint (ECGroup group, Number x, Number y, Number z)
		{
			_group = group;
			_field = group.FiniteField;
			_x = x;
			_y = y;
			_z = z;
		}
示例#3
0
 public ECPoint(ECGroup group, Number x, Number y, Number z)
 {
     _group = group;
     _field = group.FiniteField;
     _x     = x;
     _y     = y;
     _z     = z;
 }
		public ECDomainParameters (ECGroup group, ECPoint G, Number order, uint h, uint bits, IFiniteField fieldN, Uri uri)
		{
			_group = group;
			_G = G;
			_order = order;
			_h = h;
			_bits = bits;
			_fieldN = fieldN;
			_uri = uri;
		}
示例#5
0
 public ECDomainParameters(ECGroup group, ECPoint G, Number order, uint h, uint bits, IFiniteField fieldN, Uri uri)
 {
     _group  = group;
     _G      = G;
     _order  = order;
     _h      = h;
     _bits   = bits;
     _fieldN = fieldN;
     _uri    = uri;
 }
示例#6
0
        /// <summary>バイト配列より点を作成する (SEC1, 2.3.4)</summary>
        public ECPoint(ECGroup group, byte[] data)
        {
            _group = group;
            _field = group.FiniteField;
            switch (data[0])
            {
            case 0: {                     // 無限遠点
                ECPoint tmp = _field.GetInfinityPoint(_group);
                _x = tmp._x;
                _y = tmp._y;
                _z = tmp._z;
                return;
            }

            case 2:
            case 3: {                     // 点圧縮済みデータ
                int keyBits  = group.P.BitCount();
                int keyBytes = (keyBits >> 3) + ((keyBits & 7) == 0 ? 0 : 1);
                if (data.Length != keyBytes + 1)
                {
                    throw new ArgumentException();
                }
                Number x  = _field.ToElement(new Number(data, 1, keyBytes, false));
                Number y2 = _field.Add(_field.Multiply(_field.Add(_field.Multiply(x, x), _group.A), x), _group.B);                             // (x^2 + a)*x + b
                Number y  = _field.Sqrt(y2);
                if (_field.ToNormal(y).GetBit(0) != data[0] - 2)
                {
                    y = _field.Modulus - y;
                }
                _x = x;
                _y = y;
                _z = _field.ToElement(Number.One);
                return;
            }

            case 4: {                     // 非圧縮データ
                int keyBits  = group.P.BitCount();
                int keyBytes = (keyBits >> 3) + ((keyBits & 7) == 0 ? 0 : 1);
                _x = _field.ToElement(new Number(data, 1, keyBytes, false));
                _y = _field.ToElement(new Number(data, 1 + keyBytes, keyBytes, false));
                _z = _field.ToElement(Number.One);
                return;
            }

            default:
                throw new ArgumentException();
            }
        }
示例#7
0
		/// <summary>バイト配列より点を作成する (SEC1, 2.3.4)</summary>
		public ECPoint (ECGroup group, byte[] data)
		{
			_group = group;
			_field = group.FiniteField;
			switch (data[0]) {
				case 0: { // 無限遠点
					ECPoint tmp = _field.GetInfinityPoint (_group);
					_x = tmp._x;
					_y = tmp._y;
					_z = tmp._z;
					return;
				}
				case 2:
				case 3: { // 点圧縮済みデータ
					int keyBits = group.P.BitCount ();
					int keyBytes = (keyBits >> 3) + ((keyBits & 7) == 0 ? 0 : 1);
					if (data.Length != keyBytes + 1)
						throw new ArgumentException ();
					Number x = _field.ToElement (new Number (data, 1, keyBytes, false));
					Number y2 = _field.Add (_field.Multiply (_field.Add (_field.Multiply (x, x), _group.A), x), _group.B); // (x^2 + a)*x + b
					Number y = _field.Sqrt (y2);
					if (_field.ToNormal (y).GetBit (0) != data[0] - 2)
						y = _field.Modulus - y;
					_x = x;
					_y = y;
					_z = _field.ToElement (Number.One);
					return;
				}
				case 4: { // 非圧縮データ
					int keyBits = group.P.BitCount ();
					int keyBytes = (keyBits >> 3) + ((keyBits & 7) == 0 ? 0 : 1);
					_x = _field.ToElement (new Number (data, 1, keyBytes, false));
					_y = _field.ToElement (new Number (data, 1 + keyBytes, keyBytes, false));
					_z = _field.ToElement (Number.One);
					return;
				}
				default:
					throw new ArgumentException ();
			}
		}
示例#8
0
		public override ECPoint GetInfinityPoint (ECGroup group)
		{
			return new ECPoint (group, PADDED_ZERO, PADDED_ZERO, PADDED_ZERO);
		}
		public ECDomainParameters (ECGroup group, ECPoint G, Number order, uint h, uint bits, IFiniteField fieldN)
			: this (group, G, order, h, bits, fieldN, null)
		{
		}
示例#10
0
 public ECDomainParameters(ECGroup group, ECPoint G, Number order, uint h, uint bits, IFiniteField fieldN)
     : this(group, G, order, h, bits, fieldN, null)
 {
 }
示例#11
0
		void PointCompressTest (int bits, ECGroup group, ECPoint p, int repeats, string name)
		{
			int bytes = (bits >> 3) + ((bits & 7) == 0 ? 0 : 1) + 1;
			for (int i = 0; i < repeats; i ++) {
				byte[] tmp = p.ToByteArray (true);
				Assert.IsTrue (tmp.Length == bytes, name + " #1");
				ECPoint x = new ECPoint (group, tmp).Export ();
				ECPoint p2 = p.Export ();
				Assert.IsTrue (x.X.CompareTo (p2.X) == 0, name + " #2");
				Assert.IsTrue (x.Y.CompareTo (p2.Y) == 0, name + " #3");
				p = p.Multiply (Number.CreateRandomElement (group.P));
			}
		}
示例#12
0
		public virtual ECPoint GetInfinityPoint (ECGroup group)
		{
			return new ECPoint (group, Number.Zero, Number.Zero, Number.Zero);
		}
示例#13
0
		public virtual ECPoint ExportECPoint (Number x, Number y, Number z, ECGroup group)
		{
			if (z.IsOne ())
				return new ECPoint (group, x, y, z);
			Number iz = Invert (z);
			Number z2 = Multiply (iz, iz);
			return new ECPoint (group, Multiply (x, z2), Multiply (y, Multiply (z2, iz)), Number.One);
		}
示例#14
0
		public override ECPoint ExportECPoint (Number x, Number y, Number z, ECGroup group)
		{
			if (montOne == null) montOne = ToElement (Number.One);
			if (z.CompareTo (montOne) == 0)
				return new ECPoint (group, Multiply (x, Number.One), Multiply (y, Number.One), Number.One);

			Number izm = Invert (z);
			Number iz = Multiply (izm, Number.One);
			Number z2 = Multiply (iz, izm);
			return new ECPoint (group, Multiply (x, z2), Multiply (y, (Multiply (z2, izm))), Number.One);
		}