本文整理汇总了Python中anon_crypto.AnonCrypto.sign方法的典型用法代码示例。如果您正苦于以下问题:Python AnonCrypto.sign方法的具体用法?Python AnonCrypto.sign怎么用?Python AnonCrypto.sign使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类anon_crypto.AnonCrypto
的用法示例。
在下文中一共展示了AnonCrypto.sign方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: unpickle_pub_keys
# 需要导入模块: from anon_crypto import AnonCrypto [as 别名]
# 或者: from anon_crypto.AnonCrypto import sign [as 别名]
def unpickle_pub_keys(self, msgs):
""" Leader uses this method to unpack keys from other nodes """
addrs = []
key_dict = {}
key_dict[self.id] = (
self.key_from_file(1),
AnonCrypto.sign(self.id, self.key1, self.key_from_file(2)))
for data in msgs:
(rem_id, rem_round, rem_ip, rem_port,
rem_key1, rem_key2) = marshal.loads(data)
self.debug("Unpickled msg from node %d" % (rem_id))
if rem_round != self.round_id:
raise RuntimeError, "Mismatched round numbers! (mine: %d, other: %d)" % (
self.round_id, rem_round)
k1 = AnonCrypto.pub_key_from_str(rem_key1)
self.pub_keys[rem_id] = (k1, k1)
k2 = AnonCrypto.pub_key_from_str(AnonCrypto.verify(self.pub_keys, rem_key2))
self.pub_keys[rem_id] = (k1, k2)
addrs.append((rem_ip, rem_port))
key_dict[rem_id] = (rem_key1, rem_key2)
return (marshal.dumps((self.round_id, key_dict)), addrs)
示例2: broadcast_to_all_nodes
# 需要导入模块: from anon_crypto import AnonCrypto [as 别名]
# 或者: from anon_crypto.AnonCrypto import sign [as 别名]
def broadcast_to_all_nodes(self, msg, signed = True):
if not self.am_leader():
raise RuntimeError, 'Only leader can broadcast'
if signed: outmsg = AnonCrypto.sign(self.id, self.key1, msg)
else: outmsg = msg
AnonNet.broadcast_using(self.sockets, AnonNet.send_to_socket, outmsg)
示例3: phase1_msg
# 需要导入模块: from anon_crypto import AnonCrypto [as 别名]
# 或者: from anon_crypto.AnonCrypto import sign [as 别名]
def phase1_msg(self):
""" Message that non-leader nodes send to the leader. """
return marshal.dumps(
(self.id,
self.round_id,
self.ip,
self.port,
self.key_from_file(1),
AnonCrypto.sign(self.id, self.key1, self.key_from_file(2))))
return marshal.dumps((self.round_id, newdict))
示例4: run_phase4
# 需要导入模块: from anon_crypto import AnonCrypto [as 别名]
# 或者: from anon_crypto.AnonCrypto import sign [as 别名]
def run_phase4(self):
self.advance_phase()
if self.am_leader():
self.debug("Leader broadcasting ciphers to all nodes")
self.broadcast_to_all_nodes(marshal.dumps(self.final_ciphers))
self.debug("Cipher set len %d" % (len(self.final_ciphers)))
else:
""" Get C' ciphertexts from leader. """
self.final_ciphers = marshal.loads(self.recv_from_leader())
"""
self.final_ciphers holds an array of
pickled (round_id, cipher_prime) tuples
"""
my_cipher_str = marshal.dumps((self.round_id, self.cipher_prime))
go = False
if my_cipher_str in self.final_ciphers:
self.info("Found my ciphertext in set")
go = True
else:
self.critical("ABORT! My ciphertext is not in set!")
self.debug(self.final_ciphers)
go = False
raise RuntimeError, "Protocol violation: My ciphertext is missing!"
hashval = AnonCrypto.hash_list(self.final_ciphers)
go_msg = marshal.dumps((
self.id,
self.round_id,
go,
hashval))
go_data = ''
if self.am_leader():
""" Collect go msgs """
data = self.recv_from_all(False)
""" Add leader's signed GO message to set """
data.append(AnonCrypto.sign(self.id, self.key1, go_msg))
go_data = marshal.dumps((data))
self.broadcast_to_all_nodes(go_data)
else:
""" Send go msg to leader """
self.send_to_leader(go_msg)
go_data = self.recv_from_leader()
self.check_go_data(hashval, go_data)
self.info("All nodes report GO")
return
示例5: run_phase5
# 需要导入模块: from anon_crypto import AnonCrypto [as 别名]
# 或者: from anon_crypto.AnonCrypto import sign [as 别名]
def run_phase5(self):
self.advance_phase()
self.info("Starting phase 5")
#Create list of outputs and individual signature
addresses=self.get_list_outputs()
self.my_sign = AnonCrypto.sign(self.id, self.key1, marshal.dumps((self.id, addresses)))
#Everybody sends her own signature to the leader.
if self.am_leader():
all_sign = self.recv_from_all()
self.debug("Received all signatures from participants")
else:
self.send_to_leader(marshal.dumps((self.round_id,
self.my_sign)))
self.debug("Sent signature to leader")
#The leader broadcast the list of signatures and every participant checks if her signature
# is included
if self.am_leader():
self.broadcast_to_all_nodes(marshal.dumps(marshal.dumps((self.id, all_sign))))
self.debug("All signatures sent to participants")
self.debug("Sign = TRUE")
else:
all_sign = marshal.loads(self.recv_from_socket(self.leader_socket))
self.debug("Received signature list")
check_sig = marshal.dumps((self.round_id,
self.my_sign))
if check_sig in all_sign:
self.info("Found my signature in set")
self.debug("Sign = TRUE")
self.critical("Sign = TRUE")
self.send_to_leader(marshal.dumps((self.id, "input address")))
else:
self.critical("ABORT! My signature is not in set!")
self.debug(self.final_ciphers)
self.critical("Sign = FALSE")
raise RuntimeError, "Protocol violation: My signature is missing!"
#The leader waits for ack of every participant before creating the Bitcoin transaction
if self.am_leader():
""" Leader waits for ciphers from member N. """
self.final_acks = self.recv_from_all()
self.debug("Got acks from other nodes")
self.critical("Leader: Bitcoin transaction finished")
示例6: run_phase5
# 需要导入模块: from anon_crypto import AnonCrypto [as 别名]
# 或者: from anon_crypto.AnonCrypto import sign [as 别名]
def run_phase5(self):
self.advance_phase()
mykeystr = AnonCrypto.sign(self.id, self.key1, marshal.dumps((
self.id,
self.round_id,
AnonCrypto.priv_key_to_str(self.key2))))
if self.am_leader():
data = self.recv_from_all()
""" Add leader's signed key to set """
data.append(mykeystr)
self.debug("Key data... len = %d" % len(data))
self.broadcast_to_all_nodes(marshal.dumps(data))
else:
self.info('Sending key to leader')
self.send_to_leader(mykeystr)
data = marshal.loads(self.recv_from_leader())
self.info("Got key set from leader, len = %d" % len(data))
self.decrypt_ciphers(data)
self.info('Decrypted ciphertexts')
示例7: send_to_socket
# 需要导入模块: from anon_crypto import AnonCrypto [as 别名]
# 或者: from anon_crypto.AnonCrypto import sign [as 别名]
def send_to_socket(self, sock, msg, signed=True):
if signed:
outmsg = AnonCrypto.sign(self.id, self.key1, msg)
else:
outmsg = msg
AnonNet.send_to_socket(sock, outmsg)
示例8: send_to_addr
# 需要导入模块: from anon_crypto import AnonCrypto [as 别名]
# 或者: from anon_crypto.AnonCrypto import sign [as 别名]
def send_to_addr(self, ip, port, msg, signed = True):
if signed: outmsg = AnonCrypto.sign(self.id, self.key1, msg)
else: outmsg = msg
AnonNet.send_to_addr(ip, port, outmsg)