1
- using System . Collections . Generic ;
1
+ using System ;
2
+ using System . Collections ;
2
3
using System . IO ;
3
4
using System . Text . RegularExpressions ;
4
5
using NUnit . Framework ;
6
+ using Org . BouncyCastle . Asn1 . X9 ;
5
7
using Org . BouncyCastle . Math ;
8
+ using Org . BouncyCastle . Math . EC ;
6
9
using Org . BouncyCastle . Utilities . Test ;
7
10
8
11
namespace Org . BouncyCastle . Crypto . Tests
@@ -14,19 +17,20 @@ public class NistEccTest : SimpleTest
14
17
15
18
public override void PerformTest ( )
16
19
{
17
- foreach ( var testVector in CollectTestVectors ( ) )
20
+ foreach ( object [ ] testVector in CollectTestVectors ( ) )
18
21
{
19
22
TestMultiply (
20
- curve : testVector [ 0 ] as string ,
21
- k : testVector [ 1 ] as BigInteger ,
22
- expectedX : testVector [ 2 ] as BigInteger ,
23
- expectedY : testVector [ 3 ] as BigInteger
23
+ testVector [ 0 ] as string ,
24
+ testVector [ 1 ] as BigInteger ,
25
+ testVector [ 2 ] as BigInteger ,
26
+ testVector [ 3 ] as BigInteger
24
27
) ;
25
28
}
26
29
}
27
30
28
- public IEnumerable < object [ ] > CollectTestVectors ( )
31
+ public IEnumerable CollectTestVectors ( )
29
32
{
33
+ ArrayList testVectors = new ArrayList ( ) ;
30
34
string curve = null ;
31
35
BigInteger k = null ;
32
36
BigInteger x = null ;
@@ -37,12 +41,12 @@ public IEnumerable<object[]> CollectTestVectors()
37
41
string line ;
38
42
while ( null != ( line = r . ReadLine ( ) ) )
39
43
{
40
- var capture = new Regex ( @"^ ?(\w+):? =? ?(\w+)" , RegexOptions . Compiled ) ;
41
- var data = capture . Match ( line ) ;
44
+ Regex capture = new Regex ( @"^ ?(\w+):? =? ?(\w+)" , RegexOptions . Compiled ) ;
45
+ Match data = capture . Match ( line ) ;
42
46
43
47
if ( ! data . Success ) continue ;
44
- var nistKey = data . Groups [ 1 ] . Value ;
45
- var nistValue = data . Groups [ 2 ] . Value ;
48
+ string nistKey = data . Groups [ 1 ] . Value ;
49
+ string nistValue = data . Groups [ 2 ] . Value ;
46
50
switch ( nistKey )
47
51
{
48
52
case "Curve" :
@@ -62,22 +66,24 @@ public IEnumerable<object[]> CollectTestVectors()
62
66
63
67
if ( null != curve && null != k && null != x && null != y )
64
68
{
65
- yield return new object [ ] { curve , k , x , y } ;
69
+ testVectors . Add ( new object [ ] { curve , k , x , y } ) ;
66
70
k = null ;
67
71
x = null ;
68
72
y = null ;
69
73
}
70
74
}
71
75
}
76
+
77
+ return testVectors ;
72
78
}
73
79
74
80
public void TestMultiply ( string curve , BigInteger k , BigInteger expectedX , BigInteger expectedY )
75
81
{
76
82
// Arrange
77
- var x9EcParameters = Asn1 . Nist . NistNamedCurves . GetByName ( curve ) ;
83
+ X9ECParameters x9EcParameters = Asn1 . Nist . NistNamedCurves . GetByName ( curve ) ;
78
84
79
85
// Act
80
- var ecPoint = x9EcParameters . G . Multiply ( k ) . Normalize ( ) ;
86
+ ECPoint ecPoint = x9EcParameters . G . Multiply ( k ) . Normalize ( ) ;
81
87
82
88
// Assert
83
89
IsEquals ( "Unexpected X Coordinate" , expectedX , ecPoint . AffineXCoord . ToBigInteger ( ) ) ;
0 commit comments