From ff04a61efa764f3852a64e5473d07b4380832d65 Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Fri, 22 Jun 2018 04:49:33 +1000 Subject: [PATCH] Redesign how Noise protocol descriptors are defined --- host/Crypto/Makefile | 1 - .../src/NoiseProtocolDescriptor.cpp | 77 ------------------- .../src/NoiseProtocolDescriptor.h | 32 ++++---- .../src/Noise_IK_25519_AESGCM_SHA256.cpp | 21 ++--- .../src/Noise_IK_25519_AESGCM_SHA256.h | 9 +-- .../src/Noise_IK_25519_ChaChaPoly_BLAKE2s.cpp | 21 ++--- .../src/Noise_IK_25519_ChaChaPoly_BLAKE2s.h | 9 +-- .../src/Noise_IK_25519_ChaChaPoly_SHA256.cpp | 21 ++--- .../src/Noise_IK_25519_ChaChaPoly_SHA256.h | 9 +-- .../src/Noise_NNpsk0_25519_AESGCM_SHA256.cpp | 21 ++--- .../src/Noise_NNpsk0_25519_AESGCM_SHA256.h | 9 +-- .../Noise_NNpsk0_25519_ChaChaPoly_BLAKE2s.cpp | 21 ++--- .../Noise_NNpsk0_25519_ChaChaPoly_BLAKE2s.h | 9 +-- .../Noise_NNpsk0_25519_ChaChaPoly_SHA256.cpp | 21 ++--- .../Noise_NNpsk0_25519_ChaChaPoly_SHA256.h | 2 + .../src/Noise_XX_25519_AESGCM_SHA256.cpp | 21 ++--- .../src/Noise_XX_25519_AESGCM_SHA256.h | 9 +-- .../src/Noise_XX_25519_ChaChaPoly_BLAKE2s.cpp | 21 ++--- .../src/Noise_XX_25519_ChaChaPoly_BLAKE2s.h | 9 +-- .../src/Noise_XX_25519_ChaChaPoly_SHA256.cpp | 21 ++--- .../src/Noise_XX_25519_ChaChaPoly_SHA256.h | 9 +-- 21 files changed, 128 insertions(+), 245 deletions(-) delete mode 100644 libraries/NoiseProtocol/src/NoiseProtocolDescriptor.cpp diff --git a/host/Crypto/Makefile b/host/Crypto/Makefile index 407092b4..6da44297 100644 --- a/host/Crypto/Makefile +++ b/host/Crypto/Makefile @@ -98,7 +98,6 @@ SOURCES += \ Noise_NNpsk0_25519_ChaChaPoly_SHA256.cpp \ Noise_NNpsk0.cpp \ NoiseProtobufs.cpp \ - NoiseProtocolDescriptor.cpp \ NoiseSymmetricState_AESGCM_SHA256.cpp \ NoiseSymmetricState_ChaChaPoly_BLAKE2s.cpp \ NoiseSymmetricState_ChaChaPoly_SHA256.cpp \ diff --git a/libraries/NoiseProtocol/src/NoiseProtocolDescriptor.cpp b/libraries/NoiseProtocol/src/NoiseProtocolDescriptor.cpp deleted file mode 100644 index 377270aa..00000000 --- a/libraries/NoiseProtocol/src/NoiseProtocolDescriptor.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2018 Southern Storm Software, Pty Ltd. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -#include "NoiseProtocolDescriptor.h" - -/** - * \class NoiseProtocolDescriptor NoiseProtocolDescriptor.h - * \brief Description of a Noise protocol and a method to create a handshake - * object that implements the protocol. - * - * This class is abstract. The caller should instantiate a subclass like - * Noise_XX_25519_ChaChaPoly_BLAKE2s or Noise_XX_25519_AESGCM_SHA256 to - * get an actual descriptor. - */ - -/** - * \fn NoiseProtocolDescriptor::NoiseProtocolDescriptor(const char *name, const char *alias) - * \brief Creates a new Noise protocol descriptor. - * - * \param name Name of the Noise protocol, e.g. "Noise_XX_25519_AESGCM_SHA256". - * \param alias NoiseTinyLink alias for the Noise protocol; e.g. "1". Set this - * to NULL if the protocol does not have a NoiseTinyLink alias defined. - */ - -/** - * \brief Destroys this Noise protocol descriptor. - */ -NoiseProtocolDescriptor::~NoiseProtocolDescriptor() -{ -} - -/** - * \fn const char *NoiseProtocolDescriptor::protocolName() const - * \brief Gets the name of the Noise protocol represented by this descriptor. - * - * \return The name of the Noise protocol. - * - * \sa protocolAlias() - */ - -/** - * \fn const char *NoiseProtocolDescriptor::protocolAlias() const - * \brief Gets the NoiseTinyLink alias for the Noise protocol represented - * by this descriptor. - * - * \return The alias or NULL if the protocol does not have a NoiseTinyLink - * alias defined. - * - * \sa protocolName() - */ - -/** - * \fn NoiseHandshakeState *NoiseProtocolDescriptor::createHandshake() const - * \brief Creates a handshake object for the Noise protocol represented - * by this descriptor. - * - * \return A new handshake object for the protocol. - */ diff --git a/libraries/NoiseProtocol/src/NoiseProtocolDescriptor.h b/libraries/NoiseProtocol/src/NoiseProtocolDescriptor.h index 257b68f5..60f4b198 100644 --- a/libraries/NoiseProtocol/src/NoiseProtocolDescriptor.h +++ b/libraries/NoiseProtocol/src/NoiseProtocolDescriptor.h @@ -25,23 +25,29 @@ class NoiseHandshakeState; -class NoiseProtocolDescriptor +/** Noise Protocol needs a local static key pair to connect */ +#define NOISE_PROTOCOL_NEEDS_LOCAL_STATIC 0x0001 +/** Noise protocol needs a remote static public key to connect */ +#define NOISE_PROTOCOL_NEEDS_REMOTE_STATIC 0x0002 +/** Noise protocol needs a pre-shared symmetric key to connect */ +#define NOISE_PROTOCOL_NEEDS_PSK 0x0004 + +/** + * \brief Structure that provides metadata for Noise protocols. + */ +struct NoiseProtocolDescriptor { -public: - virtual ~NoiseProtocolDescriptor(); + /** Flags that define the properties and required keys for the protocol */ + unsigned flags; - const char *protocolName() const { return protoName; } - const char *protocolAlias() const { return protoAlias; } + /** Full Noise protocol name; e.g. "Noise_XX_25519_ChaChaPoly_BLAKE2s" */ + const char *protocolName; - virtual NoiseHandshakeState *createHandshake() const = 0; + /** NoiseTinyLink alias for the protocol, or NULL if no alias */ + const char *protocolAlias; -protected: - explicit NoiseProtocolDescriptor(const char *name, const char *alias = 0) - : protoName(name), protoAlias(alias) {} - -private: - const char *protoName; - const char *protoAlias; + /** Function that creates a handshake instance for the protocol */ + NoiseHandshakeState *(*createHandshake)(); }; #endif diff --git a/libraries/NoiseProtocol/src/Noise_IK_25519_AESGCM_SHA256.cpp b/libraries/NoiseProtocol/src/Noise_IK_25519_AESGCM_SHA256.cpp index 88868f4c..ff2aeeb8 100644 --- a/libraries/NoiseProtocol/src/Noise_IK_25519_AESGCM_SHA256.cpp +++ b/libraries/NoiseProtocol/src/Noise_IK_25519_AESGCM_SHA256.cpp @@ -46,16 +46,17 @@ NoiseHandshakeState_IK_25519_AESGCM_SHA256::~NoiseHandshakeState_IK_25519_AESGCM { } -Noise_IK_25519_AESGCM_SHA256::Noise_IK_25519_AESGCM_SHA256() - : NoiseProtocolDescriptor(Noise_IK_25519_AESGCM_SHA256_Name) -{ -} - -Noise_IK_25519_AESGCM_SHA256::~Noise_IK_25519_AESGCM_SHA256() -{ -} - -NoiseHandshakeState *Noise_IK_25519_AESGCM_SHA256::createHandshake() const +static NoiseHandshakeState *Noise_IK_25519_AESGCM_SHA256_createHandshake() { return new NoiseHandshakeState_IK_25519_AESGCM_SHA256(); } + +/** + * \brief Protocol descriptor for "Noise_IK_25519_AESGCM_SHA256". + */ +const NoiseProtocolDescriptor Noise_IK_25519_AESGCM_SHA256 = { + NOISE_PROTOCOL_NEEDS_LOCAL_STATIC | NOISE_PROTOCOL_NEEDS_REMOTE_STATIC, + Noise_IK_25519_AESGCM_SHA256_Name, + 0, + Noise_IK_25519_AESGCM_SHA256_createHandshake +}; diff --git a/libraries/NoiseProtocol/src/Noise_IK_25519_AESGCM_SHA256.h b/libraries/NoiseProtocol/src/Noise_IK_25519_AESGCM_SHA256.h index 91f8b0be..e341395b 100644 --- a/libraries/NoiseProtocol/src/Noise_IK_25519_AESGCM_SHA256.h +++ b/libraries/NoiseProtocol/src/Noise_IK_25519_AESGCM_SHA256.h @@ -39,13 +39,6 @@ private: NoiseDHState_Curve25519 dh; }; -class Noise_IK_25519_AESGCM_SHA256 : public NoiseProtocolDescriptor -{ -public: - Noise_IK_25519_AESGCM_SHA256(); - virtual ~Noise_IK_25519_AESGCM_SHA256(); - - NoiseHandshakeState *createHandshake() const; -}; +extern const NoiseProtocolDescriptor Noise_IK_25519_AESGCM_SHA256; #endif diff --git a/libraries/NoiseProtocol/src/Noise_IK_25519_ChaChaPoly_BLAKE2s.cpp b/libraries/NoiseProtocol/src/Noise_IK_25519_ChaChaPoly_BLAKE2s.cpp index a98bb8b2..802172d9 100644 --- a/libraries/NoiseProtocol/src/Noise_IK_25519_ChaChaPoly_BLAKE2s.cpp +++ b/libraries/NoiseProtocol/src/Noise_IK_25519_ChaChaPoly_BLAKE2s.cpp @@ -46,16 +46,17 @@ NoiseHandshakeState_IK_25519_ChaChaPoly_BLAKE2s::~NoiseHandshakeState_IK_25519_C { } -Noise_IK_25519_ChaChaPoly_BLAKE2s::Noise_IK_25519_ChaChaPoly_BLAKE2s() - : NoiseProtocolDescriptor(Noise_IK_25519_ChaChaPoly_BLAKE2s_Name) -{ -} - -Noise_IK_25519_ChaChaPoly_BLAKE2s::~Noise_IK_25519_ChaChaPoly_BLAKE2s() -{ -} - -NoiseHandshakeState *Noise_IK_25519_ChaChaPoly_BLAKE2s::createHandshake() const +static NoiseHandshakeState *Noise_IK_25519_ChaChaPoly_BLAKE2s_createHandshake() { return new NoiseHandshakeState_IK_25519_ChaChaPoly_BLAKE2s(); } + +/** + * \brief Protocol descriptor for "Noise_IK_25519_ChaChaPoly_BLAKE2s". + */ +const NoiseProtocolDescriptor Noise_IK_25519_ChaChaPoly_BLAKE2s = { + NOISE_PROTOCOL_NEEDS_LOCAL_STATIC | NOISE_PROTOCOL_NEEDS_REMOTE_STATIC, + Noise_IK_25519_ChaChaPoly_BLAKE2s_Name, + 0, + Noise_IK_25519_ChaChaPoly_BLAKE2s_createHandshake +}; diff --git a/libraries/NoiseProtocol/src/Noise_IK_25519_ChaChaPoly_BLAKE2s.h b/libraries/NoiseProtocol/src/Noise_IK_25519_ChaChaPoly_BLAKE2s.h index 132d02ee..a1520746 100644 --- a/libraries/NoiseProtocol/src/Noise_IK_25519_ChaChaPoly_BLAKE2s.h +++ b/libraries/NoiseProtocol/src/Noise_IK_25519_ChaChaPoly_BLAKE2s.h @@ -40,13 +40,6 @@ private: NoiseDHState_Curve25519 dh; }; -class Noise_IK_25519_ChaChaPoly_BLAKE2s : public NoiseProtocolDescriptor -{ -public: - Noise_IK_25519_ChaChaPoly_BLAKE2s(); - virtual ~Noise_IK_25519_ChaChaPoly_BLAKE2s(); - - NoiseHandshakeState *createHandshake() const; -}; +extern const NoiseProtocolDescriptor Noise_IK_25519_ChaChaPoly_BLAKE2s; #endif diff --git a/libraries/NoiseProtocol/src/Noise_IK_25519_ChaChaPoly_SHA256.cpp b/libraries/NoiseProtocol/src/Noise_IK_25519_ChaChaPoly_SHA256.cpp index e60eed53..2c064a0e 100644 --- a/libraries/NoiseProtocol/src/Noise_IK_25519_ChaChaPoly_SHA256.cpp +++ b/libraries/NoiseProtocol/src/Noise_IK_25519_ChaChaPoly_SHA256.cpp @@ -46,16 +46,17 @@ NoiseHandshakeState_IK_25519_ChaChaPoly_SHA256::~NoiseHandshakeState_IK_25519_Ch { } -Noise_IK_25519_ChaChaPoly_SHA256::Noise_IK_25519_ChaChaPoly_SHA256() - : NoiseProtocolDescriptor(Noise_IK_25519_ChaChaPoly_SHA256_Name) -{ -} - -Noise_IK_25519_ChaChaPoly_SHA256::~Noise_IK_25519_ChaChaPoly_SHA256() -{ -} - -NoiseHandshakeState *Noise_IK_25519_ChaChaPoly_SHA256::createHandshake() const +static NoiseHandshakeState *Noise_IK_25519_ChaChaPoly_SHA256_createHandshake() { return new NoiseHandshakeState_IK_25519_ChaChaPoly_SHA256(); } + +/** + * \brief Protocol descriptor for "Noise_IK_25519_ChaChaPoly_SHA256". + */ +const NoiseProtocolDescriptor Noise_IK_25519_ChaChaPoly_SHA256 = { + NOISE_PROTOCOL_NEEDS_LOCAL_STATIC | NOISE_PROTOCOL_NEEDS_REMOTE_STATIC, + Noise_IK_25519_ChaChaPoly_SHA256_Name, + 0, + Noise_IK_25519_ChaChaPoly_SHA256_createHandshake +}; diff --git a/libraries/NoiseProtocol/src/Noise_IK_25519_ChaChaPoly_SHA256.h b/libraries/NoiseProtocol/src/Noise_IK_25519_ChaChaPoly_SHA256.h index 3e95e03e..e57e4c6e 100644 --- a/libraries/NoiseProtocol/src/Noise_IK_25519_ChaChaPoly_SHA256.h +++ b/libraries/NoiseProtocol/src/Noise_IK_25519_ChaChaPoly_SHA256.h @@ -40,13 +40,6 @@ private: NoiseDHState_Curve25519 dh; }; -class Noise_IK_25519_ChaChaPoly_SHA256 : public NoiseProtocolDescriptor -{ -public: - Noise_IK_25519_ChaChaPoly_SHA256(); - virtual ~Noise_IK_25519_ChaChaPoly_SHA256(); - - NoiseHandshakeState *createHandshake() const; -}; +extern const NoiseProtocolDescriptor Noise_IK_25519_ChaChaPoly_SHA256; #endif diff --git a/libraries/NoiseProtocol/src/Noise_NNpsk0_25519_AESGCM_SHA256.cpp b/libraries/NoiseProtocol/src/Noise_NNpsk0_25519_AESGCM_SHA256.cpp index 719f0323..6e45459d 100644 --- a/libraries/NoiseProtocol/src/Noise_NNpsk0_25519_AESGCM_SHA256.cpp +++ b/libraries/NoiseProtocol/src/Noise_NNpsk0_25519_AESGCM_SHA256.cpp @@ -46,16 +46,17 @@ NoiseHandshakeState_NNpsk0_25519_AESGCM_SHA256::~NoiseHandshakeState_NNpsk0_2551 { } -Noise_NNpsk0_25519_AESGCM_SHA256::Noise_NNpsk0_25519_AESGCM_SHA256() - : NoiseProtocolDescriptor(Noise_NNpsk0_25519_AESGCM_SHA256_Name) -{ -} - -Noise_NNpsk0_25519_AESGCM_SHA256::~Noise_NNpsk0_25519_AESGCM_SHA256() -{ -} - -NoiseHandshakeState *Noise_NNpsk0_25519_AESGCM_SHA256::createHandshake() const +static NoiseHandshakeState *Noise_NNpsk0_25519_AESGCM_SHA256_createHandshake() { return new NoiseHandshakeState_NNpsk0_25519_AESGCM_SHA256(); } + +/** + * \brief Protocol descriptor for "Noise_NNps0_25519_AESGCM_SHA256". + */ +const NoiseProtocolDescriptor Noise_NNpsk0_25519_AESGCM_SHA256 = { + NOISE_PROTOCOL_NEEDS_PSK, + Noise_NNpsk0_25519_AESGCM_SHA256_Name, + 0, + Noise_NNpsk0_25519_AESGCM_SHA256_createHandshake +}; diff --git a/libraries/NoiseProtocol/src/Noise_NNpsk0_25519_AESGCM_SHA256.h b/libraries/NoiseProtocol/src/Noise_NNpsk0_25519_AESGCM_SHA256.h index 48f0c2c8..8ce7ff3c 100644 --- a/libraries/NoiseProtocol/src/Noise_NNpsk0_25519_AESGCM_SHA256.h +++ b/libraries/NoiseProtocol/src/Noise_NNpsk0_25519_AESGCM_SHA256.h @@ -40,13 +40,6 @@ private: NoiseDHState_Curve25519_EphemOnly dh; }; -class Noise_NNpsk0_25519_AESGCM_SHA256 : public NoiseProtocolDescriptor -{ -public: - Noise_NNpsk0_25519_AESGCM_SHA256(); - virtual ~Noise_NNpsk0_25519_AESGCM_SHA256(); - - NoiseHandshakeState *createHandshake() const; -}; +extern const NoiseProtocolDescriptor Noise_NNpsk0_25519_AESGCM_SHA256; #endif diff --git a/libraries/NoiseProtocol/src/Noise_NNpsk0_25519_ChaChaPoly_BLAKE2s.cpp b/libraries/NoiseProtocol/src/Noise_NNpsk0_25519_ChaChaPoly_BLAKE2s.cpp index 7ceffca7..f03b3d3d 100644 --- a/libraries/NoiseProtocol/src/Noise_NNpsk0_25519_ChaChaPoly_BLAKE2s.cpp +++ b/libraries/NoiseProtocol/src/Noise_NNpsk0_25519_ChaChaPoly_BLAKE2s.cpp @@ -46,16 +46,17 @@ NoiseHandshakeState_NNpsk0_25519_ChaChaPoly_BLAKE2s::~NoiseHandshakeState_NNpsk0 { } -Noise_NNpsk0_25519_ChaChaPoly_BLAKE2s::Noise_NNpsk0_25519_ChaChaPoly_BLAKE2s() - : NoiseProtocolDescriptor(Noise_NNpsk0_25519_ChaChaPoly_BLAKE2s_Name) -{ -} - -Noise_NNpsk0_25519_ChaChaPoly_BLAKE2s::~Noise_NNpsk0_25519_ChaChaPoly_BLAKE2s() -{ -} - -NoiseHandshakeState *Noise_NNpsk0_25519_ChaChaPoly_BLAKE2s::createHandshake() const +static NoiseHandshakeState *Noise_NNpsk0_25519_ChaChaPoly_BLAKE2s_createHandshake() { return new NoiseHandshakeState_NNpsk0_25519_ChaChaPoly_BLAKE2s(); } + +/** + * \brief Protocol descriptor for "Noise_NNps0_25519_ChaChaPoly_BLAKE2s". + */ +const NoiseProtocolDescriptor Noise_NNpsk0_25519_ChaChaPoly_BLAKE2s = { + NOISE_PROTOCOL_NEEDS_PSK, + Noise_NNpsk0_25519_ChaChaPoly_BLAKE2s_Name, + 0, + Noise_NNpsk0_25519_ChaChaPoly_BLAKE2s_createHandshake +}; diff --git a/libraries/NoiseProtocol/src/Noise_NNpsk0_25519_ChaChaPoly_BLAKE2s.h b/libraries/NoiseProtocol/src/Noise_NNpsk0_25519_ChaChaPoly_BLAKE2s.h index c89bf7cf..8cbf4b70 100644 --- a/libraries/NoiseProtocol/src/Noise_NNpsk0_25519_ChaChaPoly_BLAKE2s.h +++ b/libraries/NoiseProtocol/src/Noise_NNpsk0_25519_ChaChaPoly_BLAKE2s.h @@ -40,13 +40,6 @@ private: NoiseDHState_Curve25519_EphemOnly dh; }; -class Noise_NNpsk0_25519_ChaChaPoly_BLAKE2s : public NoiseProtocolDescriptor -{ -public: - Noise_NNpsk0_25519_ChaChaPoly_BLAKE2s(); - virtual ~Noise_NNpsk0_25519_ChaChaPoly_BLAKE2s(); - - NoiseHandshakeState *createHandshake() const; -}; +extern const NoiseProtocolDescriptor Noise_NNpsk0_25519_ChaChaPoly_BLAKE2s; #endif diff --git a/libraries/NoiseProtocol/src/Noise_NNpsk0_25519_ChaChaPoly_SHA256.cpp b/libraries/NoiseProtocol/src/Noise_NNpsk0_25519_ChaChaPoly_SHA256.cpp index e51cb4e6..3d56f5b8 100644 --- a/libraries/NoiseProtocol/src/Noise_NNpsk0_25519_ChaChaPoly_SHA256.cpp +++ b/libraries/NoiseProtocol/src/Noise_NNpsk0_25519_ChaChaPoly_SHA256.cpp @@ -46,16 +46,17 @@ NoiseHandshakeState_NNpsk0_25519_ChaChaPoly_SHA256::~NoiseHandshakeState_NNpsk0_ { } -Noise_NNpsk0_25519_ChaChaPoly_SHA256::Noise_NNpsk0_25519_ChaChaPoly_SHA256() - : NoiseProtocolDescriptor(Noise_NNpsk0_25519_ChaChaPoly_SHA256_Name) -{ -} - -Noise_NNpsk0_25519_ChaChaPoly_SHA256::~Noise_NNpsk0_25519_ChaChaPoly_SHA256() -{ -} - -NoiseHandshakeState *Noise_NNpsk0_25519_ChaChaPoly_SHA256::createHandshake() const +static NoiseHandshakeState *Noise_NNpsk0_25519_ChaChaPoly_SHA256_createHandshake() { return new NoiseHandshakeState_NNpsk0_25519_ChaChaPoly_SHA256(); } + +/** + * \brief Protocol descriptor for "Noise_NNps0_25519_ChaChaPoly_SHA256". + */ +const NoiseProtocolDescriptor Noise_NNpsk0_25519_ChaChaPoly_SHA256 = { + NOISE_PROTOCOL_NEEDS_PSK, + Noise_NNpsk0_25519_ChaChaPoly_SHA256_Name, + 0, + Noise_NNpsk0_25519_ChaChaPoly_SHA256_createHandshake +}; diff --git a/libraries/NoiseProtocol/src/Noise_NNpsk0_25519_ChaChaPoly_SHA256.h b/libraries/NoiseProtocol/src/Noise_NNpsk0_25519_ChaChaPoly_SHA256.h index 9713853e..af8ccff2 100644 --- a/libraries/NoiseProtocol/src/Noise_NNpsk0_25519_ChaChaPoly_SHA256.h +++ b/libraries/NoiseProtocol/src/Noise_NNpsk0_25519_ChaChaPoly_SHA256.h @@ -49,4 +49,6 @@ public: NoiseHandshakeState *createHandshake() const; }; +extern const NoiseProtocolDescriptor Noise_NNpsk0_25519_ChaChaPoly_SHA256; + #endif diff --git a/libraries/NoiseProtocol/src/Noise_XX_25519_AESGCM_SHA256.cpp b/libraries/NoiseProtocol/src/Noise_XX_25519_AESGCM_SHA256.cpp index ab34d1a7..a0004714 100644 --- a/libraries/NoiseProtocol/src/Noise_XX_25519_AESGCM_SHA256.cpp +++ b/libraries/NoiseProtocol/src/Noise_XX_25519_AESGCM_SHA256.cpp @@ -46,16 +46,17 @@ NoiseHandshakeState_XX_25519_AESGCM_SHA256::~NoiseHandshakeState_XX_25519_AESGCM { } -Noise_XX_25519_AESGCM_SHA256::Noise_XX_25519_AESGCM_SHA256() - : NoiseProtocolDescriptor(Noise_XX_25519_AESGCM_SHA256_Name, "1") -{ -} - -Noise_XX_25519_AESGCM_SHA256::~Noise_XX_25519_AESGCM_SHA256() -{ -} - -NoiseHandshakeState *Noise_XX_25519_AESGCM_SHA256::createHandshake() const +static NoiseHandshakeState *Noise_XX_25519_AESGCM_SHA256_createHandshake() { return new NoiseHandshakeState_XX_25519_AESGCM_SHA256(); } + +/** + * \brief Protocol descriptor for "Noise_XX_25519_AESGCM_SHA256". + */ +const NoiseProtocolDescriptor Noise_XX_25519_AESGCM_SHA256 = { + NOISE_PROTOCOL_NEEDS_LOCAL_STATIC, + Noise_XX_25519_AESGCM_SHA256_Name, + "1", + Noise_XX_25519_AESGCM_SHA256_createHandshake +}; diff --git a/libraries/NoiseProtocol/src/Noise_XX_25519_AESGCM_SHA256.h b/libraries/NoiseProtocol/src/Noise_XX_25519_AESGCM_SHA256.h index 67042945..8290b466 100644 --- a/libraries/NoiseProtocol/src/Noise_XX_25519_AESGCM_SHA256.h +++ b/libraries/NoiseProtocol/src/Noise_XX_25519_AESGCM_SHA256.h @@ -39,13 +39,6 @@ private: NoiseDHState_Curve25519 dh; }; -class Noise_XX_25519_AESGCM_SHA256 : public NoiseProtocolDescriptor -{ -public: - Noise_XX_25519_AESGCM_SHA256(); - virtual ~Noise_XX_25519_AESGCM_SHA256(); - - NoiseHandshakeState *createHandshake() const; -}; +extern const NoiseProtocolDescriptor Noise_XX_25519_AESGCM_SHA256; #endif diff --git a/libraries/NoiseProtocol/src/Noise_XX_25519_ChaChaPoly_BLAKE2s.cpp b/libraries/NoiseProtocol/src/Noise_XX_25519_ChaChaPoly_BLAKE2s.cpp index c18a8c2e..f40cc909 100644 --- a/libraries/NoiseProtocol/src/Noise_XX_25519_ChaChaPoly_BLAKE2s.cpp +++ b/libraries/NoiseProtocol/src/Noise_XX_25519_ChaChaPoly_BLAKE2s.cpp @@ -46,16 +46,17 @@ NoiseHandshakeState_XX_25519_ChaChaPoly_BLAKE2s::~NoiseHandshakeState_XX_25519_C { } -Noise_XX_25519_ChaChaPoly_BLAKE2s::Noise_XX_25519_ChaChaPoly_BLAKE2s() - : NoiseProtocolDescriptor(Noise_XX_25519_ChaChaPoly_BLAKE2s_Name, "3") -{ -} - -Noise_XX_25519_ChaChaPoly_BLAKE2s::~Noise_XX_25519_ChaChaPoly_BLAKE2s() -{ -} - -NoiseHandshakeState *Noise_XX_25519_ChaChaPoly_BLAKE2s::createHandshake() const +static NoiseHandshakeState *Noise_XX_25519_ChaChaPoly_BLAKE2s_createHandshake() { return new NoiseHandshakeState_XX_25519_ChaChaPoly_BLAKE2s(); } + +/** + * \brief Protocol descriptor for "Noise_XX_25519ChaChaPoly_BLAKE2s". + */ +const NoiseProtocolDescriptor Noise_XX_25519_ChaChaPoly_BLAKE2s = { + NOISE_PROTOCOL_NEEDS_LOCAL_STATIC, + Noise_XX_25519_ChaChaPoly_BLAKE2s_Name, + "3", + Noise_XX_25519_ChaChaPoly_BLAKE2s_createHandshake +}; diff --git a/libraries/NoiseProtocol/src/Noise_XX_25519_ChaChaPoly_BLAKE2s.h b/libraries/NoiseProtocol/src/Noise_XX_25519_ChaChaPoly_BLAKE2s.h index a3a1af11..de35b3a2 100644 --- a/libraries/NoiseProtocol/src/Noise_XX_25519_ChaChaPoly_BLAKE2s.h +++ b/libraries/NoiseProtocol/src/Noise_XX_25519_ChaChaPoly_BLAKE2s.h @@ -40,13 +40,6 @@ private: NoiseDHState_Curve25519 dh; }; -class Noise_XX_25519_ChaChaPoly_BLAKE2s : public NoiseProtocolDescriptor -{ -public: - Noise_XX_25519_ChaChaPoly_BLAKE2s(); - virtual ~Noise_XX_25519_ChaChaPoly_BLAKE2s(); - - NoiseHandshakeState *createHandshake() const; -}; +extern const NoiseProtocolDescriptor Noise_XX_25519_ChaChaPoly_BLAKE2s; #endif diff --git a/libraries/NoiseProtocol/src/Noise_XX_25519_ChaChaPoly_SHA256.cpp b/libraries/NoiseProtocol/src/Noise_XX_25519_ChaChaPoly_SHA256.cpp index d3e7af32..86acf2e6 100644 --- a/libraries/NoiseProtocol/src/Noise_XX_25519_ChaChaPoly_SHA256.cpp +++ b/libraries/NoiseProtocol/src/Noise_XX_25519_ChaChaPoly_SHA256.cpp @@ -46,16 +46,17 @@ NoiseHandshakeState_XX_25519_ChaChaPoly_SHA256::~NoiseHandshakeState_XX_25519_Ch { } -Noise_XX_25519_ChaChaPoly_SHA256::Noise_XX_25519_ChaChaPoly_SHA256() - : NoiseProtocolDescriptor(Noise_XX_25519_ChaChaPoly_SHA256_Name, "2") -{ -} - -Noise_XX_25519_ChaChaPoly_SHA256::~Noise_XX_25519_ChaChaPoly_SHA256() -{ -} - -NoiseHandshakeState *Noise_XX_25519_ChaChaPoly_SHA256::createHandshake() const +static NoiseHandshakeState *Noise_XX_25519_ChaChaPoly_SHA256_createHandshake() { return new NoiseHandshakeState_XX_25519_ChaChaPoly_SHA256(); } + +/** + * \brief Protocol descriptor for "Noise_XX_25519ChaChaPoly_SHA256". + */ +const NoiseProtocolDescriptor Noise_XX_25519_ChaChaPoly_SHA256 = { + NOISE_PROTOCOL_NEEDS_LOCAL_STATIC, + Noise_XX_25519_ChaChaPoly_SHA256_Name, + "2", + Noise_XX_25519_ChaChaPoly_SHA256_createHandshake +}; diff --git a/libraries/NoiseProtocol/src/Noise_XX_25519_ChaChaPoly_SHA256.h b/libraries/NoiseProtocol/src/Noise_XX_25519_ChaChaPoly_SHA256.h index 5ab73adf..51b7d2a1 100644 --- a/libraries/NoiseProtocol/src/Noise_XX_25519_ChaChaPoly_SHA256.h +++ b/libraries/NoiseProtocol/src/Noise_XX_25519_ChaChaPoly_SHA256.h @@ -40,13 +40,6 @@ private: NoiseDHState_Curve25519 dh; }; -class Noise_XX_25519_ChaChaPoly_SHA256 : public NoiseProtocolDescriptor -{ -public: - Noise_XX_25519_ChaChaPoly_SHA256(); - virtual ~Noise_XX_25519_ChaChaPoly_SHA256(); - - NoiseHandshakeState *createHandshake() const; -}; +extern const NoiseProtocolDescriptor Noise_XX_25519_ChaChaPoly_SHA256; #endif