@@ -19,13 +19,51 @@ Crates have not yet received any formal cryptographic and security reviews.
19
19
| ` cfb-mode ` | [ ![ crates.io] ( https://img.shields.io/crates/v/cfb-mode.svg )] ( https://crates.io/crates/cfb-mode ) | [ ![ Documentation] ( https://docs.rs/cfb-mode/badge.svg )] ( https://docs.rs/cfb-mode ) |
20
20
| ` cfb8 ` | [ ![ crates.io] ( https://img.shields.io/crates/v/cfb8.svg )] ( https://crates.io/crates/cfb8 ) | [ ![ Documentation] ( https://docs.rs/cfb8/badge.svg )] ( https://docs.rs/cfb8 ) |
21
21
| ` ctr ` | [ ![ crates.io] ( https://img.shields.io/crates/v/ctr.svg )] ( https://crates.io/crates/ctr ) | [ ![ Documentation] ( https://docs.rs/ctr/badge.svg )] ( https://docs.rs/ctr ) |
22
+ | ` ofb ` | [ ![ crates.io] ( https://img.shields.io/crates/v/ofb.svg )] ( https://crates.io/crates/ofb ) | [ ![ Documentation] ( https://docs.rs/ofb/badge.svg )] ( https://docs.rs/ofb ) |
22
23
23
24
24
25
### Minimum Rust version
25
26
All crates in this repository support Rust 1.27 or higher. In future minimum
26
27
supported Rust version can be changed, but it will be done with the minor
27
28
version bump.
28
29
30
+ ## Usage
31
+
32
+ Crates functionality is expressed in terms of traits defined in the
33
+ [ ` stream-cipher ` ] [ 2 ] crate.
34
+
35
+ Let's use AES-128-OFB to demonstrate usage of synchronous stream cipher:
36
+ ``` rust
37
+ extern crate aes;
38
+ extern crate ofb;
39
+
40
+ use aes :: Aes128 ;
41
+ use ofb :: Ofb ;
42
+ // import relevant traits
43
+ use ofb :: stream_cipher :: {NewStreamCipher , SyncStreamCipher };
44
+
45
+ // OFB mode implementation is generic over block ciphers
46
+ // we will create a type alias for convenience
47
+ type AesOfb = Ofb <Aes128 >;
48
+
49
+ let key = b " very secret key." ;
50
+ let iv = b " unique init vect" ;
51
+ let plaintext = b " The quick brown fox jumps over the lazy dog." ;
52
+
53
+ let mut buffer = plaintext . to_vec ();
54
+ // create cipher instance
55
+ let mut cipher = AesOfb :: new_var (key , iv )? ;
56
+ // apply keystream (encrypt)
57
+ cipher . apply_keystream (& mut buffer );
58
+ // and decrypt it back
59
+ AesOfb :: new_var (key , iv )? . apply_keystream (& mut buffer );
60
+ // stream ciphers can be used with streaming messages
61
+ let mut cipher = AesOfb :: new_var (key , iv ). unwrap ();
62
+ for chunk in buffer . chunks_mut (3 ) {
63
+ cipher . apply_keystream (chunk );
64
+ }
65
+ ```
66
+
29
67
## License
30
68
31
69
All crates licensed under either of
@@ -42,3 +80,4 @@ for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
42
80
dual licensed as above, without any additional terms or conditions.
43
81
44
82
[ 1 ] : https://en.wikipedia.org/wiki/Stream_cipher
83
+ [ 2 ] : https://docs.rs/stream-cipher
0 commit comments