herumi / mcl

a portable and fast pairing-based cryptography library
BSD 3-Clause "New" or "Revised" License
458 stars 157 forks source link

How to get the order of my bilinear environment with Java API? #99

Closed NotBad4U closed 3 years ago

NotBad4U commented 3 years ago

Hi everyone,

I'm trying to reimplement this paper. It uses the library over the 254-bits Barreto-Naehrig curve. Some steps of the protocol need the q order of the tuple (q, G1 , g1 , G2 , g2 , Gt , e(·, ·)) referred to as a bilinear environment, to perform modulo calculation.

Do we have a way to retrieve this order with the current Java API? I found this method in the C++ part: here, but not the binding with the Java SWIG interface. Moreover, as a new user of the library, I add that I do not know if my method is the correct one.

Best regards

herumi commented 3 years ago

Okay, I'll append the interface. But the value is fixed, so you can use r written in https://github.com/herumi/mcl/blob/master/api.md#curve-parameter .

NotBad4U commented 3 years ago

Thank you @herumi for your response. Should we you use the Java interface like that to setup this "big" number ?

Fr fr = new Fr();
f.setStr(" 0x2523648240000001ba344d8000000007ff9f800000000010a10000000000000d");
herumi commented 3 years ago

What do you want to?

setStr accepts decimal and hexadecimal strings. cf. https://github.com/herumi/mcl/blob/master/ffi/java/MclTest.java#L45-L47

But Fr is a class of a finite field of the prime r, and so setStr accepts a value between 0 and r-1. You can't set the value r.

NotBad4U commented 3 years ago

I try to understand how can I implement the workaround that you've proposed on your first message:

... But the value is fixed, so you can use r written in ...

So I'm trying to find a way to serialize the curve order value r. I thought that the Fr was the correct structure.

herumi commented 3 years ago

Okay, I'll append the interface.

Sorry, I tried to do so, but it was a little troublesome. So could you use fixed literals?