示例#1
0
文件: test.py 项目: david415/pynacl-1
    def test_known(self):
        sk3 = binascii.a2b_hex("5305ca1802ea41cd48f904e85d97868c"
                               "c0f30819473cd07727d7c44974bc8e58")
        pk3 = nacl.crypto_scalarmult_curve25519_base(sk3)
        sk4 = binascii.a2b_hex("fba6870b71790aa6ca40ca1fe29533a4"
                               "ab09d401b3b2c624ad15d615454ba27a")
        pk4 = nacl.crypto_scalarmult_curve25519_base(sk4)

        s1 = nacl.crypto_scalarmult_curve25519(sk3, pk4)
        s2 = nacl.crypto_scalarmult_curve25519(sk4, pk3)
        expected = ("63b564b8218367b7d8d700cdc0d2e23a"
                    "65ef73905606f9c2e23b00d818c16a7e")
        self.assertEqual(binascii.b2a_hex(s1), expected)
        self.assertEqual(binascii.b2a_hex(s2), expected)
示例#2
0
    def test_known(self):
        sk3 = binascii.a2b_hex("5305ca1802ea41cd48f904e85d97868c"
                               "c0f30819473cd07727d7c44974bc8e58")
        pk3 = nacl.crypto_scalarmult_curve25519_base(sk3)
        sk4 = binascii.a2b_hex("fba6870b71790aa6ca40ca1fe29533a4"
                               "ab09d401b3b2c624ad15d615454ba27a")
        pk4 = nacl.crypto_scalarmult_curve25519_base(sk4)

        s1 = nacl.crypto_scalarmult_curve25519(sk3, pk4)
        s2 = nacl.crypto_scalarmult_curve25519(sk4, pk3)
        expected = ("63b564b8218367b7d8d700cdc0d2e23a"
                    "65ef73905606f9c2e23b00d818c16a7e")
        self.assertEqual(binascii.b2a_hex(s1), expected)
        self.assertEqual(binascii.b2a_hex(s2), expected)
示例#3
0
    def test_nacl_scalarmult_curve25519_base(self):
        try:
            import nacl

            while True:
                private = urandom(32)
                (v, public, representative) = elligator.scalarbasemult(private)
                if v:
                    break

            public2 = nacl.crypto_scalarmult_curve25519_base(private)
            self.assertEqual(public, public2)
        except ImportError:
            raise ImportError('Can\'t import TweetNaCl')
示例#4
0
        def __init__(self, query = None, consumer = None):
                """
                """

                asyncore.dispatcher.__init__(self)

                self.consumer  = consumer
                self.query     = query

                if not len(self.query.transport):
                        raise Exception("XXX")
                (self.ip, self.remotepk, self.zone, self.timeout) = self.query.transport[0]
                self.query.transport = self.query.transport[1:]
        
                self.dnsid = nacl.randombytes(2)
                #dnscurve
                self.nonce = ""
                self.mypk  = ""
                self.txtid = ""
                self.key   = ""
                if self.remotepk:
                        self.nonce = nacl.randombytes(12)
                        mysk       = nacl.randombytes(32)
                        self.mypk  = nacl.crypto_scalarmult_curve25519_base(mysk)
                        self.key   = nacl.crypto_box_curve25519xsalsa20poly1305_beforenm(self.remotepk, mysk)
                        if self.zone:
                                self.txtid = nacl.randombytes(2)

                self.start     = time.time()
                self.connected = False
                self.response  = ""

                if self.remotepk:
                        self.request = self.query.dnscurve_packet(self.zone, self.mypk, self.key, self.nonce, self.dnsid, self.txtid)
                else:
                        self.request = self.query.packet(self.dnsid)

                if self.query.tcp:
                        self.request = "%s%s" % (struct.pack('>H', len(self.request)), self.request)

                try:
                        self.bindconnect()
                except socket.error:
                        self.handle_error()
示例#5
0
文件: test.py 项目: david415/pynacl-1
 def setUp(self):
     self.sk1 = nacl.randombytes(nacl.crypto_scalarmult_curve25519_BYTES)
     self.pk1 = nacl.crypto_scalarmult_curve25519_base(self.sk1)
     self.sk2 = nacl.randombytes(nacl.crypto_scalarmult_curve25519_BYTES)
     self.pk2 = nacl.crypto_scalarmult_curve25519_base(self.sk2)
示例#6
0
def keygen():
        sk = os.urandom(32)
        pk = nacl.crypto_scalarmult_curve25519_base(sk)
        noncekey = os.urandom(16)
        return (pk, sk, noncekey)
示例#7
0
 def setUp(self):
     self.sk1 = nacl.randombytes(nacl.crypto_scalarmult_curve25519_BYTES)
     self.pk1 = nacl.crypto_scalarmult_curve25519_base(self.sk1)
     self.sk2 = nacl.randombytes(nacl.crypto_scalarmult_curve25519_BYTES)
     self.pk2 = nacl.crypto_scalarmult_curve25519_base(self.sk2)
示例#8
0
        pubkey = pubkey.decode('hex')
        if len(pubkey) != 32:
            raise 'Invalid DNSCurve public key'
    except TypeError, e:
        pubkey = dnscurve.dnscurve_getpubkey(dns.dns_domain_fromdot(pubkey))
        if not pubkey:
            raise 'Invalid DNSCurve public key'

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect((server, 53))

query0 = dns.dns_build_query(type, name)
if pubkey:
    nonce1 = open('/dev/urandom').read(12)
    mykey = open('/dev/urandom').read(32)
    mypubkey = nacl.crypto_scalarmult_curve25519_base(mykey)
    box = nacl.crypto_box_curve25519xsalsa20poly1305(query0, nonce1 + 12 * '\0', pubkey, mykey)
    #XXX - TODO
    #key = nacl.crypto_box_curve25519xsalsa20poly1305_beforenm(pubkey, mykey)
    #box = nacl.crypto_box_curve25519xsalsa20poly1305_afternm(query0, nonce1 + 12 * '\0', key)
    if zone is not False:
        query = dnscurve.dnscurve_encode_txt_query(nonce1, box, mypubkey, zone)
    else:
        query = dnscurve.dnscurve_encode_streamlined_query(nonce1, box, mypubkey)
else:
    query = query0
s.send(query)

response = s.recv(4096)
if pubkey:
    if zone is not False: