|
1 /* |
|
2 * Copyright (c) 2017, Oracle and/or its affiliates. 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. Oracle designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 * or visit www.oracle.com if you need additional information or have any |
|
23 * questions. |
|
24 */ |
|
25 |
|
26 package sun.security.krb5.internal.crypto; |
|
27 |
|
28 import sun.security.krb5.internal.crypto.dk.AesSha2DkCrypto; |
|
29 import sun.security.krb5.KrbCryptoException; |
|
30 import java.security.GeneralSecurityException; |
|
31 |
|
32 /** |
|
33 * Class with static methods for doing aes256-cts-hmac-sha384-192 operations. |
|
34 */ |
|
35 |
|
36 public class Aes256Sha2 { |
|
37 private static final AesSha2DkCrypto CRYPTO = new AesSha2DkCrypto(256); |
|
38 |
|
39 private Aes256Sha2() { |
|
40 } |
|
41 |
|
42 public static byte[] stringToKey(char[] password, String salt, byte[] params) |
|
43 throws GeneralSecurityException { |
|
44 return CRYPTO.stringToKey(password, salt, params); |
|
45 } |
|
46 |
|
47 // in bytes |
|
48 public static int getChecksumLength() { |
|
49 return CRYPTO.getChecksumLength(); |
|
50 } |
|
51 |
|
52 public static byte[] calculateChecksum(byte[] baseKey, int usage, |
|
53 byte[] input, int start, int len) throws GeneralSecurityException { |
|
54 return CRYPTO.calculateChecksum(baseKey, usage, input, start, len); |
|
55 } |
|
56 |
|
57 public static byte[] encrypt(byte[] baseKey, int usage, |
|
58 byte[] ivec, byte[] plaintext, int start, int len) |
|
59 throws GeneralSecurityException, KrbCryptoException { |
|
60 return CRYPTO.encrypt(baseKey, usage, ivec, null /* new_ivec */, |
|
61 plaintext, start, len); |
|
62 } |
|
63 |
|
64 /* Encrypt plaintext; do not add confounder, padding, or checksum */ |
|
65 public static byte[] encryptRaw(byte[] baseKey, int usage, |
|
66 byte[] ivec, byte[] plaintext, int start, int len) |
|
67 throws GeneralSecurityException, KrbCryptoException { |
|
68 return CRYPTO.encryptRaw(baseKey, usage, ivec, plaintext, start, len); |
|
69 } |
|
70 |
|
71 public static byte[] decrypt(byte[] baseKey, int usage, byte[] ivec, |
|
72 byte[] ciphertext, int start, int len) |
|
73 throws GeneralSecurityException { |
|
74 return CRYPTO.decrypt(baseKey, usage, ivec, ciphertext, start, len); |
|
75 } |
|
76 |
|
77 /* |
|
78 * Decrypt ciphertext; do not remove confounder, padding, or check |
|
79 * checksum |
|
80 */ |
|
81 public static byte[] decryptRaw(byte[] baseKey, int usage, byte[] ivec, |
|
82 byte[] ciphertext, int start, int len) |
|
83 throws GeneralSecurityException { |
|
84 return CRYPTO.decryptRaw(baseKey, usage, ivec, ciphertext, start, len); |
|
85 } |
|
86 }; |