Struct secret_integers::U8

source ·
pub struct U8(pub u8);

Tuple Fields§

§0: u8

Implementations§

source§

impl U8

source

pub fn classify<T: Into<u8>>(x: T) -> Self

Examples found in repository?
examples/chacha20.rs (line 70)
68
69
70
71
72
73
fn chacha20_block(k: &Key, counter: U32, nonce: &Nonce) -> Block {
    let st = chacha20(k, counter, nonce);
    let mut block = [U8::classify(0u8); BLOCK_SIZE];
    block.copy_from_slice(U32::to_le_bytes(&st).as_slice());
    block
}
source

pub fn declassify(self) -> u8

Warning: use with caution, breaks the constant-time guarantee.

source

pub fn zero() -> Self

Examples found in repository?
examples/chacha20.rs (line 89)
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()
}
source

pub fn one() -> Self

source

pub fn ones() -> Self

source

pub fn from_le_bytes(bytes: &[U8]) -> Vec<U8>

source

pub fn to_le_bytes(ints: &[U8]) -> Vec<U8>

source

pub fn from_be_bytes(bytes: &[U8]) -> Vec<U8>

source

pub fn to_be_bytes(ints: &[U8]) -> Vec<U8>

source

pub fn max_value() -> U8

source§

impl U8

source

pub fn checked_add(self, rhs: Self) -> Self

Warning: panics when overflow.

source§

impl U8

source

pub fn checked_sub(self, rhs: Self) -> Self

Warning: panics when overflow.

source§

impl U8

source

pub fn checked_mul(self, rhs: Self) -> Self

Warning: panics when overflow.

source§

impl U8

source

pub fn rotate_left(self, rotval: usize) -> Self

source

pub fn rotate_right(self, rotval: usize) -> Self

source§

impl U8

source

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.

source

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.

source

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.

source

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.

source

pub fn comp_lte(self, rhs: Self) -> Self

Produces a new integer which is all ones if the first argument is less than or equal to the second argument, and all zeroes otherwise.

source

pub fn comp_lt(self, rhs: Self) -> Self

Produces a new integer which is all ones if the first argument is strictly less than the second argument, and all zeroes otherwise.

Trait Implementations§

source§

impl Add<U8> for U8

Warning: has wrapping semantics.

§

type Output = U8

The resulting type after applying the + operator.
source§

fn add(self, rhs: Self) -> Self

Performs the + operation. Read more
source§

impl AddAssign<U8> for U8

Warning: has wrapping semantics.

source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
source§

impl BitAnd<U8> for U8

§

type Output = U8

The resulting type after applying the & operator.
source§

fn bitand(self, rhs: Self) -> Self

Performs the & operation. Read more
source§

impl BitAndAssign<U8> for U8

source§

fn bitand_assign(&mut self, rhs: Self)

Performs the &= operation. Read more
source§

impl BitOr<U8> for U8

§

type Output = U8

The resulting type after applying the | operator.
source§

fn bitor(self, rhs: Self) -> Self

Performs the | operation. Read more
source§

impl BitOrAssign<U8> for U8

source§

fn bitor_assign(&mut self, rhs: Self)

Performs the |= operation. Read more
source§

impl BitXor<U8> for U8

§

type Output = U8

The resulting type after applying the ^ operator.
source§

fn bitxor(self, rhs: Self) -> Self

Performs the ^ operation. Read more
source§

impl BitXorAssign<U8> for U8

source§

fn bitxor_assign(&mut self, rhs: Self)

Performs the ^= operation. Read more
source§

impl Clone for U8

source§

fn clone(&self) -> U8

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for U8

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for U8

source§

fn default() -> U8

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

impl Display for U8

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<I8> for U8

source§

fn from(x: I8) -> U8

Converts to this type from the input type.
source§

impl From<U128> for U8

Warning: wrapping semantics.

source§

fn from(x: U128) -> U8

Converts to this type from the input type.
source§

impl From<U16> for U8

Warning: wrapping semantics.

source§

fn from(x: U16) -> U8

Converts to this type from the input type.
source§

impl From<U32> for U8

Warning: wrapping semantics.

source§

fn from(x: U32) -> U8

Converts to this type from the input type.
source§

impl From<U64> for U8

Warning: wrapping semantics.

source§

fn from(x: U64) -> U8

Converts to this type from the input type.
source§

impl From<U8> for I8

Warning: wrapping semantics.

source§

fn from(x: U8) -> I8

Converts to this type from the input type.
source§

impl From<U8> for U128

source§

fn from(x: U8) -> U128

Converts to this type from the input type.
source§

impl From<U8> for U16

source§

fn from(x: U8) -> U16

Converts to this type from the input type.
source§

impl From<U8> for U32

source§

fn from(x: U8) -> U32

Converts to this type from the input type.
source§

impl From<U8> for U64

source§

fn from(x: U8) -> U64

Converts to this type from the input type.
source§

impl From<U8> for u128

Warning: conversion can be lossy!

source§

fn from(x: U8) -> u128

Converts to this type from the input type.
source§

impl From<U8> for u16

Warning: conversion can be lossy!

source§

fn from(x: U8) -> u16

Converts to this type from the input type.
source§

impl From<U8> for u32

Warning: conversion can be lossy!

source§

fn from(x: U8) -> u32

Converts to this type from the input type.
source§

impl From<U8> for u64

Warning: conversion can be lossy!

source§

fn from(x: U8) -> u64

Converts to this type from the input type.
source§

impl From<U8> for u8

Warning: conversion can be lossy!

source§

fn from(x: U8) -> u8

Converts to this type from the input type.
source§

impl From<U8> for usize

Warning: conversion can be lossy!

source§

fn from(x: U8) -> usize

Converts to this type from the input type.
source§

impl From<u8> for U8

source§

fn from(x: u8) -> Self

Converts to this type from the input type.
source§

impl From<usize> for U8

source§

fn from(x: usize) -> U8

Converts to this type from the input type.
source§

impl LowerHex for U8

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter.
source§

impl Mul<U8> for U8

Warning: has wrapping semantics.

§

type Output = U8

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Self) -> Self

Performs the * operation. Read more
source§

impl MulAssign<U8> for U8

Warning: has wrapping semantics.

source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
source§

impl Neg for U8

§

type Output = U8

The resulting type after applying the - operator.
source§

fn neg(self) -> Self

Performs the unary - operation. Read more
source§

impl Not for U8

§

type Output = U8

The resulting type after applying the ! operator.
source§

fn not(self) -> Self

Performs the unary ! operation. Read more
source§

impl Shl<usize> for U8

§

type Output = U8

The resulting type after applying the << operator.
source§

fn shl(self, rhs: usize) -> Self

Performs the << operation. Read more
source§

impl ShlAssign<usize> for U8

source§

fn shl_assign(&mut self, rhs: usize)

Performs the <<= operation. Read more
source§

impl Shr<usize> for U8

§

type Output = U8

The resulting type after applying the >> operator.
source§

fn shr(self, rhs: usize) -> Self

Performs the >> operation. Read more
source§

impl ShrAssign<usize> for U8

source§

fn shr_assign(&mut self, rhs: usize)

Performs the >>= operation. Read more
source§

impl Sub<U8> for U8

Warning: has wrapping semantics.

§

type Output = U8

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Self) -> Self

Performs the - operation. Read more
source§

impl SubAssign<U8> for U8

Warning: has wrapping semantics.

source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
source§

impl Copy for U8

Auto Trait Implementations§

§

impl RefUnwindSafe for U8

§

impl Send for U8

§

impl Sync for U8

§

impl Unpin for U8

§

impl UnwindSafe for U8

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.