Skip to content

Latest commit

 

History

History
79 lines (48 loc) · 1.38 KB

readme.md

File metadata and controls

79 lines (48 loc) · 1.38 KB

Web Assembly Demo

A basic example of using the pqc_kyber npm module

Installation

From this folder:

npm install

Run

npm run start

The demo is at localhost:8080

Library Usage

import * as kyber from "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