* Adding handshake patterns

* Adding token constants for handshake patterns
This commit is contained in:
Piotr Lizonczyk
2017-08-06 00:04:16 +02:00
parent b7b9e29c27
commit bf36429fd7
2 changed files with 171 additions and 0 deletions

View File

@@ -1,2 +1,12 @@
class Empty:
pass
# Handshake pattern tokens
TOKEN_E = 'e'
TOKEN_S = 's'
TOKEN_EE = 'ee'
TOKEN_ES = 'es'
TOKEN_SE = 'se'
TOKEN_SS = 'ss'
TOKEN_PSK = 'psk'

161
noise/patterns.py Normal file
View File

@@ -0,0 +1,161 @@
from noise.constants import TOKEN_E, TOKEN_S, TOKEN_EE, TOKEN_ES, TOKEN_SE, TOKEN_SS, TOKEN_PSK
class Pattern(object):
"""
TODO document
"""
# As per specification, if both parties have pre-messages, the initiator is listed first. To reduce complexity,
# pre_messages shall be a list of two lists:
# the first for the initiator's pre-messages, the second for the responder
pre_messages = [
[],
[]
]
# TODO Comment
tokens = []
# One-way patterns
class PatternN(Pattern):
pre_messages = [
[],
[TOKEN_S]
]
tokens = [
[TOKEN_E, TOKEN_ES]
]
class PatternK(Pattern):
pre_messages = [
[TOKEN_S],
[TOKEN_S]
]
tokens = [
[TOKEN_E, TOKEN_ES, TOKEN_SS]
]
class PatternX(Pattern):
pre_messages = [
[],
[TOKEN_S]
]
tokens = [
[TOKEN_E, TOKEN_ES, TOKEN_S, TOKEN_SS]
]
# Interactive patterns
class PatternNN(Pattern):
tokens = [
[TOKEN_E],
[TOKEN_E, TOKEN_EE]
]
class PatternKN(Pattern):
pre_messages = [
[TOKEN_S],
[]
]
tokens = [
[TOKEN_E],
[TOKEN_E, TOKEN_EE, TOKEN_SE]
]
class PatternNK(Pattern):
pre_messages = [
[],
[TOKEN_S]
]
tokens = [
[TOKEN_E, TOKEN_ES],
[TOKEN_E, TOKEN_EE]
]
class PatternKK(Pattern):
pre_messages = [
[TOKEN_S],
[TOKEN_S]
]
tokens = [
[TOKEN_E, TOKEN_ES, TOKEN_SS],
[TOKEN_E, TOKEN_EE, TOKEN_SE]
]
class PatternNX(Pattern):
tokens = [
[TOKEN_E],
[TOKEN_E, TOKEN_EE, TOKEN_S, TOKEN_ES]
]
class PatternKX(Pattern):
pre_messages = [
[TOKEN_S],
[]
]
tokens = [
[TOKEN_E],
[TOKEN_E, TOKEN_EE, TOKEN_SE, TOKEN_S, TOKEN_ES]
]
class PatternXN(Pattern):
tokens = [
[TOKEN_E],
[TOKEN_E, TOKEN_EE],
[TOKEN_S, TOKEN_SE]
]
class PatternIN(Pattern):
tokens = [
[TOKEN_E, TOKEN_S],
[TOKEN_E, TOKEN_EE, TOKEN_SE]
]
class PatternXK(Pattern):
pre_messages = [
[],
[TOKEN_S]
]
tokens = [
[TOKEN_E, TOKEN_ES],
[TOKEN_E, TOKEN_EE],
[TOKEN_S, TOKEN_SE]
]
class PatternIK(Pattern):
pre_messages = [
[],
[TOKEN_S]
]
tokens = [
[TOKEN_E, TOKEN_ES, TOKEN_S, TOKEN_SS],
[TOKEN_E, TOKEN_EE, TOKEN_SE]
]
class PatternXX(Pattern):
tokens = [
[TOKEN_E],
[TOKEN_E, TOKEN_EE, TOKEN_S, TOKEN_ES],
[TOKEN_S, TOKEN_SE]
]
class PatternIX(Pattern):
tokens = [
[TOKEN_E, TOKEN_S],
[TOKEN_E, TOKEN_EE, TOKEN_SE, TOKEN_S, TOKEN_ES]
]