Skip to main content

AES

Struct AES 

Source
pub struct AES { /* private fields */ }
Expand description

Main AES structure.

Usage:

extern crate dumb_crypto;

use::dumb_crypto::aes::{AES, BLOCK_SIZE};

let mut aes = AES::new();
let key: [u8; 16] = [
    0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
    0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c,
];
aes.init(&key).unwrap();

let cleartext: [u8; BLOCK_SIZE] = [
    0x32, 0x43, 0xf6, 0xa8, 0x88, 0x5a, 0x30, 0x8d,
    0x31, 0x31, 0x98, 0xa2, 0xe0, 0x37, 0x07, 0x34,
];

let ciphertext = aes.encrypt(&cleartext).unwrap();

assert_eq!(aes.decrypt(&ciphertext).unwrap(), cleartext);

Implementations§

Source§

impl AES

Source

pub fn new() -> Self

Create new uninitialized instance of AES.

Source

pub fn init(&mut self, key: &[u8]) -> Result<(), AESError>

Initialize an instance with a encryption/decryption key.

Source

pub fn encrypt(&self, b: &[u8; 16]) -> Result<[u8; 16], AESError>

Encrypt block of data.

Source

pub fn decrypt(&self, b: &[u8; 16]) -> Result<[u8; 16], AESError>

Decrypt block of data.

Trait Implementations§

Source§

impl Default for AES

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for AES

§

impl RefUnwindSafe for AES

§

impl Send for AES

§

impl Sync for AES

§

impl Unpin for AES

§

impl UnsafeUnpin for AES

§

impl UnwindSafe for AES

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.