https://github.com/sgiath/noise-protocol
Elixir implementation of Noise protocol specification
https://github.com/sgiath/noise-protocol
elixir noise-protocol-framework
Last synced: about 20 hours ago
JSON representation
Elixir implementation of Noise protocol specification
- Host: GitHub
- URL: https://github.com/sgiath/noise-protocol
- Owner: sgiath
- License: other
- Created: 2023-12-29T20:24:49.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2025-11-24T22:31:35.000Z (7 months ago)
- Last Synced: 2026-05-29T04:09:38.936Z (22 days ago)
- Topics: elixir, noise-protocol-framework
- Language: Elixir
- Homepage: https://sgiath.dev/libraries#noise
- Size: 1.74 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Noise Protocol
[](https://hex.pm/packages/noise_protocol)
[](https://hexdocs.pm/noise_protocol)
Elixir implementation of [Noise Protocol Framework](https://noiseprotocol.org/noise.html).
## Project Goals
The main goal of this project is to provide a complete and correct implementation of the Noise Protocol Framework in Elixir. It aims to:
- Follow the [Noise Protocol Specification](https://noiseprotocol.org/noise.html) precisely.
- Offer a flexible and easy-to-use API for building secure network protocols.
- Support a wide range of cryptographic primitives as defined in the spec.
## Project Status
The project currently implements the core Noise protocol framework with support for the following primitives:
- **Cipher Functions**: AESGCM, ChaChaPoly
- **Diffie-Hellman Functions**: X25519, X448, Secp256k1
- **Hash Functions**: SHA256, SHA512, BLAKE2s, BLAKE2b
It supports the standard handshake patterns and can be used to establish secure channels.
## Quick Installation
Add `noise_protocol` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:noise_protocol, "~> 0.2.0"}
]
end
```
## Usage Guide
Here is a basic example of how to perform a handshake using the `Noise_IK_25519_ChaChaPoly_BLAKE2s` protocol.
### Initiator
```elixir
# 1. Select the protocol
protocol = Noise.protocol("Noise_IK_25519_ChaChaPoly_BLAKE2s")
# 2. Generate keys (or load them)
kp_i = Noise.generate_keypair(protocol)
# Assuming we know the responder's static public key `kp_r_pub`
# 3. Initialize handshake state
# :s -> Local static keypair
# :rs -> Remote static public key
state_i = Noise.handshake(protocol, true, <<>>, s: kp_i, rs: kp_r_pub)
# 4. Perform handshake step (Initiator starts in IK pattern)
# Write the first message
{:ok, msg1, state_i} = Noise.handshake_step(state_i, "payload1")
# Send `msg1` to the responder...
```
### Responder
```elixir
# 1. Select the protocol
protocol = Noise.protocol("Noise_IK_25519_ChaChaPoly_BLAKE2s")
# 2. Load keys
# `kp_r` is the responder's static keypair
# 3. Initialize handshake state
# responder is `false` for initiator param
state_r = Noise.handshake(protocol, false, <<>>, s: kp_r)
# 4. Receive message and process it
# `msg1` received from network
{:ok, "payload1", state_r} = Noise.handshake_step(state_r, msg1)
```
Once the handshake is complete (which depends on the specific pattern), `Noise.handshake_step/2` will return `{:complete, message, {cipher_state_1, cipher_state_2}}`. You can then use these cipher states to encrypt and decrypt transport messages.
```elixir
# Encrypting data
{ciphertext, new_cs1} = Noise.encrypt(cipher_state_1, "Hello World")
# Decrypting data
{plaintext, new_cs2} = Noise.decrypt(cipher_state_2, ciphertext)
```
For detailed documentation, refer to the [API Docs](https://hexdocs.pm/noise_protocol).