Update() public method

update the internal digest with the byte b
public Update ( byte input ) : void
input byte
return void
Ejemplo n.º 1
0
        public virtual void DoTest5()
        {
            RsaKeyParameters pubParameters = new RsaKeyParameters(false, mod3, pub3);
            RsaKeyParameters privParameters = new RsaKeyParameters(true, mod3, pri3);
            RsaEngine rsa = new RsaEngine();
            byte[] data;

            //
            // ISO 9796-2 - Signing
            //
            Iso9796d2Signer eng = new Iso9796d2Signer(rsa, new RipeMD160Digest(), true);

            eng.Init(true, privParameters);

            eng.Update(msg5[0]);
            eng.BlockUpdate(msg5, 1, msg5.Length - 1);

            data = eng.GenerateSignature();

            eng.Init(false, pubParameters);

            if (!IsSameAs(sig5, 0, data))
            {
                Fail("failed ISO9796-2 generation Test 5");
            }

            eng.Update(msg5[0]);
            eng.BlockUpdate(msg5, 1, msg5.Length - 1);

            if (!eng.VerifySignature(data))
            {
                Fail("failed ISO9796-2 verify Test 5");
            }

            if (eng.HasFullMessage())
            {
                Fail("fullMessage true - Test 5");
            }

            if (!StartsWith(msg5, eng.GetRecoveredMessage()))
            {
                Fail("failed ISO9796-2 partial recovered message Test 5");
            }

            int length = eng.GetRecoveredMessage().Length;

            if (length >= msg5.Length)
            {
                Fail("Test 5 recovered message too long");
            }

            eng = new Iso9796d2Signer(rsa, new RipeMD160Digest(), true);

            eng.Init(false, pubParameters);

            eng.UpdateWithRecoveredMessage(sig5);

            if (!StartsWith(msg5, eng.GetRecoveredMessage()))
            {
                Fail("failed ISO9796-2 updateWithRecovered partial recovered message Test 5");
            }

            if (eng.HasFullMessage())
            {
                Fail("fullMessage updateWithRecovered true - Test 5");
            }

            for (int i = length ; i != msg5.Length; i++)
            {
                eng.Update(msg5[i]);
            }

            if (!eng.VerifySignature(sig5))
            {
                Fail("failed ISO9796-2 verify Test 5");
            }

            if (eng.HasFullMessage())
            {
                Fail("fullMessage updateWithRecovered true - Test 5");
            }

            // should fail
            eng.UpdateWithRecoveredMessage(sig5);

            eng.BlockUpdate(msg5, 0, msg5.Length);

            if (eng.VerifySignature(sig5))
            {
                Fail("failed ISO9796-2 updateWithRecovered verify fail Test 5");
            }
        }
Ejemplo n.º 2
0
        public virtual void DoTest4()
        {
            RsaKeyParameters pubParameters = new RsaKeyParameters(false, mod3, pub3);
            RsaKeyParameters privParameters = new RsaKeyParameters(true, mod3, pri3);
            RsaEngine rsa = new RsaEngine();
            byte[] data;

            //
            // ISO 9796-2 - Signing
            //
            Iso9796d2Signer eng = new Iso9796d2Signer(rsa, new RipeMD128Digest());

            eng.Init(true, privParameters);

            eng.Update(msg4[0]);
            eng.BlockUpdate(msg4, 1, msg4.Length - 1);

            data = eng.GenerateSignature();

            eng.Init(false, pubParameters);

            if (!IsSameAs(sig4, 0, data))
            {
                Fail("failed ISO9796-2 generation Test 4");
            }

            eng.Update(msg4[0]);
            eng.BlockUpdate(msg4, 1, msg4.Length - 1);

            if (!eng.VerifySignature(data))
            {
                Fail("failed ISO9796-2 verify Test 4");
            }

            if (eng.HasFullMessage())
            {
                eng = new Iso9796d2Signer(rsa, new RipeMD128Digest());

                eng.Init(false, pubParameters);

                if (!eng.VerifySignature(sig4))
                {
                    Fail("failed ISO9796-2 verify and recover Test 4");
                }

                if(!IsSameAs(eng.GetRecoveredMessage(), 0, msg4))
                {
                    Fail("failed ISO9796-2 recovered message Test 4");
                }

                // try update with recovered
                eng.UpdateWithRecoveredMessage(sig4);

                if(!IsSameAs(eng.GetRecoveredMessage(), 0, msg4))
                {
                    Fail("failed ISO9796-2 updateWithRecovered recovered message Test 4");
                }
                
                if (!eng.VerifySignature(sig4))
                {
                    Fail("failed ISO9796-2 updateWithRecovered verify and recover Test 4");
                }
                
                if(!IsSameAs(eng.GetRecoveredMessage(), 0, msg4))
                {
                    Fail("failed ISO9796-2 updateWithRecovered recovered verify message Test 4");
                }
                
                // should fail
                eng.UpdateWithRecoveredMessage(sig4);
                
                eng.BlockUpdate(msg4, 0, msg4.Length);
                
                if (eng.VerifySignature(sig4))
                {
                    Fail("failed ISO9796-2 updateWithRecovered verify and recover Test 4");
                }
            }
            else
            {
                Fail("full message flag false - Test 4");
            }
        }