post_quantum 1.0.0-prerelease.3 copy "post_quantum: ^1.0.0-prerelease.3" to clipboard
post_quantum: ^1.0.0-prerelease.3 copied to clipboard

unlisted

Dart implementation of the Kyber and Dilithium algorithms.

post_quantum #

plugin version likes pub points popularity Coverage Status

Dart implementation of NIST's post-quantum algorithm candidates.

Features #

This library includes the following algorithms:

  • Kyber, a post-quantum Key Encapsulation Mechanism.
  • Dilithium, a post quantum Signature scheme.

Usage #

Key Encapsulation with Kyber #

// Instantiate Kyber KEM.
var kyber = Kyber.kem512();

// Define a key generation seed.
var seed = base64Decode("AAECAwQFBgcICQoLDA0ODwABAgMEBQYHCAkKCwwNDg8AAQIDBAUGBwgJCgsMDQ4PAAECAwQFBgcICQoLDA0ODw==");

// Generate keys from seed.
var (pk, sk) = kyber.generateKeys(seed);

// Define a KEM nonce.
var nonce = base64Decode("Dw8ODg0NDAwLCwoKCQkICAcHBgYFBQQEAwMCAgEBAAA=");

// Encapsulate nonce and retrieve cipher and shared key.
var (cipher, sharedKey1) = kyber.encapsulate(pk, nonce);

// Or decapsulate the cipher and retrieve the shared key.
var sharedKey2 = kyber.decapsulate(cipher, sk);

Encryption and decryption with the internal Kyber PKE #

// Instantiate Kyber's internal PKE.
var kyber = KyberPKE.pke512();

// Define a key generation seed.
var seed = base64Decode("AAECAwQFBgcICQoLDA0ODwABAgMEBQYHCAkKCwwNDg8=");

// Generate keys from seed.
var (pk, sk) = kyber.generateKeys(seed);

// Set the message.
var msg = base64Decode("Dw4NDAsKCQgHBgUEAwIBAA8ODQwLCgkIBwYFBAMCAQA=");

// Define an encryption randomizer.
var coins = base64Decode("Dw8ODg0NDAwLCwoKCQkICAcHBgYFBQQEAwMCAgEBAAA=");

// Encrypt the message with the public key.
var cipher = kyber.encrypt(pk, msg, coins);

// Decrypt the cipher with the private key.
var decryptedMsg = kyber.decrypt(sk, cipher);

Signing and validating with Dilithium #

// Instantiate Dilithium.
var dilithium = Dilithium.level2();

// Define a key generation seed.
var seed = base64Decode("AAECAwQFBgcICQoLDA0ODwABAgMEBQYHCAkKCwwNDg8=");

// Generate keys from seed.
var (pk, sk) = dilithium.generateKeys(seed);

// Set the message.
var msg = base64Decode("Dw4NDAsKCQgHBgUEAwIBAA8ODQwLCgkIBwYFBAMCAQA=");

// Sign the message with the private key.
var signature = dilithium.sign(sk, msg);

// Verify the signature with the public key.
var isValid = dilithium.verify(pk, msg, signature);

Disclaimer #

This library has not been reviewed by security specialists, and therefore should not be treated as cryptographically secure.

Acknowledgements #

This implementation is based on the python implementation written by Giacomo Pope. Please go and check and support all of his projects.

1
likes
0
pub points
2%
popularity

Publisher

unverified uploader

Dart implementation of the Kyber and Dilithium algorithms.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

hashlib

More

Packages that depend on post_quantum