anubis-wormhole 1.0.0

A post-quantum secure file transfer tool based on the Magic Wormhole protocol.
Documentation
use crate::aead_policy::{AAD, TAG_LEN, pack_nonce};
use crate::traits::Aead;
use crate::providers::aes_gcm_siv::Aes256GcmSivProvider;
use crate::error::{Result, AnubisError};

pub struct Frame;

impl Frame {
    pub fn seal(aead: &Aes256GcmSivProvider, key: &[u8;32], aad: &AAD, pt: &[u8]) -> Result<Vec<u8>> {
        let nonce = pack_nonce(aad.subchannel, aad.seq);
        let aad_buf = aad.to_bytes();
        // ciphertext includes tag appended by provider
        let ct = aead.seal(key, &nonce, &aad_buf, pt)?;
        Ok(ct)
    }
    pub fn open(aead: &Aes256GcmSivProvider, key: &[u8;32], aad: &AAD, ct: &[u8]) -> Result<Vec<u8>> {
        if ct.len() < TAG_LEN { return Err(AnubisError::DecryptFailed); }
        let nonce = pack_nonce(aad.subchannel, aad.seq);
        let aad_buf = aad.to_bytes();
        let pt = aead.open(key, &nonce, &aad_buf, ct)?;
        Ok(pt)
    }
}