diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f3f26d1..66a31ff 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -8,7 +8,8 @@ Changelog .. note:: This version is not yet released and is under active development. -* Cryptography requirement updated to the newest version (2.1) - **Python 3.5** is supported again. +* Compatible with revision 33 (doesn't break compatibility with revision 32). +* Cryptography requirement updated to the newest version (2.1.1) - **Python 3.5** is supported again. * Adding sphinx documentation for Read the Docs publication. * Minor fixes for better performance. diff --git a/README.md b/README.md index fc92d6e..06307e2 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ noiseprotocol [![PyPI](https://img.shields.io/pypi/v/noiseprotocol.svg)](https://pypi.python.org/pypi/noiseprotocol) This repository contains source code of **noiseprotocol** - a Python 3 implementation of [Noise Protocol Framework](http://www.noiseprotocol.org/). +Compatible with revisions 32 and 33. ### Warning This package shall not be used (yet) for production purposes. There was little to none peer review done so far. diff --git a/noise/noise_protocol.py b/noise/noise_protocol.py index 7491f60..e067c00 100644 --- a/noise/noise_protocol.py +++ b/noise/noise_protocol.py @@ -102,7 +102,7 @@ class NoiseProtocol(object): self.cipher_state_decrypt = None else: self.cipher_state_encrypt = None - self.handshake_hash = self.symmetric_state.h + self.handshake_hash = self.symmetric_state.get_handshake_hash() del self.handshake_state del self.symmetric_state del self.cipher_state_handshake diff --git a/noise/state.py b/noise/state.py index a006d40..4bffad4 100644 --- a/noise/state.py +++ b/noise/state.py @@ -33,6 +33,9 @@ class CipherState(object): """ return not isinstance(self.k, Empty) + def set_nonce(self, nonce): + self.n = nonce + def encrypt_with_ad(self, ad: bytes, plaintext: bytes) -> bytes: """ If k is non-empty returns ENCRYPT(k, n++, ad, plaintext). Otherwise returns plaintext. @@ -148,6 +151,9 @@ class SymmetricState(object): # Calls InitializeKey(temp_k). self.cipher_state.initialize_key(temp_k) + def get_handshake_hash(self): + return self.h + def encrypt_and_hash(self, plaintext: bytes) -> bytes: """ Sets ciphertext = EncryptWithAd(h, plaintext), calls MixHash(ciphertext), and returns ciphertext. Note that if diff --git a/requirements.txt b/requirements.txt index f540345..64d75b8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -cryptography==2.1.0 +cryptography==2.1.1 diff --git a/setup.py b/setup.py index 44876bf..297fbaa 100644 --- a/setup.py +++ b/setup.py @@ -32,6 +32,6 @@ setup( ], keywords='cryptography noiseprotocol noise security', packages=find_packages(exclude=['contrib', 'docs', 'tests', 'examples']), - install_requires=['cryptography==2.1.0'], + install_requires=['cryptography==2.1.1'], python_requires='~=3.5,~=3.6', ) diff --git a/tests/test_rev33_compat.py b/tests/test_rev33_compat.py new file mode 100644 index 0000000..13eeb21 --- /dev/null +++ b/tests/test_rev33_compat.py @@ -0,0 +1,26 @@ +from noise.noise_protocol import NoiseProtocol +from noise.state import CipherState, SymmetricState + + +class TestRevision33Compatibility(object): + def test_noise_protocol_accepts_slash(self): + class FakeSHA3_256(): + fn = None + + noise_name = b"Noise_NN_25519_AESGCM_SHA3/256" + modified_class = NoiseProtocol + modified_class.methods['hash']['SHA3/256'] = FakeSHA3_256 # Add callable to hash functions mapping + modified_class(noise_name) + + def test_cipher_state_set_nonce(self): + noise_protocol = NoiseProtocol(b"Noise_NN_25519_AESGCM_SHA256") + cipher_state = CipherState(noise_protocol) + cipher_state.initialize_key(b'\x00'*32) + assert cipher_state.n == 0 + cipher_state.set_nonce(42) + assert cipher_state.n == 42 + + def test_symmetric_state_get_handshake_hash(self): + symmetric_state = SymmetricState() + symmetric_state.h = 42 + assert symmetric_state.get_handshake_hash() == 42