8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /** 25 * @test 26 * @bug 8209951 27 * @summary SIGBUS in com.sun.crypto.provider.CipherBlockChaining 28 * @run main/othervm/timeout=300 -Xbatch 29 * compiler.codegen.aes.TestCipherBlockChainingEncrypt 30 */ 31 32 package compiler.codegen.aes; 33 34 import java.io.PrintStream; 35 import java.security.*; 36 import java.util.Random; 37 import java.lang.reflect.Method; 38 import javax.crypto.Cipher; 39 import javax.crypto.SecretKey; 40 import javax.crypto.SecretKeyFactory; 41 import javax.crypto.spec.PBEKeySpec; 42 43 public class TestCipherBlockChainingEncrypt { 44 private static String algorithm = "PBEWithHmacSHA1AndAES_256"; 45 private static final String PBEPASS = "Hush, it's supposed to be a secret!"; 46 47 private static final int INPUT_LENGTH = 800; 48 private static final int[] OFFSETS = {0}; 49 private static final int NUM_PAD_BYTES = 8; 50 private static final int PBKDF2_ADD_PAD_BYTES = 8; 51 52 private static SecretKey key; 53 private static Cipher ci; 54 55 public static void main(String[] args) throws Exception { 56 for(int i=0; i<5_000; i++) { 57 if (!(new TestCipherBlockChainingEncrypt().test(args))) { 58 throw new RuntimeException("TestCipherBlockChainingEncrypt test failed"); 59 } 60 } 61 } 62 63 public boolean test(String[] args) throws Exception { 64 boolean result = true; 65 66 Provider p = Security.getProvider("SunJCE"); 67 ci = Cipher.getInstance(algorithm, p); 68 key = SecretKeyFactory.getInstance(algorithm, p).generateSecret( 69 new PBEKeySpec(PBEPASS.toCharArray())); 70 71 // generate input data 72 byte[] inputText = new byte[INPUT_LENGTH + NUM_PAD_BYTES 73 + PBKDF2_ADD_PAD_BYTES]; 74 new Random().nextBytes(inputText); 75 76 try { | 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /** 25 * @test 26 * @bug 8209951 27 * @summary SIGBUS in com.sun.crypto.provider.CipherBlockChaining 28 * @library /test/lib / 29 * @build sun.hotspot.WhiteBox 30 * @run driver ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission 31 * 32 * @run main/othervm -Xbatch 33 * -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. 34 * compiler.codegen.aes.TestCipherBlockChainingEncrypt 35 */ 36 37 package compiler.codegen.aes; 38 39 import java.io.PrintStream; 40 import java.security.*; 41 import java.util.Random; 42 import java.lang.reflect.Method; 43 import javax.crypto.Cipher; 44 import javax.crypto.SecretKey; 45 import javax.crypto.SecretKeyFactory; 46 import javax.crypto.spec.PBEKeySpec; 47 48 import compiler.whitebox.CompilerWhiteBoxTest; 49 import sun.hotspot.code.Compiler; 50 import jtreg.SkippedException; 51 52 public class TestCipherBlockChainingEncrypt { 53 private static String algorithm = "PBEWithHmacSHA1AndAES_256"; 54 private static final String PBEPASS = "Hush, it's supposed to be a secret!"; 55 56 private static final int INPUT_LENGTH = 800; 57 private static final int[] OFFSETS = {0}; 58 private static final int NUM_PAD_BYTES = 8; 59 private static final int PBKDF2_ADD_PAD_BYTES = 8; 60 61 private static SecretKey key; 62 private static Cipher ci; 63 64 public static void main(String[] args) throws Exception { 65 if (!Compiler.isIntrinsicAvailable(CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION, "com.sun.crypto.provider.CipherBlockChaining", "implEncrypt", byte[].class, int.class, int.class, byte[].class, int.class)) { 66 throw new SkippedException("Base64 intrinsic is not available"); 67 } 68 for(int i=0; i<2_000; i++) { 69 if (!(new TestCipherBlockChainingEncrypt().test(args))) { 70 throw new RuntimeException("TestCipherBlockChainingEncrypt test failed"); 71 } 72 } 73 } 74 75 public boolean test(String[] args) throws Exception { 76 boolean result = true; 77 78 Provider p = Security.getProvider("SunJCE"); 79 ci = Cipher.getInstance(algorithm, p); 80 key = SecretKeyFactory.getInstance(algorithm, p).generateSecret( 81 new PBEKeySpec(PBEPASS.toCharArray())); 82 83 // generate input data 84 byte[] inputText = new byte[INPUT_LENGTH + NUM_PAD_BYTES 85 + PBKDF2_ADD_PAD_BYTES]; 86 new Random().nextBytes(inputText); 87 88 try { |