Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OTRv4
otrv4_reference_design
Commits
da7453ad
Commit
da7453ad
authored
Nov 11, 2016
by
Fan Jiang
Browse files
change some senarios
parent
166d9880
Changes
1
Hide whitespace changes
Inline
Side-by-side
double_ratchet.py
View file @
da7453ad
...
...
@@ -35,23 +35,37 @@ class Entity:
self
.
rid
+=
1
self
.
mid
=
0
self
.
derive
()
print
self
.
name
,
'
\t
next our_dh:'
,
self
.
our_dh
,
'key:'
,
self
.
our_dh
[
1
]
+
self
.
their_dh
print
self
.
name
,
'
\t
next our_dh:'
,
self
.
our_dh
self
.
r_flag
=
False
if
self
.
role
==
'A'
:
self
.
Ca
[
self
.
rid
][
'chain'
].
append
(
self
.
mid
)
else
:
self
.
Cb
[
self
.
rid
][
'chain'
].
append
(
self
.
mid
)
if
self
.
role
==
'A'
:
self
.
Ca
[
self
.
rid
][
'chain'
].
append
(
self
.
Ca
[
self
.
rid
][
'chain'
][
self
.
mid
-
1
]
+
1
)
else
:
self
.
Cb
[
self
.
rid
][
'chain'
].
append
(
self
.
Cb
[
self
.
rid
][
'chain'
][
self
.
mid
-
1
]
+
1
)
toSend
=
Msg
(
self
.
name
,
self
.
rid
,
self
.
mid
,
self
.
our_dh
[
1
])
self
.
mid
+=
1
print
self
.
name
,
'
\t
sending: '
,
toSend
.
__dict__
print
self
.
name
,
'
\t
key:'
,
self
.
our_dh
[
1
],
'+'
,
self
.
their_dh
,
'='
,
self
.
our_dh
[
1
]
+
self
.
their_dh
return
toSend
def
receive
(
self
,
m
):
print
self
.
name
,
"
\t
receive: "
,
m
.
__dict__
if
m
.
rid
>=
self
.
rid
:
if
m
.
rid
==
self
.
rid
+
1
:
print
self
.
name
,
"
\t
key: "
,
self
.
our_dh
[
1
],
'+'
,
self
.
their_dh
,
'='
,
self
.
our_dh
[
1
]
+
self
.
their_dh
self
.
rid
+=
1
self
.
their_dh
=
m
.
dh
self
.
r_flag
=
True
print
self
.
name
,
"
\t
key: "
,
self
.
our_dh
[
1
]
+
self
.
their_dh
self
.
derive
()
else
:
if
self
.
role
==
'B'
:
self
.
Ca
[
self
.
rid
][
'chain'
].
append
(
self
.
Ca
[
self
.
rid
][
'chain'
][
m
.
mid
-
1
]
+
1
)
else
:
self
.
Cb
[
self
.
rid
][
'chain'
].
append
(
self
.
Cb
[
self
.
rid
][
'chain'
][
m
.
mid
-
1
]
+
1
)
if
self
.
role
==
'B'
:
c
=
self
.
Ca
[
self
.
rid
][
'chain'
][
m
.
mid
]
else
:
c
=
self
.
Cb
[
self
.
rid
][
'chain'
][
m
.
mid
]
print
self
.
name
,
"
\t
chain key: "
,
c
def
genDH
(
self
):
self
.
our_dh
=
[
random
.
randint
(
0
,
1024
),
random
.
randint
(
0
,
1024
)]
...
...
@@ -59,8 +73,8 @@ class Entity:
def
derive
(
self
):
i
=
self
.
rid
self
.
R
.
append
(
i
)
self
.
Ca
.
append
({
'rid'
:
i
,
'chain'
:[]})
self
.
Cb
.
append
({
'rid'
:
i
,
'chain'
:[]})
self
.
Ca
.
append
({
'rid'
:
i
,
'chain'
:[
0
]})
self
.
Cb
.
append
({
'rid'
:
i
,
'chain'
:[
100
]})
def
initialize
():
print
"Initializing"
...
...
@@ -83,17 +97,21 @@ def initialize():
return
a
,
b
a
,
b
=
initialize
()
m1
=
a
.
send
()
m2
=
b
.
send
()
a
.
receive
(
m2
)
b
.
receive
(
m1
)
a
.
receive
(
b
.
send
())
a
.
receive
(
b
.
send
())
a
.
receive
(
b
.
send
())
a
.
receive
(
b
.
send
())
b
.
receive
(
a
.
send
())
b
.
receive
(
a
.
send
())
b
.
receive
(
a
.
send
())
a
.
receive
(
b
.
send
())
a
.
receive
(
b
.
send
())
a
.
receive
(
b
.
send
())
a
.
receive
(
b
.
send
())
b
.
receive
(
a
.
send
())
b
.
receive
(
a
.
send
())
b
.
receive
(
a
.
send
())
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