Example #1
0
        public virtual void DoTest9()
        {
            RsaKeyParameters pubParameters  = new RsaKeyParameters(false, mod6, pub6);
            RsaKeyParameters privParameters = new RsaKeyParameters(true, mod6, pri6);
            RsaEngine        rsa            = new RsaEngine();

            byte[] data;

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

            eng.Init(true, privParameters);

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

            data = eng.GenerateSignature();

            eng.Init(false, pubParameters);

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

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

            if (!eng.VerifySignature(data))
            {
                Fail("failed ISO9796-2 verify Test 9");
            }
        }
Example #2
0
        public virtual void DoTest7()
        {
            byte[]             salt           = new byte[0];
            RsaKeyParameters   pubParameters  = new RsaKeyParameters(false, mod6, pub6);
            RsaKeyParameters   privParameters = new RsaKeyParameters(true, mod6, pri6);
            ParametersWithSalt sigParameters  = new ParametersWithSalt(privParameters, salt);
            RsaEngine          rsa            = new RsaEngine();

            byte[] data;

            //
            // ISO 9796-2 - PSS Signing
            //
            Iso9796d2PssSigner eng = new Iso9796d2PssSigner(rsa, new Sha1Digest(), 0, false);

            eng.Init(true, sigParameters);

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

            data = eng.GenerateSignature();

            eng.Init(false, pubParameters);

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

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

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

            if (!IsSameAs(msg7, 0, eng.GetRecoveredMessage()))
            {
                Fail("failed ISO9796-2 recovery Test 7");
            }
        }
Example #3
0
        public virtual void DoTest10()
        {
            BigInteger       mod            = new BigInteger("B3ABE6D91A4020920F8B3847764ECB34C4EB64151A96FDE7B614DC986C810FF2FD73575BDF8532C06004C8B4C8B64F700A50AEC68C0701ED10E8D211A4EA554D", 16);
            BigInteger       pubExp         = new BigInteger("65537", 10);
            BigInteger       priExp         = new BigInteger("AEE76AE4716F77C5782838F328327012C097BD67E5E892E75C1356E372CCF8EE1AA2D2CBDFB4DA19F703743F7C0BA42B2D69202BA7338C294D1F8B6A5771FF41", 16);
            RsaKeyParameters pubParameters  = new RsaKeyParameters(false, mod, pubExp);
            RsaKeyParameters privParameters = new RsaKeyParameters(true, mod, priExp);
            RsaEngine        rsa            = new RsaEngine();

            byte[] data;

            //
            // ISO 9796-2 - PSS Signing
            //
            IDigest            dig = new Sha1Digest();
            Iso9796d2PssSigner eng = new Iso9796d2PssSigner(rsa, dig, dig.GetDigestSize());

            //
            // as the padding is random this test needs to repeat a few times to
            // make sure
            //
            for (int i = 0; i != 500; i++)
            {
                eng.Init(true, privParameters);

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

                data = eng.GenerateSignature();

                eng.Init(false, pubParameters);

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

                if (!eng.VerifySignature(data))
                {
                    Fail("failed ISO9796-2 verify Test 10");
                }
            }
        }
Example #4
0
        public virtual void DoTest8()
        {
            byte[]             salt           = Hex.Decode("78E293203CBA1B7F92F05F4D171FF8CA3E738FF8");
            RsaKeyParameters   pubParameters  = new RsaKeyParameters(false, mod6, pub6);
            RsaKeyParameters   privParameters = new RsaKeyParameters(true, mod6, pri6);
            ParametersWithSalt sigParameters  = new ParametersWithSalt(privParameters, salt);
            RsaEngine          rsa            = new RsaEngine();

            byte[] data;

            //
            // ISO 9796-2 - PSS Signing
            //
            Iso9796d2PssSigner eng = new Iso9796d2PssSigner(rsa, new RipeMD160Digest(), 20, false);

            eng.Init(true, sigParameters);

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

            data = eng.GenerateSignature();

            eng.Init(false, pubParameters);

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

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

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