1 /** 2 * Copyright (c) 2014, 2015, 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.oracle.security.ucrypto; 27 28 import java.util.HashMap; 29 30 /** 31 * Enum for representing the ucrypto mechanisms. 32 * 33 * @since 1.9 34 */ 35 // Check /usr/include/libsoftcrypto.h for updates 36 public enum UcryptoMech { 37 38 CRYPTO_AES_ECB(1, new ServiceDesc[] 39 { sd("Cipher", "AES/ECB/NoPadding", "com.oracle.security.ucrypto.NativeCipher$AesEcbNoPadding"), 40 sd("Cipher", "AES/ECB/PKCS5Padding", "com.oracle.security.ucrypto.NativeCipherWithJavaPadding$AesEcbPKCS5", 41 "AES"), 42 sd("Cipher", "AES_128/ECB/NoPadding", "com.oracle.security.ucrypto.NativeCipher$Aes128EcbNoPadding", 43 "2.16.840.1.101.3.4.1.1", "OID.2.16.840.1.101.3.4.1.1"), 44 sd("Cipher", "AES_192/ECB/NoPadding", "com.oracle.security.ucrypto.NativeCipher$Aes192EcbNoPadding", 45 "2.16.840.1.101.3.4.1.21", "OID.2.16.840.1.101.3.4.1.21"), 46 sd("Cipher", "AES_256/ECB/NoPadding", "com.oracle.security.ucrypto.NativeCipher$Aes256EcbNoPadding", 47 "2.16.840.1.101.3.4.1.41", "OID.2.16.840.1.101.3.4.1.41") 48 }), 49 CRYPTO_AES_CBC(2, new ServiceDesc[] 50 { sd("Cipher", "AES/CBC/NoPadding", "com.oracle.security.ucrypto.NativeCipher$AesCbcNoPadding"), 51 sd("Cipher", "AES/CBC/PKCS5Padding", "com.oracle.security.ucrypto.NativeCipherWithJavaPadding$AesCbcPKCS5"), 52 sd("Cipher", "AES_128/CBC/NoPadding", "com.oracle.security.ucrypto.NativeCipher$Aes128CbcNoPadding", 53 "2.16.840.1.101.3.4.1.2", "OID.2.16.840.1.101.3.4.1.2"), 54 sd("Cipher", "AES_192/CBC/NoPadding", "com.oracle.security.ucrypto.NativeCipher$Aes192CbcNoPadding", 55 "2.16.840.1.101.3.4.1.22", "OID.2.16.840.1.101.3.4.1.22"), 56 sd("Cipher", "AES_256/CBC/NoPadding", "com.oracle.security.ucrypto.NativeCipher$Aes256CbcNoPadding", 57 "2.16.840.1.101.3.4.1.42", "OID.2.16.840.1.101.3.4.1.42") 58 }), 59 CRYPTO_AES_CBC_PAD(3, null), // No support from Solaris yet 60 CRYPTO_AES_CTR(4, new ServiceDesc[] 61 { sd("Cipher", "AES/CTR/NoPadding", "com.oracle.security.ucrypto.NativeCipher$AesCtrNoPadding") }), 62 CRYPTO_AES_CCM(5, null), // Cannot support due to lack of Java API which corresponds to CK_AES_CCM_PARAMS 63 CRYPTO_AES_GCM(6, new ServiceDesc[] 64 { sd("Cipher", "AES/GCM/NoPadding", "com.oracle.security.ucrypto.NativeGCMCipher$AesGcmNoPadding"), 65 sd("Cipher", "AES_128/GCM/NoPadding", "com.oracle.security.ucrypto.NativeGCMCipher$Aes128GcmNoPadding", 66 "2.16.840.1.101.3.4.1.6", "OID.2.16.840.1.101.3.4.1.6"), 67 sd("Cipher", "AES_192/GCM/NoPadding", "com.oracle.security.ucrypto.NativeGCMCipher$Aes192GcmNoPadding", 68 "2.16.840.1.101.3.4.1.26", "OID.2.16.840.1.101.3.4.1.26"), 69 sd("Cipher", "AES_256/GCM/NoPadding", "com.oracle.security.ucrypto.NativeGCMCipher$Aes256GcmNoPadding", 70 "2.16.840.1.101.3.4.1.46", "OID.2.16.840.1.101.3.4.1.46") 71 }), 72 CRYPTO_AES_GMAC(7, null), // No support from Solaris yet 73 CRYPTO_AES_CFB128(8, new ServiceDesc[] 74 { sd("Cipher", "AES/CFB128/NoPadding", "com.oracle.security.ucrypto.NativeCipher$AesCfb128NoPadding"), 75 sd("Cipher", "AES/CFB128/PKCS5Padding", "com.oracle.security.ucrypto.NativeCipherWithJavaPadding$AesCfb128PKCS5") }), 76 CRYPTO_RSA_PKCS(31, new ServiceDesc[] 77 { sd("Cipher", "RSA/ECB/PKCS1Padding", "com.oracle.security.ucrypto.NativeRSACipher$PKCS1Padding", 78 "RSA") }), 79 CRYPTO_RSA_X_509(32, new ServiceDesc[] 80 { sd("Cipher", "RSA/ECB/NoPadding", "com.oracle.security.ucrypto.NativeRSACipher$NoPadding") }), 81 CRYPTO_MD5_RSA_PKCS(33, new ServiceDesc[] 82 { sd("Signature", "MD5withRSA", "com.oracle.security.ucrypto.NativeRSASignature$MD5", 83 "1.2.840.113549.1.1.4", "OID.1.2.840.113549.1.1.4") }), 84 CRYPTO_SHA1_RSA_PKCS(34, new ServiceDesc[] 85 { sd("Signature", "SHA1withRSA", "com.oracle.security.ucrypto.NativeRSASignature$SHA1", 86 "1.2.840.113549.1.1.5", "OID.1.2.840.113549.1.1.5", 87 "1.3.14.3.2.29") }), 88 CRYPTO_SHA256_RSA_PKCS(35, new ServiceDesc[] 89 { sd("Signature", "SHA256withRSA", "com.oracle.security.ucrypto.NativeRSASignature$SHA256", 90 "1.2.840.113549.1.1.11", "OID.1.2.840.113549.1.1.11") }), 91 CRYPTO_SHA384_RSA_PKCS(36, new ServiceDesc[] 92 { sd("Signature", "SHA384withRSA", "com.oracle.security.ucrypto.NativeRSASignature$SHA384", 93 "1.2.840.113549.1.1.12", "OID.1.2.840.113549.1.1.12") }), 94 CRYPTO_SHA512_RSA_PKCS(37, new ServiceDesc[] 95 { sd("Signature", "SHA512withRSA", "com.oracle.security.ucrypto.NativeRSASignature$SHA512", 96 "1.2.840.113549.1.1.13", "OID.1.2.840.113549.1.1.13") }); 97 98 private final int mech; 99 private final ServiceDesc[] serviceDescs; 100 101 private static ServiceDesc sd(String type, String algo, String cn, String... aliases) { 102 return new ServiceDesc(type, algo, cn, aliases); 103 } 104 105 UcryptoMech(int mech, ServiceDesc[] serviceDescs) { 106 this.mech = mech; 107 this.serviceDescs = serviceDescs; 108 } 109 110 public int value() { return mech; } 111 public ServiceDesc[] getServiceDescriptions() { return serviceDescs; } 112 }