-
Notifications
You must be signed in to change notification settings - Fork 0
/
tag.c
78 lines (61 loc) · 1.57 KB
/
tag.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
#include "tag.h"
void tag_init(Tag* t, size_t n, fq_ctx_t ctx, pairing_t p) {
size_t r, s, i;
fq_init(t->y, ctx);
fq_zero(t->y, ctx);
t->Y = (element_t*) malloc(sizeof(element_t) * n);
t->Z = (element_t*) malloc(sizeof(element_t) * (n*(n+1)/2));
for (r = 0; r < n; r++) {
element_init_G1(t->Y[r], p);
element_set1(t->Y[r]);
}
i = 0;
for (r = 1; r <= n; r++) {
// i = ((r-1)*n + (r-1)*(r-2)/2);
for (s = r; s <= n; s++) {
element_init_GT(t->Z[i], p);
element_set1(t->Z[i]);
i++;
}
}
}
void tag_clear(Tag* t, size_t n, fq_ctx_t ctx) {
size_t r, s, i;
fq_clear(t->y, ctx);
for (r = 0; r < n; r++) {
element_clear(t->Y[r]);
}
i = 0;
for (r = 1; r <= n; r++) {
// i = ((r-1)*n + (r-1)*(r-2)/2);
for (s = r; s <= n; s++) {
element_clear(t->Z[i]);
i++;
}
}
free(t->Y);
free(t->Z);
}
void tag_copy(Tag* res, Tag* src, size_t n, fq_ctx_t ctx) {
size_t r, s, i;
fq_set(res->y, src->y, ctx);
for (r = 0; r < n; r++) {
element_set(res->Y[r], src->Y[r]);
}
i = 0;
for (r = 1; r <= n; r++) {
for (s = r; s <= n; s++) {
element_set(res->Z[i], src->Z[i]);
i++;
}
}
}
void tag_print(Tag* t, size_t n, fq_ctx_t ctx) {
printf("The message: ");
fq_print_pretty(t->y, ctx);
printf(". \tThe Y-list: ");
for (size_t i = 0; i < n; i++) {
element_printf(" %B, ", t->Y[i]);
}
printf("\n");
}