mirror of
https://github.com/morgan9e/noiseprotocol
synced 2026-04-14 00:14:05 +09:00
Ensure compatibility with revision 33
* Allowed '/' in protocol name * Added SymmetricState.GetHandshakeHash() * Added CipherState.SetNonce() * Unittests to ensure that each of above is working Closes #3
This commit is contained in:
@@ -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.
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ noiseprotocol
|
||||
[](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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1 +1 @@
|
||||
cryptography==2.1.0
|
||||
cryptography==2.1.1
|
||||
|
||||
2
setup.py
2
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',
|
||||
)
|
||||
|
||||
26
tests/test_rev33_compat.py
Normal file
26
tests/test_rev33_compat.py
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user