1 /*
2 * Copyright (c) 1997, 2007, 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 javax.crypto.spec;
27
28 import java.math.BigInteger;
29 import java.security.spec.AlgorithmParameterSpec;
30
31 /**
32 * This class specifies the set of parameters used with the Diffie-Hellman
33 * algorithm, as specified in PKCS #3: <i>Diffie-Hellman Key-Agreement
34 * Standard</i>.
35 *
36 * <p>A central authority generates parameters and gives them to the two
37 * entities seeking to generate a secret key. The parameters are a prime
38 * <code>p</code>, a base <code>g</code>, and optionally the length
39 * in bits of the private value, <code>l</code>.
40 *
41 * <p>It is possible that more than one instance of parameters may be
42 * generated by a given central authority, and that there may be more than
43 * one central authority. Indeed, each individual may be its own central
44 * authority, with different entities having different parameters.
45 *
46 * <p>Note that this class does not perform any validation on specified
47 * parameters. Thus, the specified values are returned directly even
48 * if they are null.
49 *
50 * @author Jan Luehe
51 *
52 * @see javax.crypto.KeyAgreement
53 * @since 1.4
54 */
55 public class DHParameterSpec implements AlgorithmParameterSpec {
56
57 // The prime modulus
58 private BigInteger p;
59
60 // The base generator
61 private BigInteger g;
62
63 // The size in bits of the random exponent (private value) (optional)
64 private int l;
65
66 /**
67 * Constructs a parameter set for Diffie-Hellman, using a prime modulus
68 * <code>p</code> and a base generator <code>g</code>.
69 *
70 * @param p the prime modulus
71 * @param g the base generator
72 */
73 public DHParameterSpec(BigInteger p, BigInteger g) {
74 this.p = p;
75 this.g = g;
76 this.l = 0;
77 }
78
79 /**
80 * Constructs a parameter set for Diffie-Hellman, using a prime modulus
81 * <code>p</code>, a base generator <code>g</code>,
82 * and the size in bits, <code>l</code>, of the random exponent
83 * (private value).
84 *
85 * @param p the prime modulus
86 * @param g the base generator
87 * @param l the size in bits of the random exponent (private value)
88 */
89 public DHParameterSpec(BigInteger p, BigInteger g, int l) {
90 this.p = p;
91 this.g = g;
92 this.l = l;
93 }
94
95 /**
96 * Returns the prime modulus <code>p</code>.
97 *
98 * @return the prime modulus <code>p</code>
99 */
100 public BigInteger getP() {
101 return this.p;
102 }
103
104 /**
105 * Returns the base generator <code>g</code>.
106 *
107 * @return the base generator <code>g</code>
108 */
109 public BigInteger getG() {
110 return this.g;
111 }
112
113 /**
114 * Returns the size in bits, <code>l</code>, of the random exponent
115 * (private value).
116 *
117 * @return the size in bits, <code>l</code>, of the random exponent
118 * (private value), or 0 if this size has not been set
119 */
120 public int getL() {
121 return this.l;
122 }
123 }
124