noise

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 15, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const ChaChaPolyTagSize = byte(16)
View Source
const MaxUint8 = 1<<8 - 1
View Source
const NoisePaddingBlockSize = 248

Variables

View Source
var (
	None                                 = WakuNoiseProtocolID(0)
	Noise_K1K1_25519_ChaChaPoly_SHA256   = WakuNoiseProtocolID(10)
	Noise_XK1_25519_ChaChaPoly_SHA256    = WakuNoiseProtocolID(11)
	Noise_XX_25519_ChaChaPoly_SHA256     = WakuNoiseProtocolID(12)
	Noise_XXpsk0_25519_ChaChaPoly_SHA256 = WakuNoiseProtocolID(13)
	ChaChaPoly                           = WakuNoiseProtocolID(30)
)
View Source
var ErrorHandshakeComplete = errors.New("handshake complete")
View Source
var HandshakeK1K1 = n.HandshakePattern{
	Name:                 "K1K1",
	InitiatorPreMessages: []n.MessagePattern{n.MessagePatternS},
	ResponderPreMessages: []n.MessagePattern{n.MessagePatternS},
	Messages: [][]n.MessagePattern{
		{n.MessagePatternE},
		{n.MessagePatternE, n.MessagePatternDHEE, n.MessagePatternDHES},
		{n.MessagePatternDHSE},
	},
}

K1K1:

->  s
<-  s
   ...
->  e
<-  e, ee, es
->  se

XK1:

<-  s
   ...
->  e
<-  e, ee, es
->  s, se

XX:

->  e
<-  e, ee, s, es
->  s, se

XXpsk0:

->  psk, e
<-  e, ee, s, es
->  s, se

Functions

func PKCS7_Pad added in v0.2.2

func PKCS7_Pad(payload []byte, paddingSize int) ([]byte, error)

PKCS7_Pad pads a payload according to PKCS#7 as per RFC 5652 https://datatracker.ietf.org/doc/html/rfc5652#section-6.3

func PKCS7_Unpad added in v0.2.2

func PKCS7_Unpad(payload []byte, paddingSize int) ([]byte, error)

PKCS7_Unpad unpads a payload according to PKCS#7 as per RFC 5652 https://datatracker.ietf.org/doc/html/rfc5652#section-6.3

Types

type Handshake

type Handshake struct {
	// contains filtered or unexported fields
}

func NewHandshake

func NewHandshake(protocolID WakuNoiseProtocolID, initiator bool, staticKeypair n.DHKey, prologue []byte, presharedKey []byte, peerStatic []byte, peerEphemeral []byte) (*Handshake, error)

NewHandshake creates a new handshake using aa WakuNoiseProtocolID that is maped to a handshake pattern.

func NewHandshake_K1K1_25519_ChaChaPoly_SHA256

func NewHandshake_K1K1_25519_ChaChaPoly_SHA256(staticKeypair n.DHKey, initiator bool, peerStaticKey []byte, prologue []byte) (*Handshake, error)

NewHandshake_K1K1_25519_ChaChaPoly_SHA256 creates a handshake where both initiator and recever know each other handshake. Only ephemeral keys are exchanged. This handshake is useful in case the initiator needs to instantiate a new separate encrypted communication channel with the receiver

func NewHandshake_XK1_25519_ChaChaPoly_SHA256

func NewHandshake_XK1_25519_ChaChaPoly_SHA256(staticKeypair n.DHKey, initiator bool, peerStaticKey []byte, prologue []byte) (*Handshake, error)

NewHandshake_XK1_25519_ChaChaPoly_SHA256 creates a handshake where the initiator knows the receiver public static key. Within this handshake, the initiator and receiver reciprocally authenticate their static keys using ephemeral keys. We note that while the receiver's static key is assumed to be known to Alice (and hence is not transmitted), The initiator static key is sent to the receiver encrypted with a key derived from both parties ephemeral keys and the receiver's static key.

func NewHandshake_XX_25519_ChaChaPoly_SHA256

func NewHandshake_XX_25519_ChaChaPoly_SHA256(staticKeypair n.DHKey, initiator bool, prologue []byte) (*Handshake, error)

NewHandshake_XX_25519_ChaChaPoly_SHA256 creates a handshake where the initiator and receiver are not aware of each other static keys

func NewHandshake_XXpsk0_25519_ChaChaPoly_SHA256

func NewHandshake_XXpsk0_25519_ChaChaPoly_SHA256(staticKeypair n.DHKey, initiator bool, presharedKey []byte, prologue []byte) (*Handshake, error)

NewHandshake_XXpsk0_25519_ChaChaPoly_SHA256 creates a handshake where the initiator and receiver are not aware of each other static keys and use a preshared secret to strengthen their mutual authentication

func (*Handshake) Decrypt

func (hs *Handshake) Decrypt(payload *PayloadV2) ([]byte, error)

Decrypt calls the cipher's decryption. It decrypts the provided payload and returns the message in plaintext

func (*Handshake) Encrypt

func (hs *Handshake) Encrypt(plaintext []byte) (*PayloadV2, error)

Encrypt calls the cipher's encryption. It encrypts the provided plaintext and returns a PayloadV2

func (*Handshake) HandshakeComplete

func (hs *Handshake) HandshakeComplete() bool

HandshakeComplete indicates whether the handshake process is complete or not

func (*Handshake) Step

func (hs *Handshake) Step(readPayloadV2 *PayloadV2, transportMessage []byte) (*HandshakeStepResult, error)

Step advances a step in the handshake. Each user in a handshake alternates writing and reading of handshake messages. If the user is writing the handshake message, the transport message (if not empty) has to be passed to transportMessage and readPayloadV2 can be left to its default value It the user is reading the handshake message, the read payload v2 has to be passed to readPayloadV2 and the transportMessage can be left to its default values. TODO: this might be refactored into a separate `sendHandshakeMessage` and `receiveHandshakeMessage`

type HandshakeStepResult

type HandshakeStepResult struct {
	Payload2         PayloadV2
	TransportMessage []byte
}

HandshakeStepResult stores the intermediate result of processing messages patterns

type NoisePublicKey

type NoisePublicKey struct {
	Flag   byte
	PubKey []byte
}

This follows https://rfc.vac.dev/spec/35/#public-keys-serialization pk contains the X coordinate of the public key, if unencrypted (this implies flag = 0) or the encryption of the X coordinate concatenated with the authorization tag, if encrypted (this implies flag = 1) Note: besides encryption, flag can be used to distinguish among multiple supported Elliptic Curves

func Ed25519PubKeyToNoisePublicKey

func Ed25519PubKeyToNoisePublicKey(pk ed25519.PublicKey) *NoisePublicKey

EcdsaPubKeyToNoisePublicKey converts a Elliptic Curve public key to an unencrypted Noise public key

func (*NoisePublicKey) Decrypt

func (pk *NoisePublicKey) Decrypt(state *n.CipherState) error

Decrypts decrypts a Noise public key using a Cipher State

func (*NoisePublicKey) Encrypt

func (pk *NoisePublicKey) Encrypt(state *n.CipherState) error

Encrypt encrypts a Noise public key using a Cipher State

func (*NoisePublicKey) Equals

func (pk *NoisePublicKey) Equals(pk2 *NoisePublicKey) bool

Equals checks equality between two Noise public keys

func (*NoisePublicKey) Serialize

func (pk *NoisePublicKey) Serialize() SerializedNoisePublicKey

Serialize converts a Noise public key to a stream of bytes as in https://rfc.vac.dev/spec/35/#public-keys-serialization

type PayloadV2

type PayloadV2 struct {
	ProtocolId       byte
	HandshakeMessage []*NoisePublicKey
	TransportMessage []byte
}

PayloadV2 defines an object for Waku payloads with version 2 as in https://rfc.vac.dev/spec/35/#public-keys-serialization It contains a protocol ID field, the handshake message (for Noise handshakes) and a transport message (for Noise handshakes and ChaChaPoly encryptions)

func DeserializePayloadV2

func DeserializePayloadV2(payload []byte) (*PayloadV2, error)

Deserializes a byte sequence to a PayloadV2 object according to https://rfc.vac.dev/spec/35/. The input serialized payload concatenates the output PayloadV2 object fields as payload = ( protocolId || serializedHandshakeMessageLen || serializedHandshakeMessage || transportMessageLen || transportMessage)

func (*PayloadV2) Equals

func (p *PayloadV2) Equals(p2 *PayloadV2) bool

Checks equality between two PayloadsV2 objects

func (*PayloadV2) Serialize

func (p *PayloadV2) Serialize() ([]byte, error)

Serializes a PayloadV2 object to a byte sequences according to https://rfc.vac.dev/spec/35/ The output serialized payload concatenates the input PayloadV2 object fields as payload = ( protocolId || serializedHandshakeMessageLen || serializedHandshakeMessage || transportMessageLen || transportMessage) The output can be then passed to the payload field of a WakuMessage https://rfc.vac.dev/spec/14/

type SerializedNoisePublicKey

type SerializedNoisePublicKey []byte

func (SerializedNoisePublicKey) Unserialize

func (s SerializedNoisePublicKey) Unserialize() (*NoisePublicKey, error)

Unserialize converts a serialized Noise public key to a NoisePublicKey object as in https://rfc.vac.dev/spec/35/#public-keys-serialization

type WakuNoiseProtocolID

type WakuNoiseProtocolID = byte

WakuNoiseProtocolID indicates the protocol ID defined according to https://rfc.vac.dev/spec/35/#specification

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL