Skip to content

Commit 27202bf

Browse files
committed
Tests for ScalarOps.multiplyAndAdd()
1 parent 91cfaec commit 27202bf

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

test/net/i2p/crypto/eddsa/math/bigint/BigIntegerScalarOpsTest.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,19 @@ public void testReduce() {
4747
*/
4848
@Test
4949
public void testMultiplyAndAdd() {
50-
fail("Not yet implemented");
50+
ScalarOps sc = new BigIntegerScalarOps(ed25519Field,
51+
new BigInteger("5"));
52+
assertThat(sc.multiplyAndAdd(new byte[] {7}, new byte[] {2}, new byte[] {5}),
53+
is(equalTo(Utils.hexToBytes("0400000000000000000000000000000000000000000000000000000000000000"))));
54+
55+
ScalarOps sc2 = new BigIntegerScalarOps(ed25519Field,
56+
new BigInteger("7237005577332262213973186563042994240857116359379907606001950938285454250989"));
57+
// Example from test case 1
58+
byte[] h = Utils.hexToBytes("86eabc8e4c96193d290504e7c600df6cf8d8256131ec2c138a3e7e162e525404");
59+
byte[] a = Utils.hexToBytes("307c83864f2833cb427a2ef1c00a013cfdff2768d980c0a3a520f006904de94f");
60+
byte[] r = Utils.hexToBytes("f38907308c893deaf244787db4af53682249107418afc2edc58f75ac58a07404");
61+
byte[] S = Utils.hexToBytes("5fb8821590a33bacc61e39701cf9b46bd25bf5f0595bbe24655141438e7a100b");
62+
assertThat(sc2.multiplyAndAdd(h, a, r), is(equalTo(S)));
5163
}
5264

5365
}

test/net/i2p/crypto/eddsa/math/ed25519/Ed25519ScalarOpsTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ public void testReduce() {
3131
*/
3232
@Test
3333
public void testMultiplyAndAdd() {
34-
fail("Not yet implemented");
34+
ScalarOps sc = new Ed25519ScalarOps();
35+
// Example from test case 1
36+
byte[] h = Utils.hexToBytes("86eabc8e4c96193d290504e7c600df6cf8d8256131ec2c138a3e7e162e525404");
37+
byte[] a = Utils.hexToBytes("307c83864f2833cb427a2ef1c00a013cfdff2768d980c0a3a520f006904de94f");
38+
byte[] r = Utils.hexToBytes("f38907308c893deaf244787db4af53682249107418afc2edc58f75ac58a07404");
39+
byte[] S = Utils.hexToBytes("5fb8821590a33bacc61e39701cf9b46bd25bf5f0595bbe24655141438e7a100b");
40+
assertThat(sc.multiplyAndAdd(h, a, r), is(equalTo(S)));
3541
}
3642

3743
}

0 commit comments

Comments
 (0)