src/java.base/share/classes/sun/security/util/ECParameters.java
author redestad
Mon, 08 Oct 2018 18:16:03 +0200
changeset 52040 d8aebcc2d3ac
parent 47216 71c04702a3d5
permissions -rw-r--r--
8211860: Avoid reading security properties eagerly on Manifest class initialization Reviewed-by: mullan, alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
25669
daa21271c03b 8035166: Remove dependency on EC classes from pkcs11 provider
valeriep
parents: 23010
diff changeset
     2
 * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
25669
daa21271c03b 8035166: Remove dependency on EC classes from pkcs11 provider
valeriep
parents: 23010
diff changeset
    26
package sun.security.util;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.security.spec.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * This class implements encoding and decoding of Elliptic Curve parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * as specified in RFC 3279.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * However, only named curves are currently supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * ASN.1 from RFC 3279 follows. Note that X9.62 (2005) has added some additional
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * options.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *    EcpkParameters ::= CHOICE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *      ecParameters  ECParameters,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *      namedCurve    OBJECT IDENTIFIER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *      implicitlyCA  NULL }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *    ECParameters ::= SEQUENCE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *       version   ECPVer,          -- version is always 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *       fieldID   FieldID,         -- identifies the finite field over
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *                                  -- which the curve is defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *       curve     Curve,           -- coefficients a and b of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *                                  -- elliptic curve
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *       base      ECPoint,         -- specifies the base point P
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *                                  -- on the elliptic curve
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *       order     INTEGER,         -- the order n of the base point
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *       cofactor  INTEGER OPTIONAL -- The integer h = #E(Fq)/n
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *    ECPVer ::= INTEGER {ecpVer1(1)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *    Curve ::= SEQUENCE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *       a         FieldElement,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *       b         FieldElement,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *       seed      BIT STRING OPTIONAL }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *    FieldElement ::= OCTET STRING
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *    ECPoint ::= OCTET STRING
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * @since   1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * @author  Andreas Sterbenz
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
public final class ECParameters extends AlgorithmParametersSpi {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
17491
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
    77
    // used by ECPublicKeyImpl and ECPrivateKeyImpl
25669
daa21271c03b 8035166: Remove dependency on EC classes from pkcs11 provider
valeriep
parents: 23010
diff changeset
    78
    public static AlgorithmParameters getAlgorithmParameters(ECParameterSpec spec)
17491
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
    79
            throws InvalidKeyException {
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
    80
        try {
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
    81
            AlgorithmParameters params =
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
    82
                AlgorithmParameters.getInstance("EC", "SunEC");
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
    83
            params.init(spec);
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
    84
            return params;
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
    85
        } catch (GeneralSecurityException e) {
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
    86
            throw new InvalidKeyException("EC parameters error", e);
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
    87
        }
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
    88
    }
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
    89
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
    90
    /*
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
    91
     * The parameters these AlgorithmParameters object represents.
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
    92
     * Currently, it is always an instance of NamedCurve.
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
    93
     */
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
    94
    private NamedCurve namedCurve;
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
    95
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
    96
    // A public constructor is required by AlgorithmParameters class.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    public ECParameters() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        // empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
17491
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   101
    // AlgorithmParameterSpi methods
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   102
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   103
    protected void engineInit(AlgorithmParameterSpec paramSpec)
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   104
            throws InvalidParameterSpecException {
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   105
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   106
        if (paramSpec == null) {
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   107
            throw new InvalidParameterSpecException
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   108
                ("paramSpec must not be null");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        }
17491
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   110
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   111
        if (paramSpec instanceof NamedCurve) {
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   112
            namedCurve = (NamedCurve)paramSpec;
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   113
            return;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
17491
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   116
        if (paramSpec instanceof ECParameterSpec) {
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   117
            namedCurve = CurveDB.lookup((ECParameterSpec)paramSpec);
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   118
        } else if (paramSpec instanceof ECGenParameterSpec) {
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   119
            String name = ((ECGenParameterSpec)paramSpec).getName();
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   120
            namedCurve = CurveDB.lookup(name);
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   121
        } else if (paramSpec instanceof ECKeySizeParameterSpec) {
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   122
            int keySize = ((ECKeySizeParameterSpec)paramSpec).getKeySize();
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   123
            namedCurve = CurveDB.lookup(keySize);
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   124
        } else {
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   125
            throw new InvalidParameterSpecException
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   126
                ("Only ECParameterSpec and ECGenParameterSpec supported");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
17491
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   129
        if (namedCurve == null) {
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   130
            throw new InvalidParameterSpecException(
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   131
                "Not a supported curve: " + paramSpec);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
17491
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   135
    protected void engineInit(byte[] params) throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        DerValue encodedParams = new DerValue(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        if (encodedParams.tag == DerValue.tag_ObjectId) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            ObjectIdentifier oid = encodedParams.getOID();
17491
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   139
            NamedCurve spec = CurveDB.lookup(oid.toString());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            if (spec == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                throw new IOException("Unknown named curve: " + oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            }
17491
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   143
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   144
            namedCurve = spec;
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   145
            return;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        throw new IOException("Only named ECParameters supported");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        // The code below is incomplete.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        // It is left as a starting point for a complete parsing implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        if (encodedParams.tag != DerValue.tag_Sequence) {
17491
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   155
            throw new IOException("Unsupported EC parameters, tag: " +
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   156
                encodedParams.tag);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        encodedParams.data.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        DerInputStream in = encodedParams.data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        int version = in.getInteger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        if (version != 1) {
17491
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   165
            throw new IOException("Unsupported EC parameters version: " +
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   166
               version);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        ECField field = parseField(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        EllipticCurve curve = parseCurve(in, field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        ECPoint point = parsePoint(in, curve);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        BigInteger order = in.getBigInteger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        int cofactor = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        if (in.available() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            cofactor = in.getInteger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        // XXX HashAlgorithm optional
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        if (encodedParams.data.available() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            throw new IOException("encoded params have " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                                  encodedParams.data.available() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                                  " extra bytes");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        return new ECParameterSpec(curve, point, order, cofactor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
17491
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   191
    protected void engineInit(byte[] params, String decodingMethod)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        engineInit(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
17491
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   196
    protected <T extends AlgorithmParameterSpec> T
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   197
            engineGetParameterSpec(Class<T> spec)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            throws InvalidParameterSpecException {
17491
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   199
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        if (spec.isAssignableFrom(ECParameterSpec.class)) {
17491
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   201
            return spec.cast(namedCurve);
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   202
        }
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   203
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   204
        if (spec.isAssignableFrom(ECGenParameterSpec.class)) {
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   205
            // Ensure the name is the Object ID
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   206
            String name = namedCurve.getObjectId();
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   207
            return spec.cast(new ECGenParameterSpec(name));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        }
17491
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   209
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   210
        if (spec.isAssignableFrom(ECKeySizeParameterSpec.class)) {
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   211
            int keySize = namedCurve.getCurve().getField().getFieldSize();
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   212
            return spec.cast(new ECKeySizeParameterSpec(keySize));
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   213
        }
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   214
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   215
        throw new InvalidParameterSpecException(
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   216
            "Only ECParameterSpec and ECGenParameterSpec supported");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    protected byte[] engineGetEncoded() throws IOException {
17491
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   220
        return namedCurve.getEncoded();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
17491
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   223
    protected byte[] engineGetEncoded(String encodingMethod)
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   224
            throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        return engineGetEncoded();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    protected String engineToString() {
17491
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   229
        if (namedCurve == null) {
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   230
            return "Not initialized";
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   231
        }
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   232
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   233
        return namedCurve.toString();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
}
17491
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 13813
diff changeset
   236