Struct Block

Source
pub struct Block(/* private fields */);
Expand description

A 128-bit block. Uses SIMD operations where available.

Implementations§

Source§

impl Block

Source

pub fn clmul(&self, rhs: &Self) -> (Self, Self)

Carryless multiplication of two Blocks as polynomials over GF(2).

Returns (low, high) bits.

Source

pub fn gf_mul(&self, rhs: &Self) -> Self

Multiplication over GF(2^128).

Uses the irreducible polynomial `x^128 + x^7 + x^2 + x + 1.

Source

pub fn gf_reduce(low: &Self, high: &Self) -> Self

Reduce polynomial over GF(2) by x^128 + x^7 + x^2 + x + 1.

Source

pub fn gf_pow(&self, exp: u64) -> Block

Source§

impl Block

Source

pub const ZERO: Self

All bits set to 0.

Source

pub const ONES: Self

All bits set to 1.

Source

pub const ONE: Self

Lsb set to 1, all others zero.

Source

pub const MASK_LSB: Self

Mask to mask off the LSB of a Block.

let b = Block::ONES;
let masked = b & Block::MASK_LSB;
assert_eq!(masked, Block::ONES << 1)
Source

pub const BYTES: usize = 16usize

16 bytes in a Block.

Source

pub const BITS: usize = 128usize

128 bits in a block.

Source

pub const fn new(bytes: [u8; 16]) -> Self

Create a new block from bytes.

Source

pub const fn splat(byte: u8) -> Self

Create a block with all bytes set to byte.

Source

pub const fn pack(low: u64, high: u64) -> Self

Pack two u64 into a Block. Usable in const context.

In non-const contexts, using Block::from([low, high]) is likely faster.

Source

pub fn as_bytes(&self) -> &[u8; 16]

Bytes of the block.

Source

pub fn as_mut_bytes(&mut self) -> &mut [u8; 16]

Mutable bytes of the block.

Source

pub fn ro_hash(&self) -> Hash

Hash the block with a random_oracle.

Source

pub fn from_choices(choices: &[Choice]) -> Self

Create a block from 128 Choices.

§Panics

If choices.len() != 128

Source

pub fn low(&self) -> u64

Low 64 bits of the block.

Source

pub fn high(&self) -> u64

High 64 bits of the block.

Source

pub fn lsb(&self) -> bool

Least significant bit of the block

Source

pub fn bits(&self) -> impl Iterator<Item = bool>

Iterator over bits of the Block.

Trait Implementations§

Source§

impl Add for Block

Source§

type Output = Block

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl AsMut<[u8]> for Block

Source§

fn as_mut(&mut self) -> &mut [u8]

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl AsRef<[u8]> for Block

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Binary for Block

Source§

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

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

impl BitAnd for Block

Source§

type Output = Block

The resulting type after applying the & operator.
Source§

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

Performs the & operation. Read more
Source§

impl BitAndAssign for Block

Source§

fn bitand_assign(&mut self, rhs: Self)

Performs the &= operation. Read more
Source§

impl BitOr for Block

Source§

type Output = Block

The resulting type after applying the | operator.
Source§

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

Performs the | operation. Read more
Source§

impl BitOrAssign for Block

Source§

fn bitor_assign(&mut self, rhs: Self)

Performs the |= operation. Read more
Source§

impl BitXor for Block

Source§

type Output = Block

The resulting type after applying the ^ operator.
Source§

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

Performs the ^ operation. Read more
Source§

impl BitXorAssign for Block

Source§

fn bitxor_assign(&mut self, rhs: Self)

Performs the ^= operation. Read more
Source§

impl Clone for Block

Source§

fn clone(&self) -> Block

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 ConditionallySelectable for Block

Source§

fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self

Select a or b according to choice. Read more
Source§

fn conditional_assign(&mut self, other: &Self, choice: Choice)

Conditionally assign other to self, according to choice. Read more
Source§

fn conditional_swap(a: &mut Self, b: &mut Self, choice: Choice)

Conditionally swap self and other if choice == 1; otherwise, reassign both unto themselves. Read more
Source§

impl Debug for Block

Source§

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

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

impl Default for Block

Source§

fn default() -> Block

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

impl<'de> Deserialize<'de> for Block

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Distribution<Block> for StandardUniform

Source§

fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Block

Generate a random value of T, using rng as the source of randomness.
Source§

fn sample_iter<R>(self, rng: R) -> Iter<Self, R, T>
where R: Rng, Self: Sized,

Create an iterator that generates random values of T, using rng as the source of randomness. Read more
Source§

fn map<F, S>(self, func: F) -> Map<Self, F, T, S>
where F: Fn(T) -> S, Self: Sized,

Map sampled values to type S Read more
Source§

impl From<&Block> for __m128i

Source§

fn from(value: &Block) -> Self

Converts to this type from the input type.
Source§

impl From<&Block> for u128

Source§

fn from(value: &Block) -> Self

Converts to this type from the input type.
Source§

impl From<&__m128i> for Block

Source§

fn from(value: &__m128i) -> Self

Converts to this type from the input type.
Source§

impl From<&u128> for Block

Source§

fn from(value: &u128) -> Self

Converts to this type from the input type.
Source§

impl From<[u64; 2]> for Block

Source§

fn from(value: [u64; 2]) -> Self

Converts to this type from the input type.
Source§

impl From<Array<u8, UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>>> for Block

Source§

fn from(value: Array<u8, U16>) -> Self

Converts to this type from the input type.
Source§

impl From<Block> for [u64; 2]

Source§

fn from(value: Block) -> Self

Converts to this type from the input type.
Source§

impl From<Block> for Array<u8, U16>

Source§

fn from(value: Block) -> Self

Converts to this type from the input type.
Source§

impl From<Block> for __m128i

Source§

fn from(value: Block) -> Self

Converts to this type from the input type.
Source§

impl From<Block> for u128

Source§

fn from(value: Block) -> Self

Converts to this type from the input type.
Source§

impl From<__m128i> for Block

Source§

fn from(value: __m128i) -> Self

Converts to this type from the input type.
Source§

impl From<u128> for Block

Source§

fn from(value: u128) -> Self

Converts to this type from the input type.
Source§

impl From<usize> for Block

Source§

fn from(value: usize) -> Self

Converts to this type from the input type.
Source§

impl Not for Block

Source§

type Output = Block

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self

Performs the unary ! operation. Read more
Source§

impl PartialEq for Block

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Block

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<Rhs> Shl<Rhs> for Block
where u128: Shl<Rhs, Output = u128>,

Source§

type Output = Block

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

fn shl(self, rhs: Rhs) -> Self::Output

Performs the << operation. Read more
Source§

impl<Rhs> Shr<Rhs> for Block
where u128: Shr<Rhs, Output = u128>,

Source§

type Output = Block

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

fn shr(self, rhs: Rhs) -> Self::Output

Performs the >> operation. Read more
Source§

impl TryFrom<&[u8]> for Block

Source§

type Error = WrongLength

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

fn try_from(value: &[u8]) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Zero for Block

Source§

fn zero() -> Self

Returns the additive identity element of Self, 0. Read more
Source§

fn is_zero(&self) -> bool

Returns true if self is equal to the additive identity.
Source§

fn set_zero(&mut self)

Sets self to the additive identity element of Self, 0.
Source§

impl Zeroable for Block

Source§

fn zeroed() -> Self

Source§

impl Copy for Block

Source§

impl Eq for Block

Source§

impl Pod for Block

Auto Trait Implementations§

§

impl Freeze for Block

§

impl RefUnwindSafe for Block

§

impl Send for Block

§

impl Sync for Block

§

impl Unpin for Block

§

impl UnwindSafe for Block

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> CheckedBitPattern for T
where T: AnyBitPattern,

Source§

type Bits = T

Self must have the same layout as the specified Bits except for the possible invalid bit patterns being checked during is_valid_bit_pattern.
Source§

fn is_valid_bit_pattern(_bits: &T) -> bool

If this function returns true, then it must be valid to reinterpret bits as &Self.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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, 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> AnyBitPattern for T
where T: Pod,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> NoUninit for T
where T: Pod,