1 #!/usr/local/bin/perl -w
5 # It does this by parsing the header files and looking for the
6 # prototyped functions: it then prunes the output.
8 # Intermediary files are created, call libeay.num and ssleay.num,...
9 # Previously, they had the following format:
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.
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
26 # The format now becomes:
28 # routine-name nnnn info
30 # and the "info" part is actually a colon-separated string of fields with
31 # the following meaning:
33 # existence:platform:kind:algorithms
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
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
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
59 my $crypto_num= "util/libeay.num";
60 my $ssl_num= "util/ssleay.num";
68 my $do_checkexist = 0;
74 # Set this to make typesafe STACK definitions appear in DEF
75 my $safe_stack_def = 0;
77 my @known_platforms = ( "__FreeBSD__", "PERL5", "NeXT" );
78 my @known_ossl_platforms = ( "VMS", "WIN16", "WIN32", "WINNT" );
79 my @known_algorithms = ( "RC2", "RC4", "RC5", "IDEA", "DES", "BF",
80 "CAST", "MD2", "MD4", "MD5", "SHA", "SHA0", "SHA1",
82 "MDC2", "RSA", "DSA", "DH", "HMAC", "AES",
83 # Envelope "algorithms"
84 "EVP", "X509", "ASN1_TYPEDEFS",
86 "BIO", "COMP", "BUFFER", "LHASH", "STACK", "ERR",
88 # External "algorithms"
89 "FP_API", "STDIO", "SOCK", "KRB5" );
92 open(IN,"<Makefile.ssl") || die "unable to open Makefile.ssl!\n";
94 $options=$1 if (/^OPTIONS=(.*)$/);
98 # The following ciphers may be excluded (by Configure). This means functions
99 # defined with ifndef(NO_XXX) are not included in the .def file, and everything
100 # in directory xxx is ignored.
101 my $no_rc2; my $no_rc4; my $no_rc5; my $no_idea; my $no_des; my $no_bf;
103 my $no_md2; my $no_md4; my $no_md5; my $no_sha; my $no_ripemd; my $no_mdc2;
104 my $no_rsa; my $no_dsa; my $no_dh; my $no_hmac=0; my $no_aes; my $no_krb5;
107 foreach (@ARGV, split(/ /, $options))
109 $W32=1 if $_ eq "32";
110 $W16=1 if $_ eq "16";
115 $VMS=1 if $_ eq "VMS";
117 $do_ssl=1 if $_ eq "ssleay";
118 $do_ssl=1 if $_ eq "ssl";
119 $do_crypto=1 if $_ eq "libeay";
120 $do_crypto=1 if $_ eq "crypto";
121 $do_update=1 if $_ eq "update";
122 $do_rewrite=1 if $_ eq "rewrite";
123 $do_ctest=1 if $_ eq "ctest";
124 $do_ctestall=1 if $_ eq "ctestall";
125 $do_checkexist=1 if $_ eq "exist";
126 #$safe_stack_def=1 if $_ eq "-DDEBUG_SAFESTACK";
128 if (/^no-rc2$/) { $no_rc2=1; }
129 elsif (/^no-rc4$/) { $no_rc4=1; }
130 elsif (/^no-rc5$/) { $no_rc5=1; }
131 elsif (/^no-idea$/) { $no_idea=1; }
132 elsif (/^no-des$/) { $no_des=1; $no_mdc2=1; }
133 elsif (/^no-bf$/) { $no_bf=1; }
134 elsif (/^no-cast$/) { $no_cast=1; }
135 elsif (/^no-md2$/) { $no_md2=1; }
136 elsif (/^no-md4$/) { $no_md4=1; }
137 elsif (/^no-md5$/) { $no_md5=1; }
138 elsif (/^no-sha$/) { $no_sha=1; }
139 elsif (/^no-ripemd$/) { $no_ripemd=1; }
140 elsif (/^no-mdc2$/) { $no_mdc2=1; }
141 elsif (/^no-rsa$/) { $no_rsa=1; }
142 elsif (/^no-dsa$/) { $no_dsa=1; }
143 elsif (/^no-dh$/) { $no_dh=1; }
144 elsif (/^no-hmac$/) { $no_hmac=1; }
145 elsif (/^no-aes$/) { $no_aes=1; }
146 elsif (/^no-evp$/) { $no_evp=1; }
147 elsif (/^no-lhash$/) { $no_lhash=1; }
148 elsif (/^no-stack$/) { $no_stack=1; }
149 elsif (/^no-err$/) { $no_err=1; }
150 elsif (/^no-buffer$/) { $no_buffer=1; }
151 elsif (/^no-bio$/) { $no_bio=1; }
152 #elsif (/^no-locking$/) { $no_locking=1; }
153 elsif (/^no-comp$/) { $no_comp=1; }
154 elsif (/^no-dso$/) { $no_dso=1; }
155 elsif (/^no-krb5$/) { $no_krb5=1; }
159 # If no platform is given, assume WIN32
160 if ($W32 + $W16 + $VMS == 0) {
164 # Add extra knowledge
169 if (!$do_ssl && !$do_crypto)
171 print STDERR "usage: $0 ( ssl | crypto ) [ 16 | 32 | NT ]\n";
175 %ssl_list=&load_numbers($ssl_num);
177 %crypto_list=&load_numbers($crypto_num);
178 $max_crypto = $max_num;
183 my $crypto ="crypto/crypto.h";
184 $crypto.=" crypto/des/des.h" unless $no_des;
185 $crypto.=" crypto/idea/idea.h" unless $no_idea;
186 $crypto.=" crypto/rc4/rc4.h" unless $no_rc4;
187 $crypto.=" crypto/rc5/rc5.h" unless $no_rc5;
188 $crypto.=" crypto/rc2/rc2.h" unless $no_rc2;
189 $crypto.=" crypto/bf/blowfish.h" unless $no_bf;
190 $crypto.=" crypto/cast/cast.h" unless $no_cast;
191 $crypto.=" crypto/md2/md2.h" unless $no_md2;
192 $crypto.=" crypto/md4/md4.h" unless $no_md4;
193 $crypto.=" crypto/md5/md5.h" unless $no_md5;
194 $crypto.=" crypto/mdc2/mdc2.h" unless $no_mdc2;
195 $crypto.=" crypto/sha/sha.h" unless $no_sha;
196 $crypto.=" crypto/ripemd/ripemd.h" unless $no_ripemd;
197 $crypto.=" crypto/rijndael/rijndael.h" unless $no_aes;
198 $crypto.=" crypto/rijndael/rd_fst.h" unless $no_aes;
200 $crypto.=" crypto/bn/bn.h";
201 $crypto.=" crypto/rsa/rsa.h" unless $no_rsa;
202 $crypto.=" crypto/dsa/dsa.h" unless $no_dsa;
203 $crypto.=" crypto/dh/dh.h" unless $no_dh;
204 $crypto.=" crypto/hmac/hmac.h" unless $no_hmac;
206 $crypto.=" crypto/engine/engine.h";
207 $crypto.=" crypto/stack/stack.h" unless $no_stack;
208 $crypto.=" crypto/buffer/buffer.h" unless $no_buffer;
209 $crypto.=" crypto/bio/bio.h" unless $no_bio;
210 $crypto.=" crypto/dso/dso.h" unless $no_dso;
211 $crypto.=" crypto/lhash/lhash.h" unless $no_lhash;
212 $crypto.=" crypto/conf/conf.h";
213 $crypto.=" crypto/txt_db/txt_db.h";
215 $crypto.=" crypto/evp/evp.h" unless $no_evp;
216 $crypto.=" crypto/objects/objects.h";
217 $crypto.=" crypto/pem/pem.h";
218 #$crypto.=" crypto/meth/meth.h";
219 $crypto.=" crypto/asn1/asn1.h";
220 $crypto.=" crypto/asn1/asn1t.h";
221 $crypto.=" crypto/asn1/asn1_mac.h";
222 $crypto.=" crypto/err/err.h" unless $no_err;
223 $crypto.=" crypto/pkcs7/pkcs7.h";
224 $crypto.=" crypto/pkcs12/pkcs12.h";
225 $crypto.=" crypto/x509/x509.h";
226 $crypto.=" crypto/x509/x509_vfy.h";
227 $crypto.=" crypto/x509v3/x509v3.h";
228 $crypto.=" crypto/rand/rand.h";
229 $crypto.=" crypto/comp/comp.h" unless $no_comp;
230 $crypto.=" crypto/ocsp/ocsp.h";
231 $crypto.=" crypto/tmdiff.h";
233 my $symhacks="crypto/symhacks.h";
235 my @ssl_symbols = &do_defs("SSLEAY", $ssl, $symhacks);
236 my @crypto_symbols = &do_defs("LIBEAY", $crypto, $symhacks);
242 &maybe_add_info("SSLEAY",*ssl_list,@ssl_symbols);
243 if ($do_rewrite == 1) {
244 open(OUT, ">$ssl_num");
245 &rewrite_numbers(*OUT,"SSLEAY",*ssl_list,@ssl_symbols);
248 open(OUT, ">>$ssl_num");
250 &update_numbers(*OUT,"SSLEAY",*ssl_list,$max_ssl,@ssl_symbols);
254 if($do_crypto == 1) {
256 &maybe_add_info("LIBEAY",*crypto_list,@crypto_symbols);
257 if ($do_rewrite == 1) {
258 open(OUT, ">$crypto_num");
259 &rewrite_numbers(*OUT,"LIBEAY",*crypto_list,@crypto_symbols);
261 open(OUT, ">>$crypto_num");
263 &update_numbers(*OUT,"LIBEAY",*crypto_list,$max_crypto,@crypto_symbols);
267 } elsif ($do_checkexist) {
268 &check_existing(*ssl_list, @ssl_symbols)
270 &check_existing(*crypto_list, @crypto_symbols)
272 } elsif ($do_ctest || $do_ctestall) {
276 /* Test file to check all DEF file symbols are present by trying
277 * to link to all of them. This is *not* intended to be run!
283 &print_test_file(*STDOUT,"SSLEAY",*ssl_list,$do_ctestall,@ssl_symbols)
286 &print_test_file(*STDOUT,"LIBEAY",*crypto_list,$do_ctestall,@crypto_symbols)
293 &print_def_file(*STDOUT,"SSLEAY",*ssl_list,@ssl_symbols)
296 &print_def_file(*STDOUT,"LIBEAY",*crypto_list,@crypto_symbols)
304 my($name,$files,$symhacksfile)=@_;
308 my %platform; # For anything undefined, we assume ""
309 my %kind; # For anything undefined, we assume "FUNCTION"
310 my %algorithm; # For anything undefined, we assume ""
313 my %unknown_algorithms = ();
315 foreach $file (split(/\s+/,$symhacksfile." ".$files))
317 open(IN,"<$file") || die "unable to open $file:$!\n";
318 my $line = "", my $def= "";
320 (map { $_ => 0 } @known_platforms),
321 (map { "OPENSSL_SYS_".$_ => 0 } @known_ossl_platforms),
322 (map { "OPENSSL_NO_".$_ => 0 } @known_algorithms),
329 my $symhacking = $file eq $symhacksfile;
330 my @current_platforms = ();
331 my @current_algorithms = ();
334 last if (/BEGIN ERROR CODES/);
342 chop; # remove ending backslash
347 $cpp = 1 if /^\#.*ifdef.*cplusplus/;
349 $cpp = 0 if /^\#.*endif/;
353 s/\/\*.*?\*\///gs; # ignore comments
354 s/{[^{}]*}//gs; # ignore {} blocks
355 print STDERR "DEBUG: \$_=\"$_\"\n" if $debug;
356 if (/^\#\s*ifndef\s+(.*)/) {
360 print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
361 } elsif (/^\#\s*if\s+!defined\(([^\)]+)\)/) {
363 if (/^\#\s*if\s+(!defined\(([^\)]+)\)(\s+\&\&\s+!defined\(([^\)]+)\))*)$/) {
366 foreach $tmp_ (split '\&\&',$tmp_1) {
367 $tmp_ =~ /!defined\(([^\)]+)\)/;
368 print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
373 print STDERR "Warning: $file: complicated expression: $_" if $debug; # because it is O...
374 print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
378 } elsif (/^\#\s*ifdef\s+(.*)/) {
382 print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
383 } elsif (/^\#\s*if\s+defined\(([^\)]+)\)/) {
385 if (/^\#\s*if\s+(defined\(([^\)]+)\)(\s+\|\|\s+defined\(([^\)]+)\))*)$/) {
388 foreach $tmp_ (split '\|\|',$tmp_1) {
389 $tmp_ =~ /defined\(([^\)]+)\)/;
390 print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
395 print STDERR "Warning: $file: complicated expression: $_\n" if $debug; # because it is O...
396 print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
400 } elsif (/^\#\s*error\s+(\w+) is disabled\./) {
402 while($tag[$tag_i] ne "-") {
403 if ($tag[$tag_i] eq "OPENSSL_NO_".$1) {
404 $tag{$tag[$tag_i]}=2;
405 print STDERR "DEBUG: $file: chaged tag $1 = 2\n" if $debug;
409 } elsif (/^\#\s*endif/) {
411 while($tag[$tag_i] ne "-") {
413 print STDERR "DEBUG: \$t=\"$t\"\n" if $debug;
419 print STDERR "DEBUG: $file: changed tag ",$t," = ",$tag{$t},"\n" if $debug;
421 if ($t =~ /^OPENSSL_NO_([A-Z0-9_]+)$/) {
427 && !grep(/^$t$/, @known_algorithms)) {
428 $unknown_algorithms{$t} = 1;
429 #print STDERR "DEBUG: Added as unknown algorithm: $t\n" if $debug;
434 } elsif (/^\#\s*else/) {
436 while($tag[$tag_i] ne "-") {
439 print STDERR "DEBUG: $file: changed tag ",$t," = ",$tag{$t},"\n" if $debug;
442 } elsif (/^\#\s*if\s+1/) {
447 print STDERR "DEBUG: $file: found 1\n" if $debug;
448 } elsif (/^\#\s*if\s+0/) {
453 print STDERR "DEBUG: $file: found 0\n" if $debug;
454 } elsif (/^\#\s*define\s+(\w+)\s+(\w+)/
455 && $symhacking && $tag{'TRUE'} != -1) {
460 map { $tag{$_} == 1 ?
465 map { $tag{"OPENSSL_SYS_".$_} == 1 ?
467 @known_ossl_platforms));
468 if ($a1 eq "") { $a1 = $a2; }
469 elsif ($a1 ne "" && $a2 ne "") { $a1 .= ",".$a2; }
470 $rename{$s} = $a.":".$a1;
471 print STDERR "DEBUG: $file: defined $s = $a\n" if $debug;
476 map { $tag{$_} == 1 ? $_ :
477 $tag{$_} == -1 ? "!".$_ : "" }
479 push @current_platforms
481 map { $tag{"OPENSSL_SYS_".$_} == 1 ? $_ :
482 $tag{"OPENSSL_SYS_".$_} == -1 ? "!".$_ : "" }
483 @known_ossl_platforms);
484 @current_algorithms =
486 map { $tag{"OPENSSL_NO_".$_} == -1 ? $_ : "" }
490 .join(',',@current_platforms).":"
491 .join(',',@current_algorithms).";";
494 if ($tag{'TRUE'} != -1) {
495 if (/^\s*DECLARE_STACK_OF\s*\(\s*(\w*)\s*\)/) {
497 } elsif (/^\s*DECLARE_ASN1_ENCODE_FUNCTIONS\s*\(\s*(\w*)\s*,\s*(\w*)\s*,\s*(\w*)\s*\)/) {
498 $def .= "int d2i_$3(void);";
499 $def .= "int i2d_$3(void);";
500 $def .= "OPENSSL_EXTERN int $2_it;";
502 } elsif (/^\s*DECLARE_ASN1_FUNCTIONS_fname\s*\(\s*(\w*)\s*,\s*(\w*)\s*,\s*(\w*)\s*\)/) {
503 $def .= "int d2i_$3(void);";
504 $def .= "int i2d_$3(void);";
505 $def .= "int $3_free(void);";
506 $def .= "int $3_new(void);";
507 $def .= "OPENSSL_EXTERN int $2_it;";
508 } elsif (/^\s*DECLARE_ASN1_FUNCTIONS\s*\(\s*(\w*)\s*\)/ ||
509 /^\s*DECLARE_ASN1_FUNCTIONS_const\s*\(\s*(\w*)\s*\)/) {
510 $def .= "int d2i_$1(void);";
511 $def .= "int i2d_$1(void);";
512 $def .= "int $1_free(void);";
513 $def .= "int $1_new(void);";
514 $def .= "OPENSSL_EXTERN int $1_it;";
516 } elsif (/^\s*DECLARE_ASN1_ENCODE_FUNCTIONS_const\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
517 $def .= "int d2i_$2(void);";
518 $def .= "int i2d_$2(void);";
519 $def .= "OPENSSL_EXTERN int $2_it;";
521 } elsif (/^\s*DECLARE_ASN1_FUNCTIONS_name\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
522 $def .= "int d2i_$2(void);";
523 $def .= "int i2d_$2(void);";
524 $def .= "int $2_free(void);";
525 $def .= "int $2_new(void);";
526 $def .= "OPENSSL_EXTERN int $2_it;";
528 } elsif (/^\s*DECLARE_ASN1_ITEM\s*\(\s*(\w*)\s*,(\w*)\s*\)/) {
529 $def .= "OPENSSL_EXTERN int $1_it;";
531 } elsif (/^\s*DECLARE_PKCS12_STACK_OF\s*\(\s*(\w*)\s*\)/) {
533 } elsif (/^\s*DECLARE_ASN1_SET_OF\s*\(\s*(\w*)\s*\)/) {
535 } elsif (/^DECLARE_PEM_rw\s*\(\s*(\w*)\s*,/ ||
536 /^DECLARE_PEM_rw_cb\s*\(\s*(\w*)\s*,/ ) {
537 # Things not in Win16
540 .join(',',"!WIN16",@current_platforms).":"
541 .join(',',@current_algorithms).";";
542 $def .= "int PEM_read_$1(void);";
543 $def .= "int PEM_write_$1(void);";
546 .join(',',@current_platforms).":"
547 .join(',',@current_algorithms).";";
548 # Things that are everywhere
549 $def .= "int PEM_read_bio_$1(void);";
550 $def .= "int PEM_write_bio_$1(void);";
552 } elsif (/^DECLARE_PEM_write\s*\(\s*(\w*)\s*,/ ||
553 /^DECLARE_PEM_write_cb\s*\(\s*(\w*)\s*,/ ) {
554 # Things not in Win16
557 .join(',',"!WIN16",@current_platforms).":"
558 .join(',',@current_algorithms).";";
559 $def .= "int PEM_write_$1(void);";
562 .join(',',@current_platforms).":"
563 .join(',',@current_algorithms).";";
564 # Things that are everywhere
565 $def .= "int PEM_write_bio_$1(void);";
567 } elsif (/^DECLARE_PEM_read\s*\(\s*(\w*)\s*,/ ||
568 /^DECLARE_PEM_read_cb\s*\(\s*(\w*)\s*,/ ) {
569 # Things not in Win16
572 .join(',',"!WIN16",@current_platforms).":"
573 .join(',',@current_algorithms).";";
574 $def .= "int PEM_read_$1(void);";
577 .join(',',@current_platforms).":"
578 .join(',',@current_algorithms).";";
579 # Things that are everywhere
580 $def .= "int PEM_read_bio_$1(void);";
582 } elsif ($tag{'CONST_STRICT'} != 1) {
583 if (/\{|\/\*|\([^\)]*$/) {
596 foreach (split /;/, $def) {
597 my $s; my $k = "FUNCTION"; my $p; my $a;
601 next if(/typedef\W/);
604 if (/^\#INFO:([^:]*):(.*)$/) {
608 } elsif (/^\s*OPENSSL_EXTERN\s.*?(\w+)(\[[0-9]*\])*\s*$/) {
611 } elsif (/\(\*(\w*)\([^\)]+/) {
613 } elsif (/\w+\W+(\w+)\W*\(\s*\)$/s) {
616 } elsif (/\w+\W+\w+\W*\(.*\)$/s) {
617 while (not /\(\)$/s) {
619 s/\([^\(\)]*\)\)$/\)/s;
624 } elsif (/\(/ and not (/=/)) {
625 print STDERR "File $file: cannot parse: $_;\n";
636 $a .= ",BF" if($s =~ /EVP_bf/);
637 $a .= ",CAST" if($s =~ /EVP_cast/);
638 $a .= ",DES" if($s =~ /EVP_des/);
639 $a .= ",DSA" if($s =~ /EVP_dss/);
640 $a .= ",IDEA" if($s =~ /EVP_idea/);
641 $a .= ",MD2" if($s =~ /EVP_md2/);
642 $a .= ",MD4" if($s =~ /EVP_md4/);
643 $a .= ",MD5" if($s =~ /EVP_md5/);
644 $a .= ",RC2" if($s =~ /EVP_rc2/);
645 $a .= ",RC4" if($s =~ /EVP_rc4/);
646 $a .= ",RC5" if($s =~ /EVP_rc5/);
647 $a .= ",RIPEMD" if($s =~ /EVP_ripemd/);
648 $a .= ",SHA" if($s =~ /EVP_sha/);
649 $a .= ",RSA" if($s =~ /EVP_(Open|Seal)(Final|Init)/);
650 $a .= ",RSA" if($s =~ /PEM_Seal(Final|Init|Update)/);
651 $a .= ",RSA" if($s =~ /RSAPrivateKey/);
652 $a .= ",RSA" if($s =~ /SSLv23?_((client|server)_)?method/);
654 $platform{$s} .= ','.$p;
655 $algorithm{$s} .= ','.$a;
657 if (defined($rename{$s})) {
658 (my $r, my $p) = split(/:/,$rename{$s});
659 my @ip = map { /^!(.*)$/ ? $1 : "!".$_ } split /,/, $p;
661 $kind{$r} = $kind{$s}."(".$s.")";
662 $algorithm{$r} = $algorithm{$s};
663 $platform{$r} = $platform{$s}.",".$p;
664 $platform{$s} .= ','.join(',', @ip).','.join(',', @ip);
669 # Prune the returned symbols
671 delete $syms{"bn_dump1"};
672 $platform{"BIO_s_log"} .= ",!WIN32,!WIN16,!macintosh";
674 $platform{"PEM_read_NS_CERT_SEQ"} = "VMS";
675 $platform{"PEM_write_NS_CERT_SEQ"} = "VMS";
676 $platform{"PEM_read_P8_PRIV_KEY_INFO"} = "VMS";
677 $platform{"PEM_write_P8_PRIV_KEY_INFO"} = "VMS";
681 push @ret, map { $_."\\".&info_string($_,"EXIST",
684 $algorithm{$_}) } keys %syms;
686 if (keys %unknown_algorithms) {
687 print STDERR "WARNING: mkdef.pl doesn't know the following algorithms:\n";
688 print STDERR "\t",join("\n\t",keys %unknown_algorithms),"\n";
694 (my $symbol, my $exist, my $platforms, my $kind, my $algorithms) = @_;
696 my %a = defined($algorithms) ?
697 map { $_ => 1 } split /,/, $algorithms : ();
698 my $pl = defined($platforms) ? $platforms : "";
699 my %p = map { $_ => 0 } split /,/, $pl;
700 my $k = defined($kind) ? $kind : "FUNCTION";
703 # We do this, because if there's code like the following, it really
704 # means the function exists in all cases and should therefore be
705 # everywhere. By increasing and decreasing, we may attain 0:
712 foreach $platform (split /,/, $pl) {
713 if ($platform =~ /^!(.*)$/) {
719 foreach $platform (keys %p) {
720 if ($p{$platform} == 0) { delete $p{$platform}; }
727 $ret .= ":".join(',',map { $p{$_} < 0 ? "!".$_ : $_ } keys %p);
729 $ret .= ":".join(',',keys %a);
734 (my $name, *nums, my @symbols) = @_;
739 print STDERR "Updating $name info\n";
740 foreach $sym (@symbols) {
741 (my $s, my $i) = split /\\/, $sym;
742 $i =~ s/^(.*?:.*?:\w+)(\(\w+\))?/$1/;
743 if (defined($nums{$s})) {
744 (my $n, my $dummy) = split /\\/, $nums{$s};
745 if (!defined($dummy) || $i ne $dummy) {
746 $nums{$s} = $n."\\".$i;
748 print STDERR "DEBUG: maybe_add_info for $s: \"$dummy\" => \"$i\"\n" if $debug;
754 my @s=sort { &parse_number($nums{$a},"n") <=> &parse_number($nums{$b},"n") } keys %nums;
756 (my $n, my $i) = split /\\/, $nums{$sym};
757 if (!defined($syms{sym})) {
759 print STDERR "DEBUG: maybe_add_info for $sym: -> undefined\n if $debug";
763 print STDERR "$new_info old symbols got an info update\n";
765 print STDERR "You should do a rewrite to fix this.\n";
768 print STDERR "No old symbols needed info update\n";
774 (*OUT,my $name,*nums,my @symbols)=@_;
775 my $n = 1; my @e; my @r;
776 my $sym; my $prev = ""; my $prefSSLeay;
778 (@e)=grep(/^SSLeay\\.*?:.*?:FUNCTION/,@symbols);
779 (@r)=grep(/^\w+\\.*?:.*?:FUNCTION/ && !/^SSLeay\\.*?:.*?:FUNCTION/,@symbols);
780 @symbols=((sort @e),(sort @r));
782 foreach $sym (@symbols) {
783 (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
785 if (!defined($nums{$s})) {
786 print STDERR "Warning: $s does not have a number assigned\n"
790 print OUT "\t$s();\n";
793 $prev = $s; # To avoid duplicates...
799 (*OUT,my $name,*nums,my @symbols)=@_;
800 my $n = 1; my @e; my @r; my @v;
809 ; Definition file for the DLL version of the $name library from OpenSSL
814 DESCRIPTION 'OpenSSL $name - http://www.openssl.org/'
820 CODE PRELOAD MOVEABLE
821 DATA PRELOAD MOVEABLE SINGLE
833 (@e)=grep(/^SSLeay\\.*?:.*?:FUNCTION/,@symbols);
834 (@r)=grep(/^\w+\\.*?:.*?:FUNCTION/ && !/^SSLeay\\.*?:.*?:FUNCTION/,@symbols);
835 (@v)=grep(/^\w+\\.*?:.*?:VARIABLE/,@symbols);
836 @symbols=((sort @e),(sort @r), (sort @v));
839 foreach $sym (@symbols) {
840 (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
842 $v = 1 if $sym=~ /^\w+\\.*?:.*?:VARIABLE/;
843 if (!defined($nums{$s})) {
844 printf STDERR "Warning: $s does not have a number assigned\n"
847 (my $n, my $i) = split /\\/, $nums{$s};
849 my @p = split(/,/, ($i =~ /^[^:]*:([^:]*):/,$1));
850 my @a = split(/,/, ($i =~ /^[^:]*:[^:]*:[^:]*:([^:]*)/,$1));
851 # @p_purged must contain hardware platforms only
854 push @p_purged, $ptmp;
856 my $negatives = !!grep(/^!/,@p);
857 # It is very important to check NT before W32
858 if ((($NT && (!@p_purged
859 || (!$negatives && grep(/^WINNT$/,@p))
860 || ($negatives && !grep(/^!WINNT$/,@p))))
861 || ($W32 && (!@p_purged
862 || (!$negatives && grep(/^WIN32$/,@p))
863 || ($negatives && !grep(/^!WIN32$/,@p))))
864 || ($W16 && (!@p_purged
865 || (!$negatives && grep(/^WIN16$/,@p))
866 || ($negatives && !grep(/^!WIN16$/,@p)))))
867 && (!@a || (!$no_rc2 || !grep(/^RC2$/,@a)))
868 && (!@a || (!$no_rc4 || !grep(/^RC4$/,@a)))
869 && (!@a || (!$no_rc5 || !grep(/^RC5$/,@a)))
870 && (!@a || (!$no_idea || !grep(/^IDEA$/,@a)))
871 && (!@a || (!$no_des || !grep(/^DES$/,@a)))
872 && (!@a || (!$no_bf || !grep(/^BF$/,@a)))
873 && (!@a || (!$no_cast || !grep(/^CAST$/,@a)))
874 && (!@a || (!$no_md2 || !grep(/^MD2$/,@a)))
875 && (!@a || (!$no_md4 || !grep(/^MD4$/,@a)))
876 && (!@a || (!$no_md5 || !grep(/^MD5$/,@a)))
877 && (!@a || (!$no_sha || !grep(/^SHA$/,@a)))
878 && (!@a || (!$no_ripemd || !grep(/^RIPEMD$/,@a)))
879 && (!@a || (!$no_mdc2 || !grep(/^MDC2$/,@a)))
880 && (!@a || (!$no_rsa || !grep(/^RSA$/,@a)))
881 && (!@a || (!$no_dsa || !grep(/^DSA$/,@a)))
882 && (!@a || (!$no_dh || !grep(/^DH$/,@a)))
883 && (!@a || (!$no_hmac || !grep(/^HMAC$/,@a)))
884 && (!@a || (!$no_aes || !grep(/^AES$/,@a)))
885 && (!@a || (!$no_krb5 || !grep(/^KRB5$/,@a)))
886 && (!@a || (!$no_fp_api || !grep(/^FP_API$/,@a)))
889 printf OUT " %s%-40s@%-8d DATA\n",($W32)?"":"_",$s,$n;
891 printf OUT " %s%-40s@%d\n",($W32)?"":"_",$s,$n;
894 # print STDERR "DEBUG: \"$sym\" (@p):",
895 # " negatives:", $negatives,
896 # " 16:", !!($W16 && (!@p_purged
897 # || (!$negatives && grep(/^WIN16$/,@p))
898 # || ($negatives && !grep(/^!WIN16$/,@p)))),
899 # " 32:", !!($W32 && (!@p_purged
900 # || (!$negatives && grep(/^WIN32$/,@p))
901 # || ($negatives && !grep(/^!WIN32$/,@p)))),
902 # " NT:", !!($NT && (!@p_purged
903 # || (!$negatives && grep(/^WINNT$/,@p))
904 # || ($negatives && !grep(/^!WINNT$/,@p)))),
920 open(IN,"<$name") || die "unable to open $name:$!\n";
926 if (defined $ret{$a[0]}) {
927 print STDERR "Warning: Symbol '",$a[0],"' redefined. old=",$ret{$a[0]},", new=",$a[1],"\n";
929 if ($max_num > $a[1]) {
930 print STDERR "Warning: Number decreased from ",$max_num," to ",$a[1],"\n";
932 if ($max_num == $a[1]) {
933 # This is actually perfectly OK
934 #print STDERR "Warning: Symbol ",$a[0]," has same number as previous ",$prev,": ",$a[1],"\n";
937 # Existence will be proven later, in do_defs
941 $ret{$a[0]}=$a[1]."\\".$a[2]; # \\ is a special marker
943 $max_num = $a[1] if $a[1] > $max_num;
947 print STDERR "Warning: $num_noinfo symbols were without info.";
949 printf STDERR " The rewrite will fix this.\n";
951 printf STDERR " You should do a rewrite to fix this.\n";
960 (my $str, my $what) = @_;
961 (my $n, my $i) = split(/\\/,$str);
971 (*OUT,$name,*nums,@symbols)=@_;
974 print STDERR "Rewriting $name\n";
976 my @r = grep(/^\w+\\.*?:.*?:\w+\(\w+\)/,@symbols);
977 my $r; my %r; my %rsyms;
979 (my $s, my $i) = split /\\/, $r;
980 my $a = $1 if $i =~ /^.*?:.*?:\w+\((\w+)\)/;
981 $i =~ s/^(.*?:.*?:\w+)\(\w+\)/$1/;
987 foreach $_ (@symbols) {
988 (my $n, my $i) = split /\\/;
992 my @s=sort { &parse_number($nums{$a},"n") <=> &parse_number($nums{$b},"n") } keys %nums;
994 (my $n, my $i) = split /\\/, $nums{$sym};
995 print STDERR "DEBUG: rewrite_numbers for sym = ",$sym,": i = ",$i,", n = ",$n,", rsym{sym} = ",$rsyms{$sym},"syms{sym} = ",$syms{$sym},"\n" if $debug;
996 next if defined($i) && $i =~ /^.*?:.*?:\w+\(\w+\)/;
997 next if defined($rsyms{$sym});
998 $i="NOEXIST::FUNCTION:"
999 if !defined($i) || $i eq "" || !defined($syms{$sym});
1000 printf OUT "%s%-40s%d\t%s\n","",$sym,$n,$i;
1001 if (exists $r{$sym}) {
1002 (my $s, $i) = split /\\/,$r{$sym};
1003 printf OUT "%s%-40s%d\t%s\n","",$s,$n,$i;
1010 (*OUT,$name,*nums,my $start_num, my @symbols)=@_;
1013 print STDERR "Updating $name numbers\n";
1015 my @r = grep(/^\w+\\.*?:.*?:\w+\(\w+\)/,@symbols);
1016 my $r; my %r; my %rsyms;
1018 (my $s, my $i) = split /\\/, $r;
1019 my $a = $1 if $i =~ /^.*?:.*?:\w+\((\w+)\)/;
1020 $i =~ s/^(.*?:.*?:\w+)\(\w+\)/$1/;
1021 $r{$a} = $s."\\".$i;
1025 foreach $sym (@symbols) {
1026 (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
1027 next if $i =~ /^.*?:.*?:\w+\(\w+\)/;
1028 next if defined($rsyms{$sym});
1029 die "ERROR: Symbol $sym had no info attached to it."
1031 if (!exists $nums{$s}) {
1033 printf OUT "%s%-40s%d\t%s\n","",$s, ++$start_num,$i;
1034 if (exists $r{$s}) {
1035 ($s, $i) = split /\\/,$r{$s};
1036 printf OUT "%s%-40s%d\t%s\n","",$s, $start_num,$i;
1041 print STDERR "$new_syms New symbols added\n";
1043 print STDERR "No New symbols Added\n";
1049 (*nums, my @symbols)=@_;
1050 my %existing; my @remaining;
1052 foreach $sym (@symbols) {
1053 (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
1056 foreach $sym (keys %nums) {
1057 if (!exists $existing{$sym}) {
1058 push @remaining, $sym;
1062 print STDERR "The following symbols do not seem to exist:\n";
1063 foreach $sym (@remaining) {
1064 print STDERR "\t",$sym,"\n";