[−][src]Crate saber
This crate implements the Saber post-quantum key-encapsulation mechanism.
Saber is a post-quantum cryptographic key-encapsulation mechanism. It has been devised by:
- Jan-Pieter D'Anvers, KU Leuven, imec-COSIC
- Angshuman Karmakar, KU Leuven, imec-COSIC
- Sujoy Sinha Roy, KU Leuven, imec-COSIC
- Frederik Vercauteren, KU Leuven, imec-COSIC
Like many others, it is one of the round-2 candidates of the NIST Post-Quantum Cryptography "competition".
Getting started
Install this crate using Cargo by adding it to your dependencies:
[dependencies]
saber = { git = "https://github.com/dsprenkels/saber-rust" }
Then, choose one of the parameter sets by importing them into your code:
extern crate saber; use saber::saber::{keygen, encapsulate, decapsulate};
Now you can use the functions keygen
, encapsulate
and decapsulate
to agree on a shared
secret key between two endpoints.
// Consider a server with a key pair let server_secret_key = keygen(); let server_public_key = server_secret_key.public_key(); // Let a client encapsulate some shared secret for the server let (client_secret, ciphertext) = encapsulate(&server_public_key); // Have the server decrypt the ciphertext let server_secret = decapsulate(&ciphertext, &server_secret_key); assert_eq!(client_secret.as_slice(), server_secret.as_slice());
(De)serializing keys
Both PublicKey
and SecretKey
can be stored into arrays using PublicKey::to_bytes
and
SecretKey::to_bytes
respectively. To load a key back from a &[u8]
buffer, use
PublicKey::from_bytes
and SecretKey::from_bytes
. For example:
let public_key = secret_key.public_key(); use saber::saber::{PublicKey, encapsulate}; // Store the public key let public_key_bytes = public_key.to_bytes().into_bytes(); println!("Saber public key: {:02x?}", &public_key_bytes[..]); // Lose the original public-key struct drop(public_key); // Reload the public key let public_key = match PublicKey::from_bytes(&public_key_bytes) { Ok(pk) => pk, Err(err) => panic!("Error decoding public key: {}", err), }; // Now you can use the key again for key encapsulation let (client_secret, ciphertext) = encapsulate(&public_key);
Modules
firesaber | Saber key encapsulation using paranoid parameters. |
lightsaber | Saber key encapsulation using lightweight parameters. |
saber | Regular saber key encapsulation mechanism. |
Enums
Error | Error type for the saber crate. |