Home | History | Annotate | Download | only in spec
      1 /*
      2  *  Licensed to the Apache Software Foundation (ASF) under one or more
      3  *  contributor license agreements.  See the NOTICE file distributed with
      4  *  this work for additional information regarding copyright ownership.
      5  *  The ASF licenses this file to You under the Apache License, Version 2.0
      6  *  (the "License"); you may not use this file except in compliance with
      7  *  the License.  You may obtain a copy of the License at
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  */
     17 
     18 package javax.crypto.spec;
     19 
     20 import java.math.BigInteger;
     21 import java.security.spec.AlgorithmParameterSpec;
     22 
     23 /**
     24  * The algorithm parameter specification for the Diffie-Hellman algorithm.
     25  */
     26 public class DHParameterSpec implements AlgorithmParameterSpec {
     27 
     28     private final BigInteger p;
     29     private final BigInteger g;
     30     private final int l;
     31 
     32     /**
     33      * Creates a new <code>DHParameterSpec</code> instance with the specified
     34      * <i>prime modulus</i> and <i>base generator</i>.
     35      *
     36      * @param p
     37      *            the prime modulus.
     38      * @param g
     39      *            the base generator.
     40      */
     41     public DHParameterSpec(BigInteger p, BigInteger g) {
     42         this.p = p;
     43         this.g = g;
     44         this.l = 0;
     45     }
     46 
     47     /**
     48      * Creates a new <code>DHParameterSpec</code> instance with the specified
     49      * <i>prime modulus</i>, <i>base generator</i> and size (in bits) of the
     50      * <i>random exponent</i>.
     51      *
     52      * @param p
     53      *            the prime modulus.
     54      * @param g
     55      *            the base generator.
     56      * @param l
     57      *            the size of the random exponent (in bits).
     58      */
     59     public DHParameterSpec(BigInteger p, BigInteger g, int l) {
     60         this.p = p;
     61         this.g = g;
     62         this.l = l;
     63     }
     64 
     65     /**
     66      * Returns the <i>prime modulus</i> of this parameter specification.
     67      *
     68      * @return the prime modulus.
     69      */
     70     public BigInteger getP() {
     71         return p;
     72     }
     73 
     74     /**
     75      * Returns the <i>base generator</i> of this parameter specification.
     76      *
     77      * @return the base generator.
     78      */
     79     public BigInteger getG() {
     80         return g;
     81     }
     82 
     83     /**
     84      * Returns the size (in bits) of the <i>random exponent</i>.
     85      *
     86      * @return the size (in bits) of the random exponent.
     87      */
     88     public int getL() {
     89         return l;
     90     }
     91 }
     92 
     93