scipr-lab / libff

C++ library for Finite Fields and Elliptic Curves
Other
153 stars 86 forks source link

F_p^n serializing to bits convention #69

Open alexander-zw opened 4 years ago

alexander-zw commented 4 years ago

Being able to convert field elements to bits and vice versa would be useful for some cryptographic protocols. There are already functions to generate random field elements and serialize with << and >>, but the F_p^n fields do not yet have the functions vector<unit_64> FieldT::to_words() and bool FieldT::from_words(vector<unit_64> words) as of 09/26/2020. They would be useful to provide additional ways to generate field elements, including from hashes. These functions are currently being added in a PR, but how exactly to implement them is unclear.

Two other relevant functions are static size_t ceil_size_in_bits() (formerly size_in_bits()) and static size_t floor_size_in_bits() (formerly capacity()).

There are three options for implementing to/from_words. For convenience, say that one words is four bits, and we are trying to store 2x+2 in F_9. Storing 2 in F_3 would be 0010.

Similarly, there are two options to implement ceil/floor_size_in_bits.

Pros and cons: