Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
D
dmlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
domotika
dmlib
Commits
9210115e
Commit
9210115e
authored
Feb 11, 2014
by
nextime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed DMHash* functions to comply with C strlen() that use null terminated strings
parent
40418db6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
6 deletions
+25
-6
dmcrypt.py
dmlib/dmcrypt.py
+10
-2
ikaprotocol.py
dmlib/ikaprotocol.py
+15
-4
No files found.
dmlib/dmcrypt.py
View file @
9210115e
...
@@ -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
):
...
...
dmlib/ikaprotocol.py
View file @
9210115e
...
@@ -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
())
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment