Path: blob/master/src/java.base/share/classes/javax/crypto/spec/DHParameterSpec.java
41159 views
/*1* Copyright (c) 1997, 2007, 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 javax.crypto.spec;2627import java.math.BigInteger;28import java.security.spec.AlgorithmParameterSpec;2930/**31* This class specifies the set of parameters used with the Diffie-Hellman32* algorithm, as specified in PKCS #3: <i>Diffie-Hellman Key-Agreement33* Standard</i>.34*35* <p>A central authority generates parameters and gives them to the two36* entities seeking to generate a secret key. The parameters are a prime37* <code>p</code>, a base <code>g</code>, and optionally the length38* in bits of the private value, <code>l</code>.39*40* <p>It is possible that more than one instance of parameters may be41* generated by a given central authority, and that there may be more than42* one central authority. Indeed, each individual may be its own central43* authority, with different entities having different parameters.44*45* <p>Note that this class does not perform any validation on specified46* parameters. Thus, the specified values are returned directly even47* if they are null.48*49* @author Jan Luehe50*51* @see javax.crypto.KeyAgreement52* @since 1.453*/54public class DHParameterSpec implements AlgorithmParameterSpec {5556// The prime modulus57private BigInteger p;5859// The base generator60private BigInteger g;6162// The size in bits of the random exponent (private value) (optional)63private int l;6465/**66* Constructs a parameter set for Diffie-Hellman, using a prime modulus67* <code>p</code> and a base generator <code>g</code>.68*69* @param p the prime modulus70* @param g the base generator71*/72public DHParameterSpec(BigInteger p, BigInteger g) {73this.p = p;74this.g = g;75this.l = 0;76}7778/**79* Constructs a parameter set for Diffie-Hellman, using a prime modulus80* <code>p</code>, a base generator <code>g</code>,81* and the size in bits, <code>l</code>, of the random exponent82* (private value).83*84* @param p the prime modulus85* @param g the base generator86* @param l the size in bits of the random exponent (private value)87*/88public DHParameterSpec(BigInteger p, BigInteger g, int l) {89this.p = p;90this.g = g;91this.l = l;92}9394/**95* Returns the prime modulus <code>p</code>.96*97* @return the prime modulus <code>p</code>98*/99public BigInteger getP() {100return this.p;101}102103/**104* Returns the base generator <code>g</code>.105*106* @return the base generator <code>g</code>107*/108public BigInteger getG() {109return this.g;110}111112/**113* Returns the size in bits, <code>l</code>, of the random exponent114* (private value).115*116* @return the size in bits, <code>l</code>, of the random exponent117* (private value), or 0 if this size has not been set118*/119public int getL() {120return this.l;121}122}123124125