Skip to content

Commit

Permalink
refactor: move Aes256Gcm & Aes256Ctr32 in /gcm & /ctr
Browse files Browse the repository at this point in the history
  • Loading branch information
AshGw committed May 31, 2024
1 parent 93b150d commit 6ffe32d
Show file tree
Hide file tree
Showing 6 changed files with 396 additions and 120 deletions.
274 changes: 274 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ license = "GPL-3.0"
[lib]
name = "gcm_rs"
path = "rust/lib.rs"
crate-type = ["cdylib"]

[profile.dev]
opt-level = 0
Expand All @@ -25,3 +26,5 @@ ctr = { version = "0.9.2", features = ["zeroize"] }
ghash = { version = "0.5.0", features = ["zeroize"] }
subtle = "2.3"
anyhow = "1.0.86"
pyo3 = "0.21.2"

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ dynamic = ["version"]

[tool.maturin]
python-source = "python"
module-name = "ready_gcm._lib_name"
module-name = "gcm_rs._lib_name"
features = ["pyo3/extension-module"]
25 changes: 25 additions & 0 deletions rust/ctr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,28 @@ impl Aes256Ctr32 {
fn is_valid_nonce_size(nonce: &Nonce, expected_size: usize) -> bool {
nonce.len() == expected_size
}

#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_aes256_ctr32_encryption_decryption() {
let key = [0u8; 32];
let nonce = [0u8; 12];
let init_ctr = 0;
let plaintext = b"plaintext";

let mut encryption =
Aes256Ctr32::from_key(&key, &nonce, init_ctr).unwrap();

let mut ciphertext = plaintext.to_vec();
encryption.xor(&mut ciphertext);

let mut decryption =
Aes256Ctr32::from_key(&key, &nonce, init_ctr).unwrap();

decryption.xor(&mut ciphertext);

assert_eq!(&ciphertext, plaintext);
}
}
Loading

0 comments on commit 6ffe32d

Please sign in to comment.