equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2006, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
60 public static Collection<? extends NamedCurve>getSupportedCurves() { |
60 public static Collection<? extends NamedCurve>getSupportedCurves() { |
61 return specCollection; |
61 return specCollection; |
62 } |
62 } |
63 |
63 |
64 // Return a NamedCurve for the specified OID/name or null if unknown. |
64 // Return a NamedCurve for the specified OID/name or null if unknown. |
65 static NamedCurve lookup(String name) { |
65 public static NamedCurve lookup(String name) { |
66 NamedCurve spec = oidMap.get(name); |
66 NamedCurve spec = oidMap.get(name); |
67 if (spec != null) { |
67 if (spec != null) { |
68 return spec; |
68 return spec; |
69 } |
69 } |
70 |
70 |
71 return nameMap.get(name); |
71 return nameMap.get(name.toLowerCase(Locale.ENGLISH)); |
72 } |
72 } |
73 |
73 |
74 // Return EC parameters for the specified field size. If there are known |
74 // Return EC parameters for the specified field size. If there are known |
75 // NIST recommended parameters for the given length, they are returned. |
75 // NIST recommended parameters for the given length, they are returned. |
76 // Otherwise, if there are multiple matches for the given size, an |
76 // Otherwise, if there are multiple matches for the given size, an |
81 return lengthMap.get(length); |
81 return lengthMap.get(length); |
82 } |
82 } |
83 |
83 |
84 // Convert the given ECParameterSpec object to a NamedCurve object. |
84 // Convert the given ECParameterSpec object to a NamedCurve object. |
85 // If params does not represent a known named curve, return null. |
85 // If params does not represent a known named curve, return null. |
86 static NamedCurve lookup(ECParameterSpec params) { |
86 public static NamedCurve lookup(ECParameterSpec params) { |
87 if ((params instanceof NamedCurve) || (params == null)) { |
87 if ((params instanceof NamedCurve) || (params == null)) { |
88 return (NamedCurve)params; |
88 return (NamedCurve)params; |
89 } |
89 } |
90 |
90 |
91 // This is a hack to allow SunJSSE to work with 3rd party crypto |
91 // This is a hack to allow SunJSSE to work with 3rd party crypto |
102 // components ourselves. |
102 // components ourselves. |
103 // Quick field size check first |
103 // Quick field size check first |
104 if (namedCurve.getCurve().getField().getFieldSize() != fieldSize) { |
104 if (namedCurve.getCurve().getField().getFieldSize() != fieldSize) { |
105 continue; |
105 continue; |
106 } |
106 } |
107 if (namedCurve.getCurve().equals(params.getCurve()) == false) { |
107 if (ECUtil.equals(namedCurve, params)) { |
108 continue; |
108 // everything matches our named curve, return it |
|
109 return namedCurve; |
109 } |
110 } |
110 if (namedCurve.getGenerator().equals(params.getGenerator()) == |
|
111 false) { |
|
112 continue; |
|
113 } |
|
114 if (namedCurve.getOrder().equals(params.getOrder()) == false) { |
|
115 continue; |
|
116 } |
|
117 if (namedCurve.getCofactor() != params.getCofactor()) { |
|
118 continue; |
|
119 } |
|
120 // everything matches our named curve, return it |
|
121 return namedCurve; |
|
122 } |
111 } |
123 // no match found |
112 // no match found |
124 return null; |
113 return null; |
125 } |
114 } |
126 |
115 |
149 throw new RuntimeException("Duplication oid: " + soid); |
138 throw new RuntimeException("Duplication oid: " + soid); |
150 } |
139 } |
151 |
140 |
152 String[] commonNames = nameSplitPattern.split(name); |
141 String[] commonNames = nameSplitPattern.split(name); |
153 for (String commonName : commonNames) { |
142 for (String commonName : commonNames) { |
154 if (nameMap.put(commonName.trim(), params) != null) { |
143 if (nameMap.put(commonName.trim().toLowerCase(Locale.ENGLISH), |
|
144 params) != null) { |
155 throw new RuntimeException("Duplication name: " + commonName); |
145 throw new RuntimeException("Duplication name: " + commonName); |
156 } |
146 } |
157 } |
147 } |
158 |
148 |
159 int len = field.getFieldSize(); |
149 int len = field.getFieldSize(); |