-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_deuxieme.c
86 lines (68 loc) · 2.31 KB
/
test_deuxieme.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
80
81
82
83
84
85
86
#include "deuxieme.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <assert.h>
int main()
{
srand(time(NULL));
//Tester Init Keys
printf("\n{ Testing init keys }\n");
Key* pKey = malloc(sizeof(Key));
Key* sKey = malloc(sizeof(Key));
init_pair_keys(pKey, sKey,3,7);
printf(" . Electeur - pKey: %lx , %lx \n", pKey->val, pKey->n);
printf(" . Electeur - sKey: %lx , %lx \n", sKey->val, sKey->n);
//Tester Key Serialization
printf("\n{ Testing Key Serialization }\n");
char* k2s = key_to_str(pKey);
printf(" . key_to_str (pKey) : %s \n", k2s);
free(k2s);
Key* s2k = str_to_key(k2s);
printf(" . str_to_key (pKey) : (%lx,%lx) \n", s2k->val, s2k->n);
free(s2k);
//Tester signature
printf("\n{ Testing signature }\n");
// Candidate keys:
Key* pKeyC = malloc(sizeof(Key));
Key* sKeyC = malloc(sizeof(Key));
init_pair_keys(pKeyC, sKeyC,3,7);
// Declaration:
char* mess = key_to_str(pKeyC);
char* elec = key_to_str(pKey);
printf(" . %s vote pour %s\n\n",elec, mess);
free(elec); free(mess);
Signature* sgn = sign(mess, sKey);
printf(" . signature :"); print_long_vector(sgn->tab,sgn->taille);
char* sgn2s = signature_to_str(sgn);
printf(" . signature to str : %s \n\n", sgn2s);
free(sgn2s);
Signature* s2sgn = str_to_signature(sgn2s);
printf(" . str to signature :"); print_long_vector(sgn->tab,sgn->taille);
liberer_signature(s2sgn);
//Tester protected
printf("\n{ Testing protected }\n");
Protected* pr = init_protected(pKey,mess, sgn);
//Verification:
if (verify(pr)) {
printf(" . Signature valide\n");
} else {
printf(" . Signature non valide\n");
}
char* p2s = protected_to_str(pr);
printf(" . protected to str : %s\n", p2s);
free(p2s);
Protected* s2p = str_to_protected(p2s);
char* str_key = key_to_str(s2p->pKey);
char* str_sgn = signature_to_str(s2p->s);
printf(" . str to protected : %s %s %s\n",str_key,s2p->mess,str_sgn);
free(str_key); free(str_sgn);
liberer_protected(s2p);
free(sKey);
free(pKeyC); free(sKeyC);
liberer_protected(pr);
generate_random_data(50,5);
return 0;
}