#aes-gcm #aes #gcm #stream #encryption-decryption

aes-gcm-stream

AES GCM stream encrypt and decrypt library, supports AES128/192/256 bit keys

7 releases

0.2.4 Nov 15, 2024
0.2.3 Nov 30, 2023
0.2.2 Oct 15, 2023
0.2.0 Sep 1, 2023
0.1.1 Aug 27, 2023

#483 in Cryptography

Download history 39/week @ 2024-09-12 32/week @ 2024-09-19 43/week @ 2024-09-26 43/week @ 2024-10-03 14/week @ 2024-10-10 31/week @ 2024-10-17 22/week @ 2024-10-24 19/week @ 2024-10-31 153/week @ 2024-11-07 213/week @ 2024-11-14 177/week @ 2024-11-21 81/week @ 2024-11-28 89/week @ 2024-12-05 103/week @ 2024-12-12 82/week @ 2024-12-19

283 downloads per month
Used in tiny-encrypt

MIT/Apache

44KB
891 lines

aes-gcm-stream

Crates | Document

Encrypt

// IMPORTANT! key and nonce SHOULD generate by random
let mut key = [0u8; 32];
let mut nonce = [0; 12];

let mut encryptor = Aes256GcmStreamEncryptor::new(key.clone(), &nonce);

let mut ciphertext = vec![];
ciphertext.extend_from_slice(&encryptor.update(b"Hello "));
ciphertext.extend_from_slice(&encryptor.update(b" World"));
ciphertext.extend_from_slice(&encryptor.update(b"!"));
let (last_block, tag) = encryptor.finalize();
ciphertext.extend_from_slice(&last_block);
ciphertext.extend_from_slice(&tag);

println!("Ciphertext: {}", hex::encode(&ciphertext));

Run Example

Open example: encrypt_and_decrypt.rs

$ cargo run --example encrypt_and_decrypt
    Finished dev [unoptimized + debuginfo] target(s) in 0.10s
     Running `target/debug/examples/encrypt_and_decrypt`
Ciphertext: 86c22c5122404b39683ca9b79b889fd00a6212d1be2ebc3f4f8f22f90b
Plaintext: Hello  World!

Benchmark @MacBook Pro (Retina, 15-inch, Late 2013/2 GHz Quad-Core Intel Core i7)

$ cargo run --release --example bench
AES128 encrypt         : 483.04 M/s
AES192 encrypt         : 466.22 M/s
AES256 encrypt         : 451.38 M/s
AES256 en/decrypt      : 222.66 M/s
AES256 encrypt aes-gcm : 547.63 M/s

Thanks:

Dependencies

~0.9–1.4MB
~32K SLoC