【问题标题】:Diffie Hellman JavaCard迪菲赫尔曼JavaCard
【发布时间】:2017-05-02 20:22:11
【问题描述】:

我对 JavaCard 上的 DiffieHellman 有疑问。我有这个类: https://pastebin.com/2F2sQ2Pe (https://github.com/ASKGLab/DHApplet) (它的文件更大,所以我向 pastebin 大声疾呼,不确定是否有问题)

然后我创建它的 2 个实例并像这样调用它(仅显示一个实例):

DiffieHellman dh = new DiffieHellman();
dh.init();
dh.getY(hostY, (short)0);
dh.setY(cardY, (short) 0, (short) cardY.length, (short) 0); 
AESKey encKey = (AESKey) KeyBuilder.buildKey(KeyBuilder.TYPE_AES_TRANSIENT_RESET, KeyBuilder.LENGTH_AES_128, false);
dh.doFinal(encKey);

hostY 和 cardY 是公共值。我在桌面应用程序上尝试过,所以我保证与 JavaCard 的通信没有问题。所以我的问题是,在所有这些 SharedSecret 不同之后,我不知道为什么,因为我通过 RSA 的解密执行 Y = G^bobPrivKey mod P 以让 Y 传输它们,然后通过 RSA 的解密执行 S = Y^a mod p。

提前感谢您的任何回答。

【问题讨论】:

  • 呃,我们可以假设您的卡实现中没有 2048 位 DH 吗?
  • 我在台式机上试过(即使没有卡)
  • 你是在使用jCardSim在桌面上模拟javacard API吗?还是别的什么?
  • 这是你PC端的代码,可以提供javacard小程序的代码吗?

标签: java javacard diffie-hellman


【解决方案1】:

(假设您在桌面上使用jCardSim 进行 Java Card API 仿真)

jCardSim 存在一个问题,它总是使用 CRT 私钥(如使用的 RSAKeyPairGenerator 总是生成 CRT 私钥,它总是实现 RSAPrivateCrtKeyParameters -- 请参阅 herehere)。

所以每一个 jCardSim RSA 私钥(即使是用ALG_RSA 生成的)都是由RSAPrivateCrtKeyImpl 实现的(你可以用.getClass().getCanonicalName() 检查自己)。

真正的问题是RSAPrivateCrtKeyImpl 类在进行实际加密时忽略了模数的值:

AssymetricCipherImpl.init():

// ...some code above skipped...
KeyWithParameters key = (KeyWithParameters) theKey;
engine.init(theMode == MODE_ENCRYPT, key.getParameters());
// ...some code below skipped...

RSAPrivateCrtKeyImpl.getParameters() -- 没有使用modulus 字段:

public CipherParameters getParameters() {
    if (!isInitialized()) {
        CryptoException.throwIt(CryptoException.UNINITIALIZED_KEY);
    }
    // modulus = p * q;
    return new RSAPrivateCrtKeyParameters(p.getBigInteger().multiply(q.getBigInteger()), null,
            null, p.getBigInteger(), q.getBigInteger(),
            dp1.getBigInteger(), dq1.getBigInteger(), pq.getBigInteger());
}

因此,用于设置所需 DH 组素数的 setModulus() call 无效,并使用原始(生成的)模数。

祝你好运!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-30
    • 2020-10-08
    相关资源
    最近更新 更多