01: package org.bouncycastle.asn1.cryptopro;
02:
03: import java.math.BigInteger;
04: import java.util.Enumeration;
05:
06: import org.bouncycastle.asn1.ASN1Encodable;
07: import org.bouncycastle.asn1.ASN1EncodableVector;
08: import org.bouncycastle.asn1.ASN1Sequence;
09: import org.bouncycastle.asn1.ASN1TaggedObject;
10: import org.bouncycastle.asn1.DERInteger;
11: import org.bouncycastle.asn1.DERObject;
12: import org.bouncycastle.asn1.DERSequence;
13:
14: public class GOST3410ParamSetParameters extends ASN1Encodable {
15: int keySize;
16: DERInteger p, q, a;
17:
18: public static GOST3410ParamSetParameters getInstance(
19: ASN1TaggedObject obj, boolean explicit) {
20: return getInstance(ASN1Sequence.getInstance(obj, explicit));
21: }
22:
23: public static GOST3410ParamSetParameters getInstance(Object obj) {
24: if (obj == null || obj instanceof GOST3410ParamSetParameters) {
25: return (GOST3410ParamSetParameters) obj;
26: }
27:
28: if (obj instanceof ASN1Sequence) {
29: return new GOST3410ParamSetParameters((ASN1Sequence) obj);
30: }
31:
32: throw new IllegalArgumentException(
33: "Invalid GOST3410Parameter: "
34: + obj.getClass().getName());
35: }
36:
37: public GOST3410ParamSetParameters(int keySize, BigInteger p,
38: BigInteger q, BigInteger a) {
39: this .keySize = keySize;
40: this .p = new DERInteger(p);
41: this .q = new DERInteger(q);
42: this .a = new DERInteger(a);
43: }
44:
45: public GOST3410ParamSetParameters(ASN1Sequence seq) {
46: Enumeration e = seq.getObjects();
47:
48: keySize = ((DERInteger) e.nextElement()).getValue().intValue();
49: p = (DERInteger) e.nextElement();
50: q = (DERInteger) e.nextElement();
51: a = (DERInteger) e.nextElement();
52: }
53:
54: /**
55: * @deprecated use getKeySize
56: */
57: public int getLKeySize() {
58: return keySize;
59: }
60:
61: public int getKeySize() {
62: return keySize;
63: }
64:
65: public BigInteger getP() {
66: return p.getPositiveValue();
67: }
68:
69: public BigInteger getQ() {
70: return q.getPositiveValue();
71: }
72:
73: public BigInteger getA() {
74: return a.getPositiveValue();
75: }
76:
77: public DERObject toASN1Object() {
78: ASN1EncodableVector v = new ASN1EncodableVector();
79:
80: v.add(new DERInteger(keySize));
81: v.add(p);
82: v.add(q);
83: v.add(a);
84:
85: return new DERSequence(v);
86: }
87: }
|