src/java.base/share/classes/sun/security/ssl/NamedGroup.java
branchJDK-8145252-TLS13-branch
changeset 56542 56aaa6cb3693
parent 56541 92cbbfc996f3
child 56543 2352538d2f6e
equal deleted inserted replaced
56541:92cbbfc996f3 56542:56aaa6cb3693
     1 /*
       
     2  * Copyright (c) 2017, 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.ssl;
       
    27 
       
    28 import java.security.spec.ECParameterSpec;
       
    29 import java.security.spec.ECGenParameterSpec;
       
    30 import static sun.security.ssl.NamedGroupType.*;
       
    31 
       
    32 enum NamedGroup {
       
    33     // Elliptic Curves (RFC 4492)
       
    34     //
       
    35     // See sun.security.util.CurveDB for the OIDs
       
    36 
       
    37     // NIST K-163
       
    38     SECT163_K1(1, NAMED_GROUP_ECDHE, "sect163k1", "1.3.132.0.1", true),
       
    39 
       
    40     SECT163_R1(2, NAMED_GROUP_ECDHE, "sect163r1", "1.3.132.0.2", false),
       
    41 
       
    42     // NIST B-163
       
    43     SECT163_R2(3, NAMED_GROUP_ECDHE, "sect163r2", "1.3.132.0.15", true),
       
    44 
       
    45     SECT193_R1(4, NAMED_GROUP_ECDHE, "sect193r1", "1.3.132.0.24", false),
       
    46     SECT193_R2(5, NAMED_GROUP_ECDHE, "sect193r2", "1.3.132.0.25", false),
       
    47 
       
    48     // NIST K-233
       
    49     SECT233_K1(6, NAMED_GROUP_ECDHE, "sect233k1", "1.3.132.0.26", true),
       
    50 
       
    51     // NIST B-233
       
    52     SECT233_R1(7, NAMED_GROUP_ECDHE, "sect233r1", "1.3.132.0.27", true),
       
    53 
       
    54     SECT239_K1(8, NAMED_GROUP_ECDHE, "sect239k1", "1.3.132.0.3", false),
       
    55 
       
    56     // NIST K-283
       
    57     SECT283_K1(9, NAMED_GROUP_ECDHE, "sect283k1", "1.3.132.0.16", true),
       
    58 
       
    59     // NIST B-283
       
    60     SECT283_R1(10, NAMED_GROUP_ECDHE, "sect283r1", "1.3.132.0.17", true),
       
    61 
       
    62     // NIST K-409
       
    63     SECT409_K1(11, NAMED_GROUP_ECDHE, "sect409k1", "1.3.132.0.36", true),
       
    64 
       
    65     // NIST B-409
       
    66     SECT409_R1(12, NAMED_GROUP_ECDHE, "sect409r1", "1.3.132.0.37", true),
       
    67 
       
    68     // NIST K-571
       
    69     SECT571_K1(13, NAMED_GROUP_ECDHE, "sect571k1", "1.3.132.0.38", true),
       
    70 
       
    71     // NIST B-571
       
    72     SECT571_R1(14, NAMED_GROUP_ECDHE, "sect571r1", "1.3.132.0.39", true),
       
    73 
       
    74     SECP160_K1(15, NAMED_GROUP_ECDHE, "secp160k1", "1.3.132.0.9", false),
       
    75     SECP160_R1(16, NAMED_GROUP_ECDHE, "secp160r1", "1.3.132.0.8", false),
       
    76     SECP160_R2(17, NAMED_GROUP_ECDHE, "secp160r2", "1.3.132.0.30", false),
       
    77     SECP192_K1(18, NAMED_GROUP_ECDHE, "secp192k1", "1.3.132.0.31", false),
       
    78 
       
    79     // NIST P-192
       
    80     SECP192_R1(19, NAMED_GROUP_ECDHE, "secp192r1", "1.2.840.10045.3.1.1", true),
       
    81 
       
    82     SECP224_K1(20, NAMED_GROUP_ECDHE, "secp224k1", "1.3.132.0.32", false),
       
    83     // NIST P-224
       
    84     SECP224_R1(21, NAMED_GROUP_ECDHE, "secp224r1", "1.3.132.0.33", true),
       
    85 
       
    86     SECP256_K1(22, NAMED_GROUP_ECDHE, "secp256k1", "1.3.132.0.10", false),
       
    87 
       
    88     // NIST P-256
       
    89     SECP256_R1(23, NAMED_GROUP_ECDHE, "secp256r1", "1.2.840.10045.3.1.7", true),
       
    90 
       
    91     // NIST P-384
       
    92     SECP384_R1(24, NAMED_GROUP_ECDHE, "secp384r1", "1.3.132.0.34", true),
       
    93 
       
    94     // NIST P-521
       
    95     SECP521_R1(25, NAMED_GROUP_ECDHE, "secp521r1", "1.3.132.0.35", true),
       
    96 
       
    97     // Finite Field Diffie-Hellman Ephemeral Parameters (RFC 7919)
       
    98     FFDHE_2048(256, NAMED_GROUP_FFDHE, "ffdhe2048",  true),
       
    99     FFDHE_3072(257, NAMED_GROUP_FFDHE, "ffdhe3072",  true),
       
   100     FFDHE_4096(258, NAMED_GROUP_FFDHE, "ffdhe4096",  true),
       
   101     FFDHE_6144(259, NAMED_GROUP_FFDHE, "ffdhe6144",  true),
       
   102     FFDHE_8192(260, NAMED_GROUP_FFDHE, "ffdhe8192",  true);
       
   103 
       
   104     int             id;
       
   105     NamedGroupType  type;
       
   106     String          name;
       
   107     String          oid;
       
   108     String          algorithm;
       
   109     boolean         isFips;
       
   110 
       
   111     // Constructor used for Elliptic Curve Groups (ECDHE)
       
   112     NamedGroup(int id, NamedGroupType type,
       
   113                 String name, String oid, boolean isFips) {
       
   114         this.id = id;
       
   115         this.type = type;
       
   116         this.name = name;
       
   117         this.oid = oid;
       
   118         this.algorithm = "EC";
       
   119         this.isFips = isFips;
       
   120     }
       
   121 
       
   122     // Constructor used for Finite Field Diffie-Hellman Groups (FFDHE)
       
   123     NamedGroup(int id, NamedGroupType type, String name, boolean isFips) {
       
   124         this.id = id;
       
   125         this.type = type;
       
   126         this.name = name;
       
   127         this.oid = null;
       
   128         this.algorithm = "DiffieHellman";
       
   129         this.isFips = isFips;
       
   130     }
       
   131 
       
   132     static NamedGroup valueOf(int id) {
       
   133         for (NamedGroup group : NamedGroup.values()) {
       
   134             if (group.id == id) {
       
   135                 return group;
       
   136             }
       
   137         }
       
   138 
       
   139         return null;
       
   140     }
       
   141 
       
   142     static NamedGroup nameOf(String name) {
       
   143         for (NamedGroup group : NamedGroup.values()) {
       
   144             if (group.name.equals(name)) {
       
   145                 return group;
       
   146             }
       
   147         }
       
   148 
       
   149         return null;
       
   150     }
       
   151 
       
   152     static NamedGroup valueOf(ECParameterSpec params) {
       
   153         String oid = JsseJce.getNamedCurveOid(params);
       
   154         if ((oid != null) && (!oid.isEmpty())) {
       
   155             for (NamedGroup group : NamedGroup.values()) {
       
   156                 if (oid.equals(group.oid)) {
       
   157                     return group;
       
   158                 }
       
   159             }
       
   160         }
       
   161 
       
   162         return null;
       
   163     }
       
   164 
       
   165     @Override
       
   166     public String toString() {
       
   167         return this.name;
       
   168     }
       
   169 }