1 /* 2 * Copyright (c) 2009, 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 sun.security.ec; 27 28 import java.util.Collection; 29 import java.util.Map; 30 31 import java.util.regex.Pattern; 32 import sun.security.util.CurveDB; 33 import sun.security.util.NamedCurve; 34 35 /** 36 * Defines the entries of the SunEC provider. 37 * 38 * @since 1.7 39 */ 40 final class SunECEntries { 41 42 private SunECEntries() { 43 // empty 44 } 45 46 static void putEntries(Map<Object, Object> map, 47 boolean useFullImplementation) { 48 49 /* 50 * Key Factory engine 51 */ 52 map.put("KeyFactory.EC", "sun.security.ec.ECKeyFactory"); 53 map.put("Alg.Alias.KeyFactory.EllipticCurve", "EC"); 54 55 map.put("KeyFactory.EC ImplementedIn", "Software"); 56 57 /* 58 * Algorithm Parameter engine 59 */ 60 map.put("AlgorithmParameters.EC", "sun.security.util.ECParameters"); 61 map.put("Alg.Alias.AlgorithmParameters.EllipticCurve", "EC"); 62 map.put("Alg.Alias.AlgorithmParameters.1.2.840.10045.2.1", "EC"); 63 64 map.put("AlgorithmParameters.EC KeySize", "256"); 65 66 map.put("AlgorithmParameters.EC ImplementedIn", "Software"); 67 68 // "AlgorithmParameters.EC SupportedCurves" prop used by unit test 69 boolean firstCurve = true; 70 StringBuilder names = new StringBuilder(); 71 Pattern nameSplitPattern = Pattern.compile(CurveDB.SPLIT_PATTERN); 72 73 Collection<? extends NamedCurve> supportedCurves = 74 CurveDB.getSupportedCurves(); 75 for (NamedCurve namedCurve : supportedCurves) { 76 if (!firstCurve) { 77 names.append("|"); 78 } else { 79 firstCurve = false; 80 } 81 82 names.append("["); 83 84 String[] commonNames = nameSplitPattern.split(namedCurve.getName()); 85 for (String commonName : commonNames) { 86 names.append(commonName.trim()); 87 names.append(","); 88 } 89 90 names.append(namedCurve.getObjectId()); 91 names.append("]"); 92 } 93 94 map.put("AlgorithmParameters.EC SupportedCurves", names.toString()); 95 96 /* 97 * Register the algorithms below only when the full ECC implementation 98 * is available 99 */ 100 if (!useFullImplementation) { 101 return; 102 } 103 104 /* 105 * Signature engines 106 */ 107 map.put("Signature.NONEwithECDSA", 108 "sun.security.ec.ECDSASignature$Raw"); 109 map.put("Signature.SHA1withECDSA", 110 "sun.security.ec.ECDSASignature$SHA1"); 111 map.put("Alg.Alias.Signature.OID.1.2.840.10045.4.1", "SHA1withECDSA"); 112 map.put("Alg.Alias.Signature.1.2.840.10045.4.1", "SHA1withECDSA"); 113 114 map.put("Signature.SHA224withECDSA", 115 "sun.security.ec.ECDSASignature$SHA224"); 116 map.put("Alg.Alias.Signature.OID.1.2.840.10045.4.3.1", "SHA224withECDSA"); 117 map.put("Alg.Alias.Signature.1.2.840.10045.4.3.1", "SHA224withECDSA"); 118 119 map.put("Signature.SHA256withECDSA", 120 "sun.security.ec.ECDSASignature$SHA256"); 121 map.put("Alg.Alias.Signature.OID.1.2.840.10045.4.3.2", "SHA256withECDSA"); 122 map.put("Alg.Alias.Signature.1.2.840.10045.4.3.2", "SHA256withECDSA"); 123 124 map.put("Signature.SHA384withECDSA", 125 "sun.security.ec.ECDSASignature$SHA384"); 126 map.put("Alg.Alias.Signature.OID.1.2.840.10045.4.3.3", "SHA384withECDSA"); 127 map.put("Alg.Alias.Signature.1.2.840.10045.4.3.3", "SHA384withECDSA"); 128 129 map.put("Signature.SHA512withECDSA", 130 "sun.security.ec.ECDSASignature$SHA512"); 131 map.put("Alg.Alias.Signature.OID.1.2.840.10045.4.3.4", "SHA512withECDSA"); 132 map.put("Alg.Alias.Signature.1.2.840.10045.4.3.4", "SHA512withECDSA"); 133 134 map.put("Signature.NONEwithECDSAinP1363Format", 135 "sun.security.ec.ECDSASignature$RawinP1363Format"); 136 map.put("Signature.SHA1withECDSAinP1363Format", 137 "sun.security.ec.ECDSASignature$SHA1inP1363Format"); 138 map.put("Signature.SHA224withECDSAinP1363Format", 139 "sun.security.ec.ECDSASignature$SHA224inP1363Format"); 140 map.put("Signature.SHA256withECDSAinP1363Format", 141 "sun.security.ec.ECDSASignature$SHA256inP1363Format"); 142 map.put("Signature.SHA384withECDSAinP1363Format", 143 "sun.security.ec.ECDSASignature$SHA384inP1363Format"); 144 map.put("Signature.SHA512withECDSAinP1363Format", 145 "sun.security.ec.ECDSASignature$SHA512inP1363Format"); 146 147 String ecKeyClasses = "java.security.interfaces.ECPublicKey" + 148 "|java.security.interfaces.ECPrivateKey"; 149 map.put("Signature.NONEwithECDSA SupportedKeyClasses", ecKeyClasses); 150 map.put("Signature.SHA1withECDSA SupportedKeyClasses", ecKeyClasses); 151 map.put("Signature.SHA224withECDSA SupportedKeyClasses", ecKeyClasses); 152 map.put("Signature.SHA256withECDSA SupportedKeyClasses", ecKeyClasses); 153 map.put("Signature.SHA384withECDSA SupportedKeyClasses", ecKeyClasses); 154 map.put("Signature.SHA512withECDSA SupportedKeyClasses", ecKeyClasses); 155 156 map.put("Signature.SHA1withECDSA KeySize", "256"); 157 158 map.put("Signature.NONEwithECDSA ImplementedIn", "Software"); 159 map.put("Signature.SHA1withECDSA ImplementedIn", "Software"); 160 map.put("Signature.SHA224withECDSA ImplementedIn", "Software"); 161 map.put("Signature.SHA256withECDSA ImplementedIn", "Software"); 162 map.put("Signature.SHA384withECDSA ImplementedIn", "Software"); 163 map.put("Signature.SHA512withECDSA ImplementedIn", "Software"); 164 165 /* 166 * Key Pair Generator engine 167 */ 168 map.put("KeyPairGenerator.EC", "sun.security.ec.ECKeyPairGenerator"); 169 map.put("Alg.Alias.KeyPairGenerator.EllipticCurve", "EC"); 170 171 map.put("KeyPairGenerator.EC KeySize", "256"); 172 173 map.put("KeyPairGenerator.EC ImplementedIn", "Software"); 174 175 /* 176 * Key Agreement engine 177 */ 178 map.put("KeyAgreement.ECDH", "sun.security.ec.ECDHKeyAgreement"); 179 180 map.put("KeyAgreement.ECDH SupportedKeyClasses", ecKeyClasses); 181 182 map.put("KeyAgreement.ECDH ImplementedIn", "Software"); 183 } 184 }