Skip to content

Commit 13a78e2

Browse files
committed
Test for BigIntegerScalarOps.reduce()
1 parent 23d5126 commit 13a78e2

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
*
3+
*/
4+
package net.i2p.crypto.eddsa.math.bigint;
5+
6+
import static org.hamcrest.Matchers.*;
7+
import static org.junit.Assert.*;
8+
9+
import java.math.BigInteger;
10+
11+
import net.i2p.crypto.eddsa.Utils;
12+
import net.i2p.crypto.eddsa.math.Field;
13+
import net.i2p.crypto.eddsa.math.ScalarOps;
14+
import net.i2p.crypto.eddsa.spec.EdDSANamedCurveSpec;
15+
import net.i2p.crypto.eddsa.spec.EdDSANamedCurveTable;
16+
17+
import org.junit.Test;
18+
19+
/**
20+
* @author str4d
21+
*
22+
*/
23+
public class BigIntegerScalarOpsTest {
24+
25+
static final EdDSANamedCurveSpec ed25519 = EdDSANamedCurveTable.getByName("ed25519-sha-512");
26+
static final Field ed25519Field = ed25519.getCurve().getField();
27+
28+
/**
29+
* Test method for {@link net.i2p.crypto.eddsa.math.bigint.BigIntegerScalarOps#reduce(byte[])}.
30+
*/
31+
@Test
32+
public void testReduce() {
33+
ScalarOps sc = new BigIntegerScalarOps(ed25519Field,
34+
new BigIntegerFieldElement(ed25519Field,
35+
new BigInteger("5")));
36+
assertThat(sc.reduce(new byte[] {7}),
37+
is(equalTo(Utils.hexToBytes("0200000000000000000000000000000000000000000000000000000000000000"))));
38+
39+
ScalarOps sc2 = new BigIntegerScalarOps(ed25519Field,
40+
new BigIntegerFieldElement(ed25519Field,
41+
new BigInteger("7237005577332262213973186563042994240857116359379907606001950938285454250989")));
42+
// Example from test case 1
43+
byte[] r = Utils.hexToBytes("b6b19cd8e0426f5983fa112d89a143aa97dab8bc5deb8d5b6253c928b65272f4044098c2a990039cde5b6a4818df0bfb6e40dc5dee54248032962323e701352d");
44+
assertThat(sc2.reduce(r), is(equalTo(Utils.hexToBytes("f38907308c893deaf244787db4af53682249107418afc2edc58f75ac58a07404"))));
45+
}
46+
47+
/**
48+
* Test method for {@link net.i2p.crypto.eddsa.math.bigint.BigIntegerScalarOps#multiplyAndAdd(byte[], byte[], byte[])}.
49+
*/
50+
@Test
51+
public void testMultiplyAndAdd() {
52+
fail("Not yet implemented");
53+
}
54+
55+
}

0 commit comments

Comments
 (0)