Moving echo-script related code into suitable directory

Adding Empty class and switching some Nones to it where required by specification
Some additions to CipherState
This commit is contained in:
Piotr Lizonczyk
2017-05-09 19:04:13 +02:00
parent 2bfc10e080
commit 8cddef8ae5
5 changed files with 68 additions and 65 deletions

View File

@@ -1,49 +1,2 @@
from enum import Enum
class PSK(Enum):
PSK_DISABLED = 0x00
PSK_ENABLED = 0x01
class PATTERN(Enum):
PATTERN_NN = 0x00
PATTERN_KN = 0x01
PATTERN_NK = 0x02
PATTERN_KK = 0x03
PATTERN_NX = 0x04
PATTERN_KX = 0x05
PATTERN_XN = 0x06
PATTERN_IN = 0x07
PATTERN_XK = 0x08
PATTERN_IK = 0x09
PATTERN_XX = 0x0A
PATTERN_IX = 0x0B
PATTERN_HFS = 0x80
class CIPHER(Enum):
CIPHER_CHACHAPOLY = 0x00
CIPHER_AESGCM = 0x01
class DH(Enum):
DH_25519 = 0x00
DH_448 = 0x01
DH_NEWHOPE = 0x02
DH_MASK = 0x0F
class HYBRID(Enum):
HYBRID_NONE = 0x00
HYBRID_25519 = 0x10
HYBRID_448 = 0x20
HYBRID_NEWHOPE = 0x30
HYBRID_MASK = 0xF0
class HASH(Enum):
HASH_SHA256 = 0x00
HASH_SHA512 = 0x01
HASH_BLAKE2s = 0x02
HASH_BLAKE2b = 0x03
class Empty:
pass

0
noise/echo/__init__.py Normal file
View File

View File

@@ -1,12 +1,8 @@
import base64
import socket
import logging
import socket
import struct
import nacl
from noise.constants import *
from noise.echo.echo_constants import PSK, PATTERN, CIPHER, DH, HASH
logger = logging.getLogger(__name__)

View File

@@ -0,0 +1,49 @@
from enum import Enum
class PSK(Enum):
PSK_DISABLED = 0x00
PSK_ENABLED = 0x01
class PATTERN(Enum):
PATTERN_NN = 0x00
PATTERN_KN = 0x01
PATTERN_NK = 0x02
PATTERN_KK = 0x03
PATTERN_NX = 0x04
PATTERN_KX = 0x05
PATTERN_XN = 0x06
PATTERN_IN = 0x07
PATTERN_XK = 0x08
PATTERN_IK = 0x09
PATTERN_XX = 0x0A
PATTERN_IX = 0x0B
PATTERN_HFS = 0x80
class CIPHER(Enum):
CIPHER_CHACHAPOLY = 0x00
CIPHER_AESGCM = 0x01
class DH(Enum):
DH_25519 = 0x00
DH_448 = 0x01
DH_NEWHOPE = 0x02
DH_MASK = 0x0F
class HYBRID(Enum):
HYBRID_NONE = 0x00
HYBRID_25519 = 0x10
HYBRID_448 = 0x20
HYBRID_NEWHOPE = 0x30
HYBRID_MASK = 0xF0
class HASH(Enum):
HASH_SHA256 = 0x00
HASH_SHA512 = 0x01
HASH_BLAKE2s = 0x02
HASH_BLAKE2b = 0x03

View File

@@ -1,25 +1,29 @@
from noise.constants import Empty
class CipherState(object):
"""
"""
def __init__(self):
self.k = None
self.k = Empty()
self.n = None
def initialize_key(self, key):
"""
:param key:
:param key:
:return:
"""
pass
self.k = key
self.n = 0
def has_key(self):
"""
:return:
:return: True if self.k is not an instance of Empty
"""
return self.k is not None
return not isinstance(self.k, Empty)
def encrypt_with_ad(self, ad, plaintext):
"""
@@ -98,13 +102,14 @@ class HandshakeState(object):
"""
def __init__(self):
self.symmetric_state = Empty()
self.handshake_pattern = None
self.initiator = None
self.prologue = b''
self.s = None
self.e = None
self.rs = None
self.re = None
self.s = Empty()
self.e = Empty()
self.rs = Empty()
self.re = Empty()
def initialize(self, handshake_pattern, initiator, prologue=b'', s=None, e=None, rs=None, re=None):
"""