Skip to content

Commit

Permalink
add example
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Mar 24, 2024
1 parent 6250283 commit 1683095
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
22 changes: 22 additions & 0 deletions ocb3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,28 @@ Pure Rust implementation of **OCB3** ([RFC 7253][rfc7253])[Authenticated Encrypt

[Documentation][docs-link]

## Example

```rust
use aes::Aes128;
use ocb3::{
aead::{Aead, AeadCore, KeyInit, OsRng, generic_array::GenericArray},
consts::U12,
AesOcb3,
};

type Aes128Ocb3 = AesOcb3<Aes128, U12>;

let key = Aes128::generate_key(&mut OsRng);
let cipher = Aes128Ocb3::new(&key);
let nonce = Aes128Ocb3::generate_nonce(&mut OsRng);
let ciphertext = cipher.encrypt(&nonce, b"plaintext message".as_ref()).unwrap();
let plaintext = cipher.decrypt(&nonce, ciphertext.as_ref()).unwrap();

assert_eq!(&plaintext, b"plaintext message");
```


## Security Notes

No security audits of this crate have ever been performed, and it has not been thoroughly assessed to ensure its operation is constant-time on common CPU architectures.
Expand Down
5 changes: 5 additions & 0 deletions ocb3/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ use cipher::{
};
use subtle::ConstantTimeEq;

/// Constants used, reexported for convenience.
pub mod consts {
pub use cipher::consts::{U0, U12, U16};
}

mod util;

use crate::util::{double, inplace_xor, ntz, Block};
Expand Down

0 comments on commit 1683095

Please sign in to comment.