Skip to content

Commit 6990319

Browse files
authored
add oprf base mode tests for jvm (#53)
1 parent 5a85114 commit 6990319

File tree

4 files changed

+179
-0
lines changed

4 files changed

+179
-0
lines changed

.github/workflows/macos.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,23 @@ jobs:
3333
run: bash <(curl -Ls https://coverage.codacy.com/get.sh) report -l C -r ./build-cov/ccov/coverage.lcov
3434
env:
3535
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
36+
37+
- name: c build
38+
run: |
39+
./build-c.sh
40+
otool -L build/libecc.dylib
41+
42+
- name: jvm tests
43+
run: |
44+
otool -L bindings/jvm/libecc-jvm.dylib
45+
cd bindings/jvm
46+
./gradlew test
47+
cd ../..
48+
49+
- uses: actions/upload-artifact@v2
50+
with:
51+
name: ecc-macos
52+
path: |
53+
build/libecc.dylib
54+
build/libecc-jvm.dylib
55+
retention-days: 5
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright (c) 2022, Alden Torres
3+
*
4+
* Licensed under the terms of the MIT license.
5+
* Copy of the license at https://opensource.org/licenses/MIT
6+
*/
7+
8+
package org.ssohub.crypto.ecc;
9+
10+
import static org.ssohub.crypto.ecc.libecc.*;
11+
12+
/**
13+
* @author aldenml
14+
*/
15+
public final class Oprf {
16+
17+
private Oprf() {
18+
}
19+
20+
public static byte[] oprf_ristretto255_sha512_Evaluate(
21+
byte[] skS,
22+
byte[] blindedElement,
23+
byte[] info
24+
) {
25+
if (info == null)
26+
info = new byte[0];
27+
28+
byte[] evaluatedElement = new byte[ecc_oprf_ristretto255_sha512_ELEMENTSIZE];
29+
ecc_oprf_ristretto255_sha512_Evaluate(
30+
evaluatedElement,
31+
skS,
32+
blindedElement,
33+
info, info.length
34+
);
35+
36+
return evaluatedElement;
37+
}
38+
39+
public static byte[] oprf_ristretto255_sha512_BlindWithScalar(
40+
byte[] input,
41+
byte[] blind
42+
) {
43+
byte[] blindedElement = new byte[ecc_oprf_ristretto255_sha512_ELEMENTSIZE];
44+
ecc_oprf_ristretto255_sha512_BlindWithScalar(
45+
blindedElement,
46+
input, input.length,
47+
blind,
48+
ecc_oprf_ristretto255_sha512_MODE_BASE
49+
);
50+
51+
return blindedElement;
52+
}
53+
54+
public static byte[] oprf_ristretto255_sha512_Finalize(
55+
byte[] input,
56+
byte[] blind,
57+
byte[] evaluatedElement,
58+
byte[] info
59+
) {
60+
if (info == null)
61+
info = new byte[0];
62+
63+
byte[] output = new byte[ecc_oprf_ristretto255_sha512_Nh];
64+
ecc_oprf_ristretto255_sha512_Finalize(
65+
output,
66+
input, input.length,
67+
blind,
68+
evaluatedElement,
69+
info, info.length
70+
);
71+
72+
return output;
73+
}
74+
}

bindings/jvm/src/main/java/org/ssohub/crypto/ecc/Util.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public static byte[] hex2bin(String hex) {
6767
int digit = Character.digit(hex.charAt(j), 16);
6868
int f = digit << 4;
6969
j++;
70+
digit = Character.digit(hex.charAt(j), 16);
7071
f = f | digit;
7172
j++;
7273
out[i] = (byte) (f & 0xFF);
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright (c) 2022, Alden Torres
3+
*
4+
* Licensed under the terms of the MIT license.
5+
* Copy of the license at https://opensource.org/licenses/MIT
6+
*/
7+
8+
package org.ssohub.crypto.ecc;
9+
10+
import org.junit.jupiter.api.Test;
11+
12+
import static org.junit.jupiter.api.Assertions.assertEquals;
13+
import static org.ssohub.crypto.ecc.Util.bin2hex;
14+
import static org.ssohub.crypto.ecc.Util.hex2bin;
15+
16+
/**
17+
* @author aldenml
18+
*/
19+
public class OprfTest {
20+
21+
@Test
22+
void oprf_ristretto255_sha512_base_test1() {
23+
byte[] skSm = hex2bin("74db8e13d2c5148a1181d57cc06debd730da4df1978b72ac18bc48992a0d2c0f");
24+
byte[] input = hex2bin("00");
25+
byte[] info = hex2bin("7465737420696e666f");
26+
byte[] blind = hex2bin("c604c785ada70d77a5256ae21767de8c3304115237d262134f5e46e512cf8e03");
27+
28+
byte[] blindedElement = Oprf.oprf_ristretto255_sha512_BlindWithScalar(
29+
input,
30+
blind
31+
);
32+
33+
assertEquals("744441a5d3ee12571a84d34812443eba2b6521a47265ad655f01e759b3dd7d35", bin2hex(blindedElement));
34+
35+
byte[] evaluationElement = Oprf.oprf_ristretto255_sha512_Evaluate(
36+
skSm,
37+
blindedElement,
38+
info
39+
);
40+
41+
assertEquals("4254c503ee2013262473eec926b109b018d699b8dd954ee878bc17b159696353", bin2hex(evaluationElement));
42+
43+
byte[] output = Oprf.oprf_ristretto255_sha512_Finalize(
44+
input,
45+
blind,
46+
evaluationElement,
47+
info
48+
);
49+
50+
assertEquals("9aef8983b729baacb7ecf1be98d1276ca29e7d62dbf39bc595be018b66b199119f18579a9ae96a39d7d506c9e00f75b433a870d76ba755a3e7196911fff89ff3", bin2hex(output));
51+
}
52+
53+
@Test
54+
void oprf_ristretto255_sha512_base_test2() {
55+
byte[] skSm = hex2bin("74db8e13d2c5148a1181d57cc06debd730da4df1978b72ac18bc48992a0d2c0f");
56+
byte[] input = hex2bin("5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a");
57+
byte[] info = hex2bin("7465737420696e666f");
58+
byte[] blind = hex2bin("5ed895206bfc53316d307b23e46ecc6623afb3086da74189a416012be037e50b");
59+
60+
byte[] blindedElement = Oprf.oprf_ristretto255_sha512_BlindWithScalar(
61+
input,
62+
blind
63+
);
64+
65+
assertEquals("f4eeea4e1bcb2ec818ee2d5c1fcec56c24064a9ff4bea5b3dd6877800fc28e4d", bin2hex(blindedElement));
66+
67+
byte[] evaluationElement = Oprf.oprf_ristretto255_sha512_Evaluate(
68+
skSm,
69+
blindedElement,
70+
info
71+
);
72+
73+
assertEquals("185dae43b6209dacbc41a62fd4889700d11eeeff4e83ffbc72d54daee7e25659", bin2hex(evaluationElement));
74+
75+
byte[] output = Oprf.oprf_ristretto255_sha512_Finalize(
76+
input,
77+
blind,
78+
evaluationElement,
79+
info
80+
);
81+
82+
assertEquals("f556e2d83e576b4edc890472572d08f0d90d2ecc52a73b35b2a8416a72ff676549e3a83054fdf4fd16fe03e03bee7bb32cbd83c7ca212ea0d03b8996c2c268b2", bin2hex(output));
83+
}
84+
}

0 commit comments

Comments
 (0)