blob: e75cc0b3541c02a011c3320fefcba9edd63d7ff9 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2004 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.Checksum;
29import sun.security.krb5.KrbCryptoException;
30import sun.security.krb5.internal.*;
31import javax.crypto.spec.DESKeySpec;
32import java.security.InvalidKeyException;
33import java.security.GeneralSecurityException;
34
35/*
36 * This class encapsulates the checksum type for AES128
37 *
38 * @author Seema Malkani
39 */
40
41public class HmacSha1Aes128CksumType extends CksumType {
42
43 public HmacSha1Aes128CksumType() {
44 }
45
46 public int confounderSize() {
47 return 16;
48 }
49
50 public int cksumType() {
51 return Checksum.CKSUMTYPE_HMAC_SHA1_96_AES128;
52 }
53
54 public boolean isSafe() {
55 return true;
56 }
57
58 public int cksumSize() {
59 return 12; // bytes
60 }
61
62 public int keyType() {
63 return Krb5.KEYTYPE_AES;
64 }
65
66 public int keySize() {
67 return 16; // bytes
68 }
69
70 public byte[] calculateChecksum(byte[] data, int size) {
71 return null;
72 }
73
74 /**
75 * Calculates keyed checksum.
76 * @param data the data used to generate the checksum.
77 * @param size length of the data.
78 * @param key the key used to encrypt the checksum.
79 * @return keyed checksum.
80 */
81 public byte[] calculateKeyedChecksum(byte[] data, int size, byte[] key,
82 int usage) throws KrbCryptoException {
83
84 try {
85 return Aes128.calculateChecksum(key, usage, data, 0, size);
86 } catch (GeneralSecurityException e) {
87 KrbCryptoException ke = new KrbCryptoException(e.getMessage());
88 ke.initCause(e);
89 throw ke;
90 }
91 }
92
93 /**
94 * Verifies keyed checksum.
95 * @param data the data.
96 * @param size the length of data.
97 * @param key the key used to encrypt the checksum.
98 * @param checksum
99 * @return true if verification is successful.
100 */
101 public boolean verifyKeyedChecksum(byte[] data, int size,
102 byte[] key, byte[] checksum, int usage) throws KrbCryptoException {
103
104 try {
105 byte[] newCksum = Aes128.calculateChecksum(key, usage,
106 data, 0, size);
107 return isChecksumEqual(checksum, newCksum);
108 } catch (GeneralSecurityException e) {
109 KrbCryptoException ke = new KrbCryptoException(e.getMessage());
110 ke.initCause(e);
111 throw ke;
112 }
113 }
114}