| Crates.io | gcm_rs |
| lib.rs | gcm_rs |
| version | 2.0.5 |
| created_at | 2024-06-09 01:10:20.235617+00 |
| updated_at | 2025-11-27 03:50:44.235949+00 |
| description | AES-256 GCM |
| homepage | |
| repository | https://github.com/rccyx/gcm_rs |
| max_upload_size | |
| id | 1266110 |
| size | 74,935 |
AES-256 in CTR-32 mode with GHASH per NIST SP 800-38D
12 byte nonce, 16 byte tag
Constant time tag verification
Zeroize for sensitive in-memory data
Rust crate for direct use
Python wheels built with maturin
pip install gcm_rs
cargo add gcm_rs
use gcm_rs::gcm::{Aes256Gcm, Encrypt, Decrypt};
use gcm_rs::random::{gen_key, gen_nonce};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let key = gen_key(); // 32 bytes
let nonce = gen_nonce(); // 12 bytes
let ad = b"header"; // associated data
let mut pt = b"attack at dawn".to_vec();
// encrypt
let mut enc = Aes256Gcm::new(&key, &nonce, ad)?;
let mut ct = pt.clone();
enc.encrypt(&mut ct);
let tag = enc.compute_tag();
// decrypt and verify
let mut dec = Aes256Gcm::new(&key, &nonce, ad)?;
let mut out = ct.clone();
dec.decrypt(&mut out);
dec.verify_tag(&tag)?;
assert_eq!(out, pt);
Ok(())
}
Current helpers:
from gcm_rs import gen_key, gen_nonce
key = gen_key() # 32 bytes
nonce = gen_nonce() # 12 bytes
print(len(key), len(nonce))
Planned in the next release: a
Gcmclass withnew,encrypt,decrypt,compute_tag, andverify_tagthat returns and acceptsbytes.
use gcm_rs::gcm::{Aes256Gcm, Encrypt, Decrypt};
// construct
let mut gcm = Aes256Gcm::new(key, nonce, associated_data)?;
// streaming style
gcm.encrypt(buf_chunk_1);
gcm.encrypt(buf_chunk_2);
let tag = gcm.compute_tag();
// decrypt + verify
let mut gcm2 = Aes256Gcm::new(key, nonce, associated_data)?;
gcm2.decrypt(buf_all);
gcm2.verify_tag(tag)?;
key: &[u8] length 32nonce: &[u8] length 12associated_data: &[u8] any lengthtag: 16 bytesInternals
CTR starts at block J0 + 1 per the spec.
GHASH runs over associated data and ciphertext, then final length block, then pads with the precomputed keystream block.
GPL-3.0