Beispiel #1
0
def _dnskey_to_dsa(key):
    # get T
    t, = struct.unpack(b'B', key[0])
    offset = 1

    # get Q
    new_offset = offset + 20
    q = bn_to_mpi(hex_to_bn(binascii.hexlify(key[offset:new_offset])))
    offset = new_offset

    # get P
    new_offset = offset + 64 + (t << 3)
    p = bn_to_mpi(hex_to_bn(binascii.hexlify(key[offset:new_offset])))
    offset = new_offset

    # get G
    new_offset = offset + 64 + (t << 3)
    g = bn_to_mpi(hex_to_bn(binascii.hexlify(key[offset:new_offset])))
    offset = new_offset

    # get Y
    new_offset = offset + 64 + (t << 3)
    y = bn_to_mpi(hex_to_bn(binascii.hexlify(key[offset:new_offset])))
    offset = new_offset

    # create the DSA public key
    return DSA.pub_key_from_params(p, q, g, y)
Beispiel #2
0
def _dnskey_to_dsa(key):
    # get T
    t = key[0]
    # python3/python2 dual compatibility
    if not isinstance(t, int):
        t = ord(t)
    offset = 1

    # get Q
    new_offset = offset + 20
    q = bn_to_mpi(hex_to_bn(binascii.hexlify(key[offset:new_offset])))
    offset = new_offset

    # get P
    new_offset = offset + 64 + (t << 3)
    p = bn_to_mpi(hex_to_bn(binascii.hexlify(key[offset:new_offset])))
    offset = new_offset

    # get G
    new_offset = offset + 64 + (t << 3)
    g = bn_to_mpi(hex_to_bn(binascii.hexlify(key[offset:new_offset])))
    offset = new_offset

    # get Y
    new_offset = offset + 64 + (t << 3)
    y = bn_to_mpi(hex_to_bn(binascii.hexlify(key[offset:new_offset])))
    offset = new_offset

    # create the DSA public key
    return DSA.pub_key_from_params(p, q, g, y)
Beispiel #3
0
def _dnskey_to_dsa(key):
    # get T
    t, = struct.unpack(b'B',key[0])
    offset = 1

    # get Q
    new_offset = offset+20
    q = bn_to_mpi(hex_to_bn(binascii.hexlify(key[offset:new_offset])))
    offset = new_offset

    # get P
    new_offset = offset+64+(t<<3)
    p = bn_to_mpi(hex_to_bn(binascii.hexlify(key[offset:new_offset])))
    offset = new_offset

    # get G
    new_offset = offset+64+(t<<3)
    g = bn_to_mpi(hex_to_bn(binascii.hexlify(key[offset:new_offset])))
    offset = new_offset

    # get Y
    new_offset = offset+64+(t<<3)
    y = bn_to_mpi(hex_to_bn(binascii.hexlify(key[offset:new_offset])))
    offset = new_offset

    # create the DSA public key
    return DSA.pub_key_from_params(p,q,g,y)
Beispiel #4
0
 def test_pub_key_from_params(self):
     dsa = DSA.gen_params(1024, self.callback)
     dsa.gen_key()
     assert len(dsa) == 1024
     p = dsa.p
     q = dsa.q
     g = dsa.g
     pub = dsa.pub
     dsa2 = DSA.pub_key_from_params(p, q, g, pub)
     assert dsa2.check_key()
     r, s = dsa.sign(self.data)
     assert dsa2.verify(self.data, r, s)
Beispiel #5
0
 def test_pub_key_from_params(self):
     dsa = DSA.gen_params(1024, self.callback)
     dsa.gen_key()
     assert len(dsa) == 1024
     p = dsa.p
     q = dsa.q
     g = dsa.g
     pub = dsa.pub
     dsa2 = DSA.pub_key_from_params(p,q,g,pub)
     assert dsa2.check_key()
     r,s = dsa.sign(self.data)
     assert dsa2.verify(self.data, r, s)
Beispiel #6
0
def _dnskey_to_dsa(key):
    # get T
    t, = struct.unpack(b'B', key[0])
    offset = 1

    # get Q
    new_offset = offset + 20
    q = b''
    for c in key[offset:new_offset]:
        q += b'%02x' % struct.unpack(b'B', c)[0]
    q = bn_to_mpi(hex_to_bn(q))
    offset = new_offset

    # get P
    new_offset = offset + 64 + (t << 3)
    p = b''
    for c in key[offset:new_offset]:
        p += b'%02x' % struct.unpack(b'B', c)[0]
    p = bn_to_mpi(hex_to_bn(p))
    offset = new_offset

    # get G
    new_offset = offset + 64 + (t << 3)
    g = b''
    for c in key[offset:new_offset]:
        g += b'%02x' % struct.unpack(b'B', c)[0]
    g = bn_to_mpi(hex_to_bn(g))
    offset = new_offset

    # get Y
    new_offset = offset + 64 + (t << 3)
    y = b''
    for c in key[offset:new_offset]:
        y += b'%02x' % struct.unpack(b'B', c)[0]
    y = bn_to_mpi(hex_to_bn(y))
    offset = new_offset

    # create the DSA public key
    return DSA.pub_key_from_params(p, q, g, y)
Beispiel #7
0
def _dnskey_to_dsa(key):
    # get T
    t, = struct.unpack(b'B',key[0])
    offset = 1

    # get Q
    new_offset = offset+20
    q = b''
    for c in key[offset:new_offset]:
        q += b'%02x' % struct.unpack(b'B',c)[0]
    q = bn_to_mpi(hex_to_bn(q))
    offset = new_offset

    # get P
    new_offset = offset+64+(t<<3)
    p = b''
    for c in key[offset:new_offset]:
        p += b'%02x' % struct.unpack(b'B',c)[0]
    p = bn_to_mpi(hex_to_bn(p))
    offset = new_offset

    # get G
    new_offset = offset+64+(t<<3)
    g = b''
    for c in key[offset:new_offset]:
        g += b'%02x' % struct.unpack(b'B',c)[0]
    g = bn_to_mpi(hex_to_bn(g))
    offset = new_offset

    # get Y
    new_offset = offset+64+(t<<3)
    y = b''
    for c in key[offset:new_offset]:
        y += b'%02x' % struct.unpack(b'B',c)[0]
    y = bn_to_mpi(hex_to_bn(y))
    offset = new_offset

    # create the DSA public key
    return DSA.pub_key_from_params(p,q,g,y)