diff -r a5d07d83b4b1 -r f5d3509ad92b jdk/test/sun/security/pkcs11/Cipher/TestRSACipher.java --- a/jdk/test/sun/security/pkcs11/Cipher/TestRSACipher.java Mon Mar 07 11:36:37 2011 -0800 +++ b/jdk/test/sun/security/pkcs11/Cipher/TestRSACipher.java Mon Mar 07 14:14:37 2011 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,7 +23,7 @@ /** * @test - * @bug 4898468 + * @bug 4898468 6994008 * @summary basic test for RSA cipher * @author Andreas Sterbenz * @library .. @@ -38,9 +38,12 @@ public class TestRSACipher extends PKCS11Test { + private static final String[] RSA_ALGOS = + { "RSA/ECB/PKCS1Padding", "RSA" }; + public void main(Provider p) throws Exception { try { - Cipher.getInstance("RSA/ECB/PKCS1Padding", p); + Cipher.getInstance(RSA_ALGOS[0], p); } catch (GeneralSecurityException e) { System.out.println("Not supported by provider, skipping"); return; @@ -55,57 +58,58 @@ b = new byte[16]; random.nextBytes(b); - Cipher c1 = Cipher.getInstance("RSA/ECB/PKCS1Padding", p); - Cipher c2 = Cipher.getInstance("RSA/ECB/PKCS1Padding", "SunJCE"); + for (String rsaAlgo: RSA_ALGOS) { + Cipher c1 = Cipher.getInstance(rsaAlgo, p); + Cipher c2 = Cipher.getInstance(rsaAlgo, "SunJCE"); - c1.init(Cipher.ENCRYPT_MODE, publicKey); - e = c1.doFinal(b); - c1.init(Cipher.DECRYPT_MODE, privateKey); - d = c1.doFinal(e); - match(b, d); - c2.init(Cipher.DECRYPT_MODE, privateKey); - d = c2.doFinal(e); - match(b, d); + c1.init(Cipher.ENCRYPT_MODE, publicKey); + e = c1.doFinal(b); + c1.init(Cipher.DECRYPT_MODE, privateKey); + d = c1.doFinal(e); + match(b, d); + c2.init(Cipher.DECRYPT_MODE, privateKey); + d = c2.doFinal(e); + match(b, d); - // invalid data - c1.init(Cipher.DECRYPT_MODE, publicKey); - try { - d = c1.doFinal(e); - throw new Exception("completed call"); - } catch (BadPaddingException ee) { - ee.printStackTrace(); - } + // invalid data + c1.init(Cipher.DECRYPT_MODE, publicKey); + try { + d = c1.doFinal(e); + throw new Exception("completed call"); + } catch (BadPaddingException ee) { + ee.printStackTrace(); + } - c1.init(Cipher.ENCRYPT_MODE, privateKey); - e = c1.doFinal(b); - c1.init(Cipher.DECRYPT_MODE, publicKey); - d = c1.doFinal(e); - match(b, d); - c2.init(Cipher.DECRYPT_MODE, publicKey); - d = c2.doFinal(e); - match(b, d); + c1.init(Cipher.ENCRYPT_MODE, privateKey); + e = c1.doFinal(b); + c1.init(Cipher.DECRYPT_MODE, publicKey); + d = c1.doFinal(e); + match(b, d); + c2.init(Cipher.DECRYPT_MODE, publicKey); + d = c2.doFinal(e); + match(b, d); - // reinit tests - c1.init(Cipher.ENCRYPT_MODE, privateKey); - c1.init(Cipher.ENCRYPT_MODE, privateKey); - e = c1.doFinal(b); - e = c1.doFinal(b); - c1.update(b); - c1.update(b); - c1.init(Cipher.ENCRYPT_MODE, privateKey); - e = c1.doFinal(); - e = c1.doFinal(); - c1.update(b); - e = c1.doFinal(); + // reinit tests + c1.init(Cipher.ENCRYPT_MODE, privateKey); + c1.init(Cipher.ENCRYPT_MODE, privateKey); + e = c1.doFinal(b); + e = c1.doFinal(b); + c1.update(b); + c1.update(b); + c1.init(Cipher.ENCRYPT_MODE, privateKey); + e = c1.doFinal(); + e = c1.doFinal(); + c1.update(b); + e = c1.doFinal(); - c1.update(new byte[256]); - try { - e = c1.doFinal(); - throw new Exception("completed call"); - } catch (IllegalBlockSizeException ee) { - System.out.println(ee); + c1.update(new byte[256]); + try { + e = c1.doFinal(); + throw new Exception("completed call"); + } catch (IllegalBlockSizeException ee) { + System.out.println(ee); + } } - } private static void match(byte[] b1, byte[] b2) throws Exception {