当前位置: 首页>>代码示例>>Python>>正文


Python EcGroup.list_curves方法代码示例

本文整理汇总了Python中petlib.ec.EcGroup.list_curves方法的典型用法代码示例。如果您正苦于以下问题:Python EcGroup.list_curves方法的具体用法?Python EcGroup.list_curves怎么用?Python EcGroup.list_curves使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在petlib.ec.EcGroup的用法示例。


在下文中一共展示了EcGroup.list_curves方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_blog_post

# 需要导入模块: from petlib.ec import EcGroup [as 别名]
# 或者: from petlib.ec.EcGroup import list_curves [as 别名]
def test_blog_post():
    # Define an EC group
    G = EcGroup(713)
    print (EcGroup.list_curves()[713])
    order = G.order()

    ## Define the Zero-Knowledge proof statement
    zk = ZKProof(G)
    g, h = zk.get(ConstGen, ["g", "h"])
    x, o = zk.get(Sec, ["x", "o"])
    Cxo = zk.get(ConstGen, "Cxo")
    zk.add_proof(Cxo, x*g + o*h)

    ## Render the proof statement in Latex
    print(zk.render_proof_statement())

    # A concrete Pedersen commitment
    ec_g = G.generator()
    ec_h = order.random() * ec_g
    bn_x = order.random()
    bn_o = order.random()
    ec_Cxo = bn_x * ec_g + bn_o * ec_h

    ## Bind the concrete variables to the Proof
    env = ZKEnv(zk)
    env.g, env.h = ec_g, ec_h 
    env.Cxo = ec_Cxo
    env.x = bn_x 
    env.o = bn_o

    # Create the Non-Interactive Zero-Knowledge (NIZK) proof
    sig = zk.build_proof(env.get())

    # Execute the verification on the proof 'sig'
    env = ZKEnv(zk)
    env.g, env.h = ec_g, ec_h 
    env.Cxo = ec_Cxo

    assert zk.verify_proof(env.get(), sig)
开发者ID:gdanezis,项目名称:petlib,代码行数:41,代码来源:blogsample.py

示例2: abs

# 需要导入模块: from petlib.ec import EcGroup [as 别名]
# 或者: from petlib.ec.EcGroup import list_curves [as 别名]
from petlib.ec import EcGroup, EcPt
from petlib.bn import Bn
import time

timings = []
curves = EcGroup.list_curves()

for gid in curves:
    G = EcGroup(gid)
    gx = G.order().random() * G.generator()

    rnd = [G.order().random() for _ in range(100)]

    t0 = time.clock()
    for r in rnd:
        dud = r * gx
    t1 = time.clock()

    repreats = 1000
    t = []
    for x in [2, 200]:
        o = Bn(2) ** x
        tests = [o.random() for _ in range(repreats)]

        tx = time.clock()
        for y in tests:
            dud = y * gx
        t += [time.clock() - tx]
        # print(x, t[-1] / repreats)
    if abs(t[0] - t[-1]) < 5.0 / 100:
        const = "CONST"
开发者ID:gdanezis,项目名称:petlib,代码行数:33,代码来源:ec_timing.py

示例3: print

# 需要导入模块: from petlib.ec import EcGroup [as 别名]
# 或者: from petlib.ec.EcGroup import list_curves [as 别名]
from petlib.ec import EcGroup, EcPt
from petlib.bn import Bn

import time

if __name__ == "__main__":
    fails = 0
    print("List of curves passing the constant-time scalar mult test:")
    for (nid, name) in sorted(EcGroup.list_curves().items()):
        G = EcGroup(nid)
        g = G.generator()
        order = G.order()
        h = order.random() * g

        repreats = 100
        t = []
        for x in range(0, 400, 100):
            o = Bn(2) ** x
            tests = [o.random() for _ in range(repreats)]

            t0 = time.clock()
            for y in tests:
                y * h
            t += [time.clock() - t0]
            # print x, t[-1] / repreats
        res = abs(t[0] - t[-1]) < 1.0 / 100
        if res:

            ps = 1.0 / (t[-1] / repreats)
            res = ["FAIL", "PASS"][res]
            print("%3d\t%s\t%2.1f/s\t%s" % (nid, res, ps, name))
开发者ID:gdanezis,项目名称:petlib,代码行数:33,代码来源:EcGroup_timing.py


注:本文中的petlib.ec.EcGroup.list_curves方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。