@@ -37,50 +37,6 @@ The following describes the security level ratings associated with each hash fun
3737| :yellow_heart : | Theoretical break: security lower than claimed |
3838| :broken_heart : | Attack demonstrated in practice: avoid if at all possible |
3939
40- ## Example
41-
42- Crates functionality is expressed in terms of traits defined in the [ ` cipher ` ] crate.
43-
44- Let's use ChaCha20 to demonstrate usage of synchronous stream cipher:
45-
46- ``` rust
47- use chacha20 :: ChaCha20 ;
48- // Import relevant traits
49- use chacha20 :: cipher :: {KeyIvInit , StreamCipher , StreamCipherSeek };
50- use hex_literal :: hex;
51-
52- let key = [0x42 ; 32 ];
53- let nonce = [0x24 ; 12 ];
54- let plaintext = hex! (" 00010203 04050607 08090a0b 0c0d0e0f" );
55- let ciphertext = hex! (" e405626e 4f1236b3 670ee428 332ea20e" );
56-
57- // Key and IV must be references to the `GenericArray` type.
58- // Here we use the `Into` trait to convert arrays into it.
59- let mut cipher = ChaCha20 :: new (& key . into (), & nonce . into ());
60-
61- let mut buffer = plaintext ;
62-
63- // apply keystream (encrypt)
64- cipher . apply_keystream (& mut buffer );
65- assert_eq! (buffer , ciphertext );
66-
67- let ciphertext = buffer ;
68-
69- // ChaCha ciphers support seeking
70- cipher . seek (0u32 );
71-
72- // decrypt ciphertext by applying keystream again
73- cipher . apply_keystream (& mut buffer );
74- assert_eq! (buffer , plaintext );
75-
76- // stream ciphers can be used with streaming messages
77- cipher . seek (0u32 );
78- for chunk in buffer . chunks_mut (3 ) {
79- cipher . apply_keystream (chunk );
80- }
81- assert_eq! (buffer , ciphertext );
82- ```
83-
8440## License
8541
8642All crates licensed under either of
0 commit comments