You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.3 KiB
53 lines
1.3 KiB
#include <stdio.h>
|
|
#include <string.h>
|
|
#define MCLBN_FP_UNIT_SIZE 4
|
|
#include <mcl/bn.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 = "123";
|
|
const char *bStr = "456";
|
|
mclBn_init(MCL_BN254, MCLBN_FP_UNIT_SIZE);
|
|
mclBnFr a, b, ab;
|
|
mclBnG1 P, aP;
|
|
mclBnG2 Q, bQ;
|
|
mclBnGT e, e1, e2;
|
|
mclBnFr_setStr(&a, aStr, strlen(aStr), 10);
|
|
mclBnFr_setStr(&b, bStr, strlen(bStr), 10);
|
|
mclBnFr_mul(&ab, &a, &b);
|
|
mclBnFr_getStr(buf, sizeof(buf), &ab, 10);
|
|
printf("%s x %s = %s\n", aStr, bStr, buf);
|
|
|
|
ASSERT(!mclBnG1_hashAndMapTo(&P, "this", 4));
|
|
ASSERT(!mclBnG2_hashAndMapTo(&Q, "that", 4));
|
|
mclBnG1_getStr(buf, sizeof(buf), &P, 16);
|
|
printf("P = %s\n", buf);
|
|
mclBnG2_getStr(buf, sizeof(buf), &Q, 16);
|
|
printf("Q = %s\n", buf);
|
|
|
|
mclBnG1_mul(&aP, &P, &a);
|
|
mclBnG2_mul(&bQ, &Q, &b);
|
|
|
|
mclBn_pairing(&e, &P, &Q);
|
|
mclBnGT_getStr(buf, sizeof(buf), &e, 16);
|
|
printf("e = %s\n", buf);
|
|
mclBnGT_pow(&e1, &e, &a);
|
|
mclBn_pairing(&e2, &aP, &Q);
|
|
ASSERT(mclBnGT_isEqual(&e1, &e2));
|
|
|
|
mclBnGT_pow(&e1, &e, &b);
|
|
mclBn_pairing(&e2, &P, &bQ);
|
|
ASSERT(mclBnGT_isEqual(&e1, &e2));
|
|
ASSERT(mclBn_setErrFile("") == 0);
|
|
if (g_err) {
|
|
printf("err %d\n", g_err);
|
|
return 1;
|
|
} else {
|
|
printf("no err\n");
|
|
return 0;
|
|
}
|
|
}
|
|
|