Path: blob/master/src/java.base/share/classes/sun/security/internal/spec/TlsPrfParameterSpec.java
41161 views
/*1* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.security.internal.spec;2627import java.security.spec.AlgorithmParameterSpec;2829import javax.crypto.SecretKey;3031/**32* Parameters for the TLS PRF (pseudo-random function). The PRF function33* is defined in RFC 2246.34* This class is used to initialize KeyGenerators of the type "TlsPrf".35*36* <p>Instances of this class are immutable.37*38* @since 1.639* @author Andreas Sterbenz40* @deprecated Sun JDK internal use only --- WILL BE REMOVED in a future41* release.42*/43@Deprecated44public class TlsPrfParameterSpec implements AlgorithmParameterSpec {4546private final SecretKey secret;47private final String label;48private final byte[] seed;49private final int outputLength;50private final String prfHashAlg;51private final int prfHashLength;52private final int prfBlockSize;5354/**55* Constructs a new TlsPrfParameterSpec.56*57* @param secret the secret to use in the calculation (or null)58* @param label the label to use in the calculation59* @param seed the random seed to use in the calculation60* @param outputLength the length in bytes of the output key to be produced61* @param prfHashAlg the name of the TLS PRF hash algorithm to use.62* Used only for TLS 1.2+. TLS1.1 and earlier use a fixed PRF.63* @param prfHashLength the output length of the TLS PRF hash algorithm.64* Used only for TLS 1.2+.65* @param prfBlockSize the input block size of the TLS PRF hash algorithm.66* Used only for TLS 1.2+.67*68* @throws NullPointerException if label or seed is null69* @throws IllegalArgumentException if outputLength is negative70*/71public TlsPrfParameterSpec(SecretKey secret, String label,72byte[] seed, int outputLength,73String prfHashAlg, int prfHashLength, int prfBlockSize) {74if ((label == null) || (seed == null)) {75throw new NullPointerException("label and seed must not be null");76}77if (outputLength <= 0) {78throw new IllegalArgumentException("outputLength must be positive");79}80this.secret = secret;81this.label = label;82this.seed = seed.clone();83this.outputLength = outputLength;84this.prfHashAlg = prfHashAlg;85this.prfHashLength = prfHashLength;86this.prfBlockSize = prfBlockSize;87}8889/**90* Returns the secret to use in the PRF calculation, or null if there is no91* secret.92*93* @return the secret to use in the PRF calculation, or null if there is no94* secret.95*/96public SecretKey getSecret() {97return secret;98}99100/**101* Returns the label to use in the PRF calcuation.102*103* @return the label to use in the PRF calcuation.104*/105public String getLabel() {106return label;107}108109/**110* Returns a copy of the seed to use in the PRF calcuation.111*112* @return a copy of the seed to use in the PRF calcuation.113*/114public byte[] getSeed() {115return seed.clone();116}117118/**119* Returns the length in bytes of the output key to be produced.120*121* @return the length in bytes of the output key to be produced.122*/123public int getOutputLength() {124return outputLength;125}126127/**128* Obtains the PRF hash algorithm to use in the PRF calculation.129*130* @return the hash algorithm, or null if no algorithm was specified.131*/132public String getPRFHashAlg() {133return prfHashAlg;134}135136/**137* Obtains the length of PRF hash algorithm.138*139* It would have been preferred to use MessageDigest.getDigestLength(),140* but the API does not require implementations to support the method.141*142* @return the hash algorithm length.143*/144public int getPRFHashLength() {145return prfHashLength;146}147148/**149* Obtains the length of PRF hash algorithm.150*151* @return the hash algorithm length.152*/153public int getPRFBlockSize() {154return prfBlockSize;155}156}157158159