Skip to content

Commit

Permalink
cts: update to cipher v0.5 (#72)
Browse files Browse the repository at this point in the history
Additionally merges Enc/Dec types.
  • Loading branch information
newpavlov authored Nov 1, 2024
1 parent 46ddd1e commit 947f6cf
Show file tree
Hide file tree
Showing 26 changed files with 852 additions and 1,141 deletions.
118 changes: 26 additions & 92 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions cts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## UNRELEASED
### Changed
- Update to cipher v0.5 ([#72])
- Merge Enc/Dec types, i.e. `CbcCs1Enc` and `CbcCs1Dec` are merged into `CbcCs1` ([#72])

[#72]: https://github.com/RustCrypto/block-modes/pull/72

## 0.6.0 (2024-11-01)
- Initial release ([#70])

Expand Down
8 changes: 4 additions & 4 deletions cts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ keywords = ["crypto", "block-mode", "ciphers"]
categories = ["cryptography", "no-std"]

[dependencies]
cipher = "0.4.2"
cipher = "=0.5.0-pre.7"

[dev-dependencies]
cipher = { version = "0.4.2", features = ["dev"] }
cipher = { version = "=0.5.0-pre.7", features = ["dev"] }
hex-literal = "0.4"
aes = "0.8"
belt-block = "0.1"
aes = "=0.9.0-pre.2"
belt-block = "=0.2.0-pre.2"

[package.metadata.docs.rs]
all-features = true
Expand Down
18 changes: 10 additions & 8 deletions cts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,21 @@ use aes::Aes128;
use cts::{Decrypt, Encrypt, KeyIvInit};
use hex_literal::hex;

type Aes128CbcCs3 = cts::CbcCs3<Aes128>;

let key = [0x42; 16];
let iv = [0x24; 16];

// Message must be bigger than block size (16 bytes for AES-128)
let msg = b"Lorem ipsum dolor sit amet";
let mut buf = [0u8; 26];

let enc_mode = cts::CbcCs3Enc::<Aes128>::new(&key.into(), &iv.into());
enc_mode.encrypt_b2b(msg, &mut buf).unwrap();
Aes128CbcCs3::new(&key.into(), &iv.into())
.encrypt_b2b(msg, &mut buf).unwrap();
assert_eq!(buf, hex!("68ec97f172e322fdd38e74fca65cee52658ae2124beb5e4e5315"));

let dec_mode = cts::CbcCs3Dec::<Aes128>::new(&key.into(), &iv.into());
dec_mode.decrypt(&mut buf).unwrap();
Aes128CbcCs3::new(&key.into(), &iv.into())
.decrypt(&mut buf).unwrap();
assert_eq!(&buf, msg);
```

Expand All @@ -52,12 +54,12 @@ let iv2 = [0x25; 16];
let msg2 = b"Lorem ipsum dolor sit";
let mut buf2 = [0u8; 21];

let enc_mode = cts::CbcCs3Enc::inner_iv_init(&cipher, &iv1.into());
enc_mode.encrypt_b2b(msg1, &mut buf1).unwrap();
cts::CbcCs3::inner_iv_init(&cipher, &iv1.into())
.encrypt_b2b(msg1, &mut buf1).unwrap();
assert_eq!(buf1, hex!("68ec97f172e322fdd38e74fca65cee52658ae2124beb5e4e5315"));

let enc_mode = cts::CbcCs3Enc::inner_iv_init(&cipher, &iv2.into());
enc_mode.encrypt_b2b(msg2, &mut buf2).unwrap();
cts::CbcCs3::inner_iv_init(&cipher, &iv2.into())
.encrypt_b2b(msg2, &mut buf2).unwrap();
assert_eq!(buf2, hex!("69ebd2059e69c6e416a67351982267a26bf5672934"));
```

Expand Down
Loading

0 comments on commit 947f6cf

Please sign in to comment.