资源简介
python3环境下的PBC库,可用于双线性配对计算的使用
python3环境下的PBC库,可用于双线性配对计算的使用
python3环境下的PBC库,可用于双线性配对计算的使用
代码片段和文件信息
#! /usr/bin/env python3
“““
KSW.py
Written by Geremy Condra
Licensed under GPLv3
Released 15 October 2009
An implementation of the Katz-Sahai-Waters predicate
encryption scheme in Python3.
“““
from pypbc import *
#############################################
# Utilities #
#############################################
def dot_product(x y n):
“““Takes the dot product of lists x and y over F_n“““
if len(x) != len(y):
raise ValueError(“x and y must be the same length!“)
if not isinstance(n int):
raise ValueError(“n must be an integer!“)
return sum([(x_i * y[i]) % n for i x_i in enumerate(x)])
#############################################
# Cryptosystem #
#############################################
class PublicKey:
g_G_p = None
g_G_r = None
Q = None
vector = None
def __init__(self gen_p gen_r Q vector):
self.g_G_p = gen_p
self.g_G_r = gen_r
self.Q = Q
self.vector = vector
class MasterSecretKey:
p = None
q = None
r = None
g_G_q = None
Hs = None
def __init__(self p q r g_G_q Hs):
self.p = p
self.q = q
self.r = r
self.g_G_q = g_G_q
self.Hs = Hs
class Cryptosystem:
def __init__(self security) -> “(PK SK)“:
self.security = security
# select p q r
p = get_random_prime(100)
q = get_random_prime(100)
r = get_random_prime(100)
# make n
self.n = p*q*r
# build the params
params = Parameters(n=self.n)
# build the pairing
self.pairing = Pairing(params)
# find the generators for the G_p G_q and G_r subgroups
g_G_p = Element.random(self.pairing G1)**(q*r)
g_G_r = Element.random(self.pairing G1)**(p*q)
g_G_q = Element.random(self.pairing G1)**(p*r)
# choose R0
R0 = g_G_r ** Element.random(self.pairing Zr)
# choose the random R‘s
Rs = [(g_G_r**Element.random(self.pairing Zr) g_G_r**Element.random(self.pairing Zr)) for i in range(security)]
hs = [(g_G_p**Element.random(self.pairing Zr) g_G_p**Element.random(self.pairing Zr)) for i in range(security)]
# choose the random H‘s
Hs = []
for i in range(security):
Hs.append((hs[i][0] * Rs[i][0] hs[i][1] * Rs[i][1]))
# calculate Q
Q = g_G_q * R0
# build the public and master secret keys
self.pk = PublicKey(g_G_p g_G_r Q Hs)
self.sk = MasterSecretKey(p q r g_G_q hs)
def keygen(self v: “description of a predicate“) -> “SK_f“:
R5 = self.pk.g_G_r**Element.random(self.pairing Zr)
Q6 = self.sk.g_G_q**Element.random(self.pairing Zr)
Rs = []
for i in range(self.security):
# build r1
r1 = Element(self.pairing Zr get_random(self.sk.p))
# build r2
r2 = Element(self.pairing Zr get_random(self.sk.p))
Rs.append((r1 r2))
f1 = Element(self.pairing Zr get_random(self.sk.q))
f2 = Element(self.pairing Zr get_random(self.sk.q))
K = R5*Q6
for pos in range(self.security):
# get h1 h2
h1 h2 = self.sk.Hs[pos]
# get r1 r2
r1 r2 = Rs[pos]
# form the intermediate value
i1 = h1**(-r1)
i2 = h2**(-r2)
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-11-21 17:22 pypbc-master\
文件 1480 2017-11-21 17:22 pypbc-master\INSTALL
文件 7601 2017-11-21 17:22 pypbc-master\KSW.py
文件 1070 2017-11-21 17:22 pypbc-master\LICENSE
文件 683 2017-11-21 17:22 pypbc-master\Makefile
文件 44874 2017-11-21 17:22 pypbc-master\pypbc.c
文件 1912 2017-11-21 17:22 pypbc-master\pypbc.h
文件 390 2017-11-21 17:22 pypbc-master\setup.py
文件 9837 2017-11-21 17:22 pypbc-master\test.py
相关资源
- HAP-NodeJS虚拟设备配置及python脚本
- Python成绩管理系统精简版
- 最全Python编程基础+简单爬虫+进阶项目
- python端口扫描代码源码
- python wxpy实现微信群消息转发
- Python_验证采样定理.py
- python爬虫爬微信公众号文章
- Python网络爬虫实战Scrapy.txt
- micropython下的ds18b20代码
- knn 字符识别 python
- EM算法Python实现
- 简单的python购物车程序
- 是AI就躲个飞机-纯Python实现人工智能
- Python接口测试框架实战与自动化进阶
- 基本蚁群算法python实现
- python核心编程第二版习题答案
- 基于二维伽马函数的光照不均匀的图
- python主题爬取百度新闻
- MySQL-python-1.2.5.win-amd64-py2.7
- nao机器人单个关节运动程序
- Python - Flask 使用Ajax 实现多文件上传
- Python魔鬼训练营系列教程
- 多线程爬虫
- python简单实现-中国象棋
- Python爬虫--抓取百度百科的前1000个页
- nlp肯定句与否定句判断
- 绘制社交网络图的幂律分布python代码
- Python 飞机大战 游戏设计需求 与 实现
- PARZEN窗和K近邻算法的python实现
- windows下fcntl.py
评论
共有 条评论