@@ -324,114 +324,3 @@ where
324324 B : DeoxysBcType ,
325325{
326326}
327-
328- #[ cfg( test) ]
329- mod tests {
330- //! this module is here to test the inout behavior which is not currently exposed.
331- //! it will be once we port over to the API made in RustCrypto/traits#1793.
332- //!
333- //! This is to drop once https://github.com/RustCrypto/traits/pull/1797 is made available.
334- //!
335- //! It duplicates test vectors from `tests/deoxys_i_128.rs` and provides a mock buffer backing
336- //! for InOut.
337-
338- use hex_literal:: hex;
339-
340- use super :: * ;
341-
342- struct MockBuffer {
343- in_buf : [ u8 ; 33 ] ,
344- out_buf : [ u8 ; 33 ] ,
345- }
346-
347- impl From < & [ u8 ] > for MockBuffer {
348- fn from ( buf : & [ u8 ] ) -> Self {
349- let mut in_buf = [ 0u8 ; 33 ] ;
350- in_buf. copy_from_slice ( buf) ;
351- Self {
352- in_buf,
353- out_buf : [ 0u8 ; 33 ] ,
354- }
355- }
356- }
357-
358- impl MockBuffer {
359- /// Get an [`InOutBuf`] from a [`MockBuffer`]
360- pub fn to_in_out_buf ( & mut self ) -> InOutBuf < ' _ , ' _ , u8 > {
361- InOutBuf :: new ( self . in_buf . as_slice ( ) , self . out_buf . as_mut_slice ( ) )
362- . expect ( "Invariant violation" )
363- }
364- }
365-
366- impl AsRef < [ u8 ] > for MockBuffer {
367- fn as_ref ( & self ) -> & [ u8 ] {
368- & self . out_buf
369- }
370- }
371-
372- #[ test]
373- fn test_deoxys_i_128_5 ( ) {
374- let plaintext = hex ! ( "5a4c652cb880808707230679224b11799b5883431292973215e9bd03cf3bc32fe4" ) ;
375- let mut buffer = MockBuffer :: from ( & plaintext[ ..] ) ;
376-
377- let aad = [ ] ;
378-
379- let key = hex ! ( "101112131415161718191a1b1c1d1e1f" ) ;
380- let key = Array ( key) ;
381-
382- let nonce = hex ! ( "202122232425262728292a2b2c2d2e2f" ) ;
383- let nonce = Array :: try_from ( & nonce[ ..8 ] ) . unwrap ( ) ;
384-
385- let ciphertext_expected =
386- hex ! ( "cded5a43d3c76e942277c2a1517530ad66037897c985305ede345903ed7585a626" ) ;
387-
388- let tag_expected: [ u8 ; 16 ] = hex ! ( "cbf5faa6b8398c47f4278d2019161776" ) ;
389-
390- type M = modes:: DeoxysI < deoxys_bc:: DeoxysBc256 > ;
391- let cipher = DeoxysI128 :: new ( & key) ;
392- let tag: Tag = M :: encrypt_inout ( & nonce, & aad, buffer. to_in_out_buf ( ) , & cipher. subkeys ) ;
393-
394- let ciphertext = buffer. as_ref ( ) ;
395- assert_eq ! ( ciphertext, ciphertext_expected) ;
396- assert_eq ! ( tag, tag_expected) ;
397-
398- let mut buffer = MockBuffer :: from ( buffer. as_ref ( ) ) ;
399- M :: decrypt_inout ( & nonce, & aad, buffer. to_in_out_buf ( ) , & tag, & cipher. subkeys )
400- . expect ( "decryption failed" ) ;
401-
402- assert_eq ! ( & plaintext[ ..] , buffer. as_ref( ) ) ;
403- }
404-
405- #[ test]
406- fn test_deoxys_ii_128_5 ( ) {
407- let plaintext = hex ! ( "06ac1756eccece62bd743fa80c299f7baa3872b556130f52265919494bdc136db3" ) ;
408- let mut buffer = MockBuffer :: from ( & plaintext[ ..] ) ;
409-
410- let aad = [ ] ;
411-
412- let key = hex ! ( "101112131415161718191a1b1c1d1e1f" ) ;
413- let key = Array ( key) ;
414-
415- let nonce = hex ! ( "202122232425262728292a2b2c2d2e2f" ) ;
416- let nonce = Array :: try_from ( & nonce[ ..15 ] ) . unwrap ( ) ;
417-
418- let ciphertext_expected =
419- hex ! ( "82bf241958b324ed053555d23315d3cc20935527fc970ff34a9f521a95e302136d" ) ;
420-
421- let tag_expected: [ u8 ; 16 ] = hex ! ( "0eadc8612d5208c491e93005195e9769" ) ;
422-
423- type M = modes:: DeoxysII < deoxys_bc:: DeoxysBc256 > ;
424- let cipher = DeoxysII128 :: new ( & key) ;
425- let tag: Tag = M :: encrypt_inout ( & nonce, & aad, buffer. to_in_out_buf ( ) , & cipher. subkeys ) ;
426-
427- let ciphertext = buffer. as_ref ( ) ;
428- assert_eq ! ( ciphertext, ciphertext_expected) ;
429- assert_eq ! ( tag, tag_expected) ;
430-
431- let mut buffer = MockBuffer :: from ( buffer. as_ref ( ) ) ;
432- M :: decrypt_inout ( & nonce, & aad, buffer. to_in_out_buf ( ) , & tag, & cipher. subkeys )
433- . expect ( "decryption failed" ) ;
434-
435- assert_eq ! ( & plaintext[ ..] , buffer. as_ref( ) ) ;
436- }
437- }
0 commit comments