Java Card中的受限椭圆曲线

拉乌尔722

我正在尝试在Java卡中的椭圆曲线上实现加密算法。

首先,我在256位椭圆曲线(NIST椭圆曲线)上实现了它,并且效果很好。

现在,我想在512位曲线上进行测试(而不是像NIST一样在521位曲线上进行测试)。我的卡支持这种大小,并且我找到了这种大小的椭圆曲线数据库(对于密码学定义明确)。但是我遇到一个奇怪的问题...

当我尝试初始化密钥时:

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引发a CryptoExceptionILLEGAL_VALUE这意味着密钥长度不匹配...但是它匹配(0x0200是曲线的大小(以位0X0040单位,是素数的长度以字节为单位)!)!

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

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引发的实际上并不涉及参数的大小,因为在两种情况下,大小是相同的...

所以呢?我的卡仅在特定字段上支持椭圆曲线吗?有人遇到过这种问题吗?

马丁·波德威斯

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

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章