-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_greyhound.c
114 lines (96 loc) · 2.24 KB
/
test_greyhound.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include "malloc.h"
#include "randombytes.h"
#include "labrador.h"
#include "chihuahua.h"
#include "pack.h"
#include "greyhound.h"
static int test_polcom(size_t len) {
int ret;
int64_t x,y;
polz *s;
polcomctx ctx;
polcomprf pi;
prncplstmnt st;
witness wt;
__attribute__((aligned(16)))
uint8_t seed[16];
printf("Testing Greyhound polynomial commitment scheme\n\n");
randombytes(seed,16);
s = _aligned_alloc(64,len*sizeof(polz));
polzvec_almostuniform(s,len,seed,0);
polzvec_center(s,len);
x = 43;
y = polzvec_eval(s,len,x);
polcom_commit(&ctx,s,len);
print_polcomctx_pp(&ctx);
polcom_eval(&wt,&pi,&ctx,x,y);
free(s);
free_polcomctx(&ctx);
print_polcomprf_pp(&pi);
ret = polcom_reduce(&st,&pi);
if(ret) {
printf("ERROR: Reduction to Chihuahua statement failed: %d\n",ret);
goto end;
}
free_polcomprf(&pi);
print_prncplstmnt_pp(&st);
print_witness_pp(&wt);
ret = principle_verify(&st,&wt);
if(ret) {
printf("ERROR: Verification of Chihuahua statement failed: %d\n",ret);
goto end;
}
end:
free_polcomprf(&pi);
free_prncplstmnt(&st);
free_witness(&wt);
return ret;
}
static int test_pack(size_t len) {
int ret;
int64_t x,y;
clock_t t;
polz *s;
polcomctx ctx = {};
polcomprf pi = {};
composite p = {};
__attribute__((aligned(16)))
uint8_t seed[16];
printf("Testing Greyhound Pack for degree 2^%.2g\n\n",log2(len << 6));
randombytes(seed,16);
s = _aligned_alloc(64,len*sizeof(polz));
polzvec_almostuniform(s,len,seed,0);
polzvec_center(s,len);
x = 43;
y = polzvec_eval(s,len,x);
t = clock();
polcom_commit(&ctx,s,len);
t = clock() - t;
printf("Greyhound Pack commit time: %.4fs\n\n",(double)t/CLOCKS_PER_SEC);
print_polcomctx_pp(&ctx);
composite_prove_polcom(&p,&pi,&ctx,x,y);
ret = composite_verify_polcom(&p,&pi);
if(ret)
printf("ERROR: verify_composite_polcom failed: %d\n",ret);
free(s);
free_polcomctx(&ctx);
free_polcomprf(&pi);
free_composite(&p);
return ret;
}
int main(void) {
int ret;
size_t len;
len = 1 << 19;
ret = test_polcom(len);
if(ret) goto end;
ret = test_pack(len);
if(ret) goto end;
end:
free_comkey();
return ret;
}