add getOpUnitSize/getCurveOrder/getFieldOrder

dev
MITSUNARI Shigeo 8 years ago
parent 84d7bb67dc
commit 91ed22cd73
  1. 32
      include/mcl/bn.h
  2. 25
      src/bn_c_impl.hpp

@ -82,11 +82,42 @@ enum {
@param maxUnitSize [in] 4 or 6 @param maxUnitSize [in] 4 or 6
curve = MCLBN_CurveFp254BNb is allowed if maxUnitSize = 4 curve = MCLBN_CurveFp254BNb is allowed if maxUnitSize = 4
curve = MCLBN_CurveFp254BNb/MCLBN_CurveFp382_1/MCLBN_CurveFp382_2 are allowed if maxUnitSize = 6 curve = MCLBN_CurveFp254BNb/MCLBN_CurveFp382_1/MCLBN_CurveFp382_2 are allowed if maxUnitSize = 6
This parameter is used to detect a library compiled with different MCLBN_FP_UNIT_SIZE for safety.
@note not threadsafe @note not threadsafe
@note MCLBN_init is used in libeay32 @note MCLBN_init is used in libeay32
*/ */
MCLBN_DLL_API int mclBn_init(int curve, int maxUnitSize); MCLBN_DLL_API int mclBn_init(int curve, int maxUnitSize);
/*
pairing : G1 x G2 -> GT
#G1 = #G2 = r
G1 is a curve defined on Fp
serialized size of elements
|Fr| = |G1| = 32 bytes (if CurveFp254BNb), 48 bytes (if CurevFp382_{1,2})
|G2| = |G1| * 2
|GT| = |G1| * 12
*/
/*
return the num of Unit(=uint64_t) to store Fr
4 if curve is mclBn_CurveFp254BNb
6 if curve is mclBn_CurveFp382_{1,2}
*/
MCLBN_DLL_API int mclBn_getOpUnitSize();
/*
return decimal string of the order of the curve(=the characteristic of Fr)
return str(buf) if success
*/
MCLBN_DLL_API size_t mclBn_getCurveOrder(char *buf, size_t maxBufSize);
/*
return decimal string of the characteristic of Fp
return str(buf) if success
*/
MCLBN_DLL_API size_t mclBn_getFieldOrder(char *buf, size_t maxBufSize);
//////////////////////////////////////////////// ////////////////////////////////////////////////
// set zero // set zero
MCLBN_DLL_API void mclBnFr_clear(mclBnFr *x); MCLBN_DLL_API void mclBnFr_clear(mclBnFr *x);
@ -101,6 +132,7 @@ MCLBN_DLL_API void mclBnFr_setInt(mclBnFr *y, int x);
*/ */
// return 0 if success // return 0 if success
MCLBN_DLL_API int mclBnFr_setStr(mclBnFr *x, const char *buf, size_t bufSize, int ioMode); MCLBN_DLL_API int mclBnFr_setStr(mclBnFr *x, const char *buf, size_t bufSize, int ioMode);
// return error if buf >= r
MCLBN_DLL_API int mclBnFr_deserialize(mclBnFr *x, const void *buf, size_t bufSize); MCLBN_DLL_API int mclBnFr_deserialize(mclBnFr *x, const void *buf, size_t bufSize);
// mask buf with (1 << (bitLen(r) - 1)) - 1 if buf >= r // mask buf with (1 << (bitLen(r) - 1)) - 1 if buf >= r
MCLBN_DLL_API int mclBnFr_setLittleEndian(mclBnFr *x, const void *buf, size_t bufSize); MCLBN_DLL_API int mclBnFr_setLittleEndian(mclBnFr *x, const void *buf, size_t bufSize);

@ -138,6 +138,31 @@ int mclBn_init(int curve, int maxUnitSize)
return -1; return -1;
} }
int mclBn_getOpUnitSize()
{
return Fp::getUnitSize() * sizeof(mcl::fp::Unit) / sizeof(uint64_t);
}
size_t copyStrAndReturnSize(chat *buf, size_t maxBufSize, const std::string& str)
{
if (str.size() >= maxBufSize) return 0;
strcpy(buf, str.c_str());
return str.size();
}
size_t mclBn_getCurveOrder(char *buf, size_t maxBufSize)
{
std::string str;
Fr::getModulo(str);
return copyStrAndReturnSize(buf, maxBufSize, str);
}
size_t mclBn_getFieldOrder(char *buf, size_t maxBufSize)
{
std::string str;
Fp::getModulo(str);
return copyStrAndReturnSize(buf, maxBufSize, str);
}
//////////////////////////////////////////////// ////////////////////////////////////////////////
// set zero // set zero
void mclBnFr_clear(mclBnFr *x) void mclBnFr_clear(mclBnFr *x)

Loading…
Cancel
Save