-
Notifications
You must be signed in to change notification settings - Fork 179
/
relic_cp_bls.c
121 lines (106 loc) · 2.54 KB
/
relic_cp_bls.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
115
116
117
118
119
120
121
/*
* RELIC is an Efficient LIbrary for Cryptography
* Copyright (c) 2010 RELIC Authors
*
* This file is part of RELIC. RELIC is legal property of its developers,
* whose names are not listed here. Please refer to the COPYRIGHT file
* for contact information.
*
* RELIC is free software; you can redistribute it and/or modify it under the
* terms of the version 2.1 (or later) of the GNU Lesser General Public License
* as published by the Free Software Foundation; or version 2.0 of the Apache
* License as published by the Apache Software Foundation. See the LICENSE files
* for more details.
*
* RELIC is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the LICENSE files for more details.
*
* You should have received a copy of the GNU Lesser General Public or the
* Apache License along with RELIC. If not, see <https://www.gnu.org/licenses/>
* or <https://www.apache.org/licenses/>.
*/
/**
* @file
*
* Implementation of the Boneh-Lynn-Schacham short signature protocol.
*
* @ingroup cp
*/
#include "relic.h"
/*============================================================================*/
/* Public definitions */
/*============================================================================*/
int cp_bls_gen(bn_t d, g2_t q) {
bn_t n;
int result = RLC_OK;
bn_null(n);
RLC_TRY {
bn_new(n);
pc_get_ord(n);
bn_rand_mod(d, n);
g2_mul_gen(q, d);
}
RLC_CATCH_ANY {
result = RLC_ERR;
}
RLC_FINALLY {
bn_free(n);
}
return result;
}
int cp_bls_sig(g1_t s, const uint8_t *msg, size_t len, const bn_t d) {
g1_t p;
int result = RLC_OK;
g1_null(p);
RLC_TRY {
g1_new(p);
g1_map(p, msg, len);
g1_mul_sec(s, p, d);
}
RLC_CATCH_ANY {
result = RLC_ERR;
}
RLC_FINALLY {
g1_free(p);
}
return result;
}
int cp_bls_ver(const g1_t s, const uint8_t *msg, size_t len, const g2_t q) {
g1_t p[2];
g2_t r[2];
gt_t e;
int result = 0;
g1_null(p[0]);
g1_null(p[1]);
g2_null(r[0]);
g2_null(r[1]);
gt_null(e);
RLC_TRY {
g1_new(p[0]);
g1_new(p[1]);
g2_new(r[0]);
g2_new(r[1]);
gt_new(e);
g1_map(p[0], msg, len);
g1_copy(p[1], s);
g2_copy(r[0], q);
g2_get_gen(r[1]);
g2_neg(r[1], r[1]);
pc_map_sim(e, p, r, 2);
if (gt_is_unity(e) && g2_is_valid(q)) {
result = 1;
}
}
RLC_CATCH_ANY {
RLC_THROW(ERR_CAUGHT);
}
RLC_FINALLY {
g1_free(p[0]);
g1_free(p[1]);
g2_free(r[0]);
g2_free(r[1]);
gt_free(e);
}
return result;
}