-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
50 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
pub const DELTA: u32 = 0x9e3779b9; | ||
pub const ROUNDS: u32 = 32; | ||
pub const ROUNDS: usize = 32; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,18 @@ | ||
use cipher::{array::Array, BlockCipherDecrypt, BlockCipherEncrypt, KeyInit}; | ||
use xtea::Xtea; | ||
|
||
#[test] | ||
fn xtea() { | ||
// https://web.archive.org/web/20231115163347/https://asecuritysite.com/encryption/xtea | ||
let key = b"0123456789012345"; | ||
let plaintext = b"ABCDEFGH"; | ||
let ciphertext = [0xea, 0x0c, 0x3d, 0x7c, 0x1c, 0x22, 0x55, 0x7f]; | ||
let cipher = Xtea::new_from_slice(key).unwrap(); | ||
|
||
let mut block = Array::clone_from_slice(plaintext); | ||
cipher.encrypt_block(&mut block); | ||
assert_eq!(ciphertext, block.as_slice()); | ||
|
||
cipher.decrypt_block(&mut block); | ||
assert_eq!(plaintext, block.as_slice()); | ||
} |