-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain-anon-proxy.c
79 lines (63 loc) · 2.61 KB
/
main-anon-proxy.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "lib-anon-proxy.h"
#include "lib-misc.h"
#include "lib-mesg.h"
int main()
{
set_messaging_level(msg_normal);
anon_proxy_params_t params;
gmp_randstate_t prng;
gmp_randinit_default(prng);
gmp_randseed_os_rng(prng, 32);
printf("\n--------INIT--------\n");
anon_proxy_init(params, prng, anon_proxy_lambda_80,false);
printf("\n--------KEYGEN--------\n");
anon_proxy_sk_t sk_1;
anon_proxy_pk_t pk_1;
anon_proxy_keygen(params, prng,false, sk_1, pk_1);
printf("\n--------PLAINTEXT--------\n");
anon_proxy_plaintext_t plaintext;
anon_proxy_plaintext_init_random(prng, plaintext, 16);
anon_proxy_plaintext_print(stdout, plaintext);
printf("\n--------ENCRYPT--------\n");
anon_proxy_ciphertext_t ciphertext;
anon_proxy_encrypt(params, prng, pk_1, plaintext, ciphertext);
anon_proxy_ciphertext_print(stdout, ciphertext);
printf("\n--------DECRYPT--------\n");
anon_proxy_plaintext_t plaintext2;
anon_proxy_decrypt_original(params, sk_1, ciphertext, plaintext2);
anon_proxy_plaintext_print(stdout, plaintext2);
assert(plaintext->m_size == plaintext2->m_size);
assert(memcmp(plaintext->m, plaintext2->m, plaintext->m_size) == 0);
printf("\n--------KEYGEN2-------\n");
anon_proxy_sk_t sk_2;
anon_proxy_pk_t pk_2;
anon_proxy_keygen(params, prng,false, sk_2, pk_2);
printf("\n--------REKEYGEN-------\n");
anon_proxy_rekey_t rekey;
anon_proxy_rekeygen(params, prng, sk_1, pk_2, rekey);
printf("\n--------REENCRYPT-------\n");
anon_proxy_reencrypted_ciphertext_t reencrypted_ciphertext;
anon_proxy_reencrypt(params, rekey, ciphertext, reencrypted_ciphertext);
anon_proxy_reencrypted_ciphertext_print(stdout, reencrypted_ciphertext);
printf("\n--------DECRYPT2-------\n");
anon_proxy_plaintext_t plaintext3;
anon_proxy_decrypt_reencrypted(params, sk_2, reencrypted_ciphertext, plaintext3);
anon_proxy_plaintext_print(stdout, plaintext3);
assert(plaintext->m_size == plaintext3->m_size);
assert(memcmp(plaintext->m, plaintext3->m, plaintext->m_size) == 0);
printf("\n--------CLEAR-------\n");
anon_proxy_plaintext_clear(plaintext);
anon_proxy_plaintext_clear(plaintext2);
anon_proxy_plaintext_clear(plaintext3);
anon_proxy_ciphertext_clear(ciphertext);
anon_proxy_reencrypted_ciphertext_clear(reencrypted_ciphertext);
anon_proxy_rekey_clear(rekey);
anon_proxy_sk_clear(sk_1);
anon_proxy_sk_clear(sk_2);
anon_proxy_pk_clear(pk_1);
anon_proxy_pk_clear(pk_2);
anon_proxy_params_clear(params);
gmp_randclear(prng);
printf("Tutto ok\n");
return 0;
}