View Javadoc

1   /**
2    *
3    *  Licensed to the Apache Software Foundation (ASF) under one or more
4    *  contributor license agreements.  See the NOTICE file distributed with
5    *  this work for additional information regarding copyright ownership.
6    *  The ASF licenses this file to You under the Apache License, Version 2.0
7    *  (the "License"); you may not use this file except in compliance with
8    *  the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *  Unless required by applicable law or agreed to in writing, software
13   *  distributed under the License is distributed on an "AS IS" BASIS,
14   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   *  See the License for the specific language governing permissions and
16   *  limitations under the License.
17   */
18  
19  package org.apache.geronimo.util.crypto.params;
20  
21  import java.math.BigInteger;
22  
23  import org.apache.geronimo.util.crypto.CipherParameters;
24  
25  public class DHParameters
26      implements CipherParameters
27  {
28      private BigInteger              g;
29      private BigInteger              p;
30      private BigInteger              q;
31      private int                     j;
32      private DHValidationParameters  validation;
33  
34      public DHParameters(
35          BigInteger  p,
36          BigInteger  g)
37      {
38          this.g = g;
39          this.p = p;
40      }
41  
42      public DHParameters(
43          BigInteger  p,
44          BigInteger  g,
45          BigInteger  q,
46          int         j)
47      {
48          this.g = g;
49          this.p = p;
50          this.q = q;
51          this.j = j;
52      }
53  
54      public DHParameters(
55          BigInteger              p,
56          BigInteger              g,
57          BigInteger              q,
58          int                     j,
59          DHValidationParameters  validation)
60      {
61          this.g = g;
62          this.p = p;
63          this.q = q;
64          this.j = j;
65      }
66  
67      public BigInteger getP()
68      {
69          return p;
70      }
71  
72      public BigInteger getG()
73      {
74          return g;
75      }
76  
77      public BigInteger getQ()
78      {
79          return q;
80      }
81  
82      /**
83       * Return the private value length in bits - if set, zero otherwise (use bitLength(P) - 1).
84       *
85       * @return the private value length in bits, zero otherwise.
86       */
87      public int getJ()
88      {
89          return j;
90      }
91  
92      public DHValidationParameters getValidationParameters()
93      {
94          return validation;
95      }
96  
97      public boolean equals(
98          Object  obj)
99      {
100         if (!(obj instanceof DHParameters))
101         {
102             return false;
103         }
104 
105         DHParameters    pm = (DHParameters)obj;
106 
107         if (this.getValidationParameters() != null)
108         {
109             if (!this.getValidationParameters().equals(pm.getValidationParameters()))
110             {
111                 return false;
112             }
113         }
114         else
115         {
116             if (pm.getValidationParameters() != null)
117             {
118                 return false;
119             }
120         }
121 
122         if (this.getQ() != null)
123         {
124             if (!this.getQ().equals(pm.getQ()))
125             {
126                 return false;
127             }
128         }
129         else
130         {
131             if (pm.getQ() != null)
132             {
133                 return false;
134             }
135         }
136 
137         return (j == pm.getJ()) && pm.getP().equals(p) && pm.getG().equals(g);
138     }
139 }