use crate::utils::*;
use botan_sys::*;
use crate::mp::MPI;
#[derive(Debug)]
#[allow(clippy::upper_case_acronyms)]
pub struct FPE {
obj: botan_fpe_t,
}
unsafe impl Sync for FPE {}
unsafe impl Send for FPE {}
botan_impl_drop!(FPE, botan_fpe_destroy);
impl FPE {
pub fn new_fe1(modulus: &MPI, key: &[u8], rounds: usize, compat_mode: bool) -> Result<FPE> {
let flags = u32::from(compat_mode);
let obj = botan_init!(
botan_fpe_fe1_init,
modulus.handle(),
key.as_ptr(),
key.len(),
rounds,
flags
)?;
Ok(FPE { obj })
}
pub fn encrypt(&self, x: &MPI, tweak: &[u8]) -> Result<MPI> {
let r = x.duplicate()?;
botan_call!(
botan_fpe_encrypt,
self.obj,
r.handle(),
tweak.as_ptr(),
tweak.len()
)?;
Ok(r)
}
pub fn decrypt(&self, x: &MPI, tweak: &[u8]) -> Result<MPI> {
let r = x.duplicate()?;
botan_call!(
botan_fpe_decrypt,
self.obj,
r.handle(),
tweak.as_ptr(),
tweak.len()
)?;
Ok(r)
}
}