public virtual void DoTest11() { 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; byte[] m1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; byte[] m2 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }; byte[] m3 = { 1, 2, 3, 4, 5, 6, 7, 8 }; // // ISO 9796-2 - PSS Signing // IDigest dig = new Sha1Digest(); Iso9796d2PssSigner eng = new Iso9796d2PssSigner(rsa, dig, dig.GetDigestSize()); // // check message bounds // eng.Init(true, privParameters); eng.BlockUpdate(m1, 0, m1.Length); data = eng.GenerateSignature(); eng.Init(false, pubParameters); eng.BlockUpdate(m2, 0, m2.Length); if (eng.VerifySignature(data)) { Fail("failed ISO9796-2 m2 verify Test 11"); } eng.Init(false, pubParameters); eng.BlockUpdate(m3, 0, m3.Length); if (eng.VerifySignature(data)) { Fail("failed ISO9796-2 m3 verify Test 11"); } eng.Init(false, pubParameters); eng.BlockUpdate(m1, 0, m1.Length); if (!eng.VerifySignature(data)) { Fail("failed ISO9796-2 verify Test 11"); } }
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"); } }
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"); } }
public virtual void DoTest6() { byte[] salt = Hex.Decode("61DF870C4890FE85D6E3DD87C3DCE3723F91DB49"); 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, true); eng.Init(true, sigParameters); data = eng.GenerateSignature(); eng.Init(false, pubParameters); if (!IsSameAs(sig6, 1, data)) { Fail("failed ISO9796-2 generation Test 6"); } if (!eng.VerifySignature(data)) { Fail("failed ISO9796-2 verify Test 6"); } }
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"); } }
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"); } } }
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"); } }
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"); } }