-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
79 lines (61 loc) · 2.23 KB
/
main.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
#include <stdio.h>
#include <openssl/evp.h>
#include <openssl/bn.h>
#include "joseph_ibs_scheme.h"
#include "log.h"
#include "buffer.h"
extern BIGNUM *_x, *_msk, *_g_x;
extern struct modp_group *_grp;
int
main(int argc, char **argv)
{
u_char *secretkey,*sig;
u_int secretkey_len, siglen;
int sizeofulong=sizeof(BN_ULONG);
printf("size of ulong is %d in your device.\n",sizeofulong);
//////////////////////////////////////////////////////////////////////////////////////////////////
// //PKG: PKG generate secret key and offline signature for each node
joseph_ibs_setup();
joseph_ibs_extract(_grp->p, _grp->q, _grp->g, _x,"10.0.0.1", 8, &secretkey, &secretkey_len);
joseph_ibs_offline_sign(_grp->p, _grp->g,"data.bin"); //store offline signature in data.bin
//////////////////////////////////////////////////////////////////////////////////////////////////
// Signer:
BIGNUM *R, *s;
R = s = NULL;
R = BN_new();
s = BN_new();
Buffer b;
int rlen=0;
/* Extract g^v and s from offline signature */
buffer_init(&b);
buffer_append(&b, secretkey, secretkey_len);
buffer_get_bignum2(&b, R);
buffer_get_bignum2(&b, s);
rlen = buffer_len(&b);
buffer_free(&b);
if (rlen != 0)
return -1;
joseph_ibs_online_sign(_grp->p, _grp->q, _grp->g, R, s, "hello world!", 12 ,"data.bin",
&sig, &siglen);
//////////////////////////////////////////////////////////////////////////////////////////////////
//verifier:
int ret=joseph_ibs_verify_buf(_grp->p, _grp->q, _grp->g, _g_x, "10.0.0.1", 8, sig, siglen,
"hello world!", 12);
if(ret==1)
printf("verification result correct!\n");
else
printf("Failed!\n");
ret=joseph_ibs_verify_buf(_grp->p, _grp->q, _grp->g, _g_x, "10.0.0.2", 8, sig, siglen,
"hello world!", 12);
if(ret==0)
printf("verification result correct!\n");
else
printf("Failed!\n");
ret=joseph_ibs_verify_buf(_grp->p, _grp->q, _grp->g, _g_x, "10.0.0.1", 8, sig, siglen,
"hello1world!", 12);
if(ret==0)
printf("verification result correct!\n");
else
printf("Failed!\n");
return 0;
}