Giter VIP home page Giter VIP logo

doubleratchet's Introduction

DoubleRatchet

This is a mostly complete implementation of the Encrypted Header variant of the The Double Ratchet Algorithm designed by Open Whisper Systems.

WARNING: This implementation was created for learning purposes and should not be used outside of a development environment. Any concerns or suggestions are very welcome.

This implementation was built using the NodeJS crypto library as its only dependency. I decided to do this as Electron is the intended usage. However, it would be trivial to abstract the crypto provider in order to make this library browser friendly.

Usage

const Ratchet = require('doubleratchet').Ratchet

const pskRoot        = ... // a shared secret between alice and bob
const pskHeader      = ... // a shared secret between alice and bob
const pskNextHeader  = ... // a shared secret between alice and bob

const alice = new Ratchet(pskRoot, pskHeader, pskNextHeader)
const bob = new Ratchet(pskRoot, pskNextHeader, pskHeader)

alice.acceptHandshake( bob.makeHandshake() )

bob.decrypt( alice.encrypt('hello bob') )   // "hello bob"
alice.decrypt( bob.encrypt('hello alice') ) // "hello alice"

See examples directory for more.

Development

git clone https://github.com/jowy/doubleratchet.git
cd doubleratchet
yarn install
yarn build

Implementation Parameters

Parameter Implementation
Ratchet ECDH Curve secp521r1
HMAC-KDF (HKDF) SHA256
Header Cipher AES256 CBC Mode
Header Key Derivation Salted HKDF
Header Key Length 32 Bytes (Truncated)
Header IV Derivation Salted HKDF
Message Cipher AES256 CBC Mode
Message Key Derivation Salted HKDF
Message Key Length 32 Bytes (Truncated)
Message IV Derivation Salted HKDF
Auth Tag Derivation Salted HKDF
Auth Key Length 32 Bytes (Truncated)
Auth Tag Length 16 Bytes (Truncated)
Skipped Message Key Expire Method Ratchet Invocation
Skipped Message Key TTL 20

TODO

  • flow typing
  • comments
  • tests
  • clean up KDF flow
  • clean up Key and CipherKey initialization and handling
  • clean up buffer handling
  • state (de)serialization
  • fix header & nextHeader initialization and flow
  • proper handling of input & output encoding
  • revise CipherKey kdf
  • error handling for various things
  • throw properly typed errors
  • rollback chain state on failure
  • more examples demonstrating various features of the protocol
  • API outline

doubleratchet's People

Contributors

jowy avatar

Watchers

James Cloos avatar Ryan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.