1 /*
2  * Copyright (c) 1997, 2020, 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 com.sun.crypto.provider;
27 
28 import java.security.AccessController;
29 import java.security.Provider;
30 import java.security.SecureRandom;
31 
32 
33 /**
34  * The "SunJCE" Cryptographic Service Provider.
35  *
36  * @author Jan Luehe
37  * @author Sharon Liu
38  */
39 
40 /**
41  * Defines the "SunJCE" provider.
42  *
43  * Supported algorithms and their names:
44  *
45  * - RSA encryption (PKCS#1 v1.5 and raw)
46  *
47  * - DES
48  *
49  * - DES-EDE
50  *
51  * - AES
52  *
53  * - Blowfish
54  *
55  * - RC2
56  *
57  * - ARCFOUR (RC4 compatible)
58  *
59  * - Cipher modes ECB, CBC, CFB, OFB, PCBC, CTR, and CTS for all block ciphers
60  *   and mode GCM for AES cipher
61  *
62  * - Cipher padding ISO10126Padding for non-PKCS#5 block ciphers and
63  *   NoPadding and PKCS5Padding for all block ciphers
64  *
65  * - Password-based Encryption (PBE)
66  *
67  * - Diffie-Hellman Key Agreement
68  *
69  * - HMAC-MD5, HMAC-SHA1, HMAC-SHA-224, HMAC-SHA-256, HMAC-SHA-384, HMAC-SHA-512
70  *
71  */
72 
73 public final class SunJCE extends Provider {
74 
75     private static final long serialVersionUID = 6812507587804302833L;
76 
77     private static final String info = "SunJCE Provider " +
78     "(implements RSA, DES, Triple DES, AES, Blowfish, ARCFOUR, RC2, PBE, "
79     + "Diffie-Hellman, HMAC)";
80 
81     private static final String OID_PKCS12_RC4_128 = "1.2.840.113549.1.12.1.1";
82     private static final String OID_PKCS12_RC4_40 = "1.2.840.113549.1.12.1.2";
83     private static final String OID_PKCS12_DESede = "1.2.840.113549.1.12.1.3";
84     private static final String OID_PKCS12_RC2_128 = "1.2.840.113549.1.12.1.5";
85     private static final String OID_PKCS12_RC2_40 = "1.2.840.113549.1.12.1.6";
86     private static final String OID_PKCS5_MD5_DES = "1.2.840.113549.1.5.3";
87     private static final String OID_PKCS5_PBKDF2 = "1.2.840.113549.1.5.12";
88     private static final String OID_PKCS5_PBES2 = "1.2.840.113549.1.5.13";
89     private static final String OID_PKCS3 = "1.2.840.113549.1.3.1";
90 
91     /* Are we debugging? -- for developers */
92     static final boolean debug = false;
93 
94     // Instance of this provider, so we don't have to call the provider list
95     // to find ourselves or run the risk of not being in the list.
96     private static volatile SunJCE instance = null;
97 
98     // lazy initialize SecureRandom to avoid potential recursion if Sun
99     // provider has not been installed yet
100     private static class SecureRandomHolder {
101         static final SecureRandom RANDOM = new SecureRandom();
102     }
getRandom()103     static SecureRandom getRandom() { return SecureRandomHolder.RANDOM; }
104 
SunJCE()105     public SunJCE() {
106         /* We are the "SunJCE" provider */
107         super("SunJCE", 1.8d, info);
108 
109         final String BLOCK_MODES = "ECB|CBC|PCBC|CTR|CTS|CFB|OFB" +
110             "|CFB8|CFB16|CFB24|CFB32|CFB40|CFB48|CFB56|CFB64" +
111             "|OFB8|OFB16|OFB24|OFB32|OFB40|OFB48|OFB56|OFB64";
112         final String BLOCK_MODES128 = BLOCK_MODES +
113             "|GCM|CFB72|CFB80|CFB88|CFB96|CFB104|CFB112|CFB120|CFB128" +
114             "|OFB72|OFB80|OFB88|OFB96|OFB104|OFB112|OFB120|OFB128";
115         final String BLOCK_PADS = "NOPADDING|PKCS5PADDING|ISO10126PADDING";
116 
117         AccessController.doPrivileged(
118             new java.security.PrivilegedAction<Object>() {
119                 public Object run() {
120 
121                     /*
122                      * Cipher engines
123                      */
124                     put("Cipher.RSA", "com.sun.crypto.provider.RSACipher");
125                     put("Cipher.RSA SupportedModes", "ECB");
126                     put("Cipher.RSA SupportedPaddings",
127                             "NOPADDING|PKCS1PADDING|OAEPPADDING"
128                             + "|OAEPWITHMD5ANDMGF1PADDING"
129                             + "|OAEPWITHSHA1ANDMGF1PADDING"
130                             + "|OAEPWITHSHA-1ANDMGF1PADDING"
131                             + "|OAEPWITHSHA-224ANDMGF1PADDING"
132                             + "|OAEPWITHSHA-256ANDMGF1PADDING"
133                             + "|OAEPWITHSHA-384ANDMGF1PADDING"
134                             + "|OAEPWITHSHA-512ANDMGF1PADDING"
135                             + "|OAEPWITHSHA-512/224ANDMGF1PADDING"
136                             + "|OAEPWITHSHA-512/256ANDMGF1PADDING");
137                     put("Cipher.RSA SupportedKeyClasses",
138                             "java.security.interfaces.RSAPublicKey" +
139                             "|java.security.interfaces.RSAPrivateKey");
140 
141                     put("Cipher.DES", "com.sun.crypto.provider.DESCipher");
142                     put("Cipher.DES SupportedModes", BLOCK_MODES);
143                     put("Cipher.DES SupportedPaddings", BLOCK_PADS);
144                     put("Cipher.DES SupportedKeyFormats", "RAW");
145 
146                     put("Cipher.DESede", "com.sun.crypto.provider.DESedeCipher");
147                     put("Alg.Alias.Cipher.TripleDES", "DESede");
148                     put("Cipher.DESede SupportedModes", BLOCK_MODES);
149                     put("Cipher.DESede SupportedPaddings", BLOCK_PADS);
150                     put("Cipher.DESede SupportedKeyFormats", "RAW");
151 
152                     put("Cipher.DESedeWrap",
153                         "com.sun.crypto.provider.DESedeWrapCipher");
154                     put("Cipher.DESedeWrap SupportedModes", "CBC");
155                     put("Cipher.DESedeWrap SupportedPaddings", "NOPADDING");
156                     put("Cipher.DESedeWrap SupportedKeyFormats", "RAW");
157 
158                     // PBES1
159 
160                     put("Cipher.PBEWithMD5AndDES",
161                         "com.sun.crypto.provider.PBEWithMD5AndDESCipher");
162                     put("Alg.Alias.Cipher.OID."+OID_PKCS5_MD5_DES,
163                         "PBEWithMD5AndDES");
164                     put("Alg.Alias.Cipher."+OID_PKCS5_MD5_DES,
165                         "PBEWithMD5AndDES");
166 
167                     put("Cipher.PBEWithMD5AndTripleDES",
168                         "com.sun.crypto.provider.PBEWithMD5AndTripleDESCipher");
169 
170                     put("Cipher.PBEWithSHA1AndDESede",
171                         "com.sun.crypto.provider.PKCS12PBECipherCore$" +
172                         "PBEWithSHA1AndDESede");
173                     put("Alg.Alias.Cipher.OID." + OID_PKCS12_DESede,
174                         "PBEWithSHA1AndDESede");
175                     put("Alg.Alias.Cipher." + OID_PKCS12_DESede,
176                         "PBEWithSHA1AndDESede");
177 
178                     put("Cipher.PBEWithSHA1AndRC2_40",
179                         "com.sun.crypto.provider.PKCS12PBECipherCore$" +
180                         "PBEWithSHA1AndRC2_40");
181                     put("Alg.Alias.Cipher.OID." + OID_PKCS12_RC2_40,
182                         "PBEWithSHA1AndRC2_40");
183                     put("Alg.Alias.Cipher." + OID_PKCS12_RC2_40,
184                         "PBEWithSHA1AndRC2_40");
185 
186                     put("Cipher.PBEWithSHA1AndRC2_128",
187                         "com.sun.crypto.provider.PKCS12PBECipherCore$" +
188                         "PBEWithSHA1AndRC2_128");
189                     put("Alg.Alias.Cipher.OID." + OID_PKCS12_RC2_128,
190                         "PBEWithSHA1AndRC2_128");
191                     put("Alg.Alias.Cipher." + OID_PKCS12_RC2_128,
192                         "PBEWithSHA1AndRC2_128");
193 
194                     put("Cipher.PBEWithSHA1AndRC4_40",
195                         "com.sun.crypto.provider.PKCS12PBECipherCore$" +
196                         "PBEWithSHA1AndRC4_40");
197                     put("Alg.Alias.Cipher.OID." + OID_PKCS12_RC4_40,
198                         "PBEWithSHA1AndRC4_40");
199                     put("Alg.Alias.Cipher." + OID_PKCS12_RC4_40,
200                         "PBEWithSHA1AndRC4_40");
201 
202                     put("Cipher.PBEWithSHA1AndRC4_128",
203                         "com.sun.crypto.provider.PKCS12PBECipherCore$" +
204                         "PBEWithSHA1AndRC4_128");
205                     put("Alg.Alias.Cipher.OID." + OID_PKCS12_RC4_128,
206                         "PBEWithSHA1AndRC4_128");
207                     put("Alg.Alias.Cipher." + OID_PKCS12_RC4_128,
208                         "PBEWithSHA1AndRC4_128");
209 
210                     //PBES2
211 
212                     put("Cipher.PBEWithHmacSHA1AndAES_128",
213                         "com.sun.crypto.provider.PBES2Core$HmacSHA1AndAES_128");
214 
215                     put("Cipher.PBEWithHmacSHA224AndAES_128",
216                         "com.sun.crypto.provider.PBES2Core$" +
217                             "HmacSHA224AndAES_128");
218 
219                     put("Cipher.PBEWithHmacSHA256AndAES_128",
220                         "com.sun.crypto.provider.PBES2Core$" +
221                             "HmacSHA256AndAES_128");
222 
223                     put("Cipher.PBEWithHmacSHA384AndAES_128",
224                         "com.sun.crypto.provider.PBES2Core$" +
225                             "HmacSHA384AndAES_128");
226 
227                     put("Cipher.PBEWithHmacSHA512AndAES_128",
228                         "com.sun.crypto.provider.PBES2Core$" +
229                             "HmacSHA512AndAES_128");
230 
231                     put("Cipher.PBEWithHmacSHA1AndAES_256",
232                         "com.sun.crypto.provider.PBES2Core$HmacSHA1AndAES_256");
233 
234                     put("Cipher.PBEWithHmacSHA224AndAES_256",
235                         "com.sun.crypto.provider.PBES2Core$" +
236                             "HmacSHA224AndAES_256");
237 
238                     put("Cipher.PBEWithHmacSHA256AndAES_256",
239                         "com.sun.crypto.provider.PBES2Core$" +
240                             "HmacSHA256AndAES_256");
241 
242                     put("Cipher.PBEWithHmacSHA384AndAES_256",
243                         "com.sun.crypto.provider.PBES2Core$" +
244                             "HmacSHA384AndAES_256");
245 
246                     put("Cipher.PBEWithHmacSHA512AndAES_256",
247                         "com.sun.crypto.provider.PBES2Core$" +
248                             "HmacSHA512AndAES_256");
249 
250                     put("Cipher.Blowfish",
251                         "com.sun.crypto.provider.BlowfishCipher");
252                     put("Cipher.Blowfish SupportedModes", BLOCK_MODES);
253                     put("Cipher.Blowfish SupportedPaddings", BLOCK_PADS);
254                     put("Cipher.Blowfish SupportedKeyFormats", "RAW");
255 
256                     put("Cipher.AES", "com.sun.crypto.provider.AESCipher$General");
257                     put("Alg.Alias.Cipher.Rijndael", "AES");
258                     put("Cipher.AES SupportedModes", BLOCK_MODES128);
259                     put("Cipher.AES SupportedPaddings", BLOCK_PADS);
260                     put("Cipher.AES SupportedKeyFormats", "RAW");
261 
262                     put("Cipher.AES_128/ECB/NoPadding", "com.sun.crypto.provider.AESCipher$AES128_ECB_NoPadding");
263                     put("Alg.Alias.Cipher.2.16.840.1.101.3.4.1.1", "AES_128/ECB/NoPadding");
264                     put("Alg.Alias.Cipher.OID.2.16.840.1.101.3.4.1.1", "AES_128/ECB/NoPadding");
265                     put("Cipher.AES_128/CBC/NoPadding", "com.sun.crypto.provider.AESCipher$AES128_CBC_NoPadding");
266                     put("Alg.Alias.Cipher.2.16.840.1.101.3.4.1.2", "AES_128/CBC/NoPadding");
267                     put("Alg.Alias.Cipher.OID.2.16.840.1.101.3.4.1.2", "AES_128/CBC/NoPadding");
268                     put("Cipher.AES_128/OFB/NoPadding", "com.sun.crypto.provider.AESCipher$AES128_OFB_NoPadding");
269                     put("Alg.Alias.Cipher.2.16.840.1.101.3.4.1.3", "AES_128/OFB/NoPadding");
270                     put("Alg.Alias.Cipher.OID.2.16.840.1.101.3.4.1.3", "AES_128/OFB/NoPadding");
271                     put("Cipher.AES_128/CFB/NoPadding", "com.sun.crypto.provider.AESCipher$AES128_CFB_NoPadding");
272                     put("Alg.Alias.Cipher.2.16.840.1.101.3.4.1.4", "AES_128/CFB/NoPadding");
273                     put("Alg.Alias.Cipher.OID.2.16.840.1.101.3.4.1.4", "AES_128/CFB/NoPadding");
274                     put("Cipher.AES_128/GCM/NoPadding", "com.sun.crypto.provider.AESCipher$AES128_GCM_NoPadding");
275                     put("Alg.Alias.Cipher.2.16.840.1.101.3.4.1.6", "AES_128/GCM/NoPadding");
276                     put("Alg.Alias.Cipher.OID.2.16.840.1.101.3.4.1.6", "AES_128/GCM/NoPadding");
277 
278                     put("Cipher.AES_192/ECB/NoPadding", "com.sun.crypto.provider.AESCipher$AES192_ECB_NoPadding");
279                     put("Alg.Alias.Cipher.2.16.840.1.101.3.4.1.21", "AES_192/ECB/NoPadding");
280                     put("Alg.Alias.Cipher.OID.2.16.840.1.101.3.4.1.21", "AES_192/ECB/NoPadding");
281                     put("Cipher.AES_192/CBC/NoPadding", "com.sun.crypto.provider.AESCipher$AES192_CBC_NoPadding");
282                     put("Alg.Alias.Cipher.2.16.840.1.101.3.4.1.22", "AES_192/CBC/NoPadding");
283                     put("Alg.Alias.Cipher.OID.2.16.840.1.101.3.4.1.22", "AES_192/CBC/NoPadding");
284                     put("Cipher.AES_192/OFB/NoPadding", "com.sun.crypto.provider.AESCipher$AES192_OFB_NoPadding");
285                     put("Alg.Alias.Cipher.2.16.840.1.101.3.4.1.23", "AES_192/OFB/NoPadding");
286                     put("Alg.Alias.Cipher.OID.2.16.840.1.101.3.4.1.23", "AES_192/OFB/NoPadding");
287                     put("Cipher.AES_192/CFB/NoPadding", "com.sun.crypto.provider.AESCipher$AES192_CFB_NoPadding");
288                     put("Alg.Alias.Cipher.2.16.840.1.101.3.4.1.24", "AES_192/CFB/NoPadding");
289                     put("Alg.Alias.Cipher.OID.2.16.840.1.101.3.4.1.24", "AES_192/CFB/NoPadding");
290                     put("Cipher.AES_192/GCM/NoPadding", "com.sun.crypto.provider.AESCipher$AES192_GCM_NoPadding");
291                     put("Alg.Alias.Cipher.2.16.840.1.101.3.4.1.26", "AES_192/GCM/NoPadding");
292                     put("Alg.Alias.Cipher.OID.2.16.840.1.101.3.4.1.26", "AES_192/GCM/NoPadding");
293 
294                     put("Cipher.AES_256/ECB/NoPadding", "com.sun.crypto.provider.AESCipher$AES256_ECB_NoPadding");
295                     put("Alg.Alias.Cipher.2.16.840.1.101.3.4.1.41", "AES_256/ECB/NoPadding");
296                     put("Alg.Alias.Cipher.OID.2.16.840.1.101.3.4.1.41", "AES_256/ECB/NoPadding");
297                     put("Cipher.AES_256/CBC/NoPadding", "com.sun.crypto.provider.AESCipher$AES256_CBC_NoPadding");
298                     put("Alg.Alias.Cipher.2.16.840.1.101.3.4.1.42", "AES_256/CBC/NoPadding");
299                     put("Alg.Alias.Cipher.OID.2.16.840.1.101.3.4.1.42", "AES_256/CBC/NoPadding");
300                     put("Cipher.AES_256/OFB/NoPadding", "com.sun.crypto.provider.AESCipher$AES256_OFB_NoPadding");
301                     put("Alg.Alias.Cipher.2.16.840.1.101.3.4.1.43", "AES_256/OFB/NoPadding");
302                     put("Alg.Alias.Cipher.OID.2.16.840.1.101.3.4.1.43", "AES_256/OFB/NoPadding");
303                     put("Cipher.AES_256/CFB/NoPadding", "com.sun.crypto.provider.AESCipher$AES256_CFB_NoPadding");
304                     put("Alg.Alias.Cipher.2.16.840.1.101.3.4.1.44", "AES_256/CFB/NoPadding");
305                     put("Alg.Alias.Cipher.OID.2.16.840.1.101.3.4.1.44", "AES_256/CFB/NoPadding");
306                     put("Cipher.AES_256/GCM/NoPadding", "com.sun.crypto.provider.AESCipher$AES256_GCM_NoPadding");
307                     put("Alg.Alias.Cipher.2.16.840.1.101.3.4.1.46", "AES_256/GCM/NoPadding");
308                     put("Alg.Alias.Cipher.OID.2.16.840.1.101.3.4.1.46", "AES_256/GCM/NoPadding");
309 
310                     put("Cipher.AESWrap", "com.sun.crypto.provider.AESWrapCipher$General");
311                     put("Cipher.AESWrap SupportedModes", "ECB");
312                     put("Cipher.AESWrap SupportedPaddings", "NOPADDING");
313                     put("Cipher.AESWrap SupportedKeyFormats", "RAW");
314 
315                     put("Cipher.AESWrap_128", "com.sun.crypto.provider.AESWrapCipher$AES128");
316                     put("Alg.Alias.Cipher.2.16.840.1.101.3.4.1.5", "AESWrap_128");
317                     put("Alg.Alias.Cipher.OID.2.16.840.1.101.3.4.1.5", "AESWrap_128");
318                     put("Cipher.AESWrap_192", "com.sun.crypto.provider.AESWrapCipher$AES192");
319                     put("Alg.Alias.Cipher.2.16.840.1.101.3.4.1.25", "AESWrap_192");
320                     put("Alg.Alias.Cipher.OID.2.16.840.1.101.3.4.1.25", "AESWrap_192");
321                     put("Cipher.AESWrap_256", "com.sun.crypto.provider.AESWrapCipher$AES256");
322                     put("Alg.Alias.Cipher.2.16.840.1.101.3.4.1.45", "AESWrap_256");
323                     put("Alg.Alias.Cipher.OID.2.16.840.1.101.3.4.1.45", "AESWrap_256");
324 
325                     put("Cipher.RC2",
326                         "com.sun.crypto.provider.RC2Cipher");
327                     put("Cipher.RC2 SupportedModes", BLOCK_MODES);
328                     put("Cipher.RC2 SupportedPaddings", BLOCK_PADS);
329                     put("Cipher.RC2 SupportedKeyFormats", "RAW");
330 
331                     put("Cipher.ARCFOUR",
332                         "com.sun.crypto.provider.ARCFOURCipher");
333                     put("Alg.Alias.Cipher.RC4", "ARCFOUR");
334                     put("Cipher.ARCFOUR SupportedModes", "ECB");
335                     put("Cipher.ARCFOUR SupportedPaddings", "NOPADDING");
336                     put("Cipher.ARCFOUR SupportedKeyFormats", "RAW");
337 
338                     /*
339                      * Key(pair) Generator engines
340                      */
341                     put("KeyGenerator.DES",
342                         "com.sun.crypto.provider.DESKeyGenerator");
343 
344                     put("KeyGenerator.DESede",
345                         "com.sun.crypto.provider.DESedeKeyGenerator");
346                     put("Alg.Alias.KeyGenerator.TripleDES", "DESede");
347 
348                     put("KeyGenerator.Blowfish",
349                         "com.sun.crypto.provider.BlowfishKeyGenerator");
350 
351                     put("KeyGenerator.AES",
352                         "com.sun.crypto.provider.AESKeyGenerator");
353                     put("Alg.Alias.KeyGenerator.Rijndael", "AES");
354 
355                     put("KeyGenerator.RC2",
356                         "com.sun.crypto.provider.KeyGeneratorCore$" +
357                         "RC2KeyGenerator");
358                     put("KeyGenerator.ARCFOUR",
359                         "com.sun.crypto.provider.KeyGeneratorCore$" +
360                         "ARCFOURKeyGenerator");
361                     put("Alg.Alias.KeyGenerator.RC4", "ARCFOUR");
362 
363                     put("KeyGenerator.HmacMD5",
364                         "com.sun.crypto.provider.HmacMD5KeyGenerator");
365 
366                     put("KeyGenerator.HmacSHA1",
367                         "com.sun.crypto.provider.HmacSHA1KeyGenerator");
368                     put("Alg.Alias.KeyGenerator.OID.1.2.840.113549.2.7", "HmacSHA1");
369                     put("Alg.Alias.KeyGenerator.1.2.840.113549.2.7", "HmacSHA1");
370 
371                     put("KeyGenerator.HmacSHA224",
372                         "com.sun.crypto.provider.KeyGeneratorCore$HmacSHA2KG$SHA224");
373                     put("Alg.Alias.KeyGenerator.OID.1.2.840.113549.2.8", "HmacSHA224");
374                     put("Alg.Alias.KeyGenerator.1.2.840.113549.2.8", "HmacSHA224");
375 
376                     put("KeyGenerator.HmacSHA256",
377                         "com.sun.crypto.provider.KeyGeneratorCore$HmacSHA2KG$SHA256");
378                     put("Alg.Alias.KeyGenerator.OID.1.2.840.113549.2.9", "HmacSHA256");
379                     put("Alg.Alias.KeyGenerator.1.2.840.113549.2.9", "HmacSHA256");
380 
381                     put("KeyGenerator.HmacSHA384",
382                         "com.sun.crypto.provider.KeyGeneratorCore$HmacSHA2KG$SHA384");
383                     put("Alg.Alias.KeyGenerator.OID.1.2.840.113549.2.10", "HmacSHA384");
384                     put("Alg.Alias.KeyGenerator.1.2.840.113549.2.10", "HmacSHA384");
385 
386                     put("KeyGenerator.HmacSHA512",
387                         "com.sun.crypto.provider.KeyGeneratorCore$HmacSHA2KG$SHA512");
388                     put("Alg.Alias.KeyGenerator.OID.1.2.840.113549.2.11", "HmacSHA512");
389                     put("Alg.Alias.KeyGenerator.1.2.840.113549.2.11", "HmacSHA512");
390 
391                     put("KeyPairGenerator.DiffieHellman",
392                         "com.sun.crypto.provider.DHKeyPairGenerator");
393                     put("Alg.Alias.KeyPairGenerator.DH", "DiffieHellman");
394                     put("Alg.Alias.KeyPairGenerator.OID."+OID_PKCS3,
395                         "DiffieHellman");
396                     put("Alg.Alias.KeyPairGenerator."+OID_PKCS3,
397                         "DiffieHellman");
398 
399                     /*
400                      * Algorithm parameter generation engines
401                      */
402                     put("AlgorithmParameterGenerator.DiffieHellman",
403                         "com.sun.crypto.provider.DHParameterGenerator");
404                     put("Alg.Alias.AlgorithmParameterGenerator.DH",
405                         "DiffieHellman");
406                     put("Alg.Alias.AlgorithmParameterGenerator.OID."+OID_PKCS3,
407                         "DiffieHellman");
408                     put("Alg.Alias.AlgorithmParameterGenerator."+OID_PKCS3,
409                         "DiffieHellman");
410 
411                     /*
412                      * Key Agreement engines
413                      */
414                     put("KeyAgreement.DiffieHellman",
415                         "com.sun.crypto.provider.DHKeyAgreement");
416                     put("Alg.Alias.KeyAgreement.DH", "DiffieHellman");
417                     put("Alg.Alias.KeyAgreement.OID."+OID_PKCS3, "DiffieHellman");
418                     put("Alg.Alias.KeyAgreement."+OID_PKCS3, "DiffieHellman");
419 
420                     put("KeyAgreement.DiffieHellman SupportedKeyClasses",
421                         "javax.crypto.interfaces.DHPublicKey" +
422                         "|javax.crypto.interfaces.DHPrivateKey");
423 
424                     /*
425                      * Algorithm Parameter engines
426                      */
427                     put("AlgorithmParameters.DiffieHellman",
428                         "com.sun.crypto.provider.DHParameters");
429                     put("Alg.Alias.AlgorithmParameters.DH", "DiffieHellman");
430                     put("Alg.Alias.AlgorithmParameters.OID."+OID_PKCS3,
431                         "DiffieHellman");
432                     put("Alg.Alias.AlgorithmParameters."+OID_PKCS3,
433                         "DiffieHellman");
434 
435                     put("AlgorithmParameters.DES",
436                         "com.sun.crypto.provider.DESParameters");
437 
438                     put("AlgorithmParameters.DESede",
439                         "com.sun.crypto.provider.DESedeParameters");
440                     put("Alg.Alias.AlgorithmParameters.TripleDES", "DESede");
441 
442                     put("AlgorithmParameters.PBE",
443                         "com.sun.crypto.provider.PBEParameters");
444 
445                     put("AlgorithmParameters.PBEWithMD5AndDES",
446                         "com.sun.crypto.provider.PBEParameters");
447                     put("Alg.Alias.AlgorithmParameters.OID."+OID_PKCS5_MD5_DES,
448                         "PBEWithMD5AndDES");
449                     put("Alg.Alias.AlgorithmParameters."+OID_PKCS5_MD5_DES,
450                         "PBEWithMD5AndDES");
451 
452                     put("AlgorithmParameters.PBEWithMD5AndTripleDES",
453                         "com.sun.crypto.provider.PBEParameters");
454 
455                     put("AlgorithmParameters.PBEWithSHA1AndDESede",
456                         "com.sun.crypto.provider.PBEParameters");
457                     put("Alg.Alias.AlgorithmParameters.OID."+OID_PKCS12_DESede,
458                         "PBEWithSHA1AndDESede");
459                     put("Alg.Alias.AlgorithmParameters."+OID_PKCS12_DESede,
460                         "PBEWithSHA1AndDESede");
461 
462                     put("AlgorithmParameters.PBEWithSHA1AndRC2_40",
463                         "com.sun.crypto.provider.PBEParameters");
464                     put("Alg.Alias.AlgorithmParameters.OID."+OID_PKCS12_RC2_40,
465                         "PBEWithSHA1AndRC2_40");
466                     put("Alg.Alias.AlgorithmParameters." + OID_PKCS12_RC2_40,
467                         "PBEWithSHA1AndRC2_40");
468 
469                     put("AlgorithmParameters.PBEWithSHA1AndRC2_128",
470                         "com.sun.crypto.provider.PBEParameters");
471                     put("Alg.Alias.AlgorithmParameters.OID."+OID_PKCS12_RC2_128,
472                         "PBEWithSHA1AndRC2_128");
473                     put("Alg.Alias.AlgorithmParameters." + OID_PKCS12_RC2_128,
474                         "PBEWithSHA1AndRC2_128");
475 
476                     put("AlgorithmParameters.PBEWithSHA1AndRC4_40",
477                         "com.sun.crypto.provider.PBEParameters");
478                     put("Alg.Alias.AlgorithmParameters.OID."+OID_PKCS12_RC4_40,
479                         "PBEWithSHA1AndRC4_40");
480                     put("Alg.Alias.AlgorithmParameters." + OID_PKCS12_RC4_40,
481                         "PBEWithSHA1AndRC4_40");
482 
483                     put("AlgorithmParameters.PBEWithSHA1AndRC4_128",
484                         "com.sun.crypto.provider.PBEParameters");
485                     put("Alg.Alias.AlgorithmParameters.OID."+OID_PKCS12_RC4_128,
486                         "PBEWithSHA1AndRC4_128");
487                     put("Alg.Alias.AlgorithmParameters." + OID_PKCS12_RC4_128,
488                         "PBEWithSHA1AndRC4_128");
489 
490                     put("AlgorithmParameters.PBES2",
491                         "com.sun.crypto.provider.PBES2Parameters$General");
492                     put("Alg.Alias.AlgorithmParameters.OID."+OID_PKCS5_PBES2,
493                         "PBES2");
494                     put("Alg.Alias.AlgorithmParameters." + OID_PKCS5_PBES2,
495                         "PBES2");
496 
497                     put("AlgorithmParameters.PBEWithHmacSHA1AndAES_128",
498                         "com.sun.crypto.provider.PBES2Parameters$HmacSHA1AndAES_128");
499 
500                     put("AlgorithmParameters.PBEWithHmacSHA224AndAES_128",
501                         "com.sun.crypto.provider.PBES2Parameters$HmacSHA224AndAES_128");
502 
503                     put("AlgorithmParameters.PBEWithHmacSHA256AndAES_128",
504                         "com.sun.crypto.provider.PBES2Parameters$HmacSHA256AndAES_128");
505 
506                     put("AlgorithmParameters.PBEWithHmacSHA384AndAES_128",
507                         "com.sun.crypto.provider.PBES2Parameters$HmacSHA384AndAES_128");
508 
509                     put("AlgorithmParameters.PBEWithHmacSHA512AndAES_128",
510                         "com.sun.crypto.provider.PBES2Parameters$HmacSHA512AndAES_128");
511 
512                     put("AlgorithmParameters.PBEWithHmacSHA1AndAES_256",
513                         "com.sun.crypto.provider.PBES2Parameters$HmacSHA1AndAES_256");
514 
515                     put("AlgorithmParameters.PBEWithHmacSHA224AndAES_256",
516                         "com.sun.crypto.provider.PBES2Parameters$HmacSHA224AndAES_256");
517 
518                     put("AlgorithmParameters.PBEWithHmacSHA256AndAES_256",
519                         "com.sun.crypto.provider.PBES2Parameters$HmacSHA256AndAES_256");
520 
521                     put("AlgorithmParameters.PBEWithHmacSHA384AndAES_256",
522                         "com.sun.crypto.provider.PBES2Parameters$HmacSHA384AndAES_256");
523 
524                     put("AlgorithmParameters.PBEWithHmacSHA512AndAES_256",
525                         "com.sun.crypto.provider.PBES2Parameters$HmacSHA512AndAES_256");
526 
527                     put("AlgorithmParameters.Blowfish",
528                         "com.sun.crypto.provider.BlowfishParameters");
529 
530                     put("AlgorithmParameters.AES",
531                         "com.sun.crypto.provider.AESParameters");
532                     put("Alg.Alias.AlgorithmParameters.Rijndael", "AES");
533                     put("AlgorithmParameters.GCM",
534                         "com.sun.crypto.provider.GCMParameters");
535 
536 
537                     put("AlgorithmParameters.RC2",
538                         "com.sun.crypto.provider.RC2Parameters");
539 
540                     put("AlgorithmParameters.OAEP",
541                         "com.sun.crypto.provider.OAEPParameters");
542 
543                     /*
544                      * Key factories
545                      */
546                     put("KeyFactory.DiffieHellman",
547                         "com.sun.crypto.provider.DHKeyFactory");
548                     put("Alg.Alias.KeyFactory.DH", "DiffieHellman");
549                     put("Alg.Alias.KeyFactory.OID."+OID_PKCS3,
550                         "DiffieHellman");
551                     put("Alg.Alias.KeyFactory."+OID_PKCS3, "DiffieHellman");
552 
553                     /*
554                      * Secret-key factories
555                      */
556                     put("SecretKeyFactory.DES",
557                         "com.sun.crypto.provider.DESKeyFactory");
558 
559                     put("SecretKeyFactory.DESede",
560                         "com.sun.crypto.provider.DESedeKeyFactory");
561                     put("Alg.Alias.SecretKeyFactory.TripleDES", "DESede");
562 
563                     put("SecretKeyFactory.PBEWithMD5AndDES",
564                         "com.sun.crypto.provider.PBEKeyFactory$PBEWithMD5AndDES"
565                         );
566                     put("Alg.Alias.SecretKeyFactory.OID."+OID_PKCS5_MD5_DES,
567                         "PBEWithMD5AndDES");
568                     put("Alg.Alias.SecretKeyFactory."+OID_PKCS5_MD5_DES,
569                         "PBEWithMD5AndDES");
570 
571                     put("Alg.Alias.SecretKeyFactory.PBE",
572                         "PBEWithMD5AndDES");
573 
574                     /*
575                      * Internal in-house crypto algorithm used for
576                      * the JCEKS keystore type.  Since this was developed
577                      * internally, there isn't an OID corresponding to this
578                      * algorithm.
579                      */
580                     put("SecretKeyFactory.PBEWithMD5AndTripleDES",
581                         "com.sun.crypto.provider.PBEKeyFactory$" +
582                         "PBEWithMD5AndTripleDES"
583                         );
584 
585                     put("SecretKeyFactory.PBEWithSHA1AndDESede",
586                         "com.sun.crypto.provider.PBEKeyFactory$PBEWithSHA1AndDESede"
587                         );
588                     put("Alg.Alias.SecretKeyFactory.OID."+OID_PKCS12_DESede,
589                         "PBEWithSHA1AndDESede");
590                     put("Alg.Alias.SecretKeyFactory." + OID_PKCS12_DESede,
591                         "PBEWithSHA1AndDESede");
592 
593                     put("SecretKeyFactory.PBEWithSHA1AndRC2_40",
594                         "com.sun.crypto.provider.PBEKeyFactory$PBEWithSHA1AndRC2_40"
595                         );
596                     put("Alg.Alias.SecretKeyFactory.OID." + OID_PKCS12_RC2_40,
597                         "PBEWithSHA1AndRC2_40");
598                     put("Alg.Alias.SecretKeyFactory." + OID_PKCS12_RC2_40,
599                         "PBEWithSHA1AndRC2_40");
600 
601                     put("SecretKeyFactory.PBEWithSHA1AndRC2_128",
602                         "com.sun.crypto.provider.PBEKeyFactory$PBEWithSHA1AndRC2_128"
603                         );
604                     put("Alg.Alias.SecretKeyFactory.OID." + OID_PKCS12_RC2_128,
605                         "PBEWithSHA1AndRC2_128");
606                     put("Alg.Alias.SecretKeyFactory." + OID_PKCS12_RC2_128,
607                         "PBEWithSHA1AndRC2_128");
608 
609                     put("SecretKeyFactory.PBEWithSHA1AndRC4_40",
610                         "com.sun.crypto.provider.PBEKeyFactory$PBEWithSHA1AndRC4_40"
611                         );
612 
613                     put("Alg.Alias.SecretKeyFactory.OID." + OID_PKCS12_RC4_40,
614                         "PBEWithSHA1AndRC4_40");
615                     put("Alg.Alias.SecretKeyFactory." + OID_PKCS12_RC4_40,
616                         "PBEWithSHA1AndRC4_40");
617 
618                     put("SecretKeyFactory.PBEWithSHA1AndRC4_128",
619                         "com.sun.crypto.provider.PBEKeyFactory$PBEWithSHA1AndRC4_128"
620                         );
621 
622                     put("Alg.Alias.SecretKeyFactory.OID." + OID_PKCS12_RC4_128,
623                         "PBEWithSHA1AndRC4_128");
624                     put("Alg.Alias.SecretKeyFactory." + OID_PKCS12_RC4_128,
625                         "PBEWithSHA1AndRC4_128");
626 
627                     put("SecretKeyFactory.PBEWithHmacSHA1AndAES_128",
628                         "com.sun.crypto.provider.PBEKeyFactory$" +
629                         "PBEWithHmacSHA1AndAES_128");
630 
631                     put("SecretKeyFactory.PBEWithHmacSHA224AndAES_128",
632                         "com.sun.crypto.provider.PBEKeyFactory$" +
633                         "PBEWithHmacSHA224AndAES_128");
634 
635                     put("SecretKeyFactory.PBEWithHmacSHA256AndAES_128",
636                         "com.sun.crypto.provider.PBEKeyFactory$" +
637                         "PBEWithHmacSHA256AndAES_128");
638 
639                     put("SecretKeyFactory.PBEWithHmacSHA384AndAES_128",
640                         "com.sun.crypto.provider.PBEKeyFactory$" +
641                         "PBEWithHmacSHA384AndAES_128");
642 
643                     put("SecretKeyFactory.PBEWithHmacSHA512AndAES_128",
644                         "com.sun.crypto.provider.PBEKeyFactory$" +
645                         "PBEWithHmacSHA512AndAES_128");
646 
647                     put("SecretKeyFactory.PBEWithHmacSHA1AndAES_256",
648                         "com.sun.crypto.provider.PBEKeyFactory$" +
649                         "PBEWithHmacSHA1AndAES_256");
650 
651                     put("SecretKeyFactory.PBEWithHmacSHA224AndAES_256",
652                         "com.sun.crypto.provider.PBEKeyFactory$" +
653                         "PBEWithHmacSHA224AndAES_256");
654 
655                     put("SecretKeyFactory.PBEWithHmacSHA256AndAES_256",
656                         "com.sun.crypto.provider.PBEKeyFactory$" +
657                         "PBEWithHmacSHA256AndAES_256");
658 
659                     put("SecretKeyFactory.PBEWithHmacSHA384AndAES_256",
660                         "com.sun.crypto.provider.PBEKeyFactory$" +
661                         "PBEWithHmacSHA384AndAES_256");
662 
663                     put("SecretKeyFactory.PBEWithHmacSHA512AndAES_256",
664                         "com.sun.crypto.provider.PBEKeyFactory$" +
665                         "PBEWithHmacSHA512AndAES_256");
666 
667                     // PBKDF2
668 
669                     put("SecretKeyFactory.PBKDF2WithHmacSHA1",
670                         "com.sun.crypto.provider.PBKDF2Core$HmacSHA1");
671                     put("Alg.Alias.SecretKeyFactory.OID." + OID_PKCS5_PBKDF2,
672                         "PBKDF2WithHmacSHA1");
673                     put("Alg.Alias.SecretKeyFactory." + OID_PKCS5_PBKDF2,
674                         "PBKDF2WithHmacSHA1");
675 
676                     put("SecretKeyFactory.PBKDF2WithHmacSHA224",
677                         "com.sun.crypto.provider.PBKDF2Core$HmacSHA224");
678                     put("SecretKeyFactory.PBKDF2WithHmacSHA256",
679                         "com.sun.crypto.provider.PBKDF2Core$HmacSHA256");
680                     put("SecretKeyFactory.PBKDF2WithHmacSHA384",
681                         "com.sun.crypto.provider.PBKDF2Core$HmacSHA384");
682                     put("SecretKeyFactory.PBKDF2WithHmacSHA512",
683                         "com.sun.crypto.provider.PBKDF2Core$HmacSHA512");
684 
685                     /*
686                      * MAC
687                      */
688                     put("Mac.HmacMD5", "com.sun.crypto.provider.HmacMD5");
689                     put("Mac.HmacSHA1", "com.sun.crypto.provider.HmacSHA1");
690                     put("Alg.Alias.Mac.OID.1.2.840.113549.2.7", "HmacSHA1");
691                     put("Alg.Alias.Mac.1.2.840.113549.2.7", "HmacSHA1");
692                     put("Mac.HmacSHA224",
693                         "com.sun.crypto.provider.HmacCore$HmacSHA224");
694                     put("Alg.Alias.Mac.OID.1.2.840.113549.2.8", "HmacSHA224");
695                     put("Alg.Alias.Mac.1.2.840.113549.2.8", "HmacSHA224");
696                     put("Mac.HmacSHA256",
697                         "com.sun.crypto.provider.HmacCore$HmacSHA256");
698                     put("Alg.Alias.Mac.OID.1.2.840.113549.2.9", "HmacSHA256");
699                     put("Alg.Alias.Mac.1.2.840.113549.2.9", "HmacSHA256");
700                     put("Mac.HmacSHA384",
701                         "com.sun.crypto.provider.HmacCore$HmacSHA384");
702                     put("Alg.Alias.Mac.OID.1.2.840.113549.2.10", "HmacSHA384");
703                     put("Alg.Alias.Mac.1.2.840.113549.2.10", "HmacSHA384");
704                     put("Mac.HmacSHA512",
705                         "com.sun.crypto.provider.HmacCore$HmacSHA512");
706                     put("Alg.Alias.Mac.OID.1.2.840.113549.2.11", "HmacSHA512");
707                     put("Alg.Alias.Mac.1.2.840.113549.2.11", "HmacSHA512");
708 
709                     put("Mac.HmacPBESHA1",
710                         "com.sun.crypto.provider.HmacPKCS12PBESHA1");
711 
712                     // PBMAC1
713 
714                     put("Mac.PBEWithHmacSHA1",
715                         "com.sun.crypto.provider.PBMAC1Core$HmacSHA1");
716                     put("Mac.PBEWithHmacSHA224",
717                         "com.sun.crypto.provider.PBMAC1Core$HmacSHA224");
718                     put("Mac.PBEWithHmacSHA256",
719                         "com.sun.crypto.provider.PBMAC1Core$HmacSHA256");
720                     put("Mac.PBEWithHmacSHA384",
721                         "com.sun.crypto.provider.PBMAC1Core$HmacSHA384");
722                     put("Mac.PBEWithHmacSHA512",
723                         "com.sun.crypto.provider.PBMAC1Core$HmacSHA512");
724 
725                     put("Mac.SslMacMD5",
726                         "com.sun.crypto.provider.SslMacCore$SslMacMD5");
727                     put("Mac.SslMacSHA1",
728                         "com.sun.crypto.provider.SslMacCore$SslMacSHA1");
729 
730                     put("Mac.HmacMD5 SupportedKeyFormats", "RAW");
731                     put("Mac.HmacSHA1 SupportedKeyFormats", "RAW");
732                     put("Mac.HmacSHA224 SupportedKeyFormats", "RAW");
733                     put("Mac.HmacSHA256 SupportedKeyFormats", "RAW");
734                     put("Mac.HmacSHA384 SupportedKeyFormats", "RAW");
735                     put("Mac.HmacSHA512 SupportedKeyFormats", "RAW");
736                     put("Mac.HmacPBESHA1 SupportedKeyFormats", "RAW");
737                     put("Mac.PBEWithHmacSHA1 SupportedKeyFormatS", "RAW");
738                     put("Mac.PBEWithHmacSHA224 SupportedKeyFormats", "RAW");
739                     put("Mac.PBEWithHmacSHA256 SupportedKeyFormats", "RAW");
740                     put("Mac.PBEWithHmacSHA384 SupportedKeyFormats", "RAW");
741                     put("Mac.PBEWithHmacSHA512 SupportedKeyFormats", "RAW");
742                     put("Mac.SslMacMD5 SupportedKeyFormats", "RAW");
743                     put("Mac.SslMacSHA1 SupportedKeyFormats", "RAW");
744 
745                     /*
746                      * KeyStore
747                      */
748                     put("KeyStore.JCEKS", "com.sun.crypto.provider.JceKeyStore");
749 
750                     /*
751                      * SSL/TLS mechanisms
752                      *
753                      * These are strictly internal implementations and may
754                      * be changed at any time.  These names were chosen
755                      * because PKCS11/SunPKCS11 does not yet have TLS1.2
756                      * mechanisms, and it will cause calls to come here.
757                      */
758                     put("KeyGenerator.SunTlsPrf",
759                             "com.sun.crypto.provider.TlsPrfGenerator$V10");
760                     put("KeyGenerator.SunTls12Prf",
761                             "com.sun.crypto.provider.TlsPrfGenerator$V12");
762 
763                     put("KeyGenerator.SunTlsMasterSecret",
764                         "com.sun.crypto.provider.TlsMasterSecretGenerator");
765                     put("Alg.Alias.KeyGenerator.SunTls12MasterSecret",
766                         "SunTlsMasterSecret");
767                     put("Alg.Alias.KeyGenerator.SunTlsExtendedMasterSecret",
768                         "SunTlsMasterSecret");
769 
770                     put("KeyGenerator.SunTlsKeyMaterial",
771                         "com.sun.crypto.provider.TlsKeyMaterialGenerator");
772                     put("Alg.Alias.KeyGenerator.SunTls12KeyMaterial",
773                         "SunTlsKeyMaterial");
774 
775                     put("KeyGenerator.SunTlsRsaPremasterSecret",
776                         "com.sun.crypto.provider.TlsRsaPremasterSecretGenerator");
777                     put("Alg.Alias.KeyGenerator.SunTls12RsaPremasterSecret",
778                         "SunTlsRsaPremasterSecret");
779 
780                     return null;
781                 }
782             });
783 
784         if (instance == null) {
785             instance = this;
786         }
787     }
788 
789     // Return the instance of this class or create one if needed.
getInstance()790     static SunJCE getInstance() {
791         if (instance == null) {
792             return new SunJCE();
793         }
794         return instance;
795     }
796 }
797