Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
print "C public: \t%s\nC exp: \t%s" % (b85encode(pC), b85encode(eC))
print
pAB = nacl.crypto_scalarmult_curve25519(eB, pA)
print "public AB", b85encode(pAB)
pBA = nacl.crypto_scalarmult_curve25519(eA, pB)
print "public BA", b85encode(pBA)
pCA = nacl.crypto_scalarmult_curve25519(eA, pC)
print "public CA", b85encode(pCA)
print
key = nacl.crypto_scalarmult_curve25519(eB, pCA)
print "key: \t%s" % (b85encode(key))
key = nacl.crypto_scalarmult_curve25519(eC, pBA)
print "key: \t%s" % (b85encode(key))
key = nacl.crypto_scalarmult_curve25519(eC, pAB)
print "key: \t%s" % (b85encode(key))
print "B public: \t%s\nB exp: \t%s" % (b85encode(pB), b85encode(eB))
eC = nacl.randombytes(nacl.crypto_scalarmult_curve25519_BYTES)
pC = nacl.crypto_scalarmult_curve25519_base(eC)
print "C public: \t%s\nC exp: \t%s" % (b85encode(pC), b85encode(eC))
print
pAB = nacl.crypto_scalarmult_curve25519(eB, pA)
print "public AB", b85encode(pAB)
pBA = nacl.crypto_scalarmult_curve25519(eA, pB)
print "public BA", b85encode(pBA)
pCA = nacl.crypto_scalarmult_curve25519(eA, pC)
print "public CA", b85encode(pCA)
print
key = nacl.crypto_scalarmult_curve25519(eB, pCA)
print "key: \t%s" % (b85encode(key))
key = nacl.crypto_scalarmult_curve25519(eC, pBA)
print "key: \t%s" % (b85encode(key))
key = nacl.crypto_scalarmult_curve25519(eC, pAB)
print "key: \t%s" % (b85encode(key))
def finish(self,point):
self.secret = nacl.crypto_scalarmult_curve25519(self.key, point)
return self.secret
eA = nacl.randombytes(nacl.crypto_scalarmult_curve25519_BYTES)
pA = nacl.crypto_scalarmult_curve25519_base(eA)
print "A public: \t%s\nA exp: \t%s" % (b85encode(pA), b85encode(eA))
eB = nacl.randombytes(nacl.crypto_scalarmult_curve25519_BYTES)
pB = nacl.crypto_scalarmult_curve25519_base(eB)
print "B public: \t%s\nB exp: \t%s" % (b85encode(pB), b85encode(eB))
eC = nacl.randombytes(nacl.crypto_scalarmult_curve25519_BYTES)
pC = nacl.crypto_scalarmult_curve25519_base(eC)
print "C public: \t%s\nC exp: \t%s" % (b85encode(pC), b85encode(eC))
print
pAB = nacl.crypto_scalarmult_curve25519(eB, pA)
print "public AB", b85encode(pAB)
pBA = nacl.crypto_scalarmult_curve25519(eA, pB)
print "public BA", b85encode(pBA)
pCA = nacl.crypto_scalarmult_curve25519(eA, pC)
print "public CA", b85encode(pCA)
print
key = nacl.crypto_scalarmult_curve25519(eB, pCA)
print "key: \t%s" % (b85encode(key))
key = nacl.crypto_scalarmult_curve25519(eC, pBA)
print "key: \t%s" % (b85encode(key))
key = nacl.crypto_scalarmult_curve25519(eC, pAB)
print "key: \t%s" % (b85encode(key))
def _3user():
eA = nacl.randombytes(nacl.crypto_scalarmult_curve25519_BYTES)
pA = nacl.crypto_scalarmult_curve25519_base(eA)
print "A public: \t%s\nA exp: \t%s" % (b85encode(pA), b85encode(eA))
eB = nacl.randombytes(nacl.crypto_scalarmult_curve25519_BYTES)
pB = nacl.crypto_scalarmult_curve25519_base(eB)
print "B public: \t%s\nB exp: \t%s" % (b85encode(pB), b85encode(eB))
eC = nacl.randombytes(nacl.crypto_scalarmult_curve25519_BYTES)
pC = nacl.crypto_scalarmult_curve25519_base(eC)
print "C public: \t%s\nC exp: \t%s" % (b85encode(pC), b85encode(eC))
print
pAB = nacl.crypto_scalarmult_curve25519(eB, pA)
print "public AB", b85encode(pAB)
pBA = nacl.crypto_scalarmult_curve25519(eA, pB)
print "public BA", b85encode(pBA)
pCA = nacl.crypto_scalarmult_curve25519(eA, pC)
print "public CA", b85encode(pCA)
print
key = nacl.crypto_scalarmult_curve25519(eB, pCA)
print "key: \t%s" % (b85encode(key))
key = nacl.crypto_scalarmult_curve25519(eC, pBA)
print "key: \t%s" % (b85encode(key))
key = nacl.crypto_scalarmult_curve25519(eC, pAB)
print "key: \t%s" % (b85encode(key))
eC = nacl.randombytes(nacl.crypto_scalarmult_curve25519_BYTES)
pC = nacl.crypto_scalarmult_curve25519_base(eC)
print "C public: \t%s\nC exp: \t%s" % (b85encode(pC), b85encode(eC))
print
pAB = nacl.crypto_scalarmult_curve25519(eB, pA)
print "public AB", b85encode(pAB)
pBA = nacl.crypto_scalarmult_curve25519(eA, pB)
print "public BA", b85encode(pBA)
pCA = nacl.crypto_scalarmult_curve25519(eA, pC)
print "public CA", b85encode(pCA)
print
key = nacl.crypto_scalarmult_curve25519(eB, pCA)
print "key: \t%s" % (b85encode(key))
key = nacl.crypto_scalarmult_curve25519(eC, pBA)
print "key: \t%s" % (b85encode(key))
key = nacl.crypto_scalarmult_curve25519(eC, pAB)
print "key: \t%s" % (b85encode(key))
def mpecdh(self, keyring = []):
if self.secret: return self.secret
if not self.key:
self.key = nacl.randombytes(nacl.crypto_scalarmult_curve25519_BYTES)
keyring = [nacl.crypto_scalarmult_curve25519(self.key, public)
for public in keyring]
keyring.append(nacl.crypto_scalarmult_curve25519_base(self.key))
if len(keyring) == self.peers: # we are last, remove our own secret
self.secret = keyring[0]
keyring = keyring[1:]
else:
self.secret = nacl.crypto_scalarmult_curve25519(self.key, keyring[0])
keyring = [nacl.crypto_scalarmult_curve25519(self.key, public)
for public in keyring[1:]]
clearmem(self.key)
self.key = None
self.next.mpecdh(keyring)
def receive(self, cipher, nonce):
# decrypt the packet
plain = self.decrypt(cipher, nonce)
# update context
self.peer_pub=plain[:nacl.crypto_scalarmult_curve25519_BYTES]
if self.e_out != ('\0' * nacl.crypto_scalarmult_curve25519_BYTES):
dh2=plain[nacl.crypto_scalarmult_curve25519_BYTES:nacl.crypto_scalarmult_curve25519_BYTES*2]
self.out_k = nacl.crypto_scalarmult_curve25519(self.e_out, dh2)
return plain[nacl.crypto_scalarmult_curve25519_BYTES*2:]
def dh3_handler(public, exp):
# finishes the 3 step DH key exchange by combining the public
# component of the peer, generated in the 2nd step by the peer,
# using the exponent generated when the exchange was initiated.
secret = nacl.crypto_scalarmult_curve25519(exp, public)
return secret
def mpecdh2(self, keyring):
self.secret = nacl.crypto_scalarmult_curve25519(self.key, keyring[0])
keyring = [nacl.crypto_scalarmult_curve25519(self.key, public)
for public in keyring[1:]]
return keyring