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): ...@@ -46,8 +46,12 @@ def DMHash128(data):
reshash=copy.deepcopy(DMHASH) reshash=copy.deepcopy(DMHASH)
i=0 i=0
while(len(data)<16): 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 i+=1
if not ord(data[len(data)-1]):
data=data[:-1]
data=struct.unpack('<4I', data[:16]) data=struct.unpack('<4I', data[:16])
i=0 i=0
while(i<4): while(i<4):
...@@ -63,8 +67,12 @@ def DMHash256(data): ...@@ -63,8 +67,12 @@ def DMHash256(data):
reshash+=reshash reshash+=reshash
i=0 i=0
while(len(data)<32): 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 i+=1
if not ord(data[len(data)-1]):
data=data[:-1]
data=struct.unpack('<8I', data[:32]) data=struct.unpack('<8I', data[:32])
i=0 i=0
while(i<8): while(i<8):
......
...@@ -216,8 +216,10 @@ class IkaPacket(object): ...@@ -216,8 +216,10 @@ class IkaPacket(object):
epoch=None epoch=None
enctype=C.IKAP_ENC_AES256 enctype=C.IKAP_ENC_AES256
memkey=DEFKEY memkey=DEFKEY
memiv=DEFIV
def __init__(self, hdr=None):
def __init__(self, hdr=None, memkey=False, memiv=False):
if not hdr: if not hdr:
self.hdr=IkaPacketHeader() self.hdr=IkaPacketHeader()
self.hdr.enctype=C.IKAP_ENC_AES256 self.hdr.enctype=C.IKAP_ENC_AES256
...@@ -228,6 +230,11 @@ class IkaPacket(object): ...@@ -228,6 +230,11 @@ class IkaPacket(object):
self.setArg(self.arg) self.setArg(self.arg)
self.setEncType(self.enctype) self.setEncType(self.enctype)
self.epoch=self.hdr.epoch 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): ...@@ -278,16 +285,20 @@ class IkaPacket(object):
def setMemkey(self, memkey): def setMemkey(self, memkey):
self.memkey=memkey self.memkey=memkey
def setMemIV(self, memiv):
self.memiv=memiv
def generateKey(self): def generateKey(self):
self.hdr.key = struct.unpack('<4L', pwgen.GenerateHexKey(16)) self.hdr.key = struct.unpack('<4L', pwgen.GenerateHexKey(16))
self.calculateChecksum() self.calculateChecksum()
def _aes(self): def _aes(self):
# XXX Gestire differenti encryption # 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=AES256(struct.unpack('<8L', memkey), struct.unpack('<4L', memiv))
aesdata.iv=self.hdr.key #aesdata.iv=self.hdr.key
aesdata=AES256(struct.unpack('<8L', self.memkey), self.hdr.key)
aeshdr.setCleanData(self.hdr.tobytes()) 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