mirror of
https://github.com/morgan9e/noiseprotocol
synced 2026-04-14 00:14:05 +09:00
* 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
28 lines
602 B
Python
28 lines
602 B
Python
import abc
|
|
|
|
from noise.constants import MAX_NONCE
|
|
|
|
|
|
class Cipher(metaclass=abc.ABCMeta):
|
|
def __init__(self):
|
|
self.cipher = None
|
|
|
|
@property
|
|
@abc.abstractmethod
|
|
def klass(self):
|
|
raise NotImplementedError
|
|
|
|
@abc.abstractmethod
|
|
def encrypt(self, k, n, ad, plaintext):
|
|
raise NotImplementedError
|
|
|
|
@abc.abstractmethod
|
|
def decrypt(self, k, n, ad, ciphertext):
|
|
raise NotImplementedError
|
|
|
|
def rekey(self, k):
|
|
return self.encrypt(k, MAX_NONCE, b'', b'\x00' * 32)[:32]
|
|
|
|
def initialize(self, key):
|
|
self.cipher = self.klass(key)
|