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 # The format of these files is:
11 # routine-name nnnn vers info
13 # The "nnnn" and "vers" fields are the numeric id and version for the symbol
14 # respectively. The "info" part is actually a colon-separated string of fields
15 # with the following meaning:
17 # existence:platform:kind:algorithms
19 # - "existence" can be "EXIST" or "NOEXIST" depending on if the symbol is
20 # found somewhere in the source,
21 # - "platforms" is empty if it exists on all platforms, otherwise it contains
22 # comma-separated list of the platform, just as they are if the symbol exists
23 # for those platforms, or prepended with a "!" if not. This helps resolve
24 # symbol name variants for platforms where the names are too long for the
25 # compiler or linker, or if the systems is case insensitive and there is a
26 # clash, or the symbol is implemented differently (see
27 # EXPORT_VAR_AS_FUNCTION). This script assumes renaming of symbols is found
28 # in the file crypto/symhacks.h.
29 # The semantics for the platforms is that every item is checked against the
30 # environment. For the negative items ("!FOO"), if any of them is false
31 # (i.e. "FOO" is true) in the environment, the corresponding symbol can't be
32 # used. For the positive itms, if all of them are false in the environment,
33 # the corresponding symbol can't be used. Any combination of positive and
34 # negative items are possible, and of course leave room for some redundancy.
35 # - "kind" is "FUNCTION" or "VARIABLE". The meaning of that is obvious.
36 # - "algorithms" is a comma-separated list of algorithm names. This helps
37 # exclude symbols that are part of an algorithm that some user wants to
43 my $crypto_num= "util/libeay.num";
44 my $ssl_num= "util/ssleay.num";
53 my $do_checkexist = 0;
62 # Set this to make typesafe STACK definitions appear in DEF
63 my $safe_stack_def = 0;
65 my @known_platforms = ( "__FreeBSD__", "PERL5",
66 "EXPORT_VAR_AS_FUNCTION", "ZLIB",
67 "OPENSSL_FIPS", "OPENSSL_FIPSCAPABLE" );
68 my @known_ossl_platforms = ( "VMS", "WIN32", "WINNT", "OS2" );
69 my @known_algorithms = ( "RC2", "RC4", "RC5", "IDEA", "DES", "BF",
70 "CAST", "MD2", "MD4", "MD5", "SHA", "SHA0", "SHA1",
71 "SHA256", "SHA512", "RMD160",
72 "MDC2", "WHIRLPOOL", "RSA", "DSA", "DH", "EC", "EC2M",
73 "HMAC", "AES", "CAMELLIA", "SEED", "GOST",
74 "SCRYPT", "CHACHA", "POLY1305",
76 "EC_NISTP_64_GCC_128",
77 # Envelope "algorithms"
78 "EVP", "X509", "ASN1_TYPEDEFS",
80 "BIO", "COMP", "BUFFER", "LHASH", "STACK", "ERR",
82 # External "algorithms"
83 "FP_API", "STDIO", "SOCK", "DGRAM",
85 "STATIC_ENGINE", "ENGINE", "HW", "GMP",
86 # X.509v3 Signed Certificate Timestamps
91 "PSK", "SRP", "HEARTBEATS",
102 # Deprecated functions
114 # APPLINK (win build feature?)
119 open(IN,"<Makefile") || die "unable to open Makefile!\n";
121 $options=$1 if (/^OPTIONS=(.*)$/);
125 # The following ciphers may be excluded (by Configure). This means functions
126 # defined with ifndef(NO_XXX) are not included in the .def file, and everything
127 # in directory xxx is ignored.
128 my $no_rc2; my $no_rc4; my $no_rc5; my $no_idea; my $no_des; my $no_bf;
129 my $no_cast; my $no_whirlpool; my $no_camellia; my $no_seed;
130 my $no_md2; my $no_md4; my $no_md5; my $no_sha; my $no_ripemd; my $no_mdc2;
131 my $no_rsa; my $no_dsa; my $no_dh; my $no_aes; my $no_scrypt;
132 my $no_ec; my $no_engine; my $no_hw;
133 my $no_chacha; my $no_poly1305;
134 my $no_fp_api; my $no_static_engine=1; my $no_deprecated;
135 my $no_sct; my $no_rfc3779; my $no_psk; my $no_cms; my $no_capieng;
136 my $no_jpake; my $no_srp; my $no_ec2m; my $no_nistp_gcc;
137 my $no_nextprotoneg; my $no_sctp; my $no_srtp; my $no_ssl_trace;
138 my $no_unit_test; my $no_ssl3_method; my $no_ocb;
145 foreach (@ARGV, split(/ /, $options))
147 $debug=1 if $_ eq "debug";
148 $W32=1 if $_ eq "32";
149 die "win16 not supported" if $_ eq "16";
154 if ($_ eq "VMS-VAX") {
158 if ($_ eq "VMS-NonVAX") {
165 $VMS=1 if $_ eq "VMS";
166 $OS2=1 if $_ eq "OS2";
168 if ($_ eq "zlib" || $_ eq "enable-zlib" || $_ eq "zlib-dynamic"
169 || $_ eq "enable-zlib-dynamic") {
173 $do_ssl=1 if $_ eq "ssleay";
178 $do_crypto=1 if $_ eq "libeay";
179 if ($_ eq "crypto") {
183 $no_static_engine=1 if $_ eq "no-static-engine";
184 $no_static_engine=0 if $_ eq "enable-static-engine";
185 $do_update=1 if $_ eq "update";
186 $do_rewrite=1 if $_ eq "rewrite";
187 $do_ctest=1 if $_ eq "ctest";
188 $do_ctestall=1 if $_ eq "ctestall";
189 $do_checkexist=1 if $_ eq "exist";
190 #$safe_stack_def=1 if $_ eq "-DDEBUG_SAFESTACK";
192 if (/^no-rc2$/) { $no_rc2=1; }
193 elsif (/^no-rc4$/) { $no_rc4=1; }
194 elsif (/^no-rc5$/) { $no_rc5=1; }
195 elsif (/^no-idea$/) { $no_idea=1; }
196 elsif (/^no-des$/) { $no_des=1; $no_mdc2=1; }
197 elsif (/^no-bf$/) { $no_bf=1; }
198 elsif (/^no-cast$/) { $no_cast=1; }
199 elsif (/^no-whirlpool$/) { $no_whirlpool=1; }
200 elsif (/^no-md2$/) { $no_md2=1; }
201 elsif (/^no-md4$/) { $no_md4=1; }
202 elsif (/^no-md5$/) { $no_md5=1; }
203 elsif (/^no-sha$/) { $no_sha=1; }
204 elsif (/^no-ripemd$/) { $no_ripemd=1; }
205 elsif (/^no-mdc2$/) { $no_mdc2=1; }
206 elsif (/^no-rsa$/) { $no_rsa=1; }
207 elsif (/^no-dsa$/) { $no_dsa=1; }
208 elsif (/^no-dh$/) { $no_dh=1; }
209 elsif (/^no-ec$/) { $no_ec=1; }
210 elsif (/^no-aes$/) { $no_aes=1; }
211 elsif (/^no-camellia$/) { $no_camellia=1; }
212 elsif (/^no-seed$/) { $no_seed=1; }
213 elsif (/^no-scrypt$/) { $no_scrypt=1; }
214 elsif (/^no-chacha$/) { $no_chacha=1; }
215 elsif (/^no-poly1305$/) { $no_poly1305=1; }
216 elsif (/^no-evp$/) { $no_evp=1; }
217 elsif (/^no-lhash$/) { $no_lhash=1; }
218 elsif (/^no-stack$/) { $no_stack=1; }
219 elsif (/^no-err$/) { $no_err=1; }
220 elsif (/^no-buffer$/) { $no_buffer=1; }
221 elsif (/^no-bio$/) { $no_bio=1; }
222 #elsif (/^no-locking$/) { $no_locking=1; }
223 elsif (/^no-comp$/) { $no_comp=1; }
224 elsif (/^no-dso$/) { $no_dso=1; }
225 elsif (/^no-engine$/) { $no_engine=1; }
226 elsif (/^no-hw$/) { $no_hw=1; }
227 elsif (/^no-sct$/) { $no_sct=1; }
228 elsif (/^no-rfc3779$/) { $no_rfc3779=1; }
229 elsif (/^no-cms$/) { $no_cms=1; }
230 elsif (/^no-ec2m$/) { $no_ec2m=1; }
231 elsif (/^no-ec-nistp224-64-gcc-128$/) { $no_nistp_gcc=1; }
232 elsif (/^no-nextprotoneg$/) { $no_nextprotoneg=1; }
233 elsif (/^no-ssl3-method$/) { $no_ssl3_method=1; }
234 elsif (/^no-ssl-trace$/) { $no_ssl_trace=1; }
235 elsif (/^no-capieng$/) { $no_capieng=1; }
236 elsif (/^no-jpake$/) { $no_jpake=1; }
237 elsif (/^no-srp$/) { $no_srp=1; }
238 elsif (/^no-sctp$/) { $no_sctp=1; }
239 elsif (/^no-srtp$/) { $no_srtp=1; }
240 elsif (/^no-unit-test$/){ $no_unit_test=1; }
241 elsif (/^no-deprecated$/) { $no_deprecated=1; }
242 elsif (/^no-ocb/){ $no_ocb=1; }
255 # If no platform is given, assume WIN32
256 if ($W32 + $VMS + $OS2 + $linux == 0) {
260 if (!$do_ssl && !$do_crypto)
262 print STDERR "usage: $0 ( ssl | crypto ) [ 16 | 32 | NT | OS2 ]\n";
266 %ssl_list=&load_numbers($ssl_num);
268 %crypto_list=&load_numbers($crypto_num);
269 $max_crypto = $max_num;
271 my $ssl="include/openssl/ssl.h";
272 $ssl.=" include/openssl/tls1.h";
273 $ssl.=" include/openssl/srtp.h";
275 my $crypto ="include/openssl/crypto.h";
276 $crypto.=" crypto/include/internal/cryptlib.h";
277 $crypto.=" crypto/include/internal/chacha.h"; # unless $no_chacha;
278 $crypto.=" crypto/include/internal/poly1305.h"; # unless $no_poly1305;
279 $crypto.=" include/internal/o_dir.h";
280 $crypto.=" include/internal/o_str.h";
281 $crypto.=" include/openssl/des.h" ; # unless $no_des;
282 $crypto.=" include/openssl/idea.h" ; # unless $no_idea;
283 $crypto.=" include/openssl/rc4.h" ; # unless $no_rc4;
284 $crypto.=" include/openssl/rc5.h" ; # unless $no_rc5;
285 $crypto.=" include/openssl/rc2.h" ; # unless $no_rc2;
286 $crypto.=" include/openssl/blowfish.h" ; # unless $no_bf;
287 $crypto.=" include/openssl/cast.h" ; # unless $no_cast;
288 $crypto.=" include/openssl/whrlpool.h" ;
289 $crypto.=" include/openssl/md2.h" ; # unless $no_md2;
290 $crypto.=" include/openssl/md4.h" ; # unless $no_md4;
291 $crypto.=" include/openssl/md5.h" ; # unless $no_md5;
292 $crypto.=" include/openssl/mdc2.h" ; # unless $no_mdc2;
293 $crypto.=" include/openssl/sha.h" ; # unless $no_sha;
294 $crypto.=" include/openssl/ripemd.h" ; # unless $no_ripemd;
295 $crypto.=" include/openssl/aes.h" ; # unless $no_aes;
296 $crypto.=" include/openssl/camellia.h" ; # unless $no_camellia;
297 $crypto.=" include/openssl/seed.h"; # unless $no_seed;
299 $crypto.=" include/openssl/bn.h";
300 $crypto.=" include/openssl/rsa.h" ; # unless $no_rsa;
301 $crypto.=" include/openssl/dsa.h" ; # unless $no_dsa;
302 $crypto.=" include/openssl/dh.h" ; # unless $no_dh;
303 $crypto.=" include/openssl/ec.h" ; # unless $no_ec;
304 $crypto.=" include/openssl/hmac.h" ; # unless $no_hmac;
305 $crypto.=" include/openssl/cmac.h" ;
307 $crypto.=" include/openssl/engine.h"; # unless $no_engine;
308 $crypto.=" include/openssl/stack.h" ; # unless $no_stack;
309 $crypto.=" include/openssl/buffer.h" ; # unless $no_buffer;
310 $crypto.=" include/openssl/bio.h" ; # unless $no_bio;
311 $crypto.=" include/openssl/dso.h" ; # unless $no_dso;
312 $crypto.=" include/openssl/lhash.h" ; # unless $no_lhash;
313 $crypto.=" include/openssl/conf.h";
314 $crypto.=" include/openssl/txt_db.h";
316 $crypto.=" include/openssl/evp.h" ; # unless $no_evp;
317 $crypto.=" include/openssl/objects.h";
318 $crypto.=" include/openssl/pem.h";
319 #$crypto.=" include/openssl/meth.h";
320 $crypto.=" include/openssl/asn1.h";
321 $crypto.=" include/openssl/asn1t.h";
322 $crypto.=" include/openssl/err.h" ; # unless $no_err;
323 $crypto.=" include/openssl/pkcs7.h";
324 $crypto.=" include/openssl/pkcs12.h";
325 $crypto.=" include/openssl/x509.h";
326 $crypto.=" include/openssl/x509_vfy.h";
327 $crypto.=" include/openssl/x509v3.h";
328 $crypto.=" include/openssl/ts.h";
329 $crypto.=" include/openssl/rand.h";
330 $crypto.=" include/openssl/comp.h" ; # unless $no_comp;
331 $crypto.=" include/openssl/ocsp.h";
332 $crypto.=" include/openssl/ui.h";
333 #$crypto.=" include/openssl/store.h";
334 $crypto.=" include/openssl/pqueue.h";
335 $crypto.=" include/openssl/cms.h";
336 $crypto.=" include/openssl/jpake.h";
337 $crypto.=" include/openssl/srp.h";
338 $crypto.=" include/openssl/modes.h";
339 $crypto.=" include/openssl/async.h";
341 my $symhacks="include/openssl/symhacks.h";
343 my @ssl_symbols = &do_defs("SSLEAY", $ssl, $symhacks);
344 my @crypto_symbols = &do_defs("LIBEAY", $crypto, $symhacks);
350 &maybe_add_info("SSLEAY",*ssl_list,@ssl_symbols);
351 if ($do_rewrite == 1) {
352 open(OUT, ">$ssl_num");
353 &rewrite_numbers(*OUT,"SSLEAY",*ssl_list,@ssl_symbols);
355 open(OUT, ">>$ssl_num");
357 &update_numbers(*OUT,"SSLEAY",*ssl_list,$max_ssl,@ssl_symbols);
361 if($do_crypto == 1) {
363 &maybe_add_info("LIBEAY",*crypto_list,@crypto_symbols);
364 if ($do_rewrite == 1) {
365 open(OUT, ">$crypto_num");
366 &rewrite_numbers(*OUT,"LIBEAY",*crypto_list,@crypto_symbols);
368 open(OUT, ">>$crypto_num");
370 &update_numbers(*OUT,"LIBEAY",*crypto_list,$max_crypto,@crypto_symbols);
374 } elsif ($do_checkexist) {
375 &check_existing(*ssl_list, @ssl_symbols)
377 &check_existing(*crypto_list, @crypto_symbols)
379 } elsif ($do_ctest || $do_ctestall) {
383 /* Test file to check all DEF file symbols are present by trying
384 * to link to all of them. This is *not* intended to be run!
390 &print_test_file(*STDOUT,"SSLEAY",*ssl_list,$do_ctestall,@ssl_symbols)
393 &print_test_file(*STDOUT,"LIBEAY",*crypto_list,$do_ctestall,@crypto_symbols)
400 &print_def_file(*STDOUT,$libname,*ssl_list,@ssl_symbols)
403 &print_def_file(*STDOUT,$libname,*crypto_list,@crypto_symbols)
411 my($name,$files,$symhacksfile)=@_;
415 my %platform; # For anything undefined, we assume ""
416 my %kind; # For anything undefined, we assume "FUNCTION"
417 my %algorithm; # For anything undefined, we assume ""
419 my %variant_cnt; # To be able to allocate "name{n}" if "name"
420 # is the same name as the original.
422 my %unknown_algorithms = ();
425 foreach $file (split(/\s+/,$symhacksfile." ".$files))
427 print STDERR "DEBUG: starting on $file:\n" if $debug;
428 open(IN,"<$file") || die "unable to open $file:$!\n";
429 my $line = "", my $def= "";
431 (map { $_ => 0 } @known_platforms),
432 (map { "OPENSSL_SYS_".$_ => 0 } @known_ossl_platforms),
433 (map { "OPENSSL_NO_".$_ => 0 } @known_algorithms),
434 (map { "OPENSSL_USE_".$_ => 0 } @known_algorithms),
441 my $symhacking = $file eq $symhacksfile;
442 my @current_platforms = ();
443 my @current_algorithms = ();
445 # params: symbol, alias, platforms, kind
446 # The reason to put this subroutine in a variable is that
447 # it will otherwise create it's own, unshared, version of
448 # %tag and %variant...
449 my $make_variant = sub
451 my ($s, $a, $p, $k) = @_;
454 print STDERR "DEBUG: make_variant: Entered with ",$s,", ",$a,", ",(defined($p)?$p:""),", ",(defined($k)?$k:""),"\n" if $debug;
459 map { $tag{$_} == 1 ? $_ : "" }
466 map { $tag{$_} == 1 ? $_ : "" }
471 map { $tag{"OPENSSL_SYS_".$_} == 1 ? $_ : "" }
472 @known_ossl_platforms));
473 print STDERR "DEBUG: make_variant: a1 = $a1; a2 = $a2\n" if $debug;
474 if ($a1 eq "") { $a1 = $a2; }
475 elsif ($a1 ne "" && $a2 ne "") { $a1 .= ",".$a2; }
478 if (!defined($variant_cnt{$s}))
480 $variant_cnt{$s} = 0;
483 $a .= "{$variant_cnt{$s}}";
485 my $toadd = $a.":".$a1.(defined($k)?":".$k:"");
486 my $togrep = $s.'(\{[0-9]+\})?:'.$a1.(defined($k)?":".$k:"");
487 if (!grep(/^$togrep$/,
488 split(/;/, defined($variant{$s})?$variant{$s}:""))) {
489 if (defined($variant{$s})) { $variant{$s} .= ";"; }
490 $variant{$s} .= $toadd;
492 print STDERR "DEBUG: make_variant: Exit with variant of ",$s," = ",$variant{$s},"\n" if $debug;
495 print STDERR "DEBUG: parsing ----------\n" if $debug;
498 #Inside a DECLARE_DEPRECATED
499 $stored_multiline .= $_;
500 chomp $stored_multiline;
501 print STDERR "DEBUG: Continuing multiline DEPRECATED: $stored_multiline\n" if $debug;
502 $parens = count_parens($stored_multiline);
504 $stored_multiline =~ /^\s*DECLARE_DEPRECATED\s*\(\s*(\w*(\s|\*|\w)*)/;
509 if (/\/\* Error codes for the \w+ functions\. \*\//)
521 chop; # remove ending backslash
527 if (not /\*\//) { # multiline comment...
528 $line = $_; # ... just accumulate
531 s/\/\*.*?\*\///gs;# wipe it
537 $cpp-- if /^#\s*endif/;
540 $cpp = 1 if /^#.*ifdef.*cplusplus/;
542 s/{[^{}]*}//gs; # ignore {} blocks
543 print STDERR "DEBUG: \$def=\"$def\"\n" if $debug && $def ne "";
544 print STDERR "DEBUG: \$_=\"$_\"\n" if $debug;
545 if (/^\#\s*ifndef\s+(.*)/) {
549 print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
550 } elsif (/^\#\s*if\s+!defined\(([^\)]+)\)/) {
552 if (/^\#\s*if\s+(!defined\(([^\)]+)\)(\s+\&\&\s+!defined\(([^\)]+)\))*)$/) {
555 foreach $tmp_ (split '\&\&',$tmp_1) {
556 $tmp_ =~ /!defined\(([^\)]+)\)/;
557 print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
562 print STDERR "Warning: $file: complicated expression: $_" if $debug; # because it is O...
563 print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
567 } elsif (/^\#\s*ifdef\s+(\S*)/) {
571 print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
572 } elsif (/^\#\s*if\s+defined\(([^\)]+)\)/) {
574 if (/^\#\s*if\s+(defined\(([^\)]+)\)(\s+\|\|\s+defined\(([^\)]+)\))*)$/) {
577 foreach $tmp_ (split '\|\|',$tmp_1) {
578 $tmp_ =~ /defined\(([^\)]+)\)/;
579 print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
584 print STDERR "Warning: $file: complicated expression: $_\n" if $debug; # because it is O...
585 print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
589 } elsif (/^\#\s*error\s+(\w+) is disabled\./) {
591 while($tag[$tag_i] ne "-") {
592 if ($tag[$tag_i] eq "OPENSSL_NO_".$1) {
593 $tag{$tag[$tag_i]}=2;
594 print STDERR "DEBUG: $file: chaged tag $1 = 2\n" if $debug;
598 } elsif (/^\#\s*endif/) {
600 while($tag_i > 0 && $tag[$tag_i] ne "-") {
602 print STDERR "DEBUG: \$t=\"$t\"\n" if $debug;
608 print STDERR "DEBUG: $file: changed tag ",$t," = ",$tag{$t},"\n" if $debug;
610 if ($t =~ /^OPENSSL_NO_([A-Z0-9_]+)$/) {
612 } elsif($t =~ /^OPENSSL_USE_([A-Z0-9_]+)$/) {
618 && !grep(/^$t$/, @known_algorithms)) {
619 $unknown_algorithms{$t} = 1;
620 #print STDERR "DEBUG: Added as unknown algorithm: $t\n" if $debug;
625 } elsif (/^\#\s*else/) {
627 while($tag[$tag_i] ne "-") {
630 print STDERR "DEBUG: $file: changed tag ",$t," = ",$tag{$t},"\n" if $debug;
633 } elsif (/^\#\s*if\s+1/) {
638 print STDERR "DEBUG: $file: found 1\n" if $debug;
639 } elsif (/^\#\s*if\s+0/) {
644 print STDERR "DEBUG: $file: found 0\n" if $debug;
645 } elsif (/^\#\s*define\s+(\w+)\s+(\w+)/
646 && $symhacking && $tag{'TRUE'} != -1) {
647 # This is for aliasing. When we find an alias,
649 &$make_variant($1,$2);
650 print STDERR "DEBUG: $file: defined $1 = $2\n" if $debug;
655 map { $tag{$_} == 1 ? $_ :
656 $tag{$_} == -1 ? "!".$_ : "" }
658 push @current_platforms
660 map { $tag{"OPENSSL_SYS_".$_} == 1 ? $_ :
661 $tag{"OPENSSL_SYS_".$_} == -1 ? "!".$_ : "" }
662 @known_ossl_platforms);
663 @current_algorithms = ();
664 @current_algorithms =
666 map { $tag{"OPENSSL_NO_".$_} == -1 ? $_ : "" }
668 push @current_algorithms
670 map { $tag{"OPENSSL_USE_".$_} == 1 ? $_ : "" }
674 .join(',',@current_platforms).":"
675 .join(',',@current_algorithms).";";
678 if ($tag{'TRUE'} != -1) {
679 if (/^\s*DECLARE_STACK_OF\s*\(\s*(\w*)\s*\)/) {
681 } elsif (/^\s*DECLARE_ASN1_ENCODE_FUNCTIONS\s*\(\s*(\w*)\s*,\s*(\w*)\s*,\s*(\w*)\s*\)/) {
682 $def .= "int d2i_$3(void);";
683 $def .= "int i2d_$3(void);";
684 # Variant for platforms that do not
685 # have to access globale variables
686 # in shared libraries through functions
689 .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
690 .join(',',@current_algorithms).";";
691 $def .= "OPENSSL_EXTERN int $2_it;";
694 .join(',',@current_platforms).":"
695 .join(',',@current_algorithms).";";
696 # Variant for platforms that have to
697 # access globale variables in shared
698 # libraries through functions
699 &$make_variant("$2_it","$2_it",
700 "EXPORT_VAR_AS_FUNCTION",
703 } elsif (/^\s*DECLARE_ASN1_FUNCTIONS_fname\s*\(\s*(\w*)\s*,\s*(\w*)\s*,\s*(\w*)\s*\)/) {
704 $def .= "int d2i_$3(void);";
705 $def .= "int i2d_$3(void);";
706 $def .= "int $3_free(void);";
707 $def .= "int $3_new(void);";
708 # Variant for platforms that do not
709 # have to access globale variables
710 # in shared libraries through functions
713 .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
714 .join(',',@current_algorithms).";";
715 $def .= "OPENSSL_EXTERN int $2_it;";
718 .join(',',@current_platforms).":"
719 .join(',',@current_algorithms).";";
720 # Variant for platforms that have to
721 # access globale variables in shared
722 # libraries through functions
723 &$make_variant("$2_it","$2_it",
724 "EXPORT_VAR_AS_FUNCTION",
727 } elsif (/^\s*DECLARE_ASN1_FUNCTIONS\s*\(\s*(\w*)\s*\)/ ||
728 /^\s*DECLARE_ASN1_FUNCTIONS_const\s*\(\s*(\w*)\s*\)/) {
729 $def .= "int d2i_$1(void);";
730 $def .= "int i2d_$1(void);";
731 $def .= "int $1_free(void);";
732 $def .= "int $1_new(void);";
733 # Variant for platforms that do not
734 # have to access globale variables
735 # in shared libraries through functions
738 .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
739 .join(',',@current_algorithms).";";
740 $def .= "OPENSSL_EXTERN int $1_it;";
743 .join(',',@current_platforms).":"
744 .join(',',@current_algorithms).";";
745 # Variant for platforms that have to
746 # access globale variables in shared
747 # libraries through functions
748 &$make_variant("$1_it","$1_it",
749 "EXPORT_VAR_AS_FUNCTION",
752 } elsif (/^\s*DECLARE_ASN1_ENCODE_FUNCTIONS_const\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
753 $def .= "int d2i_$2(void);";
754 $def .= "int i2d_$2(void);";
755 # Variant for platforms that do not
756 # have to access globale variables
757 # in shared libraries through functions
760 .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
761 .join(',',@current_algorithms).";";
762 $def .= "OPENSSL_EXTERN int $2_it;";
765 .join(',',@current_platforms).":"
766 .join(',',@current_algorithms).";";
767 # Variant for platforms that have to
768 # access globale variables in shared
769 # libraries through functions
770 &$make_variant("$2_it","$2_it",
771 "EXPORT_VAR_AS_FUNCTION",
774 } elsif (/^\s*DECLARE_ASN1_ALLOC_FUNCTIONS\s*\(\s*(\w*)\s*\)/) {
775 $def .= "int $1_free(void);";
776 $def .= "int $1_new(void);";
778 } elsif (/^\s*DECLARE_ASN1_FUNCTIONS_name\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
779 $def .= "int d2i_$2(void);";
780 $def .= "int i2d_$2(void);";
781 $def .= "int $2_free(void);";
782 $def .= "int $2_new(void);";
783 # Variant for platforms that do not
784 # have to access globale variables
785 # in shared libraries through functions
788 .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
789 .join(',',@current_algorithms).";";
790 $def .= "OPENSSL_EXTERN int $2_it;";
793 .join(',',@current_platforms).":"
794 .join(',',@current_algorithms).";";
795 # Variant for platforms that have to
796 # access globale variables in shared
797 # libraries through functions
798 &$make_variant("$2_it","$2_it",
799 "EXPORT_VAR_AS_FUNCTION",
802 } elsif (/^\s*DECLARE_ASN1_ITEM\s*\(\s*(\w*)\s*\)/) {
803 # Variant for platforms that do not
804 # have to access globale variables
805 # in shared libraries through functions
808 .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
809 .join(',',@current_algorithms).";";
810 $def .= "OPENSSL_EXTERN int $1_it;";
813 .join(',',@current_platforms).":"
814 .join(',',@current_algorithms).";";
815 # Variant for platforms that have to
816 # access globale variables in shared
817 # libraries through functions
818 &$make_variant("$1_it","$1_it",
819 "EXPORT_VAR_AS_FUNCTION",
822 } elsif (/^\s*DECLARE_ASN1_NDEF_FUNCTION\s*\(\s*(\w*)\s*\)/) {
823 $def .= "int i2d_$1_NDEF(void);";
824 } elsif (/^\s*DECLARE_ASN1_SET_OF\s*\(\s*(\w*)\s*\)/) {
826 } elsif (/^\s*DECLARE_ASN1_PRINT_FUNCTION\s*\(\s*(\w*)\s*\)/) {
827 $def .= "int $1_print_ctx(void);";
829 } elsif (/^\s*DECLARE_ASN1_PRINT_FUNCTION_name\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
830 $def .= "int $2_print_ctx(void);";
832 } elsif (/^\s*DECLARE_PKCS12_STACK_OF\s*\(\s*(\w*)\s*\)/) {
834 } elsif (/^DECLARE_PEM_rw\s*\(\s*(\w*)\s*,/ ||
835 /^DECLARE_PEM_rw_cb\s*\(\s*(\w*)\s*,/ ||
836 /^DECLARE_PEM_rw_const\s*\(\s*(\w*)\s*,/ ) {
839 .join(',',@current_platforms).":"
840 .join(',',@current_algorithms).";";
841 $def .= "int PEM_read_$1(void);";
842 $def .= "int PEM_write_$1(void);";
845 .join(',',@current_platforms).":"
846 .join(',',@current_algorithms).";";
847 # Things that are everywhere
848 $def .= "int PEM_read_bio_$1(void);";
849 $def .= "int PEM_write_bio_$1(void);";
851 } elsif (/^DECLARE_PEM_write\s*\(\s*(\w*)\s*,/ ||
852 /^DECLARE_PEM_write_const\s*\(\s*(\w*)\s*,/ ||
853 /^DECLARE_PEM_write_cb\s*\(\s*(\w*)\s*,/ ) {
856 .join(',',@current_platforms).":"
857 .join(',',@current_algorithms).";";
858 $def .= "int PEM_write_$1(void);";
861 .join(',',@current_platforms).":"
862 .join(',',@current_algorithms).";";
863 # Things that are everywhere
864 $def .= "int PEM_write_bio_$1(void);";
866 } elsif (/^DECLARE_PEM_read\s*\(\s*(\w*)\s*,/ ||
867 /^DECLARE_PEM_read_cb\s*\(\s*(\w*)\s*,/ ) {
870 .join(',',@current_platforms).":"
871 .join(',',@current_algorithms).";";
872 $def .= "int PEM_read_$1(void);";
875 .join(',',@current_platforms).":"
876 .join(',',@current_algorithms).";";
877 # Things that are everywhere
878 $def .= "int PEM_read_bio_$1(void);";
880 } elsif (/^OPENSSL_DECLARE_GLOBAL\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
881 # Variant for platforms that do not
882 # have to access globale variables
883 # in shared libraries through functions
886 .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
887 .join(',',@current_algorithms).";";
888 $def .= "OPENSSL_EXTERN int _shadow_$2;";
891 .join(',',@current_platforms).":"
892 .join(',',@current_algorithms).";";
893 # Variant for platforms that have to
894 # access globale variables in shared
895 # libraries through functions
896 &$make_variant("_shadow_$2","_shadow_$2",
897 "EXPORT_VAR_AS_FUNCTION",
899 } elsif (/^\s*DECLARE_DEPRECATED\s*\(\s*(\w*(\s|\*|\w)*)/) {
900 $parens = count_parens($_);
904 $stored_multiline = $_;
905 chomp $stored_multiline;
906 print STDERR "DEBUG: Found multiline DEPRECATED starting with: $stored_multiline\n" if $debug;
909 } elsif ($tag{'CONST_STRICT'} != 1) {
910 if (/\{|\/\*|\([^\)]*$/) {
923 print STDERR "DEBUG: postprocessing ----------\n" if $debug;
924 foreach (split /;/, $def) {
925 my $s; my $k = "FUNCTION"; my $p; my $a;
929 next if(/typedef\W/);
932 # Reduce argument lists to empty ()
933 # fold round brackets recursively: (t(*v)(t),t) -> (t{}{},t) -> {}
935 s/\([^\(\)]+\)/\{\}/gs;
936 s/\(\s*\*\s*(\w+)\s*\{\}\s*\)/$1/gs; #(*f{}) -> f
938 # pretend as we didn't use curly braces: {} -> ()
941 s/STACK_OF\(\)/void/gs;
942 s/LHASH_OF\(\)/void/gs;
944 print STDERR "DEBUG: \$_ = \"$_\"\n" if $debug;
945 if (/^\#INFO:([^:]*):(.*)$/) {
948 print STDERR "DEBUG: found info on platforms ($plats) and algorithms ($algs)\n" if $debug;
950 } elsif (/^\s*OPENSSL_EXTERN\s.*?(\w+(\{[0-9]+\})?)(\[[0-9]*\])*\s*$/) {
953 print STDERR "DEBUG: found external variable $s\n" if $debug;
954 } elsif (/TYPEDEF_\w+_OF/s) {
956 } elsif (/(\w+)\s*\(\).*/s) { # first token prior [first] () is
957 $s = $1; # a function name!
958 print STDERR "DEBUG: found function $s\n" if $debug;
959 } elsif (/\(/ and not (/=/)) {
960 print STDERR "File $file: cannot parse: $_;\n";
971 $a .= ",BF" if($s =~ /EVP_bf/);
972 $a .= ",CAST" if($s =~ /EVP_cast/);
973 $a .= ",DES" if($s =~ /EVP_des/);
974 $a .= ",DSA" if($s =~ /EVP_dss/);
975 $a .= ",IDEA" if($s =~ /EVP_idea/);
976 $a .= ",MD2" if($s =~ /EVP_md2/);
977 $a .= ",MD4" if($s =~ /EVP_md4/);
978 $a .= ",MD5" if($s =~ /EVP_md5/);
979 $a .= ",RC2" if($s =~ /EVP_rc2/);
980 $a .= ",RC4" if($s =~ /EVP_rc4/);
981 $a .= ",RC5" if($s =~ /EVP_rc5/);
982 $a .= ",RMD160" if($s =~ /EVP_ripemd/);
983 $a .= ",RSA" if($s =~ /EVP_(Open|Seal)(Final|Init)/);
984 $a .= ",RSA" if($s =~ /PEM_Seal(Final|Init|Update)/);
985 $a .= ",RSA" if($s =~ /RSAPrivateKey/);
986 $a .= ",RSA" if($s =~ /SSLv23?_((client|server)_)?method/);
989 &reduce_platforms((defined($platform{$s})?$platform{$s}.',':"").$p);
990 $algorithm{$s} .= ','.$a;
992 if (defined($variant{$s})) {
993 foreach $v (split /;/,$variant{$s}) {
994 (my $r, my $p, my $k) = split(/:/,$v);
995 my $ip = join ',',map({ /^!(.*)$/ ? $1 : "!".$_ } split /,/, $p);
997 if (!defined($k)) { $k = $kind{$s}; }
998 $kind{$r} = $k."(".$s.")";
999 $algorithm{$r} = $algorithm{$s};
1000 $platform{$r} = &reduce_platforms($platform{$s}.",".$p.",".$p);
1001 $platform{$s} = &reduce_platforms($platform{$s}.','.$ip.','.$ip);
1002 print STDERR "DEBUG: \$variant{\"$s\"} = ",$v,"; \$r = $r; \$p = ",$platform{$r},"; \$a = ",$algorithm{$r},"; \$kind = ",$kind{$r},"\n" if $debug;
1005 print STDERR "DEBUG: \$s = $s; \$p = ",$platform{$s},"; \$a = ",$algorithm{$s},"; \$kind = ",$kind{$s},"\n" if $debug;
1009 # Prune the returned symbols
1011 delete $syms{"bn_dump1"};
1012 $platform{"BIO_s_log"} .= ",!WIN32,!macintosh";
1014 $platform{"PEM_read_NS_CERT_SEQ"} = "VMS";
1015 $platform{"PEM_write_NS_CERT_SEQ"} = "VMS";
1016 $platform{"PEM_read_P8_PRIV_KEY_INFO"} = "VMS";
1017 $platform{"PEM_write_P8_PRIV_KEY_INFO"} = "VMS";
1018 $platform{"EVP_sha384"} = "!VMSVAX";
1019 $platform{"EVP_sha512"} = "!VMSVAX";
1020 $platform{"SHA384_Init"} = "!VMSVAX";
1021 $platform{"SHA384_Transform"} = "!VMSVAX";
1022 $platform{"SHA384_Update"} = "!VMSVAX";
1023 $platform{"SHA384_Final"} = "!VMSVAX";
1024 $platform{"SHA384"} = "!VMSVAX";
1025 $platform{"SHA512_Init"} = "!VMSVAX";
1026 $platform{"SHA512_Transform"} = "!VMSVAX";
1027 $platform{"SHA512_Update"} = "!VMSVAX";
1028 $platform{"SHA512_Final"} = "!VMSVAX";
1029 $platform{"SHA512"} = "!VMSVAX";
1032 # Info we know about
1034 push @ret, map { $_."\\".&info_string($_,"EXIST",
1037 $algorithm{$_}) } keys %syms;
1039 if (keys %unknown_algorithms) {
1040 print STDERR "WARNING: mkdef.pl doesn't know the following algorithms:\n";
1041 print STDERR "\t",join("\n\t",keys %unknown_algorithms),"\n";
1046 # Param: string of comma-separated platform-specs.
1047 sub reduce_platforms
1049 my ($platforms) = @_;
1050 my $pl = defined($platforms) ? $platforms : "";
1051 my %p = map { $_ => 0 } split /,/, $pl;
1054 print STDERR "DEBUG: Entered reduce_platforms with \"$platforms\"\n"
1056 # We do this, because if there's code like the following, it really
1057 # means the function exists in all cases and should therefore be
1058 # everywhere. By increasing and decreasing, we may attain 0:
1065 foreach $platform (split /,/, $pl) {
1066 if ($platform =~ /^!(.*)$/) {
1072 foreach $platform (keys %p) {
1073 if ($p{$platform} == 0) { delete $p{$platform}; }
1078 $ret = join(',',sort(map { $p{$_} < 0 ? "!".$_ : $_ } keys %p));
1079 print STDERR "DEBUG: Exiting reduce_platforms with \"$ret\"\n"
1085 (my $symbol, my $exist, my $platforms, my $kind, my $algorithms) = @_;
1087 my %a = defined($algorithms) ?
1088 map { $_ => 1 } split /,/, $algorithms : ();
1089 my $k = defined($kind) ? $kind : "FUNCTION";
1091 my $p = &reduce_platforms($platforms);
1098 $ret .= ":".join(',',sort keys %a);
1102 sub maybe_add_info {
1103 (my $name, *nums, my @symbols) = @_;
1108 print STDERR "Updating $name info\n";
1109 foreach $sym (@symbols) {
1110 (my $s, my $i) = split /\\/, $sym;
1111 if (defined($nums{$s})) {
1112 $i =~ s/^(.*?:.*?:\w+)(\(\w+\))?/$1/;
1113 (my $n, my $vers, my $dummy) = split /\\/, $nums{$s};
1114 if (!defined($dummy) || $i ne $dummy) {
1115 $nums{$s} = $n."\\".$vers."\\".$i;
1117 print STDERR "DEBUG: maybe_add_info for $s: \"$dummy\" => \"$i\"\n" if $debug;
1123 my @s=sort { &parse_number($nums{$a},"n") <=> &parse_number($nums{$b},"n") } keys %nums;
1125 (my $n, my $vers, my $i) = split /\\/, $nums{$sym};
1126 if (!defined($syms{$sym}) && $i !~ /^NOEXIST:/) {
1128 print STDERR "DEBUG: maybe_add_info for $sym: -> undefined\n" if $debug;
1132 print STDERR "$new_info old symbols got an info update\n";
1134 print STDERR "You should do a rewrite to fix this.\n";
1137 print STDERR "No old symbols needed info update\n";
1141 # Param: string of comma-separated keywords, each possibly prefixed with a "!"
1144 my ($keywords_txt,$platforms) = @_;
1145 my (@keywords) = split /,/,$keywords_txt;
1146 my ($falsesum, $truesum) = (0, 1);
1148 # Param: one keyword
1151 my ($keyword,$platforms) = @_;
1155 if ($keyword eq "VMSVAX" && $VMSVAX) { return 1; }
1156 if ($keyword eq "VMSNonVAX" && $VMSNonVAX) { return 1; }
1157 if ($keyword eq "VMS" && $VMS) { return 1; }
1158 if ($keyword eq "WIN32" && $W32) { return 1; }
1159 if ($keyword eq "WINNT" && $NT) { return 1; }
1160 if ($keyword eq "OS2" && $OS2) { return 1; }
1161 # Special platforms:
1162 # EXPORT_VAR_AS_FUNCTION means that global variables
1163 # will be represented as functions. This currently
1164 # only happens on VMS-VAX.
1165 if ($keyword eq "EXPORT_VAR_AS_FUNCTION" && ($VMSVAX || $W32)) {
1168 if ($keyword eq "OPENSSL_FIPSCAPABLE") {
1171 if ($keyword eq "OPENSSL_FIPS" && $fips) {
1174 if ($keyword eq "ZLIB" && $zlib) { return 1; }
1178 if ($keyword eq "RC2" && $no_rc2) { return 0; }
1179 if ($keyword eq "RC4" && $no_rc4) { return 0; }
1180 if ($keyword eq "RC5" && $no_rc5) { return 0; }
1181 if ($keyword eq "IDEA" && $no_idea) { return 0; }
1182 if ($keyword eq "DES" && $no_des) { return 0; }
1183 if ($keyword eq "BF" && $no_bf) { return 0; }
1184 if ($keyword eq "CAST" && $no_cast) { return 0; }
1185 if ($keyword eq "MD2" && $no_md2) { return 0; }
1186 if ($keyword eq "MD4" && $no_md4) { return 0; }
1187 if ($keyword eq "MD5" && $no_md5) { return 0; }
1188 if ($keyword eq "SHA" && $no_sha) { return 0; }
1189 if ($keyword eq "RMD160" && $no_ripemd) { return 0; }
1190 if ($keyword eq "MDC2" && $no_mdc2) { return 0; }
1191 if ($keyword eq "WHIRLPOOL" && $no_whirlpool) { return 0; }
1192 if ($keyword eq "RSA" && $no_rsa) { return 0; }
1193 if ($keyword eq "DSA" && $no_dsa) { return 0; }
1194 if ($keyword eq "DH" && $no_dh) { return 0; }
1195 if ($keyword eq "EC" && $no_ec) { return 0; }
1196 if ($keyword eq "AES" && $no_aes) { return 0; }
1197 if ($keyword eq "CAMELLIA" && $no_camellia) { return 0; }
1198 if ($keyword eq "SEED" && $no_seed) { return 0; }
1199 if ($keyword eq "SCRYPT" && $no_scrypt) { return 0; }
1200 if ($keyword eq "CHACHA" && $no_chacha) { return 0; }
1201 if ($keyword eq "POLY1305" && $no_poly1305) { return 0; }
1202 if ($keyword eq "EVP" && $no_evp) { return 0; }
1203 if ($keyword eq "LHASH" && $no_lhash) { return 0; }
1204 if ($keyword eq "STACK" && $no_stack) { return 0; }
1205 if ($keyword eq "ERR" && $no_err) { return 0; }
1206 if ($keyword eq "BUFFER" && $no_buffer) { return 0; }
1207 if ($keyword eq "BIO" && $no_bio) { return 0; }
1208 if ($keyword eq "COMP" && $no_comp) { return 0; }
1209 if ($keyword eq "DSO" && $no_dso) { return 0; }
1210 if ($keyword eq "ENGINE" && $no_engine) { return 0; }
1211 if ($keyword eq "HW" && $no_hw) { return 0; }
1212 if ($keyword eq "FP_API" && $no_fp_api) { return 0; }
1213 if ($keyword eq "STATIC_ENGINE" && $no_static_engine) { return 0; }
1214 if ($keyword eq "SCT" && $no_sct) { return 0; }
1215 if ($keyword eq "RFC3779" && $no_rfc3779) { return 0; }
1216 if ($keyword eq "PSK" && $no_psk) { return 0; }
1217 if ($keyword eq "CMS" && $no_cms) { return 0; }
1218 if ($keyword eq "EC_NISTP_64_GCC_128" && $no_nistp_gcc)
1220 if ($keyword eq "EC2M" && $no_ec2m) { return 0; }
1221 if ($keyword eq "NEXTPROTONEG" && $no_nextprotoneg) { return 0; }
1222 if ($keyword eq "SSL3_METHOD" && $no_ssl3_method) { return 0; }
1223 if ($keyword eq "SSL_TRACE" && $no_ssl_trace) { return 0; }
1224 if ($keyword eq "CAPIENG" && $no_capieng) { return 0; }
1225 if ($keyword eq "JPAKE" && $no_jpake) { return 0; }
1226 if ($keyword eq "SRP" && $no_srp) { return 0; }
1227 if ($keyword eq "SCTP" && $no_sctp) { return 0; }
1228 if ($keyword eq "SRTP" && $no_srtp) { return 0; }
1229 if ($keyword eq "UNIT_TEST" && $no_unit_test) { return 0; }
1230 if ($keyword eq "DEPRECATED" && $no_deprecated) { return 0; }
1231 if ($keyword eq "OCB" && $no_ocb) { return 0; }
1233 # Nothing recognise as true
1238 foreach $k (@keywords) {
1239 if ($k =~ /^!(.*)$/) {
1240 $falsesum += &recognise($1,$platforms);
1242 $truesum *= &recognise($k,$platforms);
1245 print STDERR "DEBUG: [",$#keywords,",",$#keywords < 0,"] is_valid($keywords_txt) => (\!$falsesum) && $truesum = ",(!$falsesum) && $truesum,"\n" if $debug;
1246 return (!$falsesum) && $truesum;
1251 (*OUT,my $name,*nums,my $testall,my @symbols)=@_;
1252 my $n = 1; my @e; my @r;
1253 my $sym; my $prev = ""; my $prefSSLeay;
1255 (@e)=grep(/^SSLeay(\{[0-9]+\})?\\.*?:.*?:.*/,@symbols);
1256 (@r)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:.*/ && !/^SSLeay(\{[0-9]+\})?\\.*?:.*?:.*/,@symbols);
1257 @symbols=((sort @e),(sort @r));
1259 foreach $sym (@symbols) {
1260 (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
1262 $v = 1 if $i=~ /^.*?:.*?:VARIABLE/;
1263 my $p = ($i =~ /^[^:]*:([^:]*):/,$1);
1264 my $a = ($i =~ /^[^:]*:[^:]*:[^:]*:([^:]*)/,$1);
1265 if (!defined($nums{$s})) {
1266 print STDERR "Warning: $s does not have a number assigned\n"
1268 } elsif (is_valid($p,1) && is_valid($a,0)) {
1269 my $s2 = ($s =~ /^(.*?)(\{[0-9]+\})?$/, $1);
1271 print OUT "\t/* The following has already appeared previously */\n";
1272 print STDERR "Warning: Symbol '",$s2,"' redefined. old=",($nums{$prev} =~ /^(.*?)\\/,$1),", new=",($nums{$s2} =~ /^(.*?)\\/,$1),"\n";
1274 $prev = $s2; # To warn about duplicates...
1276 (my $nn, my $vers, my $ni) = split /\\/, $nums{$s2};
1278 print OUT "\textern int $s2; /* type unknown */ /* $nn $ni */\n";
1280 print OUT "\textern int $s2(); /* type unknown */ /* $nn $ni */\n";
1289 open MF, 'Makefile' or return $v;
1291 $v = $1, last if /^VERSION=(.*?)\s*$/;
1299 (*OUT,my $name,*nums,my @symbols)=@_;
1300 my $n = 1; my @e; my @r; my @v; my $prev="";
1302 my $libname = $name;
1303 my $http_vendor = 'www.openssl.org/';
1304 my $version = get_version();
1305 my $what = "OpenSSL: implementation of Secure Socket Layer";
1306 my $description = "$what $version, $name - http://$http_vendor";
1307 my $prevsymversion = "", $prevprevsymversion = "";
1314 { # DLL names should not clash on the whole system.
1315 # However, they should not have any particular relationship
1316 # to the name of the static library. Chose descriptive names
1317 # (must be at most 8 chars).
1318 my %translate = (ssl => 'open_ssl', crypto => 'cryptssl');
1319 $libname = $translate{$name} || $name;
1320 $liboptions = <<EOO;
1322 DATA MULTIPLE NONSHARED
1324 # Vendor field can't contain colon, drat; so we omit http://
1325 $description = "\@#$http_vendor:$version#\@$what; DLL for library $name. Build for EMX -Zmtd";
1330 ; Definition file for the DLL version of the $name library from OpenSSL
1333 LIBRARY $libname $liboptions
1340 (@r)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:FUNCTION/,@symbols);
1341 (@v)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:VARIABLE/,@symbols);
1342 @symbols=((sort @e),(sort @r), (sort @v));
1344 my ($baseversion, $currversion) = get_openssl_version();
1347 if (!defined($thisversion)) {
1348 $thisversion = $baseversion;
1350 $thisversion = get_next_version($thisversion);
1352 foreach $sym (@symbols) {
1353 (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
1355 $v = 1 if $i =~ /^.*?:.*?:VARIABLE/;
1356 if (!defined($nums{$s})) {
1357 die "Error: $s does not have a number assigned\n"
1360 (my $n, my $symversion, my $dummy) = split /\\/, $nums{$s};
1361 next if $symversion ne $thisversion;
1363 my $p = ($i =~ /^[^:]*:([^:]*):/,$1);
1364 my $a = ($i =~ /^[^:]*:[^:]*:[^:]*:([^:]*)/,$1);
1365 if (is_valid($p,1) && is_valid($a,0)) {
1366 my $s2 = ($s =~ /^(.*?)(\{[0-9]+\})?$/, $1);
1368 print STDERR "Warning: Symbol '",$s2,
1369 "' redefined. old=",($nums{$prev} =~ /^(.*?)\\/,$1),
1370 ", new=",($nums{$s2} =~ /^(.*?)\\/,$1),"\n";
1372 $prev = $s2; # To warn about duplicates...
1374 if ($symversion ne $prevsymversion) {
1375 if ($prevsymversion ne "") {
1376 if ($prevprevsymversion ne "") {
1377 print OUT "} OPENSSL_"
1378 ."$prevprevsymversion;\n\n";
1383 print OUT "OPENSSL_$symversion {\n global:\n";
1384 $prevprevsymversion = $prevsymversion;
1385 $prevsymversion = $symversion;
1387 print OUT " $s2;\n";
1388 } elsif($v && !$OS2) {
1389 printf OUT " %s%-39s @%-8d DATA\n",
1390 ($W32)?"":"_",$s2,$n;
1392 printf OUT " %s%-39s @%d\n",
1393 ($W32||$OS2)?"":"_",$s2,$n;
1398 } while ($thisversion ne $currversion);
1400 if ($prevprevsymversion ne "") {
1401 print OUT " local: *;\n} OPENSSL_$prevprevsymversion;\n\n";
1403 print OUT " local: *;\n};\n\n";
1420 my ($baseversion, $currversion) = get_openssl_version();
1422 open(IN,"<$name") || die "unable to open $name:$!\n";
1428 if (defined $ret{$a[0]}) {
1429 # This is actually perfectly OK
1430 #print STDERR "Warning: Symbol '",$a[0],"' redefined. old=",$ret{$a[0]},", new=",$a[1],"\n";
1432 if ($max_num > $a[1]) {
1433 print STDERR "Warning: Number decreased from ",$max_num," to ",$a[1],"\n";
1435 elsif ($max_num == $a[1]) {
1436 # This is actually perfectly OK
1437 #print STDERR "Warning: Symbol ",$a[0]," has same number as previous ",$prev,": ",$a[1],"\n";
1438 if ($a[0] eq $prev) {
1440 $a[0] .= "{$prev_cnt}";
1447 # Existence will be proven later, in do_defs
1451 #Sanity check the version number
1452 if (defined $prevversion) {
1453 check_version_lte($prevversion, $a[2]);
1455 check_version_lte($a[2], $currversion);
1456 $prevversion = $a[2];
1457 $ret{$a[0]}=$a[1]."\\".$a[2]."\\".$a[3]; # \\ is a special marker
1459 $max_num = $a[1] if $a[1] > $max_num;
1463 print STDERR "Warning: $num_noinfo symbols were without info.";
1465 printf STDERR " The rewrite will fix this.\n";
1467 printf STDERR " You should do a rewrite to fix this.\n";
1476 (my $str, my $what) = @_;
1477 (my $n, my $v, my $i) = split(/\\/,$str);
1487 (*OUT,$name,*nums,@symbols)=@_;
1490 print STDERR "Rewriting $name\n";
1492 my @r = grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:\w+\(\w+\)/,@symbols);
1493 my $r; my %r; my %rsyms;
1495 (my $s, my $i) = split /\\/, $r;
1496 my $a = $1 if $i =~ /^.*?:.*?:\w+\((\w+)\)/;
1497 $i =~ s/^(.*?:.*?:\w+)\(\w+\)/$1/;
1498 $r{$a} = $s."\\".$i;
1503 foreach $_ (@symbols) {
1504 (my $n, my $i) = split /\\/;
1509 &parse_number($nums{$a},"n") <=> &parse_number($nums{$b},"n")
1513 (my $n, my $vers, my $i) = split /\\/, $nums{$sym};
1514 next if defined($i) && $i =~ /^.*?:.*?:\w+\(\w+\)/;
1515 next if defined($rsyms{$sym});
1516 print STDERR "DEBUG: rewrite_numbers for sym = ",$sym,": i = ",$i,", n = ",$n,", rsym{sym} = ",$rsyms{$sym},"syms{sym} = ",$syms{$sym},"\n" if $debug;
1517 $i="NOEXIST::FUNCTION:"
1518 if !defined($i) || $i eq "" || !defined($syms{$sym});
1520 $s2 =~ s/\{[0-9]+\}$//;
1521 printf OUT "%s%-39s %d\t%s\t%s\n","",$s2,$n,$vers,$i;
1522 if (exists $r{$sym}) {
1523 (my $s, $i) = split /\\/,$r{$sym};
1525 $s2 =~ s/\{[0-9]+\}$//;
1526 printf OUT "%s%-39s %d\t%s\t%s\n","",$s2,$n,$vers,$i;
1533 (*OUT,$name,*nums,my $start_num, my @symbols)=@_;
1538 ($basevers, $vers) = get_openssl_version();
1540 print STDERR "Updating $name numbers\n";
1542 my @r = grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:\w+\(\w+\)/,@symbols);
1543 my $r; my %r; my %rsyms;
1545 (my $s, my $i) = split /\\/, $r;
1546 my $a = $1 if $i =~ /^.*?:.*?:\w+\((\w+)\)/;
1547 $i =~ s/^(.*?:.*?:\w+)\(\w+\)/$1/;
1548 $r{$a} = $s."\\".$i;
1552 foreach $sym (@symbols) {
1553 (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
1554 next if $i =~ /^.*?:.*?:\w+\(\w+\)/;
1555 next if defined($rsyms{$sym});
1556 die "ERROR: Symbol $sym had no info attached to it."
1558 next if $i =~ /OPENSSL_FIPSCAPABLE/;
1559 if (!exists $nums{$s}) {
1562 $s2 =~ s/\{[0-9]+\}$//;
1563 printf OUT "%s%-39s %d\t%s\t%s\n","",$s2, ++$start_num,$vers,$i;
1564 if (exists $r{$s}) {
1565 ($s, $i) = split /\\/,$r{$s};
1566 $s =~ s/\{[0-9]+\}$//;
1567 printf OUT "%s%-39s %d\t%s\t%s\n","",$s, $start_num,$vers,$i;
1572 print STDERR "$new_syms New symbols added\n";
1574 print STDERR "No New symbols Added\n";
1580 (*nums, my @symbols)=@_;
1581 my %existing; my @remaining;
1583 foreach $sym (@symbols) {
1584 (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
1587 foreach $sym (keys %nums) {
1588 if (!exists $existing{$sym}) {
1589 push @remaining, $sym;
1593 print STDERR "The following symbols do not seem to exist:\n";
1594 foreach $sym (@remaining) {
1595 print STDERR "\t",$sym,"\n";
1602 my $line = shift(@_);
1604 my $open = $line =~ tr/\(//;
1605 my $close = $line =~ tr/\)//;
1607 return $open - $close;
1610 #Parse opensslv.h to get the current version number. Also work out the base
1611 #version, i.e. the lowest version number that is binary compatible with this
1613 sub get_openssl_version()
1615 open (IN, "include/openssl/opensslv.h") || die "Can't open opensslv.h";
1618 if (/OPENSSL_VERSION_TEXT\s+"OpenSSL (\d\.\d\.)(\d[a-z]*)(-| )/) {
1620 my $baseversion = $1 =~ s/\./_/gr;
1622 return ($baseversion."0", $baseversion.$suffix);
1625 die "Can't find OpenSSL version number\n";
1628 #Given an OpenSSL version number, calculate the next version number. If the
1629 #version number gets to a.b.czz then we go to a.b.(c+1)
1630 sub get_next_version()
1632 my $thisversion = shift;
1634 my ($base, $letter) = $thisversion =~ /^(\d_\d_\d)([a-z]{0,2})$/;
1636 if ($letter eq "zz") {
1637 my $lastnum = substr($base, -1);
1638 return substr($base, 0, length($base)-1).(++$lastnum);
1640 return $base.get_next_letter($letter);
1643 #Given the letters off the end of an OpenSSL version string, calculate what
1644 #the letters for the next release would be.
1645 sub get_next_letter()
1647 my $thisletter = shift;
1648 my $baseletter = "";
1651 if ($thisletter eq "") {
1654 if ((length $thisletter) > 1) {
1655 ($baseletter, $endletter) = $thisletter =~ /([a-z]+)([a-z])/;
1657 $endletter = $thisletter;
1660 if ($endletter eq "z") {
1661 return $thisletter."a";
1663 return $baseletter.(++$endletter);
1667 #Check if a version is less than or equal to the current version. Its a fatal
1668 #error if not. They must also only differ in letters, or the last number (i.e.
1669 #the first two numbers must be the same)
1670 sub check_version_lte()
1672 my ($testversion, $currversion) = @_;
1677 my ($cvnums) = $currversion =~ /^(\d_\d_\d)[a-z]*$/;
1678 my ($tvnums) = $testversion =~ /^(\d_\d_\d)[a-z]*$/;
1680 #Die if we can't parse the version numbers or they don't look sane
1681 die "Invalid version number: $testversion and $currversion\n"
1682 if (!defined($cvnums) || !defined($tvnums)
1683 || length($cvnums) != 5
1684 || length($tvnums) != 5);
1686 #If the base versions (without letters) don't match check they only differ
1688 if ($cvnums ne $tvnums) {
1689 die "Invalid version number: $testversion "
1690 ."for current version $currversion\n"
1691 if (substr($cvnums, -1) < substr($tvnums, -1)
1692 || substr($cvnums, 0, 4) ne substr($tvnums, 0, 4));
1695 #If we get here then the base version (i.e. the numbers) are the same - they
1696 #only differ in the letters
1698 $lentv = length $testversion;
1699 $lencv = length $currversion;
1701 #If the testversion has more letters than the current version then it must
1702 #be later (or malformed)
1703 if ($lentv > $lencv) {
1704 die "Invalid version number: $testversion "
1705 ."is greater than $currversion\n";
1708 #Get the last letter from the current version
1709 my ($cvletter) = $currversion =~ /([a-z])$/;
1710 if (defined $cvletter) {
1711 ($cvbase) = $currversion =~ /(\d_\d_\d[a-z]*)$cvletter$/;
1713 $cvbase = $currversion;
1715 die "Unable to parse version number $currversion" if (!defined $cvbase);
1717 my ($tvletter) = $testversion =~ /([a-z])$/;
1718 if (defined $tvletter) {
1719 ($tvbase) = $testversion =~ /(\d_\d_\d[a-z]*)$tvletter$/;
1721 $tvbase = $testversion;
1723 die "Unable to parse version number $testversion" if (!defined $tvbase);
1725 if ($lencv > $lentv) {
1726 #If current version has more letters than testversion then testversion
1727 #minus the final letter must be a substring of the current version
1728 die "Invalid version number $testversion "
1729 ."is greater than $currversion or is invalid\n"
1730 if (index($cvbase, $tvbase) != 0);
1732 #If both versions have the same number of letters then they must be
1733 #equal up to the last letter, and the last letter in testversion must
1734 #be less than or equal to the last letter in current version.
1735 die "Invalid version number $testversion "
1736 ."is greater than $currversion\n"
1737 if (($cvbase ne $tvbase) && ($tvletter gt $cvletter));