001    /**
002     *  Licensed to the Apache Software Foundation (ASF) under one or more
003     *  contributor license agreements.  See the NOTICE file distributed with
004     *  this work for additional information regarding copyright ownership.
005     *  The ASF licenses this file to You under the Apache License, Version 2.0
006     *  (the "License"); you may not use this file except in compliance with
007     *  the License.  You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     *  Unless required by applicable law or agreed to in writing, software
012     *  distributed under the License is distributed on an "AS IS" BASIS,
013     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     *  See the License for the specific language governing permissions and
015     *  limitations under the License.
016     */
017    
018    package org.apache.geronimo.crypto.crypto.params;
019    
020    import java.math.BigInteger;
021    
022    import org.apache.geronimo.crypto.crypto.CipherParameters;
023    
024    public class DHParameters
025        implements CipherParameters
026    {
027        private BigInteger              g;
028        private BigInteger              p;
029        private BigInteger              q;
030        private int                     j;
031        private DHValidationParameters  validation;
032    
033        public DHParameters(
034            BigInteger  p,
035            BigInteger  g)
036        {
037            this.g = g;
038            this.p = p;
039        }
040    
041        public DHParameters(
042            BigInteger  p,
043            BigInteger  g,
044            BigInteger  q,
045            int         j)
046        {
047            this.g = g;
048            this.p = p;
049            this.q = q;
050            this.j = j;
051        }
052    
053        public DHParameters(
054            BigInteger              p,
055            BigInteger              g,
056            BigInteger              q,
057            int                     j,
058            DHValidationParameters  validation)
059        {
060            this.g = g;
061            this.p = p;
062            this.q = q;
063            this.j = j;
064        }
065    
066        public BigInteger getP()
067        {
068            return p;
069        }
070    
071        public BigInteger getG()
072        {
073            return g;
074        }
075    
076        public BigInteger getQ()
077        {
078            return q;
079        }
080    
081        /**
082         * Return the private value length in bits - if set, zero otherwise (use bitLength(P) - 1).
083         *
084         * @return the private value length in bits, zero otherwise.
085         */
086        public int getJ()
087        {
088            return j;
089        }
090    
091        public DHValidationParameters getValidationParameters()
092        {
093            return validation;
094        }
095    
096        public boolean equals(
097            Object  obj)
098        {
099            if (!(obj instanceof DHParameters))
100            {
101                return false;
102            }
103    
104            DHParameters    pm = (DHParameters)obj;
105    
106            if (this.getValidationParameters() != null)
107            {
108                if (!this.getValidationParameters().equals(pm.getValidationParameters()))
109                {
110                    return false;
111                }
112            }
113            else
114            {
115                if (pm.getValidationParameters() != null)
116                {
117                    return false;
118                }
119            }
120    
121            if (this.getQ() != null)
122            {
123                if (!this.getQ().equals(pm.getQ()))
124                {
125                    return false;
126                }
127            }
128            else
129            {
130                if (pm.getQ() != null)
131                {
132                    return false;
133                }
134            }
135    
136            return (j == pm.getJ()) && pm.getP().equals(p) && pm.getG().equals(g);
137        }
138    }