All Projects → soatok → rawr-x3dh

soatok / rawr-x3dh

Licence: ISC license
TypeScript Implementation of X3DH

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to rawr-x3dh

Kryptor
A simple, modern, and secure encryption and signing tool that aims to be a better version of age and Minisign.
Stars: ✭ 267 (+423.53%)
Mutual labels:  libsodium, ed25519, x25519
Cryptography-Guidelines
Guidance on implementing cryptography as a developer.
Stars: ✭ 15 (-70.59%)
Mutual labels:  ed25519, x25519
noble-ed25519
Fastest JS implementation of ed25519, x25519 & ristretto255. Independently audited, high-security, 0-dependency EDDSA signatures and ECDH key agreement
Stars: ✭ 220 (+331.37%)
Mutual labels:  ed25519, x25519
Rbnacl
Ruby FFI binding to the Networking and Cryptography (NaCl) library (a.k.a. libsodium)
Stars: ✭ 910 (+1684.31%)
Mutual labels:  libsodium, ed25519
double-ratchet
Double ratchet algorithm for E2E encryption
Stars: ✭ 59 (+15.69%)
Mutual labels:  diffie-hellman, x3dh
Sodium compat
Pure PHP polyfill for ext/sodium
Stars: ✭ 736 (+1343.14%)
Mutual labels:  libsodium, ed25519
Halite
High-level cryptography interface powered by libsodium
Stars: ✭ 933 (+1729.41%)
Mutual labels:  libsodium, ed25519
rfc7748 precomputed
Updated! (Dec2-2019) This is a C-language software library that provides optimized implementations of the Diffie-Hellman functions known as X25519 and X448 (RFC-7748) for 64-bit architectures.
Stars: ✭ 43 (-15.69%)
Mutual labels:  x25519, diffie-hellman
Nsec
A modern and easy-to-use cryptographic library for .NET Core based on libsodium
Stars: ✭ 217 (+325.49%)
Mutual labels:  libsodium, ed25519
Signatory
Multi-provider digital signature library for Rust
Stars: ✭ 136 (+166.67%)
Mutual labels:  libsodium, ed25519
Tweetnacl Js
Port of TweetNaCl cryptographic library to JavaScript
Stars: ✭ 1,176 (+2205.88%)
Mutual labels:  libsodium, ed25519
sodalite
tweetnacl in rust
Stars: ✭ 26 (-49.02%)
Mutual labels:  libsodium, ed25519
libeddsa
cryptographic library for ed25519 and curve25519
Stars: ✭ 20 (-60.78%)
Mutual labels:  ed25519, x25519
Computer-Security-algorithms
👨‍💻 Computer Security algorithms in C#
Stars: ✭ 48 (-5.88%)
Mutual labels:  diffie-hellman
iroha-ed25519
RFC8032 compatible Ed25519 implementation with pluggable hash (sha2-512, sha3-512)
Stars: ✭ 28 (-45.1%)
Mutual labels:  ed25519
mpc
Secure Multi-Party Computation (MPC) with Go. This project implements secure two-party computation with Garbled circuit protocol.
Stars: ✭ 41 (-19.61%)
Mutual labels:  ed25519
libsalty
Elixir bindings for libsodium (NIF)
Stars: ✭ 20 (-60.78%)
Mutual labels:  libsodium
faexport
The API for Furaffinity you wish existed
Stars: ✭ 61 (+19.61%)
Mutual labels:  furry
wascap
Embed, extract, and validate capability claims in JWTs for WebAssembly modules
Stars: ✭ 59 (+15.69%)
Mutual labels:  ed25519
dryoc
Don't Roll Your Own Crypto: pure-Rust, hard to misuse cryptography library
Stars: ✭ 163 (+219.61%)
Mutual labels:  libsodium

Rawr X3DH

TypeScript implementation of X3DH, as described in Going Bark: A Furry's Guide to End-to-End Encryption.

Support me on Patreon

Travis CI npm version

OwO What's This?

This library implements the Extended Triple Diffie-Hellman key exchange, with a few minor tweaks:

  1. Identity keys are Ed25519 public keys, not X25519 public keys. See this for an explanation.
  2. Encryption/decryption and KDF implementations are pluggable (assuming you implement the interface I provide), so you aren't married to HKDF or a particular cipher. (Although I recommend hard-coding it to your application!)

Installation

First, you'll want to install this library via your package manager.

npm install rawr-x3dh

If you're working server-side, you'll also want to install sodium-native, so that sodium-plus will run faster.

If you're working in a browser or browser extension, don't install sodium-native.

Usage

First, you'll want to import the X3DH class from our module.

import { X3DH } from 'rawr-x3dh';

const x3dh = new X3DH();

Note: You can pass some classes to the constructor to replace my algorithm implementations for your own.

import { X3DH } from 'rawr-x3dh';

const x3dh = new X3DH(
    sessionKeyManager, /* SessionKeyManagerInterface */
    identityKeyManager, /* IdentityKeyManagerInterface */
    symmetricEncryptionHandler, /* SymmetricEncryptionInterface */
    keyDerivationFunction /* KeyDerivationFunction */
);

Once your X3DH object's instantiated, you will be able to initialize handshakes either as a sender or as a recipient. Then you will be able to encrypt additional messages on either side, and the encryption key shall ratchet forward.

const firstEncrypted = await x3dh.initSend(
    'recipient@server2',
    serverApiCallFunc,
    firstMessage
); 

The serverApiCallFunc parameter should be a function that sends a request to the server to obtain the identity key, signed pre-key, and optional one-time key for the handshake.

See the definition of the InitClientFunction type in lib/index.ts.

Once this has completed, you can call encryptNext() multiple times to append messages to send.

const nextEncrypted = await x3dh.encryptNext(
    'recipient@server2',
    'This is a follow-up message UwU'
);

On the other side, your communication partner will use the following feature.

const [sender, firstMessage] = await x3dh.initRecv(senderInfo);
const nextMessage = await x3dh.decryptNext(sender, nextEncrypted);

Note: initRecv() will always return the sender identity (a string) and the message (a Buffer that can be converted to a string). The sender identity should be usable for decryptNext() calls.

However, that doesn't mean it's trustworthy! This library only implements the X3DH pattern. It doesn't implement the Gossamer integration.

Should I Use This?

Don't use it in production until version 1.0.0 has been tagged. The API can break at any moment until that happens (especially if I decide I hate the default key management classes I wrote).

However, feel free to test and play with it.

Questions and Answers

Any Interest in Porting This to $LANG?

I'd love to port this to more languages! That will also allow me to write end-to-end integration tests.

As long as there's a good libsodium implementation, it should be doable.

However, I don't have nearly as much free time as I'd like, so I can't commit to building or supporting multiple implementations right now.

Conversely, if you've ported this to another language, let me know and I'll maintain a list here:

  • (Currently, none.)

Why "Rawr"?

The canonical abbreviation for the eXtended 3-way Diffie Hellman deniable authenticated key exchange is X3DH.

There is a cursed furry copypasta/meme that begins with "rawr x3". The juxtaposition of "x3" and "X3DH" is too perfect an opportunity for dumb jokes to pass up.

Is this a furry thing?

You betcha!

And remember: It's not furry trash, it's yiff-raff.

Why? Just, Why?

I've written a lot of words to answer this line of questioning already on my blog.

You will probably find the answer you're seeking here or here.

Comic by loviesophiee

This is Unprofessional

Folks often say there's an XKCD for Everything! And thus:

XKCD

Who Made That Awesome Project Logo?

Sophie made it.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].