/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 5083253
* @run main CTSMode
* @summary Verify that CTR mode works as expected
* @author Valerie Peng
*/
public class CTSMode {
char[] c = s.toCharArray();
byte[] t = new byte[c.length / 2];
int n = 0;
int d1 = -1;
int d2 = -1;
for (int i = 0; i < c.length; i++) {
char ch = c[i];
if (d1 == -1) {
} else {
if (d2 != -1) {
d1 = -1;
d2 = -1;
}
}
}
if (d1 != -1) {
throw new RuntimeException();
}
if (n == t.length) {
return t;
}
byte[] b = new byte[n];
return b;
}
"AES");
new IvParameterSpec(new byte[16]);
/*
* Use test vectors, i.e. PLAIN1 and CIPHER1, from the appendix B
* of RFC 3962 "Advanced Encryption Standard (AES) Encryption for
* Kerberos 5".
*/
private final static byte[][] PLAIN1 = {
toByteArray("4920776f756c64206c696b652074686520"),
toByteArray("4920776f756c64206c696b6520746865" +
"2047656e6572616c20476175277320"),
toByteArray("4920776f756c64206c696b6520746865" +
"2047656e6572616c2047617527732043"),
toByteArray("4920776f756c64206c696b6520746865" +
"2047656e6572616c2047617527732043" +
"6869636b656e2c20706c656173652c"),
toByteArray("4920776f756c64206c696b6520746865" +
"2047656e6572616c2047617527732043" +
"6869636b656e2c20706c656173652c20"),
toByteArray("4920776f756c64206c696b6520746865" +
"2047656e6572616c2047617527732043" +
"6869636b656e2c20706c656173652c20" +
"616e6420776f6e746f6e20736f75702e")
};
private final static byte[][] CIPHER1 = {
toByteArray("c6353568f2bf8cb4d8a580362da7ff7f97"),
toByteArray("fc00783e0efdb2c1d445d4c8eff7ed22" +
"97687268d6ecccc0c07b25e25ecfe5"),
toByteArray("39312523a78662d5be7fcbcc98ebf5a8" +
"97687268d6ecccc0c07b25e25ecfe584"),
toByteArray("97687268d6ecccc0c07b25e25ecfe584" +
"b3fffd940c16a18c1b5549d2f838029e" +
"39312523a78662d5be7fcbcc98ebf5"),
toByteArray("97687268d6ecccc0c07b25e25ecfe584" +
"9dad8bbb96c4cdc03bc103e1a194bbd8" +
"39312523a78662d5be7fcbcc98ebf5a8"),
toByteArray("97687268d6ecccc0c07b25e25ecfe584" +
"39312523a78662d5be7fcbcc98ebf5a8" +
"4807efe836ee89a526730dbc2f7bc840" +
"9dad8bbb96c4cdc03bc103e1a194bbd8"),
};
private final static byte[] IV2_SRC =
toByteArray("11223344556677880011223344556677");
"DES", "DESede", "Blowfish", "AES"
};
private final static int[] KEYSIZES2 = {
8, 24, 16, 16
};
for (int i = 0; i < b.length; i++) {
int k = b[i] & 0xff;
if (i != 0) {
}
}
}
test1();
test2();
test3();
}
/**
* Test with the test vectors and see if results match.
*/
// skip tests using keys whose length exceeds
// what's configured in jce jurisdiction policy files.
continue;
}
"SunJCE");
byte[] cipherText = CIPHER1[i];
throw new RuntimeException("Encryption failure for test " + i);
}
throw new RuntimeException("Decryption failure for test " + i);
}
}
}
/**
* sure that same data is recovered after decryption.
*/
if (keySize > MAX_KEYSIZE) {
// skip tests using keys whose length exceeds
// what's configured in jce jurisdiction policy files.
continue;
}
// Make sure encryption works for inputs with valid length
cipherText, 0);
throw new RuntimeException("Encryption failure for test " + i);
}
// Make sure IllegalBlockSizeException is thrown for inputs
// with less-than-a-block length
try {
throw new RuntimeException("Expected IBSE is not thrown");
} catch (IllegalBlockSizeException ibse) {
}
// Make sure data is encrypted as in CBC mode for inputs
// which is exactly one block long
throw new RuntimeException("Different encryption output " +
"for CBC and CTS");
}
// Make sure decryption works for inputs with valid length
byte[] recoveredText =
recoveredText, 0);
int processed3 =
throw new RuntimeException("Decryption failure for test " + i);
}
throw new RuntimeException("Decryption failure for test " + i);
}
// Make sure IllegalBlockSizeException is thrown for inputs
// with less-than-a-block length
try {
throw new RuntimeException("Expected IBSE is not thrown");
} catch (IllegalBlockSizeException ibse) {
}
// Make sure data is decrypted as in CBC mode for inputs
// which is exactly one block long
throw new RuntimeException("Different decryption output " +
"for CBC and CTS");
}
}
}
/**
* Test with a shortBuffer and see if encryption/decryption
* still works correctly afterwards.
*/
// Skip PLAIN1[0, 1, 2] due to their lengths
// skip tests using keys whose length exceeds
// what's configured in jce jurisdiction policy files.
continue;
}
byte[] cipherText = CIPHER1[i];
enc, 0);
try {
new byte[1], 0);
throw new RuntimeException("Expected Exception is not thrown");
} catch (ShortBufferException sbe) {
// expected exception thrown; retry
int processed2 =
enc, processed1);
throw new RuntimeException("Encryption length check " +
"failed");
}
}
throw new RuntimeException("Encryption failure for test " + i);
}
byte[] dec =
dec, 0);
try {
new byte[1], 0);
throw new RuntimeException("Expected Exception is not thrown");
} catch (ShortBufferException sbe) {
// expected exception thrown; retry
dec, processed1);
int processed3 =
throw new RuntimeException("Decryption length check " +
"failed");
}
}
throw new RuntimeException("Decryption failure for test " + i);
}
}
}
}