A multiple precision integer
상속: BcpgObject
예제 #1
0
		public RsaSecretBcpgKey(
			BigInteger d,
			BigInteger p,
			BigInteger q)
		{
			// PGP requires (p < q)
			int cmp = p.CompareTo(q);
			if (cmp >= 0)
			{
				if (cmp == 0)
					throw new ArgumentException("p and q cannot be equal");

				BigInteger tmp = p;
				p = q;
				q = tmp;
			}

			this.d = new MPInteger(d);
			this.p = new MPInteger(p);
			this.q = new MPInteger(q);
			this.u = new MPInteger(p.ModInverse(q));

			this.expP = d.Remainder(p.Subtract(BigInteger.One));
			this.expQ = d.Remainder(q.Subtract(BigInteger.One));
			this.crt = q.ModInverse(p);
		}
예제 #2
0
 public DsaPublicBcpgKey(BcpgInputStream bcpgIn)
 {
     p = new MPInteger(bcpgIn);
     q = new MPInteger(bcpgIn);
     g = new MPInteger(bcpgIn);
     y = new MPInteger(bcpgIn);
 }
 public DsaPublicBcpgKey(IBigInteger p, IBigInteger q, IBigInteger g, IBigInteger y)
 {
     _p = new MPInteger(p);
     _q = new MPInteger(q);
     _g = new MPInteger(g);
     _y = new MPInteger(y);
 }
예제 #4
0
 /// <param name="n">The modulus.</param>
 /// <param name="e">The public exponent.</param>
 public RsaPublicBcpgKey(
     BigInteger n,
     BigInteger e)
 {
     this.n = new MPInteger(n);
     this.e = new MPInteger(e);
 }
 public DsaPublicBcpgKey(IBigInteger p, IBigInteger q, IBigInteger g, IBigInteger y)
 {
     _p = new MPInteger(p);
     _q = new MPInteger(q);
     _g = new MPInteger(g);
     _y = new MPInteger(y);
 }
 /// <param name="bcpgIn">The stream to read the packet from.</param>
 public DsaPublicBcpgKey(BcpgInputStream bcpgIn)
 {
     _p = new MPInteger(bcpgIn);
     _q = new MPInteger(bcpgIn);
     _g = new MPInteger(bcpgIn);
     _y = new MPInteger(bcpgIn);
 }
 /// <param name="bcpgIn">The stream to read the packet from.</param>
 public DsaPublicBcpgKey(BcpgInputStream bcpgIn)
 {
     _p = new MPInteger(bcpgIn);
     _q = new MPInteger(bcpgIn);
     _g = new MPInteger(bcpgIn);
     _y = new MPInteger(bcpgIn);
 }
        public override void Encode(IBcpgOutputStream bcpgOut)
        {
            using (var bOut = new MemoryStream())
            {
                using (var pOut = new BcpgOutputStream(bOut))
                {
                    pOut.WriteByte((byte)_version);

                    pOut.WriteLong(_keyId);

                    pOut.WriteByte((byte)_algorithm);

                    for (var i = 0; i != _data.Length; i++)
                    {
                        MPInteger.EncodeInteger(pOut, _data[i]);
                    }

                    if (_extraData != null)
                    {
                        if (_extraData.Length > 0xFF)
                        {
                            throw new PgpException("Extra Data is too large.");
                        }
                        pOut.WriteByte((byte)_extraData.Length);
                        pOut.Write(_extraData, 0, _extraData.Length);
                    }

                    bcpgOut.WritePacket(PacketTag.PublicKeyEncryptedSession, bOut.ToArray(), true);
                }
            }
        }
예제 #9
0
 public ElGamalPublicBcpgKey(
     BcpgInputStream bcpgIn)
 {
     this.p = new MPInteger(bcpgIn);
     this.g = new MPInteger(bcpgIn);
     this.y = new MPInteger(bcpgIn);
 }
		public ElGamalPublicBcpgKey(
			BcpgInputStream bcpgIn)
		{
			this.p = new MPInteger(bcpgIn);
			this.g = new MPInteger(bcpgIn);
			this.y = new MPInteger(bcpgIn);
		}
예제 #11
0
 public DsaPublicBcpgKey(BigInteger p, BigInteger q, BigInteger g, BigInteger y)
 {
     this.p = new MPInteger(p);
     this.q = new MPInteger(q);
     this.g = new MPInteger(g);
     this.y = new MPInteger(y);
 }
예제 #12
0
 public DsaPublicBcpgKey(BcpgInputStream bcpgIn)
 {
     this.p = new MPInteger(bcpgIn);
     this.q = new MPInteger(bcpgIn);
     this.g = new MPInteger(bcpgIn);
     this.y = new MPInteger(bcpgIn);
 }
예제 #13
0
		/// <param name="n">The modulus.</param>
		/// <param name="e">The public exponent.</param>
		public RsaPublicBcpgKey(
			BigInteger	n,
			BigInteger	e)
		{
			this.n = new MPInteger(n);
			this.e = new MPInteger(e);
		}
예제 #14
0
        public RsaSecretBcpgKey(IBigInteger d, IBigInteger p, IBigInteger q)
        {
            // PGP requires (p < q)
            var cmp = p.CompareTo(q);

            if (cmp >= 0)
            {
                if (cmp == 0)
                {
                    throw new ArgumentException("p and q cannot be equal");
                }

                var tmp = p;
                p = q;
                q = tmp;
            }

            _d = new MPInteger(d);
            _p = new MPInteger(p);
            _q = new MPInteger(q);
            _u = new MPInteger(p.ModInverse(q));

            _expP = d.Remainder(p.Subtract(BigInteger.One));
            _expQ = d.Remainder(q.Subtract(BigInteger.One));
            _crt  = q.ModInverse(p);
        }
예제 #15
0
        public RsaSecretBcpgKey(
            BigInteger d,
            BigInteger p,
            BigInteger q)
        {
            // PGP requires (p < q)
            int cmp = p.CompareTo(q);

            if (cmp >= 0)
            {
                if (cmp == 0)
                {
                    throw new ArgumentException("p and q cannot be equal");
                }

                BigInteger tmp = p;
                p = q;
                q = tmp;
            }

            this.d = new MPInteger(d);
            this.p = new MPInteger(p);
            this.q = new MPInteger(q);
            this.u = new MPInteger(p.ModInverse(q));

            this.expP = d.Remainder(p.Subtract(BigInteger.One));
            this.expQ = d.Remainder(q.Subtract(BigInteger.One));
            this.crt  = q.ModInverse(p);
        }
예제 #16
0
        public override void Encode(BcpgOutputStream bcpgOut)
        {
            byte[] encoded = oid.GetEncoded();
            ((Stream)bcpgOut).Write(encoded, 1, encoded.Length - 1);
            MPInteger bcpgObject = new MPInteger(point);

            bcpgOut.WriteObject(bcpgObject);
        }
 /// <param name="bcpgIn">The stream to read the packet from.</param>
 public DsaPublicBcpgKey(
     BcpgInputStream bcpgIn)
 {
     this.p = new MPInteger(bcpgIn);
     this.q = new MPInteger(bcpgIn);
     this.g = new MPInteger(bcpgIn);
     this.y = new MPInteger(bcpgIn);
 }
		public ElGamalPublicBcpgKey(
			BigInteger p,
			BigInteger g,
			BigInteger y)
		{
			this.p = new MPInteger(p);
			this.g = new MPInteger(g);
			this.y = new MPInteger(y);
		}
예제 #19
0
 public ElGamalPublicBcpgKey(
     BigInteger p,
     BigInteger g,
     BigInteger y)
 {
     this.p = new MPInteger(p);
     this.g = new MPInteger(g);
     this.y = new MPInteger(y);
 }
예제 #20
0
        public override void Encode(
            BcpgOutputStream bcpgOut)
        {
            byte[] oid = this.oid.GetEncoded();
            bcpgOut.Write(oid, 1, oid.Length - 1);

            MPInteger point = new MPInteger(this.point);
            bcpgOut.WriteObject(point);
        }
예제 #21
0
        public override void Encode(
            BcpgOutputStream bcpgOut)
        {
            byte[] oid = this.oid.GetEncoded();
            bcpgOut.Write(oid, 1, oid.Length - 1);

            MPInteger point = new MPInteger(this.point);

            bcpgOut.WriteObject(point);
        }
예제 #22
0
 public RsaSecretBcpgKey(BcpgInputStream bcpgIn)
 {
     d    = new MPInteger(bcpgIn);
     p    = new MPInteger(bcpgIn);
     q    = new MPInteger(bcpgIn);
     u    = new MPInteger(bcpgIn);
     expP = d.Value.Remainder(p.Value.Subtract(BigInteger.One));
     expQ = d.Value.Remainder(q.Value.Subtract(BigInteger.One));
     crt  = q.Value.ModInverse(p.Value);
 }
예제 #23
0
 public RsaSecretBcpgKey(BcpgInputStream bcpgIn)
 {
     this.d    = new MPInteger(bcpgIn);
     this.p    = new MPInteger(bcpgIn);
     this.q    = new MPInteger(bcpgIn);
     this.u    = new MPInteger(bcpgIn);
     this.expP = this.d.Value.Remainder(this.p.Value.Subtract(BigInteger.One));
     this.expQ = this.d.Value.Remainder(this.q.Value.Subtract(BigInteger.One));
     this.crt  = this.q.Value.ModInverse(this.p.Value);
 }
예제 #24
0
        public RsaSecretBcpgKey(BcpgInputStream bcpgIn)
        {
            _d = new MPInteger(bcpgIn);
            _p = new MPInteger(bcpgIn);
            _q = new MPInteger(bcpgIn);
            _u = new MPInteger(bcpgIn);

            _expP = _d.Value.Remainder(_p.Value.Subtract(BigInteger.One));
            _expQ = _d.Value.Remainder(_q.Value.Subtract(BigInteger.One));
            _crt  = _q.Value.ModInverse(_p.Value);
        }
 public DsaPublicBcpgKey(
     BigInteger	p,
     BigInteger	q,
     BigInteger	g,
     BigInteger	y)
 {
     this.p = new MPInteger(p);
     this.q = new MPInteger(q);
     this.g = new MPInteger(g);
     this.y = new MPInteger(y);
 }
        public RsaSecretBcpgKey(BcpgInputStream bcpgIn)
        {
            _d = new MPInteger(bcpgIn);
            _p = new MPInteger(bcpgIn);
            _q = new MPInteger(bcpgIn);
            _u = new MPInteger(bcpgIn);

            _expP = _d.Value.Remainder(_p.Value.Subtract(BigInteger.One));
            _expQ = _d.Value.Remainder(_q.Value.Subtract(BigInteger.One));
            _crt = _q.Value.ModInverse(_p.Value);
        }
        /// <summary>
        /// Encodes the specified BCPG out.
        /// </summary>
        /// <param name="bcpgOut">The BCPG out.</param>
        public override void Encode(IBcpgOutputStream bcpgOut)
        {
            var oid = this.Oid.ToBytes();

            bcpgOut.WriteByte((byte)oid.Length);
            bcpgOut.Write(oid, 0, oid.Length);

            var point = new MPInteger(new BigInteger(1, _point.GetEncoded()));

            bcpgOut.WriteObject(point);
        }
예제 #28
0
		public RsaSecretBcpgKey(
			BcpgInputStream bcpgIn)
		{
			this.d = new MPInteger(bcpgIn);
			this.p = new MPInteger(bcpgIn);
			this.q = new MPInteger(bcpgIn);
			this.u = new MPInteger(bcpgIn);

			this.expP = d.Value.Remainder(p.Value.Subtract(BigInteger.One));
			this.expQ = d.Value.Remainder(q.Value.Subtract(BigInteger.One));
			this.crt = q.Value.ModInverse(p.Value);
		}
예제 #29
0
 /**
 * Generate a version 4 signature packet.
 *
 * @param signatureType
 * @param keyAlgorithm
 * @param hashAlgorithm
 * @param hashedData
 * @param unhashedData
 * @param fingerprint
 * @param signature
 */
 public SignaturePacket(
     int						signatureType,
     long					keyId,
     PublicKeyAlgorithmTag	keyAlgorithm,
     HashAlgorithmTag		hashAlgorithm,
     SignatureSubpacket[]	hashedData,
     SignatureSubpacket[]	unhashedData,
     byte[]					fingerprint,
     MPInteger[]				signature)
     : this(4, signatureType, keyId, keyAlgorithm, hashAlgorithm, hashedData, unhashedData, fingerprint, signature)
 {
 }
예제 #30
0
 /**
 * Generate a version 2/3 signature packet.
 *
 * @param signatureType
 * @param keyAlgorithm
 * @param hashAlgorithm
 * @param fingerprint
 * @param signature
 */
 public SignaturePacket(
     int						version,
     int						signatureType,
     long					keyId,
     PublicKeyAlgorithmTag	keyAlgorithm,
     HashAlgorithmTag		hashAlgorithm,
     long					creationTime,
     byte[]					fingerprint,
     MPInteger[]				signature)
     : this(version, signatureType, keyId, keyAlgorithm, hashAlgorithm, null, null, fingerprint, signature)
 {
     this.creationTime = creationTime;
 }
예제 #31
0
        public override void Encode(BcpgOutputStream bcpgOut)
        {
            MemoryStream     memoryStream     = new MemoryStream();
            BcpgOutputStream bcpgOutputStream = new BcpgOutputStream(memoryStream);

            bcpgOutputStream.WriteByte((byte)this.version);
            bcpgOutputStream.WriteLong(this.keyId);
            bcpgOutputStream.WriteByte((byte)this.algorithm);
            for (int num = 0; num != this.data.Length; num++)
            {
                MPInteger.Encode(bcpgOutputStream, this.data[num]);
            }
            bcpgOut.WritePacket(PacketTag.PublicKeyEncryptedSession, memoryStream.ToArray(), true);
        }
        public override void Encode(
            BcpgOutputStream bcpgOut)
        {
            MemoryStream     bOut = new MemoryStream();
            BcpgOutputStream pOut = new BcpgOutputStream(bOut);

            pOut.WriteByte((byte)version);

            pOut.WriteLong(keyId);

            pOut.WriteByte((byte)algorithm);

            for (int i = 0; i != data.Length; i++)
            {
                MPInteger.Encode(pOut, data[i]);
            }

            bcpgOut.WritePacket(PacketTag.PublicKeyEncryptedSession, bOut.ToArray(), true);
        }
        internal PublicKeyEncSessionPacket(
            BcpgInputStream bcpgIn)
        {
            version = bcpgIn.ReadByte();

            keyId |= (long)bcpgIn.ReadByte() << 56;
            keyId |= (long)bcpgIn.ReadByte() << 48;
            keyId |= (long)bcpgIn.ReadByte() << 40;
            keyId |= (long)bcpgIn.ReadByte() << 32;
            keyId |= (long)bcpgIn.ReadByte() << 24;
            keyId |= (long)bcpgIn.ReadByte() << 16;
            keyId |= (long)bcpgIn.ReadByte() << 8;
            keyId |= (uint)bcpgIn.ReadByte();

            algorithm = (PublicKeyAlgorithmTag)bcpgIn.ReadByte();

            switch ((PublicKeyAlgorithmTag)algorithm)
            {
            case PublicKeyAlgorithmTag.RsaEncrypt:
            case PublicKeyAlgorithmTag.RsaGeneral:
                data = new byte[][] { new MPInteger(bcpgIn).GetEncoded() };
                break;

            case PublicKeyAlgorithmTag.ElGamalEncrypt:
            case PublicKeyAlgorithmTag.ElGamalGeneral:
                MPInteger p = new MPInteger(bcpgIn);
                MPInteger g = new MPInteger(bcpgIn);
                data = new byte[][] {
                    p.GetEncoded(),
                        g.GetEncoded(),
                };
                break;

            case PublicKeyAlgorithmTag.ECDH:
                data = new byte[][] { Streams.ReadAll(bcpgIn) };
                break;

            default:
                throw new IOException("unknown PGP public key algorithm encountered");
            }
        }
        internal PublicKeyEncSessionPacket(BcpgInputStream bcpgIn)
        {
            //IL_0171: Unknown result type (might be due to invalid IL or missing references)
            version   = ((Stream)bcpgIn).ReadByte();
            keyId    |= (long)((Stream)bcpgIn).ReadByte() << 56;
            keyId    |= (long)((Stream)bcpgIn).ReadByte() << 48;
            keyId    |= (long)((Stream)bcpgIn).ReadByte() << 40;
            keyId    |= (long)((Stream)bcpgIn).ReadByte() << 32;
            keyId    |= (long)((Stream)bcpgIn).ReadByte() << 24;
            keyId    |= (long)((Stream)bcpgIn).ReadByte() << 16;
            keyId    |= (long)((Stream)bcpgIn).ReadByte() << 8;
            keyId    |= (uint)((Stream)bcpgIn).ReadByte();
            algorithm = (PublicKeyAlgorithmTag)((Stream)bcpgIn).ReadByte();
            switch (algorithm)
            {
            case PublicKeyAlgorithmTag.RsaGeneral:
            case PublicKeyAlgorithmTag.RsaEncrypt:
                data = new byte[1][] { new MPInteger(bcpgIn).GetEncoded() };
                break;

            case PublicKeyAlgorithmTag.ElGamalEncrypt:
            case PublicKeyAlgorithmTag.ElGamalGeneral:
            {
                MPInteger mPInteger  = new MPInteger(bcpgIn);
                MPInteger mPInteger2 = new MPInteger(bcpgIn);
                data = new byte[2][]
                {
                    mPInteger.GetEncoded(),
                        mPInteger2.GetEncoded()
                };
                break;
            }

            case PublicKeyAlgorithmTag.EC:
                data = new byte[1][] { Streams.ReadAll((Stream)(object)bcpgIn) };
                break;

            default:
                throw new IOException("unknown PGP public key algorithm encountered");
            }
        }
        public RsaSecretBcpgKey(
            BigInteger d,
            BigInteger p,
            BigInteger q)
        {
            // pgp requires (p < q)
            if (p.CompareTo(q) > 0)
            {
                BigInteger tmp = p;
                p = q;
                q = tmp;
            }

            this.d    = new MPInteger(d);
            this.p    = new MPInteger(p);
            this.q    = new MPInteger(q);
            this.u    = new MPInteger(p.ModInverse(q));
            this.expP = d.Remainder(p.Subtract(BigInteger.One));
            this.expQ = d.Remainder(q.Subtract(BigInteger.One));
            this.crt  = q.ModInverse(p);
        }
예제 #36
0
        public RsaSecretBcpgKey(
			BigInteger d,
			BigInteger p,
			BigInteger q)
        {
            // pgp requires (p < q)
            if (p.CompareTo(q) > 0)
            {
                BigInteger tmp = p;
                p = q;
                q = tmp;
            }

            this.d = new MPInteger(d);
            this.p = new MPInteger(p);
            this.q = new MPInteger(q);
            this.u = new MPInteger(p.ModInverse(q));
            this.expP = d.Remainder(p.Subtract(BigInteger.One));
            this.expQ = d.Remainder(q.Subtract(BigInteger.One));
            this.crt = q.ModInverse(p);
        }
예제 #37
0
        public RsaSecretBcpgKey(BigInteger d, BigInteger p, BigInteger q)
        {
            int num = p.CompareTo(q);

            if (num >= 0)
            {
                if (num == 0)
                {
                    throw new ArgumentException("p and q cannot be equal");
                }
                BigInteger bigInteger = p;
                p = q;
                q = bigInteger;
            }
            this.d    = new MPInteger(d);
            this.p    = new MPInteger(p);
            this.q    = new MPInteger(q);
            this.u    = new MPInteger(p.ModInverse(q));
            this.expP = d.Remainder(p.Subtract(BigInteger.One));
            this.expQ = d.Remainder(q.Subtract(BigInteger.One));
            this.crt  = q.ModInverse(p);
        }
		internal PublicKeyEncSessionPacket(
			BcpgInputStream bcpgIn)
		{
			version = bcpgIn.ReadByte();

			keyId |= (long)bcpgIn.ReadByte() << 56;
			keyId |= (long)bcpgIn.ReadByte() << 48;
			keyId |= (long)bcpgIn.ReadByte() << 40;
			keyId |= (long)bcpgIn.ReadByte() << 32;
			keyId |= (long)bcpgIn.ReadByte() << 24;
			keyId |= (long)bcpgIn.ReadByte() << 16;
			keyId |= (long)bcpgIn.ReadByte() << 8;
			keyId |= (uint)bcpgIn.ReadByte();

			algorithm = (PublicKeyAlgorithmTag) bcpgIn.ReadByte();

			switch ((PublicKeyAlgorithmTag) algorithm)
			{
				case PublicKeyAlgorithmTag.RsaEncrypt:
				case PublicKeyAlgorithmTag.RsaGeneral:
					data = new byte[][]{ new MPInteger(bcpgIn).GetEncoded() };
					break;
				case PublicKeyAlgorithmTag.ElGamalEncrypt:
				case PublicKeyAlgorithmTag.ElGamalGeneral:
                    MPInteger p = new MPInteger(bcpgIn);
                    MPInteger g = new MPInteger(bcpgIn);
					data = new byte[][]{
                        p.GetEncoded(),
                        g.GetEncoded(),
                    };
					break;
                case PublicKeyAlgorithmTag.ECDH:
                    data = new byte[][]{ Streams.ReadAll(bcpgIn) };
                    break;
				default:
					throw new IOException("unknown PGP public key algorithm encountered");
			}
		}
예제 #39
0
        public RsaSecretBcpgKey(BigInteger d, BigInteger p, BigInteger q)
        {
            //IL_001a: Unknown result type (might be due to invalid IL or missing references)
            int num = p.CompareTo(q);

            if (num >= 0)
            {
                if (num == 0)
                {
                    throw new ArgumentException("p and q cannot be equal");
                }
                BigInteger bigInteger = p;
                p = q;
                q = bigInteger;
            }
            this.d = new MPInteger(d);
            this.p = new MPInteger(p);
            this.q = new MPInteger(q);
            u      = new MPInteger(p.ModInverse(q));
            expP   = d.Remainder(p.Subtract(BigInteger.One));
            expQ   = d.Remainder(q.Subtract(BigInteger.One));
            crt    = q.ModInverse(p);
        }
        public RsaSecretBcpgKey(IBigInteger d, IBigInteger p, IBigInteger q)
        {
            // PGP requires (p < q)
            var cmp = p.CompareTo(q);
            if (cmp >= 0)
            {
                if (cmp == 0)
                    throw new ArgumentException("p and q cannot be equal");

                var tmp = p;
                p = q;
                q = tmp;
            }

            _d = new MPInteger(d);
            _p = new MPInteger(p);
            _q = new MPInteger(q);
            _u = new MPInteger(p.ModInverse(q));

            _expP = d.Remainder(p.Subtract(BigInteger.One));
            _expQ = d.Remainder(q.Subtract(BigInteger.One));
            _crt = q.ModInverse(p);
        }
        public RsaSecretBcpgKey(
            BcpgInputStream bcpgIn)
        {
            this.d = new MPInteger(bcpgIn);

            MPInteger p = new MPInteger(bcpgIn);
            MPInteger q = new MPInteger(bcpgIn);

            // pgp requires (p < q)
            if (p.Value.CompareTo(q.Value) > 0)
            {
                MPInteger tmp = p;
                p = q;
                q = tmp;
            }

            this.p = p;
            this.q = q;

            this.u    = new MPInteger(bcpgIn);
            this.expP = d.Value.Remainder(p.Value.Subtract(BigInteger.One));
            this.expQ = d.Value.Remainder(q.Value.Subtract(BigInteger.One));
            this.crt  = q.Value.ModInverse(p.Value);
        }
예제 #42
0
        public byte[] GetSignatureBytes()
        {
            if (this.signatureEncoding != null)
            {
                return((byte[])this.signatureEncoding.Clone());
            }
            MemoryStream     memoryStream     = new MemoryStream();
            BcpgOutputStream bcpgOutputStream = new BcpgOutputStream(memoryStream);

            MPInteger[] array = this.signature;
            for (int i = 0; i < array.Length; i++)
            {
                MPInteger bcpgObject = array[i];
                try
                {
                    bcpgOutputStream.WriteObject(bcpgObject);
                }
                catch (IOException arg)
                {
                    throw new Exception("internal error: " + arg);
                }
            }
            return(memoryStream.ToArray());
        }
예제 #43
0
        public RsaSecretBcpgKey(
			BcpgInputStream bcpgIn)
        {
            this.d = new MPInteger(bcpgIn);

            MPInteger p = new MPInteger(bcpgIn);
            MPInteger q = new MPInteger(bcpgIn);

            // pgp requires (p < q)
            if (p.Value.CompareTo(q.Value) > 0)
            {
                MPInteger tmp = p;
                p = q;
                q = tmp;
            }

            this.p = p;
            this.q = q;

            this.u = new MPInteger(bcpgIn);
            this.expP = d.Value.Remainder(p.Value.Subtract(BigInteger.One));
            this.expQ = d.Value.Remainder(q.Value.Subtract(BigInteger.One));
            this.crt = q.Value.ModInverse(p.Value);
        }
예제 #44
0
 public DsaSecretBcpgKey(IBigInteger x)
 {
     _x = new MPInteger(x);
 }
예제 #45
0
 /// <summary>Construct an RSA public key from the passed in stream.</summary>
 public RsaPublicBcpgKey(
     BcpgInputStream bcpgIn)
 {
     this.n = new MPInteger(bcpgIn);
     this.e = new MPInteger(bcpgIn);
 }
예제 #46
0
		public DsaSecretBcpgKey(
			BigInteger x)
		{
			this.x = new MPInteger(x);
		}
예제 #47
0
		/**
		* @param in
		*/
		public DsaSecretBcpgKey(
			BcpgInputStream bcpgIn)
		{
			this.x = new MPInteger(bcpgIn);
		}
 public ElGamalPublicBcpgKey(BcpgInputStream bcpgIn)
 {
     _p = new MPInteger(bcpgIn);
     _g = new MPInteger(bcpgIn);
     _y = new MPInteger(bcpgIn);
 }
예제 #49
0
		internal SignaturePacket(
            BcpgInputStream bcpgIn)
        {
            version = bcpgIn.ReadByte();

			if (version == 3 || version == 2)
            {
//                int l =
                bcpgIn.ReadByte();

				signatureType = bcpgIn.ReadByte();
                creationTime = (((long)bcpgIn.ReadByte() << 24) | ((long)bcpgIn.ReadByte() << 16)
                    | ((long)bcpgIn.ReadByte() << 8) | (uint)bcpgIn.ReadByte()) * 1000L;

				keyId |= (long)bcpgIn.ReadByte() << 56;
                keyId |= (long)bcpgIn.ReadByte() << 48;
                keyId |= (long)bcpgIn.ReadByte() << 40;
                keyId |= (long)bcpgIn.ReadByte() << 32;
                keyId |= (long)bcpgIn.ReadByte() << 24;
                keyId |= (long)bcpgIn.ReadByte() << 16;
                keyId |= (long)bcpgIn.ReadByte() << 8;
                keyId |= (uint)bcpgIn.ReadByte();

				keyAlgorithm = (PublicKeyAlgorithmTag) bcpgIn.ReadByte();
                hashAlgorithm = (HashAlgorithmTag) bcpgIn.ReadByte();
            }
            else if (version == 4)
            {
                signatureType = bcpgIn.ReadByte();
                keyAlgorithm = (PublicKeyAlgorithmTag) bcpgIn.ReadByte();
                hashAlgorithm = (HashAlgorithmTag) bcpgIn.ReadByte();

				int hashedLength = (bcpgIn.ReadByte() << 8) | bcpgIn.ReadByte();
                byte[] hashed = new byte[hashedLength];

				bcpgIn.ReadFully(hashed);

				//
                // read the signature sub packet data.
                //
                SignatureSubpacketsParser sIn = new SignatureSubpacketsParser(
                    new MemoryStream(hashed, false));

				ArrayList v = new ArrayList();
				SignatureSubpacket sub;
				while ((sub = sIn.ReadPacket()) != null)
                {
                    v.Add(sub);
                }

				hashedData = new SignatureSubpacket[v.Count];

				for (int i = 0; i != hashedData.Length; i++)
                {
                    SignatureSubpacket p = (SignatureSubpacket)v[i];
                    if (p is IssuerKeyId)
                    {
                        keyId = ((IssuerKeyId)p).KeyId;
                    }
                    else if (p is SignatureCreationTime)
                    {
                        creationTime = DateTimeUtilities.DateTimeToUnixMs(
							((SignatureCreationTime)p).GetTime());
                    }

					hashedData[i] = p;
                }

				int unhashedLength = (bcpgIn.ReadByte() << 8) | bcpgIn.ReadByte();
                byte[] unhashed = new byte[unhashedLength];

				bcpgIn.ReadFully(unhashed);

				sIn = new SignatureSubpacketsParser(new MemoryStream(unhashed, false));

				v.Clear();

				while ((sub = sIn.ReadPacket()) != null)
                {
                    v.Add(sub);
                }

				unhashedData = new SignatureSubpacket[v.Count];

				for (int i = 0; i != unhashedData.Length; i++)
                {
                    SignatureSubpacket p = (SignatureSubpacket)v[i];
                    if (p is IssuerKeyId)
                    {
                        keyId = ((IssuerKeyId)p).KeyId;
                    }

					unhashedData[i] = p;
                }
            }
            else
            {
                throw new Exception("unsupported version: " + version);
            }

			fingerprint = new byte[2];
            bcpgIn.ReadFully(fingerprint);

			switch (keyAlgorithm)
            {
                case PublicKeyAlgorithmTag.RsaGeneral:
                case PublicKeyAlgorithmTag.RsaSign:
                    MPInteger v = new MPInteger(bcpgIn);
					signature = new MPInteger[]{ v };
                    break;
				case PublicKeyAlgorithmTag.Dsa:
                    MPInteger r = new MPInteger(bcpgIn);
                    MPInteger s = new MPInteger(bcpgIn);
					signature = new MPInteger[]{ r, s };
                    break;
                case PublicKeyAlgorithmTag.ElGamalEncrypt: // yep, this really does happen sometimes.
                case PublicKeyAlgorithmTag.ElGamalGeneral:
                    MPInteger p = new MPInteger(bcpgIn);
                    MPInteger g = new MPInteger(bcpgIn);
                    MPInteger y = new MPInteger(bcpgIn);
					signature = new MPInteger[]{ p, g, y };
                    break;
                default:
					if (keyAlgorithm >= PublicKeyAlgorithmTag.Experimental_1 && keyAlgorithm <= PublicKeyAlgorithmTag.Experimental_11)
					{
						signature = null;
						MemoryStream bOut = new MemoryStream();
						int ch;
						while ((ch = bcpgIn.ReadByte()) >= 0)
						{
							bOut.WriteByte((byte) ch);
						}
						signatureEncoding = bOut.ToArray();
					}
					else
					{
						throw new IOException("unknown signature key algorithm: " + keyAlgorithm);
					}
					break;
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ElGamalSecretBcpgKey"/> class.
 /// </summary>
 /// <param name="bcpgIn">The BCPG in.</param>
 public ElGamalSecretBcpgKey(BcpgInputStream bcpgIn)
 {
     _x = new MPInteger(bcpgIn);
 }
예제 #51
0
 /**
  * @param in
  */
 public DsaSecretBcpgKey(
     BcpgInputStream bcpgIn)
 {
     this.x = new MPInteger(bcpgIn);
 }
예제 #52
0
		/// <summary>Construct an RSA public key from the passed in stream.</summary>
		public RsaPublicBcpgKey(
			BcpgInputStream bcpgIn)
		{
			this.n = new MPInteger(bcpgIn);
			this.e = new MPInteger(bcpgIn);
		}
 /// <param name="n">The modulus.</param>
 /// <param name="e">The public exponent.</param>
 public RsaPublicBcpgKey(IBigInteger n, IBigInteger e)
 {
     _n = new MPInteger(n);
     _e = new MPInteger(e);
 }
 /// <summary>Construct an RSA public key from the passed in stream.</summary>
 public RsaPublicBcpgKey(BcpgInputStream bcpgIn)
 {
     _n = new MPInteger(bcpgIn);
     _e = new MPInteger(bcpgIn);
 }
예제 #55
0
 public DsaSecretBcpgKey(
     BigInteger x)
 {
     this.x = new MPInteger(x);
 }
        /// <summary>
        /// Encodes the specified BCPG out.
        /// </summary>
        /// <param name="bcpgOut">The BCPG out.</param>
        public override void Encode(IBcpgOutputStream bcpgOut)
        {
            var oid = this.Oid.ToBytes();
            bcpgOut.WriteByte((byte)oid.Length);
            bcpgOut.Write(oid, 0, oid.Length);

            var point = new MPInteger(new BigInteger(1, _point.GetEncoded()));
            bcpgOut.WriteObject(point);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ElGamalSecretBcpgKey"/> class.
 /// </summary>
 /// <param name="x">The x.</param>
 public ElGamalSecretBcpgKey(IBigInteger x)
 {
     _x = new MPInteger(x);
 }
 public ElGamalPublicBcpgKey(IBigInteger p, IBigInteger g, IBigInteger y)
 {
     _p = new MPInteger(p);
     _g = new MPInteger(g);
     _y = new MPInteger(y);
 }
예제 #59
0
		public SignaturePacket(
            int						version,
            int						signatureType,
            long					keyId,
            PublicKeyAlgorithmTag	keyAlgorithm,
            HashAlgorithmTag		hashAlgorithm,
            SignatureSubpacket[]	hashedData,
            SignatureSubpacket[]	unhashedData,
            byte[]					fingerprint,
            MPInteger[]				signature)
        {
            this.version = version;
            this.signatureType = signatureType;
            this.keyId = keyId;
            this.keyAlgorithm = keyAlgorithm;
            this.hashAlgorithm = hashAlgorithm;
            this.hashedData = hashedData;
            this.unhashedData = unhashedData;
            this.fingerprint = fingerprint;
            this.signature = signature;

			if (hashedData != null)
			{
				setCreationTime();
			}
		}
		/**
		* @param x
		*/
		public ElGamalSecretBcpgKey(
			BigInteger x)
		{
			this.x = new MPInteger(x);
		}