https://github.com/abeaumont/ocaml-chacha
ChaCha20, ChaCha12 and ChaCha8 encryption functions, in OCaml
https://github.com/abeaumont/ocaml-chacha
chacha chacha20 cryptography ocaml
Last synced: 6 months ago
JSON representation
ChaCha20, ChaCha12 and ChaCha8 encryption functions, in OCaml
- Host: GitHub
- URL: https://github.com/abeaumont/ocaml-chacha
- Owner: abeaumont
- License: bsd-2-clause
- Created: 2017-09-29T20:40:27.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2022-04-03T22:26:14.000Z (over 3 years ago)
- Last Synced: 2023-03-15T19:30:57.751Z (over 2 years ago)
- Topics: chacha, chacha20, cryptography, ocaml
- Language: OCaml
- Homepage: https://abeaumont.github.io/ocaml-chacha
- Size: 44.9 KB
- Stars: 12
- Watchers: 6
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: LICENSE.md
Awesome Lists containing this project
README
[](https://abeaumont.github.io/ocaml-chacha)
[](https://travis-ci.org/abeaumont/ocaml-chacha)# ChaCha family of encryption functions, in OCaml
An OCaml implementation of [ChaCha](https://cr.yp.to/chacha/chacha-20080120.pdf) functions,
both ChaCha20 and the reduced ChaCha8 and ChaCha12 functions.
The hot loop is implemented in C for efficiency reasons.## Installation
```
opam install chacha
```## Usage
```ocaml
utop[0]> #require "mirage-crypto";;
utop[1]> #require "mirage-crypto-rng.unix";;
utop[2]> Mirage_crypto_rng_unix.initialize ();;
- : unit = ()
utop[3]> let key = Mirage_crypto_rng.generate 32;;
val key : Cstruct.t = {Cstruct.buffer = ; off = 0; len = 32}
utop[4]> let nonce = Cstruct.create 8;;
val nonce : Cstruct.t = {Cstruct.buffer = ; off = 0; len = 8}
utop[5]> #require "chacha";;
utop[6]> let state = Chacha.create key nonce;;
val state : Chacha.t =
utop[7]> Chacha.encrypt (Cstruct.of_string "My secret text") state |> Cstruct.to_string;;
- : string = "\026m.\\363\\026\\263\\207Xg\\256l\\262\\232F"
```* Key can either 32 (recommended) or 16 bytes
* Chacha state may use a different hashing function,
the recommended `Chacha_core.chacha20` is used by default.