h : {0,1}* → G
This means that h maps a bit string of any length to a point of the the elliptic curve group G.
These sort of functions are quite common in literature and I came up with a quick fix solution for one :-) (and I'm sure there are much better implementations out there).
Here's the code:
import it.unisa.dia.gas.jpbc.Element;
import it.unisa.dia.gas.jpbc.Pairing;
import it.unisa.dia.gas.plaf.jpbc.pairing.CurveParams;
import it.unisa.dia.gas.plaf.jpbc.pairing.PairingFactory;
import java.io.InputStream;
import java.math.BigInteger;
import org.bouncycastle.crypto.digests.SHA256Digest;
public class Digest {
private Element gElem = null;
private Pairing pairing = null;
public Digest() throws Exception {
CurveParams curveParams = new CurveParams();
curveParams.load(Digest.class.getClassLoader().getResourceAsStream("a_181_603.properties"));
//Load private key
InputStream fis = Digest.class.getClassLoader().getResourceAsStream("keys/digest/g");
byte[] tmp = new byte[1024];
int read = fis.read(tmp);
byte[] gBytes = new byte[read];
System.arraycopy(tmp, 0, gBytes, 0, read);
this.pairing = PairingFactory.getPairing(curveParams);
this.gElem = this.pairing.getG1().newElement();
this.gElem.setFromBytes(gBytes);
}
public byte[] createHash(byte[] data) throws Exception {
//Create a sha 256 of the message
SHA256Digest dgst = new SHA256Digest();
dgst.reset();
dgst.update(data, 0, data.length);
int digestSize = dgst.getDigestSize();
byte[] hash = new byte[digestSize];
dgst.doFinal(hash, 0);
BigInteger val = new BigInteger(hash);
BigInteger order = this.pairing.getG1().getOrder();
BigInteger fact = val.mod(order);
Element gen = this.gElem.duplicate();
Element mul = gen.mul(fact);
return mul.toBytes();
}
}
This uses the jPBC library.
























