jdk/src/java.base/share/classes/sun/security/ssl/EllipticCurvesExtension.java
author xuelei
Tue, 11 Oct 2016 09:11:34 +0000
changeset 41473 bf73db8c61e0
parent 39563 1449ed425710
child 43693 e340c8d10cbb
permissions -rw-r--r--
8167472: Chrome interop regression with JDK-8148516 Reviewed-by: weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
     1
/*
37814
844e590a011a 8156502: Use short name of SupportedEllipticCurvesExtension.java
xuelei
parents: 32649
diff changeset
     2
 * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
     4
 *
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    10
 *
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    15
 * accompanied this code).
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    16
 *
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    20
 *
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    23
 * questions.
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    24
 */
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    25
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    26
package sun.security.ssl;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    27
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    28
import java.io.IOException;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    29
import java.security.spec.ECParameterSpec;
39563
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    30
import java.security.spec.ECGenParameterSpec;
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    31
import java.security.spec.InvalidParameterSpecException;
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    32
import java.security.AlgorithmParameters;
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    33
import java.security.AlgorithmConstraints;
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    34
import java.security.CryptoPrimitive;
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    35
import java.security.AccessController;
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    36
import java.util.EnumSet;
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    37
import java.util.HashMap;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    38
import java.util.Map;
39563
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    39
import java.util.ArrayList;
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    40
import javax.net.ssl.SSLProtocolException;
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    41
39563
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    42
import sun.security.action.GetPropertyAction;
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    43
37814
844e590a011a 8156502: Use short name of SupportedEllipticCurvesExtension.java
xuelei
parents: 32649
diff changeset
    44
final class EllipticCurvesExtension extends HelloExtension {
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    45
39563
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    46
    private static final int ARBITRARY_PRIME = 0xff01;
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    47
    private static final int ARBITRARY_CHAR2 = 0xff02;
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    48
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    49
    // speed up the searching
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    50
    private static final Map<String, Integer> oidToIdMap = new HashMap<>();
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    51
    private static final Map<Integer, String> idToOidMap = new HashMap<>();
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    52
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    53
    // speed up the parameters construction
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    54
    private static final Map<Integer,
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    55
                AlgorithmParameters> idToParams = new HashMap<>();
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    56
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    57
    // the supported elliptic curves
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    58
    private static final int[] supportedCurveIds;
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    59
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    60
    // the curves of the extension
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    61
    private final int[] curveIds;
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    62
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    63
    // See sun.security.util.CurveDB for the OIDs
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    64
    private static enum NamedEllipticCurve {
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    65
        T163_K1(1,  "sect163k1",    "1.3.132.0.1",      true),  // NIST K-163
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    66
        T163_R1(2,  "sect163r1",    "1.3.132.0.2",      false),
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    67
        T163_R2(3,  "sect163r2",    "1.3.132.0.15",     true),  // NIST B-163
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    68
        T193_R1(4,  "sect193r1",    "1.3.132.0.24",     false),
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    69
        T193_R2(5,  "sect193r2",    "1.3.132.0.25",     false),
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    70
        T233_K1(6,  "sect233k1",    "1.3.132.0.26",     true),  // NIST K-233
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    71
        T233_R1(7,  "sect233r1",    "1.3.132.0.27",     true),  // NIST B-233
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    72
        T239_K1(8,  "sect239k1",    "1.3.132.0.3",      false),
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    73
        T283_K1(9,  "sect283k1",    "1.3.132.0.16",     true),  // NIST K-283
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    74
        T283_R1(10, "sect283r1",    "1.3.132.0.17",     true),  // NIST B-283
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    75
        T409_K1(11, "sect409k1",    "1.3.132.0.36",     true),  // NIST K-409
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    76
        T409_R1(12, "sect409r1",    "1.3.132.0.37",     true),  // NIST B-409
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    77
        T571_K1(13, "sect571k1",    "1.3.132.0.38",     true),  // NIST K-571
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    78
        T571_R1(14, "sect571r1",    "1.3.132.0.39",     true),  // NIST B-571
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    79
39563
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    80
        P160_K1(15, "secp160k1",    "1.3.132.0.9",      false),
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    81
        P160_R1(16, "secp160r1",    "1.3.132.0.8",      false),
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    82
        P160_R2(17, "secp160r2",    "1.3.132.0.30",     false),
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    83
        P192_K1(18, "secp192k1",    "1.3.132.0.31",     false),
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    84
        P192_R1(19, "secp192r1",    "1.2.840.10045.3.1.1", true), // NIST P-192
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    85
        P224_K1(20, "secp224k1",    "1.3.132.0.32",     false),
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    86
        P224_R1(21, "secp224r1",    "1.3.132.0.33",     true),  // NIST P-224
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    87
        P256_K1(22, "secp256k1",    "1.3.132.0.10",     false),
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    88
        P256_R1(23, "secp256r1",    "1.2.840.10045.3.1.7", true), // NIST P-256
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    89
        P384_R1(24, "secp384r1",    "1.3.132.0.34",     true),  // NIST P-384
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    90
        P521_R1(25, "secp521r1",    "1.3.132.0.35",     true);  // NIST P-521
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    91
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    92
        int          id;
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    93
        String       name;
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    94
        String       oid;
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    95
        boolean      isFips;
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    96
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    97
        NamedEllipticCurve(int id, String name, String oid, boolean isFips) {
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    98
            this.id = id;
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
    99
            this.name = name;
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   100
            this.oid = oid;
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   101
            this.isFips = isFips;
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   102
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   103
            if (oidToIdMap.put(oid, id) != null ||
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   104
                idToOidMap.put(id, oid) != null) {
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   105
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   106
                throw new RuntimeException(
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   107
                        "Duplicate named elliptic curve definition: " + name);
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   108
            }
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   109
        }
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   110
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   111
        static NamedEllipticCurve getCurve(String name, boolean requireFips) {
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   112
            for (NamedEllipticCurve curve : NamedEllipticCurve.values()) {
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   113
                if (curve.name.equals(name) && (!requireFips || curve.isFips)) {
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   114
                    return curve;
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   115
                }
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   116
            }
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   117
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   118
            return null;
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   119
        }
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   120
    }
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   121
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   122
    static {
39563
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   123
        boolean requireFips = SunJSSE.isFIPS();
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   124
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   125
        // hack code to initialize NamedEllipticCurve
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   126
        NamedEllipticCurve nec =
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   127
                NamedEllipticCurve.getCurve("secp256r1", false);
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   128
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   129
        // The value of the System Property defines a list of enabled named
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   130
        // curves in preference order, separated with comma.  For example:
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   131
        //
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   132
        //      jdk.tls.namedGroups="secp521r1, secp256r1, secp384r1"
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   133
        //
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   134
        // If the System Property is not defined or the value is empty, the
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   135
        // default curves and preferences will be used.
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   136
        String property = AccessController.doPrivileged(
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   137
                    new GetPropertyAction("jdk.tls.namedGroups"));
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   138
        if (property != null && property.length() != 0) {
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   139
            // remove double quote marks from beginning/end of the property
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   140
            if (property.length() > 1 && property.charAt(0) == '"' &&
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   141
                    property.charAt(property.length() - 1) == '"') {
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   142
                property = property.substring(1, property.length() - 1);
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   143
            }
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   144
        }
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   145
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   146
        ArrayList<Integer> idList;
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   147
        if (property != null && property.length() != 0) {   // customized curves
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   148
            String[] curves = property.split(",");
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   149
            idList = new ArrayList<>(curves.length);
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   150
            for (String curve : curves) {
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   151
                curve = curve.trim();
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   152
                if (!curve.isEmpty()) {
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   153
                    NamedEllipticCurve namedCurve =
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   154
                            NamedEllipticCurve.getCurve(curve, requireFips);
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   155
                    if (namedCurve != null) {
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   156
                        if (isAvailableCurve(namedCurve.id)) {
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   157
                            idList.add(namedCurve.id);
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   158
                        }
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   159
                    }   // ignore unknown curves
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   160
                }
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   161
            }
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   162
        } else {        // default curves
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   163
            int[] ids;
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   164
            if (requireFips) {
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   165
                ids = new int[] {
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   166
                    // only NIST curves in FIPS mode
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   167
                    23, 24, 25, 9, 10, 11, 12, 13, 14,
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   168
                };
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   169
            } else {
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   170
                ids = new int[] {
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   171
                    // NIST curves first
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   172
                    23, 24, 25, 9, 10, 11, 12, 13, 14,
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   173
                    // non-NIST curves
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   174
                    22,
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   175
                };
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   176
            }
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   177
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   178
            idList = new ArrayList<>(ids.length);
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   179
            for (int curveId : ids) {
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   180
                if (isAvailableCurve(curveId)) {
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   181
                    idList.add(curveId);
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   182
                }
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   183
            }
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   184
        }
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   185
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   186
        if (idList.isEmpty()) {
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   187
            throw new IllegalArgumentException(
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   188
                "System property jdk.tls.namedGroups(" + property + ") " +
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   189
                "contains no supported elliptic curves");
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   190
        } else {
39563
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   191
            supportedCurveIds = new int[idList.size()];
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   192
            int i = 0;
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   193
            for (Integer id : idList) {
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   194
                supportedCurveIds[i++] = id;
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   195
            }
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   196
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   197
    }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   198
39563
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   199
    // check whether the curve is supported by the underlying providers
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   200
    private static boolean isAvailableCurve(int curveId) {
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   201
        String oid = idToOidMap.get(curveId);
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   202
        if (oid != null) {
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   203
            AlgorithmParameters params = null;
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   204
            try {
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   205
                params = JsseJce.getAlgorithmParameters("EC");
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   206
                params.init(new ECGenParameterSpec(oid));
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   207
            } catch (Exception e) {
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   208
                return false;
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   209
            }
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   210
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   211
            // cache the parameters
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   212
            idToParams.put(curveId, params);
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   213
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   214
            return true;
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   215
        }
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   216
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   217
        return false;
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   218
    }
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   219
37814
844e590a011a 8156502: Use short name of SupportedEllipticCurvesExtension.java
xuelei
parents: 32649
diff changeset
   220
    private EllipticCurvesExtension(int[] curveIds) {
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   221
        super(ExtensionType.EXT_ELLIPTIC_CURVES);
39563
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   222
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   223
        this.curveIds = curveIds;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   224
    }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   225
37814
844e590a011a 8156502: Use short name of SupportedEllipticCurvesExtension.java
xuelei
parents: 32649
diff changeset
   226
    EllipticCurvesExtension(HandshakeInStream s, int len)
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   227
            throws IOException {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   228
        super(ExtensionType.EXT_ELLIPTIC_CURVES);
39563
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   229
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   230
        int k = s.getInt16();
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   231
        if (((len & 1) != 0) || (k + 2 != len)) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   232
            throw new SSLProtocolException("Invalid " + type + " extension");
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   233
        }
39563
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   234
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   235
        // Note: unknown curves will be ignored later.
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   236
        curveIds = new int[k >> 1];
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   237
        for (int i = 0; i < curveIds.length; i++) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   238
            curveIds[i] = s.getInt16();
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   239
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   240
    }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   241
39563
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   242
    // get the preferred active curve
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   243
    static int getActiveCurves(AlgorithmConstraints constraints) {
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   244
        return getPreferredCurve(supportedCurveIds, constraints);
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   245
    }
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   246
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   247
    static boolean hasActiveCurves(AlgorithmConstraints constraints) {
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   248
        return getActiveCurves(constraints) >= 0;
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   249
    }
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   250
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   251
    static EllipticCurvesExtension createExtension(
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   252
                AlgorithmConstraints constraints) {
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   253
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   254
        ArrayList<Integer> idList = new ArrayList<>(supportedCurveIds.length);
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   255
        for (int curveId : supportedCurveIds) {
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   256
            if (constraints.permits(
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   257
                    EnumSet.of(CryptoPrimitive.KEY_AGREEMENT),
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   258
                                "EC", idToParams.get(curveId))) {
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   259
                idList.add(curveId);
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   260
            }
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   261
        }
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   262
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   263
        if (!idList.isEmpty()) {
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   264
            int[] ids = new int[idList.size()];
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   265
            int i = 0;
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   266
            for (Integer id : idList) {
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   267
                ids[i++] = id;
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   268
            }
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   269
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   270
            return new EllipticCurvesExtension(ids);
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   271
        }
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   272
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   273
        return null;
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   274
    }
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   275
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   276
    // get the preferred activated curve
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   277
    int getPreferredCurve(AlgorithmConstraints constraints) {
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   278
        return getPreferredCurve(curveIds, constraints);
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   279
    }
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   280
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   281
    // get a preferred activated curve
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   282
    private static int getPreferredCurve(int[] curves,
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   283
                AlgorithmConstraints constraints) {
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   284
        for (int curveId : curves) {
41473
bf73db8c61e0 8167472: Chrome interop regression with JDK-8148516
xuelei
parents: 39563
diff changeset
   285
            if (isSupported(curveId) && constraints.permits(
39563
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   286
                    EnumSet.of(CryptoPrimitive.KEY_AGREEMENT),
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   287
                                "EC", idToParams.get(curveId))) {
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   288
                return curveId;
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   289
            }
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   290
        }
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   291
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   292
        return -1;
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   293
    }
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   294
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   295
    boolean contains(int index) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   296
        for (int curveId : curveIds) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   297
            if (index == curveId) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   298
                return true;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   299
            }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   300
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   301
        return false;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   302
    }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   303
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14342
diff changeset
   304
    @Override
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   305
    int length() {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   306
        return 6 + (curveIds.length << 1);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   307
    }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   308
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14342
diff changeset
   309
    @Override
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   310
    void send(HandshakeOutStream s) throws IOException {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   311
        s.putInt16(type.id);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   312
        int k = curveIds.length << 1;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   313
        s.putInt16(k + 2);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   314
        s.putInt16(k);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   315
        for (int curveId : curveIds) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   316
            s.putInt16(curveId);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   317
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   318
    }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   319
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14342
diff changeset
   320
    @Override
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   321
    public String toString() {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   322
        StringBuilder sb = new StringBuilder();
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   323
        sb.append("Extension " + type + ", curve names: {");
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   324
        boolean first = true;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   325
        for (int curveId : curveIds) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   326
            if (first) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   327
                first = false;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   328
            } else {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   329
                sb.append(", ");
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   330
            }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   331
            // first check if it is a known named curve, then try other cases.
39563
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   332
            String curveName = getCurveName(curveId);
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   333
            if (curveName != null) {
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   334
                sb.append(curveName);
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   335
            } else if (curveId == ARBITRARY_PRIME) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   336
                sb.append("arbitrary_explicit_prime_curves");
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   337
            } else if (curveId == ARBITRARY_CHAR2) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   338
                sb.append("arbitrary_explicit_char2_curves");
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   339
            } else {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   340
                sb.append("unknown curve " + curveId);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   341
            }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   342
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   343
        sb.append("}");
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   344
        return sb.toString();
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   345
    }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   346
39563
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   347
    // Test whether the given curve is supported.
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   348
    static boolean isSupported(int index) {
39563
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   349
        for (int curveId : supportedCurveIds) {
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   350
            if (index == curveId) {
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   351
                return true;
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   352
            }
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   353
        }
39563
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   354
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   355
        return false;
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   356
    }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   357
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   358
    static int getCurveIndex(ECParameterSpec params) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   359
        String oid = JsseJce.getNamedCurveOid(params);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   360
        if (oid == null) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   361
            return -1;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   362
        }
39563
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   363
        Integer n = oidToIdMap.get(oid);
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   364
        return (n == null) ? -1 : n;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   365
    }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   366
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   367
    static String getCurveOid(int index) {
39563
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   368
        return idToOidMap.get(index);
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   369
    }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   370
39563
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   371
    static ECGenParameterSpec getECGenParamSpec(int index) {
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   372
        AlgorithmParameters params = idToParams.get(index);
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   373
        try {
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   374
            return params.getParameterSpec(ECGenParameterSpec.class);
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   375
        } catch (InvalidParameterSpecException ipse) {
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   376
            // should be unlikely
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   377
            String curveOid = getCurveOid(index);
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   378
            return new ECGenParameterSpec(curveOid);
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   379
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   380
    }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   381
39563
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   382
    private static String getCurveName(int index) {
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   383
        for (NamedEllipticCurve namedCurve : NamedEllipticCurve.values()) {
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   384
            if (namedCurve.id == index) {
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   385
                return namedCurve.name;
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   386
            }
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   387
        }
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   388
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   389
        return null;
1449ed425710 8148516: Improve the default strength of EC in JDK
xuelei
parents: 37814
diff changeset
   390
    }
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   391
}