hash2field
This crate is designed to be used no-std environments.
Implements safe hash to a finite field as described in section 5 from the IETF Draft.
This crate is designed to be called by implementers of hash to curve without needing to write the hash to field section, since this is curve agnostic.
It provides two structs, two traits, and the function hash_to_field
.
FromRO
should be implemented by the caller of hash_to_field
and is used to convert the output digests to field elements.
ExpandMsg
is implemented by ExpandMsgXof
and ExpandMsgXmd
so it should not need to be implemented directly.
ExpandMsgXmd
is the implementation of Section 5.4.1
and allows the caller the flexibility of picking a fixed output digest.
ExpandMsgXof
is the implementation of Section 5.4.2
and allows the caller the flexibility of picking any XOF.
hash_to_field
uses const generics as implemented in rust 1.51.
Here's an example of using it for the k256
crate
use *;
use ;
use FieldElement;
use BigUint;
use Integer;
use Sha256;
const L: usize = 48;
const COUNT: usize = 2;
const OUT: usize = L * COUNT;
const DST: & = b"QUUX-V01-CS02-with-secp256k1_XMD:SHA-256_SSWU_RO_";
let output = ;
}
Using ExpandMsgXof
is very similar
use *;
use ;
use FieldElement;
use BigUint;
use Integer;
use Shake256;
const L: usize = 48;
const COUNT: usize = 2;
const OUT: usize = L * COUNT;
const DST: & = b"QUUX-V01-CS02-with-secp256k1_XOF:SHAKE-256_SSWU_RO_";
let output = ;