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 * @run main/othervm/timeout=600 -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<2_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 { |