@@ -45,28 +45,30 @@ pub fn random_u64() -> u64 {
45
45
}
46
46
47
47
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
+ */
52
53
pub fn public_key_valid ( & PublicKey ( ref pk) : & PublicKey ) -> bool {
53
54
pk[ PUBLICKEYBYTES - 1 ] <= 127 // Last bit of key is always zero.
54
55
}
55
56
56
57
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
+ */
70
72
#[ inline]
71
73
pub fn encrypt_precompute ( their_public_key : & PublicKey ,
72
74
our_secret_key : & SecretKey ) -> PrecomputedKey {
@@ -76,18 +78,19 @@ pub fn encrypt_precompute(their_public_key: &PublicKey,
76
78
//pub use sodiumoxide::crypto::box_::precompute as encrypt_precompute;
77
79
78
80
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
+ */
91
94
#[ inline]
92
95
pub fn encrypt_data_symmetric ( precomputed_key : & PrecomputedKey ,
93
96
nonce : & Nonce ,
@@ -98,18 +101,19 @@ pub fn encrypt_data_symmetric(precomputed_key: &PrecomputedKey,
98
101
//pub use sodiumoxide::crypto::box_::seal_precomputed as encrypt_data_symmetric;
99
102
100
103
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
+ */
113
117
#[ inline]
114
118
pub fn decrypt_data_symmetric ( precomputed_key : & PrecomputedKey ,
115
119
nonce : & Nonce ,
@@ -118,16 +122,17 @@ pub fn decrypt_data_symmetric(precomputed_key: &PrecomputedKey,
118
122
}
119
123
120
124
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
+ */
131
136
// TODO: needs to be tested on BE arch
132
137
#[ inline]
133
138
pub fn increment_nonce ( nonce : & mut Nonce ) {
0 commit comments