Java Card中的受限椭圆曲线 [英] Restricted elliptic curves in Java Card

查看:163
本文介绍了Java Card中的受限椭圆曲线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Java Card中的椭圆曲线上实现加密算法。

I am trying to implement cryptographic algorithms on elliptic curve in Java Card.

首先,我在256bits椭圆曲线。

First, I implemented it on 256bits elliptic curve (the NIST one) and it worked well.

现在我想在512bits的曲线上测试它(而不是像NIST那样的521)。我的卡支持这个大小,我发现了一个椭圆曲线(明确定义为加密)的数据库这种大小。
但我遇到一个奇怪的问题...

Now I want to test it on a 512bits curve (and not 521 like the NIST one). My card support this size and I found a database of elliptic curves (well defined for cryptography) of this size. But I am encountering a strange problem...

当我尝试初始化我的键:

When I try to initialize my key:

ECPublicKey pubKey = (ECPublicKey) KeyBuilder.buildKey(
            KeyBuilder.TYPE_EC_FP_PUBLIC, (short) 0x0200, false);

pubKey.setFieldFP(new byte[] { (byte) 0x25, (byte) 0x37,
            (byte) 0xD2, (byte) 0x9C, (byte) 0x8B, (byte) 0xFE,
            (byte) 0x7D, (byte) 0x9F, (byte) 0x48, (byte) 0x98,
            (byte) 0xF7, (byte) 0x60, (byte) 0xF8, (byte) 0x7D,
            (byte) 0xBF, (byte) 0x63, (byte) 0x90, (byte) 0x6E,
            (byte) 0x28, (byte) 0x99, (byte) 0x0A, (byte) 0x27,
            (byte) 0x0C, (byte) 0xA6, (byte) 0x15, (byte) 0xD9,
            (byte) 0x1D, (byte) 0xC4, (byte) 0x89, (byte) 0xA8,
            (byte) 0xD0, (byte) 0xA1, (byte) 0xA0, (byte) 0xE7,
            (byte) 0x52, (byte) 0x43, (byte) 0xB0, (byte) 0x39,
            (byte) 0x01, (byte) 0x6A, (byte) 0x61, (byte) 0x43,
            (byte) 0x5C, (byte) 0xA5, (byte) 0x91, (byte) 0xE9,
            (byte) 0x4B, (byte) 0x1A, (byte) 0xF7, (byte) 0x60,
            (byte) 0xC9, (byte) 0xAE, (byte) 0xE2, (byte) 0xCE,
            (byte) 0xE0, (byte) 0x15, (byte) 0x53, (byte) 0x51,
            (byte) 0x1C, (byte) 0x93, (byte) 0x0E, (byte) 0xF3,
            (byte) 0xBA, (byte) 0x0B }, (short) 0x0000, (short) 0x0040);

函数 setFieldFP $ c> CryptoException 与原因代码 ILLEGAL_VALUE 这意味着密钥长度不匹配...但它确实( 0x0200 是以位为单位的曲线大小, 0X0040 是以字节为单位的素数长度)!

The function setFieldFP raises a CryptoException with the reason code ILLEGAL_VALUE which means that the key length doesn't match... But it does (0x0200 is the size of the curve in bits and 0X0040 is the length of the prime in bytes)!

我说这很奇怪,因为如果我尝试使用下面的值:

I said it is really strange because if I try with the following value:

ECPublicKey pubKey = (ECPublicKey) KeyBuilder.buildKey(
            KeyBuilder.TYPE_EC_FP_PUBLIC, (short) 0x0200, false);

pubKey.setFieldFP(new byte[] { (byte) 0xFF, (byte) 0xFF,
            (byte) 0xFF, (byte) 0xFF, (byte) 0x00, (byte) 0x00,
            (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x00,
            (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
            (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
            (byte) 0x00, (byte) 0x00, (byte) 0xFF, (byte) 0xFF,
            (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
            (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
            (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
            (byte) 0xFF, (byte) 0xFF, (byte) 0x00, (byte) 0x00,
            (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x00,
            (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
            (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
            (byte) 0x00, (byte) 0x00, (byte) 0xFF, (byte) 0xFF,
            (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
            (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
            (byte) 0xFF, (byte) 0xFF}, (short) 0x0000, (short) 0x0040);

它工作正常...

因此,我必须得出结论,提出的 CryptoException 并不真的涉及参数的大小,因为在两种情况下,大小是相同的...

So I have to conclude that the CryptoException that is raised doesn't really concern the size of the parameter because, in the two cases, the size is the same...

那么什么呢?我的卡只支持在特定字段上的椭圆曲线吗?有人遇到过这种问题吗?

So what? Does my card only support elliptic curve on specific fields? Has someone ever encountered this kind of problem?

推荐答案

你的素质不够大。对于512位F(p)的曲线,您应该使用512位元素。您的第一个字节(字节)0x25 ,但是以十六进制数字 2 开头。这意味着第一个字节首先以2个二进制数字设置为 0 开始,这意味着您定义了一个512 - 2 = 510位素数。

Your prime is not big enough. For curves over F(p) of 512 bit you should use 512 bit primes. Your first byte, (byte) 0x25, however starts with a hex digit 2. That means that the first byte first starts with 2 binary digits set to 0, meaning that you've defined a 512 - 2 = 510 bit prime.

请仅使用明确定义的曲线,例如NIST P521曲线或BrainpoolP512r1曲线。

Please use only well defined curves, such as the NIST P521 curve or the BrainpoolP512r1 curve.

这篇关于Java Card中的受限椭圆曲线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆