rustaes-gcm

AES-GCM without AEAD (tag)


I'm trying to implement a decryption service in rust. The rust-crypto crate doesn't work on my machine (Apple M1 Max) because the symbol _rust_crypto_util_fixed_time_eq_asm isn't defined.

After switching to the aes-gcm crate (v0.10.3), the program now doesn't immediately fail but instead the decryption fails internally and just returns an aead::Error.

The key, iv (nonce) and decrypted data are correct (tested with a Java program). There is no tag present.

Have I missed something out? Besides the missing question marks, I've just used the sample code from the AES-GCM crate documentation.

The code:

use aes_gcm::{aead::{Aead, AeadCore, KeyInit}, Nonce, Key, Aes128Gcm};

fn main() {
    let key = hex::decode("some_hex_string").expect("Decoding failed");
    let key = Key::<Aes128Gcm>::from_slice(key.as_ref());
    let cipher = Aes128Gcm::new(&key);

    let iv: [u8; 12] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
    let nonce = Nonce::from_slice(&iv);

    let plaintext = cipher.decrypt(nonce, decryped_byte_array.as_ref());
}


Solution

  • I found that if I can't use a tag I can't use the cipher.decrypt function because it requires me to send either a payload (containing AEAD/tag) or a concatenation of encrypted_message+tag. (Tag can not be null or empty)

    Following this answer on AES-GCM 256 decryption fails even with correct data, I now use the underlying function. (Still haven't figured out why "encrypting" works for "decrypting, but never mind...?)

    cipher.encrypt_in_place_detached(&iv.into(), &[], &mut some_byte_array)
    // Manipulate the now decrypted some_byte_array further