1 /*
2  * Copyright (c) 2018, Red Hat, Inc.
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.pkcs11.wrapper;
27 
28 /**
29  * CK_TLS12_KEY_MAT_PARAMS from PKCS#11 v2.40.
30  */
31 public class CK_TLS12_KEY_MAT_PARAMS {
32 
33     /**
34      * <B>PKCS#11:</B>
35      * <PRE>
36      *   CK_ULONG ulMacSizeInBits;
37      * </PRE>
38      */
39     public long ulMacSizeInBits;
40 
41     /**
42      * <B>PKCS#11:</B>
43      * <PRE>
44      *   CK_ULONG ulKeySizeInBits;
45      * </PRE>
46      */
47     public long ulKeySizeInBits;
48 
49     /**
50      * <B>PKCS#11:</B>
51      * <PRE>
52      *   CK_ULONG ulIVSizeInBits;
53      * </PRE>
54      */
55     public long ulIVSizeInBits;
56 
57     /**
58      * <B>PKCS#11:</B>
59      * <PRE>
60      *   CK_BBOOL bIsExport;
61      * </PRE>
62      */
63     public boolean bIsExport;
64 
65     /**
66      * <B>PKCS#11:</B>
67      * <PRE>
68      *   CK_SSL3_RANDOM_DATA RandomInfo;
69      * </PRE>
70      */
71     public CK_SSL3_RANDOM_DATA RandomInfo;
72 
73     /**
74      * <B>PKCS#11:</B>
75      * <PRE>
76      *   CK_SSL3_KEY_MAT_OUT_PTR pReturnedKeyMaterial;
77      * </PRE>
78      */
79     public CK_SSL3_KEY_MAT_OUT pReturnedKeyMaterial;
80 
81     /**
82      * <B>PKCS#11:</B>
83      * <PRE>
84      *   CK_MECHANISM_TYPE prfHashMechanism;
85      * </PRE>
86      */
87     public long prfHashMechanism;
88 
CK_TLS12_KEY_MAT_PARAMS( int macSize, int keySize, int ivSize, boolean export, CK_SSL3_RANDOM_DATA random, long prfHashMechanism)89     public CK_TLS12_KEY_MAT_PARAMS(
90             int macSize, int keySize, int ivSize, boolean export,
91             CK_SSL3_RANDOM_DATA random, long prfHashMechanism) {
92         ulMacSizeInBits = macSize;
93         ulKeySizeInBits = keySize;
94         ulIVSizeInBits = ivSize;
95         bIsExport = export;
96         RandomInfo = random;
97         pReturnedKeyMaterial = new CK_SSL3_KEY_MAT_OUT();
98         if (ivSize != 0) {
99             int n = ivSize >> 3;
100             pReturnedKeyMaterial.pIVClient = new byte[n];
101             pReturnedKeyMaterial.pIVServer = new byte[n];
102         }
103         this.prfHashMechanism = prfHashMechanism;
104     }
105 
106     /**
107      * Returns the string representation of CK_TLS12_KEY_MAT_PARAMS.
108      *
109      * @return the string representation of CK_TLS12_KEY_MAT_PARAMS
110      */
toString()111     public String toString() {
112         StringBuilder buffer = new StringBuilder();
113 
114         buffer.append(Constants.INDENT);
115         buffer.append("ulMacSizeInBits: ");
116         buffer.append(ulMacSizeInBits);
117         buffer.append(Constants.NEWLINE);
118 
119         buffer.append(Constants.INDENT);
120         buffer.append("ulKeySizeInBits: ");
121         buffer.append(ulKeySizeInBits);
122         buffer.append(Constants.NEWLINE);
123 
124         buffer.append(Constants.INDENT);
125         buffer.append("ulIVSizeInBits: ");
126         buffer.append(ulIVSizeInBits);
127         buffer.append(Constants.NEWLINE);
128 
129         buffer.append(Constants.INDENT);
130         buffer.append("bIsExport: ");
131         buffer.append(bIsExport);
132         buffer.append(Constants.NEWLINE);
133 
134         buffer.append(Constants.INDENT);
135         buffer.append("RandomInfo: ");
136         buffer.append(RandomInfo);
137         buffer.append(Constants.NEWLINE);
138 
139         buffer.append(Constants.INDENT);
140         buffer.append("pReturnedKeyMaterial: ");
141         buffer.append(pReturnedKeyMaterial);
142         buffer.append(Constants.NEWLINE);
143 
144         buffer.append(Constants.INDENT);
145         buffer.append("prfHashMechanism: ");
146         buffer.append(prfHashMechanism);
147 
148         return buffer.toString();
149     }
150 
151 }
152