Struct timing_shield::TpU8
[−]
[src]
pub struct TpU8(_);
A number type that prevents its value from being leaked to attackers through timing information.
Use this type's protect method as early as possible to prevent the value from being
used in variable-time computations.
Unlike Rust's built-in number types, rust-timing-shield number types have no overflow
checking, even in debug mode. In other words, they behave like Rust's
Wrapping types.
Additionally, all shift distances are reduced mod the bit width of the type
(e.g. some_i64 << 104 is equivalent to some_i64 << 40).
// Protect the value as early as possible to limit the risk let protected_value = TpU8::protect(some_u8); let other_protected_value = TpU8::protect(some_other_u8); // Do some computation with the protected values let x = (other_protected_value + protected_value) & 0x40; // If needed, remove protection using `expose` println!("{}", x.expose());
Methods
impl TpU8[src]
fn protect(input: u8) -> Self
Hide input behind a protective abstraction to prevent the value from being used
in such a way that the value could leak out via a timing side channel.
let protected = TpU32::protect(secret_u32); // Use `protected` instead of `secret_u32` to avoid timing leaks
fn as_u16(self) -> TpU16
Casts from one number type to another, following the same conventions as Rust's as
keyword.
fn as_u32(self) -> TpU32
Casts from one number type to another, following the same conventions as Rust's as
keyword.
fn as_u64(self) -> TpU64
Casts from one number type to another, following the same conventions as Rust's as
keyword.
fn as_i8(self) -> TpI8
Casts from one number type to another, following the same conventions as Rust's as
keyword.
fn as_i16(self) -> TpI16
Casts from one number type to another, following the same conventions as Rust's as
keyword.
fn as_i32(self) -> TpI32
Casts from one number type to another, following the same conventions as Rust's as
keyword.
fn as_i64(self) -> TpI64
Casts from one number type to another, following the same conventions as Rust's as
keyword.
fn expose(self) -> u8
Remove the timing protection and expose the raw number value. Once a value is exposed, it is the library user's responsibility to prevent timing leaks (if necessary).
Commonly, this method is used when a value is safe to make public (e.g. when an
encryption algorithm outputs a ciphertext). Alternatively, this method may need to
be used when providing a secret value to an interface that does not use
timing-shield's types (e.g. writing a secret key to a file using a file system
API).
Trait Implementations
impl Clone for TpU8[src]
fn clone(&self) -> TpU8
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)1.0.0
Performs copy-assignment from source. Read more
impl Copy for TpU8[src]
impl Not for TpU8[src]
type Output = TpU8
The resulting type after applying the ! operator
fn not(self) -> TpU8
The method for the unary ! operator
impl Add<TpU8> for TpU8[src]
type Output = TpU8
The resulting type after applying the + operator
fn add(self, other: TpU8) -> TpU8
The method for the + operator
impl Add<u8> for TpU8[src]
type Output = TpU8
The resulting type after applying the + operator
fn add(self, other: u8) -> TpU8
The method for the + operator
impl Sub<TpU8> for TpU8[src]
type Output = TpU8
The resulting type after applying the - operator
fn sub(self, other: TpU8) -> TpU8
The method for the - operator
impl Sub<u8> for TpU8[src]
type Output = TpU8
The resulting type after applying the - operator
fn sub(self, other: u8) -> TpU8
The method for the - operator
impl Mul<TpU8> for TpU8[src]
type Output = TpU8
The resulting type after applying the * operator
fn mul(self, other: TpU8) -> TpU8
The method for the * operator
impl Mul<u8> for TpU8[src]
type Output = TpU8
The resulting type after applying the * operator
fn mul(self, other: u8) -> TpU8
The method for the * operator
impl BitAnd<TpU8> for TpU8[src]
type Output = TpU8
The resulting type after applying the & operator
fn bitand(self, other: TpU8) -> TpU8
The method for the & operator
impl BitAnd<u8> for TpU8[src]
type Output = TpU8
The resulting type after applying the & operator
fn bitand(self, other: u8) -> TpU8
The method for the & operator
impl BitOr<TpU8> for TpU8[src]
type Output = TpU8
The resulting type after applying the | operator
fn bitor(self, other: TpU8) -> TpU8
The method for the | operator
impl BitOr<u8> for TpU8[src]
type Output = TpU8
The resulting type after applying the | operator
fn bitor(self, other: u8) -> TpU8
The method for the | operator
impl BitXor<TpU8> for TpU8[src]
type Output = TpU8
The resulting type after applying the ^ operator
fn bitxor(self, other: TpU8) -> TpU8
The method for the ^ operator
impl BitXor<u8> for TpU8[src]
type Output = TpU8
The resulting type after applying the ^ operator
fn bitxor(self, other: u8) -> TpU8
The method for the ^ operator
impl Shl<u32> for TpU8[src]
type Output = TpU8
The resulting type after applying the << operator
fn shl(self, other: u32) -> TpU8
The method for the << operator
impl Shr<u32> for TpU8[src]
type Output = TpU8
The resulting type after applying the >> operator
fn shr(self, other: u32) -> TpU8
The method for the >> operator
impl AddAssign<TpU8> for TpU8[src]
fn add_assign(&mut self, rhs: TpU8)
The method for the += operator
impl AddAssign<u8> for TpU8[src]
fn add_assign(&mut self, rhs: u8)
The method for the += operator
impl SubAssign<TpU8> for TpU8[src]
fn sub_assign(&mut self, rhs: TpU8)
The method for the -= operator
impl SubAssign<u8> for TpU8[src]
fn sub_assign(&mut self, rhs: u8)
The method for the -= operator
impl MulAssign<TpU8> for TpU8[src]
fn mul_assign(&mut self, rhs: TpU8)
The method for the *= operator
impl MulAssign<u8> for TpU8[src]
fn mul_assign(&mut self, rhs: u8)
The method for the *= operator
impl BitAndAssign<TpU8> for TpU8[src]
fn bitand_assign(&mut self, rhs: TpU8)
The method for the &= operator
impl BitAndAssign<u8> for TpU8[src]
fn bitand_assign(&mut self, rhs: u8)
The method for the &= operator
impl BitOrAssign<TpU8> for TpU8[src]
fn bitor_assign(&mut self, rhs: TpU8)
The method for the |= operator
impl BitOrAssign<u8> for TpU8[src]
fn bitor_assign(&mut self, rhs: u8)
The method for the |= operator
impl BitXorAssign<TpU8> for TpU8[src]
fn bitxor_assign(&mut self, rhs: TpU8)
The method for the ^= operator
impl BitXorAssign<u8> for TpU8[src]
fn bitxor_assign(&mut self, rhs: u8)
The method for the ^= operator
impl ShlAssign<u32> for TpU8[src]
fn shl_assign(&mut self, rhs: u32)
The method for the <<= operator
impl ShrAssign<u32> for TpU8[src]
fn shr_assign(&mut self, rhs: u32)
The method for the >>= operator
impl TpEq<TpU8> for TpU8[src]
fn tp_eq(&self, other: &TpU8) -> TpBool
Compare self with other for equality without leaking the result. Important: if either input is not a timing-protected type, this operation might leak the value of that type. To prevent timing leaks, protect values before performing any operations on them. Read more
fn tp_not_eq(&self, other: &TpU8) -> TpBool
Compare self with other for inequality without leaking the result. Important: if either input is not a timing-protected type, this operation might leak the value of that type. To prevent timing leaks, protect values before performing any operations on them. Read more
impl TpEq<u8> for TpU8[src]
fn tp_eq(&self, other: &u8) -> TpBool
Compare self with other for equality without leaking the result. Important: if either input is not a timing-protected type, this operation might leak the value of that type. To prevent timing leaks, protect values before performing any operations on them. Read more
fn tp_not_eq(&self, other: &u8) -> TpBool
Compare self with other for inequality without leaking the result. Important: if either input is not a timing-protected type, this operation might leak the value of that type. To prevent timing leaks, protect values before performing any operations on them. Read more
impl TpOrd<TpU8> for TpU8[src]
fn tp_lt(&self, other: &TpU8) -> TpBool
Compute self < other without leaking the result. Important: if either input is not a timing-protected type, this operation might leak the value of that type. To prevent timing leaks, protect values before performing any operations on them. Read more
fn tp_gt(&self, other: &TpU8) -> TpBool
Compute self > other without leaking the result. Important: if either input is not a timing-protected type, this operation might leak the value of that type. To prevent timing leaks, protect values before performing any operations on them. Read more
fn tp_lt_eq(&self, other: &TpU8) -> TpBool
Compute self <= other without leaking the result. Important: if either input is not a timing-protected type, this operation might leak the value of that type. To prevent timing leaks, protect values before performing any operations on them. Read more
fn tp_gt_eq(&self, other: &TpU8) -> TpBool
Compute self >= other without leaking the result. Important: if either input is not a timing-protected type, this operation might leak the value of that type. To prevent timing leaks, protect values before performing any operations on them. Read more
impl TpOrd<u8> for TpU8[src]
fn tp_lt(&self, other: &u8) -> TpBool
Compute self < other without leaking the result. Important: if either input is not a timing-protected type, this operation might leak the value of that type. To prevent timing leaks, protect values before performing any operations on them. Read more
fn tp_gt(&self, other: &u8) -> TpBool
Compute self > other without leaking the result. Important: if either input is not a timing-protected type, this operation might leak the value of that type. To prevent timing leaks, protect values before performing any operations on them. Read more
fn tp_lt_eq(&self, other: &u8) -> TpBool
Compute self <= other without leaking the result. Important: if either input is not a timing-protected type, this operation might leak the value of that type. To prevent timing leaks, protect values before performing any operations on them. Read more
fn tp_gt_eq(&self, other: &u8) -> TpBool
Compute self >= other without leaking the result. Important: if either input is not a timing-protected type, this operation might leak the value of that type. To prevent timing leaks, protect values before performing any operations on them. Read more
impl TpCondSwap for TpU8[src]
fn tp_cond_swap(condition: TpBool, a: &mut TpU8, b: &mut TpU8)
Swap a and b if and only if condition is true. Read more