使用jPBC在java中实现双线性配对

时间:2016-01-29 07:17:20

标签: java

我尝试使用jPBC在Java中实现双线性配对,并使用以下代码检查Bilinearity属性。 这是对的吗? 我不知道如何知道它是否正确。请帮忙。

     PairingFactory.getInstance().setUsePBCWhenPossible(true);
    Pairing pairing = PairingFactory.getPairing("F:\\try\\params\\curves\\a.properties");
   int degree = pairing.getDegree();
   System.out.println("degree = "+ degree);

    /* Return Zr */
    Field Zr = pairing.getZr();

    /* Return G1 */
    Field G1 = pairing.getG1();

    /* Return G2 */
    Field G2 = pairing.getG2();

    /* Return GT */
    Field GT = pairing.getGT();

    Element u = G1.newRandomElement(); 
    Element v = G2.newRandomElement();

    Element e1 = pairing.pairing(u, v); //pairing can be computed

    System.out.println("Element u = "+ u);
    System.out.println("Element v = "+ v);
    System.out.println("pairing e(u,v) = "+ e1);


    //CHECK BILINEARITY PROPERTY OF BILINEAR-PAIRING
    // e( u^a , v^b ) = e(u,v)^(a*b)
    Element a = Zr.newRandomElement();
    Element b = Zr.newRandomElement();

    System.out.println("Element a = "+ a);
    System.out.println("Element b = "+ b);

    Element LHS = pairing.pairing(u.powZn(a), v.powZn(b));
    Element RHS = e1.powZn(a.mul(b));

    System.out.println("LHS = "+LHS);
    System.out.println("RHS = "+RHS);

    if(LHS.isEqual(RHS))
    {
        System.out.println("BILINEAR");
    }
    else
    {
        System.out.println("NOT BILINEAR");
    }

我的输出是

degree = 2
Element u = 4866041342894402677803693405130010832349339992236773091903579144194363002203438055317050262465150164708359404800429625278583966038535861732618064981597588,2520129541588537942227591395792708348477737843963482402959590033554670903024187404197414712797505861725822220731358101319943167983180677145528408822293587,0
Element v = 6529258305528540310250832226812328115955374264752957892339595921573477787820817174021465903363097848161094331714483348574944223486909340975642036873512616,3691480837121382500601782418389559456783070610647315982199609076044168554795955799987737829489239176417326640138311078114124128153650566676808890301518470,0
pairing e(u,v) = {x=7680797668329937815088420850270374629509382249103994006581639961464198477062710179129546441620215742476345389500469950463014995069256898530079394630800905,y=4381713099922646676896241268471865978284848986483823691187964242279854012615948775464846659757919737326079688679266942570087087450470377987737389535849010}
Element a = 393845971301072953348418011317340085945313299952
Element b = 87466036726809504477215126720848633203781454447
LHS = {x=3098294361406206064115429913268673069433256494954089884628823190592635636111566932396144131395192369872555728858136558844620669431467808470302071809950199,y=5813928251188210989466471963926842747815078174548948204704296203413728702115252887863505105608557349187188341013964975053787442451645922266533731535114150}
RHS = {x=3098294361406206064115429913268673069433256494954089884628823190592635636111566932396144131395192369872555728858136558844620669431467808470302071809950199,y=5813928251188210989466471963926842747815078174548948204704296203413728702115252887863505105608557349187188341013964975053787442451645922266533731535114150}
BILINEAR

1 个答案:

答案 0 :(得分:2)

是的,使用JPBC库实现双线性配对的正确方法是:  元素G =配对。配对(Q1,Q2);

没有此类检查来验证您的答案,但这是正确的实施方式。