#aead #io #encryption #decryption #cryptography

no-std aead-io

A wrapper around Write/Read interfaces with AEAD

6 releases

0.2.0 Sep 15, 2022
0.1.4 May 9, 2022
0.1.2 Jan 24, 2022
0.1.1 Oct 31, 2021

#311 in Cryptography

Download history 187/week @ 2022-06-05 158/week @ 2022-06-12 189/week @ 2022-06-19 133/week @ 2022-06-26 147/week @ 2022-07-03 196/week @ 2022-07-10 116/week @ 2022-07-17 174/week @ 2022-07-24 56/week @ 2022-07-31 109/week @ 2022-08-07 47/week @ 2022-08-14 101/week @ 2022-08-21 129/week @ 2022-08-28 100/week @ 2022-09-04 92/week @ 2022-09-11 118/week @ 2022-09-18

455 downloads per month

MIT/Apache

38KB
938 lines

aead-io

Provides a wrapper around a Write/Read object and a StreamPrimitive to provide an easy interface for doing correct encryption.

let key = b"my very super super secret key!!".into();
let plaintext = b"hello world!";

let ciphertext = {
    let mut ciphertext = Vec::default();
    let mut writer = EncryptBE32BufWriter::<ChaCha20Poly1305, _, _>::new(
        key,
        &Default::default(), // please use a better nonce ;)
        Vec::with_capacity(128),
        &mut ciphertext,
    )
    .unwrap();
    writer.write_all(plaintext)?;
    writer.flush()?;
    ciphertext
};

let decrypted = {
    let mut reader = DecryptBE32BufReader::<ChaCha20Poly1305, _, _>::new(
        key,
        Vec::with_capacity(256),
        ciphertext.as_slice(),
    )
    .unwrap();
    let mut out = Vec::new();
    let _ = reader.read_to_end(&mut out).unwrap();
    out
};

assert_eq!(decrypted, plaintext);
#

no_std

This package is compatible with no_std environments. Just disable the default features, and implement the Buffer, CappedBuffer, ResizeBuffer, Write and Read accordingly. There should be some default implementations for Vec<u8> and byte slices

License: MIT OR Apache-2.0

Dependencies

~285KB