Package: chily
🌶 CryptoLib: chilyAuthenticated EncryptionThe plan forchilyis to have pure Rust implementation for the following crypto protocols (following RFC 7539):Key exchange: X25519Encryption: XSalsa20 stream cipherAuthentication: Poly1305 MACIn contrast to RFC 7530 we use XChaCha20 instead of ChaCha in order to have a 24 byte nonce (instead of  96bits).RandomnessWe 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:getrandomsystem call if available, otherwise/dev/urandomSGX:  Based onrdrandinstructions of the CPU (https://docs.rs/rdrand/0.6.0/rdrand/)WASM:Crypto.getRandomValuesexposed by the JS engine viawasm-bindgenbridge🚴 UsageRustJust addchilyas a dependency and see how it's being used in the following example:// generate random keypairletalice=Keypair::generate();// or parse a secret from existing bytesletbob_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 keypairletbob=Keypair::from_secret_key(bob_secret.into());// define some bufferletplaintext=b"avato rocks";letmutbuffer=plaintext.to_vec();// create a random Nonceletnonce=Nonce::from_random();// instantiate the cipherletmutcipher=Cipher::new(&alice.secret,&bob.public);// encrypt in placelettag=cipher.encrypt_in_place_detached(&mutbuffer,b"",&nonce);// decrypt in placecipher.decrypt_in_place_detached(&mutbuffer,b"",&nonce,&tag);assert_eq!(plaintext.to_vec(),buffer);// Ok!JavaScript / TypeScriptAdd the package from folderjs/pkgas dependency to thepackage.jsonin your project:"dependencies": {
    "chily": "file:chily-0.2.0.tgz"
  }Then the library can be used as shown below:import*aschilyfrom"chily";// generate random keypairletalice=chily.Keypair.fromRandom();// or parse a secret from existing bytesletbob_secret=chily.StaticSecret.fromBytes(newUint8Array([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 keypairletbob=chily.Keypair.fromSecret(bob_secret);// create a random Nonceletnonce=chily.Nonce.fromRandom();// instantiate the cipherletcipher=chily.Cipher.new(alice.secret,bob.publicKey);// define some buffervarplaintext=newUint8Array([21,31]);// encryptletencrypted=cipher.encrypt(plaintext,nonce);// decryptletdecrypted=cipher.decrypt(encrypted,nonce);expect(plaintext).to.eql(decrypted);// Ok!PythonInstall the wheel from folderpy/pkgby runningpip3 install chily.whlThen the library can be used as shown below:importchily# generate random keypairalice=chily.Keypair.from_random();# or parse a secret from existing bytesbob_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 keypairbob=chily.Keypair.from_secret(bob_secret)# create a random Noncenonce=chily.Nonce.from_random();# instantiate the ciphercipher=chily.Cipher(alice.secret,bob.publicKey,nonce)# define some bufferplaintext=[21,31]# encryptenc=cipher.encrypt(plaintext,nonce)# decryptdec=cipher.decrypt(enc,nonce)assertplaintext==dec🛠️ TestWe have four different test stages.RustRegular tests written in Rust. Just callcargo test.WASMSome 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 thejsfolder:npmrunwasm-testJavaScript / TypeScriptThere also are some tests for the JavaScript bindings usingmochaandchai.They are defined in the folderjs/testsand can be run  using the following command:npmruntestPythonThere also are some tests for the Python bindings usingtox.They are defined in the folderpy/testsand can be run  using the following command:tox🎁 Build & PackageJavaScript / TypeScriptTo build the wasm code and the js/ts binding run in thejsfolder:npm run build-nodefor nodejsnpm run build-bundlerfor browser / webpacknpm run buildfor one compatible with bothThen package the dependency by runningnpm packin the correspondingpkgdir.PythonTo build the python bindings you'll needmaturin. Run in thepyfolder:pip3 install maturinto install maturin./build.shto build the wheel for the current platform in the pkg folder🔋 ToDosAdd X.509 cert supportError handlingAdd Poly1305 MAC