@@ -45,28 +45,30 @@ pub fn random_u64() -> u64 {
4545}
4646
4747
48- /// Check if Tox public key `PUBLICKEYBYTES` is valid. Should be used only for
49- /// input validation.
50- ///
51- /// Returns `true` if valid, `false` otherwise.
48+ /** Check if Tox public key `PUBLICKEYBYTES` is valid. Should be used only for
49+ input validation.
50+
51+ Returns `true` if valid, `false` otherwise.
52+ */
5253pub fn public_key_valid ( & PublicKey ( ref pk) : & PublicKey ) -> bool {
5354 pk[ PUBLICKEYBYTES - 1 ] <= 127 // Last bit of key is always zero.
5455}
5556
5657
57- /// Precomputes the shared key from `their_public_key` and `our_secret_key`.
58- ///
59- /// For fast encrypt/decrypt - this way we can avoid an expensive elliptic
60- /// curve scalar multiply for each encrypt/decrypt operation.
61- ///
62- /// Use if communication is not one-time.
63- ///
64- /// `encrypt_precompute` does the shared-key generation once, so that it does
65- /// not have to be performed on every encrypt/decrypt.
66- ///
67- /// This a wrapper for the
68- /// [`precompute()`](../../../sodiumoxide/crypto/box_/curve25519xsalsa20poly1305/fn.precompute.html)
69- /// function from `sodiumoxide` crate.
58+ /** Precomputes the shared key from `their_public_key` and `our_secret_key`.
59+
60+ For fast encrypt/decrypt - this way we can avoid an expensive elliptic
61+ curve scalar multiply for each encrypt/decrypt operation.
62+
63+ Use if communication is not one-time.
64+
65+ `encrypt_precompute` does the shared-key generation once, so that it does
66+ not have to be performed on every encrypt/decrypt.
67+
68+ This a wrapper for the
69+ [`precompute()`](../../../sodiumoxide/crypto/box_/curve25519xsalsa20poly1305/fn.precompute.html)
70+ function from `sodiumoxide` crate.
71+ */
7072#[ inline]
7173pub fn encrypt_precompute ( their_public_key : & PublicKey ,
7274 our_secret_key : & SecretKey ) -> PrecomputedKey {
@@ -76,18 +78,19 @@ pub fn encrypt_precompute(their_public_key: &PublicKey,
7678//pub use sodiumoxide::crypto::box_::precompute as encrypt_precompute;
7779
7880
79- /// Returns encrypted data from `plain`, with length of `plain + 16` due to
80- /// padding.
81- ///
82- /// Encryption is done using precomputed key (from the public key (32 bytes)
83- /// of receiver and the secret key of sender) and a 24 byte nonce.
84- ///
85- /// `sodiumoxide` takes care of padding the data, so the resulting encrypted
86- /// data has length of `plain + 16`.
87- ///
88- /// A wrapper for the
89- /// [`seal_precomputed()`](../../../sodiumoxide/crypto/box_/curve25519xsalsa20poly1305/fn.seal_precomputed.html)
90- /// function from `sodiumoxide`.
81+ /** Returns encrypted data from `plain`, with length of `plain + 16` due to
82+ padding.
83+
84+ Encryption is done using precomputed key (from the public key (32 bytes)
85+ of receiver and the secret key of sender) and a 24 byte nonce.
86+
87+ `sodiumoxide` takes care of padding the data, so the resulting encrypted
88+ data has length of `plain + 16`.
89+
90+ A wrapper for the
91+ [`seal_precomputed()`](../../../sodiumoxide/crypto/box_/curve25519xsalsa20poly1305/fn.seal_precomputed.html)
92+ function from `sodiumoxide`.
93+ */
9194#[ inline]
9295pub fn encrypt_data_symmetric ( precomputed_key : & PrecomputedKey ,
9396 nonce : & Nonce ,
@@ -98,18 +101,19 @@ pub fn encrypt_data_symmetric(precomputed_key: &PrecomputedKey,
98101//pub use sodiumoxide::crypto::box_::seal_precomputed as encrypt_data_symmetric;
99102
100103
101- /// Returns plain data from `encrypted`, with length of `encrypted - 16` due to
102- /// padding, or `()` if data couldn't be decrypted.
103- ///
104- /// Decryption is done using precomputed key (from the secret key of receiver
105- /// and the public key of sender) and a 24 byte nonce.
106- ///
107- /// `sodiumoxide` takes care of removing padding from the data, so the
108- /// resulting plain data has length of `encrypted - 16`.
109- ///
110- /// This function is a wrapper for the
111- /// [`open_precomputed()`](../../../sodiumoxide/crypto/box_/curve25519xsalsa20poly1305/fn.open_precomputed.html)
112- /// function from `sodiumoxide`.
104+ /** Returns plain data from `encrypted`, with length of `encrypted - 16` due to
105+ padding, or `()` if data couldn't be decrypted.
106+
107+ Decryption is done using precomputed key (from the secret key of receiver
108+ and the public key of sender) and a 24 byte nonce.
109+
110+ `sodiumoxide` takes care of removing padding from the data, so the
111+ resulting plain data has length of `encrypted - 16`.
112+
113+ This function is a wrapper for the
114+ [`open_precomputed()`](../../../sodiumoxide/crypto/box_/curve25519xsalsa20poly1305/fn.open_precomputed.html)
115+ function from `sodiumoxide`.
116+ */
113117#[ inline]
114118pub fn decrypt_data_symmetric ( precomputed_key : & PrecomputedKey ,
115119 nonce : & Nonce ,
@@ -118,16 +122,17 @@ pub fn decrypt_data_symmetric(precomputed_key: &PrecomputedKey,
118122}
119123
120124
121- /// Inrement given nonce by 1.
122- ///
123- /// Treats `Nonce` as BE number.
124- ///
125- /// If nonce can't be incremented (all bits are `1`), nonce is zeroed.
126- ///
127- /// *Note that behaviour of this function might change to not increment supplied
128- /// nonces, but rather, return an increased nonce.*
129- ///
130- /// Spec: https://toktok.github.io/spec#nonce-2
125+ /** Inrement given nonce by 1.
126+
127+ Treats `Nonce` as BE number.
128+
129+ If nonce can't be incremented (all bits are `1`), nonce is zeroed.
130+
131+ *Note that behaviour of this function might change to not increment supplied
132+ nonces, but rather, return an increased nonce.*
133+
134+ Spec: https://toktok.github.io/spec#nonce-2
135+ */
131136// TODO: needs to be tested on BE arch
132137#[ inline]
133138pub fn increment_nonce ( nonce : & mut Nonce ) {
0 commit comments