Noise protocol implemented with Swift.
Add the following lines to Package.swift
.
dependencies: [
...,
.package(url: "https://github.com/samueltangz/swift-noise-protocol.git", from: "0.2.1")
...
],
targets: (
...
dependencies: [
...,
"SwiftNoise",
...
],
...
)
import SwiftNoise
The functions are supported based on section 12 of the specification.
The handshake patterns defined in section 7 of the specification will be supported.
N
K
X
NN
NK
NX
KN
KK
KX
XN
XK
XX
IN
IK
IX
The following is an example usage for Noise with Noise_X_25519_AESGCM_SHA256
.
let responderStaticKeyPair = try! generateKeyPair()
let initiatorEphemeralKeyPair = try! generateKeyPair()
let responderEphemeralKeyPair = try! generateKeyPair()
let prologue = Data()
let initiatorState = try! HandshakeState(
pattern: .N,
initiator: true,
prologue: prologue,
e: initiatorEphemeralKeyPair,
rs: responderStaticKeyPair.publicKey
)
let responderState = try! HandshakeState(
pattern: .N,
initiator: false,
prologue: prologue,
s: responderStaticKeyPair,
e: responderEphemeralKeyPair
)
// -> e, es
let initiatorTx = try! initiatorState.writeMessage(payload: Data())
assert(try! responderState.readMessage(message: initiatorTx) == Data())
assert(responderState.remoteE! == initiatorEphemeralKeyPair.publicKey)
We use swift-format for automatic code formatting.
brew install swift-format
swift-format -i --configuration=swift-format.json */**/**/*.swift