Closed exfinen closed 1 year ago
You should have to check whether the return value of mclBnFr_deserialize is not zero.
It returns zero if the value is bigger than or equal to the r
.
The following codes shows
ret=32
3fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
#include <mcl/bn_c384_256.h>
#include <stdint.h>
#include <vector>
#include <iostream>
int main()
try
{
mclBn_init(MCL_BLS12_381, MCLBN_COMPILED_TIME_VAR);
std::vector<uint8_t> nbuf = {
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
63,
};
mclBnFr fr;
int ret = mclBnFr_deserialize(&fr, &nbuf[0], 32);
printf("ret=%d\n", ret);
if (ret == 0) {
fprintf(stderr, "bad value\n");
return 1;
}
char sbuf[1024];
mclBnFr_getStr(sbuf, 1024, &fr, 16);
std::cout << sbuf << std::endl;
} catch (std::exception& e) {
printf("err %s\n", e.what());
}
Thank you. I understood. So mclBnFr doesn't accept a value outside Fr range from outside.
Hi Mitsunari-san,
Based on your comments in #144, I'm trying to write a complement operator that works on top of
mclBnFr
in the following way:mclBnFr
instance to a 32-byte buffer bymclBnFr_serialize
mclBnFr
bymclBnFr_deserialize
This works for a small number such as INT64_MAX. Below code outputs:
But when I try a big number such as ~1, I get an unexpected result. Below code outputs:
which differs from nbuf mod curve order or nbuf's hex representation that is:
While trying other bn.h functions, I found that setting curve order to
mclBnFr
withmclBnFr_setStr
results in an error while curve order - 1 is accepted.Is it the case that
mclBnFr_deserialize
expects its input to be below curve order likemclBnFr_setStr
does? Or could you suggest if I and missing something?