pub struct SignerPair { /* private fields */ }Expand description
A complete key pair used for both signing and verification
This struct represents a post-quantum cryptography key pair used for creating digital signatures and verifying them. It contains both public and secret key components using the Falcon-padded-1024 algorithm.
Implementations§
Source§impl SignerPair
impl SignerPair
Sourcepub fn create() -> Self
pub fn create() -> Self
Examples found in repository?
examples/full_exchange.rs (line 8)
6fn main() {
7 let alice_kem = KEMPair::create();
8 let alice_signer = SignerPair::create();
9
10 let bob_kem = KEMPair::create();
11 let bob_signer = SignerPair::create();
12
13 // Create a base nonce with a new session id, and a counter of
14 let base_nonce = create_nonce(&gen_session_id(), 0);
15
16 // Lets create the message session for Alice first
17 let (mut alice_session, ciphertext) = MessageSession::new_initiator(
18 alice_kem,
19 alice_signer.clone(),
20 base_nonce,
21 &bob_kem.to_bytes().unwrap().0, // Bob's public KEM key
22 &bob_signer.to_bytes().unwrap().0, // Bob's public signer key
23 )
24 .unwrap();
25
26 // Now for Bob it would look like this
27 let mut bob_session = MessageSession::new_responder(
28 bob_kem,
29 bob_signer.clone(),
30 base_nonce,
31 &ciphertext,
32 &alice_signer.to_bytes().unwrap().0, // Alice's public signer key
33 )
34 .unwrap();
35
36 // Now both sessions contain a shared secret they use to encrypt and decrypt messages
37 // and a nonce that is incremented with each message sent or received.
38
39 // Alice creates a mesasge and prepares to send it to Bob
40 let message = b"Hello, Bob! This is a secret message.";
41 let encrypted_message = alice_session.craft_message(message).unwrap();
42
43 // Bob decrypts and verifies Alice's message
44 let raw_message = bob_session.validate_message(&encrypted_message).unwrap();
45
46 // Both message and raw_message are equal, let's print them out to illustrate
47 let message_str = String::from_utf8_lossy(message);
48 let raw_message_str = String::from_utf8_lossy(&raw_message);
49
50 println!("[1] Alice's message: {}", message_str);
51 println!("[2] Bob's decrypted message: {}", raw_message_str);
52
53 // Bob crafts a reply message to Alice
54 let reply = b"Hello, Alice! I received your message safely.";
55 let encrypted_reply = bob_session.craft_message(reply).unwrap();
56
57 // Alice decrypts and verifies Bob's reply
58 let raw_reply = alice_session.validate_message(&encrypted_reply).unwrap();
59
60 // Both reply and raw_reply are equal, let's print them again
61 let reply_str = String::from_utf8_lossy(reply);
62 let raw_reply_str = String::from_utf8_lossy(&raw_reply);
63
64 println!("[3] Bob's reply: {}", reply_str);
65 println!("[4] Alice's decrypted reply: {}", raw_reply_str);
66}Sourcepub fn sign(&self, msg: &[u8]) -> SignedMessage
pub fn sign(&self, msg: &[u8]) -> SignedMessage
Sourcepub fn from_bytes(pub_key: &[u8], sec_key: &[u8]) -> Result<Self, CryptoError>
pub fn from_bytes(pub_key: &[u8], sec_key: &[u8]) -> Result<Self, CryptoError>
Sourcepub fn to_bytes(&self) -> Result<([u8; 1793], [u8; 2305]), CryptoError>
pub fn to_bytes(&self) -> Result<([u8; 1793], [u8; 2305]), CryptoError>
Converts the key pair to raw byte arrays
§Returns
Result<([u8; PUBLICKEYBYTES], [u8; SECRETKEYBYTES]), CryptoError>: A tuple containing the public and secret keys as byte arrays
Examples found in repository?
examples/full_exchange.rs (line 22)
6fn main() {
7 let alice_kem = KEMPair::create();
8 let alice_signer = SignerPair::create();
9
10 let bob_kem = KEMPair::create();
11 let bob_signer = SignerPair::create();
12
13 // Create a base nonce with a new session id, and a counter of
14 let base_nonce = create_nonce(&gen_session_id(), 0);
15
16 // Lets create the message session for Alice first
17 let (mut alice_session, ciphertext) = MessageSession::new_initiator(
18 alice_kem,
19 alice_signer.clone(),
20 base_nonce,
21 &bob_kem.to_bytes().unwrap().0, // Bob's public KEM key
22 &bob_signer.to_bytes().unwrap().0, // Bob's public signer key
23 )
24 .unwrap();
25
26 // Now for Bob it would look like this
27 let mut bob_session = MessageSession::new_responder(
28 bob_kem,
29 bob_signer.clone(),
30 base_nonce,
31 &ciphertext,
32 &alice_signer.to_bytes().unwrap().0, // Alice's public signer key
33 )
34 .unwrap();
35
36 // Now both sessions contain a shared secret they use to encrypt and decrypt messages
37 // and a nonce that is incremented with each message sent or received.
38
39 // Alice creates a mesasge and prepares to send it to Bob
40 let message = b"Hello, Bob! This is a secret message.";
41 let encrypted_message = alice_session.craft_message(message).unwrap();
42
43 // Bob decrypts and verifies Alice's message
44 let raw_message = bob_session.validate_message(&encrypted_message).unwrap();
45
46 // Both message and raw_message are equal, let's print them out to illustrate
47 let message_str = String::from_utf8_lossy(message);
48 let raw_message_str = String::from_utf8_lossy(&raw_message);
49
50 println!("[1] Alice's message: {}", message_str);
51 println!("[2] Bob's decrypted message: {}", raw_message_str);
52
53 // Bob crafts a reply message to Alice
54 let reply = b"Hello, Alice! I received your message safely.";
55 let encrypted_reply = bob_session.craft_message(reply).unwrap();
56
57 // Alice decrypts and verifies Bob's reply
58 let raw_reply = alice_session.validate_message(&encrypted_reply).unwrap();
59
60 // Both reply and raw_reply are equal, let's print them again
61 let reply_str = String::from_utf8_lossy(reply);
62 let raw_reply_str = String::from_utf8_lossy(&raw_reply);
63
64 println!("[3] Bob's reply: {}", reply_str);
65 println!("[4] Alice's decrypted reply: {}", raw_reply_str);
66}Sourcepub fn to_bytes_uniform(&self) -> Vec<u8> ⓘ
pub fn to_bytes_uniform(&self) -> Vec<u8> ⓘ
Converts the key pair to a single byte vector with public key followed by secret key
§Returns
A vector containing the concatenated public and secret key bytes
Sourcepub fn from_bytes_uniform(bytes: &[u8]) -> Result<Self, CryptoError>
pub fn from_bytes_uniform(bytes: &[u8]) -> Result<Self, CryptoError>
Trait Implementations§
Source§impl Clone for SignerPair
impl Clone for SignerPair
Source§fn clone(&self) -> SignerPair
fn clone(&self) -> SignerPair
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl ViewOperations for SignerPair
impl ViewOperations for SignerPair
Source§fn pub_key_bytes(&self) -> &[u8; 1793]
fn pub_key_bytes(&self) -> &[u8; 1793]
Gets a reference to the public key as a byte array
Source§fn verify_comp(&self, msg: &[u8], sig: &[u8]) -> Result<bool, CryptoError>
fn verify_comp(&self, msg: &[u8], sig: &[u8]) -> Result<bool, CryptoError>
Verifies if a signature is valid for the provided message Read more
Source§fn verify_message_bytes(&self, sig: &[u8]) -> Result<Vec<u8>, CryptoError>
fn verify_message_bytes(&self, sig: &[u8]) -> Result<Vec<u8>, CryptoError>
Verifies a signature and returns the original message bytes Read more
Source§fn verify_message(&self, sm: &SignedMessage) -> Result<Vec<u8>, CryptoError>
fn verify_message(&self, sm: &SignedMessage) -> Result<Vec<u8>, CryptoError>
Verifies a signature and returns the original message bytes Read more
Auto Trait Implementations§
impl Freeze for SignerPair
impl RefUnwindSafe for SignerPair
impl Send for SignerPair
impl Sync for SignerPair
impl Unpin for SignerPair
impl UnwindSafe for SignerPair
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