4

Android アプリの作成にscryptを使用していますが、ハッシュの計算に非常に時間がかかります。これは私がそれを呼び出す方法です:

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 でハッシュを計算するのにほぼ 1 分かかりますが、もちろん非常に遅いです。これをもっと速くする方法について誰か考えがありますか? 私はこれに慣れていないため、なぜそんなに遅いのか、どのようにスピードアップするのかわかりません。

4

1 に答える 1

2

I think the SCrypt.scrypt()parameters should be optimized for your use cases.

Some numbers in 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)

and the N,r,p meanings:

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

So if you want less time, the N should be reduced. r and p is related to hardware, it need more runtime environment to adjust dynamically.

于 2016-07-08T04:21:37.297 に答える