1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
|
using System;
using System.Collections;
using Org.BouncyCastle.Asn1.Rosstandart;
using Org.BouncyCastle.Asn1.X9;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Math;
using Org.BouncyCastle.Math.EC;
using Org.BouncyCastle.Math.EC.Multiplier;
using Org.BouncyCastle.Utilities;
using Org.BouncyCastle.Utilities.Collections;
using Org.BouncyCastle.Utilities.Encoders;
namespace Org.BouncyCastle.Asn1.CryptoPro
{
/// <summary>
/// Table of the available named parameters for GOST 3410-2001 / 2012.
/// </summary>
public sealed class ECGost3410NamedCurves
{
private ECGost3410NamedCurves()
{
}
private static X9ECPoint ConfigureBasepoint(ECCurve curve, BigInteger x, BigInteger y)
{
ECPoint G = curve.CreatePoint(x, y);
WNafUtilities.ConfigureBasepoint(G);
return new X9ECPoint(G, false);
}
private static ECCurve ConfigureCurve(ECCurve curve)
{
return curve;
}
private static BigInteger FromHex(string hex)
{
return new BigInteger(1, Hex.DecodeStrict(hex));
}
/*
* GostR3410-2001-CryptoPro-A (and GostR3410-2001-CryptoPro-XchA)
*/
internal class Holder_gostR3410_2001_CryptoPro_A
: X9ECParametersHolder
{
private Holder_gostR3410_2001_CryptoPro_A() {}
internal static readonly X9ECParametersHolder Instance = new Holder_gostR3410_2001_CryptoPro_A();
protected override ECCurve CreateCurve()
{
BigInteger mod_p = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD97");
BigInteger mod_q = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF6C611070995AD10045841B09B761B893");
return ConfigureCurve(new FpCurve(
mod_p,
FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD94"),
FromHex("A6"),
mod_q, BigInteger.One));
}
protected override X9ECParameters CreateParameters()
{
byte[] S = null;
ECCurve curve = Curve;
X9ECPoint G = ConfigureBasepoint(curve,
BigInteger.One,
FromHex("8D91E471E0989CDA27DF505A453F2B7635294F2DDF23E3B122ACC99C9E9F1E14"));
return new X9ECParameters(curve, G, curve.Order, curve.Cofactor, S);
}
};
/*
* GostR3410-2001-CryptoPro-B
*/
internal class Holder_gostR3410_2001_CryptoPro_B
: X9ECParametersHolder
{
private Holder_gostR3410_2001_CryptoPro_B() {}
internal static readonly X9ECParametersHolder Instance = new Holder_gostR3410_2001_CryptoPro_B();
protected override ECCurve CreateCurve()
{
BigInteger mod_p = FromHex("8000000000000000000000000000000000000000000000000000000000000C99");
BigInteger mod_q = FromHex("800000000000000000000000000000015F700CFFF1A624E5E497161BCC8A198F");
return ConfigureCurve(new FpCurve(
mod_p,
FromHex("8000000000000000000000000000000000000000000000000000000000000C96"),
FromHex("3E1AF419A269A5F866A7D3C25C3DF80AE979259373FF2B182F49D4CE7E1BBC8B"),
mod_q, BigInteger.One));
}
protected override X9ECParameters CreateParameters()
{
byte[] S = null;
ECCurve curve = Curve;
X9ECPoint G = ConfigureBasepoint(curve,
BigInteger.One,
FromHex("3FA8124359F96680B83D1C3EB2C070E5C545C9858D03ECFB744BF8D717717EFC"));
return new X9ECParameters(curve, G, curve.Order, curve.Cofactor, S);
}
};
/*
* GostR3410-2001-CryptoPro-C
*/
internal class Holder_gostR3410_2001_CryptoPro_C
: X9ECParametersHolder
{
private Holder_gostR3410_2001_CryptoPro_C() {}
internal static readonly X9ECParametersHolder Instance = new Holder_gostR3410_2001_CryptoPro_C();
protected override ECCurve CreateCurve()
{
BigInteger mod_p = FromHex("9B9F605F5A858107AB1EC85E6B41C8AACF846E86789051D37998F7B9022D759B");
BigInteger mod_q = FromHex("9B9F605F5A858107AB1EC85E6B41C8AA582CA3511EDDFB74F02F3A6598980BB9");
return ConfigureCurve(new FpCurve(
mod_p,
FromHex("9B9F605F5A858107AB1EC85E6B41C8AACF846E86789051D37998F7B9022D7598"),
FromHex("805A"),
mod_q, BigInteger.One));
}
protected override X9ECParameters CreateParameters()
{
byte[] S = null;
ECCurve curve = Curve;
X9ECPoint G = ConfigureBasepoint(curve,
BigInteger.Zero,
FromHex("41ECE55743711A8C3CBF3783CD08C0EE4D4DC440D4641A8F366E550DFDB3BB67"));
return new X9ECParameters(curve, G, curve.Order, curve.Cofactor, S);
}
};
/*
* GostR3410-2001-CryptoPro-XchB
*/
internal class Holder_gostR3410_2001_CryptoPro_XchB
: X9ECParametersHolder
{
private Holder_gostR3410_2001_CryptoPro_XchB() {}
internal static readonly X9ECParametersHolder Instance = new Holder_gostR3410_2001_CryptoPro_XchB();
protected override ECCurve CreateCurve()
{
BigInteger mod_p = FromHex("9B9F605F5A858107AB1EC85E6B41C8AACF846E86789051D37998F7B9022D759B");
BigInteger mod_q = FromHex("9B9F605F5A858107AB1EC85E6B41C8AA582CA3511EDDFB74F02F3A6598980BB9");
return ConfigureCurve(new FpCurve(
mod_p,
FromHex("9B9F605F5A858107AB1EC85E6B41C8AACF846E86789051D37998F7B9022D7598"),
FromHex("805A"),
mod_q, BigInteger.One));
}
protected override X9ECParameters CreateParameters()
{
byte[] S = null;
ECCurve curve = Curve;
X9ECPoint G = ConfigureBasepoint(curve,
BigInteger.Zero,
FromHex("41ECE55743711A8C3CBF3783CD08C0EE4D4DC440D4641A8F366E550DFDB3BB67"));
return new X9ECParameters(curve, G, curve.Order, curve.Cofactor, S);
}
};
/*
* Tc26-Gost-3410-12-256-paramSetA
*/
internal class Holder_id_tc26_gost_3410_12_256_paramSetA
: X9ECParametersHolder
{
private Holder_id_tc26_gost_3410_12_256_paramSetA() {}
internal static readonly X9ECParametersHolder Instance = new Holder_id_tc26_gost_3410_12_256_paramSetA();
protected override ECCurve CreateCurve()
{
BigInteger mod_p = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD97");
BigInteger mod_q = FromHex("400000000000000000000000000000000FD8CDDFC87B6635C115AF556C360C67");
return ConfigureCurve(new FpCurve(
mod_p,
FromHex("C2173F1513981673AF4892C23035A27CE25E2013BF95AA33B22C656F277E7335"),
FromHex("295F9BAE7428ED9CCC20E7C359A9D41A22FCCD9108E17BF7BA9337A6F8AE9513"),
mod_q, BigInteger.Four));
}
protected override X9ECParameters CreateParameters()
{
byte[] S = null;
ECCurve curve = Curve;
X9ECPoint G = ConfigureBasepoint(curve,
FromHex("91E38443A5E82C0D880923425712B2BB658B9196932E02C78B2582FE742DAA28"),
FromHex("32879423AB1A0375895786C4BB46E9565FDE0B5344766740AF268ADB32322E5C"));
return new X9ECParameters(curve, G, curve.Order, curve.Cofactor, S);
}
};
/*
* Tc26-Gost-3410-12-512-paramSetA
*/
internal class Holder_id_tc26_gost_3410_12_512_paramSetA
: X9ECParametersHolder
{
private Holder_id_tc26_gost_3410_12_512_paramSetA() {}
internal static readonly X9ECParametersHolder Instance = new Holder_id_tc26_gost_3410_12_512_paramSetA();
protected override ECCurve CreateCurve()
{
BigInteger mod_p = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFDC7");
BigInteger mod_q = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF27E69532F48D89116FF22B8D4E0560609B4B38ABFAD2B85DCACDB1411F10B275");
return ConfigureCurve(new FpCurve(
mod_p,
FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFDC4"),
FromHex("E8C2505DEDFC86DDC1BD0B2B6667F1DA34B82574761CB0E879BD081CFD0B6265EE3CB090F30D27614CB4574010DA90DD862EF9D4EBEE4761503190785A71C760"),
mod_q, BigInteger.One));
}
protected override X9ECParameters CreateParameters()
{
byte[] S = null;
ECCurve curve = Curve;
X9ECPoint G = ConfigureBasepoint(curve,
BigInteger.Three,
FromHex("7503CFE87A836AE3A61B8816E25450E6CE5E1C93ACF1ABC1778064FDCBEFA921DF1626BE4FD036E93D75E6A50E3A41E98028FE5FC235F5B889A589CB5215F2A4"));
return new X9ECParameters(curve, G, curve.Order, curve.Cofactor, S);
}
};
/*
* Tc26-Gost-3410-12-512-paramSetB
*/
internal class Holder_id_tc26_gost_3410_12_512_paramSetB
: X9ECParametersHolder
{
private Holder_id_tc26_gost_3410_12_512_paramSetB() {}
internal static readonly X9ECParametersHolder Instance = new Holder_id_tc26_gost_3410_12_512_paramSetB();
protected override ECCurve CreateCurve()
{
BigInteger mod_p = FromHex("8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006F");
BigInteger mod_q = FromHex("800000000000000000000000000000000000000000000000000000000000000149A1EC142565A545ACFDB77BD9D40CFA8B996712101BEA0EC6346C54374F25BD");
return ConfigureCurve(new FpCurve(
mod_p,
FromHex("8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006C"),
FromHex("687D1B459DC841457E3E06CF6F5E2517B97C7D614AF138BCBF85DC806C4B289F3E965D2DB1416D217F8B276FAD1AB69C50F78BEE1FA3106EFB8CCBC7C5140116"),
mod_q, BigInteger.One));
}
protected override X9ECParameters CreateParameters()
{
byte[] S = null;
ECCurve curve = Curve;
X9ECPoint G = ConfigureBasepoint(curve,
BigInteger.Two,
FromHex("1A8F7EDA389B094C2C071E3647A8940F3C123B697578C213BE6DD9E6C8EC7335DCB228FD1EDF4A39152CBCAAF8C0398828041055F94CEEEC7E21340780FE41BD"));
return new X9ECParameters(curve, G, curve.Order, curve.Cofactor, S);
}
};
/*
* Tc26-Gost-3410-12-512-paramSetC
*/
internal class Holder_id_tc26_gost_3410_12_512_paramSetC
: X9ECParametersHolder
{
private Holder_id_tc26_gost_3410_12_512_paramSetC() {}
internal static readonly X9ECParametersHolder Instance = new Holder_id_tc26_gost_3410_12_512_paramSetC();
protected override ECCurve CreateCurve()
{
BigInteger mod_p = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFDC7");
BigInteger mod_q = FromHex("3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC98CDBA46506AB004C33A9FF5147502CC8EDA9E7A769A12694623CEF47F023ED");
return ConfigureCurve(new FpCurve(
mod_p,
FromHex("DC9203E514A721875485A529D2C722FB187BC8980EB866644DE41C68E143064546E861C0E2C9EDD92ADE71F46FCF50FF2AD97F951FDA9F2A2EB6546F39689BD3"),
FromHex("B4C4EE28CEBC6C2C8AC12952CF37F16AC7EFB6A9F69F4B57FFDA2E4F0DE5ADE038CBC2FFF719D2C18DE0284B8BFEF3B52B8CC7A5F5BF0A3C8D2319A5312557E1"),
mod_q, BigInteger.Four));
}
protected override X9ECParameters CreateParameters()
{
byte[] S = null;
ECCurve curve = Curve;
X9ECPoint G = ConfigureBasepoint(curve,
FromHex("E2E31EDFC23DE7BDEBE241CE593EF5DE2295B7A9CBAEF021D385F7074CEA043AA27272A7AE602BF2A7B9033DB9ED3610C6FB85487EAE97AAC5BC7928C1950148"),
FromHex("F5CE40D95B5EB899ABBCCFF5911CB8577939804D6527378B8C108C3D2090FF9BE18E2D33E3021ED2EF32D85822423B6304F726AA854BAE07D0396E9A9ADDC40F"));
return new X9ECParameters(curve, G, curve.Order, curve.Cofactor, S);
}
};
private static readonly IDictionary objIds = Platform.CreateHashtable();
private static readonly IDictionary curves = Platform.CreateHashtable();
private static readonly IDictionary names = Platform.CreateHashtable();
private static void DefineCurve(string name, DerObjectIdentifier oid, X9ECParametersHolder holder)
{
objIds.Add(name, oid);
names.Add(oid, name);
curves.Add(oid, holder);
}
static ECGost3410NamedCurves()
{
DefineCurve("GostR3410-2001-CryptoPro-A", CryptoProObjectIdentifiers.GostR3410x2001CryptoProA,
Holder_gostR3410_2001_CryptoPro_A.Instance);
DefineCurve("GostR3410-2001-CryptoPro-B", CryptoProObjectIdentifiers.GostR3410x2001CryptoProB,
Holder_gostR3410_2001_CryptoPro_B.Instance);
DefineCurve("GostR3410-2001-CryptoPro-C", CryptoProObjectIdentifiers.GostR3410x2001CryptoProC,
Holder_gostR3410_2001_CryptoPro_C.Instance);
DefineCurve("GostR3410-2001-CryptoPro-XchA", CryptoProObjectIdentifiers.GostR3410x2001CryptoProXchA,
Holder_gostR3410_2001_CryptoPro_A.Instance);
DefineCurve("GostR3410-2001-CryptoPro-XchB", CryptoProObjectIdentifiers.GostR3410x2001CryptoProXchB,
Holder_gostR3410_2001_CryptoPro_XchB.Instance);
DefineCurve("Tc26-Gost-3410-12-256-paramSetA", RosstandartObjectIdentifiers.id_tc26_gost_3410_12_256_paramSetA,
Holder_id_tc26_gost_3410_12_256_paramSetA.Instance);
DefineCurve("Tc26-Gost-3410-12-512-paramSetA", RosstandartObjectIdentifiers.id_tc26_gost_3410_12_512_paramSetA,
Holder_id_tc26_gost_3410_12_512_paramSetA.Instance);
DefineCurve("Tc26-Gost-3410-12-512-paramSetB", RosstandartObjectIdentifiers.id_tc26_gost_3410_12_512_paramSetB,
Holder_id_tc26_gost_3410_12_512_paramSetB.Instance);
DefineCurve("Tc26-Gost-3410-12-512-paramSetC", RosstandartObjectIdentifiers.id_tc26_gost_3410_12_512_paramSetC,
Holder_id_tc26_gost_3410_12_512_paramSetC.Instance);
}
public static X9ECParameters GetByNameX9(string name)
{
DerObjectIdentifier oid = GetOid(name);
return oid == null ? null : GetByOidX9(oid);
}
public static X9ECParametersHolder GetByNameLazy(string name)
{
DerObjectIdentifier oid = GetOid(name);
return oid == null ? null : GetByOidLazy(oid);
}
public static X9ECParameters GetByOidX9(DerObjectIdentifier oid)
{
X9ECParametersHolder holder = GetByOidLazy(oid);
return holder == null ? null : holder.Parameters;
}
public static X9ECParametersHolder GetByOidLazy(DerObjectIdentifier oid)
{
return (X9ECParametersHolder)curves[oid];
}
public static DerObjectIdentifier GetOid(
string name)
{
return (DerObjectIdentifier)objIds[name];
}
/**
* return the named curve name represented by the given object identifier.
*/
public static string GetName(
DerObjectIdentifier oid)
{
return (string)names[oid];
}
/**
* returns an enumeration containing the name strings for curves
* contained in this structure.
*/
public static IEnumerable Names
{
get { return new EnumerableProxy(names.Values); }
}
}
}
|