hash2curve 0.1.0

Traits and algorithms for hashing arbitrary values to curve group element
Documentation
/// These traits are meant to create the return values
/// from random bytes generated by hash_to_field
use digest::generic_array::{ArrayLength, GenericArray};

/// Generate an element from a random byte sequence
pub trait FromRO {
    /// The amount of bytes the element expects to receive
    type Length: ArrayLength<u8>;

    /// Crate an element from the specified random byte sequence
    fn from_ro(okm: &GenericArray<u8, <Self as FromRO>::Length>) -> Self;
}

/// Generate an element of a base field from a random byte sequence
/// (used by FromRO for extension fields)
pub trait BaseFromRO {
    /// The amount of bytes the element expects to receive
    type BaseLength: ArrayLength<u8>;

    /// Crate an element of a base field from the specified random byte sequence
    fn from_okm(okm: &GenericArray<u8, <Self as BaseFromRO>::BaseLength>) -> Self;
}

/// BaseFromRO is a FromRO implementation for a field with extension degree 1.
impl<T: BaseFromRO> FromRO for T {
    type Length = <T as BaseFromRO>::BaseLength;

    fn from_ro(okm: &GenericArray<u8, <Self as FromRO>::Length>) -> T {
        T::from_okm(okm)
    }
}