JS bindings and playground of post-quantum asymmetric ciphers

Overview

pqc.js

Overview

This project provides JS bindings and playground of post-quantum asymmetric cipher compiled to WebAssembly using emscripten with a fallback in plain JS.

The available methods are the finalists (and alternate candidates) of NIST Post-Quantum Cryptography Competition:

The C implementations used to create the bindings are the clean versions provided by PQClean.

This project has been inspired by ntru.js that used to provide an NTRU JS binding.

Playground

It is possible to test the bindings, to compare them in real-world conditions on this playground.

How to download pre-built bindings and NPM packages

Pre-built bindings are available on the playground.

How to build

  • sudo apt install emscripten
  • npm ci
  • make clean
  • make kem-<the KEM algorithm you want to build> or make sign-<the signature algorithm you want to build>
  • All bindings can be built using make all

The output directory is docs/bin/ and each output binding is made of a JS module and its associated WebAssembly file, a browser package, and a node package.

How to use

Key Encapsulation

import kemBuilder from 'pqc-kem-<algoName>.js'

async function run() {
    const kem = await kemBuilder();
    
    const { publicKey, privateKey } = await kem.keypair();
    const { ciphertext, sharedSecret: sharedSecretA } = await kem.encapsulate(publicKey);
    const { sharedSecret: sharedSecretB } = await kem.decapsulate(ciphertext, privateKey);
    // sharedSecretA === sharedSecretB
}

run();

Signature

import signBuilder from 'pqc-sign-<algoName>.js'

async function run() {
    const sign = await signBuilder();
    
    const message = new Uint8Array([0x44, 0x61, 0x73, 0x68, 0x6c, 0x61, 0x6e, 0x65]);
    
    const { publicKey, privateKey } = await sign.keypair();
    const { signature } = await sign.sign(message, privateKey);
    const validSignature = await sign.verify(signature, message, publicKey);
    // validSignature === true
}

run();

Disable WebAssembly execution

The first optional parameter of the builders is set to true is you want to disable WebAssembly execution.

If it is set to false, the fallback JavaScript may still be used if the WebAssembly fails.

Change the path of the WebAssembly

The second optional parameter of the builders is the path to the WebAssembly file.

Implementation notes

  • Random generation is provided by libsodium that is using crypto.randomBytes.
  • SHA-2 and AES implementations are provided by SubtleCrypto that is an implementation of Web Crypto API. This may slow down the execution of the bindings because of the asynchronous calls to SubtleCrypto, even more when AES-ECB is used because in this case AES-CTR is called for each block.
  • SHA-2 PQClean implementation is still used by sphincs-sha256-* bindings because they are using incremental version of sha256 that do not exist in Web Crypto API.
  • SHA-3 PQClean implementation is still used by NTRU, Kyber, SABER, FrodoKEM and McEliece-Classic because there are no implementations in Web Crypto API.
You might also like...

Playground for studying design patterns, solid principles, GoF, testing and more with TypeScript

TypeScript design patterns study Playground for studying design patterns, solid principles, GoF, testing and more with TypeScript Index TypeScript des

Dec 9, 2022

⚡ Extremely fast online playground for every programming language.

Riju Riju is a very fast online playground for every programming language. In less than a second, you can start playing with a Python interpreter or c

Dec 28, 2022

A simple code playground

CodeeBox A simple code playground 😏 Features: Instant change preview Saving without accounts or databases, everything's on the URL (Encoded) Resizabl

Nov 17, 2022

TypeScript playground plugin to save on format

TypeScript Playground Plugin TypeScript Playground plugin to save on format Running this plugin Click this link to install or Open up the TypeScript P

Apr 11, 2022

An ergonomic, mobile-first, Prolog playground!

An ergonomic, mobile-first, Prolog playground!

Paízo Programmer Pronounced "Pay-zo Programmer". https://lf94.github.io/paizo-programmer/ Paizo is a playground for programmers. It's intended to be u

Aug 13, 2022

A (very) minimalist creative coding playground. Make animations using only 64 HTML sliders!

Sliderland A (very) minimalist creative coding playground. Make animations using only 64 HTML sliders! Credits The recording feature uses ffmpeg.wasm

Dec 30, 2022

A Next.js playground to test Reanimated bundle size.

React Native Reanimated Tree Shaking Playground Here we can test react-native-reanimated's bundle size. 🎙 Discussion here 🗺 Progress here Instructio

Jun 16, 2022

A playground project for JavaScript.

A playground project for JavaScript.

Awesome books Screenshot Built With HTML CSS JS Live Demo Awesome books Getting Started To get a local copy up and running: Clone this repository or d

Aug 25, 2022

js move playground by imcoding.online

JS MOVE PLAYGROUND Wrapper move playground by pontem. Only support Browser environment. Demo imcoding.online Install npm i @imcoding.online/js-move-pl

Dec 3, 2022
Owner
Dashlane
We believe in a radically easier internet, and we’ll help you get there.
Dashlane
Dominating set solver using quantum algorithm Grover

Solution for dominating set problem using improved quantum algorithm Grover, which uses Schoning algorithm for k-SAT problem to accomplish this improvement

Fatemehe Lajevardi 8 Aug 31, 2022
This is an example of Quantum physics congress.

This is an example of Quantum physics congress. This is an imaginary congress in which are shown 2 pages with information about the congress, about activities which will be held there and speakers who will speak about the topic

Sanja Mandic 7 Jun 24, 2022
Move all the disks from the left hand post to the right hand post, only moving the disks one at a time and a bigger disk can never be placed on a smaller disk.

Hanoi Tower Description The Tower of Hanoi was a famous problem posed by a mathematician in 1883, The "puzzle" is to move all the disks from the left

Dustin J Sellers 1 Feb 5, 2022
Create your own wrappings with optional key bindings for selected text, a set of useful defaults is also provided.

Create your own wrappings with optional key bindings for selected text, a set of useful defaults is also provided.

Seth Yuan 66 Jan 1, 2023
Melon.js game engine bindings for Solid

Melon Solid This project fuses the awesome frameworks Melon.js (for game development) and Solid.js (for making websites). By combining them together y

null 10 Oct 4, 2022
Deno bindings for yoga, using Deno FFI.

deno_yoga Deno bindings for yoga, using Deno FFI. Usage flags: --allow-ffi: Requires ffi access to "yogacore.dll", "libyogacore.so", "libyogacore.dyli

迷渡 6 Feb 11, 2022
🦆 lightning fast duckdb bindings for bun runtime

@evan/duckdb lightning fast duckdb bindings for bun runtime Install bun add @evan/duckdb Features ?? batteries included ?? jit optimized bindings ?? 4

evan 29 Oct 20, 2022
Code Playground is a online application for testing and showcasing user-created and collaborational HTML, CSS and JavaScript code snippets

Code Playground About Code Playground is a online application for testing and showcasing user-created and collaborational HTML, CSS and JavaScript cod

Arshansh Agarwal 5 Dec 17, 2022
A simple playground to create and test your Katas in Typescript.

Kata Playground TS A simple playground to create and test your Katas in Typescript. A code kata is an exercise in programming which helps programmers

Willian Justen 23 Jan 20, 2022
Rollup + React + Babel + Prettier + Strict ESlint and Stylelint + Sass + VSCode + Playground app - Enterprise grade boilerplate

React package boilerplate by HackingBay Rollup + React 17 + Babel + Prettier + Strict ESlint and Stylelint + Sass + VSCode + Playground app - Enterpri

HackingBay 2 Jan 19, 2022