Struct secret_integers::U8
source · pub struct U8(pub u8);
Tuple Fields§
§0: u8
Implementations§
source§impl U8
impl U8
sourcepub fn declassify(self) -> u8
pub fn declassify(self) -> u8
Warning: use with caution, breaks the constant-time guarantee.
sourcepub fn zero() -> Self
pub fn zero() -> Self
Examples found in repository?
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
fn chacha20_counter_mode(key: &Key, counter: U32, nonce: &Nonce, msg: &Vec<U8>) -> Vec<U8> {
let mut blocks: Vec<[U8; BLOCK_SIZE]> = msg
.chunks(BLOCK_SIZE)
.map(|block| {
let mut new_block = [U8::zero(); BLOCK_SIZE];
new_block[0..block.len()].copy_from_slice(block);
new_block
})
.collect();
let nb_blocks = blocks.len();
let mut key_block: [U8; BLOCK_SIZE];
let mut ctr = counter;
for i in 0..blocks.len() - 1 {
key_block = chacha20_block(key, ctr, nonce);
blocks[i] = xor_block(&blocks[i], &key_block);
ctr += U32::one();
}
let last = &mut blocks[nb_blocks - 1];
key_block = chacha20_block(key, ctr, nonce);
*last = xor_block(last, &key_block);
blocks
.iter()
.map(|block| block.to_vec())
.flatten()
.take(msg.len())
.collect()
}
pub fn one() -> Self
pub fn ones() -> Self
pub fn from_le_bytes(bytes: &[U8]) -> Vec<U8>
pub fn to_le_bytes(ints: &[U8]) -> Vec<U8>
pub fn from_be_bytes(bytes: &[U8]) -> Vec<U8>
pub fn to_be_bytes(ints: &[U8]) -> Vec<U8>
pub fn max_value() -> U8
source§impl U8
impl U8
sourcepub fn checked_add(self, rhs: Self) -> Self
pub fn checked_add(self, rhs: Self) -> Self
Warning: panics when overflow.
source§impl U8
impl U8
sourcepub fn checked_sub(self, rhs: Self) -> Self
pub fn checked_sub(self, rhs: Self) -> Self
Warning: panics when overflow.
source§impl U8
impl U8
sourcepub fn checked_mul(self, rhs: Self) -> Self
pub fn checked_mul(self, rhs: Self) -> Self
Warning: panics when overflow.
source§impl U8
impl U8
pub fn rotate_left(self, rotval: usize) -> Self
pub fn rotate_right(self, rotval: usize) -> Self
source§impl U8
impl U8
sourcepub fn comp_eq(self, rhs: Self) -> Self
pub fn comp_eq(self, rhs: Self) -> Self
Produces a new integer which is all ones if the two arguments are equal and all zeroes otherwise. With inspiration from Wireguard.
sourcepub fn comp_ne(self, rhs: Self) -> Self
pub fn comp_ne(self, rhs: Self) -> Self
Produces a new integer which is all ones if the first argument is different from the second argument, and all zeroes otherwise.
sourcepub fn comp_gte(self, rhs: Self) -> Self
pub fn comp_gte(self, rhs: Self) -> Self
Produces a new integer which is all ones if the first argument is greater than or equal to the second argument, and all zeroes otherwise. With inspiration from WireGuard.
sourcepub fn comp_gt(self, rhs: Self) -> Self
pub fn comp_gt(self, rhs: Self) -> Self
Produces a new integer which is all ones if the first argument is strictly greater than the second argument, and all zeroes otherwise.
Trait Implementations§
source§impl AddAssign<U8> for U8
impl AddAssign<U8> for U8
Warning: has wrapping semantics.
source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+=
operation. Read moresource§impl BitAndAssign<U8> for U8
impl BitAndAssign<U8> for U8
source§fn bitand_assign(&mut self, rhs: Self)
fn bitand_assign(&mut self, rhs: Self)
&=
operation. Read moresource§impl BitOrAssign<U8> for U8
impl BitOrAssign<U8> for U8
source§fn bitor_assign(&mut self, rhs: Self)
fn bitor_assign(&mut self, rhs: Self)
|=
operation. Read moresource§impl BitXorAssign<U8> for U8
impl BitXorAssign<U8> for U8
source§fn bitxor_assign(&mut self, rhs: Self)
fn bitxor_assign(&mut self, rhs: Self)
^=
operation. Read moresource§impl MulAssign<U8> for U8
impl MulAssign<U8> for U8
Warning: has wrapping semantics.
source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*=
operation. Read moresource§impl ShlAssign<usize> for U8
impl ShlAssign<usize> for U8
source§fn shl_assign(&mut self, rhs: usize)
fn shl_assign(&mut self, rhs: usize)
<<=
operation. Read moresource§impl ShrAssign<usize> for U8
impl ShrAssign<usize> for U8
source§fn shr_assign(&mut self, rhs: usize)
fn shr_assign(&mut self, rhs: usize)
>>=
operation. Read moresource§impl SubAssign<U8> for U8
impl SubAssign<U8> for U8
Warning: has wrapping semantics.
source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-=
operation. Read more