Commit Graph

12 Commits

Author SHA1 Message Date
Piotr Lizończyk
e84db3c232 Added possibilty to use different crypto backends.
* Created NoiseBackend class serving as a base for backends

* Refactored NoiseProtocol name parsing

* Refactored existing spec-defined functions into abstract classes.
Implementing classes are connecting crypto primitives to expected
interfaces.

* Refactored existing usage of Cryptography as source of crypto into
"default" backend (along with in-house implementation of X448).

* Provisioned "experimental" backend, it will contain e.g. non-default
crypto algorithms

* Backend can be chosen while creating NoiseConnection, though by
default, the Cryptography backend ("default") is used

Closes #7
2018-07-16 01:47:29 +02:00
Piotr Lizonczyk
7e51c3a6f7 Switched from lists to tuples for const data type
Closes #2
2017-10-08 00:54:54 +02:00
Piotr Lizonczyk
3a8439894a Prepare for public release
- Added readme
- Updated setup.py
- Removed pytest from requirements, added version of cryptography
package
- Small improvements in code:

noise/noise_protocol.py:
* removed unused one_way variable

noise/patterns.py
* fixed has_pre_messages - no longer a variable, but method - and now
works properly

noise/state.py
* SymmetricState now holds reference to CipherState.
2017-09-12 21:59:47 +02:00
Piotr Lizonczyk
368d401701 Improved validation, various additions
noise/builder.py:
- Added guard for data length in decrypt
- Handling InvalidTag exception when AEAD fails
- New NoiseInvalidMessage exception class

noise/exceptions.py
- Three new exception classes

noise/noise_protocol.py
- Implemented rest of validation, now checks for required keypairs, setting initiator/responder role, warns if ephemeral keypairs are set.

noise/patterns.py:
- added name field to every Pattern with pattern name
- added get_required_keypairs method that returns list of keypairs required for given handshake pattern

noise/state.py
- new NoiseMaxNonceError exception

Overall: some TODOs resolved
2017-09-03 13:33:15 +02:00
Piotr Lizonczyk
52fd5058bc Enabling PSK support. Core functionality ready!
noise/noise_protocol.py
* PSKs should be now delivered to NoiseProtocol while initialising
* New field `is_psk_handshake` in NoiseProtocol

noise/patterns.py
* Fixed erronenous super call in OneWayPattern
* Changed class variables to instance variables in Patterns, fixes
things.

noise/state.py
* Added missing mix_key_and_hash to SymmetricState
* Added required calls when in PSK handshake (TOKEN_E and TOKEN_PSK),
both in write_message and read_message of HandshakeState

tests/test_vectors.py
* Enabled PSK tests, some minor fixes to make them work
2017-08-19 01:27:59 +02:00
Piotr Lizonczyk
582ead091d Tons of fixes, working except Blake and PSK
noise/functions.py
* Enabling ChaCha20 usage (from Cryptography)
* Switching to per-cipher nonce formatting function
* Changes to KeyPair interface - now wrappers exist for every ECDH
* Fixing hmac_hash bug in implementation

noise/noise_protocol.py
* Added placeholders for multiple datafields in __init__, as well as for
transport mode cipher states
* Added handshake_done method for cleanup (post-handshake,
pre-transport), not finished though

noise/patterns.py
* Now Pattern holds boolean telling if it's oneway. OneWayPattern class
created for derivation by PatternN, PatternK, PatternX
* Fixed wrong mapping of PatternK and PatternX in patterns_map

noise/state.py
* CipherState now takes noise_protocol in __init__, so that
initialize_key() only reinitalizes CipherState instead of creating it.
* Changed CipherState creation in SymmetricState to reflect change above
* Fixing wrong sequence of concatenation hash and data in mix_hash()
* SymmetricState's split() fixed and calling noise_protocol's
handshake_done()
* Pattern tokens are now copied to HandshakeState instead of modifying
original Pattern
* Changes in HandshakeState's writemessage and readmessage to reflect
changes in KeyPair interface
* Added workaround for tests (usage of pre-generated ephemeral keypair),
to be removed in future

tests/test_vectors.py
* Individual test now is properly described in pytest with protocol name
* Finished main test case, fully utilises test vectors (and all their
messages)

tests/vectors/noise-c-basic.txttests/vectors/noise-c-basic.txt
* Forked rev30 test vector from noise-c
2017-08-18 23:13:07 +02:00
Piotr Lizonczyk
8d807f9c6c Removing variable annotations for python 3.5 compatibility... again. 2017-08-14 22:54:52 +02:00
Piotr Lizonczyk
1164c4cabe Switching string formatting for python3.5 compat 2017-08-12 19:24:31 +02:00
Piotr Lizonczyk
bcaceb9ccd Improvements to initialization of NoiseProtocol
noise/noise_protocol.py
* Added validation of given function names vs available crypto methods
* Members of NoiseProtocol should now refer to proper classes/methods
after initialization of an instance

noise/patterns.py
* Added method for application of pattern modifiers

noise/crypto.py
* Provisioned ed448 function

noise/state.py
* Changed references to NoiseProtocol instances to make it more
consistent throughout the code
2017-08-12 13:30:44 +02:00
Piotr Lizonczyk
de73505ac3 Implementing NoiseProtocol (WIP), binding crypto
noise/noise_protocol.py - added maps of cryptofunctions that will be
used, finished protocol name splitting

noise/patterns.py - added map of patterns

requirements.txt - switching to pycryptodome as a source of cipher and
hashing functions, and ed25519 package for that curve
2017-08-09 23:55:32 +02:00
Piotr Lizonczyk
a6eec85ef7 Implemented HandshakeState.initialize()
constants.py
* Adding max Noise protocol name constant

noise_protocol.py
* Provisioning NoiseProtocol and KeyPair classes

patterns.py
* Switching to proper intra-package relative imports
* Adding getter functions for pre-messages

state.py
* Switching to proper intra-package relative imports
* Removed __init__ of HandshakeState, leaving only initialize() as
constructor function.
* Implemented initialize() along with helper functions for retrieving
keypairs
* Modified SymmetricState, removing __init__ and leaving
initialize_symmetric as a constructor function (only provisioned)
2017-08-07 00:50:45 +02:00
Piotr Lizonczyk
bf36429fd7 * Adding handshake patterns
* Adding token constants for handshake patterns
2017-08-06 21:29:10 +02:00