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