//! Module rc6 implements the Rc6 stream cipher algorithm.
#[cfg(test)]
mod tests;

mod imp;
use crate::{
    aead::ocb3::Ocb3Marker,
    block::{BlockCipher, BlockCipherMarker},
    error::CryptoResult,
};
use imp::*;

pub struct Rc6 {
    skey: Rc6Key,
}

impl BlockCipherMarker for Rc6 {}
impl Ocb3Marker for Rc6 {}

impl Rc6 {
    pub fn new(key: &[u8]) -> CryptoResult<Self> {
        let mut skey: Rc6Key = Rc6Key { key: [0; 44] };

        rc6_setup(key, key.len(), &mut skey)?;

        Ok(Self { skey })
    }
}

impl BlockCipher for Rc6 {
    fn block_size(&self) -> usize {
        16
    }

    fn encrypt_block(&self, inout: &mut [u8]) {
        let ret = rc6_ecb_encrypt(inout, &self.skey);
        assert!(ret.is_ok());
    }

    fn decrypt_block(&self, inout: &mut [u8]) {
        let ret = rc6_ecb_decrypt(inout, &self.skey);
        assert!(ret.is_ok());
    }
}
