Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Alice wishes to sign a message. She generates her public and private keys as follows. Her private key is a random element x of Zr, and her corresponding public key is g^x.
- * To sign a message, Alice hashes the message to some element h of G1, and then outputs the signature h^x.
- * To verify a signature σ, Bob checks that e(h,g^x) = e(σ, g).
- *
- *
- * */
- #include <pbc/pbc.h>
- #include <pbc/pbc_test.h>
- int main(int argc, char **argv)
- {
- // declare g and h random elements from G1 and G2 respectively
- element_t g, h;
- // public and private key of alice
- element_t public_key, private_key;
- element_t sig;
- element_t temp1, temp2;
- pairing_t pairing;
- //char param[1024];
- //size_t count = fread(param, 1, 1024, stdin);
- //if (!count) pbc_die("input error");
- //pairing_init_set_buf(pairing, param, count);
- pbc_demo_pairing_init(pairing, argc, argv);
- // initialise all elements and keys
- element_init_G2(g, pairing);
- element_init_G2(public_key, pairing);
- element_init_G1(h, pairing);
- element_init_G1(sig, pairing);
- element_init_GT(temp1, pairing);
- element_init_GT(temp2, pairing);
- element_init_Zr(private_key, pairing);
- // pick system parameter g
- element_random(g);
- element_printf(" g = %B\n", g);
- // Alice generates private key
- element_random(private_key);
- element_printf("Alices random private key = %B\n", private_key);
- // Alice generates public key, which is g^(private_key)
- element_pow_zn(public_key, g, private_key);
- element_printf("Alices random public key = %B\n", public_key);
- //Now Alice will sign a message
- printf("=============Now Alice will hash the message==============\n");
- element_from_hash(h, "Alice wants to kill you", 20);
- element_printf("Alices hash to element h = %B\n", h);
- //Sign the message
- element_pow_zn(sig, h, private_key);
- // Bob verifies the signature
- pairing_apply(temp1, sig, g, pairing);
- pairing_apply(temp2, h, public_key, pairing);
- if (!element_cmp(temp1, temp2)) {
- printf("signature verifies\n");
- } else {
- printf("signature does not verify\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement