src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/wrapper/CK_MECHANISM.java
author mbalao
Wed, 12 Sep 2018 13:09:51 +0200
changeset 51800 bccd9966f1ed
parent 47216 71c04702a3d5
child 55332 f492567244ab
permissions -rw-r--r--
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider Summary: TLS v1.2 algorithms for key and MAC derivation added to SunPKCS11 crypto provider. Reviewed-by: valeriep
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
     2
 * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
/* Copyright  (c) 2002 Graz University of Technology. All rights reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * Redistribution and use in  source and binary forms, with or without
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * modification, are permitted  provided that the following conditions are met:
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * 1. Redistributions of  source code must retain the above copyright notice,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 *    this list of conditions and the following disclaimer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * 2. Redistributions in  binary form must reproduce the above copyright notice,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *    this list of conditions and the following disclaimer in the documentation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *    and/or other materials provided with the distribution.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * 3. The end-user documentation included with the redistribution, if any, must
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *    include the following acknowledgment:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *    "This product includes software developed by IAIK of Graz University of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 *     Technology."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 *    Alternately, this acknowledgment may appear in the software itself, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 *    and wherever such third-party acknowledgments normally appear.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * 4. The names "Graz University of Technology" and "IAIK of Graz University of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *    Technology" must not be used to endorse or promote products derived from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *    this software without prior written permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * 5. Products derived from this software may not be called
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *    "IAIK PKCS Wrapper", nor may "IAIK" appear in their name, without prior
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *    written permission of Graz University of Technology.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *  THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LICENSOR BE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *  POSSIBILITY  OF SUCH DAMAGE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
package sun.security.pkcs11.wrapper;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.math.BigInteger;
8542
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
    51
import static sun.security.pkcs11.wrapper.PKCS11Constants.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * class CK_MECHANISM specifies a particular mechanism and any parameters it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * requires.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <B>PKCS#11 structure:</B>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *  typedef struct CK_MECHANISM {&nbsp;&nbsp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *    CK_MECHANISM_TYPE mechanism;&nbsp;&nbsp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *    CK_VOID_PTR pParameter;&nbsp;&nbsp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *    CK_ULONG ulParameterLen;&nbsp;&nbsp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *  } CK_MECHANISM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * </PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * @author Karl Scheibelhofer <Karl.Scheibelhofer@iaik.at>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * @author Martin Schlaeffer <schlaeff@sbox.tugraz.at>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
public class CK_MECHANISM {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * <B>PKCS#11:</B>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * <PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     *   CK_MECHANISM_TYPE mechanism;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * </PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public long mechanism;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * <B>PKCS#11:</B>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * <PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     *   CK_VOID_PTR pParameter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     *   CK_ULONG ulParameterLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * </PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    public Object pParameter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public CK_MECHANISM() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        // empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    public CK_MECHANISM(long mechanism) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        this.mechanism = mechanism;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    // We don't have a (long,Object) constructor to force type checking.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    // This makes sure we don't accidentally pass a class that the native
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    // code cannot handle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    public CK_MECHANISM(long mechanism, byte[] pParameter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        init(mechanism, pParameter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    public CK_MECHANISM(long mechanism, BigInteger b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        init(mechanism, sun.security.pkcs11.P11Util.getMagnitude(b));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public CK_MECHANISM(long mechanism, CK_VERSION version) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        init(mechanism, version);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    public CK_MECHANISM(long mechanism, CK_SSL3_MASTER_KEY_DERIVE_PARAMS params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        init(mechanism, params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   115
    public CK_MECHANISM(long mechanism, CK_TLS12_MASTER_KEY_DERIVE_PARAMS params) {
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   116
        init(mechanism, params);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   117
    }
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   118
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public CK_MECHANISM(long mechanism, CK_SSL3_KEY_MAT_PARAMS params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        init(mechanism, params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   123
    public CK_MECHANISM(long mechanism, CK_TLS12_KEY_MAT_PARAMS params) {
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   124
        init(mechanism, params);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   125
    }
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   126
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public CK_MECHANISM(long mechanism, CK_TLS_PRF_PARAMS params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        init(mechanism, params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   131
    public CK_MECHANISM(long mechanism, CK_TLS_MAC_PARAMS params) {
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   132
        init(mechanism, params);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   133
    }
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   134
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public CK_MECHANISM(long mechanism, CK_ECDH1_DERIVE_PARAMS params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        init(mechanism, params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public CK_MECHANISM(long mechanism, Long params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        init(mechanism, params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
8542
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   143
    public CK_MECHANISM(long mechanism, CK_AES_CTR_PARAMS params) {
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   144
        init(mechanism, params);
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   145
    }
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   146
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    private void init(long mechanism, Object pParameter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        this.mechanism = mechanism;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        this.pParameter = pParameter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * Returns the string representation of CK_MECHANISM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * @return the string representation of CK_MECHANISM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    public String toString() {
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 8542
diff changeset
   158
        StringBuilder sb = new StringBuilder();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 8542
diff changeset
   160
        sb.append(Constants.INDENT);
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 8542
diff changeset
   161
        sb.append("mechanism: ");
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 8542
diff changeset
   162
        sb.append(mechanism);
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 8542
diff changeset
   163
        sb.append(Constants.NEWLINE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 8542
diff changeset
   165
        sb.append(Constants.INDENT);
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 8542
diff changeset
   166
        sb.append("pParameter: ");
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 8542
diff changeset
   167
        sb.append(pParameter.toString());
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 8542
diff changeset
   168
        sb.append(Constants.NEWLINE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 8542
diff changeset
   170
        sb.append(Constants.INDENT);
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 8542
diff changeset
   171
        sb.append("ulParameterLen: ??");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        //buffer.append(pParameter.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        //buffer.append(Constants.NEWLINE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 8542
diff changeset
   175
        return sb.toString() ;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
}