2362N/A * Copyright (c) 2005, 2007, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * @summary Verify that CTR mode works as expected 0N/A * @author Valerie Peng 0N/A byte[] b =
new byte[n];
0N/A * Use test vectors, i.e. PLAIN1 and CIPHER1, from the appendix B 0N/A * of RFC 3962 "Advanced Encryption Standard (AES) Encryption for 0N/A "2047656e6572616c20476175277320"),
0N/A "2047656e6572616c2047617527732043"),
0N/A "2047656e6572616c2047617527732043" +
0N/A "6869636b656e2c20706c656173652c"),
0N/A "2047656e6572616c2047617527732043" +
0N/A "6869636b656e2c20706c656173652c20"),
0N/A "2047656e6572616c2047617527732043" +
0N/A "6869636b656e2c20706c656173652c20" +
0N/A "616e6420776f6e746f6e20736f75702e")
0N/A "97687268d6ecccc0c07b25e25ecfe5"),
0N/A "97687268d6ecccc0c07b25e25ecfe584"),
0N/A "b3fffd940c16a18c1b5549d2f838029e" +
0N/A "39312523a78662d5be7fcbcc98ebf5"),
0N/A "9dad8bbb96c4cdc03bc103e1a194bbd8" +
0N/A "39312523a78662d5be7fcbcc98ebf5a8"),
0N/A "39312523a78662d5be7fcbcc98ebf5a8" +
0N/A "4807efe836ee89a526730dbc2f7bc840" +
0N/A "9dad8bbb96c4cdc03bc103e1a194bbd8"),
0N/A "DES",
"DESede",
"Blowfish",
"AES" 0N/A int k = b[i] &
0xff;
0N/A * Test with the test vectors and see if results match. 0N/A // skip tests using keys whose length exceeds 0N/A // what's configured in jce jurisdiction policy files. 0N/A * sure that same data is recovered after decryption. 0N/A // skip tests using keys whose length exceeds 0N/A // what's configured in jce jurisdiction policy files. 0N/A // Make sure encryption works for inputs with valid length 0N/A // Make sure IllegalBlockSizeException is thrown for inputs 0N/A // with less-than-a-block length 0N/A // Make sure data is encrypted as in CBC mode for inputs 0N/A // which is exactly one block long 0N/A // Make sure decryption works for inputs with valid length 0N/A // Make sure IllegalBlockSizeException is thrown for inputs 0N/A // with less-than-a-block length 0N/A // Make sure data is decrypted as in CBC mode for inputs 0N/A // which is exactly one block long 0N/A * still works correctly afterwards. 0N/A // Skip PLAIN1[0, 1, 2] due to their lengths 0N/A // skip tests using keys whose length exceeds 0N/A // what's configured in jce jurisdiction policy files. 0N/A // expected exception thrown; retry 0N/A // expected exception thrown; retry