• API Reference
Show / Hide Table of Contents
  • Noise
    • CipherFunction
    • DhFunction
    • HandshakePattern
    • HandshakeState
    • HashFunction
    • KeyPair
    • MessagePattern
    • PatternModifiers
    • PreMessagePattern
    • Protocol
    • ProtocolConfig
    • Token
    • Transport

Class Protocol

A concrete Noise protocol (e.g. Noise_XX_25519_AESGCM_SHA256 or Noise_IK_25519_ChaChaPoly_BLAKE2b).

Inheritance
System.Object
Protocol
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: Noise
Assembly: Noise.dll
Syntax
public sealed class Protocol

Constructors

| Improve this Doc View Source

Protocol(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 handshakePattern, cipher, or hash is null.

System.ArgumentException

Thrown if modifiers does not represent a valid combination of pattern modifiers.

| Improve this Doc View Source

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 handshakePattern is null.

System.ArgumentException

Thrown if modifiers does not represent a valid combination of pattern modifiers.

Fields

| Improve this Doc View Source

MaxMessageLength

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 Source

Cipher

Gets the cipher function.

Declaration
public CipherFunction Cipher { get; }
Property Value
Type Description
CipherFunction
| Improve this Doc View Source

Dh

Gets the Diffie-Hellman function.

Declaration
public DhFunction Dh { get; }
Property Value
Type Description
DhFunction
| Improve this Doc View Source

HandshakePattern

Gets the handshake pattern.

Declaration
public HandshakePattern HandshakePattern { get; }
Property Value
Type Description
HandshakePattern
| Improve this Doc View Source

Hash

Gets the hash function.

Declaration
public HashFunction Hash { get; }
Property Value
Type Description
HashFunction
| Improve this Doc View Source

Modifiers

Gets the combination of pattern modifiers.

Declaration
public PatternModifiers Modifiers { get; }
Property Value
Type Description
PatternModifiers

Methods

| Improve this Doc View Source

Create(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 config is null.

System.ArgumentException

Thrown if any of the following conditions is satisfied:

- config does not contain a valid DH private key.

- config does not contain a valid DH public key.

- 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.

| Improve this Doc View Source

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:

- s is not a valid DH private key.

- rs is not a valid DH public key.

- HandshakePattern requires the HandshakeState to be initialized with local and/or remote static key, but s and/or rs 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.

- Fallback modifier is present (fallback can only be applied by calling the Fallback(Protocol, ProtocolConfig) method on existing handshake state).

| Improve this Doc View Source

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 s.

Exceptions
Type Condition
System.ArgumentException

Thrown if s is not a valid Noise protocol name.

  • Improve this Doc
  • View Source
Back to top Generated by DocFX