001: /*
002: * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package sun.security.krb5.internal.crypto;
027:
028: import sun.security.krb5.KrbCryptoException;
029: import sun.security.krb5.internal.*;
030: import java.security.GeneralSecurityException;
031: import sun.security.krb5.EncryptedData;
032: import sun.security.krb5.Checksum;
033:
034: /*
035: * This class encapsulates the encryption type for RC4-HMAC
036: *
037: * @author Seema Malkani
038: * @version 1.7, 05/05/07
039: */
040:
041: public final class ArcFourHmacEType extends EType {
042:
043: public int eType() {
044: return EncryptedData.ETYPE_ARCFOUR_HMAC;
045: }
046:
047: public int minimumPadSize() {
048: return 1;
049: }
050:
051: public int confounderSize() {
052: return 8;
053: }
054:
055: public int checksumType() {
056: return Checksum.CKSUMTYPE_HMAC_MD5_ARCFOUR;
057: }
058:
059: public int checksumSize() {
060: return ArcFourHmac.getChecksumLength();
061: }
062:
063: public int blockSize() {
064: return 1;
065: }
066:
067: public int keyType() {
068: return Krb5.KEYTYPE_ARCFOUR_HMAC;
069: }
070:
071: public int keySize() {
072: return 16; // bytes
073: }
074:
075: public byte[] encrypt(byte[] data, byte[] key, int usage)
076: throws KrbCryptoException {
077: byte[] ivec = new byte[blockSize()];
078: return encrypt(data, key, ivec, usage);
079: }
080:
081: public byte[] encrypt(byte[] data, byte[] key, byte[] ivec,
082: int usage) throws KrbCryptoException {
083: try {
084: return ArcFourHmac.encrypt(key, usage, ivec, data, 0,
085: data.length);
086: } catch (GeneralSecurityException e) {
087: KrbCryptoException ke = new KrbCryptoException(e
088: .getMessage());
089: ke.initCause(e);
090: throw ke;
091: }
092: }
093:
094: public byte[] decrypt(byte[] cipher, byte[] key, int usage)
095: throws KrbApErrException, KrbCryptoException {
096: byte[] ivec = new byte[blockSize()];
097: return decrypt(cipher, key, ivec, usage);
098: }
099:
100: public byte[] decrypt(byte[] cipher, byte[] key, byte[] ivec,
101: int usage) throws KrbApErrException, KrbCryptoException {
102: try {
103: return ArcFourHmac.decrypt(key, usage, ivec, cipher, 0,
104: cipher.length);
105: } catch (GeneralSecurityException e) {
106: KrbCryptoException ke = new KrbCryptoException(e
107: .getMessage());
108: ke.initCause(e);
109: throw ke;
110: }
111: }
112:
113: // Override default, because our decrypted data does not return confounder
114: // Should eventually get rid of EType.decryptedData and
115: // EncryptedData.decryptedData altogether
116: public byte[] decryptedData(byte[] data) {
117: return data;
118: }
119: }
|