Skip to main content

KyberSecretKey

Struct KyberSecretKey 

Source
pub struct KyberSecretKey(/* private fields */);
Expand description

Kyber1024 secret key

Implementations§

Source§

impl KyberSecretKey

Source

pub fn from_bytes(bytes: &[u8]) -> Result<Self>

Create a secret key from raw bytes

Source

pub fn as_bytes(&self) -> &[u8] ⓘ

Get the raw secret key bytes

Examples found in repository?
examples/basic_usage.rs (line 66)
61fn kyber_example() -> Result<()> {
62    // Alice generates a key pair
63    let alice_keypair = KyberCrypto::generate_keypair();
64    
65    println!("  Alice's public key size: {} bytes", alice_keypair.public_key.as_bytes().len());
66    println!("  Alice's secret key size: {} bytes", alice_keypair.secret_key.as_bytes().len());
67    
68    // Bob encapsulates a shared secret for Alice
69    let (bob_shared_secret, ciphertext) = KyberCrypto::encapsulate(&alice_keypair.public_key);
70    
71    println!("  Encapsulated ciphertext size: {} bytes", ciphertext.as_bytes().len());
72    println!("  Bob's shared secret: {} bytes", bob_shared_secret.as_bytes().len());
73    
74    // Alice decapsulates the shared secret
75    let alice_shared_secret = KyberCrypto::decapsulate(&ciphertext, &alice_keypair.secret_key);
76    
77    println!("  Alice's shared secret: {} bytes", alice_shared_secret.as_bytes().len());
78    
79    // Verify they match
80    assert_eq!(bob_shared_secret.as_bytes(), alice_shared_secret.as_bytes());
81    println!("  ✓ Key encapsulation successful!");
82    
83    // Display key sizes
84    let sizes = KyberCrypto::sizes();
85    println!("  Component sizes:");
86    println!("    - Public key: {} bytes", sizes.public_key);
87    println!("    - Secret key: {} bytes", sizes.secret_key);
88    println!("    - Ciphertext: {} bytes", sizes.ciphertext);
89    println!("    - Shared secret: {} bytes", sizes.shared_secret);
90    
91    Ok(())
92}
Source

pub fn size() -> usize

Get the size of a secret key in bytes

Trait Implementations§

Source§

impl Drop for KyberSecretKey

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.