diff options
author | MITSUNARI Shigeo <herumi@nifty.com> | 2017-02-21 11:07:41 +0800 |
---|---|---|
committer | MITSUNARI Shigeo <herumi@nifty.com> | 2017-02-21 11:07:41 +0800 |
commit | 405ea71301fad2b2d8bce97586e22f1c0c9611ff (patch) | |
tree | a29ac9c90d601c3b7ff591894ec18c8a9f47e8de | |
parent | 425444df9203527daca07ac4ef07acd87595c545 (diff) | |
download | dexon-mcl-405ea71301fad2b2d8bce97586e22f1c0c9611ff.tar.gz dexon-mcl-405ea71301fad2b2d8bce97586e22f1c0c9611ff.tar.zst dexon-mcl-405ea71301fad2b2d8bce97586e22f1c0c9611ff.zip |
fix typo
-rw-r--r-- | sample/pairing_if.c | 52 | ||||
-rw-r--r-- | src/bn256_if.cpp | 2 |
2 files changed, 53 insertions, 1 deletions
diff --git a/sample/pairing_if.c b/sample/pairing_if.c new file mode 100644 index 0000000..3e34e9c --- /dev/null +++ b/sample/pairing_if.c @@ -0,0 +1,52 @@ +#define BN256_DEFINE_STRUCT +#include <mcl/bn256_if.h> +#include <stdio.h> + +int g_err = 0; +#define ASSERT(x) { if (!(x)) { printf("err %s:%d\n", __FILE__, __LINE__); g_err++; } } + +int main() +{ + char buf[1024]; + const char *aStr = "1234567788234243234234"; + const char *bStr = "239482098243"; + BN256_init(); + BN256_Fr a, b, ab; + BN256_G1 P, aP; + BN256_G2 Q, bQ; + BN256_GT e, e1, e2; + BN256_Fr_setStr(&a, aStr); + BN256_Fr_setStr(&b, bStr); + BN256_Fr_mul(&ab, &a, &b); + BN256_Fr_getStr(buf, sizeof(buf), &ab); + printf("%s x %s = %s\n", aStr, bStr, buf); + + ASSERT(!BN256_G1_setStr(&P, "1 -1 1")); // "1 <x> <y>" + ASSERT(!BN256_G2_hashAndMapTo(&Q, "1")); + BN256_G1_getStr(buf, sizeof(buf), &P); + printf("P = %s\n", buf); + BN256_G2_getStr(buf, sizeof(buf), &Q); + printf("Q = %s\n", buf); + + BN256_G1_mul(&aP, &P, &a); + BN256_G2_mul(&bQ, &Q, &b); + + BN256_pairing(&e, &P, &Q); + BN256_GT_getStr(buf, sizeof(buf), &e); + printf("e = %s\n", buf); + BN256_GT_pow(&e1, &e, &a); + BN256_pairing(&e2, &aP, &Q); + ASSERT(BN256_GT_isSame(&e1, &e2)); + + BN256_GT_pow(&e1, &e, &b); + BN256_pairing(&e2, &P, &bQ); + ASSERT(BN256_GT_isSame(&e1, &e2)); + ASSERT(BN256_setErrFile("") == 0); + if (g_err) { + printf("err %d\n", g_err); + return 1; + } else { + printf("no err\n"); + return 0; + } +} diff --git a/src/bn256_if.cpp b/src/bn256_if.cpp index 2ef6784..aa6114a 100644 --- a/src/bn256_if.cpp +++ b/src/bn256_if.cpp @@ -43,7 +43,7 @@ int BN256_setErrFile(const char *name) return ret; } if (ret) return ret; - if (strcmp(name, "strerr") == 0) { + if (strcmp(name, "stderr") == 0) { g_fp = stderr; return 0; } |