项目作者: abeaumont

项目描述 :
ChaCha20, ChaCha12 and ChaCha8 encryption functions, in OCaml
高级语言: OCaml
项目地址: git://github.com/abeaumont/ocaml-chacha.git
创建时间: 2017-09-29T20:40:27Z
项目社区:https://github.com/abeaumont/ocaml-chacha

开源协议:BSD 2-Clause "Simplified" License

下载


docs
Build Status

ChaCha family of encryption functions, in OCaml

An OCaml implementation of ChaCha functions,
both ChaCha20 and the reduced ChaCha8 and ChaCha12 functions.
The hot loop is implemented in C for efficiency reasons.

Installation

  1. opam install chacha

Usage

  1. utop[0]> #require "mirage-crypto";;
  2. utop[1]> #require "mirage-crypto-rng.unix";;
  3. utop[2]> Mirage_crypto_rng_unix.initialize ();;
  4. - : unit = ()
  5. utop[3]> let key = Mirage_crypto_rng.generate 32;;
  6. val key : Cstruct.t = {Cstruct.buffer = <abstr>; off = 0; len = 32}
  7. utop[4]> let nonce = Cstruct.create 8;;
  8. val nonce : Cstruct.t = {Cstruct.buffer = <abstr>; off = 0; len = 8}
  9. utop[5]> #require "chacha";;
  10. utop[6]> let state = Chacha.create key nonce;;
  11. val state : Chacha.t = <abstr>
  12. utop[7]> Chacha.encrypt (Cstruct.of_string "My secret text") state |> Cstruct.to_string;;
  13. - : 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.