Skip to content

Commit 5f7d49f

Browse files
committed
update readme
1 parent ecb9fde commit 5f7d49f

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,51 @@ Crates have not yet received any formal cryptographic and security reviews.
1919
| `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) |
2020
| `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) |
2121
| `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) |
2223

2324

2425
### Minimum Rust version
2526
All crates in this repository support Rust 1.27 or higher. In future minimum
2627
supported Rust version can be changed, but it will be done with the minor
2728
version bump.
2829

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+
2967
## License
3068

3169
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
4280
dual licensed as above, without any additional terms or conditions.
4381

4482
[1]: https://en.wikipedia.org/wiki/Stream_cipher
83+
[2]: https://docs.rs/stream-cipher

0 commit comments

Comments
 (0)