Module evercrypt::aead[][src]

Expand description

Authenticated Encryption with Associated Data (AEAD)

This module implements AES-GCM 128 and 256, and Chacha20Poly1305.

Usage

This module provides two APIs

Aead with key state

use evercrypt::aead::{Aead, Mode, Error};

let key = [0x5b, 0x96, 0x04, 0xfe, 0x14, 0xea, 0xdb, 0xa9, 0x31, 0xb0, 0xcc,
           0xf3, 0x48, 0x43, 0xda, 0xb9, 0x5b, 0x96, 0x04, 0xfe, 0x14, 0xea,
           0xdb, 0xa9, 0x31, 0xb0, 0xcc, 0xf3, 0x48, 0x43, 0xda, 0xb9];
let cipher = match Aead::new(Mode::Chacha20Poly1305, &key) {
   Ok(c) => c,
   Err(e) => panic!("Error instantiating AEAD.\n{:?}", e),
};

let iv = [0x02, 0x83, 0x18, 0xab, 0xc1, 0x82, 0x40, 0x29, 0x13, 0x81, 0x41, 0xa2];
let msg = [0x00, 0x1d, 0x0c, 0x23, 0x12, 0x87, 0xc1, 0x18, 0x27, 0x84, 0x55, 0x4c, 0xa3, 0xa2, 0x19, 0x08];
let aad = [];

let (ciphertext, tag) = match cipher.encrypt(&msg, &iv, &aad) {
    Ok(r) => r,
    Err(e) => panic!("Error encrypting.\n{:?}", e),
};

let msg_ = match cipher.decrypt(&ciphertext, &tag, &iv, &aad) {
    Ok(r) => r,
    Err(e) => panic!("Error decrypting.\n{:?}", e),
};

assert_eq!(&msg[..], &msg_[..]);

Single-shot API

use evercrypt::aead::{self, Mode};

let key = [0x5b, 0x96, 0x04, 0xfe, 0x14, 0xea, 0xdb, 0xa9, 0x31, 0xb0, 0xcc,
           0xf3, 0x48, 0x43, 0xda, 0xb9, 0x5b, 0x96, 0x04, 0xfe, 0x14, 0xea,
           0xdb, 0xa9, 0x31, 0xb0, 0xcc, 0xf3, 0x48, 0x43, 0xda, 0xb9];
let iv = [0x02, 0x83, 0x18, 0xab, 0xc1, 0x82, 0x40, 0x29, 0x13, 0x81, 0x41, 0xa2];
let msg = [0x00, 0x1d, 0x0c, 0x23, 0x12, 0x87, 0xc1, 0x18, 0x27, 0x84, 0x55, 0x4c, 0xa3, 0xa2, 0x19, 0x08];
let aad = [];

let (ciphertext, tag) = match aead::encrypt(Mode::Chacha20Poly1305, &key, &msg, &iv, &aad) {
   Ok(r) => r,
   Err(e) => panic!("Error encrypting.\n{:?}", e),
};

let msg_ = match aead::decrypt(Mode::Chacha20Poly1305, &key, &ciphertext, &tag, &iv, &aad) {
    Ok(r) => r,
    Err(e) => panic!("Error decrypting.\n{:?}", e),
};

assert_eq!(&msg[..], &msg_[..]);

Structs

The Aead struct allows to re-use a key without having to initialize it every time.

Enums

The AEAD Mode.

Functions

Single-shot API for AEAD decryption.

Single-shot API for combined AEAD decryption.

Single-shot API for AEAD decryption in place.

Single-shot API for AEAD encryption.

Single-shot API for combined AEAD encryption.

Single-shot API for in place AEAD encryption.

Generate a random key.

Get the key size of the Mode in bytes.

Generate a nonce.

Get the nonce size of the Mode in bytes.

Get the tag size of the Mode in bytes.

Type Definitions

Associated data are byte arrays.

Ciphertexts are byte vectors.

Aead keys are byte vectors.

Nonces are byte vectors.

Aead tags are byte vectors.