001: package org.bouncycastle.jce.spec;
002:
003: import java.security.spec.AlgorithmParameterSpec;
004:
005: import org.bouncycastle.asn1.DERObjectIdentifier;
006: import org.bouncycastle.asn1.cryptopro.CryptoProObjectIdentifiers;
007: import org.bouncycastle.asn1.cryptopro.GOST3410NamedParameters;
008: import org.bouncycastle.asn1.cryptopro.GOST3410ParamSetParameters;
009: import org.bouncycastle.jce.interfaces.GOST3410Params;
010:
011: /**
012: * ParameterSpec for a GOST 3410-94 key.
013: */
014: public class GOST3410ParameterSpec implements AlgorithmParameterSpec,
015: GOST3410Params {
016: private GOST3410PublicKeyParameterSetSpec keyParameters;
017: private String keyParamSetOID;
018: private String digestParamSetOID;
019: private String encryptionParamSetOID;
020:
021: public GOST3410ParameterSpec(String keyParamSetID,
022: String digestParamSetOID, String encryptionParamSetOID) {
023: GOST3410ParamSetParameters ecP = null;
024:
025: try {
026: ecP = GOST3410NamedParameters
027: .getByOID(new DERObjectIdentifier(keyParamSetID));
028: } catch (IllegalArgumentException e) {
029: DERObjectIdentifier oid = GOST3410NamedParameters
030: .getOID(keyParamSetID);
031: if (oid != null) {
032: keyParamSetID = oid.getId();
033: ecP = GOST3410NamedParameters.getByOID(oid);
034: }
035: }
036:
037: if (ecP == null) {
038: throw new IllegalArgumentException(
039: "no key parameter set for passed in name/OID.");
040: }
041:
042: this .keyParameters = new GOST3410PublicKeyParameterSetSpec(ecP
043: .getP(), ecP.getQ(), ecP.getA());
044:
045: this .keyParamSetOID = keyParamSetID;
046: this .digestParamSetOID = digestParamSetOID;
047: this .encryptionParamSetOID = encryptionParamSetOID;
048: }
049:
050: public GOST3410ParameterSpec(String keyParamSetID,
051: String digestParamSetOID) {
052: this (keyParamSetID, digestParamSetOID, null);
053: }
054:
055: public GOST3410ParameterSpec(String keyParamSetID) {
056: this (
057: keyParamSetID,
058: CryptoProObjectIdentifiers.gostR3411_94_CryptoProParamSet
059: .getId(), null);
060: }
061:
062: public GOST3410ParameterSpec(GOST3410PublicKeyParameterSetSpec spec) {
063: this .keyParameters = spec;
064: this .digestParamSetOID = CryptoProObjectIdentifiers.gostR3411_94_CryptoProParamSet
065: .getId();
066: this .encryptionParamSetOID = null;
067: }
068:
069: public String getPublicKeyParamSetOID() {
070: return this .keyParamSetOID;
071: }
072:
073: public GOST3410PublicKeyParameterSetSpec getPublicKeyParameters() {
074: return keyParameters;
075: }
076:
077: public String getDigestParamSetOID() {
078: return this .digestParamSetOID;
079: }
080:
081: public String getEncryptionParamSetOID() {
082: return this .encryptionParamSetOID;
083: }
084:
085: public boolean equals(Object o) {
086: if (o instanceof GOST3410ParameterSpec) {
087: GOST3410ParameterSpec other = (GOST3410ParameterSpec) o;
088:
089: return this .keyParameters.equals(other.keyParameters)
090: && this .digestParamSetOID
091: .equals(other.digestParamSetOID)
092: && (this .encryptionParamSetOID == other.encryptionParamSetOID || (this .encryptionParamSetOID != null && this .encryptionParamSetOID
093: .equals(other.encryptionParamSetOID)));
094: }
095:
096: return false;
097: }
098:
099: public int hashCode() {
100: return this .keyParameters.hashCode()
101: ^ this .digestParamSetOID.hashCode()
102: ^ (this .encryptionParamSetOID != null ? this .encryptionParamSetOID
103: .hashCode()
104: : 0);
105: }
106: }
|