/*
* 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
/*
*/
/**
* This class provides the implementation of AES Encryption for Kerberos
* as defined RFC 3962.
*
* Algorithm profile described in [KCRYPTO]:
* +--------------------------------------------------------------------+
* | protocol key format 128- or 256-bit string |
* | |
* | string-to-key function PBKDF2+DK with variable |
* | iteration count (see |
* | above) |
* | |
* | default string-to-key parameters 00 00 10 00 |
* | |
* | key-generation seed length key size |
* | |
* | random-to-key function identity function |
* | |
* | hash function, H SHA-1 |
* | |
* | HMAC output size, h 12 octets (96 bits) |
* | |
* | message block size, m 1 octet |
* | |
* | encryption/decryption functions, AES in CBC-CTS mode |
* | E and D (cipher block size 16 |
* | octets), with next to |
* | last block as CBC-style |
* | ivec |
* +--------------------------------------------------------------------+
*
* Supports AES128 and AES256
*
* @author Seema Malkani
*/
private static final boolean debug = false;
0, 0, 0, 0, 0, 0, 0, 0 };
private final int keyLength;
}
protected int getKeySeedLength() {
return keyLength; // bits; AES key material
}
throws GeneralSecurityException {
try {
} catch (Exception e) {
return null;
} finally {
}
}
}
throws GeneralSecurityException {
throw new RuntimeException("Invalid parameter to stringToKey");
}
}
getKeySeedLength()));
return result;
}
// simple identity operation
return in;
}
throws GeneralSecurityException {
// IV
}
return cipher;
}
// get an instance of the AES Cipher in CTS mode
public int getChecksumLength() {
return hashSize; // bytes
}
/**
* Get the truncated HMAC
*/
throws GeneralSecurityException {
// generate hash
// truncate hash
return output;
}
/**
* Calculate the checksum
*/
throw new GeneralSecurityException("Invalid key usage number: "
+ usage);
}
// Derive keys
byte[] constant = new byte[5];
if (debug) {
}
try {
// Generate checksum
// H1 = HMAC(Kc, input)
if (debug) {
}
return hmac;
byte[] buf = new byte[getChecksumLength()];
return buf;
} else {
throw new GeneralSecurityException("checksum size too short: " +
}
} finally {
}
}
/**
* Performs encryption using derived key; adds confounder.
*/
throws GeneralSecurityException, KrbCryptoException {
throw new GeneralSecurityException("Invalid key usage number: "
+ usage);
}
return output;
}
/**
* Performs encryption using derived key; does not add confounder.
*/
throws GeneralSecurityException, KrbCryptoException {
throw new GeneralSecurityException("Invalid key usage number: "
+ usage);
}
return output;
}
/**
* @param baseKey key from which keys are to be derived using usage
* @param ciphertext E(Ke, conf | plaintext | padding, ivec) | H1[1..h]
*/
throw new GeneralSecurityException("Invalid key usage number: "
+ usage);
}
return output;
}
/**
* Decrypts data using specified key and initial vector.
* @param baseKey encryption key to use
* @param ciphertext encrypted data to be decrypted
* @param usage ignored
*/
throws GeneralSecurityException {
throw new GeneralSecurityException("Invalid key usage number: "
+ usage);
}
return output;
}
/**
* Encrypt AES in CBC-CTS mode using derived keys.
*/
boolean confounder_exists)
throws GeneralSecurityException, KrbCryptoException {
if (debug) {
}
}
try {
// derive Encryption key
byte[] constant = new byte[5];
byte[] toBeEncrypted = null;
if (confounder_exists) {
} else {
toBeEncrypted = new byte[len];
}
// encryptedData + HMAC
// AES in JCE
// Derive integrity key
if (debug) {
}
// Generate checksum
// H1 = HMAC(Ki, conf | plaintext | pad)
// encryptedData + HMAC
return output;
} finally {
}
}
}
}
/**
* Decrypt AES in CBC-CTS mode using derived keys.
*/
throws GeneralSecurityException {
try {
// Derive encryption key
byte[] constant = new byte[5];
if (debug) {
}
}
// Decrypt [confounder | plaintext ] (without checksum)
// AES in JCE
if (debug) {
}
// Derive integrity key
if (debug) {
}
// Verify checksum
// H1 = HMAC(Ki, conf | plaintext | pad)
if (debug) {
}
boolean cksumFailed = false;
for (int i = 0; i < hashSize; i++) {
cksumFailed = true;
if (debug) {
}
break;
}
}
}
if (cksumFailed) {
throw new GeneralSecurityException("Checksum failed");
}
if (confounder_exists) {
// Get rid of confounder
// [ confounder | plaintext ]
return output;
} else {
return plaintext;
}
} finally {
}
}
}
}
/*
* Invoke the PKCS#5 PBKDF2 algorithm
*/
return result;
}
int retVal = 0;
while (size > 0) {
shifter -= 8;
pos++;
size--;
}
return retVal;
}
}