]>
Commit | Line | Data |
---|---|---|
ce9449cf | 1 | #!/usr/local/bin/perl -w |
d02b48c6 RE |
2 | # |
3 | # generate a .def file | |
4 | # | |
5 | # It does this by parsing the header files and looking for the | |
47339f61 | 6 | # prototyped functions: it then prunes the output. |
d02b48c6 | 7 | # |
948d0125 RL |
8 | # Intermediary files are created, call libeay.num and ssleay.num,... |
9 | # Previously, they had the following format: | |
10 | # | |
11 | # routine-name nnnn | |
12 | # | |
13 | # But that isn't enough for a number of reasons, the first on being that | |
14 | # this format is (needlessly) very Win32-centric, and even then... | |
15 | # One of the biggest problems is that there's no information about what | |
16 | # routines should actually be used, which varies with what crypto algorithms | |
17 | # are disabled. Also, some operating systems (for example VMS with VAX C) | |
18 | # need to keep track of the global variables as well as the functions. | |
19 | # | |
20 | # So, a remake of this script is done so as to include information on the | |
21 | # kind of symbol it is (function or variable) and what algorithms they're | |
22 | # part of. This will allow easy translating to .def files or the corresponding | |
23 | # file in other operating systems (a .opt file for VMS, possibly with a .mar | |
24 | # file). | |
25 | # | |
26 | # The format now becomes: | |
27 | # | |
28 | # routine-name nnnn info | |
29 | # | |
30 | # and the "info" part is actually a colon-separated string of fields with | |
31 | # the following meaning: | |
32 | # | |
33 | # existence:platform:kind:algorithms | |
34 | # | |
35 | # - "existence" can be "EXIST" or "NOEXIST" depending on if the symbol is | |
36 | # found somewhere in the source, | |
37 | # - "platforms" is empty if it exists on all platforms, otherwise it contains | |
38 | # comma-separated list of the platform, just as they are if the symbol exists | |
39 | # for those platforms, or prepended with a "!" if not. This helps resolve | |
40 | # symbol name replacements for platforms where the names are too long for the | |
41 | # compiler or linker, or if the systems is case insensitive and there is a | |
42 | # clash. This script assumes those redefinitions are place in the file | |
d63b8db8 RL |
43 | # crypto/symhacks.h. |
44 | # The semantics for the platforms list is a bit complicated. The rule of | |
45 | # thumb is that the list is exclusive, but it seems to mean different things. | |
46 | # So, if the list is all negatives (like "!VMS,!WIN16"), the symbol exists | |
47 | # on all platforms except those listed. If the list is all positives (like | |
48 | # "VMS,WIN16"), the symbol exists only on those platforms and nowhere else. | |
49 | # The combination of positives and negatives will act as if the positives | |
50 | # weren't there. | |
948d0125 RL |
51 | # - "kind" is "FUNCTION" or "VARIABLE". The meaning of that is obvious. |
52 | # - "algorithms" is a comma-separated list of algorithm names. This helps | |
53 | # exclude symbols that are part of an algorithm that some user wants to | |
54 | # exclude. | |
55 | # | |
d02b48c6 | 56 | |
948d0125 RL |
57 | my $crypto_num= "util/libeay.num"; |
58 | my $ssl_num= "util/ssleay.num"; | |
d02b48c6 | 59 | |
47339f61 | 60 | my $do_update = 0; |
948d0125 | 61 | my $do_rewrite = 0; |
47339f61 DSH |
62 | my $do_crypto = 0; |
63 | my $do_ssl = 0; | |
0f583f69 | 64 | my $do_ctest = 0; |
967f4ca8 | 65 | my $do_ctestall = 0; |
0f583f69 | 66 | my $rsaref = 0; |
47339f61 | 67 | |
948d0125 RL |
68 | my $VMS=0; |
69 | my $W32=0; | |
70 | my $W16=0; | |
0f583f69 | 71 | my $NT=0; |
28a98809 | 72 | # Set this to make typesafe STACK definitions appear in DEF |
e41c8d6a | 73 | my $safe_stack_def = 0; |
31ff97b2 | 74 | |
948d0125 RL |
75 | my @known_platforms = ( "__FreeBSD__", "VMS", "WIN16", "WIN32", |
76 | "WINNT", "PERL5", "NeXT" ); | |
77 | my @known_algorithms = ( "RC2", "RC4", "RC5", "IDEA", "DES", "BF", | |
78 | "CAST", "MD2", "MD4", "MD5", "SHA", "RIPEMD", | |
79 | "MDC2", "RSA", "DSA", "DH", "HMAC", "FP_API" ); | |
80 | ||
0f583f69 | 81 | my $options=""; |
31ff97b2 UM |
82 | open(IN,"<Makefile.ssl") || die "unable to open Makefile.ssl!\n"; |
83 | while(<IN>) { | |
84 | $options=$1 if (/^OPTIONS=(.*)$/); | |
85 | } | |
ce457a54 | 86 | close(IN); |
31ff97b2 | 87 | |
0f583f69 UM |
88 | # The following ciphers may be excluded (by Configure). This means functions |
89 | # defined with ifndef(NO_XXX) are not included in the .def file, and everything | |
90 | # in directory xxx is ignored. | |
91 | my $no_rc2; my $no_rc4; my $no_rc5; my $no_idea; my $no_des; my $no_bf; | |
3009458e RL |
92 | my $no_cast; |
93 | my $no_md2; my $no_md4; my $no_md5; my $no_sha; my $no_ripemd; my $no_mdc2; | |
0f583f69 | 94 | my $no_rsa; my $no_dsa; my $no_dh; my $no_hmac=0; |
948d0125 | 95 | my $no_fp_api; |
0f583f69 | 96 | |
31ff97b2 | 97 | foreach (@ARGV, split(/ /, $options)) |
d02b48c6 | 98 | { |
06c68491 | 99 | $W32=1 if $_ eq "32"; |
948d0125 | 100 | $W16=1 if $_ eq "16"; |
06c68491 DSH |
101 | if($_ eq "NT") { |
102 | $W32 = 1; | |
103 | $NT = 1; | |
104 | } | |
948d0125 | 105 | $VMS=1 if $_ eq "VMS"; |
d63b8db8 RL |
106 | $rsaref=1 if $_ eq "rsaref"; |
107 | ||
d02b48c6 | 108 | $do_ssl=1 if $_ eq "ssleay"; |
55a9cc6e | 109 | $do_ssl=1 if $_ eq "ssl"; |
d02b48c6 | 110 | $do_crypto=1 if $_ eq "libeay"; |
55a9cc6e DSH |
111 | $do_crypto=1 if $_ eq "crypto"; |
112 | $do_update=1 if $_ eq "update"; | |
948d0125 | 113 | $do_rewrite=1 if $_ eq "rewrite"; |
12aefe78 | 114 | $do_ctest=1 if $_ eq "ctest"; |
967f4ca8 | 115 | $do_ctestall=1 if $_ eq "ctestall"; |
a8b07aa4 | 116 | #$safe_stack_def=1 if $_ eq "-DDEBUG_SAFESTACK"; |
8cf65228 UM |
117 | |
118 | if (/^no-rc2$/) { $no_rc2=1; } | |
119 | elsif (/^no-rc4$/) { $no_rc4=1; } | |
120 | elsif (/^no-rc5$/) { $no_rc5=1; } | |
121 | elsif (/^no-idea$/) { $no_idea=1; } | |
122 | elsif (/^no-des$/) { $no_des=1; } | |
123 | elsif (/^no-bf$/) { $no_bf=1; } | |
124 | elsif (/^no-cast$/) { $no_cast=1; } | |
125 | elsif (/^no-md2$/) { $no_md2=1; } | |
3009458e | 126 | elsif (/^no-md4$/) { $no_md4=1; } |
8cf65228 UM |
127 | elsif (/^no-md5$/) { $no_md5=1; } |
128 | elsif (/^no-sha$/) { $no_sha=1; } | |
129 | elsif (/^no-ripemd$/) { $no_ripemd=1; } | |
130 | elsif (/^no-mdc2$/) { $no_mdc2=1; } | |
131 | elsif (/^no-rsa$/) { $no_rsa=1; } | |
132 | elsif (/^no-dsa$/) { $no_dsa=1; } | |
133 | elsif (/^no-dh$/) { $no_dh=1; } | |
134 | elsif (/^no-hmac$/) { $no_hmac=1; } | |
d02b48c6 RE |
135 | } |
136 | ||
12aefe78 | 137 | |
948d0125 RL |
138 | # If no platform is given, assume WIN32 |
139 | if ($W32 + $W16 + $VMS == 0) { | |
140 | $W32 = 1; | |
141 | } | |
142 | ||
143 | # Add extra knowledge | |
144 | if ($W16) { | |
145 | $no_fp_api=1; | |
146 | } | |
147 | ||
d02b48c6 RE |
148 | if (!$do_ssl && !$do_crypto) |
149 | { | |
47339f61 | 150 | print STDERR "usage: $0 ( ssl | crypto ) [ 16 | 32 | NT ] [rsaref]\n"; |
d02b48c6 RE |
151 | exit(1); |
152 | } | |
153 | ||
154 | %ssl_list=&load_numbers($ssl_num); | |
55a9cc6e | 155 | $max_ssl = $max_num; |
d02b48c6 | 156 | %crypto_list=&load_numbers($crypto_num); |
55a9cc6e | 157 | $max_crypto = $max_num; |
d02b48c6 | 158 | |
0f583f69 | 159 | my $ssl="ssl/ssl.h"; |
d02b48c6 | 160 | |
0f583f69 | 161 | my $crypto ="crypto/crypto.h"; |
8cf65228 UM |
162 | $crypto.=" crypto/des/des.h" unless $no_des; |
163 | $crypto.=" crypto/idea/idea.h" unless $no_idea; | |
164 | $crypto.=" crypto/rc4/rc4.h" unless $no_rc4; | |
165 | $crypto.=" crypto/rc5/rc5.h" unless $no_rc5; | |
166 | $crypto.=" crypto/rc2/rc2.h" unless $no_rc2; | |
167 | $crypto.=" crypto/bf/blowfish.h" unless $no_bf; | |
168 | $crypto.=" crypto/cast/cast.h" unless $no_cast; | |
169 | $crypto.=" crypto/md2/md2.h" unless $no_md2; | |
3009458e | 170 | $crypto.=" crypto/md4/md4.h" unless $no_md4; |
8cf65228 UM |
171 | $crypto.=" crypto/md5/md5.h" unless $no_md5; |
172 | $crypto.=" crypto/mdc2/mdc2.h" unless $no_mdc2; | |
173 | $crypto.=" crypto/sha/sha.h" unless $no_sha; | |
174 | $crypto.=" crypto/ripemd/ripemd.h" unless $no_ripemd; | |
d02b48c6 RE |
175 | |
176 | $crypto.=" crypto/bn/bn.h"; | |
8cf65228 UM |
177 | $crypto.=" crypto/rsa/rsa.h" unless $no_rsa; |
178 | $crypto.=" crypto/dsa/dsa.h" unless $no_dsa; | |
179 | $crypto.=" crypto/dh/dh.h" unless $no_dh; | |
180 | $crypto.=" crypto/hmac/hmac.h" unless $no_hmac; | |
d02b48c6 RE |
181 | |
182 | $crypto.=" crypto/stack/stack.h"; | |
183 | $crypto.=" crypto/buffer/buffer.h"; | |
184 | $crypto.=" crypto/bio/bio.h"; | |
c22e4b19 | 185 | $crypto.=" crypto/dso/dso.h"; |
d02b48c6 RE |
186 | $crypto.=" crypto/lhash/lhash.h"; |
187 | $crypto.=" crypto/conf/conf.h"; | |
188 | $crypto.=" crypto/txt_db/txt_db.h"; | |
189 | ||
190 | $crypto.=" crypto/evp/evp.h"; | |
191 | $crypto.=" crypto/objects/objects.h"; | |
192 | $crypto.=" crypto/pem/pem.h"; | |
193 | #$crypto.=" crypto/meth/meth.h"; | |
194 | $crypto.=" crypto/asn1/asn1.h"; | |
195 | $crypto.=" crypto/asn1/asn1_mac.h"; | |
196 | $crypto.=" crypto/err/err.h"; | |
197 | $crypto.=" crypto/pkcs7/pkcs7.h"; | |
ee0508d4 | 198 | $crypto.=" crypto/pkcs12/pkcs12.h"; |
d02b48c6 RE |
199 | $crypto.=" crypto/x509/x509.h"; |
200 | $crypto.=" crypto/x509/x509_vfy.h"; | |
679ab7c3 | 201 | $crypto.=" crypto/x509v3/x509v3.h"; |
d02b48c6 | 202 | $crypto.=" crypto/rand/rand.h"; |
dfeab068 RE |
203 | $crypto.=" crypto/comp/comp.h"; |
204 | $crypto.=" crypto/tmdiff.h"; | |
d02b48c6 | 205 | |
948d0125 | 206 | my $symhacks="crypto/symhacks.h"; |
55a9cc6e | 207 | |
948d0125 RL |
208 | my @ssl_symbols = &do_defs("SSLEAY", $ssl, $symhacks); |
209 | my @crypto_symbols = &do_defs("LIBEAY", $crypto, $symhacks); | |
47339f61 | 210 | |
55a9cc6e DSH |
211 | if ($do_update) { |
212 | ||
213 | if ($do_ssl == 1) { | |
948d0125 RL |
214 | |
215 | &maybe_add_info("SSLEAY",*ssl_list,@ssl_symbols); | |
216 | if ($do_rewrite == 1) { | |
217 | open(OUT, ">$ssl_num"); | |
218 | &rewrite_numbers(*OUT,"SSLEAY",*ssl_list,@ssl_symbols); | |
219 | close OUT; | |
220 | } else { | |
221 | open(OUT, ">>$ssl_num"); | |
222 | } | |
223 | &update_numbers(*OUT,"SSLEAY",*ssl_list,$max_ssl,@ssl_symbols); | |
55a9cc6e DSH |
224 | close OUT; |
225 | } | |
226 | ||
227 | if($do_crypto == 1) { | |
948d0125 RL |
228 | |
229 | &maybe_add_info("LIBEAY",*crypto_list,@crypto_symbols); | |
230 | if ($do_rewrite == 1) { | |
231 | open(OUT, ">$crypto_num"); | |
232 | &rewrite_numbers(*OUT,"LIBEAY",*crypto_list,@crypto_symbols); | |
233 | } else { | |
234 | open(OUT, ">>$crypto_num"); | |
235 | } | |
236 | &update_numbers(*OUT,"LIBEAY",*crypto_list,$max_crypto,@crypto_symbols); | |
55a9cc6e | 237 | close OUT; |
12aefe78 DSH |
238 | } |
239 | ||
967f4ca8 | 240 | } elsif ($do_ctest || $do_ctestall) { |
12aefe78 DSH |
241 | |
242 | print <<"EOF"; | |
243 | ||
244 | /* Test file to check all DEF file symbols are present by trying | |
245 | * to link to all of them. This is *not* intended to be run! | |
246 | */ | |
247 | ||
248 | int main() | |
249 | { | |
250 | EOF | |
948d0125 | 251 | &print_test_file(*STDOUT,"SSLEAY",*ssl_list,$do_ctestall,@ssl_symbols) |
12aefe78 DSH |
252 | if $do_ssl == 1; |
253 | ||
948d0125 | 254 | &print_test_file(*STDOUT,"LIBEAY",*crypto_list,$do_ctestall,@crypto_symbols) |
12aefe78 DSH |
255 | if $do_crypto == 1; |
256 | ||
257 | print "}\n"; | |
55a9cc6e DSH |
258 | |
259 | } else { | |
8cf65228 | 260 | |
948d0125 | 261 | &print_def_file(*STDOUT,"SSLEAY",*ssl_list,@ssl_symbols) |
55a9cc6e DSH |
262 | if $do_ssl == 1; |
263 | ||
948d0125 | 264 | &print_def_file(*STDOUT,"LIBEAY",*crypto_list,@crypto_symbols) |
55a9cc6e | 265 | if $do_crypto == 1; |
8cf65228 | 266 | |
55a9cc6e | 267 | } |
d02b48c6 | 268 | |
d02b48c6 RE |
269 | |
270 | sub do_defs | |
47339f61 | 271 | { |
948d0125 | 272 | my($name,$files,$symhacksfile)=@_; |
0f583f69 | 273 | my $file; |
47339f61 | 274 | my @ret; |
948d0125 RL |
275 | my %syms; |
276 | my %platform; # For anything undefined, we assume "" | |
277 | my %kind; # For anything undefined, we assume "FUNCTION" | |
278 | my %algorithm; # For anything undefined, we assume "" | |
279 | my %rename; | |
0f583f69 | 280 | my $cpp; |
d02b48c6 | 281 | |
948d0125 | 282 | foreach $file (split(/\s+/,$symhacksfile." ".$files)) |
d02b48c6 | 283 | { |
d02b48c6 | 284 | open(IN,"<$file") || die "unable to open $file:$!\n"; |
0f583f69 | 285 | my $line = "", my $def= ""; |
47339f61 | 286 | my %tag = ( |
948d0125 RL |
287 | (map { $_ => 0 } @known_platforms), |
288 | (map { "NO_".$_ => 0 } @known_algorithms), | |
47339f61 | 289 | NOPROTO => 0, |
47339f61 DSH |
290 | PERL5 => 0, |
291 | _WINDLL => 0, | |
47339f61 DSH |
292 | CONST_STRICT => 0, |
293 | TRUE => 1, | |
294 | ); | |
948d0125 | 295 | my $symhacking = $file eq $symhacksfile; |
47339f61 DSH |
296 | while(<IN>) { |
297 | last if (/BEGIN ERROR CODES/); | |
298 | if ($line ne '') { | |
299 | $_ = $line . $_; | |
300 | $line = ''; | |
d02b48c6 | 301 | } |
47339f61 DSH |
302 | |
303 | if (/\\$/) { | |
304 | $line = $_; | |
305 | next; | |
306 | } | |
307 | ||
948d0125 | 308 | $cpp = 1 if /^\#.*ifdef.*cplusplus/; |
47339f61 | 309 | if ($cpp) { |
948d0125 | 310 | $cpp = 0 if /^\#.*endif/; |
47339f61 DSH |
311 | next; |
312 | } | |
313 | ||
314 | s/\/\*.*?\*\///gs; # ignore comments | |
315 | s/{[^{}]*}//gs; # ignore {} blocks | |
316 | if (/^\#\s*ifndef (.*)/) { | |
d02b48c6 RE |
317 | push(@tag,$1); |
318 | $tag{$1}=-1; | |
47339f61 | 319 | } elsif (/^\#\s*if !defined\(([^\)]+)\)/) { |
d02b48c6 RE |
320 | push(@tag,$1); |
321 | $tag{$1}=-1; | |
47339f61 | 322 | } elsif (/^\#\s*ifdef (.*)/) { |
d02b48c6 RE |
323 | push(@tag,$1); |
324 | $tag{$1}=1; | |
948d0125 | 325 | } elsif (/^\#\s*if defined\(([^\)]+)\)/) { |
d02b48c6 RE |
326 | push(@tag,$1); |
327 | $tag{$1}=1; | |
948d0125 RL |
328 | } elsif (/^\#\s*error\s+(\w+) is disabled\./) { |
329 | if ($tag[$#tag] eq "NO_".$1) { | |
330 | $tag{$tag[$#tag]}=2; | |
331 | } | |
47339f61 | 332 | } elsif (/^\#\s*endif/) { |
948d0125 RL |
333 | if ($tag{$tag[$#tag]}==2) { |
334 | $tag{$tag[$#tag]}=-1; | |
335 | } else { | |
336 | $tag{$tag[$#tag]}=0; | |
337 | } | |
d02b48c6 | 338 | pop(@tag); |
47339f61 DSH |
339 | } elsif (/^\#\s*else/) { |
340 | my $t=$tag[$#tag]; | |
d02b48c6 | 341 | $tag{$t}= -$tag{$t}; |
47339f61 DSH |
342 | } elsif (/^\#\s*if\s+1/) { |
343 | # Dummy tag | |
344 | push(@tag,"TRUE"); | |
345 | $tag{"TRUE"}=1; | |
1e414935 BM |
346 | } elsif (/^\#\s*if\s+0/) { |
347 | # Dummy tag | |
348 | push(@tag,"TRUE"); | |
349 | $tag{"TRUE"}=-1; | |
948d0125 RL |
350 | } elsif (/^\#\s*define\s+(\w+)\s+(\w+)/ |
351 | && $symhacking) { | |
352 | my $s = $1; | |
353 | my $a = | |
354 | $2.":".join(",", grep(!/^$/, | |
355 | map { $tag{$_} == 1 ? | |
356 | $_ : "" } | |
357 | @known_platforms)); | |
358 | $rename{$s} = $a; | |
359 | } | |
360 | if (/^\#/) { | |
361 | my @p = grep(!/^$/, | |
362 | map { $tag{$_} == 1 ? $_ : | |
363 | $tag{$_} == -1 ? "!".$_ : "" } | |
364 | @known_platforms); | |
365 | my @a = grep(!/^$/, | |
366 | map { $tag{"NO_".$_} == -1 ? $_ : "" } | |
367 | @known_algorithms); | |
368 | $def .= "#INFO:".join(',',@p).":".join(',',@a).";"; | |
47339f61 DSH |
369 | next; |
370 | } | |
13083215 | 371 | if (/^\s*DECLARE_STACK_OF\s*\(\s*(\w*)\s*\)/) { |
a8b07aa4 | 372 | next; |
948d0125 RL |
373 | } elsif (/^\s*DECLARE_PKCS12_STACK_OF\s*\(\s*(\w*)\s*\)/) { |
374 | next; | |
13083215 | 375 | } elsif (/^\s*DECLARE_ASN1_SET_OF\s*\(\s*(\w*)\s*\)/) { |
a8b07aa4 | 376 | next; |
dbd665c2 | 377 | } elsif (/^DECLARE_PEM_rw\s*\(\s*(\w*)\s*,/ || |
948d0125 RL |
378 | /^DECLARE_PEM_rw_cb\s*\(\s*(\w*)\s*,/ ) { |
379 | # Things not in Win16 | |
380 | $syms{"PEM_read_${1}"} = 1; | |
381 | $platform{"PEM_read_${1}"} = "!WIN16"; | |
382 | $syms{"PEM_write_${1}"} = 1; | |
383 | $platform{"PEM_write_${1}"} = "!WIN16"; | |
384 | # Things that are everywhere | |
385 | $syms{"PEM_read_bio_${1}"} = 1; | |
386 | $syms{"PEM_write_bio_${1}"} = 1; | |
387 | if ($1 eq "RSAPrivateKey" || | |
388 | $1 eq "RSAPublicKey" || | |
389 | $1 eq "RSA_PUBKEY") { | |
390 | $algorithm{"PEM_read_${1}"} = "RSA"; | |
391 | $algorithm{"PEM_write_${1}"} = "RSA"; | |
392 | $algorithm{"PEM_read_bio_${1}"} = "RSA"; | |
393 | $algorithm{"PEM_write_bio_${1}"} = "RSA"; | |
394 | } | |
395 | elsif ($1 eq "DSAPrivateKey" || | |
396 | $1 eq "DSAparams" || | |
397 | $1 eq "RSA_PUBKEY") { | |
398 | $algorithm{"PEM_read_${1}"} = "DSA"; | |
399 | $algorithm{"PEM_write_${1}"} = "DSA"; | |
400 | $algorithm{"PEM_read_bio_${1}"} = "DSA"; | |
401 | $algorithm{"PEM_write_bio_${1}"} = "DSA"; | |
402 | } | |
403 | elsif ($1 eq "DHparams") { | |
404 | $algorithm{"PEM_read_${1}"} = "DH"; | |
405 | $algorithm{"PEM_write_${1}"} = "DH"; | |
406 | $algorithm{"PEM_read_bio_${1}"} = "DH"; | |
407 | $algorithm{"PEM_write_bio_${1}"} = "DH"; | |
dbd665c2 | 408 | } |
8a208cba DSH |
409 | } elsif (/^DECLARE_PEM_write\s*\(\s*(\w*)\s*,/ || |
410 | /^DECLARE_PEM_write_cb\s*\(\s*(\w*)\s*,/ ) { | |
948d0125 RL |
411 | # Things not in Win16 |
412 | $syms{"PEM_write_${1}"} = 1; | |
413 | $platform{"PEM_write_${1}"} .= ",!WIN16"; | |
414 | # Things that are everywhere | |
415 | $syms{"PEM_write_bio_${1}"} = 1; | |
416 | if ($1 eq "RSAPrivateKey" || | |
417 | $1 eq "RSAPublicKey" || | |
418 | $1 eq "RSA_PUBKEY") { | |
419 | $algorithm{"PEM_write_${1}"} = "RSA"; | |
420 | $algorithm{"PEM_write_bio_${1}"} = "RSA"; | |
421 | } | |
422 | elsif ($1 eq "DSAPrivateKey" || | |
423 | $1 eq "DSAparams" || | |
424 | $1 eq "RSA_PUBKEY") { | |
425 | $algorithm{"PEM_write_${1}"} = "DSA"; | |
426 | $algorithm{"PEM_write_bio_${1}"} = "DSA"; | |
427 | } | |
428 | elsif ($1 eq "DHparams") { | |
429 | $algorithm{"PEM_write_${1}"} = "DH"; | |
430 | $algorithm{"PEM_write_bio_${1}"} = "DH"; | |
8a208cba | 431 | } |
8a208cba DSH |
432 | } elsif (/^DECLARE_PEM_read\s*\(\s*(\w*)\s*,/ || |
433 | /^DECLARE_PEM_read_cb\s*\(\s*(\w*)\s*,/ ) { | |
948d0125 RL |
434 | # Things not in Win16 |
435 | $syms{"PEM_read_${1}"} = 1; | |
436 | $platform{"PEM_read_${1}"} .= ",!WIN16"; | |
437 | # Things that are everywhere | |
438 | $syms{"PEM_read_bio_${1}"} = 1; | |
0f583f69 | 439 | } elsif ( |
948d0125 RL |
440 | ($tag{'TRUE'} != -1) |
441 | && ($tag{'CONST_STRICT'} != 1) | |
442 | ) | |
d02b48c6 | 443 | { |
948d0125 | 444 | if (/\{|\/\*|\([^\)]*$/) { |
47339f61 DSH |
445 | $line = $_; |
446 | } else { | |
447 | $def .= $_; | |
448 | } | |
d02b48c6 RE |
449 | } |
450 | } | |
451 | close(IN); | |
47339f61 | 452 | |
948d0125 RL |
453 | my $algs; |
454 | my $plays; | |
455 | ||
47339f61 | 456 | foreach (split /;/, $def) { |
948d0125 | 457 | my $s; my $k = "FUNCTION"; my $p; my $a; |
47339f61 DSH |
458 | s/^[\n\s]*//g; |
459 | s/[\n\s]*$//g; | |
948d0125 | 460 | next if(/\#undef/); |
47339f61 | 461 | next if(/typedef\W/); |
948d0125 RL |
462 | next if(/\#define/); |
463 | ||
464 | if (/^\#INFO:([^:]*):(.*)$/) { | |
465 | $plats = $1; | |
466 | $algs = $2; | |
467 | next; | |
468 | } elsif (/^\s*OPENSSL_EXTERN\s.*?(\w+)(\[[0-9]*\])*\s*$/) { | |
469 | $s = $1; | |
470 | $k = "VARIABLE"; | |
471 | } elsif (/\(\*(\w*)\([^\)]+/) { | |
472 | $s = $1; | |
47339f61 DSH |
473 | } elsif (/\w+\W+(\w+)\W*\(\s*\)$/s) { |
474 | # K&R C | |
475 | next; | |
476 | } elsif (/\w+\W+\w+\W*\(.*\)$/s) { | |
477 | while (not /\(\)$/s) { | |
478 | s/[^\(\)]*\)$/\)/s; | |
479 | s/\([^\(\)]*\)\)$/\)/s; | |
480 | } | |
481 | s/\(void\)//; | |
482 | /(\w+)\W*\(\)/s; | |
948d0125 | 483 | $s = $1; |
47339f61 DSH |
484 | } elsif (/\(/ and not (/=/)) { |
485 | print STDERR "File $file: cannot parse: $_;\n"; | |
948d0125 RL |
486 | next; |
487 | } else { | |
488 | next; | |
489 | } | |
490 | ||
491 | $syms{$s} = 1; | |
492 | $kind{$s} = $k; | |
493 | ||
494 | $p = $plats; | |
495 | $a = $algs; | |
496 | $a .= ",BF" if($s =~ /EVP_bf/); | |
497 | $a .= ",CAST" if($s =~ /EVP_cast/); | |
498 | $a .= ",DES" if($s =~ /EVP_des/); | |
499 | $a .= ",DSA" if($s =~ /EVP_dss/); | |
500 | $a .= ",IDEA" if($s =~ /EVP_idea/); | |
501 | $a .= ",MD2" if($s =~ /EVP_md2/); | |
502 | $a .= ",MD4" if($s =~ /EVP_md4/); | |
503 | $a .= ",MD5" if($s =~ /EVP_md5/); | |
504 | $a .= ",RC2" if($s =~ /EVP_rc2/); | |
505 | $a .= ",RC4" if($s =~ /EVP_rc4/); | |
506 | $a .= ",RC5" if($s =~ /EVP_rc5/); | |
507 | $a .= ",RIPEMD" if($s =~ /EVP_ripemd/); | |
508 | $a .= ",SHA" if($s =~ /EVP_sha/); | |
509 | $a .= ",RSA" if($s =~ /EVP_(Open|Seal)(Final|Init)/); | |
510 | $a .= ",RSA" if($s =~ /PEM_Seal(Final|Init|Update)/); | |
511 | $a .= ",RSA" if($s =~ /RSAPrivateKey/); | |
512 | $a .= ",RSA" if($s =~ /SSLv23?_((client|server)_)?method/); | |
513 | ||
514 | $platform{$s} .= ','.$p; | |
515 | $algorithm{$s} .= ','.$a; | |
516 | ||
517 | if (defined($rename{$s})) { | |
518 | (my $r, my $p) = split(/:/,$rename{$s}); | |
519 | my @ip = map { /^!(.*)$/ ? $1 : "!".$_ } split /,/, $p; | |
520 | $syms{$r} = 1; | |
521 | $kind{$r} = $kind{$s}."(".$s.")"; | |
522 | $algorithm{$r} = $algorithm{$s}; | |
523 | $platform{$r} = $platform{$s}.",".$p; | |
524 | $platform{$s} .= ','.join(',', @ip).','.join(',', @ip); | |
47339f61 | 525 | } |
d02b48c6 | 526 | } |
d02b48c6 RE |
527 | } |
528 | ||
948d0125 | 529 | # Prune the returned symbols |
47339f61 | 530 | |
948d0125 | 531 | $platform{"crypt"} .= ",!PERL5,!__FreeBSD__,!NeXT"; |
47339f61 | 532 | |
948d0125 RL |
533 | delete $syms{"SSL_add_dir_cert_subjects_to_stack"}; |
534 | delete $syms{"bn_dump1"}; | |
535 | ||
536 | $platform{"BIO_s_file_internal"} .= ",WIN16"; | |
537 | $platform{"BIO_new_file_internal"} .= ",WIN16"; | |
538 | $platform{"BIO_new_fp_internal"} .= ",WIN16"; | |
539 | ||
540 | $platform{"BIO_s_file"} .= ",!WIN16"; | |
541 | $platform{"BIO_new_file"} .= ",!WIN16"; | |
542 | $platform{"BIO_new_fp"} .= ",!WIN16"; | |
543 | ||
544 | $platform{"BIO_s_log"} .= ",!WIN32,!WIN16,!macintosh"; | |
545 | ||
546 | if(exists $syms{"ERR_load_CRYPTO_strings"}) { | |
547 | $platform{"ERR_load_CRYPTO_strings"} .= ",!VMS,!WIN16"; | |
548 | $syms{"ERR_load_CRYPTOlib_strings"} = 1; | |
549 | $platform{"ERR_load_CRYPTOlib_strings"} .= ",VMS,WIN16"; | |
550 | } | |
551 | ||
552 | # Info we know about | |
553 | ||
554 | $platform{"RSA_PKCS1_RSAref"} = "RSAREF"; | |
555 | $algorithm{"RSA_PKCS1_RSAref"} = "RSA"; | |
556 | ||
557 | push @ret, map { $_."\\".&info_string($_,"EXIST", | |
558 | $platform{$_}, | |
559 | $kind{$_}, | |
560 | $algorithm{$_}) } keys %syms; | |
561 | ||
562 | return(@ret); | |
563 | } | |
564 | ||
565 | sub info_string { | |
566 | (my $symbol, my $exist, my $platforms, my $kind, my $algorithms) = @_; | |
567 | ||
568 | my %a = defined($algorithms) ? | |
569 | map { $_ => 1 } split /,/, $algorithms : (); | |
570 | my $pl = defined($platforms) ? $platforms : ""; | |
571 | my %p = map { $_ => 0 } split /,/, $pl; | |
572 | my $k = defined($kind) ? $kind : "FUNCTION"; | |
573 | my $ret; | |
574 | ||
575 | # We do this, because if there's code like the following, it really | |
576 | # means the function exists in all cases and should therefore be | |
577 | # everywhere. By increasing and decreasing, we may attain 0: | |
578 | # | |
579 | # ifndef WIN16 | |
580 | # int foo(); | |
581 | # else | |
582 | # int _fat foo(); | |
583 | # endif | |
584 | foreach $platform (split /,/, $pl) { | |
585 | if ($platform =~ /^!(.*)$/) { | |
586 | $p{$1}--; | |
587 | } else { | |
588 | $p{$platform}++; | |
d02b48c6 | 589 | } |
47339f61 | 590 | } |
948d0125 RL |
591 | foreach $platform (keys %p) { |
592 | if ($p{$platform} == 0) { delete $p{$platform}; } | |
d02b48c6 RE |
593 | } |
594 | ||
948d0125 RL |
595 | delete $p{""}; |
596 | delete $a{""}; | |
d02b48c6 | 597 | |
948d0125 RL |
598 | $ret = $exist; |
599 | $ret .= ":".join(',',map { $p{$_} < 0 ? "!".$_ : $_ } keys %p); | |
600 | $ret .= ":".$k; | |
601 | $ret .= ":".join(',',keys %a); | |
602 | return $ret; | |
603 | } | |
604 | ||
605 | sub maybe_add_info { | |
606 | (my $name, *nums, my @symbols) = @_; | |
607 | my $sym; | |
608 | my $new_info = 0; | |
609 | ||
610 | print STDERR "Updating $name info\n"; | |
611 | foreach $sym (@symbols) { | |
612 | (my $s, my $i) = split /\\/, $sym; | |
613 | $i =~ s/^(.*?:.*?:\w+)(\(\w+\))?/$1/; | |
614 | if (defined($nums{$s})) { | |
615 | (my $n, my $dummy) = split /\\/, $nums{$s}; | |
616 | if (!defined($dummy) || $i ne $dummy) { | |
617 | $nums{$s} = $n."\\".$i; | |
618 | $new_info++; | |
619 | #print STDERR "DEBUG: maybe_add_info for $s: \"$dummy\" => \"$i\"\n"; | |
620 | } | |
621 | } | |
622 | } | |
623 | if ($new_info) { | |
624 | print STDERR "$new_info old symbols got an info update\n"; | |
625 | } else { | |
626 | print STDERR "No old symbols needed info update\n"; | |
627 | } | |
47339f61 | 628 | } |
d02b48c6 | 629 | |
12aefe78 DSH |
630 | sub print_test_file |
631 | { | |
948d0125 | 632 | (*OUT,my $name,*nums,my @symbols)=@_; |
0f583f69 | 633 | my $n = 1; my @e; my @r; |
948d0125 RL |
634 | my $sym; my $prev = ""; my $prefSSLeay; |
635 | ||
636 | (@e)=grep(/^SSLeay\\.*?:.*?:FUNCTION/,@symbols); | |
637 | (@r)=grep(/^\w+\\.*?:.*?:FUNCTION/ && !/^SSLeay\\.*?:.*?:FUNCTION/,@symbols); | |
638 | @symbols=((sort @e),(sort @r)); | |
639 | ||
640 | foreach $sym (@symbols) { | |
641 | (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/; | |
642 | if ($s ne $prev) { | |
643 | if (!defined($nums{$sym})) { | |
644 | printf STDERR "Warning: $sym does not have a number assigned\n" | |
645 | if(!$do_update); | |
967f4ca8 | 646 | } else { |
948d0125 RL |
647 | $n=$nums{$s}; |
648 | print OUT "\t$s();\n"; | |
967f4ca8 | 649 | } |
12aefe78 | 650 | } |
948d0125 | 651 | $prev = $s; # To avoid duplicates... |
12aefe78 DSH |
652 | } |
653 | } | |
654 | ||
d02b48c6 | 655 | sub print_def_file |
47339f61 | 656 | { |
948d0125 | 657 | (*OUT,my $name,*nums,my @symbols)=@_; |
0f583f69 | 658 | my $n = 1; my @e; my @r; |
d02b48c6 | 659 | |
06c68491 | 660 | if ($W32) |
d02b48c6 RE |
661 | { $name.="32"; } |
662 | else | |
663 | { $name.="16"; } | |
664 | ||
665 | print OUT <<"EOF"; | |
666 | ; | |
9b3086fe | 667 | ; Definition file for the DLL version of the $name library from OpenSSL |
d02b48c6 RE |
668 | ; |
669 | ||
670 | LIBRARY $name | |
671 | ||
9b3086fe | 672 | DESCRIPTION 'OpenSSL $name - http://www.openssl.org/' |
d02b48c6 RE |
673 | |
674 | EOF | |
675 | ||
47339f61 | 676 | if (!$W32) { |
d02b48c6 RE |
677 | print <<"EOF"; |
678 | CODE PRELOAD MOVEABLE | |
679 | DATA PRELOAD MOVEABLE SINGLE | |
680 | ||
681 | EXETYPE WINDOWS | |
682 | ||
683 | HEAPSIZE 4096 | |
684 | STACKSIZE 8192 | |
685 | ||
686 | EOF | |
47339f61 | 687 | } |
d02b48c6 RE |
688 | |
689 | print "EXPORTS\n"; | |
690 | ||
948d0125 RL |
691 | (@e)=grep(/^SSLeay\\.*?:.*?:FUNCTION/,@symbols); |
692 | (@r)=grep(/^\w+\\.*?:.*?:FUNCTION/ && !/^SSLeay\\.*?:.*?:FUNCTION/,@symbols); | |
693 | @symbols=((sort @e),(sort @r)); | |
d02b48c6 | 694 | |
d02b48c6 | 695 | |
948d0125 RL |
696 | foreach $sym (@symbols) { |
697 | (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/; | |
698 | if (!defined($nums{$s})) { | |
699 | printf STDERR "Warning: $s does not have a number assigned\n" | |
8cf65228 | 700 | if(!$do_update); |
47339f61 | 701 | } else { |
948d0125 | 702 | (my $n, my $i) = split /\\/, $nums{$s}; |
d63b8db8 | 703 | my %pf = (); |
948d0125 | 704 | my @p = split(/,/, ($i =~ /^.*?:(.*?):/,$1)); |
d63b8db8 RL |
705 | # @p_purged must contain hardware platforms only |
706 | my @p_purged = (); | |
707 | foreach $ptmp (@p) { | |
708 | next if $ptmp =~ /^!?RSAREF$/; | |
709 | push @p_purged, $ptmp; | |
710 | } | |
711 | my $negatives = !!grep(/^!/,@p); | |
965c1775 | 712 | # It is very important to check NT before W32 |
d63b8db8 RL |
713 | if ((($NT && (!@p_purged |
714 | || (!$negatives && grep(/^WINNT$/,@p)) | |
715 | || ($negatives && !grep(/^!WINNT$/,@p)))) | |
716 | || ($W32 && (!@p_purged | |
717 | || (!$negatives && grep(/^WIN32$/,@p)) | |
718 | || ($negatives && !grep(/^!WIN32$/,@p)))) | |
719 | || ($W16 && (!@p_purged | |
720 | || (!$negatives && grep(/^WIN16$/,@p)) | |
721 | || ($negatives && !grep(/^!WIN16$/,@p))))) | |
722 | && (!@p | |
723 | || (!$negatives | |
724 | && ($rsaref || !grep(/^RSAREF$/,@p))) | |
725 | || ($negatives | |
726 | && (!$rsaref || !grep(/^!RSAREF$/,@p))))) { | |
965c1775 | 727 | printf OUT " %s%-40s@%d\n",($W32)?"":"_",$s,$n; |
d63b8db8 RL |
728 | # } else { |
729 | # print STDERR "DEBUG: \"$sym\" (@p):", | |
730 | # " rsaref:", !!(!@p | |
731 | # || (!$negatives | |
732 | # && ($rsaref || !grep(/^RSAREF$/,@p))) | |
733 | # || ($negatives | |
734 | # && (!$rsaref || !grep(/^!RSAREF$/,@p))))?1:0, | |
735 | # " 16:", !!($W16 && (!@p_purged | |
736 | # || (!$negatives && grep(/^WIN16$/,@p)) | |
737 | # || ($negatives && !grep(/^!WIN16$/,@p)))), | |
738 | # " 32:", !!($W32 && (!@p_purged | |
739 | # || (!$negatives && grep(/^WIN32$/,@p)) | |
740 | # || ($negatives && !grep(/^!WIN32$/,@p)))), | |
741 | # " NT:", !!($NT && (!@p_purged | |
742 | # || (!$negatives && grep(/^WINNT$/,@p)) | |
743 | # || ($negatives && !grep(/^!WINNT$/,@p)))), | |
744 | # "\n"; | |
965c1775 | 745 | } |
d02b48c6 | 746 | } |
d02b48c6 | 747 | } |
47339f61 DSH |
748 | printf OUT "\n"; |
749 | } | |
d02b48c6 RE |
750 | |
751 | sub load_numbers | |
47339f61 DSH |
752 | { |
753 | my($name)=@_; | |
754 | my(@a,%ret); | |
d02b48c6 | 755 | |
55a9cc6e | 756 | $max_num = 0; |
948d0125 RL |
757 | $num_noinfo = 0; |
758 | $prev = ""; | |
55a9cc6e | 759 | |
d02b48c6 | 760 | open(IN,"<$name") || die "unable to open $name:$!\n"; |
47339f61 | 761 | while (<IN>) { |
d02b48c6 RE |
762 | chop; |
763 | s/#.*$//; | |
764 | next if /^\s*$/; | |
765 | @a=split; | |
948d0125 RL |
766 | if (defined $ret{$a[0]}) { |
767 | print STDERR "Warning: Symbol '",$a[0],"' redefined. old=",$ret{$a[0]},", new=",$a[1],"\n"; | |
768 | } | |
769 | if ($max_num > $a[1]) { | |
770 | print STDERR "Warning: Number decreased from ",$max_num," to ",$a[1],"\n"; | |
771 | } | |
772 | if ($max_num == $a[1]) { | |
773 | # This is actually perfectly OK | |
774 | #print STDERR "Warning: Symbol ",$a[0]," has same number as previous ",$prev,": ",$a[1],"\n"; | |
775 | } | |
776 | if ($#a < 2) { | |
777 | # Existence will be proven later, in do_defs | |
778 | $ret{$a[0]}=$a[1]; | |
779 | $num_noinfo++; | |
780 | } else { | |
781 | $ret{$a[0]}=$a[1]."\\".$a[2]; # \\ is a special marker | |
782 | } | |
55a9cc6e | 783 | $max_num = $a[1] if $a[1] > $max_num; |
948d0125 RL |
784 | $prev=$a[0]; |
785 | } | |
786 | if ($num_noinfo) { | |
787 | print STDERR "Warning: $num_noinfo symbols were without info."; | |
788 | if ($do_rewrite) { | |
789 | printf STDERR " The rewrite will fix this.\n"; | |
790 | } else { | |
791 | printf STDERR " You should do a rewrite to fix this.\n"; | |
792 | } | |
47339f61 | 793 | } |
d02b48c6 RE |
794 | close(IN); |
795 | return(%ret); | |
47339f61 | 796 | } |
55a9cc6e | 797 | |
948d0125 RL |
798 | sub parse_number |
799 | { | |
800 | (my $str, my $what) = @_; | |
801 | (my $n, my $i) = split(/\\/,$str); | |
802 | if ($what eq "n") { | |
803 | return $n; | |
804 | } else { | |
805 | return $i; | |
806 | } | |
807 | } | |
808 | ||
809 | sub rewrite_numbers | |
810 | { | |
811 | (*OUT,$name,*nums,@symbols)=@_; | |
812 | my $thing; | |
813 | ||
814 | print STDERR "Rewriting $name\n"; | |
815 | ||
816 | my @r = grep(/^\w+\\.*?:.*?:\w+\(\w+\)/,@symbols); | |
817 | my $r; my %r; my %rsyms; | |
818 | foreach $r (@r) { | |
819 | (my $s, my $i) = split /\\/, $r; | |
820 | my $a = $1 if $i =~ /^.*?:.*?:\w+\((\w+)\)/; | |
821 | $i =~ s/^(.*?:.*?:\w+)\(\w+\)/$1/; | |
822 | $r{$a} = $s."\\".$i; | |
823 | $rsyms{$s} = 1; | |
824 | } | |
825 | ||
826 | my @s=sort { &parse_number($nums{$a},"n") <=> &parse_number($nums{$b},"n") } keys %nums; | |
827 | foreach $sym (@s) { | |
828 | (my $n, my $i) = split /\\/, $nums{$sym}; | |
829 | next if defined($i) && $i =~ /^.*?:.*?:\w+\(\w+\)/; | |
830 | next if defined($rsyms{$sym}); | |
831 | $i="NOEXIST::FUNCTION:" if !defined($i) || $i eq ""; | |
832 | printf OUT "%s%-40s%d\t%s\n","",$sym,$n,$i; | |
833 | if (exists $r{$sym}) { | |
834 | (my $s, $i) = split /\\/,$r{$sym}; | |
835 | printf OUT "%s%-40s%d\t%s\n","",$s,$n,$i; | |
836 | } | |
837 | } | |
838 | } | |
839 | ||
55a9cc6e | 840 | sub update_numbers |
47339f61 | 841 | { |
948d0125 RL |
842 | (*OUT,$name,*nums,my $start_num, my @symbols)=@_; |
843 | my $new_syms = 0; | |
844 | ||
845 | print STDERR "Updating $name numbers\n"; | |
846 | ||
847 | my @r = grep(/^\w+\\.*?:.*?:\w+\(\w+\)/,@symbols); | |
848 | my $r; my %r; my %rsyms; | |
849 | foreach $r (@r) { | |
850 | (my $s, my $i) = split /\\/, $r; | |
851 | my $a = $1 if $i =~ /^.*?:.*?:\w+\((\w+)\)/; | |
852 | $i =~ s/^(.*?:.*?:\w+)\(\w+\)/$1/; | |
853 | $r{$a} = $s."\\".$i; | |
854 | $rsyms{$s} = 1; | |
855 | } | |
856 | ||
857 | foreach $sym (@symbols) { | |
858 | (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/; | |
859 | next if $i =~ /^.*?:.*?:\w+\(\w+\)/; | |
860 | next if defined($rsyms{$sym}); | |
861 | die "ERROR: Symbol $sym had no info attached to it." | |
862 | if $i eq ""; | |
863 | if (!exists $nums{$s}) { | |
864 | $new_syms++; | |
865 | printf OUT "%s%-40s%d\t%s\n","",$s, ++$start_num,$i; | |
866 | if (exists $r{$s}) { | |
867 | ($s, $i) = split /\\/,$r{$sym}; | |
868 | printf OUT "%s%-40s%d\t%s\n","",$s, $start_num,$i; | |
869 | } | |
55a9cc6e | 870 | } |
47339f61 | 871 | } |
948d0125 RL |
872 | if($new_syms) { |
873 | print STDERR "$new_syms New symbols added\n"; | |
55a9cc6e | 874 | } else { |
948d0125 RL |
875 | print STDERR "No New symbols Added\n"; |
876 | } | |
877 | } | |
878 | ||
879 | sub check_existing | |
880 | { | |
881 | (*nums, my @symbols)=@_; | |
882 | my %existing; my @remaining; | |
883 | @remaining=(); | |
884 | foreach $sym (@symbols) { | |
885 | (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/; | |
886 | $existing{$s}=1; | |
887 | } | |
888 | foreach $sym (keys %nums) { | |
889 | if (!exists $existing{$sym}) { | |
890 | push @remaining, $sym; | |
891 | } | |
892 | } | |
893 | if(@remaining) { | |
894 | print STDERR "The following symbols do not seem to exist:\n"; | |
895 | foreach $sym (@remaining) { | |
896 | print STDERR "\t",$sym,"\n"; | |
897 | } | |
55a9cc6e | 898 | } |
47339f61 | 899 | } |
948d0125 | 900 |