001: package org.bouncycastle.asn1.cryptopro;
002:
003: import java.math.BigInteger;
004: import java.util.Enumeration;
005: import java.util.Hashtable;
006:
007: import org.bouncycastle.asn1.DERObjectIdentifier;
008: import org.bouncycastle.crypto.params.ECDomainParameters;
009: import org.bouncycastle.math.ec.ECCurve;
010: import org.bouncycastle.math.ec.ECFieldElement;
011: import org.bouncycastle.math.ec.ECPoint;
012:
013: /**
014: * table of the available named parameters for GOST 3410-2001.
015: */
016: public class ECGOST3410NamedCurves {
017: static final Hashtable objIds = new Hashtable();
018: static final Hashtable params = new Hashtable();
019: static final Hashtable names = new Hashtable();
020:
021: static {
022: BigInteger mod_p = new BigInteger(
023: "115792089237316195423570985008687907853269984665640564039457584007913129639319");
024: BigInteger mod_q = new BigInteger(
025: "115792089237316195423570985008687907853073762908499243225378155805079068850323");
026:
027: ECCurve.Fp curve = new ECCurve.Fp(
028: mod_p, // p
029: new BigInteger(
030: "115792089237316195423570985008687907853269984665640564039457584007913129639316"), // a
031: new BigInteger("166")); // b
032:
033: ECDomainParameters ecParams = new ECDomainParameters(
034: curve,
035: new ECPoint.Fp(curve,
036: new ECFieldElement.Fp(curve.getQ(),
037: new BigInteger("1")), // x
038: new ECFieldElement.Fp(
039: curve.getQ(),
040: new BigInteger(
041: "64033881142927202683649881450433473985931760268884941288852745803908878638612"))), // y
042: mod_q);
043:
044: params.put(
045: CryptoProObjectIdentifiers.gostR3410_2001_CryptoPro_A,
046: ecParams);
047:
048: mod_p = new BigInteger(
049: "115792089237316195423570985008687907853269984665640564039457584007913129639319");
050: mod_q = new BigInteger(
051: "115792089237316195423570985008687907853073762908499243225378155805079068850323");
052:
053: curve = new ECCurve.Fp(
054: mod_p, // p
055: new BigInteger(
056: "115792089237316195423570985008687907853269984665640564039457584007913129639316"),
057: new BigInteger("166"));
058:
059: ecParams = new ECDomainParameters(
060: curve,
061: new ECPoint.Fp(curve,
062: new ECFieldElement.Fp(curve.getQ(),
063: new BigInteger("1")), // x
064: new ECFieldElement.Fp(
065: curve.getQ(),
066: new BigInteger(
067: "64033881142927202683649881450433473985931760268884941288852745803908878638612"))), // y
068: mod_q);
069:
070: params
071: .put(
072: CryptoProObjectIdentifiers.gostR3410_2001_CryptoPro_XchA,
073: ecParams);
074:
075: mod_p = new BigInteger(
076: "57896044618658097711785492504343953926634992332820282019728792003956564823193"); //p
077: mod_q = new BigInteger(
078: "57896044618658097711785492504343953927102133160255826820068844496087732066703"); //q
079:
080: curve = new ECCurve.Fp(
081: mod_p, // p
082: new BigInteger(
083: "57896044618658097711785492504343953926634992332820282019728792003956564823190"), // a
084: new BigInteger(
085: "28091019353058090096996979000309560759124368558014865957655842872397301267595")); // b
086:
087: ecParams = new ECDomainParameters(
088: curve,
089: new ECPoint.Fp(curve,
090: new ECFieldElement.Fp(mod_p,
091: new BigInteger("1")), // x
092: new ECFieldElement.Fp(
093: mod_p,
094: new BigInteger(
095: "28792665814854611296992347458380284135028636778229113005756334730996303888124"))), // y
096: mod_q); // q
097:
098: params.put(
099: CryptoProObjectIdentifiers.gostR3410_2001_CryptoPro_B,
100: ecParams);
101:
102: mod_p = new BigInteger(
103: "70390085352083305199547718019018437841079516630045180471284346843705633502619");
104: mod_q = new BigInteger(
105: "70390085352083305199547718019018437840920882647164081035322601458352298396601");
106:
107: curve = new ECCurve.Fp(
108: mod_p, // p
109: new BigInteger(
110: "70390085352083305199547718019018437841079516630045180471284346843705633502616"),
111: new BigInteger("32858"));
112:
113: ecParams = new ECDomainParameters(
114: curve,
115: new ECPoint.Fp(
116: curve,
117: new ECFieldElement.Fp(mod_p,
118: new BigInteger("0")),
119: new ECFieldElement.Fp(
120: mod_p,
121: new BigInteger(
122: "29818893917731240733471273240314769927240550812383695689146495261604565990247"))),
123: mod_q);
124:
125: params
126: .put(
127: CryptoProObjectIdentifiers.gostR3410_2001_CryptoPro_XchB,
128: ecParams);
129:
130: mod_p = new BigInteger(
131: "70390085352083305199547718019018437841079516630045180471284346843705633502619"); //p
132: mod_q = new BigInteger(
133: "70390085352083305199547718019018437840920882647164081035322601458352298396601"); //q
134: curve = new ECCurve.Fp(
135: mod_p, // p
136: new BigInteger(
137: "70390085352083305199547718019018437841079516630045180471284346843705633502616"), // a
138: new BigInteger("32858")); // b
139:
140: ecParams = new ECDomainParameters(
141: curve,
142: new ECPoint.Fp(curve,
143: new ECFieldElement.Fp(mod_p,
144: new BigInteger("0")), // x
145: new ECFieldElement.Fp(
146: mod_p,
147: new BigInteger(
148: "29818893917731240733471273240314769927240550812383695689146495261604565990247"))), // y
149: mod_q); // q
150:
151: params.put(
152: CryptoProObjectIdentifiers.gostR3410_2001_CryptoPro_C,
153: ecParams);
154:
155: objIds.put("GostR3410-2001-CryptoPro-A",
156: CryptoProObjectIdentifiers.gostR3410_2001_CryptoPro_A);
157: objIds.put("GostR3410-2001-CryptoPro-B",
158: CryptoProObjectIdentifiers.gostR3410_2001_CryptoPro_B);
159: objIds.put("GostR3410-2001-CryptoPro-C",
160: CryptoProObjectIdentifiers.gostR3410_2001_CryptoPro_C);
161: objIds
162: .put(
163: "GostR3410-2001-CryptoPro-XchA",
164: CryptoProObjectIdentifiers.gostR3410_2001_CryptoPro_XchA);
165: objIds
166: .put(
167: "GostR3410-2001-CryptoPro-XchB",
168: CryptoProObjectIdentifiers.gostR3410_2001_CryptoPro_XchB);
169:
170: names.put(
171: CryptoProObjectIdentifiers.gostR3410_2001_CryptoPro_A,
172: "GostR3410-2001-CryptoPro-A");
173: names.put(
174: CryptoProObjectIdentifiers.gostR3410_2001_CryptoPro_B,
175: "GostR3410-2001-CryptoPro-B");
176: names.put(
177: CryptoProObjectIdentifiers.gostR3410_2001_CryptoPro_C,
178: "GostR3410-2001-CryptoPro-C");
179: names
180: .put(
181: CryptoProObjectIdentifiers.gostR3410_2001_CryptoPro_XchA,
182: "GostR3410-2001-CryptoPro-XchA");
183: names
184: .put(
185: CryptoProObjectIdentifiers.gostR3410_2001_CryptoPro_XchB,
186: "GostR3410-2001-CryptoPro-XchB");
187: }
188:
189: /**
190: * return the ECDomainParameters object for the given OID, null if it
191: * isn't present.
192: *
193: * @param oid an object identifier representing a named parameters, if present.
194: */
195: public static ECDomainParameters getByOID(DERObjectIdentifier oid) {
196: return (ECDomainParameters) params.get(oid);
197: }
198:
199: /**
200: * returns an enumeration containing the name strings for parameters
201: * contained in this structure.
202: */
203: public static Enumeration getNames() {
204: return objIds.keys();
205: }
206:
207: public static ECDomainParameters getByName(String name) {
208: DERObjectIdentifier oid = (DERObjectIdentifier) objIds
209: .get(name);
210:
211: if (oid != null) {
212: return (ECDomainParameters) params.get(oid);
213: }
214:
215: return null;
216: }
217:
218: /**
219: * return the named curve name represented by the given object identifier.
220: */
221: public static String getName(DERObjectIdentifier oid) {
222: return (String) names.get(oid);
223: }
224:
225: public static DERObjectIdentifier getOID(String name) {
226: return (DERObjectIdentifier) objIds.get(name);
227: }
228: }
|