hacspec_lib

Module prelude

Source
Expand description

This module conveniently exports common subroutines necessary for hacspecs

Re-exports§

pub use num;
pub use crate::array::*;
pub use crate::buf::*;
pub use crate::math_integers::*;
pub use crate::seq::*;
pub use crate::*;

Modules§

abstract_int
ct_util
fmt
Utilities for formatting and printing strings.
nat_mod
poly
vec
A contiguous growable array type with heap-allocated contents, written Vec<T>.

Macros§

abstract_int
abstract_nat_mod
abstract_public
abstract_public_modular_integer
abstract_public_nat_mod
abstract_secret
abstract_secret_modular_integer
abstract_signed
abstract_signed_public_integer
abstract_signed_secret_integer
abstract_unsigned
abstract_unsigned_public_integer
abstract_unsigned_secret_integer
define_abstract_integer_checked
Defines a bounded natural integer with regular arithmetic operations, checked for overflow and underflow.
define_refined_modular_integer
Defines a bounded natural integer with modular arithmetic operations
format
Creates a String using interpolation of runtime expressions.
modular_integer
vec
Creates a Vec containing the arguments.

Structs§

BigInt
A big signed integer type.
BigUint
A big unsigned integer type.
I8
I16
I32
I64
I128
ParseIntError
An error which can be returned when parsing an integer.
Range
A (half-open) range bounded inclusively below and exclusively above (start..end).
RangeFrom
A range only bounded inclusively below (start..).
RangeFull
An unbounded range (..).
RangeInclusive
A range bounded inclusively below and above (start..=end).
RangeTo
A range only bounded exclusively above (..end).
RangeToInclusive
A range only bounded inclusively above (..=end).
String
A UTF-8–encoded, growable string.
U8
U16
U32
U64
U16Word
Fixed length byte array.
U32Word
Fixed length byte array.
U64Word
Fixed length byte array.
U128
U128Word
Fixed length byte array.
Vec
A contiguous growable array type, written as Vec<T>, short for ‘vector’.
u16Word
Fixed length byte array.
u32Word
Fixed length byte array.
u64Word
Fixed length byte array.
u128Word
Fixed length byte array.
YeetExperimental
Implement FromResidual<Yeet<T>> on your type to enable do yeet expr syntax in functions returning your type.

Enums§

Bound
An endpoint of a range of keys.
ControlFlow
Used to tell an operation whether it should exit early or go on as usual.
Ordering
An Ordering is the result of a comparison between two values.
Sign
A Sign is a BigInt’s composing element.
CoroutineStateExperimental
The result of a coroutine resumption.

Traits§

Add
The addition operator +.
AddAssign
The addition assignment operator +=.
AsyncFn
An async-aware version of the Fn trait.
AsyncFnMut
An async-aware version of the FnMut trait.
AsyncFnOnce
An async-aware version of the FnOnce trait.
BitAnd
The bitwise AND operator &.
BitAndAssign
The bitwise AND assignment operator &=.
BitOr
The bitwise OR operator |.
BitOrAssign
The bitwise OR assignment operator |=.
BitXor
The bitwise XOR operator ^.
BitXorAssign
The bitwise XOR assignment operator ^=.
CheckedSub
Performs subtraction that returns None instead of wrapping around on underflow.
ConstOne
Defines an associated constant representing the multiplicative identity element for Self.
ConstZero
Defines an associated constant representing the additive identity element for Self.
Debug
? formatting.
Deref
Used for immutable dereferencing operations, like *v.
DerefMut
Used for mutable dereferencing operations, like in *v = 1;.
Display
Format trait for an empty format, {}.
Div
The division operator /.
DivAssign
The division assignment operator /=.
Drop
Custom code within the destructor.
Fn
The version of the call operator that takes an immutable receiver.
FnMut
The version of the call operator that takes a mutable receiver.
FnOnce
The version of the call operator that takes a by-value receiver.
FromStr
Parse a value from a string
Index
Used for indexing operations (container[index]) in immutable contexts.
IndexMut
Used for indexing operations (container[index]) in mutable contexts.
Integer
This trait extends the Numeric trait and is implemented by all integer types. It offers bit manipulation, instantiation from literal, and convenient constants.
ModNumeric
Mul
The multiplication operator *.
MulAssign
The multiplication assignment operator *=.
Neg
The unary negation operator -.
Not
The unary logical negation operator !.
Num
The base trait for numeric types, covering 0 and 1 values, comparisons, basic numeric operations, and string conversion.
Numeric
The Numeric trait has to be implemented by all numeric objects.
NumericCopy
One
Defines a multiplicative identity element for Self.
PartialEq
Trait for comparisons using the equality operator.
PublicInteger
PublicIntegerCopy
RangeBounds
RangeBounds is implemented by Rust’s built-in range types, produced by range syntax like .., a.., ..b, ..=c, d..e, or f..=g.
Rem
The remainder operator %.
RemAssign
The remainder assignment operator %=.
SecretInteger
SecretIntegerCopy
SeqTrait
Common trait for all byte arrays and sequences.
Shl
The left shift operator <<. Note that because this trait is implemented for all integer types with multiple right-hand-side types, Rust’s type checker has special handling for _ << _, setting the result type for integer operations to the type of the left-hand-side operand. This means that though a << b and a.shl(b) are one and the same from an evaluation standpoint, they are different when it comes to type inference.
ShlAssign
The left shift assignment operator <<=.
Shr
The right shift operator >>. Note that because this trait is implemented for all integer types with multiple right-hand-side types, Rust’s type checker has special handling for _ >> _, setting the result type for integer operations to the type of the left-hand-side operand. This means that though a >> b and a.shr(b) are one and the same from an evaluation standpoint, they are different when it comes to type inference.
ShrAssign
The right shift assignment operator >>=.
Signed
Useful functions for signed numbers (i.e. numbers that can be negative).
SignedInteger
SignedIntegerCopy
Sub
The subtraction operator -.
SubAssign
The subtraction assignment operator -=.
ToString
A trait for converting a value to a String.
TryFrom
Simple and safe type conversions that may fail in a controlled way under some circumstances. It is the reciprocal of TryInto.
UnsignedInteger
UnsignedIntegerCopy
UnsignedPublicInteger
UnsignedPublicIntegerCopy
UnsignedSecretInteger
UnsignedSecretIntegerCopy
Zero
Defines an additive identity element for Self.
CoerceUnsizedExperimental
Trait that indicates that this is a pointer or a wrapper for one, where unsizing can be performed on the pointee.
CoroutineExperimental
The trait implemented by builtin coroutine types.
DerefPureExperimental
Perma-unstable marker trait. Indicates that the type has a well-behaved Deref (and, if applicable, DerefMut) implementation. This is relied on for soundness of deref patterns.
DispatchFromDynExperimental
DispatchFromDyn is used in the implementation of dyn-compatibility checks (specifically allowing arbitrary self types), to guarantee that a method’s receiver type can be dispatched on.
FromResidualExperimental
Used to specify which residuals can be converted into which crate::ops::Try types.
OneSidedRangeExperimental
OneSidedRange is implemented for built-in range types that are unbounded on one side. For example, a.., ..b and ..=c implement OneSidedRange, but .., d..e, and f..=g do not.
ReceiverExperimental
Indicates that a struct can be used as a method receiver. That is, a type can use this type as a type of self, like this:
ResidualExperimental
Allows retrieving the canonical type implementing Try that has this type as its residual and allows it to hold an O as its output.
TryExperimental
The ? operator and try {} blocks.

Functions§

I8_from_I16
Warning: wrapping semantics.
I8_from_I32
Warning: wrapping semantics.
I8_from_I64
Warning: wrapping semantics.
I8_from_I128
Warning: wrapping semantics.
I16_from_I8
I16_from_I32
Warning: wrapping semantics.
I16_from_I64
Warning: wrapping semantics.
I16_from_I128
Warning: wrapping semantics.
I32_from_I8
I32_from_I16
I32_from_I64
Warning: wrapping semantics.
I32_from_I128
Warning: wrapping semantics.
I64_from_I8
I64_from_I16
I64_from_I32
I64_from_I128
Warning: wrapping semantics.
I128_from_I8
I128_from_I16
I128_from_I32
I128_from_I64
U8_from_U16
Warning: wrapping semantics.
U8_from_U32
Warning: wrapping semantics.
U8_from_U64
Warning: wrapping semantics.
U8_from_U128
Warning: wrapping semantics.
U8_from_usize
U16_from_U8
U16_from_U32
Warning: wrapping semantics.
U16_from_U64
Warning: wrapping semantics.
U16_from_U128
Warning: wrapping semantics.
U16_from_be_bytes
U16_from_le_bytes
U16_to_be_bytes
U16_to_le_bytes
U32_from_U8
U32_from_U16
U32_from_U64
Warning: wrapping semantics.
U32_from_U128
Warning: wrapping semantics.
U32_from_be_bytes
U32_from_le_bytes
U32_to_be_bytes
U32_to_le_bytes
U64_from_U8
U64_from_U16
U64_from_U32
U64_from_U128
Warning: wrapping semantics.
U64_from_be_bytes
U64_from_le_bytes
U64_from_usize
U64_to_be_bytes
U64_to_le_bytes
U128_from_U8
U128_from_U16
U128_from_U32
U128_from_U64
U128_from_be_bytes
U128_from_le_bytes
U128_from_usize
U128_to_be_bytes
U128_to_le_bytes
add_poly
Polynomial Addition, calculates a + b mod modulo
cadd
Add two numerics if condition c is set (all bits 1). Returns x if condition c is 0. Note: Addition is always wrapping.
cmul
Multiply two numerics if condition c is set (all bits 1). Returns x if condition c is 0. Note: Multiplication is always wrapping.
cset_bit
Set bit at position i in x to b if c is all 1 and return the restult. Returns x if c is 0.
csub
Subtract two numerics if condition c is set (all bits 1). Returns x if condition c is 0. Note: Addition is always wrapping.
cswap
Conditional, constant-time swapping. Returns (x, y) if c == 0 and (y, x) if c == T::max. The return value is undefined if c has any other value.
cswap_bit
Conditional, constant-time swapping. Returns (x, y) if c == 0 and (y, x) if c == 1.
ct_div
Constant time division for Numerics. Note that this function is only constant time if T is a secret integer and hence provides constant time implementations for the used functions.
declassify_u8_from_U8
Warning: conversion can be lossy!
declassify_u16_from_U8
Warning: conversion can be lossy!
declassify_u16_from_U16
Warning: conversion can be lossy!
declassify_u32_from_U8
Warning: conversion can be lossy!
declassify_u32_from_U16
Warning: conversion can be lossy!
declassify_u32_from_U32
Warning: conversion can be lossy!
declassify_u64_from_U8
Warning: conversion can be lossy!
declassify_u64_from_U16
Warning: conversion can be lossy!
declassify_u64_from_U32
Warning: conversion can be lossy!
declassify_u64_from_U64
Warning: conversion can be lossy!
declassify_u128_from_U8
Warning: conversion can be lossy!
declassify_u128_from_U32
Warning: conversion can be lossy!
declassify_u128_from_U64
Warning: conversion can be lossy!
declassify_u128_from_U128
Warning: conversion can be lossy!
declassify_usize_from_U8
Warning: conversion can be lossy!
degree_poly
Returns degree of polynomial, e.g. for 3x² + 2x + 1 -> 2
div_poly
Euclidean polynomial division, calculates a/b in R_n. Returns Ok(quotient, remainder) or Err("Can't divide these two polynomials")
div_scalar
Scalar division in R_p. Returns a / scalar mod p.
extended_euclid
Euclidean algorithm to compute the inverse of x in yℤ[x]
hex_string_to_bytes
make_positive
makes coefficients positiv, e.g. -3 mod 4 = 1
min
Compares and returns the minimum of two values.
mul_poly
Simple polynomial multiplication for two fixed size polynomials O(n²) with a * b mod n
mul_poly_irr
Polynomial multiplication of two size fixed polynomials in R_modulo \ irr
one
Returns the multiplicative identity, 1.
poly_to_ring
Makes poly to an element of R_modulo \ irr
sub_poly
polynomial subtraction, calculates a - b mod modulo
to_array
u8_from_U16
u8_from_U32
u8_from_U64
u8_from_U128
u16_from_U32
u16_from_U64
u16_from_U128
u16_from_be_bytes
u16_from_le_bytes
u16_to_be_bytes
u16_to_le_bytes
u32_from_U64
u32_from_U128
u32_from_be_bytes
u32_from_le_bytes
u32_to_be_bytes
u32_to_le_bytes
u64_from_U128
u64_from_be_bytes
u64_from_le_bytes
u64_to_be_bytes
u64_to_le_bytes
u128_from_U16
Warning: conversion can be lossy!
u128_from_be_bytes
u128_from_le_bytes
u128_to_be_bytes
u128_to_le_bytes
vec_poly_add
vec_poly_mul
vec_poly_sub
weight
Returns number of coefficient != 0, e.g. for -3x⁵ + 3x² + 2x + 1 -> 4
zero
Returns the additive identity, 0.

Derive Macros§

Debug
Derive macro generating an impl of the trait Debug.
PartialEq
Derive macro generating an impl of the trait PartialEq. The behavior of this macro is described in detail here.