Getting started with JPBC programming

1. Introduction

1.1 JPBC, which is the short of Java Pairing-Based Cryptography Library.

1.2 JPBC网址: http://gas.dia.unisa.it/projects/jpbc

1.3 基于配对的密码学,这里的配对指双线性配对,有关双线性对性质见《现代密码学》杨波,第四版,P107。

1.4 Pairing for Cryptography definition from http://gas.dia.unisa.it/projects/jpbc/docs/pairing.html#.XIxffOgzZPY

 主要性质,双线性(Billinearity)&非退化性(Non-degeneracy)
 

1.5 Elements belonging to an algebraic structure (groups, rings and fields) are accessible through the Element interface that represents a mutable value.
Code example:

Field G1 = pairing.getG1();
Element g = G1.newRandomElement();

1.6 Pairing Parameters Generators, JPBC provides a set of interfaces and classes to generate and manage the parameters that describe a pairing setting. The PairingParametersGenerator interface is the starting point. Once an instance of such interface has been created then pairing parameters can be generated by invoking the generate method as follow:

import it.unisa.dia.gas.jpbc.PairingParametersGenerator;
import it.unisa.dia.gas.jpbc.PairingParameters;

             
// Initialize the pairing parameters generator.
ParametersGenerator parametersGenerator = ...
         
// Then, generate the parameters by invoking the generate method.
PairingParameters params = parametersGenerator.generate();

JPBC提供的一些default配对参数,详见http://gas.dia.unisa.it/projects/jpbc/docs/ecpg.html#.XIxouugzZPY

2. Interface

2.1 API详见http://gas.dia.unisa.it/projects/jpbc/java-docs/api/index.html
2.2 重要的3个接口Pairing, Filed, Element


2.2.1 Pairing 配对
默认实例化:

Pairing pairing = PairingFactory.getPairing("params.properties");

随机实例化:

PairingParameters pg = new TypeACurveGenerator(rBits, qBits).generate();
pairing = PairingFactory.getPairing(pg);

配对操作( pairing.pairing(g1, g2) ):
2.2.2 Field 群
详细的解释是algebraic structure (groups, rings and fields)
实例化需通过Pairing对象,别问为什么,不知道为什么这么设计

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

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

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

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

2.2.3 Element 元素
Filed中的元素

Element e = pairing.getG2().newRandomElement(); //随机
Element out = pairing.pairing(e1, e2);

add() 加
mul() 乘
mulZn() 乘 注意和mul的区别
sub() 减
div() 除
twice() (this+this)
halve() (this/2)
invert() 乘法逆元
square() 平方
negate() (-this)
sqrt() 开平方
pow() 乘方
powZn() 乘方 注意和pow的区别

详细的用法查看详细的API:http://gas.dia.unisa.it/projects/jpbc/java-docs/api/index.html

3. Configure

3.1 下载JPBC库的jar包
地址:https://sourceforge.net/projects/jpbc


点击Download后需要等待一段时间(有可能需要几分钟)


解压后


jars文件夹中是相应需要使用的jar包,里面是已经编译好的字节码文件
jpbc-*是相应的.java文件,so我们能get源码并追踪一些乘方计算为什么不那么耗时了
params文件夹中是关于双线性对(或者说是椭圆曲线)的配置文件
里面有两个文件夹“curves”和“mm/ctl13”
总的来说,这两个文件夹内都是一些.properties配置文件
目前使用的是curves里面的一些配置文件
关于配对类型详解可以参考李发根的《基于配对的密码学》中P24
3.2 配置过程
在项目中根目录下新建lib文件夹,将所需要的jar文件拷贝到lib中
然后右键项目文件-->Build Path-->Configure Bulid Path


弹出一下对话框后点击Libraries

从刚刚的lib中Add JARs

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值