在 android 上加速 scrypt
Speeding up scrypt on android
我正在使用 scrypt 制作 Android 应用程序,计算哈希值需要很长时间。我是这样称呼它的:
String hash = Base64.encodeToString(SCrypt.scrypt("password".getBytes(), "salt".toString().getBytes(), 16384, 16, 2, 128), Base64.DEFAULT);
这就是我在 Gradle 中声明依赖关系的方式:
compile group: 'com.lambdaworks', name: 'scrypt', version: '1.4.0'
在我的 Nexus 6P 上计算哈希值需要将近一分钟的时间,这当然非常慢。有没有人知道如何让它更快?我对此很陌生,因此对它为什么这么慢以及如何加速它一无所知。
我认为 SCrypt.scrypt()
参数应该针对您的用例进行优化。
this answer and this slide p17
中的一些数字
(N = 2^14, r = 8, p = 1) for < 100ms (interactive use)
(N = 2^20, r = 8, p = 1) for < 5s (sensitive storage)
和N
、r
、p
的含义:
N: General work factor, iteration count.
r: blocksize in use for underlying hash; fine-tunes the relative memory-cost.
p: parallelization factor; fine-tunes the relative cpu-cost
所以如果你想要更少的时间,应该减少 N
。 r
和p
与硬件有关,需要更多运行环境动态调整。
我正在使用 scrypt 制作 Android 应用程序,计算哈希值需要很长时间。我是这样称呼它的:
String hash = Base64.encodeToString(SCrypt.scrypt("password".getBytes(), "salt".toString().getBytes(), 16384, 16, 2, 128), Base64.DEFAULT);
这就是我在 Gradle 中声明依赖关系的方式:
compile group: 'com.lambdaworks', name: 'scrypt', version: '1.4.0'
在我的 Nexus 6P 上计算哈希值需要将近一分钟的时间,这当然非常慢。有没有人知道如何让它更快?我对此很陌生,因此对它为什么这么慢以及如何加速它一无所知。
我认为 SCrypt.scrypt()
参数应该针对您的用例进行优化。
this answer and this slide p17
中的一些数字(N = 2^14, r = 8, p = 1) for < 100ms (interactive use)
(N = 2^20, r = 8, p = 1) for < 5s (sensitive storage)
和N
、r
、p
的含义:
N: General work factor, iteration count.
r: blocksize in use for underlying hash; fine-tunes the relative memory-cost.
p: parallelization factor; fine-tunes the relative cpu-cost
所以如果你想要更少的时间,应该减少 N
。 r
和p
与硬件有关,需要更多运行环境动态调整。