Struct present::Block [] [src]

pub struct Block { /* fields omitted */ }

A single 64-bit block used for encryption/decryption.


impl Block

Constructs a new Block with the given state.

Constructs a new Block from the given bytes.

The initial state of the block is computed from the given byte array, with the most significant bits being at the beginning of the array.


use present::Block;
let bytes = [0x10, 0x34, 0x52, 0xD9, 0xAF, 0x55, 0x90, 0xFC];
let block = Block::from_bytes(&bytes);
assert_eq!(block.get_state(), 0x103452D9AF5590FC);Run

Returns the current state of the block as a byte array.

The returned byte array has the most significant bits of the state at the beginning.


use present::Block;
let block = Block::new(0x9F238517AB6CD820);
let bytes = block.to_bytes();
assert_eq!(bytes, [0x9F, 0x23, 0x85, 0x17, 0xAB, 0x6C, 0xD8, 0x20]);Run

Encrypts this block using the given key.

This function applies the complete encryption algorithm of PRESENT to the block, consisting of 32 rounds. See the paper for details.

Decrypts this block using the given key.

This function applies PRESENT's encryption algorithm to the block in reverse order, with inverse substitution and permutation functions.

Retrieve the current state of the block.

This returns the state as it is saved internally (u64). If you want a byte array, use Block::to_bytes() instead.

Trait Implementations

impl<'a> BitXorAssign<&'a RoundKey> for Block

Add a round key to the block (bitwise XOR with the current state).

impl<'a> BitXorAssign<&'a Block> for Block

Add another block to this block (bitwise XOR).

This is useful e.g. for initialization vectors.