简体   繁体   English

brainpool320r1 Java Card不支持Elliptic Curve?

[英]brainpool320r1 Elliptic Curve not supported in Java Card?

I am working on a Java Card 3.0.1 applet on which I use ECC. 我正在使用我使用ECC的Java Card 3.0.1 applet。 My card supports ECC GF(p) up to 320bits, so I tried to use the brainpool320r1 elliptic curve ( parameters ). 我的卡支持高达320位的ECC GF(p),所以我尝试使用brainpool320r1椭圆曲线( 参数 )。 The problem is that I get a CryptoException that I don't understand... It is the same kind of problem that I had a few time ago: Restricted elliptic curves in Java Card but the solution given doesn't match with this case (the curve is well defined with a 320bits prime). 问题是我得到了一个我不理解的CryptoException ...这是我前几天遇到的同样的问题: Java Card中受限制的椭圆曲线但是给出的解决方案与这种情况不匹配(曲线很好地定义了320bits prime。

I post the corresponding code : 我发布了相应的代码:

byte[] p = new byte[] { (byte) 0xD3, (byte) 0x5E, (byte) 0x47, (byte) 0x20,
        (byte) 0x36, (byte) 0xBC, (byte) 0x4F, (byte) 0xB7,
        (byte) 0xE1, (byte) 0x3C, (byte) 0x78, (byte) 0x5E,
        (byte) 0xD2, (byte) 0x01, (byte) 0xE0, (byte) 0x65,
        (byte) 0xF9, (byte) 0x8F, (byte) 0xCF, (byte) 0xA6,
        (byte) 0xF6, (byte) 0xF4, (byte) 0x0D, (byte) 0xEF,
        (byte) 0x4F, (byte) 0x92, (byte) 0xB9, (byte) 0xEC,
        (byte) 0x78, (byte) 0x93, (byte) 0xEC, (byte) 0x28,
        (byte) 0xFC, (byte) 0xD4, (byte) 0x12, (byte) 0xB1,
        (byte) 0xF1, (byte) 0xB3, (byte) 0x2E, (byte) 0x27 };

byte[] a = new byte[] { (byte) 0x3E, (byte) 0xE3, (byte) 0x0B, (byte) 0x56,
    (byte) 0x8F, (byte) 0xBA, (byte) 0xB0, (byte) 0xF8,
    (byte) 0x83, (byte) 0xCC, (byte) 0xEB, (byte) 0xD4,
    (byte) 0x6D, (byte) 0x3F, (byte) 0x3B, (byte) 0xB8,
    (byte) 0xA2, (byte) 0xA7, (byte) 0x35, (byte) 0x13,
    (byte) 0xF5, (byte) 0xEB, (byte) 0x79, (byte) 0xDA,
    (byte) 0x66, (byte) 0x19, (byte) 0x0E, (byte) 0xB0,
    (byte) 0x85, (byte) 0xFF, (byte) 0xA9, (byte) 0xF4,
    (byte) 0x92, (byte) 0xF3, (byte) 0x75, (byte) 0xA9,
    (byte) 0x7D, (byte) 0x86, (byte) 0x0E, (byte) 0xB4 };

byte[] b = new byte[] { (byte) 0x52, (byte) 0x08, (byte) 0x83, (byte) 0x94,
    (byte) 0x9D, (byte) 0xFD, (byte) 0xBC, (byte) 0x42,
    (byte) 0xD3, (byte) 0xAD, (byte) 0x19, (byte) 0x86,
    (byte) 0x40, (byte) 0x68, (byte) 0x8A, (byte) 0x6F,
    (byte) 0xE1, (byte) 0x3F, (byte) 0x41, (byte) 0x34,
    (byte) 0x95, (byte) 0x54, (byte) 0xB4, (byte) 0x9A,
    (byte) 0xCC, (byte) 0x31, (byte) 0xDC, (byte) 0xCD,
    (byte) 0x88, (byte) 0x45, (byte) 0x39, (byte) 0x81,
    (byte) 0x6F, (byte) 0x5E, (byte) 0xB4, (byte) 0xAC,
    (byte) 0x8F, (byte) 0xB1, (byte) 0xF1, (byte) 0xA6 };

byte[] r = new byte[] { (byte) 0xD3, (byte) 0x5E, (byte) 0x47, (byte) 0x20,
    (byte) 0x36, (byte) 0xBC, (byte) 0x4F, (byte) 0xB7,
    (byte) 0xE1, (byte) 0x3C, (byte) 0x78, (byte) 0x5E,
    (byte) 0xD2, (byte) 0x01, (byte) 0xE0, (byte) 0x65,
    (byte) 0xF9, (byte) 0x8F, (byte) 0xCF, (byte) 0xA5,
    (byte) 0xB6, (byte) 0x8F, (byte) 0x12, (byte) 0xA3,
    (byte) 0x2D, (byte) 0x48, (byte) 0x2E, (byte) 0xC7,
    (byte) 0xEE, (byte) 0x86, (byte) 0x58, (byte) 0xE9,
    (byte) 0x86, (byte) 0x91, (byte) 0x55, (byte) 0x5B,
    (byte) 0x44, (byte) 0xC5, (byte) 0x93, (byte) 0x11 };

byte[] g = new byte[] { (byte) 0x04, (byte) 0x43, (byte) 0xBD, (byte) 0x7E,
    (byte) 0x9A, (byte) 0xFB, (byte) 0x53, (byte) 0xD8,
    (byte) 0xB8, (byte) 0x52, (byte) 0x89, (byte) 0xBC,
    (byte) 0xC4, (byte) 0x8E, (byte) 0xE5, (byte) 0xBF,
    (byte) 0xE6, (byte) 0xF2, (byte) 0x01, (byte) 0x37,
    (byte) 0xD1, (byte) 0x0A, (byte) 0x08, (byte) 0x7E,
    (byte) 0xB6, (byte) 0xE7, (byte) 0x87, (byte) 0x1E,
    (byte) 0x2A, (byte) 0x10, (byte) 0xA5, (byte) 0x99,
    (byte) 0xC7, (byte) 0x10, (byte) 0xAF, (byte) 0x8D,
    (byte) 0x0D, (byte) 0x39, (byte) 0xE2, (byte) 0x06,
    (byte) 0x11, (byte) 0x14, (byte) 0xFD, (byte) 0xD0,
    (byte) 0x55, (byte) 0x45, (byte) 0xEC, (byte) 0x1C,
    (byte) 0xC8, (byte) 0xAB, (byte) 0x40, (byte) 0x93,
    (byte) 0x24, (byte) 0x7F, (byte) 0x77, (byte) 0x27,
    (byte) 0x5E, (byte) 0x07, (byte) 0x43, (byte) 0xFF,
    (byte) 0xED, (byte) 0x11, (byte) 0x71, (byte) 0x82,
    (byte) 0xEA, (byte) 0xA9, (byte) 0xC7, (byte) 0x78,
    (byte) 0x77, (byte) 0xAA, (byte) 0xAC, (byte) 0x6A,
    (byte) 0xC7, (byte) 0xD3, (byte) 0x52, (byte) 0x45,
    (byte) 0xD1, (byte) 0x69, (byte) 0x2E, (byte) 0x8E, (byte) 0xE1 };

    ECPublicKey ecdhPubKey = (ECPublicKey) KeyBuilder.buildKey(
            KeyBuilder.TYPE_EC_FP_PUBLIC, (short) 0x0140, false);
    ecdhPubKey.setFieldFP(p, (short) 0x0000, (short) 0x0028);
    ecdhPubKey.setA(a, (short) 0x0000, (short) 0x0028);
    ecdhPubKey.setB(b, (short) 0x0000, (short) 0x0028);
    ecdhPubKey.setR(r, (short) 0x0000, (short) 0x0028);
    ecdhPubKey.setG(g, (short) 0x0000, (short) g.length);

    ECPrivateKey ecdhPrivKey = (ECPrivateKey) KeyBuilder.buildKey(
        KeyBuilder.TYPE_EC_FP_PRIVATE, (short) 0x0140, false);

    // Generate a key pair (x, xG) for ECDH.
    KeyPair keypair = new KeyPair(ecdhPubKey, ecdhPrivKey);
    keypair.genKeyPair();

I checked step by step, all is going right, except the last line keypair.genKeyPair(); 我一步一步检查,一切正常,除了最后一行keypair.genKeyPair(); that raises a CryptoException.ILLEGAL_VALUE . 引发了CryptoException.ILLEGAL_VALUE In the Java Card specifications, it is said it means that the values FP , A , B , R and G specified for the ECPublicKey are invalid... I verified, it corresponds well to the brainpool520r1 . 在Java Card规范中,据说这意味着为ECPublicKey指定的值FPABRG无效......我验证了,它与brainpool520r1很好地对应。 So what ? 所以呢 ? Am I doing something wrong ? 难道我做错了什么 ? Is this curve not well defined for ECC ? 这条曲线没有为ECC定义好吗? Thank you in advance. 先感谢您。

正如Maarten Bodewes在上面评论中所说, 问题在于我没有ECPrivateKey 设置域参数 ,尽管Java Card规范提到它只是ECPublicKey必需的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM