本文整理汇总了Python中petlib.ec.EcGroup.order方法的典型用法代码示例。如果您正苦于以下问题:Python EcGroup.order方法的具体用法?Python EcGroup.order怎么用?Python EcGroup.order使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类petlib.ec.EcGroup
的用法示例。
在下文中一共展示了EcGroup.order方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Ct_dec_unit_test
# 需要导入模块: from petlib.ec import EcGroup [as 别名]
# 或者: from petlib.ec.EcGroup import order [as 别名]
def Ct_dec_unit_test():
try:
G = EcGroup()
x_1 = G.order().random()
y_1 = x_1 * G.generator()
x_2 = G.order().random()
y_2 = x_2 * G.generator()
x_3 = G.order().random()
y_3 = x_3 * G.generator()
#
E1 = Ct.enc(y_1+y_2, 2)
E = copy(E1)
E.b = E1.partial_dec(x_1)
#
E3 = Ct.enc(y_1, 22)
E4 = Ct.enc(y_2+y_3, E3)
E5 = copy(E4)
E5.b = E4.partial_dec(x_1)
return ((E.dec(x_2) == 2) and (E1.dec(x_1+x_2) == 2) and (E5.dec(x_2+x_3)==22))
except Exception:
return False
示例2: setup
# 需要导入模块: from petlib.ec import EcGroup [as 别名]
# 或者: from petlib.ec.EcGroup import order [as 别名]
def setup():
""" Generates parameters for Commitments """
G = EcGroup()
g = G.hash_to_point(b'g')
h = G.hash_to_point(b'h')
o = G.order()
return (G, g, h, o)
示例3: setup
# 需要导入模块: from petlib.ec import EcGroup [as 别名]
# 或者: from petlib.ec.EcGroup import order [as 别名]
def setup():
''' Setup the parameters of the mix crypto-system '''
G = EcGroup()
o = G.order()
g = G.generator()
o_bytes = int(math.ceil(math.log(float(int(o))) / math.log(256)))
return G, o, g, o_bytes
示例4: test_timings
# 需要导入模块: from petlib.ec import EcGroup [as 别名]
# 或者: from petlib.ec.EcGroup import order [as 别名]
def test_timings():
# Make 100 keys
G = EcGroup()
keys = []
for _ in range(100):
sec = G.order().random()
k = Key(sec.binary(), False)
# bpub, bsec = k.export()
keys += [k]
msg = urandom(32)
# time sign
t0 = timer()
sigs = []
for i in range(1000):
sigs += [(keys[i % 100], keys[i % 100].sign(msg))]
t1 = timer()
print "\nSign rate: %2.2f / sec" % (1.0 / ((t1-t0)/1000.0))
# time verify
t0 = timer()
for k, sig in sigs:
assert k.verify(msg, sig)
t1 = timer()
print "Verify rate: %2.2f / sec" % (1.0 / ((t1-t0)/1000.0))
# time hash
t0 = timer()
for _ in range(10000):
sha256(msg).digest()
t1 = timer()
print "Hash rate: %2.2f / sec" % (1.0 / ((t1-t0)/10000.0))
示例5: _make_table
# 需要导入模块: from petlib.ec import EcGroup [as 别名]
# 或者: from petlib.ec.EcGroup import order [as 别名]
def _make_table(trunc_limit, start=conf.LOWER_LIMIT, end=conf.UPPER_LIMIT):
G = EcGroup(nid=713)
g = G.generator()
o = G.order()
i_table = {}
n_table = {}
ix = start * g
print "Generating db with truc: " + str(trunc_limit)
#trunc_limit = conf.TRUNC_LIMIT
for i in range(start, end):
#i_table[str(ix)] = str(i) #Uncompressed
#Compression trick
trunc_ix = str(ix)[:trunc_limit]
#print ix
#print trunc_ix
if trunc_ix in i_table:
i_table[trunc_ix] = i_table[trunc_ix] + "," + str(i)
else:
i_table[trunc_ix] = str(i)
n_table[str((o + i) % o)] = str(ix)
ix = ix + g
#print type(ix)
#print type(ix.export())
print "size: " + str(len(i_table))
return i_table, n_table
示例6: test_Alice_encode_3_hop
# 需要导入模块: from petlib.ec import EcGroup [as 别名]
# 或者: from petlib.ec.EcGroup import order [as 别名]
def test_Alice_encode_3_hop():
"""
Test sending a multi-hop message through 1-hop
"""
from os import urandom
G = EcGroup()
g = G.generator()
o = G.order()
private_keys = [o.random() for _ in range(3)]
public_keys = [pk * g for pk in private_keys]
address = b"Alice"
message = b"Dear Alice,\nHello!\nBob"
m1 = mix_client_n_hop(public_keys, address, message)
out = mix_server_n_hop(private_keys[0], [m1])
out = mix_server_n_hop(private_keys[1], out)
out = mix_server_n_hop(private_keys[2], out, final=True)
assert len(out) == 1
assert out[0][0] == address
assert out[0][1] == message
示例7: ecdsa_key_gen
# 需要导入模块: from petlib.ec import EcGroup [as 别名]
# 或者: from petlib.ec.EcGroup import order [as 别名]
def ecdsa_key_gen():
""" Returns an EC group, a random private key for signing
and the corresponding public key for verification"""
G = EcGroup()
priv_sign = G.order().random()
pub_verify = priv_sign * G.generator()
return (G, priv_sign, pub_verify)
示例8: mix_client_one_hop
# 需要导入模块: from petlib.ec import EcGroup [as 别名]
# 或者: from petlib.ec.EcGroup import order [as 别名]
def mix_client_one_hop(public_key, address, message):
"""
Encode a message to travel through a single mix with a set public key.
The maximum size of the final address and the message are 256 bytes and 1000 bytes respectively.
Returns an 'OneHopMixMessage' with four parts: a public key, an hmac (20 bytes),
an address ciphertext (256 + 2 bytes) and a message ciphertext (1002 bytes).
"""
G = EcGroup()
assert G.check_point(public_key)
assert isinstance(address, bytes) and len(address) <= 256
assert isinstance(message, bytes) and len(message) <= 1000
# Encode the address and message
# Use those as the payload for encryption
address_plaintext = pack("!H256s", len(address), address)
message_plaintext = pack("!H1000s", len(message), message)
## Generate a fresh public key
private_key = G.order().random()
client_public_key = private_key * G.generator()
#TODO ADD CODE HERE
return OneHopMixMessage(client_public_key, expected_mac, address_cipher, message_cipher)
示例9: mix_client_n_hop
# 需要导入模块: from petlib.ec import EcGroup [as 别名]
# 或者: from petlib.ec.EcGroup import order [as 别名]
def mix_client_n_hop(public_keys, address, message, use_blinding_factor=False):
"""
Encode a message to travel through a sequence of mixes with a sequence public keys.
The maximum size of the final address and the message are 256 bytes and 1000 bytes respectively.
Returns an 'NHopMixMessage' with four parts: a public key, a list of hmacs (20 bytes each),
an address ciphertext (256 + 2 bytes) and a message ciphertext (1002 bytes).
The implementation of the blinding factor is optional and therefore only activated
in the bonus tests. It can be ignored for the standard task.
If you implement the bonus task make sure to only activate it if use_blinding_factor is True.
"""
G = EcGroup()
# assert G.check_point(public_key)
assert isinstance(address, bytes) and len(address) <= 256
assert isinstance(message, bytes) and len(message) <= 1000
# Encode the address and message
# use those encoded values as the payload you encrypt!
address_plaintext = pack("!H256s", len(address), address)
message_plaintext = pack("!H1000s", len(message), message)
## Generate a fresh public key
private_key = G.order().random()
client_public_key = private_key * G.generator()
#TODO ADD CODE HERE
return NHopMixMessage(client_public_key, hmacs, address_cipher, message_cipher)
示例10: test_broad
# 需要导入模块: from petlib.ec import EcGroup [as 别名]
# 或者: from petlib.ec.EcGroup import order [as 别名]
def test_broad():
G = EcGroup()
g = G.generator()
x = G.order().random()
a, puba = pair(G)
b, pubb = pair(G)
c, pubc = pair(G)
a2, puba2 = pair(G)
b2, pubb2 = pair(G)
c2, pubc2 = pair(G)
pki = {"a":(puba,puba2) , "b":(pubb, pubb2), "c":(pubc, pubc2)}
client = KulanClient(G, "me", x, pki)
msgs = client.broadcast_encrypt(b"Hello!")
pki2 = {"me": x * g, "b":(pubb, pubb2), "c":(pubc, pubc2)}
dec_client = KulanClient(G, "a", a, pki2)
dec_client.priv_enc = a2
dec_client.pub_enc = puba2
namex, keysx = dec_client.broadcast_decrypt(msgs)
assert namex == "me"
# print msgs
示例11: test_Pedersen_Shorthand
# 需要导入模块: from petlib.ec import EcGroup [as 别名]
# 或者: from petlib.ec.EcGroup import order [as 别名]
def test_Pedersen_Shorthand():
# Define an EC group
G = EcGroup(713)
order = G.order()
## Proof definitions
zk = ZKProof(G)
zk.g, zk.h = ConstGen, ConstGen
zk.x, zk.o = Sec, Sec
zk.Cxo = Gen
zk.add_proof(zk.Cxo, zk.x*zk.g + zk.o*zk.h)
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
env = ZKEnv(zk)
env.g, env.h = ec_g, ec_h
env.Cxo = ec_Cxo
env.x = bn_x
env.o = bn_o
sig = zk.build_proof(env.get())
# Execute the verification
env = ZKEnv(zk)
env.g, env.h = ec_g, ec_h
assert zk.verify_proof(env.get(), sig)
示例12: mix_client_n_hop
# 需要导入模块: from petlib.ec import EcGroup [as 别名]
# 或者: from petlib.ec.EcGroup import order [as 别名]
def mix_client_n_hop(public_keys, address, message):
"""
Encode a message to travel through a sequence of mixes with a sequence public keys.
The maximum size of the final address and the message are 256 bytes and 1000 bytes respectively.
Returns an 'NHopMixMessage' with four parts: a public key, a list of hmacs (20 bytes each),
an address ciphertext (256 + 2 bytes) and a message ciphertext (1002 bytes).
"""
G = EcGroup()
# assert G.check_point(public_key)
assert isinstance(address, bytes) and len(address) <= 256
assert isinstance(message, bytes) and len(message) <= 1000
# Encode the address and message
# use those encoded values as the payload you encrypt!
address_plaintext = pack("!H256s", len(address), address)
message_plaintext = pack("!H1000s", len(message), message)
## Generate a fresh public key
private_key = G.order().random()
client_public_key = private_key * G.generator()
## ADD CODE HERE
return NHopMixMessage(client_public_key, hmacs, address_cipher, message_cipher)
示例13: setup
# 需要导入模块: from petlib.ec import EcGroup [as 别名]
# 或者: from petlib.ec.EcGroup import order [as 别名]
def setup():
"""Generates the Cryptosystem Parameters."""
G = EcGroup(nid=713)
g = G.hash_to_point(b"g")
h = G.hash_to_point(b"h")
o = G.order()
return (G, g, h, o)
示例14: setup_ggm
# 需要导入模块: from petlib.ec import EcGroup [as 别名]
# 或者: from petlib.ec.EcGroup import order [as 别名]
def setup_ggm(nid = 713):
"""Generates the parameters for an EC group nid"""
G = EcGroup(nid)
g = G.hash_to_point(b"g")
h = G.hash_to_point(b"h")
o = G.order()
return (G, g, h, o)
示例15: setup
# 需要导入模块: from petlib.ec import EcGroup [as 别名]
# 或者: from petlib.ec.EcGroup import order [as 别名]
def setup():
""" Generates the Cryptosystem Parameters. """
G = EcGroup(nid=713)
g = G.hash_to_point(b"g")
hs = [G.hash_to_point(("h%s" % i).encode("utf8")) for i in range(4)]
o = G.order()
return (G, g, hs, o)