Skip to main content

Crypto wrapper library for the Decentriq platform.

Project description

🌶 CryptoLib: chily

Authenticated Encryption

The plan for chily is to have pure Rust implementation for the following crypto protocols (following RFC 7539):

  • Key exchange: X25519
  • Encryption: XSalsa20 stream cipher
  • Authentication: Poly1305 MAC

In contrast to RFC 7530 we use XChaCha20 instead of ChaCha in order to have a 24 byte nonce (instead of 96bits).

Randomness

We heavily rely on "secure" randomness in this library. Mainly for key generation in the enclave (no external static key can be provided) and nonce derivation. Depending on the target we use the following sources:

  • x64: getrandom system call if available, otherwise /dev/urandom
  • SGX: Based on rdrand instructions of the CPU (https://docs.rs/rdrand/0.6.0/rdrand/)
  • WASM: Crypto.getRandomValues exposed by the JS engine via wasm-bindgen bridge

🚴 Usage

Rust

Just add chily as a dependency and see how it's being used in the following example:

// generate random keypair
let alice = Keypair::generate();

// or parse a secret from existing bytes
let bob_secret: [u8; 32] = [
    64, 218, 126, 251, 171, 87, 50, 212, 196, 55, 166, 65, 195, 199, 64, 229, 128, 129,
    243, 144, 211, 52, 77, 159, 48, 167, 45, 8, 79, 228, 116, 101,
];
// and then create the keypair
let bob = Keypair::from_secret_key(bob_secret.into());

// define some buffer
let plaintext = b"avato rocks";
let mut buffer = plaintext.to_vec();

// create a random Nonce
let nonce = Nonce::from_random();

// instantiate the cipher
let mut cipher = Cipher::new(&alice.secret, &bob.public);

// encrypt in place
let tag = cipher.encrypt_in_place_detached(&mut buffer, b"", &nonce);

// decrypt in place
cipher.decrypt_in_place_detached(&mut buffer, b"", &nonce, &tag);

assert_eq!(plaintext.to_vec(), buffer); // Ok!

JavaScript / TypeScript

Add the package from folder js/pkg as dependency to the package.json in your project:

  "dependencies": {
    "chily": "file:chily-0.2.0.tgz"
  }

Then the library can be used as shown below:

import * as chily from "chily";

// generate random keypair
let alice = chily.Keypair.fromRandom();

// or parse a secret from existing bytes
let bob_secret = chily.StaticSecret.fromBytes(new Uint8Array([
    64, 218, 126, 251, 171, 87, 50, 212, 196, 55, 166, 65, 195, 199, 64, 229, 128, 129,
    243, 144, 211, 52, 77, 159, 48, 167, 45, 8, 79, 228, 116, 101,
]));
// and then create the keypair
let bob = chily.Keypair.fromSecret(bob_secret);

// create a random Nonce
let nonce = chily.Nonce.fromRandom();

// instantiate the cipher
let cipher = chily.Cipher.new(alice.secret, bob.publicKey);

// define some buffer
var plaintext = new Uint8Array([21,31]);

// encrypt
let encrypted = cipher.encrypt(plaintext, nonce);

// decrypt
let decrypted = cipher.decrypt(encrypted, nonce);

expect(plaintext).to.eql(decrypted); // Ok!

Python

Install the wheel from folder py/pkg by running pip3 install chily.whl Then the library can be used as shown below:

import chily

# generate random keypair
alice = chily.Keypair.from_random();

# or parse a secret from existing bytes
bob_secret = chily.StaticSecret.from_bytes([
    64, 218, 126, 251, 171, 87, 50, 212, 196, 55, 166, 65, 195, 199, 64, 229, 128, 129,
    243, 144, 211, 52, 77, 159, 48, 167, 45, 8, 79, 228, 116, 101,
])
# and then create the keypair
bob = chily.Keypair.from_secret(bob_secret)

# create a random Nonce
nonce = chily.Nonce.from_random();

# instantiate the cipher
cipher = chily.Cipher(alice.secret, bob.publicKey, nonce)

# define some buffer
plaintext = [21,31]

# encrypt 
enc = cipher.encrypt(plaintext, nonce)

# decrypt
dec = cipher.decrypt(enc, nonce)

assert plaintext == dec

🛠️ Test

We have four different test stages.

Rust

Regular tests written in Rust. Just call cargo test.

WASM

Some test can be specified to run in the node wasm interpreter. They are defined using the [wasm_bindgen_test] attribute. In order to run them go execute the following command in the js folder:

npm run wasm-test

JavaScript / TypeScript

There also are some tests for the JavaScript bindings using mocha and chai.
They are defined in the folder js/tests and can be run using the following command:

npm run test

Python

There also are some tests for the Python bindings using tox.
They are defined in the folder py/tests and can be run using the following command:

tox

🎁 Build & Package

JavaScript / TypeScript

To build the wasm code and the js/ts binding run in the js folder:

  • npm run build-node for nodejs
  • npm run build-bundler for browser / webpack
  • npm run build for one compatible with both

Then package the dependency by running npm pack in the corresponding pkg dir.

Python

To build the python bindings you'll need maturin. Run in the py folder:

  • pip3 install maturin to install maturin
  • ./build.sh to build the wheel for the current platform in the pkg folder

🔋 ToDos

  • Add X.509 cert support
  • Error handling
  • Add Poly1305 MAC

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

chily-0.6.0-pp37-pypy37_pp73-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (936.7 kB view details)

Uploaded PyPymanylinux: glibc 2.12+ x86-64

chily-0.6.0-cp310-none-win_amd64.whl (191.6 kB view details)

Uploaded CPython 3.10Windows x86-64

chily-0.6.0-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (936.4 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.12+ x86-64

chily-0.6.0-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (572.5 kB view details)

Uploaded CPython 3.10macOS 10.9+ universal2 (ARM64, x86-64)macOS 10.9+ x86-64macOS 11.0+ ARM64

chily-0.6.0-cp39-none-win_amd64.whl (191.6 kB view details)

Uploaded CPython 3.9Windows x86-64

chily-0.6.0-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (936.4 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.12+ x86-64

chily-0.6.0-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (572.5 kB view details)

Uploaded CPython 3.9macOS 10.9+ universal2 (ARM64, x86-64)macOS 10.9+ x86-64macOS 11.0+ ARM64

chily-0.6.0-cp38-none-win_amd64.whl (191.5 kB view details)

Uploaded CPython 3.8Windows x86-64

chily-0.6.0-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (936.4 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.12+ x86-64

chily-0.6.0-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (572.4 kB view details)

Uploaded CPython 3.8macOS 10.9+ universal2 (ARM64, x86-64)macOS 10.9+ x86-64macOS 11.0+ ARM64

chily-0.6.0-cp37-none-win_amd64.whl (191.5 kB view details)

Uploaded CPython 3.7Windows x86-64

chily-0.6.0-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (936.5 kB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.12+ x86-64

chily-0.6.0-cp37-cp37m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (572.7 kB view details)

Uploaded CPython 3.7mmacOS 10.9+ universal2 (ARM64, x86-64)macOS 10.9+ x86-64macOS 11.0+ ARM64

chily-0.6.0-cp36-cp36m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (936.5 kB view details)

Uploaded CPython 3.6mmanylinux: glibc 2.12+ x86-64

File details

Details for the file chily-0.6.0-pp37-pypy37_pp73-manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for chily-0.6.0-pp37-pypy37_pp73-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 3af265dd7a4ec9743a741e941874cf36db059d92207eef6eafd3b199e1106f4e
MD5 c88e5754f24d1a20db86588f713d9b2e
BLAKE2b-256 be7eae49ec7e51fdcb4cddfbf432963c6ba62c03a2a84b44d563499359b90eca

See more details on using hashes here.

File details

Details for the file chily-0.6.0-cp310-none-win_amd64.whl.

File metadata

  • Download URL: chily-0.6.0-cp310-none-win_amd64.whl
  • Upload date:
  • Size: 191.6 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.7.9

File hashes

Hashes for chily-0.6.0-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 9ac3f2e95f7641811ed76101ac21331ef5761653901ec846d1bec157ea356230
MD5 ef9597b2c8b2dd75aa16125006b28cb5
BLAKE2b-256 eb2770bfecab088d4bd1d117524f10d119eba713b3be3f699c6481d854dfe627

See more details on using hashes here.

File details

Details for the file chily-0.6.0-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for chily-0.6.0-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 35f4e8138fdef13eac0828e54eba0ad5acb39b44f9aea5935a485709454ccbc0
MD5 e06aeb81ca646a8106b38304573d5619
BLAKE2b-256 663e5466641f9161c5c09fe54e2660c6fdb06b2cbf41c41e476e2cbe9662011f

See more details on using hashes here.

File details

Details for the file chily-0.6.0-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for chily-0.6.0-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 641ca3cc400798a6086a8a966d92ce4e3ac6f3e8afc2d31c8a1220fa69cd0c5c
MD5 17938237e725f41c8fe01dbf7946dd6a
BLAKE2b-256 9cf64d6b3be66ea827368b26e3d37ba18688b399da4e1d29f610ca4ec36a495c

See more details on using hashes here.

File details

Details for the file chily-0.6.0-cp39-none-win_amd64.whl.

File metadata

  • Download URL: chily-0.6.0-cp39-none-win_amd64.whl
  • Upload date:
  • Size: 191.6 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.7.9

File hashes

Hashes for chily-0.6.0-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 8a5c12d9c6e2f52eebb687a029fa73a193e7377134f5e11c46c16736f425b9f4
MD5 c75f6367522fc5f571cd050ba5fbd5f4
BLAKE2b-256 70f9f5b87ea93582d48b09690c0fdcbd296e8e12c622cfba5f73ab8b794ec415

See more details on using hashes here.

File details

Details for the file chily-0.6.0-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for chily-0.6.0-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 67a18bda9e31e205219247e6e7aa85968275a8ddad472a5753da2a54de6e0843
MD5 645b8680e79c130849b801222d2d7144
BLAKE2b-256 c50d783b13bc2cf42dcb6e8a5d5c61cbd2c1604e22a87c4d3c31530dfde7834c

See more details on using hashes here.

File details

Details for the file chily-0.6.0-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for chily-0.6.0-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 734c3d8d0960175bcbb4d40b374882265b4d2033f7fc5139d2bdbf585eb63f8e
MD5 557d680a536972c939bf71d5173c2958
BLAKE2b-256 2574bc7847ef15c8de472eb23336029851f35e67203bc06fc6e5cd5d9c1ba37f

See more details on using hashes here.

File details

Details for the file chily-0.6.0-cp38-none-win_amd64.whl.

File metadata

  • Download URL: chily-0.6.0-cp38-none-win_amd64.whl
  • Upload date:
  • Size: 191.5 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.7.9

File hashes

Hashes for chily-0.6.0-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 35f0e2e6992c47dd1bfe132449ed5788bafb7a4559b5d37ee68361103a337f8d
MD5 e2e9d4ba40f6d798eb569c7630cfb2c0
BLAKE2b-256 b7876efaf51f02a55e488de3d06acc9dd9d668de2c807055310683499eb6e8a9

See more details on using hashes here.

File details

Details for the file chily-0.6.0-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for chily-0.6.0-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 fd41cc39effb5dcea65d51083b0dc67728ddad97233c3947424be586f8c965c9
MD5 294738914aeb88fdb1c396ef1acdff11
BLAKE2b-256 37511b698be4ef8a9c02b120fb88ce32ff122619d69942dbac2511c9b6017c44

See more details on using hashes here.

File details

Details for the file chily-0.6.0-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for chily-0.6.0-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 6e2f5068a68b5166fc9f02a34ddd78f81bd997a48b1d44d32ecf7323f2098b84
MD5 319f29cb8187f4c074105e7d10005e9f
BLAKE2b-256 a00ec7c8d866ea86616c2dd869723805c26093b0b2af5bdf20182312ce6cd10f

See more details on using hashes here.

File details

Details for the file chily-0.6.0-cp37-none-win_amd64.whl.

File metadata

  • Download URL: chily-0.6.0-cp37-none-win_amd64.whl
  • Upload date:
  • Size: 191.5 kB
  • Tags: CPython 3.7, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.7.9

File hashes

Hashes for chily-0.6.0-cp37-none-win_amd64.whl
Algorithm Hash digest
SHA256 eb0b878eb7027bef4feb9d3a6842fecf2d0e9c6aee36db888b70c6fab2d1a5c4
MD5 a59352a08809cc7ad369fdd1fe45edd8
BLAKE2b-256 60b04c4115184af210f4d24aa58fe8e0085a8fbb34156dabc867e11d953a9533

See more details on using hashes here.

File details

Details for the file chily-0.6.0-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for chily-0.6.0-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 42eaeb7f57347c5e830903b2e403c40b8d2a939419538e2ef1dc2ebea60c9c6e
MD5 d010fe50c7860af84b3f3a73068f845f
BLAKE2b-256 2b4b4035a5aa05135c89f16a42ad48e15fc45e1d9addac1c09d27289ec854664

See more details on using hashes here.

File details

Details for the file chily-0.6.0-cp37-cp37m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for chily-0.6.0-cp37-cp37m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 0b561893a49bdb6b18462136d0ef00468c6bc5d04c9040a79d3f4977299d3cc6
MD5 83f6f18db7c668e82cb8bb233716ed33
BLAKE2b-256 44a402a6457d10479434bc2843585e9500cd1c74837a835987883dbb8db2b71d

See more details on using hashes here.

File details

Details for the file chily-0.6.0-cp36-cp36m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for chily-0.6.0-cp36-cp36m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 8ca1ac8fa66a48a8b731aab8ed046434cfe8ccefc8bbf3464197d920a8085c95
MD5 8dc44670d57ac8246fcfe85f4ec5bb5a
BLAKE2b-256 e8f080b5c5a044ec1a86fd762bf26800462c506f1c02f414c8029f4854039242

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page