Пример #1
0
        public void DoShortPartialTest()
        {
            byte[]     recovered = Hex.Decode("5553482b312b534536383031353332393731392b322b312b362b322b312b313a3a393939393939393939393939393a3a392b323a3a373737373737373737373737373a3a392b2b353a32303133303430353a313133");
            BigInteger exp       = new BigInteger("10001", 16);
            BigInteger mod       = new BigInteger("b9b70b083da9e37e23cde8e654855db31e21d2d3fc11a5f91d2b3c311efa8f5e28c757dd6fc798631cb1b9d051c14119749cb122ad76e8c3fd7bd93abe282c026a14fba9f8023977a7a0d8b49a24d1ad87e4379a931846a1ef9520ea57e28c998cf65722683d0caaa0da8306973e2496a25cbd3cb4adb4b284e25604fabf12f385456c75da7c3c4cde37440cfb7db8c8fe6851e2bc59767b9f7218540238ac8acef3bc7bd3dc6671320c2c1a2ac8a6799ce1eaf62b9683ab1e1341b37b9249dbd6cd987b2f27b5c4619a1eda7f0fb0b59a519afbbc3cee640261cec90a4bb8fefbc844082dca9f549e56943e758579a453a357e6ccb37fc46718a5b8c3227e5d", 16);

            AsymmetricKeyParameter pubKey = new RsaKeyParameters(false, mod, exp);

            Iso9796d2PssSigner pssSign = new Iso9796d2PssSigner(new RsaEngine(), new Sha1Digest(), 20);

            pssSign.Init(false, pubKey);

            pssSign.UpdateWithRecoveredMessage(shortPartialSig);

            byte[] recoveredMessage = pssSign.GetRecoveredMessage();
            pssSign.BlockUpdate(longMessage, recoveredMessage.Length, longMessage.Length - recoveredMessage.Length);

            if (!pssSign.VerifySignature(shortPartialSig))
            {
                Fail("short partial PSS sig verification failed.");
            }

            byte[] mm = pssSign.GetRecoveredMessage();

            if (!Arrays.AreEqual(recovered, mm))
            {
                Fail("short partial PSS recovery failed");
            }
        }
Пример #2
0
        public void DoFullMessageTest()
        {
            BigInteger       modulus    = new BigInteger(1, Hex.Decode("CDCBDABBF93BE8E8294E32B055256BBD0397735189BF75816341BB0D488D05D627991221DF7D59835C76A4BB4808ADEEB779E7794504E956ADC2A661B46904CDC71337DD29DDDD454124EF79CFDD7BC2C21952573CEFBA485CC38C6BD2428809B5A31A898A6B5648CAA4ED678D9743B589134B7187478996300EDBA16271A861"));
            BigInteger       pubExp     = new BigInteger(1, Hex.Decode("010001"));
            BigInteger       privExp    = new BigInteger(1, Hex.Decode("4BA6432AD42C74AA5AFCB6DF60FD57846CBC909489994ABD9C59FE439CC6D23D6DE2F3EA65B8335E796FD7904CA37C248367997257AFBD82B26F1A30525C447A236C65E6ADE43ECAAF7283584B2570FA07B340D9C9380D88EAACFFAEEFE7F472DBC9735C3FF3A3211E8A6BBFD94456B6A33C17A2C4EC18CE6335150548ED126D"));
            RsaKeyParameters pubParams  = new RsaKeyParameters(false, modulus, pubExp);
            RsaKeyParameters privParams = new RsaKeyParameters(true, modulus, privExp);

            IAsymmetricBlockCipher rsaEngine = new RsaBlindedEngine();

            // set challenge to all zero's for verification
            byte[] challenge = new byte[8];

            Iso9796d2PssSigner pssSign = new Iso9796d2PssSigner(new RsaEngine(), new Sha256Digest(), 20, true);

            pssSign.Init(true, privParams);

            pssSign.BlockUpdate(challenge, 0, challenge.Length);

            byte[] sig = pssSign.GenerateSignature();

            pssSign.Init(false, pubParams);

            pssSign.UpdateWithRecoveredMessage(sig);

            if (!pssSign.VerifySignature(sig))
            {
                Fail("challenge PSS sig verification failed.");
            }

            byte[] mm = pssSign.GetRecoveredMessage();

            if (!Arrays.AreEqual(challenge, mm))
            {
                Fail("challenge partial PSS recovery failed");
            }
        }