-
Notifications
You must be signed in to change notification settings - Fork 0
/
eddsa_example.c
44 lines (34 loc) · 968 Bytes
/
eddsa_example.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "lib/cryptoolz.h"
int main()
{
// we initialize the public BN128 and Baby JubJub parameters
init_public_parameters();
// generate keypair
secretKey sk;
sk.sk = "00112233445566778899";
publicKey pk;
generate_keypair(&pk, &sk);
printf("KEYPAIR GENERATION\n");
gmp_printf("A1: %Zd \n", pk.A1);
gmp_printf("A2: %Zd \n", pk.A2);
// sign message
char *message = "1234";
signature sig;
sign_message(&sig, message, &sk, &pk);
printf("\nSIGN MESSAGE\n");
printf("msg: %s \n", message);
gmp_printf("R1: %Zd \n", sig.R1);
gmp_printf("R2: %Zd \n", sig.R2);
gmp_printf("S: %Zd \n", sig.S);
// verify signature
printf("\nVERIFY SIGNATURE\n");
int isVerified = verify_signature(&sig, message, &pk);
printf("Is verified: %d\n", isVerified);
// we clear the public parameters to avoid memory leaks
clear_public_parameters();
// we clear the structs we used
clear_signature(&sig);
clear_publickey(&pk);
clear_secretkey(&sk);
return 0;
}