pub trait FromUniformBytes {
type Bytes: ByteArray;
// Required method
fn from_uniform_bytes(bytes: &Self::Bytes) -> Self;
}Expand description
Uniform instance of the type can be derived from uniformly distributed byte array
Required Associated Types§
Sourcetype Bytes: ByteArray
type Bytes: ByteArray
Byte array that can be converted into instance of Self via FromUniformBytes::from_uniform_bytes
Required Methods§
Sourcefn from_uniform_bytes(bytes: &Self::Bytes) -> Self
fn from_uniform_bytes(bytes: &Self::Bytes) -> Self
Maps uniformly distributed bytes array to uniformly distributed instance of Self.
Instead of taking a source of randomness directly, this implementation takes a byte array, that was populated from the source of randomness, and outputs a random element.
§Guarantees
When bytes are uniformly distributed, output distribution must be indistinguishable from uniform,
with bias respective to the security level of the curve, meaning that any instance of the type can
appear with equal probability.
Implementation is reproducible: the same input bytes give the same output on all platforms.
Implementation is constant-time: there’s no branching on the input.
§Implementation details
This trait is required to be implemented for scalars. It’s recommended to take approach described in “5. Hashing to Finite Field” of RFC9380:
-
Take a uniform bytestring of
Lbytes, whereL = ceil((ceil(log2(q)) + k) / 8)qis prime (sub)group order, andkis target security level in bits -
Interpret the bytestring as big-endian/little-endian encoding of the integer, and reduce it modulo
q
The output is then guaranteed to have a bias at most 2^-k.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.