1313#[ cfg( not( fuzzing) ) ]
1414mod real_chachapoly {
1515 use super :: super :: chacha20:: ChaCha20 ;
16- use super :: super :: poly1305:: Poly1305 ;
1716 use super :: super :: fixed_time_eq;
17+ use super :: super :: poly1305:: Poly1305 ;
1818
1919 #[ derive( Clone , Copy ) ]
2020 pub struct ChaCha20Poly1305RFC {
@@ -70,7 +70,9 @@ mod real_chachapoly {
7070 self . mac . raw_result ( out_tag) ;
7171 }
7272
73- pub fn encrypt_full_message_in_place ( & mut self , input_output : & mut [ u8 ] , out_tag : & mut [ u8 ] ) {
73+ pub fn encrypt_full_message_in_place (
74+ & mut self , input_output : & mut [ u8 ] , out_tag : & mut [ u8 ] ,
75+ ) {
7476 self . encrypt_in_place ( input_output) ;
7577 self . finish_and_get_tag ( out_tag) ;
7678 }
@@ -98,7 +100,9 @@ mod real_chachapoly {
98100 /// Decrypt the `input`, checking the given `tag` prior to writing the decrypted contents
99101 /// into `output`. Note that, because `output` is not touched until the `tag` is checked,
100102 /// this decryption is *variable time*.
101- pub fn variable_time_decrypt ( & mut self , input : & [ u8 ] , output : & mut [ u8 ] , tag : & [ u8 ] ) -> Result < ( ) , ( ) > {
103+ pub fn variable_time_decrypt (
104+ & mut self , input : & [ u8 ] , output : & mut [ u8 ] , tag : & [ u8 ] ,
105+ ) -> Result < ( ) , ( ) > {
102106 assert ! ( input. len( ) == output. len( ) ) ;
103107 assert ! ( !self . finished) ;
104108
@@ -111,7 +115,7 @@ mod real_chachapoly {
111115 self . mac . input ( & self . aad_len . to_le_bytes ( ) ) ;
112116 self . mac . input ( & ( self . data_len as u64 ) . to_le_bytes ( ) ) ;
113117
114- let mut calc_tag = [ 0u8 ; 16 ] ;
118+ let mut calc_tag = [ 0u8 ; 16 ] ;
115119 self . mac . raw_result ( & mut calc_tag) ;
116120 if fixed_time_eq ( & calc_tag, tag) {
117121 self . cipher . process ( input, output) ;
@@ -121,9 +125,15 @@ mod real_chachapoly {
121125 }
122126 }
123127
124- pub fn check_decrypt_in_place ( & mut self , input_output : & mut [ u8 ] , tag : & [ u8 ] ) -> Result < ( ) , ( ) > {
128+ pub fn check_decrypt_in_place (
129+ & mut self , input_output : & mut [ u8 ] , tag : & [ u8 ] ,
130+ ) -> Result < ( ) , ( ) > {
125131 self . decrypt_in_place ( input_output) ;
126- if self . finish_and_check_tag ( tag) { Ok ( ( ) ) } else { Err ( ( ) ) }
132+ if self . finish_and_check_tag ( tag) {
133+ Ok ( ( ) )
134+ } else {
135+ Err ( ( ) )
136+ }
127137 }
128138
129139 /// Decrypt in place, without checking the tag. Use `finish_and_check_tag` to check it
@@ -146,7 +156,7 @@ mod real_chachapoly {
146156 self . mac . input ( & self . aad_len . to_le_bytes ( ) ) ;
147157 self . mac . input ( & ( self . data_len as u64 ) . to_le_bytes ( ) ) ;
148158
149- let mut calc_tag = [ 0u8 ; 16 ] ;
159+ let mut calc_tag = [ 0u8 ; 16 ] ;
150160 self . mac . raw_result ( & mut calc_tag) ;
151161 if fixed_time_eq ( & calc_tag, tag) {
152162 true
@@ -177,10 +187,7 @@ mod fuzzy_chachapoly {
177187 let mut tag = [ 0 ; 16 ] ;
178188 tag. copy_from_slice ( & key[ 0 ..16 ] ) ;
179189
180- ChaCha20Poly1305RFC {
181- tag,
182- finished : false ,
183- }
190+ ChaCha20Poly1305RFC { tag, finished : false }
184191 }
185192
186193 pub fn encrypt ( & mut self , input : & [ u8 ] , output : & mut [ u8 ] , out_tag : & mut [ u8 ] ) {
@@ -192,7 +199,9 @@ mod fuzzy_chachapoly {
192199 self . finished = true ;
193200 }
194201
195- pub fn encrypt_full_message_in_place ( & mut self , input_output : & mut [ u8 ] , out_tag : & mut [ u8 ] ) {
202+ pub fn encrypt_full_message_in_place (
203+ & mut self , input_output : & mut [ u8 ] , out_tag : & mut [ u8 ] ,
204+ ) {
196205 self . encrypt_in_place ( input_output) ;
197206 self . finish_and_get_tag ( out_tag) ;
198207 }
@@ -207,27 +216,39 @@ mod fuzzy_chachapoly {
207216 self . finished = true ;
208217 }
209218
210- pub fn variable_time_decrypt ( & mut self , input : & [ u8 ] , output : & mut [ u8 ] , tag : & [ u8 ] ) -> Result < ( ) , ( ) > {
219+ pub fn variable_time_decrypt (
220+ & mut self , input : & [ u8 ] , output : & mut [ u8 ] , tag : & [ u8 ] ,
221+ ) -> Result < ( ) , ( ) > {
211222 assert ! ( input. len( ) == output. len( ) ) ;
212223 assert ! ( self . finished == false ) ;
213224
214- if tag[ ..] != self . tag [ ..] { return Err ( ( ) ) ; }
225+ if tag[ ..] != self . tag [ ..] {
226+ return Err ( ( ) ) ;
227+ }
215228 output. copy_from_slice ( input) ;
216229 self . finished = true ;
217230 Ok ( ( ) )
218231 }
219232
220- pub fn check_decrypt_in_place ( & mut self , input_output : & mut [ u8 ] , tag : & [ u8 ] ) -> Result < ( ) , ( ) > {
233+ pub fn check_decrypt_in_place (
234+ & mut self , input_output : & mut [ u8 ] , tag : & [ u8 ] ,
235+ ) -> Result < ( ) , ( ) > {
221236 self . decrypt_in_place ( input_output) ;
222- if self . finish_and_check_tag ( tag) { Ok ( ( ) ) } else { Err ( ( ) ) }
237+ if self . finish_and_check_tag ( tag) {
238+ Ok ( ( ) )
239+ } else {
240+ Err ( ( ) )
241+ }
223242 }
224243
225244 pub ( in super :: super ) fn decrypt_in_place ( & mut self , _input : & mut [ u8 ] ) {
226245 assert ! ( self . finished == false ) ;
227246 }
228247
229248 pub ( in super :: super ) fn finish_and_check_tag ( & mut self , tag : & [ u8 ] ) -> bool {
230- if tag[ ..] != self . tag [ ..] { return false ; }
249+ if tag[ ..] != self . tag [ ..] {
250+ return false ;
251+ }
231252 self . finished = true ;
232253 true
233254 }
0 commit comments