blob: cb53862cb73ec64ed3d2a2316a3ea19121af64a3 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26package sun.security.krb5.internal.crypto;
27
28import sun.security.krb5.EncryptedData;
29import sun.security.krb5.internal.crypto.dk.ArcFourCrypto;
30import sun.security.krb5.KrbCryptoException;
31import java.security.GeneralSecurityException;
32
33/**
34 * Class with static methods for doing RC4-HMAC operations.
35 *
36 * @author Seema Malkani
37 */
38
39public class ArcFourHmac {
40 private static final ArcFourCrypto CRYPTO = new ArcFourCrypto(128);
41
42 private ArcFourHmac() {
43 }
44
45 public static byte[] stringToKey(char[] password)
46 throws GeneralSecurityException {
47 return CRYPTO.stringToKey(password);
48 }
49
50 // in bytes
51 public static int getChecksumLength() {
52 return CRYPTO.getChecksumLength();
53 }
54
55 public static byte[] calculateChecksum(byte[] baseKey, int usage,
56 byte[] input, int start, int len) throws GeneralSecurityException {
57 return CRYPTO.calculateChecksum(baseKey, usage, input, start, len);
58 }
59
60 /* Encrypt Sequence Number */
61 public static byte[] encryptSeq(byte[] baseKey, int usage,
62 byte[] checksum, byte[] plaintext, int start, int len)
63 throws GeneralSecurityException, KrbCryptoException {
64 return CRYPTO.encryptSeq(baseKey, usage, checksum, plaintext, start, len);
65 }
66
67 /* Decrypt Sequence Number */
68 public static byte[] decryptSeq(byte[] baseKey, int usage, byte[] checksum,
69 byte[] ciphertext, int start, int len)
70 throws GeneralSecurityException, KrbCryptoException {
71 return CRYPTO.decryptSeq(baseKey, usage, checksum, ciphertext, start, len);
72 }
73
74 public static byte[] encrypt(byte[] baseKey, int usage,
75 byte[] ivec, byte[] plaintext, int start, int len)
76 throws GeneralSecurityException, KrbCryptoException {
77 return CRYPTO.encrypt(baseKey, usage, ivec, null /* new_ivec */,
78 plaintext, start, len);
79 }
80
81 /* Encrypt plaintext; do not add confounder, or checksum */
82 public static byte[] encryptRaw(byte[] baseKey, int usage,
83 byte[] seqNum, byte[] plaintext, int start, int len)
84 throws GeneralSecurityException, KrbCryptoException {
85 return CRYPTO.encryptRaw(baseKey, usage, seqNum, plaintext, start, len);
86 }
87
88 public static byte[] decrypt(byte[] baseKey, int usage, byte[] ivec,
89 byte[] ciphertext, int start, int len)
90 throws GeneralSecurityException {
91 return CRYPTO.decrypt(baseKey, usage, ivec, ciphertext, start, len);
92 }
93
94 /* Decrypt ciphertext; do not remove confounder, or check checksum */
95 public static byte[] decryptRaw(byte[] baseKey, int usage, byte[] ivec,
96 byte[] ciphertext, int start, int len, byte[] seqNum)
97 throws GeneralSecurityException {
98 return CRYPTO.decryptRaw(baseKey, usage, ivec, ciphertext, start, len, seqNum);
99 }
100};