Skip to content

veritas-shine/ntru.js

 
 

Repository files navigation

ntru.js

Overview

The NTRU post-quantum asymmetric cipher compiled to WebAssembly using Emscripten. A simple JavaScript wrapper is provided to make NTRU easy to use in web applications.

The default parameter set is EES743EP1 (roughly 256-bit strength, as per NTRU's documentation). To change this, modify line 13 of Makefile and rebuild with make.

Example Usage

(async () => {
	const keyPair /*: {privateKey: Uint8Array; publicKey: Uint8Array} */ =
		await ntru.keyPair()
	;

	const plaintext /*: Uint8Array */ =
		new Uint8Array([104, 101, 108, 108, 111, 0]) // "hello"
	;

	const encrypted /*: Uint8Array */ =
		await ntru.encrypt(plaintext, keyPair.publicKey)
	;

	const decrypted /*: Uint8Array */ =
		await ntru.decrypt(encrypted, keyPair.privateKey) // same as plaintext
	;

	console.log(keyPair);
	console.log(plaintext);
	console.log(encrypted);
	console.log(decrypted);
})();

Note: NTRU is a low-level cryptographic primitive, not a high-level construct like libsodium's crypto_box. This module can be combined with a symmetric cipher and a MAC to provide such a construct, but you should avoid using ntru.js directly for anything important if you lack the experience to do so.

Changelog

Breaking changes in major versions:

3.0.0:

  • As part of upgrading from asm.js to WebAssembly (with asm.js included as a fallback), the API is fully asynchronous.

2.0.0:

  • Removed some undocumented functions as part of minor API cleanup.

About

JavaScript wrapper for a WebAssembly build of NTRU.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 40.3%
  • C 33.6%
  • Makefile 26.1%