/*
* 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.
*/
/**
* Support for ArcFour in Kerberos
* as defined in RFC 4757.
*
* @author Seema Malkani
*/
private static final boolean debug = false;
private final int keyLength;
}
protected int getKeySeedLength() {
return keyLength; // bits; RC4 key material
}
// simple identity operation
return in;
}
throws GeneralSecurityException {
}
/*
* String2Key(Password)
* K = MD4(UNICODE(password))
*/
throws GeneralSecurityException {
throw new RuntimeException("Invalid parameter to stringToKey");
}
try {
// convert ascii to unicode
// provider for MD4
} catch (Exception e) {
return null;
} finally {
}
}
return digest;
}
throws GeneralSecurityException {
// IV
}
return cipher;
}
public int getChecksumLength() {
return hashSize; // bytes
}
/**
* Get the HMAC-MD5
*/
throws GeneralSecurityException {
// generate hash
return hash;
}
/**
* Calculate the checksum
*/
if (debug) {
usage);
}
throw new GeneralSecurityException("Invalid key usage number: "
+ usage);
}
// Derive signing key from session key
try {
// need to append end-of-string 00
} catch (Exception e) {
new GeneralSecurityException("Calculate Checkum Failed!");
throw gse;
}
// get the salt using key usage
// Generate checksum of message
try {
} catch (NoSuchAlgorithmException e) {
new GeneralSecurityException("Calculate Checkum Failed!");
throw gse;
}
// Generate checksum
if (debug) {
}
return hmac;
byte[] buf = new byte[getChecksumLength()];
return buf;
} else {
throw new GeneralSecurityException("checksum size too short: " +
}
}
/**
* Performs encryption of Sequence Number using derived key.
*/
throws GeneralSecurityException, KrbCryptoException {
throw new GeneralSecurityException("Invalid key usage number: "
+ usage);
}
// derive encryption for sequence number
byte[] salt = new byte[4];
// derive new encryption key salted with sequence number
return output;
}
/**
* Performs decryption of Sequence Number using derived key.
*/
throws GeneralSecurityException, KrbCryptoException {
throw new GeneralSecurityException("Invalid key usage number: "
+ usage);
}
// derive decryption for sequence number
byte[] salt = new byte[4];
// derive new encryption key salted with sequence number
return output;
}
/**
* Performs encryption using derived key; adds confounder.
*/
throws GeneralSecurityException, KrbCryptoException {
throw new GeneralSecurityException("Invalid key usage number: "
+ usage);
}
if (debug) {
}
// get the confounder
// add confounder to the plaintext for encryption
byte[] toBeEncrypted = new byte[plainSize];
/* begin the encryption, compute K1 */
// get the salt using key usage
// compute K2 using K1
// generate checksum using K2
// compute K3 using K2 and checksum
// encryptedData + HMAC
return result;
}
/**
* Performs encryption using derived key; does not add confounder.
*/
throws GeneralSecurityException, KrbCryptoException {
throw new GeneralSecurityException("Invalid key usage number: "
+ usage);
}
if (debug) {
}
// Derive encryption key for data
// Key derivation salt = 0
for (int i = 0; i <= 15; i++) {
}
byte[] salt = new byte[4];
// Note: When using this RC4 based encryption type, the sequence number
// is always sent in big-endian rather than little-endian order.
// new encryption key salted with sequence number
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]
*/
throws GeneralSecurityException {
throw new GeneralSecurityException("Invalid key usage number: "
+ usage);
}
if (debug) {
}
// compute K1
// get the salt using key usage
// compute K2 using K1
// compute K3 using K2 and checksum
// Decrypt [confounder | plaintext ] (without checksum)
// Verify checksum
if (debug) {
hashSize);
}
boolean cksumFailed = false;
for (int i = 0; i < hashSize; i++) {
if (calculatedHmac[i] != ciphertext[i]) {
cksumFailed = true;
if (debug) {
}
break;
}
}
}
if (cksumFailed) {
throw new GeneralSecurityException("Checksum failed");
}
// Get rid of confounder
// [ confounder | plaintext ]
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);
}
if (debug) {
}
// Derive encryption key for data
// Key derivation salt = 0
for (int i = 0; i <= 15; i++) {
}
byte[] salt = new byte[4];
// need only first 4 bytes of sequence number
byte[] sequenceNum = new byte[4];
// new encryption key salted with sequence number
return output;
}
// get the salt using key usage
byte[] salt = new byte[4];
return salt;
}
// Key usage translation for MS
switch (usage) {
case 3: return 8;
case 9: return 8;
case 23: return 13;
default: return usage;
}
}
}