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
|
|
|
|
|
|
|
CODE: |
173
|
1
|
|
|
|
|
|
to = malloc(sizeof(char) * 128); |
174
|
1
|
|
|
|
|
|
ECDSA_SIG_get0(ecdsa_sig, &r, NULL); |
175
|
1
|
|
|
|
|
|
len = BN_bn2bin(r, to); |
176
|
1
|
|
|
|
|
|
RETVAL = newSVpvn((const char*)to, len); |
177
|
1
|
|
|
|
|
|
free(to); |
178
|
|
|
|
|
|
|
OUTPUT: |
179
|
|
|
|
|
|
|
RETVAL |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
SV * |
182
|
|
|
|
|
|
|
get_s(ecdsa_sig) |
183
|
|
|
|
|
|
|
ECDSA_SIG *ecdsa_sig |
184
|
|
|
|
|
|
|
PREINIT: |
185
|
|
|
|
|
|
|
const BIGNUM *s; |
186
|
|
|
|
|
|
|
unsigned char *to; |
187
|
|
|
|
|
|
|
STRLEN len; |
188
|
|
|
|
|
|
|
CODE: |
189
|
1
|
|
|
|
|
|
to = malloc(sizeof(char) * 128); |
190
|
1
|
|
|
|
|
|
ECDSA_SIG_get0(ecdsa_sig, NULL, &s); |
191
|
1
|
|
|
|
|
|
len = BN_bn2bin(s, to); |
192
|
1
|
|
|
|
|
|
RETVAL = newSVpvn((const char*)to, len); |
193
|
1
|
|
|
|
|
|
free(to); |
194
|
|
|
|
|
|
|
OUTPUT: |
195
|
|
|
|
|
|
|
RETVAL |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
void |
198
|
|
|
|
|
|
|
set_r(ecdsa_sig, r_SV) |
199
|
|
|
|
|
|
|
ECDSA_SIG *ecdsa_sig |
200
|
|
|
|
|
|
|
SV * r_SV |
201
|
|
|
|
|
|
|
PREINIT: |
202
|
|
|
|
|
|
|
char *string; |
203
|
|
|
|
|
|
|
STRLEN len; |
204
|
|
|
|
|
|
|
BIGNUM *r; |
205
|
|
|
|
|
|
|
BIGNUM *s; |
206
|
|
|
|
|
|
|
const BIGNUM *old_s; |
207
|
|
|
|
|
|
|
CODE: |
208
|
3
|
50
|
|
|
|
|
string = SvPV(r_SV, len); |
209
|
3
|
|
|
|
|
|
r = BN_bin2bn((const unsigned char *)string, len, NULL); |
210
|
3
|
50
|
|
|
|
|
if (NULL == r) |
211
|
0
|
|
|
|
|
|
croak("Could not convert ECDSA parameter string to big number"); |
212
|
3
|
|
|
|
|
|
ECDSA_SIG_get0(ecdsa_sig, NULL, &old_s); |
213
|
3
|
50
|
|
|
|
|
if (NULL == old_s) { |
214
|
0
|
|
|
|
|
|
s = BN_new(); |
215
|
|
|
|
|
|
|
} else { |
216
|
3
|
|
|
|
|
|
s = BN_dup(old_s); |
217
|
|
|
|
|
|
|
} |
218
|
3
|
50
|
|
|
|
|
if (NULL == s) { |
219
|
0
|
|
|
|
|
|
BN_free(r); |
220
|
0
|
|
|
|
|
|
croak("Could not duplicate unchanged ECDSA parameter"); |
221
|
|
|
|
|
|
|
} |
222
|
3
|
50
|
|
|
|
|
if (!ECDSA_SIG_set0(ecdsa_sig, r, s)) { |
223
|
0
|
|
|
|
|
|
BN_free(r); |
224
|
0
|
|
|
|
|
|
BN_free(s); |
225
|
0
|
|
|
|
|
|
croak("Could not store ECDSA parameters"); |
226
|
|
|
|
|
|
|
} |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
void |
229
|
|
|
|
|
|
|
set_s(ecdsa_sig, s_SV) |
230
|
|
|
|
|
|
|
ECDSA_SIG *ecdsa_sig |
231
|
|
|
|
|
|
|
SV * s_SV |
232
|
|
|
|
|
|
|
PREINIT: |
233
|
|
|
|
|
|
|
char *string; |
234
|
|
|
|
|
|
|
STRLEN len; |
235
|
|
|
|
|
|
|
BIGNUM *r; |
236
|
|
|
|
|
|
|
BIGNUM *s; |
237
|
|
|
|
|
|
|
const BIGNUM *old_r; |
238
|
|
|
|
|
|
|
CODE: |
239
|
3
|
50
|
|
|
|
|
string = SvPV(s_SV, len); |
240
|
3
|
|
|
|
|
|
s = BN_bin2bn((const unsigned char *)string, len, NULL); |
241
|
3
|
50
|
|
|
|
|
if (NULL == s) |
242
|
0
|
|
|
|
|
|
croak("Could not convert ECDSA parameter string to big number"); |
243
|
3
|
|
|
|
|
|
ECDSA_SIG_get0(ecdsa_sig, &old_r, NULL); |
244
|
3
|
50
|
|
|
|
|
if (NULL == old_r) { |
245
|
0
|
|
|
|
|
|
r = BN_new(); |
246
|
|
|
|
|
|
|
} else { |
247
|
3
|
|
|
|
|
|
r = BN_dup(old_r); |
248
|
|
|
|
|
|
|
} |
249
|
3
|
50
|
|
|
|
|
if (NULL == r) { |
250
|
0
|
|
|
|
|
|
BN_free(s); |
251
|
0
|
|
|
|
|
|
croak("Could not duplicate unchanged ECDSA parameter"); |
252
|
|
|
|
|
|
|
} |
253
|
3
|
50
|
|
|
|
|
if (!ECDSA_SIG_set0(ecdsa_sig, r, s)) { |
254
|
0
|
|
|
|
|
|
BN_free(r); |
255
|
0
|
|
|
|
|
|
BN_free(s); |
256
|
0
|
|
|
|
|
|
croak("Could not store ECDSA parameters"); |
257
|
|
|
|
|
|
|
} |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
|