diff options
author | MITSUNARI Shigeo <herumi@nifty.com> | 2017-02-19 23:22:38 +0800 |
---|---|---|
committer | MITSUNARI Shigeo <herumi@nifty.com> | 2017-02-19 23:22:38 +0800 |
commit | ebc006b7ab83b1e17adedfb8e2f6775be0bfe1d4 (patch) | |
tree | a4cedec1b68e3de6f9e78a419b5203f9087a1215 | |
parent | 333317aafd16cebd164bfc36e73a9edc16c09c5c (diff) | |
download | dexon-mcl-ebc006b7ab83b1e17adedfb8e2f6775be0bfe1d4.tar.gz dexon-mcl-ebc006b7ab83b1e17adedfb8e2f6775be0bfe1d4.tar.zst dexon-mcl-ebc006b7ab83b1e17adedfb8e2f6775be0bfe1d4.zip |
add Fr/G1/G2 isValid
-rw-r--r-- | include/mcl/bn256_if.h | 11 | ||||
-rw-r--r-- | src/bn256_if.cpp | 20 | ||||
-rw-r--r-- | test/bn256_if_test.cpp | 9 |
3 files changed, 32 insertions, 8 deletions
diff --git a/include/mcl/bn256_if.h b/include/mcl/bn256_if.h index e76004e..02b610c 100644 --- a/include/mcl/bn256_if.h +++ b/include/mcl/bn256_if.h @@ -61,7 +61,8 @@ void BN256_Fr_copy(BN256_Fr *y, const BN256_Fr *x); // return 0 if success int BN256_Fr_setStr(BN256_Fr *x, const char *str); -// return 1 if same and 0 otherwise +// return 1 if true and 0 otherwise +int BN256_Fr_isValid(const BN256_Fr *x); int BN256_Fr_isSame(const BN256_Fr *x, const BN256_Fr *y); int BN256_Fr_isZero(const BN256_Fr *x); int BN256_Fr_isOne(const BN256_Fr *x); @@ -90,7 +91,8 @@ void BN256_G1_copy(BN256_G1 *y, const BN256_G1 *x); // return 0 if success int BN256_G1_setStr(BN256_G1 *x, const char *str); -// return 1 if same and 0 otherwise +// return 1 if true and 0 otherwise +int BN256_G1_isValid(const BN256_G1 *x); int BN256_G1_isSame(const BN256_G1 *x, const BN256_G1 *y); int BN256_G1_isZero(const BN256_G1 *x); @@ -114,7 +116,8 @@ void BN256_G2_copy(BN256_G2 *y, const BN256_G2 *x); // return 0 if success int BN256_G2_setStr(BN256_G2 *x, const char *str); -// return 1 if same and 0 otherwise +// return 1 if true and 0 otherwise +int BN256_G2_isValid(const BN256_G2 *x); int BN256_G2_isSame(const BN256_G2 *x, const BN256_G2 *y); int BN256_G2_isZero(const BN256_G2 *x); @@ -138,7 +141,7 @@ void BN256_GT_copy(BN256_GT *y, const BN256_GT *x); // return 0 if success int BN256_GT_setStr(BN256_GT *x, const char *str); -// return 1 if same and 0 otherwise +// return 1 if true and 0 otherwise int BN256_GT_isSame(const BN256_GT *x, const BN256_GT *y); int BN256_GT_isZero(const BN256_GT *x); int BN256_GT_isOne(const BN256_GT *x); diff --git a/src/bn256_if.cpp b/src/bn256_if.cpp index 32676c2..1a9ac3b 100644 --- a/src/bn256_if.cpp +++ b/src/bn256_if.cpp @@ -93,7 +93,11 @@ int BN256_Fr_setStr(BN256_Fr *x, const char *str) return 1; } -// return 1 if same +// return 1 if true +int BN256_Fr_isValid(const BN256_Fr *x) +{ + return cast(x)->isValid(); +} int BN256_Fr_isSame(const BN256_Fr *x, const BN256_Fr *y) { return *cast(x) == *cast(y); @@ -182,7 +186,11 @@ int BN256_G1_setStr(BN256_G1 *x, const char *str) return 1; } -// return 1 if same +// return 1 if true +int BN256_G1_isValid(const BN256_G1 *x) +{ + return cast(x)->isValid(); +} int BN256_G1_isSame(const BN256_G1 *x, const BN256_G1 *y) { return *cast(x) == *cast(y); @@ -264,7 +272,11 @@ int BN256_G2_setStr(BN256_G2 *x, const char *str) return 1; } -// return 1 if same +// return 1 if true +int BN256_G2_isValid(const BN256_G2 *x) +{ + return cast(x)->isValid(); +} int BN256_G2_isSame(const BN256_G2 *x, const BN256_G2 *y) { return *cast(x) == *cast(y); @@ -347,7 +359,7 @@ int BN256_GT_setStr(BN256_GT *x, const char *str) return 1; } -// return 1 if same +// return 1 if true int BN256_GT_isSame(const BN256_GT *x, const BN256_GT *y) { return *cast(x) == *cast(y); diff --git a/test/bn256_if_test.cpp b/test/bn256_if_test.cpp index 5b5bb6c..e767c03 100644 --- a/test/bn256_if_test.cpp +++ b/test/bn256_if_test.cpp @@ -37,7 +37,10 @@ CYBOZU_TEST_AUTO(init) CYBOZU_TEST_AUTO(Fr) { BN256_Fr x, y; + memset(&x, 0xff, sizeof(x)); + CYBOZU_TEST_ASSERT(!BN256_Fr_isValid(&x)); memset(&x, 1, sizeof(x)); + CYBOZU_TEST_ASSERT(BN256_Fr_isValid(&x)); CYBOZU_TEST_ASSERT(!BN256_Fr_isZero(&x)); BN256_Fr_clear(&x); @@ -102,7 +105,10 @@ CYBOZU_TEST_AUTO(Fr) CYBOZU_TEST_AUTO(G1) { BN256_G1 x, y, z; + memset(&x, 0xff, sizeof(x)); + CYBOZU_TEST_ASSERT(!BN256_G1_isValid(&x)); BN256_G1_clear(&x); + CYBOZU_TEST_ASSERT(BN256_G1_isValid(&x)); BN256_G1_setStr(&y, "0"); CYBOZU_TEST_ASSERT(BN256_G1_isZero(&x)); CYBOZU_TEST_ASSERT(BN256_G1_isZero(&y)); @@ -142,7 +148,10 @@ CYBOZU_TEST_AUTO(G1) CYBOZU_TEST_AUTO(G2) { BN256_G2 x, y, z; + memset(&x, 0xff, sizeof(x)); + CYBOZU_TEST_ASSERT(!BN256_G2_isValid(&x)); BN256_G2_clear(&x); + CYBOZU_TEST_ASSERT(BN256_G2_isValid(&x)); BN256_G2_setStr(&y, "0"); CYBOZU_TEST_ASSERT(BN256_G2_isZero(&x)); CYBOZU_TEST_ASSERT(BN256_G2_isZero(&y)); |