Skip to content

Commit bc886d8

Browse files
committed
jni Libsodium
1 parent 453abd0 commit bc886d8

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

‎build.gradle‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,15 @@ dependencies {
175175
compile 'org.eclipse.jetty:jetty-server:9.4.11.v20180605'
176176
compile 'org.eclipse.jetty:jetty-servlet:9.4.11.v20180605'
177177
compile 'com.alibaba:fastjson:1.2.47'
178-
compile group: 'org.apache.httpcomponents', name:'httpasyncclient', version:'4.1.1'
178+
compile group: 'org.apache.httpcomponents', name: 'httpasyncclient', version: '4.1.1'
179179
// end http
180180

181181
compile "io.vavr:vavr:0.9.2"
182182
compile group: 'org.pf4j', name: 'pf4j', version: '2.5.0'
183183

184-
185184
// for jna, zksark
186185
compile group: 'com.sun.jna', name: 'jna', version: '3.0.9'
186+
compile 'com.github.joshjdevl.libsodiumjni:libsodium-jni:2.0.1'
187187
}
188188

189189
check.dependsOn 'lint'

‎src/main/java/org/tron/common/zksnark/zen/utils/PRF.java‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package org.tron.common.zksnark.zen.utils;
22

3+
import org.libsodium.jni.NaCl;
4+
import org.libsodium.jni.Sodium;
35
import org.tron.common.zksnark.zen.Librustzcash;
4-
import org.tron.common.zksnark.zen.Libsodium;
5-
import org.tron.common.zksnark.zen.Libsodium.ILibsodium.crypto_generichash_blake2b_state;
66

77
public class PRF {
88

@@ -33,12 +33,17 @@ public static byte[] prfOvk(byte[] sk) {
3333
private static byte[] prfExpand(byte[] sk, byte t) {
3434
byte[] res = new byte[64];
3535
byte[] blob = new byte[33];
36-
36+
Sodium sodium = NaCl.sodium();
3737
System.arraycopy(sk, 0, blob, 0, 32);
3838
blob[32] = t;
39-
crypto_generichash_blake2b_state.ByReference state = new crypto_generichash_blake2b_state.ByReference();
40-
Libsodium.cryptoGenerichashBlake2bUpdate(state, blob, 33);
41-
Libsodium.cryptoGenerichashBlake2bFinal(state, res, 64);
39+
40+
byte[] state = new byte[Sodium.crypto_generichash_statebytes()];
41+
byte[] key = new byte[Sodium.crypto_generichash_keybytes()];
42+
43+
// Sodium.crypto_generichash_blake2b_init(state, key, 0, 32);
44+
Sodium.crypto_generichash_blake2b_update(state, blob, 33);
45+
Sodium.crypto_generichash_blake2b_final(state, res, 64);
46+
4247
return res;
4348
}
4449
}

0 commit comments

Comments
 (0)