• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2005, 2010, 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.internal.spec;
27 
28 import java.security.spec.AlgorithmParameterSpec;
29 
30 import javax.crypto.SecretKey;
31 
32 /**
33  * Parameters for the TLS PRF (pseudo-random function). The PRF function
34  * is defined in RFC 2246.
35  * This class is used to initialize KeyGenerators of the type "TlsPrf".
36  *
37  * <p>Instances of this class are immutable.
38  *
39  * @since   1.6
40  * @author  Andreas Sterbenz
41  * @deprecated Sun JDK internal use only --- WILL BE REMOVED in a future
42  * release.
43  */
44 @Deprecated
45 public class TlsPrfParameterSpec implements AlgorithmParameterSpec {
46 
47     private final SecretKey secret;
48     private final String label;
49     private final byte[] seed;
50     private final int outputLength;
51     private final String prfHashAlg;
52     private final int prfHashLength;
53     private final int prfBlockSize;
54 
55     /**
56      * Constructs a new TlsPrfParameterSpec.
57      *
58      * @param secret the secret to use in the calculation (or null)
59      * @param label the label to use in the calculation
60      * @param seed the random seed to use in the calculation
61      * @param outputLength the length in bytes of the output key to be produced
62      * @param prfHashAlg the name of the TLS PRF hash algorithm to use.
63      *        Used only for TLS 1.2+.  TLS1.1 and earlier use a fixed PRF.
64      * @param prfHashLength the output length of the TLS PRF hash algorithm.
65      *        Used only for TLS 1.2+.
66      * @param prfBlockSize the input block size of the TLS PRF hash algorithm.
67      *        Used only for TLS 1.2+.
68      *
69      * @throws NullPointerException if label or seed is null
70      * @throws IllegalArgumentException if outputLength is negative
71      */
TlsPrfParameterSpec(SecretKey secret, String label, byte[] seed, int outputLength, String prfHashAlg, int prfHashLength, int prfBlockSize)72     public TlsPrfParameterSpec(SecretKey secret, String label,
73             byte[] seed, int outputLength,
74             String prfHashAlg, int prfHashLength, int prfBlockSize) {
75         if ((label == null) || (seed == null)) {
76             throw new NullPointerException("label and seed must not be null");
77         }
78         if (outputLength <= 0) {
79             throw new IllegalArgumentException("outputLength must be positive");
80         }
81         this.secret = secret;
82         this.label = label;
83         this.seed = seed.clone();
84         this.outputLength = outputLength;
85         this.prfHashAlg = prfHashAlg;
86         this.prfHashLength = prfHashLength;
87         this.prfBlockSize = prfBlockSize;
88     }
89 
90     /**
91      * Returns the secret to use in the PRF calculation, or null if there is no
92      * secret.
93      *
94      * @return the secret to use in the PRF calculation, or null if there is no
95      * secret.
96      */
getSecret()97     public SecretKey getSecret() {
98         return secret;
99     }
100 
101     /**
102      * Returns the label to use in the PRF calcuation.
103      *
104      * @return the label to use in the PRF calcuation.
105      */
getLabel()106     public String getLabel() {
107         return label;
108     }
109 
110     /**
111      * Returns a copy of the seed to use in the PRF calcuation.
112      *
113      * @return a copy of the seed to use in the PRF calcuation.
114      */
getSeed()115     public byte[] getSeed() {
116         return seed.clone();
117     }
118 
119     /**
120      * Returns the length in bytes of the output key to be produced.
121      *
122      * @return the length in bytes of the output key to be produced.
123      */
getOutputLength()124     public int getOutputLength() {
125         return outputLength;
126     }
127 
128     /**
129      * Obtains the PRF hash algorithm to use in the PRF calculation.
130      *
131      * @return the hash algorithm, or null if no algorithm was specified.
132      */
getPRFHashAlg()133     public String getPRFHashAlg() {
134         return prfHashAlg;
135     }
136 
137     /**
138      * Obtains the length of PRF hash algorithm.
139      *
140      * It would have been preferred to use MessageDigest.getDigestLength(),
141      * but the API does not require implementations to support the method.
142      *
143      * @return the hash algorithm length.
144      */
getPRFHashLength()145     public int getPRFHashLength() {
146         return prfHashLength;
147     }
148 
149     /**
150      * Obtains the length of PRF hash algorithm.
151      *
152      * @return the hash algorithm length.
153      */
getPRFBlockSize()154     public int getPRFBlockSize() {
155         return prfBlockSize;
156     }
157 }
158