Class Protocol
A concrete Noise protocol (e.g. Noise_XX_25519_AESGCM_SHA256 or Noise_IK_25519_ChaChaPoly_BLAKE2b).
Inheritance
Inherited Members
Namespace: Noise
Assembly: Noise.dll
Syntax
public sealed class Protocol
Constructors
| Improve this Doc View SourceProtocol(HandshakePattern, CipherFunction, HashFunction, PatternModifiers)
Initializes a new instance of the Protocol class.
Declaration
public Protocol(HandshakePattern handshakePattern, CipherFunction cipher, HashFunction hash, PatternModifiers modifiers = PatternModifiers.None)
Parameters
Type | Name | Description |
---|---|---|
HandshakePattern | handshakePattern | The handshake pattern (e.q. NX or IK). |
CipherFunction | cipher | The cipher function (AESGCM or ChaChaPoly). |
HashFunction | hash | The hash function (SHA256, SHA512, BLAKE2s, or BLAKE2b). |
PatternModifiers | modifiers | The combination of pattern modifiers (e.q. empty, psk0, or psk1+psk2). |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Thrown if either |
System.ArgumentException | Thrown if |
Protocol(HandshakePattern, PatternModifiers)
Initializes a new instance of the Protocol class using ChaChaPoly, 25519, and SHA256 functions.
Declaration
public Protocol(HandshakePattern handshakePattern, PatternModifiers modifiers = PatternModifiers.None)
Parameters
Type | Name | Description |
---|---|---|
HandshakePattern | handshakePattern | The handshake pattern (e.q. NX or IK). |
PatternModifiers | modifiers | The combination of pattern modifiers (e.q. empty, psk0, or psk1+psk2). |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Thrown if the |
System.ArgumentException | Thrown if |
Fields
| Improve this Doc View SourceMaxMessageLength
Maximum size of the Noise protocol message in bytes.
Declaration
public const int MaxMessageLength = 65535
Field Value
Type | Description |
---|---|
System.Int32 |
Properties
| Improve this Doc View SourceCipher
Gets the cipher function.
Declaration
public CipherFunction Cipher { get; }
Property Value
Type | Description |
---|---|
CipherFunction |
Dh
Gets the Diffie-Hellman function.
Declaration
public DhFunction Dh { get; }
Property Value
Type | Description |
---|---|
DhFunction |
HandshakePattern
Gets the handshake pattern.
Declaration
public HandshakePattern HandshakePattern { get; }
Property Value
Type | Description |
---|---|
HandshakePattern |
Hash
Gets the hash function.
Declaration
public HashFunction Hash { get; }
Property Value
Type | Description |
---|---|
HashFunction |
Modifiers
Gets the combination of pattern modifiers.
Declaration
public PatternModifiers Modifiers { get; }
Property Value
Type | Description |
---|---|
PatternModifiers |
Methods
| Improve this Doc View SourceCreate(ProtocolConfig)
Creates an initial HandshakeState.
Declaration
public HandshakeState Create(ProtocolConfig config)
Parameters
Type | Name | Description |
---|---|---|
ProtocolConfig | config | A set of parameters used to instantiate an initial HandshakeState. |
Returns
Type | Description |
---|---|
HandshakeState | The initial handshake state. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Thrown if the |
System.ArgumentException | Thrown if any of the following conditions is satisfied: - - - HandshakePattern requires the HandshakeState to be initialized with local and/or remote static key, but LocalStatic and/or RemoteStatic is null. - One or more pre-shared keys are not 32 bytes in length. - Number of pre-shared keys does not match the number of PSK modifiers. |
Create(Boolean, ReadOnlySpan<Byte>, Byte[], Byte[], IEnumerable<Byte[]>)
Creates an initial HandshakeState.
Declaration
public HandshakeState Create(bool initiator, ReadOnlySpan<byte> prologue = default(ReadOnlySpan<byte>), byte[] s = null, byte[] rs = null, IEnumerable<byte[]> psks = null)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | initiator | A boolean indicating the initiator or responder role. |
System.ReadOnlySpan<System.Byte> | prologue | A byte sequence which may be zero-length, or which may contain context information that both parties want to confirm is identical. |
System.Byte[] | s | The local static private key (optional). |
System.Byte[] | rs | The remote party's static public key (optional). |
System.Collections.Generic.IEnumerable<System.Byte[]> | psks | The collection of zero or more 32-byte pre-shared secret keys. |
Returns
Type | Description |
---|---|
HandshakeState | The initial handshake state. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | Thrown if any of the following conditions is satisfied: - - - HandshakePattern requires the HandshakeState
to be initialized with local and/or remote static key,
but - One or more pre-shared keys are not 32 bytes in length. - Number of pre-shared keys does not match the number of PSK modifiers. - Fallback modifier is present (fallback can only be applied by calling the Fallback(Protocol, ProtocolConfig) method on existing handshake state). |
Parse(ReadOnlySpan<Char>)
Converts the Noise protocol name to its Protocol equivalent.
Declaration
public static Protocol Parse(ReadOnlySpan<char> s)
Parameters
Type | Name | Description |
---|---|---|
System.ReadOnlySpan<System.Char> | s | The Noise protocol name (e.q. Noise_KNpsk2_25519_ChaChaPoly_SHA512). |
Returns
Type | Description |
---|---|
Protocol | An object that is equivalent to the Noise
protocol name contained in |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | Thrown if |