Score:2

How to have a hash function that maps from a group element to a binary string of a certain size in charm-crypto?

mq flag

I am facing a problem in programming with the charm-crypto library. The hash functions for pairing group elements in charm-crypto can only map from a string to a specific field: $\mathbb Z_r$, $G_1$ or $G_2$.

Examples: $$\begin{align} H_1: \{0, 1\}^*\to\ &G_1\\ H_2: \{0, 1\}^*\to\ &Z_r\\ H_3: \{0, 1\}^*\to\ &G_2\\ \end{align}$$

I am implementing a certificateless public key encryption scheme with keyword search from this research paper. And in this algorithm in the global setup part I want a hash function as $H_4: G_2\to \{0, 1\}^n$ for some length $n$ i.e., mapping from group element to a binary string of length $n$. In this case the group $G_2$ consists of points on an elliptic curve.

Can someone please guide me how to implement the hash mapping $H4$ in charm-crypto? I would be grateful for any help in this regard.

kelalaka avatar
in flag
I wonder why this kind of paper is circulation around. We had two question about this, let me search. [1](https://crypto.stackexchange.com/q/87012/18298) and [2](https://crypto.stackexchange.com/q/86375/18298)
ashizz avatar
mq flag
Thank you @kelalaka I will take a look at these.
fgrieu avatar
ng flag
Anything wrong with: if $r\in G_2$ we define $H_4(r)$ as $\operatorname{SHAKE256}(R,n)$ where $R$ is a unique representation of $r$ as bitstring, and $\operatorname{SHAKE256}$ as defined in [FIPS 202](https://doi.org/10.6028/NIST.FIPS.202)?
ashizz avatar
mq flag
@fgrieu Not sure if it will work. I will have to check it
Score:2
ng flag

I want a hash function as $H_4: G_2\to \{0, 1\}^n$ for some length $n$ i.e., mapping from group element to a binary string of length $n$. In this case the group $G_2$ consists of points on an elliptic curve.

If $r\in G_2$, we can define $H_4(r)$ as $\operatorname{SHAKE256}(R,n)$ where $R$ is a unique representation of $r$ as bitstring, and $\operatorname{SHAKE256}$ as defined in FIPS 202.

One way to obtain $R$: if the point $r$ has Cartesian coordinates $(x,y)$ in field $\mathbb F_p$ with $p$ prime, $2^{8(\ell-1)}<p<2^{8\ell}$, $0\le x<p$, $0\le y<q$, then we can use $R=\operatorname{I2OSP}(x,\ell)\mathbin\|\operatorname{I2OSP}(y,\ell)$ where $\operatorname{I2OSP}$ is standard big-endian conversion to octet string (as used in e.g. PKCS#1). This can be adapted to other fields.

If $\operatorname{SHAKE256}$ is used to construct the other hashes $H_1$, $H_2$, $H_3$, it's prudent to prefix the input of $\operatorname{SHAKE256}$ with distinct constants.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.