line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#define PERL_NO_GET_CONTEXT |
2
|
|
|
|
|
|
|
#include "EXTERN.h" |
3
|
|
|
|
|
|
|
#include "perl.h" |
4
|
|
|
|
|
|
|
#include "XSUB.h" |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
#include "ppport.h" |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
#include |
9
|
|
|
|
|
|
|
#include |
10
|
|
|
|
|
|
|
#include |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
#include "const-c.inc" |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
#if OPENSSL_VERSION_NUMBER >= 0x10100000L |
16
|
|
|
|
|
|
|
#include |
17
|
|
|
|
|
|
|
#else |
18
|
|
|
|
|
|
|
/* ECDSA_SIG_get0() and ECDSA_SIG_set0() copied from OpenSSL 1.1.0b. */ |
19
|
8
|
|
|
|
|
|
static void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, |
20
|
|
|
|
|
|
|
const BIGNUM **ps) { |
21
|
8
|
100
|
|
|
|
|
if (pr != NULL) |
22
|
4
|
|
|
|
|
|
*pr = sig->r; |
23
|
8
|
100
|
|
|
|
|
if (ps != NULL) |
24
|
4
|
|
|
|
|
|
*ps = sig->s; |
25
|
8
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
6
|
|
|
|
|
|
static int ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s) |
28
|
|
|
|
|
|
|
{ |
29
|
6
|
50
|
|
|
|
|
if (r == NULL || s == NULL) |
|
|
50
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
return 0; |
31
|
6
|
|
|
|
|
|
BN_clear_free(sig->r); |
32
|
6
|
|
|
|
|
|
BN_clear_free(sig->s); |
33
|
6
|
|
|
|
|
|
sig->r = r; |
34
|
6
|
|
|
|
|
|
sig->s = s; |
35
|
6
|
|
|
|
|
|
return 1; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
#endif |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
MODULE = Crypt::OpenSSL::ECDSA PACKAGE = Crypt::OpenSSL::ECDSA |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
PROTOTYPES: ENABLE |
42
|
|
|
|
|
|
|
INCLUDE: const-xs.inc |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
BOOT: |
45
|
1
|
|
|
|
|
|
ERR_load_crypto_strings(); |
46
|
|
|
|
|
|
|
#if OPENSSL_VERSION_NUMBER >= 0x10002000L && OPENSSL_VERSION_NUMBER < 0x10100000L |
47
|
1
|
|
|
|
|
|
ERR_load_ECDSA_strings(); |
48
|
|
|
|
|
|
|
#endif |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
#ECDSA_SIG * |
51
|
|
|
|
|
|
|
#ECDSA_SIG_new() |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
#void |
54
|
|
|
|
|
|
|
#ECDSA_SIG_free(ECDSA_SIG *sig) |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
#int |
57
|
|
|
|
|
|
|
#i2d_ECDSA_SIG(const ECDSA_SIG *sig, unsigned char **pp) |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
#ECDSA_SIG * |
60
|
|
|
|
|
|
|
#d2i_ECDSA_SIG(ECDSA_SIG **sig, const unsigned char **pp, long len) |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
ECDSA_SIG * |
63
|
|
|
|
|
|
|
ECDSA_do_sign(const unsigned char *dgst, EC_KEY *eckey) |
64
|
|
|
|
|
|
|
PREINIT: |
65
|
|
|
|
|
|
|
STRLEN dgst_len; |
66
|
|
|
|
|
|
|
CODE: |
67
|
1
|
50
|
|
|
|
|
dgst = (const unsigned char *)SvPV(ST(0), dgst_len); |
68
|
1
|
|
|
|
|
|
RETVAL = ECDSA_do_sign(dgst, dgst_len, eckey); |
69
|
|
|
|
|
|
|
OUTPUT: |
70
|
|
|
|
|
|
|
RETVAL |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
ECDSA_SIG * |
73
|
|
|
|
|
|
|
ECDSA_do_sign_ex(const unsigned char *dgst, const BIGNUM *kinv, const BIGNUM *rp, EC_KEY *eckey) |
74
|
|
|
|
|
|
|
PREINIT: |
75
|
|
|
|
|
|
|
STRLEN dgst_len; |
76
|
|
|
|
|
|
|
CODE: |
77
|
1
|
50
|
|
|
|
|
dgst = (const unsigned char *)SvPV(ST(0), dgst_len); |
78
|
1
|
|
|
|
|
|
RETVAL = ECDSA_do_sign_ex(dgst, dgst_len, kinv, rp, eckey); |
79
|
|
|
|
|
|
|
OUTPUT: |
80
|
|
|
|
|
|
|
RETVAL |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
int |
83
|
|
|
|
|
|
|
ECDSA_do_verify(const unsigned char *dgst, const ECDSA_SIG *sig, EC_KEY* eckey); |
84
|
|
|
|
|
|
|
PREINIT: |
85
|
|
|
|
|
|
|
STRLEN dgst_len; |
86
|
|
|
|
|
|
|
CODE: |
87
|
4
|
50
|
|
|
|
|
dgst = (const unsigned char *)SvPV(ST(0), dgst_len); |
88
|
4
|
|
|
|
|
|
RETVAL = ECDSA_do_verify(dgst, dgst_len, sig, eckey); |
89
|
|
|
|
|
|
|
OUTPUT: |
90
|
|
|
|
|
|
|
RETVAL |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# These ECDSA_METHOD functions only became available in 1.0.2, |
93
|
|
|
|
|
|
|
# but some of them removed again in 1.1.0. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
#if OPENSSL_VERSION_NUMBER >= 0x10002000L |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
int |
98
|
|
|
|
|
|
|
ECDSA_size(const EC_KEY *eckey) |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
#if OPENSSL_VERSION_NUMBER < 0x10100000L |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
const ECDSA_METHOD * |
103
|
|
|
|
|
|
|
ECDSA_OpenSSL() |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
void |
106
|
|
|
|
|
|
|
ECDSA_set_default_method(const ECDSA_METHOD *meth) |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
const ECDSA_METHOD * |
109
|
|
|
|
|
|
|
ECDSA_get_default_method() |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
int |
112
|
|
|
|
|
|
|
ECDSA_set_method(EC_KEY *eckey, const ECDSA_METHOD *meth) |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
ECDSA_METHOD * |
115
|
|
|
|
|
|
|
ECDSA_METHOD_new(ECDSA_METHOD *ecdsa_method=0) |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
void |
118
|
|
|
|
|
|
|
ECDSA_METHOD_free(ECDSA_METHOD *ecdsa_method) |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
void |
121
|
|
|
|
|
|
|
ECDSA_METHOD_set_flags(ECDSA_METHOD *ecdsa_method, int flags) |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
void |
124
|
|
|
|
|
|
|
ECDSA_METHOD_set_name(ECDSA_METHOD *ecdsa_method, char *name) |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
void |
127
|
|
|
|
|
|
|
ERR_load_ECDSA_strings() |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
#endif |
130
|
|
|
|
|
|
|
#endif |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
unsigned long |
136
|
|
|
|
|
|
|
ERR_get_error() |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
char * |
139
|
|
|
|
|
|
|
ERR_error_string(error,buf=NULL) |
140
|
|
|
|
|
|
|
unsigned long error |
141
|
|
|
|
|
|
|
char * buf |
142
|
|
|
|
|
|
|
CODE: |
143
|
0
|
|
|
|
|
|
RETVAL = ERR_error_string(error,buf); |
144
|
|
|
|
|
|
|
OUTPUT: |
145
|
|
|
|
|
|
|
RETVAL |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
MODULE = Crypt::OpenSSL::ECDSA PACKAGE = Crypt::OpenSSL::ECDSA::ECDSA_SIG |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
ECDSA_SIG * |
151
|
|
|
|
|
|
|
new(CLASS) |
152
|
|
|
|
|
|
|
char * CLASS |
153
|
|
|
|
|
|
|
CODE: |
154
|
2
|
|
|
|
|
|
CLASS = CLASS; /* prevent unused warnings */ |
155
|
2
|
|
|
|
|
|
RETVAL = ECDSA_SIG_new(); |
156
|
|
|
|
|
|
|
OUTPUT: |
157
|
|
|
|
|
|
|
RETVAL |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
void |
160
|
|
|
|
|
|
|
DESTROY(ecdsa_sig) |
161
|
|
|
|
|
|
|
ECDSA_SIG *ecdsa_sig |
162
|
|
|
|
|
|
|
CODE: |
163
|
4
|
|
|
|
|
|
ECDSA_SIG_free(ecdsa_sig); |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
SV * |
166
|
|
|
|
|
|
|
get_r(ecdsa_sig) |
167
|
|
|
|
|
|
|
ECDSA_SIG *ecdsa_sig |
168
|
|
|
|
|
|
|
PREINIT: |
169
|
|
|
|
|
|
|
const BIGNUM *r; |
170
|
|
|
|
|
|
|
unsigned char *to; |
171
|
|
|
|
|
|
|
STRLEN len; |
172
|
|
|
|
|
|
|
int bnlen; |
173
|
|
|
|
|
|
|
CODE: |
174
|
1
|
|
|
|
|
|
ECDSA_SIG_get0(ecdsa_sig, &r, NULL); |
175
|
1
|
|
|
|
|
|
bnlen = BN_num_bytes(r); |
176
|
1
|
|
|
|
|
|
to = malloc(sizeof(char) * bnlen); |
177
|
1
|
|
|
|
|
|
len = BN_bn2bin(r, to); |
178
|
1
|
|
|
|
|
|
RETVAL = newSVpvn((const char*)to, len); |
179
|
1
|
|
|
|
|
|
free(to); |
180
|
|
|
|
|
|
|
OUTPUT: |
181
|
|
|
|
|
|
|
RETVAL |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
SV * |
184
|
|
|
|
|
|
|
get_s(ecdsa_sig) |
185
|
|
|
|
|
|
|
ECDSA_SIG *ecdsa_sig |
186
|
|
|
|
|
|
|
PREINIT: |
187
|
|
|
|
|
|
|
const BIGNUM *s; |
188
|
|
|
|
|
|
|
unsigned char *to; |
189
|
|
|
|
|
|
|
STRLEN len; |
190
|
|
|
|
|
|
|
int bnlen; |
191
|
|
|
|
|
|
|
CODE: |
192
|
1
|
|
|
|
|
|
ECDSA_SIG_get0(ecdsa_sig, NULL, &s); |
193
|
1
|
|
|
|
|
|
bnlen = BN_num_bytes(s); |
194
|
1
|
|
|
|
|
|
to = malloc(sizeof(char) * bnlen); |
195
|
1
|
|
|
|
|
|
len = BN_bn2bin(s, to); |
196
|
1
|
|
|
|
|
|
RETVAL = newSVpvn((const char*)to, len); |
197
|
1
|
|
|
|
|
|
free(to); |
198
|
|
|
|
|
|
|
OUTPUT: |
199
|
|
|
|
|
|
|
RETVAL |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
void |
202
|
|
|
|
|
|
|
set_r(ecdsa_sig, r_SV) |
203
|
|
|
|
|
|
|
ECDSA_SIG *ecdsa_sig |
204
|
|
|
|
|
|
|
SV * r_SV |
205
|
|
|
|
|
|
|
PREINIT: |
206
|
|
|
|
|
|
|
char *string; |
207
|
|
|
|
|
|
|
STRLEN len; |
208
|
|
|
|
|
|
|
BIGNUM *r; |
209
|
|
|
|
|
|
|
BIGNUM *s; |
210
|
|
|
|
|
|
|
const BIGNUM *old_s; |
211
|
|
|
|
|
|
|
CODE: |
212
|
3
|
50
|
|
|
|
|
string = SvPV(r_SV, len); |
213
|
3
|
|
|
|
|
|
r = BN_bin2bn((const unsigned char *)string, len, NULL); |
214
|
3
|
50
|
|
|
|
|
if (NULL == r) |
215
|
0
|
|
|
|
|
|
croak("Could not convert ECDSA parameter string to big number"); |
216
|
3
|
|
|
|
|
|
ECDSA_SIG_get0(ecdsa_sig, NULL, &old_s); |
217
|
3
|
50
|
|
|
|
|
if (NULL == old_s) { |
218
|
0
|
|
|
|
|
|
s = BN_new(); |
219
|
|
|
|
|
|
|
} else { |
220
|
3
|
|
|
|
|
|
s = BN_dup(old_s); |
221
|
|
|
|
|
|
|
} |
222
|
3
|
50
|
|
|
|
|
if (NULL == s) { |
223
|
0
|
|
|
|
|
|
BN_free(r); |
224
|
0
|
|
|
|
|
|
croak("Could not duplicate unchanged ECDSA parameter"); |
225
|
|
|
|
|
|
|
} |
226
|
3
|
50
|
|
|
|
|
if (!ECDSA_SIG_set0(ecdsa_sig, r, s)) { |
227
|
0
|
|
|
|
|
|
BN_free(r); |
228
|
0
|
|
|
|
|
|
BN_free(s); |
229
|
0
|
|
|
|
|
|
croak("Could not store ECDSA parameters"); |
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
void |
233
|
|
|
|
|
|
|
set_s(ecdsa_sig, s_SV) |
234
|
|
|
|
|
|
|
ECDSA_SIG *ecdsa_sig |
235
|
|
|
|
|
|
|
SV * s_SV |
236
|
|
|
|
|
|
|
PREINIT: |
237
|
|
|
|
|
|
|
char *string; |
238
|
|
|
|
|
|
|
STRLEN len; |
239
|
|
|
|
|
|
|
BIGNUM *r; |
240
|
|
|
|
|
|
|
BIGNUM *s; |
241
|
|
|
|
|
|
|
const BIGNUM *old_r; |
242
|
|
|
|
|
|
|
CODE: |
243
|
3
|
50
|
|
|
|
|
string = SvPV(s_SV, len); |
244
|
3
|
|
|
|
|
|
s = BN_bin2bn((const unsigned char *)string, len, NULL); |
245
|
3
|
50
|
|
|
|
|
if (NULL == s) |
246
|
0
|
|
|
|
|
|
croak("Could not convert ECDSA parameter string to big number"); |
247
|
3
|
|
|
|
|
|
ECDSA_SIG_get0(ecdsa_sig, &old_r, NULL); |
248
|
3
|
50
|
|
|
|
|
if (NULL == old_r) { |
249
|
0
|
|
|
|
|
|
r = BN_new(); |
250
|
|
|
|
|
|
|
} else { |
251
|
3
|
|
|
|
|
|
r = BN_dup(old_r); |
252
|
|
|
|
|
|
|
} |
253
|
3
|
50
|
|
|
|
|
if (NULL == r) { |
254
|
0
|
|
|
|
|
|
BN_free(s); |
255
|
0
|
|
|
|
|
|
croak("Could not duplicate unchanged ECDSA parameter"); |
256
|
|
|
|
|
|
|
} |
257
|
3
|
50
|
|
|
|
|
if (!ECDSA_SIG_set0(ecdsa_sig, r, s)) { |
258
|
0
|
|
|
|
|
|
BN_free(r); |
259
|
0
|
|
|
|
|
|
BN_free(s); |
260
|
0
|
|
|
|
|
|
croak("Could not store ECDSA parameters"); |
261
|
|
|
|
|
|
|
} |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
|