Skip to content
This repository was archived by the owner on May 25, 2021. It is now read-only.

Commit eadb4da

Browse files
committed
Add a jjs runnable JavaScript test script to ease testing whether native
library is loaded on a specific platform. Signed-off-by: Haochen Xie <haochen@xie.name>
1 parent 32762a8 commit eadb4da

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

src/test/js/scryptSpeed.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* Example command for running this testing utility:
3+
*
4+
* <pre>
5+
* jjs -cp ~/.m2/repository/commons-codec/commons-codec/1.10/commons-codec-1.10.jar:target/scrypt-1.4.0.jar scryptTimer.js
6+
* </pre>
7+
*
8+
* If you don't have commons-codec, use the following command to download with Maven:
9+
*
10+
* <pre>
11+
* mvn dependency:get -Dartifact=commons-codec:commons-codec:1.10
12+
* </pre>
13+
*
14+
*/
15+
16+
var SCrypt = com.lambdaworks.crypto.SCrypt;
17+
var System = java.lang.System;
18+
var Hex = org.apache.commons.codec.binary.Hex;
19+
20+
var f = Hex.class.getClassLoader().loadClass("com.lambdaworks.crypto.SCrypt").getDeclaredField("native_library_loaded");
21+
f.setAccessible(true);
22+
var native = f.get(null);
23+
System.out.println("Using " + (native ? "Native" : "Java") + " scrypt implementation." );
24+
25+
var startTs = System.currentTimeMillis();
26+
27+
var P, S, N, r, p, dkLen;
28+
var expected, actual;
29+
30+
P = "pleaseletmein".getBytes("UTF-8");
31+
S = "SodiumChloride".getBytes("UTF-8");
32+
N = 1048576;
33+
r = 8;
34+
p = 1;
35+
dkLen = 64;
36+
expected = "2101cb9b6a511aaeaddbbe09cf70f881ec568d574a2ffd4dabe5ee9820adaa478e56fd8f4ba5d09ffa1c6d927c40f4c337304049e8a952fbcbf45c6fa77a41a4";
37+
38+
actual = SCrypt.scrypt(P, S, N, r, p, dkLen);
39+
actual = Hex.encodeHexString(actual);
40+
41+
var endTs = System.currentTimeMillis();
42+
43+
System.out.println("expect: " + expected);
44+
System.out.println("actual: " + actual);
45+
System.out.println("Time: " + (endTs - startTs) / 1000 + " sec");

0 commit comments

Comments
 (0)