gcm_aes_decrypt

Function gcm_aes_decrypt 

Source
pub fn gcm_aes_decrypt(
    key: &[u8],
    iv: &[u8],
    cipher_text: &[u8],
    aad: &[u8],
    mul_fn: &GcmBlockMulFn,
) -> (Vec<u8>, [u8; 16])
Expand description

Decrypts cipher_text to plain text by XOR’ing with AES-encrypted “Counter block”. “Counter block” is initialized by “Initialization Vector” and incremented for each input block i.e. each 16 bytes of plain text. Cipher text then gets concatenated with “additional authenticated data” to produce GHASH which in turn XOR’ed with first AES-encrypted counter block to produce “Authentication tag”

  • cipher_key cipher key of underlying block cipher protocol i.e. AES
  • iv Initialization Vector. To initialize counter block.
  • cipher_text cipher text to decrypt and authenticate.
  • aad additional authenticated data.
  • mul_fn block multiplication function. The output of block_mul_to_block_mul_fn which should be provided within same session/key .
  • (Vec<u8>, [u8; 16]) (plain_text, tag) output

Tag should be compared with the one received with cipher_text. If not equal, then authentication failed (message is forged or corrupted).

§Examples

 use crypto_async_rs::aes_gcm::{GcmBlockMulEnhancement, gcm_aes_decrypt};

 let cipher_key = [0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08];
 let iv = [0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad, 0xde, 0xca, 0xf8, 0x88];
 let cipher_text = [0x42, 0x83, 0x1e, 0xc2, 0x21, 0x77, 0x74, 0x24, 0x4b, 0x72, 0x21, 0xb7, 0x84, 0xd0, 0xd4, 0x9c, 0xe3, 0xaa, 0x21, 0x2f, 0x2c, 0x02, 0xa4, 0xe0, 0x35, 0xc1, 0x7e, 0x23, 0x29, 0xac, 0xa1, 0x2e, 0x21, 0xd5, 0x14, 0xb2, 0x54, 0x66, 0x93, 0x1c, 0x7d, 0x8f, 0x6a, 0x5a, 0xac, 0x84, 0xaa, 0x05, 0x1b, 0xa3, 0x0b, 0x39, 0x6a, 0x0a, 0xac, 0x97, 0x3d, 0x58, 0xe0, 0x91, 0x47, 0x3f, 0x59, 0x85];
 let aad = [];
 let mul_fn = GcmBlockMulEnhancement::None.to_mul_fn(&cipher_key);
 let (p, tag) = gcm_aes_decrypt(&cipher_key, &iv, &cipher_text, &aad, &mul_fn);