pub struct Keypair {
pub public: PublicKey,
pub secret: SecretKey,
}
Expand description
A public/secret keypair for use with Kyber.
Byte lengths of the keys are determined by the security level chosen.
Fields§
§public: PublicKey
The public key.
secret: SecretKey
The secret key.
Implementations§
Source§impl Keypair
impl Keypair
Sourcepub fn generate<R: CryptoRng + RngCore>(
rng: &mut R,
) -> Result<Keypair, KyberLibError>
pub fn generate<R: CryptoRng + RngCore>( rng: &mut R, ) -> Result<Keypair, KyberLibError>
Securely generates a new keypair.
This function generates a new Kyber key pair and returns it as a Keypair
struct.
§Arguments
rng
- The random number generator implementing theRngCore
andCryptoRng
traits.
§Example
let mut rng = rand::thread_rng();
let keys = Keypair::generate(&mut rng)?;
public: [0u8; KYBER_PUBLIC_KEY_BYTES], secret: [0u8; KYBER_SECRET_KEY_BYTES]
};
Sourcepub fn expose_secret(&self) -> &SecretKey
pub fn expose_secret(&self) -> &SecretKey
Explicitly exposes the secret key
use kyberlib::*;
let mut rng = rand::thread_rng();
let keys = Keypair::generate(&mut rng);
let binding = keys.expect("Exposed secret key");
let secret = binding.expose_secret();
assert!(secret.len() == KYBER_SECRET_KEY_BYTES);
assert!(secret.len() != 0);
Sourcepub fn import<R: CryptoRng + RngCore>(
public: &mut [u8; 1184],
secret: &mut [u8; 2400],
rng: &mut R,
) -> Result<Keypair, KyberLibError>
pub fn import<R: CryptoRng + RngCore>( public: &mut [u8; 1184], secret: &mut [u8; 2400], rng: &mut R, ) -> Result<Keypair, KyberLibError>
Imports a keypair from existing public and secret key arrays.
This function imports a keypair from existing public and secret key arrays and returns it as a Keypair
struct.
§Arguments
public
- A mutable reference to a[u8; KYBER_PUBLIC_KEY_BYTES]
array representing the public key.secret
- A mutable reference to a[u8; KYBER_SECRET_KEY_BYTES]
array representing the secret key.rng
- The random number generator implementing theRngCore
andCryptoRng
traits.
§Example
let mut rng = rand::thread_rng();
let keys = keypair(&mut rng)?;
let mut public_key = keys.public;
let mut secret_key = keys.secret;
let keys = Keypair::import(&mut public_key, &mut secret_key, &mut rng)?;
let _ = Keypair::import(&mut public_key, &mut secret_key, &mut rng)?;
Trait Implementations§
impl Copy for Keypair
impl Eq for Keypair
impl StructuralPartialEq for Keypair
Auto Trait Implementations§
impl Freeze for Keypair
impl RefUnwindSafe for Keypair
impl Send for Keypair
impl Sync for Keypair
impl Unpin for Keypair
impl UnwindSafe for Keypair
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more