feat: v0.1.0

This commit is contained in:
2023-09-04 00:10:23 +08:00
parent 147f29a9dd
commit e7c311eacb
8 changed files with 230 additions and 17 deletions

View File

@@ -1,5 +1,8 @@
use std::error::Error;
use sm4::cipher::BlockSizeUser;
use sm4::cipher::consts::U16;
use zeroize::Zeroize;
pub(crate) struct Sm4Block {}
@@ -9,6 +12,20 @@ impl BlockSizeUser for Sm4Block {
pub(crate) const BLOCK_SIZE: usize = 16;
pub struct Sm4Key(pub [u8; 16]);
impl Sm4Key {
pub fn from_slice(key: &[u8]) -> Result<Self, Box<dyn Error>> {
Ok(Self(key.try_into()?))
}
}
impl Drop for Sm4Key {
fn drop(&mut self) {
self.0.zeroize();
}
}
// R = 11100001 || 0(120)
const R: u128 = 0b11100001 << 120;