Tuesday, November 16, 2010

Hashing a message into an elliptic curve group

I wanted a hash function (h) defined as follows for an implementation that I'm working on these days:

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.

24 comments:

IT said...

I have read your blog its very attractive and impressive. I like it your blog.


JavaEE Training in Chennai JavaEE Training in Chennai

Java Training in Chennai Core Java Training in Chennai Core Java Training in Chennai

Java Online Training Java Online Training Core Java 8 Training in Chennai Java 8 Training in Chennai

IT said...

Java Training Institutes Java Training Institutes
Java Spring Hibernate Training Institutes in Chennai J2EE Training Institutes in Chennai J2EE Training Institutes in Chennai Java Spring Hibernate Training Institutes in Chennai | Hibernate Training Institutes in Chennai Core Java Training Institutes in Chennai Core Java Training Institutes in Chennai

Hibernate Online Training Hibernate Online Training Hibernate Training in Chennai Hibernate Training in Chennai Java Online Training Java Online Training Hibernate Training Institutes in ChennaiHibernate Training Institutes in Chennai

Unknown said...

Good post. Keep sharing such a new topic.

php training in chennai

Unknown said...

Very Interest information. Keep sharing,
Java Training in Chennai | Java Training Institute in Chennai

sathyaramesh said...

Thank you for this wonderful post, It really nice and informative. Keep sharing!!
SEO Training in Chennai
JAVA Training in Chennai
Big Data Training in Chennai
Selenium Training in Chennai
German Classes in chennai
Android Course in Chennai
Android Training in Tambaram

sangeetha sathyan said...

Very nice post with lots of information. Thanks for this updates.
ui ux design course in Chennai
ui ux designer course in Chennai
ui ux course in chennai
ReactJS Training in Chennai
Web Designing Course in chennai
web designing training in chennai
Tally course in Chennai
ui ux design course in Porur
ui ux design course in Tambaram
ui ux design course in Adyar

divi said...

excellent blog very nice article I have read the article thanks for it web design company in velachery

janathan said...

very intresting information..
Free Inplant Training Course For ECE Students
INTERNSHIP
INTERNSHIP FOR AERONAUTICAL ENGINERING STUDENTS IN INDIA
INTERNSHIP FOR CSE 3RD YEAR STUDENTS
Free Inplant Training Course for Mechanical Students
INTERNSHIP FOR ECE STUDENTS
INPLANT TRAINING FOR CIVIL
INTERNSHIP AT BSNL
INTERNSHIP FOR 2ND YEAR ECE STUDENTS
INTERNSHIP FOR AERONAUTICAL STUDENTS

janathan said...

very nice post...
foreach loop in node js
ywy cable
javascript integer max value
adder and subtractor using op amp
"c program to find frequency of a word in a string"
on selling an article for rs 1020, a merchant loses 15%. for how much price should he sell the article to gain 12% on it ?
paramatrix interview questions
why you consider yourself suitable for the position applied for

Vijaykumar said...

great post....
Inplant Training in Chennai
Iot Internship
Internship in Chennai for CSE
Internship in Chennai
Python Internship in Chennai
Implant Training in Chennai
Android Training in Chennai
R Programming Training in Chennai
Python Internship
Internship in chennai for EEE

Vijaykumar said...

very nice information...
Crome://Flags
Python Programming Questions and Answers PDF
Qdxm Sfyn Uioz
How To Hack Whatsapp Account Ethical Hacking
Power Bi Resume
Whatsapp Unblock Software
Tp Link Password Hack
The Simple Interest Earned On a Certain Amount Is Double
A Certain Sum Amounts To RS. 7000 in 2 years and to RS. 8000 in 3 Years. Find The Sum.
Zensoft Aptitude Questions

ammu said...

excellent....!!!
chile web hosting
colombia web hosting
croatia web hosting
cyprus web hosting
bahrain web hosting
india web hosting
iran web hosting
kazakhstan web hosting
korea web hosting
moldova web hosting

Naveen said...

Taldeen is one of the best plastic manufacturing company in Saudi Arabia. They are manufacturing Handling Solutions Plastic products like Plastic Pallets and plastic crates. Here is the link of the product
Handling Solutions
Plastic Pallets
GrueBleen is one of the Branding and Marketing agency Based in Riyadh- Saudi Arabia. The main functions of GrueBleen is Advertising, Branding, Marketing, Office Branding, Exhibition Management and Digital Marketing. Visit the below link to know more about GrueBleen Creative Club.
Branding Agency Riyadh
Marketing Agency Riyadh
Agriculture Solutions – Taldeen is a plastic manufacturing company in Saudi Arabia. They are manufacturing agricultural plastic products like greenhouse cover and hay cover. Visit the below link to know more details
Agriculture Solutions
Greenhouse Cover
GrueBleen – One of the best social media marketing agency in Riyadh- Saudi Arabia. Visit here for the all service details of GrueBleen.
Social Media Marketing Agency | Social Media Agency In Saudi Arabia | Social Media Agency In Riyadh | Social Media Agency in Jeddah |

w3webschool said...

Such a wonderful article and I feel that it is best to write more on this topic. Thank you so much because i learn a lot of ideas about it. Keep posting...
Digital Marketing Course In Kolkata
Web Design Course In Kolkata

Faizal said...

Excellent works!!!Information's are amazing visit here for more...
Java training in chennai | Java training in annanagar | Java training in omr | Java training in porur | Java training in tambaram | Java training in velachery

Rajan Mhatre said...

I read this article. I think You have put a lot of effort to create this article. I appreciate your work.
Visit us for Printing IDs & Accessories.

Revathi said...

I had completely gothrow your post and it is full of innovative information.thanks for sharing this.keep it up!!

android training in chennai

android online training in chennai

android training in bangalore

android training in hyderabad

android Training in coimbatore

android training

android online training

jenani said...

This is really informative. Thanks for sharing this with us. Do share more.
Java Training in Chennai

Java Training in Velachery

Java Training inTambaram

Java Training in Porur

Java Training in Omr

Java Training in Annanagar


vanathi said...

Such a wonderful article and I feel that it is best to write more on this topic. Thank you so much because i learn a lot of ideas about it. Keep posting...
Software Testing Training in Chennai

Software Testing Training in Velachery

Software Testing Training in Tambaram

Software Testing Training in Porur

Software Testing Training in Omr
Software Testing Training in Annanagar

subathara said...

Thank you for this wonderful post, It really nice and informative. Keep sharing!!
Digital Marketing Training in Chennai

Digital Marketing Training in Velachery

Digital Marketing Training in Tambaram

Digital Marketing Training in Porur

Digital Marketing Training in Omr

Digital MarketingTraining in Annanagar

Tiger Online shop said...


You can get Apple-certified repairs and service at the Apple Store or with one of our Apple Authorized Service Providers.
mobile phone repair in North Olmsted
Worked as a Senior SEO & Digital & Social Media & Graphics Design & cpa & Drop shipping & Video Editing And Youtube & Web Design And Development & Affiliate Marketing trainer at BITM (BASIS Institute of Technology & Management) since 2014-2018. Successfully completed 50+ SEO batches, 20+
Affiliate Marketing batches and 30+ workshop on Freelancing under SEIP (Skills for Employment Investment Program).
outsourcing training courses in uttara

Pathway for German Language said...
This comment has been removed by the author.
arshiya said...

Amazing article, Really useful information to all, Keep sharing more useful updates.
data science skills
latest new technologies
ccna job opportunities
courses with guaranteed jobs
cyber security interview questions pdf
java interview questions and answers for freshers

salvadorabler said...

Harrah's Cherokee Casino Resort - Mapyro
Harrah's Cherokee Casino Resort · Casino Information 대구광역 출장안마 · Gaming · 순천 출장샵 Hotel 원주 출장샵 Rooms. 통영 출장안마 All Rooms · 나주 출장마사지 Casino Rooms. All Salon Suites · Casino Information · Casino Rooms.