public void doTest6() throws Exception { 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(); if (eng.getRecoveredMessage().length != 0) { fail("failed zero check"); } 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 void doTest8() throws Exception { 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.update(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.update(msg8, 1, msg8.length - 1); if (!eng.verifySignature(sig8)) { fail("failed ISO9796-2 verify Test 8"); } }
private void doShortPartialTest() throws Exception { 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); pssSign.update(longMessage, pssSign.getRecoveredMessage().length, longMessage.length - pssSign.getRecoveredMessage().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"); } }
private void doFullMessageTest() throws Exception { 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); AsymmetricBlockCipher 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.update(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 void doTest6() throws Exception { 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 void doTest9() throws Exception { 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.update(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.update(msg9, 1, msg9.length - 1); if (!eng.verifySignature(sig9)) { fail("failed ISO9796-2 verify Test 9"); } }
public void doTest7() throws Exception { 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.update(msg7, 1, msg7.length - 1); data = eng.generateSignature(); if (!eng.hasFullMessage()) { fail("full message not detected"); } byte[] recovered = new byte[eng.getRecoveredMessage().length]; System.arraycopy(eng.getRecoveredMessage(), 0, recovered, 0, recovered.length); eng.init(false, pubParameters); if (!isSameAs(sig7, 0, data)) { fail("failed ISO9796-2 generation Test 7"); } eng.update(msg7[0]); eng.update(msg7, 1, msg7.length - 1); if (!eng.verifySignature(sig7)) { fail("failed ISO9796-2 verify Test 7"); } if (!eng.hasFullMessage()) { fail("full message not detected"); } if (!isSameAs(msg7, 0, eng.getRecoveredMessage())) { fail("failed ISO9796-2 recovery Test 7"); } if (!isSameAs(recovered, 0, eng.getRecoveredMessage())) { fail("failed ISO9796-2 recovery Test 7 recover"); } }
public void doTest9() throws Exception { 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.update(msg9, 1, msg9.length - 1); data = eng.generateSignature(); byte[] recovered = new byte[eng.getRecoveredMessage().length]; System.arraycopy(eng.getRecoveredMessage(), 0, recovered, 0, recovered.length); eng.init(false, pubParameters); if (!isSameAs(sig9, 0, data)) { fail("failed ISO9796-2 generation Test 9"); } eng.update(msg9[0]); eng.update(msg9, 1, msg9.length - 1); if (!eng.verifySignature(sig9)) { fail("failed ISO9796-2 verify Test 9"); } if (!isSameAs(recovered, 0, eng.getRecoveredMessage())) { fail("failed ISO9796-2 recovery Test 7 recover"); } }
public void doTest10() throws Exception { 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 // Digest 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.update(msg9, 1, msg9.length - 1); data = eng.generateSignature(); eng.init(false, pubParameters); eng.update(msg9[0]); eng.update(msg9, 1, msg9.length - 1); if (!eng.verifySignature(data)) { fail("failed ISO9796-2 verify Test 10"); } } }
public void doTest11() throws Exception { 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 // Digest dig = new SHA1Digest(); ISO9796d2PSSSigner eng = new ISO9796d2PSSSigner(rsa, dig, dig.getDigestSize()); // // check message bounds // eng.init(true, privParameters); eng.update(m1, 0, m1.length); data = eng.generateSignature(); eng.init(false, pubParameters); eng.update(m2, 0, m2.length); if (eng.verifySignature(data)) { fail("failed ISO9796-2 m2 verify Test 11"); } eng.init(false, pubParameters); eng.update(m3, 0, m3.length); if (eng.verifySignature(data)) { fail("failed ISO9796-2 m3 verify Test 11"); } eng.init(false, pubParameters); eng.update(m1, 0, m1.length); if (!eng.verifySignature(data)) { fail("failed ISO9796-2 verify Test 11"); } }
public void doTest7() throws Exception { 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.update(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.update(msg7, 1, msg7.length - 1); if (!eng.verifySignature(sig7)) { fail("failed ISO9796-2 verify Test 7"); } if (!isSameAs(msg7, 0, eng.getRecoveredMessage())) { fail("failed ISO9796-2 recovery Test 7"); } }