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.7.0rc1-py3-none-win_amd64.whl (65.8 kB view details)

Uploaded Python 3Windows x86-64

chily-0.7.0rc1-py3-none-win32.whl (64.6 kB view details)

Uploaded Python 3Windows x86

chily-0.7.0rc1-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl (831.4 kB view details)

Uploaded Python 3manylinux: glibc 2.17+ s390x

chily-0.7.0rc1-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (748.0 kB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64le

chily-0.7.0rc1-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (532.4 kB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARMv7l

chily-0.7.0rc1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (747.2 kB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

chily-0.7.0rc1-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl (758.1 kB view details)

Uploaded Python 3manylinux: glibc 2.5+ x86-64

chily-0.7.0rc1-py3-none-manylinux_2_5_i686.manylinux1_i686.whl (763.2 kB view details)

Uploaded Python 3manylinux: glibc 2.5+ i686

chily-0.7.0rc1-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (4.5 kB view details)

Uploaded Python 3macOS 10.9+ universal2 (ARM64, x86-64)macOS 10.9+ x86-64macOS 11.0+ ARM64

chily-0.7.0rc1-py3-none-macosx_10_7_x86_64.whl (3.9 kB view details)

Uploaded Python 3macOS 10.7+ x86-64

File details

Details for the file chily-0.7.0rc1-py3-none-win_amd64.whl.

File metadata

  • Download URL: chily-0.7.0rc1-py3-none-win_amd64.whl
  • Upload date:
  • Size: 65.8 kB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/0.14.16

File hashes

Hashes for chily-0.7.0rc1-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 aa94ba862349c17ea28aac70b397b9ef064d93b0096b6259cd0ffabf98184035
MD5 6e4eb0edcd229b3ed41202b87ac1a841
BLAKE2b-256 17c6d9accee50505c955df28572920ad2ecb01c24aefcdbeff7b19575e0c2bac

See more details on using hashes here.

File details

Details for the file chily-0.7.0rc1-py3-none-win32.whl.

File metadata

  • Download URL: chily-0.7.0rc1-py3-none-win32.whl
  • Upload date:
  • Size: 64.6 kB
  • Tags: Python 3, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/0.14.16

File hashes

Hashes for chily-0.7.0rc1-py3-none-win32.whl
Algorithm Hash digest
SHA256 8dee79b8c9df1eadc1e5fbf6d50ee5fb816562c965101e31fab24e603ec109b1
MD5 1053e4d4daa1e5f21218f85326075208
BLAKE2b-256 26d26085519e7f5c5d3d8ee4aae6e7d055f00ac28af3e498511c39061811d176

See more details on using hashes here.

File details

Details for the file chily-0.7.0rc1-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl.

File metadata

File hashes

Hashes for chily-0.7.0rc1-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 86c252b325060ed1bf455adab8205a8000fdd9d4e226d1c51025ceba3ca9926e
MD5 77683dfc4d5df0137f0558f1bbdc3dd3
BLAKE2b-256 c5fd8d8e1fad6100d8b965f55be0556035a2616a6cee04de230a41a662511658

See more details on using hashes here.

File details

Details for the file chily-0.7.0rc1-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl.

File metadata

File hashes

Hashes for chily-0.7.0rc1-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 b1f4721a336ddc545221e49fddba51ddbfa76587e8fddbb53c3390fbf8b65a94
MD5 864b41ce54877928c2659f5ca8d21c40
BLAKE2b-256 9d2ef1eb7a6b0dcccf9b2072d61ae3a4702c7b6fb336377f34e90fc3aa94e5ab

See more details on using hashes here.

File details

Details for the file chily-0.7.0rc1-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for chily-0.7.0rc1-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 35950ed3ffdbf39a2f43c7f17763fa34b7852eae0bbd18a28af6cfc12f194292
MD5 cbb5a14637e0d350d829f4110cb77ba7
BLAKE2b-256 6e783df8a480fc4ec8224ce51cb80f0adf753521f3a7ac681ceed3a88116cf38

See more details on using hashes here.

File details

Details for the file chily-0.7.0rc1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for chily-0.7.0rc1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 cd73c4269fc907d9de2baaddf2cd82bae67cb8ba342062408118294632f359e4
MD5 499234cfb029026e0c4e065e5b37ac52
BLAKE2b-256 08865d86660b78ec02cfd661a383e813e72d4fc8f432b3643f9fe5843120feaf

See more details on using hashes here.

File details

Details for the file chily-0.7.0rc1-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for chily-0.7.0rc1-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 7f0fc8a08db153e04204e3866137d6f6c904095f396b0764ff65e6082959f2a5
MD5 0b464c7bcbe047f2755421c08a8424f6
BLAKE2b-256 dd6c1edb8a5f94924bce86c7362d00232fbb2be899a607856d38d3fa90772c39

See more details on using hashes here.

File details

Details for the file chily-0.7.0rc1-py3-none-manylinux_2_5_i686.manylinux1_i686.whl.

File metadata

File hashes

Hashes for chily-0.7.0rc1-py3-none-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 8d649fd0c6fdef9ab81adaed4c582b2eee82994ec8d5bf8237c955e0eb482306
MD5 44d3e2da24f66084b7682e3f0d2e5832
BLAKE2b-256 79e3abeaa5df6ae34adbe008aa0a7383cad90c811c60b7b90f9a853e0fa343f6

See more details on using hashes here.

File details

Details for the file chily-0.7.0rc1-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for chily-0.7.0rc1-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 7b001ab7ebb2c90714b34a1e6be5282b0f2b1ef1401a9536aaa5fb2c2ba459aa
MD5 54d78b1d072ae2b5e7bdc470b7c991da
BLAKE2b-256 6c2f4460d616d2cfc2af94803bb8cef8dffa9f7d1d677b48b57fc3e61ebe0325

See more details on using hashes here.

File details

Details for the file chily-0.7.0rc1-py3-none-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for chily-0.7.0rc1-py3-none-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 6cf7e57b9a44343a8e44cb14c18b0972f2254c35b0cbe290bd85a350f8d30287
MD5 0885c8984a9f4c7c2b042fc36ab08d8b
BLAKE2b-256 63ecfcc16e2be6b5c33eeb3372b8dde9bbc76a1a2bfc87848134aaa3bd16db58

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