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
- Parse
IntError - An error which can be returned when parsing an integer.
- Range
- A (half-open) range bounded inclusively below and exclusively above
(
start..end
). - Range
From - A range only bounded inclusively below (
start..
). - Range
Full - An unbounded range (
..
). - Range
Inclusive - A range bounded inclusively below and above (
start..=end
). - RangeTo
- A range only bounded exclusively above (
..end
). - Range
ToInclusive - 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
- U128
Word - 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.
- u128
Word - Fixed length byte array.
- Yeet
Experimental - Implement
FromResidual<Yeet<T>>
on your type to enabledo yeet expr
syntax in functions returning your type.
Enums§
- Bound
- An endpoint of a range of keys.
- Control
Flow - 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 aBigInt
’s composing element. - Coroutine
State Experimental - 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. - Async
FnMut - An async-aware version of the
FnMut
trait. - Async
FnOnce - An async-aware version of the
FnOnce
trait. - BitAnd
- The bitwise AND operator
&
. - BitAnd
Assign - The bitwise AND assignment operator
&=
. - BitOr
- The bitwise OR operator
|
. - BitOr
Assign - The bitwise OR assignment operator
|=
. - BitXor
- The bitwise XOR operator
^
. - BitXor
Assign - The bitwise XOR assignment operator
^=
. - Checked
Sub - Performs subtraction that returns
None
instead of wrapping around on underflow. - Const
One - Defines an associated constant representing the multiplicative identity
element for
Self
. - Const
Zero - Defines an associated constant representing the additive identity element
for
Self
. - Debug
?
formatting.- Deref
- Used for immutable dereferencing operations, like
*v
. - Deref
Mut - 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. - Index
Mut - 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
and1
values, comparisons, basic numeric operations, and string conversion. - Numeric
- The
Numeric
trait has to be implemented by all numeric objects. - Numeric
Copy - One
- Defines a multiplicative identity element for
Self
. - Partial
Eq - Trait for comparisons using the equality operator.
- Public
Integer - Public
Integer Copy - Range
Bounds RangeBounds
is implemented by Rust’s built-in range types, produced by range syntax like..
,a..
,..b
,..=c
,d..e
, orf..=g
.- Rem
- The remainder operator
%
. - RemAssign
- The remainder assignment operator
%=
. - Secret
Integer - Secret
Integer Copy - 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 thougha << b
anda.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 thougha >> b
anda.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).
- Signed
Integer - Signed
Integer Copy - 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
. - Unsigned
Integer - Unsigned
Integer Copy - Unsigned
Public Integer - Unsigned
Public Integer Copy - Unsigned
Secret Integer - Unsigned
Secret Integer Copy - Zero
- Defines an additive identity element for
Self
. - Coerce
Unsized Experimental - Trait that indicates that this is a pointer or a wrapper for one, where unsizing can be performed on the pointee.
- Coroutine
Experimental - The trait implemented by builtin coroutine types.
- Deref
Pure Experimental - 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. - Dispatch
From Dyn Experimental 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.- From
Residual Experimental - Used to specify which residuals can be converted into which
crate::ops::Try
types. - OneSided
Range Experimental OneSidedRange
is implemented for built-in range types that are unbounded on one side. For example,a..
,..b
and..=c
implementOneSidedRange
, but..
,d..e
, andf..=g
do not.- Receiver
Experimental - 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: - Residual
Experimental - Allows retrieving the canonical type implementing
Try
that has this type as its residual and allows it to hold anO
as its output. - Try
Experimental - The
?
operator andtry {}
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). Returnsx
if conditionc
is0
. Note: Addition is always wrapping. - cmul
- Multiply two numerics if condition
c
is set (all bits 1). Returnsx
if conditionc
is0
. Note: Multiplication is always wrapping. - cset_
bit - Set bit at position
i
inx
tob
ifc
is all 1 and return the restult. Returnsx
ifc
is0
. - csub
- Subtract two numerics if condition
c
is set (all bits 1). Returnsx
if conditionc
is0
. Note: Addition is always wrapping. - cswap
- Conditional, constant-time swapping.
Returns
(x, y)
ifc == 0
and(y, x)
ifc == T::max
. The return value is undefined ifc
has any other value. - cswap_
bit - Conditional, constant-time swapping.
Returns
(x, y)
ifc == 0
and(y, x)
ifc == 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
inR_n
. ReturnsOk(quotient, remainder)
orErr("Can't divide these two polynomials")
- div_
scalar - Scalar division in
R_p
. Returnsa / 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
.