@@ -12,13 +12,15 @@ public class DSTU4145NamedCurves
1212{
1313 private static final BigInteger ZERO = BigInteger .valueOf (0 );
1414 private static final BigInteger ONE = BigInteger .valueOf (1 );
15+ private static final BigInteger TWO = BigInteger .valueOf (2 );
16+ private static final BigInteger FOUR = BigInteger .valueOf (4 );
1517
16- static final ECDomainParameters [] params = new ECDomainParameters [10 ];
17- static final ASN1ObjectIdentifier [] oids = new ASN1ObjectIdentifier [10 ];
18+ private static final ECDomainParameters [] DOMAIN_PARAMETERS = new ECDomainParameters [10 ];
19+ private static final ASN1ObjectIdentifier [] OIDS = new ASN1ObjectIdentifier [10 ];
1820
1921 //All named curves have the following oid format: 1.2.804.2.1.1.1.1.3.1.1.2.X
2022 //where X is the curve number 0-9
21- static final String oidBase = UAObjectIdentifiers .dstu4145le .getId () + ".2." ;
23+ private static final ASN1ObjectIdentifier OID_BASE = UAObjectIdentifiers .dstu4145le .branch ( "2" ) ;
2224
2325 private static ECPoint configureBasepoint (ECCurve curve , BigInteger x , BigInteger y )
2426 {
@@ -42,16 +44,16 @@ private static ECPoint configureBasepoint(ECCurve curve, BigInteger x, BigIntege
4244 n_s [9 ] = new BigInteger ("3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBA3175458009A8C0A724F02F81AA8A1FCBAF80D90C7A95110504CF" , 16 );
4345
4446 BigInteger [] h_s = new BigInteger [10 ];
45- h_s [0 ] = BigInteger . valueOf ( 2 ) ;
46- h_s [1 ] = BigInteger . valueOf ( 2 ) ;
47- h_s [2 ] = BigInteger . valueOf ( 4 ) ;
48- h_s [3 ] = BigInteger . valueOf ( 2 ) ;
49- h_s [4 ] = BigInteger . valueOf ( 2 ) ;
50- h_s [5 ] = BigInteger . valueOf ( 2 ) ;
51- h_s [6 ] = BigInteger . valueOf ( 4 ) ;
52- h_s [7 ] = BigInteger . valueOf ( 2 ) ;
53- h_s [8 ] = BigInteger . valueOf ( 2 ) ;
54- h_s [9 ] = BigInteger . valueOf ( 2 ) ;
47+ h_s [0 ] = TWO ;
48+ h_s [1 ] = TWO ;
49+ h_s [2 ] = FOUR ;
50+ h_s [3 ] = TWO ;
51+ h_s [4 ] = TWO ;
52+ h_s [5 ] = TWO ;
53+ h_s [6 ] = FOUR ;
54+ h_s [7 ] = TWO ;
55+ h_s [8 ] = TWO ;
56+ h_s [9 ] = TWO ;
5557
5658 ECCurve .F2m [] curves = new ECCurve .F2m [10 ];
5759 curves [0 ] = new ECCurve .F2m (163 , 3 , 6 , 7 , ONE , new BigInteger ("5FF6108462A2DC8210AB403925E638A19C1455D21" , 16 ), n_s [0 ], h_s [0 ]);
@@ -77,14 +79,10 @@ private static ECPoint configureBasepoint(ECCurve curve, BigInteger x, BigIntege
7779 points [8 ] = configureBasepoint (curves [8 ], new BigInteger ("324A6EDDD512F08C49A99AE0D3F961197A76413E7BE81A400CA681E09639B5FE12E59A109F78BF4A373541B3B9A1" , 16 ), new BigInteger ("1AB597A5B4477F59E39539007C7F977D1A567B92B043A49C6B61984C3FE3481AAF454CD41BA1F051626442B3C10" , 16 ));
7880 points [9 ] = configureBasepoint (curves [9 ], new BigInteger ("1A62BA79D98133A16BBAE7ED9A8E03C32E0824D57AEF72F88986874E5AAE49C27BED49A2A95058068426C2171E99FD3B43C5947C857D" , 16 ), new BigInteger ("70B5E1E14031C1F70BBEFE96BDDE66F451754B4CA5F48DA241F331AA396B8D1839A855C1769B1EA14BA53308B5E2723724E090E02DB9" , 16 ));
7981
80- for (int i = 0 ; i < params . length ; i ++)
82+ for (int i = 0 ; i < 10 ; i ++)
8183 {
82- params [i ] = new ECDomainParameters (curves [i ], points [i ], n_s [i ], h_s [i ]);
83- }
84-
85- for (int i = 0 ; i < oids .length ; i ++)
86- {
87- oids [i ] = new ASN1ObjectIdentifier (oidBase + i );
84+ DOMAIN_PARAMETERS [i ] = new ECDomainParameters (curves [i ], points [i ], n_s [i ], h_s [i ]);
85+ OIDS [i ] = OID_BASE .branch ("" + i );
8886 }
8987 }
9088
@@ -94,7 +92,9 @@ private static ECPoint configureBasepoint(ECCurve curve, BigInteger x, BigIntege
9492 */
9593 public static ASN1ObjectIdentifier [] getOIDs ()
9694 {
97- return oids ;
95+ ASN1ObjectIdentifier [] result = new ASN1ObjectIdentifier [OIDS .length ];
96+ System .arraycopy (OIDS , 0 , result , 0 , OIDS .length );
97+ return result ;
9898 }
9999
100100 /**
@@ -103,11 +103,15 @@ public static ASN1ObjectIdentifier[] getOIDs()
103103 */
104104 public static ECDomainParameters getByOID (ASN1ObjectIdentifier oid )
105105 {
106- String oidStr = oid .getId ();
107- if (oidStr .startsWith (oidBase ))
106+ if (oid .on (OID_BASE ))
108107 {
109- int index = Integer .parseInt (oidStr .substring (oidStr .lastIndexOf ('.' ) + 1 ));
110- return (index >= 0 && index < params .length ) ? params [index ] : null ;
108+ for (int i = 0 ; i < 10 ; ++i )
109+ {
110+ if (OIDS [i ].equals (oid ))
111+ {
112+ return DOMAIN_PARAMETERS [i ];
113+ }
114+ }
111115 }
112116 return null ;
113117 }
0 commit comments