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