Commit 9210115e authored by nextime's avatar nextime

Fixed DMHash* functions to comply with C strlen() that use null terminated strings

parent 40418db6
......@@ -46,8 +46,12 @@ def DMHash128(data):
reshash=copy.deepcopy(DMHASH)
i=0
while(len(data)<16):
data+=struct.pack('B', struct.unpack('B', data[i])[0]^struct.unpack('B', data[len(data)-1])[0])
#data+=struct.pack('B', struct.unpack('B', data[i])[0]^struct.unpack('B', data[len(data)-1])[0])
data+=struct.pack('<B', struct.unpack('<B', data[i])[0]^struct.unpack('<B', data[len(data)-1] if ord(data[len(data)-1]) else data[len(data)-2])[0])
i+=1
if not ord(data[len(data)-1]):
data=data[:-1]
data=struct.unpack('<4I', data[:16])
i=0
while(i<4):
......@@ -63,8 +67,12 @@ def DMHash256(data):
reshash+=reshash
i=0
while(len(data)<32):
data+=struct.pack('B', struct.unpack('B', data[i])[0]^struct.unpack('B', data[len(data)-1])[0])
#data+=struct.pack('B', struct.unpack('B', data[i])[0]^struct.unpack('B', data[len(data)-1])[0])
data+=struct.pack('<B', struct.unpack('<B', data[i])[0]^struct.unpack('<B', data[len(data)-1] if ord(data[len(data)-1]) else data[len(data)-2])[0])
i+=1
if not ord(data[len(data)-1]):
data=data[:-1]
data=struct.unpack('<8I', data[:32])
i=0
while(i<8):
......
......@@ -216,8 +216,10 @@ class IkaPacket(object):
epoch=None
enctype=C.IKAP_ENC_AES256
memkey=DEFKEY
memiv=DEFIV
def __init__(self, hdr=None):
def __init__(self, hdr=None, memkey=False, memiv=False):
if not hdr:
self.hdr=IkaPacketHeader()
self.hdr.enctype=C.IKAP_ENC_AES256
......@@ -228,6 +230,11 @@ class IkaPacket(object):
self.setArg(self.arg)
self.setEncType(self.enctype)
self.epoch=self.hdr.epoch
if memkey:
self.setMemKey(memkey)
self.setMemIV(pwgen.generateIV128(memkey))
if memiv:
self.setMemIV(memiv)
......@@ -278,16 +285,20 @@ class IkaPacket(object):
def setMemkey(self, memkey):
self.memkey=memkey
def setMemIV(self, memiv):
self.memiv=memiv
def generateKey(self):
self.hdr.key = struct.unpack('<4L', pwgen.GenerateHexKey(16))
self.calculateChecksum()
def _aes(self):
# XXX Gestire differenti encryption
aeshdr=AES256(struct.unpack('<8L', DEFKEY), struct.unpack('<4L', DEFIV))
aeshdr=AES256(struct.unpack('<8L', self.memkey), struct.unpack('<4L', self.memiv))
aesdata=AES256(struct.unpack('<8L', DEFKEY), struct.unpack('<4L', DEFIV))
aesdata.iv=self.hdr.key
#aesdata=AES256(struct.unpack('<8L', memkey), struct.unpack('<4L', memiv))
#aesdata.iv=self.hdr.key
aesdata=AES256(struct.unpack('<8L', self.memkey), self.hdr.key)
aeshdr.setCleanData(self.hdr.tobytes())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment