簡體   English   中英

在javacard上使用Curve25519

[英]Using Curve25519 on javacard

我正在研究在javacard 3.0.4上使用curve25519但是我遇到了問題,我有以下問題:

javacard 3.0.4是否支持這樣的曲線?

到目前為止我所嘗試的是將蒙哥馬利方程轉換為Weierstrass方程。 這樣做並使用Bernstein的網站我得到了以下參數:

p  = 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed
a  = 0x2aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa984914a144
b  = 0x7b425ed097b425ed097b425ed097b425ed097b425ed097b4260b5e9c7710c864
r  = 0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed
Gx = 0x9
Gy = 0x20ae19a1b8a086b4e01edd2c7748d14c923d4d7e6d7c61b229e9c5a27eced3d9

當我在互聯網上找到一些其他價值觀時,我也試過了

Gx: 0x2aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaad245a

然后我跟着ykneo-curves的實現,最后得到了這個:

public class Curve25519 {

   public final static byte[] p = { // 32 bytes
        (byte) 0x7f, (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) 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) 0xed };

   public final static byte[] a = { // 32 bytes
        (byte) 0x2a, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa,
        (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa,
        (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa,
        (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0x98, (byte) 0x49, (byte) 0x14, (byte) 0xa1, (byte) 0x44 };

   public final static byte[] b = { // 32 bytes
        (byte) 0x7b, (byte) 0x42, (byte) 0x5e, (byte) 0xd0, (byte) 0x97, (byte) 0xb4, (byte) 0x25, (byte) 0xed,
        (byte) 0x09, (byte) 0x7b, (byte) 0x42, (byte) 0x5e, (byte) 0xd0, (byte) 0x97, (byte) 0xb4, (byte) 0x25,
        (byte) 0xed, (byte) 0x09, (byte) 0x7b, (byte) 0x42, (byte) 0x5e, (byte) 0xd0, (byte) 0x97, (byte) 0xb4,
        (byte) 0x26, (byte) 0x0b, (byte) 0x5e, (byte) 0x9c, (byte) 0x77, (byte) 0x10, (byte) 0xc8, (byte) 0x64 };

   public final static byte[] G = { // 65 bytes
        (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) 0x00, (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) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
        (byte) 0x09, (byte) 0x20, (byte) 0xae, (byte) 0x19, (byte) 0xa1, (byte) 0xb8, (byte) 0xa0, (byte) 0x86,
        (byte) 0xb4, (byte) 0xe0, (byte) 0x1e, (byte) 0xdd, (byte) 0x2c, (byte) 0x77, (byte) 0x48, (byte) 0xd1,
        (byte) 0x4c, (byte) 0x92, (byte) 0x3d, (byte) 0x4d, (byte) 0x7e, (byte) 0x6d, (byte) 0x7c, (byte) 0x61,
        (byte) 0xb2, (byte) 0x29, (byte) 0xe9, (byte) 0xc5, (byte) 0xa2, (byte) 0x7e, (byte) 0xce, (byte) 0xd3,
        (byte) 0xd9 };

   public final static byte[] r = { // 32 bytes
        (byte) 0x10, (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) 0x00, (byte) 0x00, (byte) 0x00,
        (byte) 0x14, (byte) 0xde, (byte) 0xf9, (byte) 0xde, (byte) 0xa2, (byte) 0xf7, (byte) 0x9c, (byte) 0xd6,
        (byte) 0x58, (byte) 0x12, (byte) 0x63, (byte) 0x1a, (byte) 0x5c, (byte) 0xf5, (byte) 0xd3, (byte) 0xed };

   static public KeyPair newKeyPair() {
      KeyPair kp = new KeyPair(KeyPair.ALG_EC_FP, (short) 256);

      ECPrivateKey ecPrv = (ECPrivateKey) kp.getPrivate();
      ECPublicKey ecPub = (ECPublicKey) kp.getPublic();

      ecPrv.setFieldFP(p, (short) 0, (short) p.length);
      ecPrv.setA(a, (short) 0, (short) a.length);
      ecPrv.setB(b, (short) 0, (short) b.length);
      ecPrv.setG(G, (short) 0, (short) G.length);
      ecPrv.setR(r, (short) 0, (short) r.length);

      ecPub.setFieldFP(p, (short) 0, (short) p.length);
      ecPub.setA(a, (short) 0, (short) a.length);
      ecPub.setB(b, (short) 0, (short) b.length);
      ecPub.setG(G, (short) 0, (short) G.length);
      ecPub.setR(r, (short) 0, (short) r.length);

      return kp;
   }
}

在applet中我有以下代碼:

private MyApplet(byte[] bArray, short bOffset, byte bLength) {
    ecKeyPair = Curve25519.newKeyPair();
    ecKeyPair.genKeyPair();
    register();
}
public static void install(byte[] bArray, short bOffset, byte bLength) {
        new MyApplet(bArray, bOffset, bLength);
}

當我嘗試使用GPP在javacard上安裝它時,我得到以下異常:

pro.javacard.gp.GPException: Install for Install and make selectable failed SW: 6F00
        at pro.javacard.gp.GlobalPlatform.check(GlobalPlatform.java:1092)
        at pro.javacard.gp.GlobalPlatform.installAndMakeSelectable(GlobalPlatform.java:798
)
        at pro.javacard.gp.GPTool.main(GPTool.java:478)

我可以使用Curve25519密鑰對進行ECDSA javacard簽名嗎?

不,不直接支持這樣的曲線。

所有Java Card Elliptic Curve工具都使用Weierstraß方程

y ^ 2 = x ^ 3 + a * x + b mod p

曲線25519基於

y ^ 2 = x ^ 3 + 486662 * x ^ 2 + x mod p

不幸的是,它不可能直接支持這種蒙哥馬利曲線。

不完全的。 蒙哥馬利和Weierstrass表格可以互相轉換: http ://samuelkerr.com/?p = 431

然而,有各種注意事項可以讓它在Javacards上運行,並且部分曲線操作/轉換必須在與卡通信的PC上完成。 我正在努力解決這個問題,並且很樂意在實際完成后分享代碼。

更新:我在這里上傳了相應的代碼: https//github.com/david-oswald/jc_curve25519

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM