pub struct KyberPublicKey(/* private fields */);Expand description
Kyber1024 public key
Implementations§
Source§impl KyberPublicKey
impl KyberPublicKey
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self>
pub fn from_bytes(bytes: &[u8]) -> Result<Self>
Create a public key from raw bytes
Sourcepub fn as_bytes(&self) -> &[u8] ⓘ
pub fn as_bytes(&self) -> &[u8] ⓘ
Get the raw public key bytes
Examples found in repository?
examples/basic_usage.rs (line 65)
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}Trait Implementations§
Auto Trait Implementations§
impl Freeze for KyberPublicKey
impl RefUnwindSafe for KyberPublicKey
impl Send for KyberPublicKey
impl Sync for KyberPublicKey
impl Unpin for KyberPublicKey
impl UnsafeUnpin for KyberPublicKey
impl UnwindSafe for KyberPublicKey
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