diff --git a/readme.md b/readme.md index 5230e4e..8e97ec5 100644 --- a/readme.md +++ b/readme.md @@ -8,7 +8,6 @@ # Kyber [![Build Status](https://github.com/Argyle-Software/kyber/actions/workflows/kat.yml/badge.svg)](https://github.com/bwesterb/argyle-kyber/actions) [![Crates](https://img.shields.io/crates/v/safe_pqc_kyber)](https://crates.io/crates/safe_pqc_kyber) -[![NPM](https://img.shields.io/npm/v/pqc-kyber?color=yellow)](https://www.npmjs.com/package/safe_pqc_kyber) [![License](https://img.shields.io/crates/l/safe_pqc_kyber)](https://github.com/Argyle-Software/kyber/blob/master/LICENSE-MIT) [![dependency status](https://deps.rs/crate/safe_pqc_kyber/0.6.2/status.svg)](https://deps.rs/crate/safe_pqc_kyber/0.6.2) @@ -177,45 +176,6 @@ The fuzzing suite uses honggfuzz, installation and instructions are on the [fuzz --- -## WebAssembly - -This library has been compiled into web assembly and published as a npm package. Usage instructions are here: - -https://www.npmjs.com/package/pqc-kyber - -Which is also located here in the [wasm readme](./pkg/readme.md) - -To install: - -```shell -npm i pqc-kyber -``` - -To compile the wasm files yourself you need to enable the `wasm` feature. - -For example, using [wasm-pack](https://rustwasm.github.io/wasm-pack/installer/): - -```shell -wasm-pack build -- --features wasm -``` - -Which will export the wasm, javascript and typescript files into [./pkg/](./pkg/readme.md). - -To compile a different variant into a separate folder: -```shell -wasm-pack build --out-dir pkg_kyber512/ -- --features "wasm kyber512" -``` - -There is also a basic html demo in the [www](./www/readme.md) folder. - -From the www folder run: - -```shell -npm run start -``` - ---- - ## Security Considerations While much care has been taken porting from the C reference codebase, this library has not undergone any third-party security auditing nor can any guarantees be made about the potential for underlying vulnerabilities in LWE cryptography or potential side-channel attacks arising from this implementation. diff --git a/www/bootstrap.js b/www/bootstrap.js deleted file mode 100644 index 7934d62..0000000 --- a/www/bootstrap.js +++ /dev/null @@ -1,5 +0,0 @@ -// A dependency graph that contains any wasm must all be imported -// asynchronously. This `bootstrap.js` file does the single async import, so -// that no one else needs to worry about it again. -import("./index.js") - .catch(e => console.error("Error importing `index.js`:", e)); diff --git a/www/index.html b/www/index.html deleted file mode 100755 index f9aedca..0000000 --- a/www/index.html +++ /dev/null @@ -1,53 +0,0 @@ - - - - - Kyber Web Assembly Demo - - - - -

safe_pqc_kyber wasm demo

- import * as kyber from safe_pqc_kyber -

- kyber.Params.publicKeyBytes:
- kyber.Params.secretKeyBytes:
- kyber.Params.ciphertextBytes:
- kyber.Params.sharedSecretBytes: -

- - var keys = kyber.keypair();
- const publicKeyAlice = keys.pubkey;
- const privateKeyAlice = keys.secret;
-
-

-
-

Public Key (Output):

-
Private Key (Output):
-

- - var enc = kyber.encapsulate(publicKeyAlice);
- var ciphertextBob = enc.ciphertext;
- var sharedSecretBob = enc.sharedSecret;
-
-

-
-

Public Key (Input):

-
Ciphertext (Output):

-
Shared Key (Output):
-

- - var dec = kyber.decapsulate(ciphertextBob, privateKeyAlice);
- var sharedSecretAlice = dec.sharedSecret;
- assert.equal(sharedSecretAlice, sharedSecretBob);
-
-

- - -
-

Private Key (Input):

-
Ciphertext (Input):

-
Shared Key (Output):
-

- - diff --git a/www/index.js b/www/index.js deleted file mode 100755 index cb4e94e..0000000 --- a/www/index.js +++ /dev/null @@ -1,104 +0,0 @@ -import * as kyber from "safe_pqc_kyber"; - -const generateKeyButton = document.getElementById("generatekey"); -const encapButton = document.getElementById("encapsulate"); -const decapButton = document.getElementById("decapsulate"); -const movebutton = document.getElementById("movebelow"); -const movebutton2 = document.getElementById("movebelow2"); -const clearButton = document.getElementById("clear"); -const checkButton = document.getElementById("check"); - -const pubKeyBox = document.getElementById("pubkeybox"); -const pubKeyBox2 = document.getElementById("pubkeybox2"); -const privKeyBox = document.getElementById("privkeybox"); -const privKeyBox2 = document.getElementById("privkeybox2"); -const cipherTextBox = document.getElementById("ciphertext"); -const cipherTextBox2 = document.getElementById("ciphertext2"); -const sharedKeyBox = document.getElementById("sharedkey"); -const sharedKeyBox2 = document.getElementById("sharedkey2"); - -document.getElementById('pkbytes').innerHTML = kyber.Params.publicKeyBytes; -document.getElementById('skbytes').innerHTML = kyber.Params.secretKeyBytes; -document.getElementById('ctbytes').innerHTML = kyber.Params.ciphertextBytes; -document.getElementById('ssbytes').innerHTML = kyber.Params.sharedSecretBytes; - -clearButton.addEventListener("click", event => { - var elements = document.getElementsByTagName("input"); - for (var i=0; i < elements.length; i++) { - elements[i].value = ""; - } -}); - -generateKeyButton.addEventListener("click", event => { - let keys = kyber.keypair(); - const pubKey = keys.pubkey; - const privKey = keys.secret; - - pubKeyBox.value = toHexString(pubKey); - privKeyBox.value = toHexString(privKey); - - pubKeyBox2.value = pubKeyBox.value; - privKeyBox2.value = privKeyBox.value; - // TODO: Add a base64 option - // pubKeyBox.value = Buffer.from(pubKey).toString('base64'); -}); - -encapButton.addEventListener("click", event => { - try { - let encapsulated = kyber.encapsulate(hexToBytes(pubKeyBox2.value)); - cipherTextBox.value = toHexString(encapsulated.ciphertext); - sharedKeyBox.value = toHexString(encapsulated.sharedSecret); - cipherTextBox2.value = cipherTextBox.value; - } - catch(err) { - alert("Error Encapsulating"); - } -}); - -decapButton.addEventListener("click", event => { - try { - let decapsulated = kyber.decapsulate( - hexToBytes(cipherTextBox2.value), - hexToBytes(privKeyBox2.value) - ); - sharedKeyBox2.value = toHexString(decapsulated); - } - catch(err) { - alert("Error Decapsulating"); - } -}); - -// movebutton.addEventListener("click", event => { -// pubKeyBox2.value = pubKeyBox.value; -// privKeyBox2.value = privKeyBox.value; -// }); - -// movebutton2.addEventListener("click", event => { -// cipherTextBox2.value = cipherTextBox.value; -// }); - -checkButton.addEventListener("click", event => { - if (sharedKeyBox.value === sharedKeyBox2.value){ - alert("Shared Keys Match"); - } - else { - alert("Failed - Shared Keys Don't Match"); - }; -}); - -function toHexString(bytes) { - for (var hex = [], i = 0; i < bytes.length; i++) { - var current = bytes[i] < 0 ? bytes[i] + 256 : bytes[i]; - hex.push((current >>> 4).toString(16)); - hex.push((current & 0xF).toString(16)); - } - return hex.join(""); -} - -function hexToBytes(hex) { - for (var bytes = [], c = 0; c < hex.length; c += 2) - bytes.push(parseInt(hex.substr(c, 2), 16)); - return bytes; -} - - diff --git a/www/package.json b/www/package.json deleted file mode 100644 index 8bed8e8..0000000 --- a/www/package.json +++ /dev/null @@ -1,39 +0,0 @@ -{ - "name": "safe_pqc_kyber_demo", - "version": "0.1.0", - "description": "Basic example demonstrator of using the safe_pqc_kyber wasm module", - "main": "index.js", - "bin": { - "create-wasm-app": ".bin/create-wasm-app.js" - }, - "scripts": { - "build": "webpack --config webpack.config.js", - "start": "webpack-dev-server" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/rustwasm/create-wasm-app.git" - }, - "keywords": [ - "webassembly", - "wasm", - "rust", - "webpack" - ], - "author": "Mitchell Berry ", - "license": "(MIT OR Apache-2.0)", - "bugs": { - "url": "https://github.com/rustwasm/create-wasm-app/issues" - }, - "homepage": "https://github.com/rustwasm/create-wasm-app#readme", - "dependencies": { - "safe_pqc_kyber": "file:../pkg" - }, - "devDependencies": { - "hello-wasm-pack": "^0.1.0", - "webpack": "^4.29.3", - "webpack-cli": "^3.1.0", - "webpack-dev-server": "^3.1.5", - "copy-webpack-plugin": "^5.0.0" - } -} diff --git a/www/readme.md b/www/readme.md deleted file mode 100644 index 1035216..0000000 --- a/www/readme.md +++ /dev/null @@ -1,79 +0,0 @@ -
- -

Web Assembly Demo

- - A basic example of using the safe_pqc_kyber npm module - - - -
- - -### Installation - -From this folder: - -```shell -npm install -``` - -### Run -``` -npm run start -``` - -The demo is at [localhost:8080](localhost:8080) - - -### Library Usage - -```js -import * as kyber from "safe_pqc_kyber"; - -// Generate Keypair -let keys = kyber.keypair(); -const publicKeyAlice = keys.pubkey; -const privateKeyAlice = keys.secret; - -// Encapsulate secret -try { - let encapsulated = kyber.encapsulate(publicKeyAlice); - var ciphertextBob = encapsulated.ciphertext; - var sharedSecretBob = encapsulated.sharedSecret; -} -catch(err) { - alert("Error Encapsulating"); -} - -// Decapsulate secret -try { - let decapsulated = kyber.decapsulate(ciphertextBob, privateKeyAlice); - var sharedSecretAlice = decapsulated.sharedSecret -} -catch(err) { - alert("Error Decapsulating"); -} - -var assert = require('assert'); - -assert.equal(sharedSecretAlice, sharedSecretBob) - -// Valid input lengths are found in the `Params` class -assert.equal(publicKeyAlice.len(), kyber.Params.publicKeyBytes); -assert.equal(secretKeyAlice.len(), kyber.Params.secretKeyBytes); -assert.equal(ciphertextBob.len(), kyber.Params.ciphertextbytes); - -``` - - -# Errors -If the ciphertext cannot be decapsulated with the private key or the functions are -given incorrectly sized byte arrays an error will be raised - - - - - - - - diff --git a/www/style.css b/www/style.css deleted file mode 100644 index 77b5eba..0000000 --- a/www/style.css +++ /dev/null @@ -1,28 +0,0 @@ -body { - margin: auto; - width: 500px; - padding: 20px; - background-color: lightblue; - -} - -h1 { - text-align: center; -} - -input { - width: 70%; - margin-left: auto -} - -.box { - font-family: 'Times New Roman', serif; - display: flex; - flex-direction: row; - justify-content: center; -} - -code { - font-family: 'Courier New', monospace; - font-size: small; -} diff --git a/www/webpack.config.js b/www/webpack.config.js deleted file mode 100644 index 80ad814..0000000 --- a/www/webpack.config.js +++ /dev/null @@ -1,14 +0,0 @@ -const CopyWebpackPlugin = require("copy-webpack-plugin"); -const path = require('path'); - -module.exports = { - entry: "./bootstrap.js", - output: { - path: path.resolve(__dirname, "dist"), - filename: "bootstrap.js", - }, - mode: "development", - plugins: [ - new CopyWebpackPlugin(['index.html']) - ], -};