src/jdk.crypto.ucrypto/solaris/classes/com/oracle/security/ucrypto/UcryptoMech.java

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




 115         this.mech = mech;
 116         this.jceProps = jceProps;
 117     }
 118 
 119     public int value() { return mech; }
 120     public String[] jceProperties() { return jceProps; }
 121 }
   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 }