DH密钥对生成时间在Android

DH密钥对生成时间在Android

本文介绍了DH密钥对生成时间在Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我使用生成一个密钥对DH的code:

This is the code that I'm using to generate a DH keypair:

KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DH");
keyGen.initialize(1024, new SecureRandom());
KeyPair ackp = keyGen.generateKeyPair();

(没有需要的try / catch,当然)。

(without the needed try/catch, of course).

我已经做了这样的运行code反复和不同的密钥大小(从128特别斜坡了一个128步至1024 1024将所需的大小一些测试。

I've done some tests running such code iteratively and varying the key size (in particular ramping up from 128 with a 128 step up to 1024. 1024 would be the desired size.

首先,运行的每个大小代10次,对结果有一些最起码的标准偏差给出结果的高波动,平均而言,无论如何,所需的时间用于创建密钥( 1024位 )是:683027ms,这轮高达约作为创建密钥

First of all, running each size generation 10 times to have some minimal std deviation on the results gives HIGH fluctuation of results, on average, anyway, the time needed for creating the keys (1024 bit) is: 683027ms, which rounds up to around 11 minutes for creating a key.

的问题是:

  1. 是任何人都得到同样的结果吗?
  2. 有一些优化是为了实现更低的时间运行?
  3. 什么是高波动的依赖呢? (即,用于产生1024bit的钥匙可能需要18秒至30分钟...)

测试已经运行在一台Nexus-One手机

Tests have been run on a Nexus-One phone

在此先感谢脱落一些轻的问题

Thanks in advance for shedding some light on the "issue"

问候

推荐答案

我做了一些进一步的编码/研究,显然呼叫这是最时间(电池?)消费是:

I did some further coding/research and apparently the call that's the most time (battery?) consuming is:

new SecureRandom()

在具体地,虽然,由于用于DH的参数(G,P,升)可以是$ P $对计算和硬$ C $光盘它是一个明智建议这样做事先并使用所产生的值以产生密钥对(这将是几乎瞬时)。

In particular, though, since for DH the parameters (g, p, l) can be pre-computed and hard-coded it's a wise suggestion to do so beforehand and use the generated values to generate the key pair (which will be almost instantaneous).

例如code:

KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DH");
keyGen.initialize(new DHParameterSpec(p, g, l));
KeyPair ackp = keyGen.generateKeyPair();

其中p,克,和l是:

Where p, g, and l are:

final BigInteger p = new BigInteger("X");
final BigInteger g = new BigInteger("Y");
final int l = 1023;

和X和Y可以离线与产生:

And X and Y can be generated offline with:

AlgorithmParameterGenerator paramGen = AlgorithmParameterGenerator.getInstance("DH");
paramGen.init(1024, new SecureRandom());
AlgorithmParameters params = paramGen.generateParameters();
DHParameterSpec dhSpec = (DHParameterSpec)params.getParameterSpec(DHParameterSpec.class);
System.out.println("p: " + dhSpec.getP() + "\ng: " + dhSpec.getG() + " \nl: " + dhSpec.getL());

这篇关于DH密钥对生成时间在Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 20:39