Documentation ¶
Index ¶
- Constants
- Variables
- func PKCS7_Pad(payload []byte, paddingSize int) ([]byte, error)
- func PKCS7_Unpad(payload []byte, paddingSize int) ([]byte, error)
- type Handshake
- func NewHandshake(protocolID WakuNoiseProtocolID, initiator bool, staticKeypair n.DHKey, ...) (*Handshake, error)
- func NewHandshake_K1K1_25519_ChaChaPoly_SHA256(staticKeypair n.DHKey, initiator bool, peerStaticKey []byte, prologue []byte) (*Handshake, error)
- func NewHandshake_XK1_25519_ChaChaPoly_SHA256(staticKeypair n.DHKey, initiator bool, peerStaticKey []byte, prologue []byte) (*Handshake, error)
- func NewHandshake_XX_25519_ChaChaPoly_SHA256(staticKeypair n.DHKey, initiator bool, prologue []byte) (*Handshake, error)
- func NewHandshake_XXpsk0_25519_ChaChaPoly_SHA256(staticKeypair n.DHKey, initiator bool, presharedKey []byte, prologue []byte) (*Handshake, error)
- type HandshakeStepResult
- type NoisePublicKey
- type PayloadV2
- type SerializedNoisePublicKey
- type WakuNoiseProtocolID
Constants ¶
const ChaChaPolyTagSize = byte(16)
const MaxUint8 = 1<<8 - 1
const NoisePaddingBlockSize = 248
Variables ¶
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) )
var ErrorHandshakeComplete = errors.New("handshake complete")
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
var HandshakeXK1 = n.HandshakePattern{ Name: "XK1", ResponderPreMessages: []n.MessagePattern{n.MessagePatternS}, Messages: [][]n.MessagePattern{ {n.MessagePatternE}, {n.MessagePatternE, n.MessagePatternDHEE, n.MessagePatternDHES}, {n.MessagePatternS, n.MessagePatternDHSE}, }, }
XK1:
<- s ... -> e <- e, ee, es -> s, se
var HandshakeXX = n.HandshakePattern{ Name: "XX", Messages: [][]n.MessagePattern{ {n.MessagePatternE}, {n.MessagePatternE, n.MessagePatternDHEE, n.MessagePatternS, n.MessagePatternDHES}, {n.MessagePatternS, n.MessagePatternDHSE}, }, }
XX:
-> e <- e, ee, s, es -> s, se
var HandshakeXXpsk0 = n.HandshakePattern{ Name: "XXpsk0", Messages: [][]n.MessagePattern{ {n.MessagePatternPSK, n.MessagePatternE}, {n.MessagePatternE, n.MessagePatternDHEE, n.MessagePatternS, n.MessagePatternDHES}, {n.MessagePatternS, n.MessagePatternDHSE}, }, }
XXpsk0:
-> psk, e <- e, ee, s, es -> s, se
Functions ¶
func PKCS7_Pad ¶ added in v0.2.2
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
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 ¶
Decrypt calls the cipher's decryption. It decrypts the provided payload and returns the message in plaintext
func (*Handshake) Encrypt ¶
Encrypt calls the cipher's encryption. It encrypts the provided plaintext and returns a PayloadV2
func (*Handshake) HandshakeComplete ¶
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 ¶
HandshakeStepResult stores the intermediate result of processing messages patterns
type NoisePublicKey ¶
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 ¶
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) Serialize ¶
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