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"
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;
143 foreach (@ARGV, split(/ /, $options))
145 $debug=1 if $_ eq "debug";
146 $W32=1 if $_ eq "32";
147 die "win16 not supported" if $_ eq "16";
152 if ($_ eq "VMS-VAX") {
156 if ($_ eq "VMS-NonVAX") {
163 $VMS=$VMSNonVAX=1 if $_ eq "VMS";
164 $OS2=1 if $_ eq "OS2";
165 if ($_ eq "zlib" || $_ eq "enable-zlib" || $_ eq "zlib-dynamic"
166 || $_ eq "enable-zlib-dynamic") {
170 $do_ssl=1 if $_ eq "ssleay";
175 $do_crypto=1 if $_ eq "libeay";
176 if ($_ eq "crypto") {
180 $no_static_engine=1 if $_ eq "no-static-engine";
181 $no_static_engine=0 if $_ eq "enable-static-engine";
182 $do_update=1 if $_ eq "update";
183 $do_rewrite=1 if $_ eq "rewrite";
184 $do_ctest=1 if $_ eq "ctest";
185 $do_ctestall=1 if $_ eq "ctestall";
186 $do_checkexist=1 if $_ eq "exist";
187 #$safe_stack_def=1 if $_ eq "-DDEBUG_SAFESTACK";
189 if (/^no-rc2$/) { $no_rc2=1; }
190 elsif (/^no-rc4$/) { $no_rc4=1; }
191 elsif (/^no-rc5$/) { $no_rc5=1; }
192 elsif (/^no-idea$/) { $no_idea=1; }
193 elsif (/^no-des$/) { $no_des=1; $no_mdc2=1; }
194 elsif (/^no-bf$/) { $no_bf=1; }
195 elsif (/^no-cast$/) { $no_cast=1; }
196 elsif (/^no-whirlpool$/) { $no_whirlpool=1; }
197 elsif (/^no-md2$/) { $no_md2=1; }
198 elsif (/^no-md4$/) { $no_md4=1; }
199 elsif (/^no-md5$/) { $no_md5=1; }
200 elsif (/^no-sha$/) { $no_sha=1; }
201 elsif (/^no-ripemd$/) { $no_ripemd=1; }
202 elsif (/^no-mdc2$/) { $no_mdc2=1; }
203 elsif (/^no-rsa$/) { $no_rsa=1; }
204 elsif (/^no-dsa$/) { $no_dsa=1; }
205 elsif (/^no-dh$/) { $no_dh=1; }
206 elsif (/^no-ec$/) { $no_ec=1; }
207 elsif (/^no-aes$/) { $no_aes=1; }
208 elsif (/^no-camellia$/) { $no_camellia=1; }
209 elsif (/^no-seed$/) { $no_seed=1; }
210 elsif (/^no-scrypt$/) { $no_scrypt=1; }
211 elsif (/^no-chacha$/) { $no_chacha=1; }
212 elsif (/^no-poly1305$/) { $no_poly1305=1; }
213 elsif (/^no-evp$/) { $no_evp=1; }
214 elsif (/^no-lhash$/) { $no_lhash=1; }
215 elsif (/^no-stack$/) { $no_stack=1; }
216 elsif (/^no-err$/) { $no_err=1; }
217 elsif (/^no-buffer$/) { $no_buffer=1; }
218 elsif (/^no-bio$/) { $no_bio=1; }
219 #elsif (/^no-locking$/) { $no_locking=1; }
220 elsif (/^no-comp$/) { $no_comp=1; }
221 elsif (/^no-dso$/) { $no_dso=1; }
222 elsif (/^no-engine$/) { $no_engine=1; }
223 elsif (/^no-hw$/) { $no_hw=1; }
224 elsif (/^no-sct$/) { $no_sct=1; }
225 elsif (/^no-rfc3779$/) { $no_rfc3779=1; }
226 elsif (/^no-cms$/) { $no_cms=1; }
227 elsif (/^no-ec2m$/) { $no_ec2m=1; }
228 elsif (/^no-ec-nistp224-64-gcc-128$/) { $no_nistp_gcc=1; }
229 elsif (/^no-nextprotoneg$/) { $no_nextprotoneg=1; }
230 elsif (/^no-ssl3-method$/) { $no_ssl3_method=1; }
231 elsif (/^no-ssl-trace$/) { $no_ssl_trace=1; }
232 elsif (/^no-capieng$/) { $no_capieng=1; }
233 elsif (/^no-jpake$/) { $no_jpake=1; }
234 elsif (/^no-srp$/) { $no_srp=1; }
235 elsif (/^no-sctp$/) { $no_sctp=1; }
236 elsif (/^no-srtp$/) { $no_srtp=1; }
237 elsif (/^no-unit-test$/){ $no_unit_test=1; }
238 elsif (/^no-deprecated$/) { $no_deprecated=1; }
239 elsif (/^no-ocb/){ $no_ocb=1; }
252 # If no platform is given, assume WIN32
253 if ($W32 + $VMS + $OS2 + $linux == 0) {
256 die "Please, only one platform at a time"
257 if ($W32 + $VMS + $OS2 + $linux > 1);
259 if (!$do_ssl && !$do_crypto)
261 print STDERR "usage: $0 ( ssl | crypto ) [ 16 | 32 | NT | OS2 | linux | VMS ]\n";
265 %ssl_list=&load_numbers($ssl_num);
267 %crypto_list=&load_numbers($crypto_num);
268 $max_crypto = $max_num;
270 my $ssl="include/openssl/ssl.h";
271 $ssl.=" include/openssl/tls1.h";
272 $ssl.=" include/openssl/srtp.h";
274 my $crypto ="include/openssl/crypto.h";
275 $crypto.=" crypto/include/internal/cryptlib.h";
276 $crypto.=" crypto/include/internal/chacha.h"; # unless $no_chacha;
277 $crypto.=" crypto/include/internal/poly1305.h"; # unless $no_poly1305;
278 $crypto.=" include/internal/o_dir.h";
279 $crypto.=" include/internal/o_str.h";
280 $crypto.=" include/openssl/des.h" ; # unless $no_des;
281 $crypto.=" include/openssl/idea.h" ; # unless $no_idea;
282 $crypto.=" include/openssl/rc4.h" ; # unless $no_rc4;
283 $crypto.=" include/openssl/rc5.h" ; # unless $no_rc5;
284 $crypto.=" include/openssl/rc2.h" ; # unless $no_rc2;
285 $crypto.=" include/openssl/blowfish.h" ; # unless $no_bf;
286 $crypto.=" include/openssl/cast.h" ; # unless $no_cast;
287 $crypto.=" include/openssl/whrlpool.h" ;
288 $crypto.=" include/openssl/md2.h" ; # unless $no_md2;
289 $crypto.=" include/openssl/md4.h" ; # unless $no_md4;
290 $crypto.=" include/openssl/md5.h" ; # unless $no_md5;
291 $crypto.=" include/openssl/mdc2.h" ; # unless $no_mdc2;
292 $crypto.=" include/openssl/sha.h" ; # unless $no_sha;
293 $crypto.=" include/openssl/ripemd.h" ; # unless $no_ripemd;
294 $crypto.=" include/openssl/aes.h" ; # unless $no_aes;
295 $crypto.=" include/openssl/camellia.h" ; # unless $no_camellia;
296 $crypto.=" include/openssl/seed.h"; # unless $no_seed;
298 $crypto.=" include/openssl/bn.h";
299 $crypto.=" include/openssl/rsa.h" ; # unless $no_rsa;
300 $crypto.=" include/openssl/dsa.h" ; # unless $no_dsa;
301 $crypto.=" include/openssl/dh.h" ; # unless $no_dh;
302 $crypto.=" include/openssl/ec.h" ; # unless $no_ec;
303 $crypto.=" include/openssl/hmac.h" ; # unless $no_hmac;
304 $crypto.=" include/openssl/cmac.h" ;
306 $crypto.=" include/openssl/engine.h"; # unless $no_engine;
307 $crypto.=" include/openssl/stack.h" ; # unless $no_stack;
308 $crypto.=" include/openssl/buffer.h" ; # unless $no_buffer;
309 $crypto.=" include/openssl/bio.h" ; # unless $no_bio;
310 $crypto.=" include/openssl/dso.h" ; # unless $no_dso;
311 $crypto.=" include/openssl/lhash.h" ; # unless $no_lhash;
312 $crypto.=" include/openssl/conf.h";
313 $crypto.=" include/openssl/txt_db.h";
315 $crypto.=" include/openssl/evp.h" ; # unless $no_evp;
316 $crypto.=" include/openssl/objects.h";
317 $crypto.=" include/openssl/pem.h";
318 #$crypto.=" include/openssl/meth.h";
319 $crypto.=" include/openssl/asn1.h";
320 $crypto.=" include/openssl/asn1t.h";
321 $crypto.=" include/openssl/err.h" ; # unless $no_err;
322 $crypto.=" include/openssl/pkcs7.h";
323 $crypto.=" include/openssl/pkcs12.h";
324 $crypto.=" include/openssl/x509.h";
325 $crypto.=" include/openssl/x509_vfy.h";
326 $crypto.=" include/openssl/x509v3.h";
327 $crypto.=" include/openssl/ts.h";
328 $crypto.=" include/openssl/rand.h";
329 $crypto.=" include/openssl/comp.h" ; # unless $no_comp;
330 $crypto.=" include/openssl/ocsp.h";
331 $crypto.=" include/openssl/ui.h";
332 #$crypto.=" include/openssl/store.h";
333 $crypto.=" include/openssl/pqueue.h";
334 $crypto.=" include/openssl/cms.h";
335 $crypto.=" include/openssl/jpake.h";
336 $crypto.=" include/openssl/srp.h";
337 $crypto.=" include/openssl/modes.h";
338 $crypto.=" include/openssl/async.h";
340 my $symhacks="include/openssl/symhacks.h";
342 my @ssl_symbols = &do_defs("SSLEAY", $ssl, $symhacks);
343 my @crypto_symbols = &do_defs("LIBEAY", $crypto, $symhacks);
349 &maybe_add_info("SSLEAY",*ssl_list,@ssl_symbols);
350 if ($do_rewrite == 1) {
351 open(OUT, ">$ssl_num");
352 &rewrite_numbers(*OUT,"SSLEAY",*ssl_list,@ssl_symbols);
354 open(OUT, ">>$ssl_num");
356 &update_numbers(*OUT,"SSLEAY",*ssl_list,$max_ssl,@ssl_symbols);
360 if($do_crypto == 1) {
362 &maybe_add_info("LIBEAY",*crypto_list,@crypto_symbols);
363 if ($do_rewrite == 1) {
364 open(OUT, ">$crypto_num");
365 &rewrite_numbers(*OUT,"LIBEAY",*crypto_list,@crypto_symbols);
367 open(OUT, ">>$crypto_num");
369 &update_numbers(*OUT,"LIBEAY",*crypto_list,$max_crypto,@crypto_symbols);
373 } elsif ($do_checkexist) {
374 &check_existing(*ssl_list, @ssl_symbols)
376 &check_existing(*crypto_list, @crypto_symbols)
378 } elsif ($do_ctest || $do_ctestall) {
382 /* Test file to check all DEF file symbols are present by trying
383 * to link to all of them. This is *not* intended to be run!
389 &print_test_file(*STDOUT,"SSLEAY",*ssl_list,$do_ctestall,@ssl_symbols)
392 &print_test_file(*STDOUT,"LIBEAY",*crypto_list,$do_ctestall,@crypto_symbols)
399 &print_def_file(*STDOUT,$libname,*ssl_list,@ssl_symbols)
402 &print_def_file(*STDOUT,$libname,*crypto_list,@crypto_symbols)
410 my($name,$files,$symhacksfile)=@_;
414 my %platform; # For anything undefined, we assume ""
415 my %kind; # For anything undefined, we assume "FUNCTION"
416 my %algorithm; # For anything undefined, we assume ""
418 my %variant_cnt; # To be able to allocate "name{n}" if "name"
419 # is the same name as the original.
421 my %unknown_algorithms = ();
424 foreach $file (split(/\s+/,$symhacksfile." ".$files))
426 print STDERR "DEBUG: starting on $file:\n" if $debug;
427 open(IN,"<$file") || die "unable to open $file:$!\n";
428 my $line = "", my $def= "";
430 (map { $_ => 0 } @known_platforms),
431 (map { "OPENSSL_SYS_".$_ => 0 } @known_ossl_platforms),
432 (map { "OPENSSL_NO_".$_ => 0 } @known_algorithms),
433 (map { "OPENSSL_USE_".$_ => 0 } @known_algorithms),
440 my $symhacking = $file eq $symhacksfile;
441 my @current_platforms = ();
442 my @current_algorithms = ();
444 # params: symbol, alias, platforms, kind
445 # The reason to put this subroutine in a variable is that
446 # it will otherwise create it's own, unshared, version of
447 # %tag and %variant...
448 my $make_variant = sub
450 my ($s, $a, $p, $k) = @_;
453 print STDERR "DEBUG: make_variant: Entered with ",$s,", ",$a,", ",(defined($p)?$p:""),", ",(defined($k)?$k:""),"\n" if $debug;
458 map { $tag{$_} == 1 ? $_ : "" }
465 map { $tag{$_} == 1 ? $_ : "" }
470 map { $tag{"OPENSSL_SYS_".$_} == 1 ? $_ : "" }
471 @known_ossl_platforms));
472 print STDERR "DEBUG: make_variant: a1 = $a1; a2 = $a2\n" if $debug;
473 if ($a1 eq "") { $a1 = $a2; }
474 elsif ($a1 ne "" && $a2 ne "") { $a1 .= ",".$a2; }
477 if (!defined($variant_cnt{$s}))
479 $variant_cnt{$s} = 0;
482 $a .= "{$variant_cnt{$s}}";
484 my $toadd = $a.":".$a1.(defined($k)?":".$k:"");
485 my $togrep = $s.'(\{[0-9]+\})?:'.$a1.(defined($k)?":".$k:"");
486 if (!grep(/^$togrep$/,
487 split(/;/, defined($variant{$s})?$variant{$s}:""))) {
488 if (defined($variant{$s})) { $variant{$s} .= ";"; }
489 $variant{$s} .= $toadd;
491 print STDERR "DEBUG: make_variant: Exit with variant of ",$s," = ",$variant{$s},"\n" if $debug;
494 print STDERR "DEBUG: parsing ----------\n" if $debug;
497 #Inside a DECLARE_DEPRECATED
498 $stored_multiline .= $_;
499 chomp $stored_multiline;
500 print STDERR "DEBUG: Continuing multiline DEPRECATED: $stored_multiline\n" if $debug;
501 $parens = count_parens($stored_multiline);
503 $stored_multiline =~ /^\s*DECLARE_DEPRECATED\s*\(\s*(\w*(\s|\*|\w)*)/;
508 if (/\/\* Error codes for the \w+ functions\. \*\//)
520 chop; # remove ending backslash
526 if (not /\*\//) { # multiline comment...
527 $line = $_; # ... just accumulate
530 s/\/\*.*?\*\///gs;# wipe it
536 $cpp-- if /^#\s*endif/;
539 $cpp = 1 if /^#.*ifdef.*cplusplus/;
541 s/{[^{}]*}//gs; # ignore {} blocks
542 print STDERR "DEBUG: \$def=\"$def\"\n" if $debug && $def ne "";
543 print STDERR "DEBUG: \$_=\"$_\"\n" if $debug;
544 if (/^\#\s*ifndef\s+(.*)/) {
548 print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
549 } elsif (/^\#\s*if\s+!defined\(([^\)]+)\)/) {
551 if (/^\#\s*if\s+(!defined\(([^\)]+)\)(\s+\&\&\s+!defined\(([^\)]+)\))*)$/) {
554 foreach $tmp_ (split '\&\&',$tmp_1) {
555 $tmp_ =~ /!defined\(([^\)]+)\)/;
556 print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
561 print STDERR "Warning: $file: complicated expression: $_" if $debug; # because it is O...
562 print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
566 } elsif (/^\#\s*ifdef\s+(\S*)/) {
570 print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
571 } elsif (/^\#\s*if\s+defined\(([^\)]+)\)/) {
573 if (/^\#\s*if\s+(defined\(([^\)]+)\)(\s+\|\|\s+defined\(([^\)]+)\))*)$/) {
576 foreach $tmp_ (split '\|\|',$tmp_1) {
577 $tmp_ =~ /defined\(([^\)]+)\)/;
578 print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
583 print STDERR "Warning: $file: complicated expression: $_\n" if $debug; # because it is O...
584 print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
588 } elsif (/^\#\s*error\s+(\w+) is disabled\./) {
590 while($tag[$tag_i] ne "-") {
591 if ($tag[$tag_i] eq "OPENSSL_NO_".$1) {
592 $tag{$tag[$tag_i]}=2;
593 print STDERR "DEBUG: $file: chaged tag $1 = 2\n" if $debug;
597 } elsif (/^\#\s*endif/) {
599 while($tag_i > 0 && $tag[$tag_i] ne "-") {
601 print STDERR "DEBUG: \$t=\"$t\"\n" if $debug;
607 print STDERR "DEBUG: $file: changed tag ",$t," = ",$tag{$t},"\n" if $debug;
609 if ($t =~ /^OPENSSL_NO_([A-Z0-9_]+)$/) {
611 } elsif($t =~ /^OPENSSL_USE_([A-Z0-9_]+)$/) {
617 && !grep(/^$t$/, @known_algorithms)) {
618 $unknown_algorithms{$t} = 1;
619 #print STDERR "DEBUG: Added as unknown algorithm: $t\n" if $debug;
624 } elsif (/^\#\s*else/) {
626 while($tag[$tag_i] ne "-") {
629 print STDERR "DEBUG: $file: changed tag ",$t," = ",$tag{$t},"\n" if $debug;
632 } elsif (/^\#\s*if\s+1/) {
637 print STDERR "DEBUG: $file: found 1\n" if $debug;
638 } elsif (/^\#\s*if\s+0/) {
643 print STDERR "DEBUG: $file: found 0\n" if $debug;
644 } elsif (/^\#\s*define\s+(\w+)\s+(\w+)/
645 && $symhacking && $tag{'TRUE'} != -1) {
646 # This is for aliasing. When we find an alias,
648 &$make_variant($1,$2);
649 print STDERR "DEBUG: $file: defined $1 = $2\n" if $debug;
654 map { $tag{$_} == 1 ? $_ :
655 $tag{$_} == -1 ? "!".$_ : "" }
657 push @current_platforms
659 map { $tag{"OPENSSL_SYS_".$_} == 1 ? $_ :
660 $tag{"OPENSSL_SYS_".$_} == -1 ? "!".$_ : "" }
661 @known_ossl_platforms);
662 @current_algorithms = ();
663 @current_algorithms =
665 map { $tag{"OPENSSL_NO_".$_} == -1 ? $_ : "" }
667 push @current_algorithms
669 map { $tag{"OPENSSL_USE_".$_} == 1 ? $_ : "" }
673 .join(',',@current_platforms).":"
674 .join(',',@current_algorithms).";";
677 if ($tag{'TRUE'} != -1) {
678 if (/^\s*DECLARE_STACK_OF\s*\(\s*(\w*)\s*\)/) {
680 } elsif (/^\s*DECLARE_ASN1_ENCODE_FUNCTIONS\s*\(\s*(\w*)\s*,\s*(\w*)\s*,\s*(\w*)\s*\)/) {
681 $def .= "int d2i_$3(void);";
682 $def .= "int i2d_$3(void);";
683 # Variant for platforms that do not
684 # have to access globale variables
685 # in shared libraries through functions
688 .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
689 .join(',',@current_algorithms).";";
690 $def .= "OPENSSL_EXTERN int $2_it;";
693 .join(',',@current_platforms).":"
694 .join(',',@current_algorithms).";";
695 # Variant for platforms that have to
696 # access globale variables in shared
697 # libraries through functions
698 &$make_variant("$2_it","$2_it",
699 "EXPORT_VAR_AS_FUNCTION",
702 } elsif (/^\s*DECLARE_ASN1_FUNCTIONS_fname\s*\(\s*(\w*)\s*,\s*(\w*)\s*,\s*(\w*)\s*\)/) {
703 $def .= "int d2i_$3(void);";
704 $def .= "int i2d_$3(void);";
705 $def .= "int $3_free(void);";
706 $def .= "int $3_new(void);";
707 # Variant for platforms that do not
708 # have to access globale variables
709 # in shared libraries through functions
712 .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
713 .join(',',@current_algorithms).";";
714 $def .= "OPENSSL_EXTERN int $2_it;";
717 .join(',',@current_platforms).":"
718 .join(',',@current_algorithms).";";
719 # Variant for platforms that have to
720 # access globale variables in shared
721 # libraries through functions
722 &$make_variant("$2_it","$2_it",
723 "EXPORT_VAR_AS_FUNCTION",
726 } elsif (/^\s*DECLARE_ASN1_FUNCTIONS\s*\(\s*(\w*)\s*\)/ ||
727 /^\s*DECLARE_ASN1_FUNCTIONS_const\s*\(\s*(\w*)\s*\)/) {
728 $def .= "int d2i_$1(void);";
729 $def .= "int i2d_$1(void);";
730 $def .= "int $1_free(void);";
731 $def .= "int $1_new(void);";
732 # Variant for platforms that do not
733 # have to access globale variables
734 # in shared libraries through functions
737 .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
738 .join(',',@current_algorithms).";";
739 $def .= "OPENSSL_EXTERN int $1_it;";
742 .join(',',@current_platforms).":"
743 .join(',',@current_algorithms).";";
744 # Variant for platforms that have to
745 # access globale variables in shared
746 # libraries through functions
747 &$make_variant("$1_it","$1_it",
748 "EXPORT_VAR_AS_FUNCTION",
751 } elsif (/^\s*DECLARE_ASN1_ENCODE_FUNCTIONS_const\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
752 $def .= "int d2i_$2(void);";
753 $def .= "int i2d_$2(void);";
754 # Variant for platforms that do not
755 # have to access globale variables
756 # in shared libraries through functions
759 .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
760 .join(',',@current_algorithms).";";
761 $def .= "OPENSSL_EXTERN int $2_it;";
764 .join(',',@current_platforms).":"
765 .join(',',@current_algorithms).";";
766 # Variant for platforms that have to
767 # access globale variables in shared
768 # libraries through functions
769 &$make_variant("$2_it","$2_it",
770 "EXPORT_VAR_AS_FUNCTION",
773 } elsif (/^\s*DECLARE_ASN1_ALLOC_FUNCTIONS\s*\(\s*(\w*)\s*\)/) {
774 $def .= "int $1_free(void);";
775 $def .= "int $1_new(void);";
777 } elsif (/^\s*DECLARE_ASN1_FUNCTIONS_name\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
778 $def .= "int d2i_$2(void);";
779 $def .= "int i2d_$2(void);";
780 $def .= "int $2_free(void);";
781 $def .= "int $2_new(void);";
782 # Variant for platforms that do not
783 # have to access globale variables
784 # in shared libraries through functions
787 .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
788 .join(',',@current_algorithms).";";
789 $def .= "OPENSSL_EXTERN int $2_it;";
792 .join(',',@current_platforms).":"
793 .join(',',@current_algorithms).";";
794 # Variant for platforms that have to
795 # access globale variables in shared
796 # libraries through functions
797 &$make_variant("$2_it","$2_it",
798 "EXPORT_VAR_AS_FUNCTION",
801 } elsif (/^\s*DECLARE_ASN1_ITEM\s*\(\s*(\w*)\s*\)/) {
802 # Variant for platforms that do not
803 # have to access globale variables
804 # in shared libraries through functions
807 .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
808 .join(',',@current_algorithms).";";
809 $def .= "OPENSSL_EXTERN int $1_it;";
812 .join(',',@current_platforms).":"
813 .join(',',@current_algorithms).";";
814 # Variant for platforms that have to
815 # access globale variables in shared
816 # libraries through functions
817 &$make_variant("$1_it","$1_it",
818 "EXPORT_VAR_AS_FUNCTION",
821 } elsif (/^\s*DECLARE_ASN1_NDEF_FUNCTION\s*\(\s*(\w*)\s*\)/) {
822 $def .= "int i2d_$1_NDEF(void);";
823 } elsif (/^\s*DECLARE_ASN1_SET_OF\s*\(\s*(\w*)\s*\)/) {
825 } elsif (/^\s*DECLARE_ASN1_PRINT_FUNCTION\s*\(\s*(\w*)\s*\)/) {
826 $def .= "int $1_print_ctx(void);";
828 } elsif (/^\s*DECLARE_ASN1_PRINT_FUNCTION_name\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
829 $def .= "int $2_print_ctx(void);";
831 } elsif (/^\s*DECLARE_PKCS12_STACK_OF\s*\(\s*(\w*)\s*\)/) {
833 } elsif (/^DECLARE_PEM_rw\s*\(\s*(\w*)\s*,/ ||
834 /^DECLARE_PEM_rw_cb\s*\(\s*(\w*)\s*,/ ||
835 /^DECLARE_PEM_rw_const\s*\(\s*(\w*)\s*,/ ) {
838 .join(',',@current_platforms).":"
839 .join(',',@current_algorithms).";";
840 $def .= "int PEM_read_$1(void);";
841 $def .= "int PEM_write_$1(void);";
844 .join(',',@current_platforms).":"
845 .join(',',@current_algorithms).";";
846 # Things that are everywhere
847 $def .= "int PEM_read_bio_$1(void);";
848 $def .= "int PEM_write_bio_$1(void);";
850 } elsif (/^DECLARE_PEM_write\s*\(\s*(\w*)\s*,/ ||
851 /^DECLARE_PEM_write_const\s*\(\s*(\w*)\s*,/ ||
852 /^DECLARE_PEM_write_cb\s*\(\s*(\w*)\s*,/ ) {
855 .join(',',@current_platforms).":"
856 .join(',',@current_algorithms).";";
857 $def .= "int PEM_write_$1(void);";
860 .join(',',@current_platforms).":"
861 .join(',',@current_algorithms).";";
862 # Things that are everywhere
863 $def .= "int PEM_write_bio_$1(void);";
865 } elsif (/^DECLARE_PEM_read\s*\(\s*(\w*)\s*,/ ||
866 /^DECLARE_PEM_read_cb\s*\(\s*(\w*)\s*,/ ) {
869 .join(',',@current_platforms).":"
870 .join(',',@current_algorithms).";";
871 $def .= "int PEM_read_$1(void);";
874 .join(',',@current_platforms).":"
875 .join(',',@current_algorithms).";";
876 # Things that are everywhere
877 $def .= "int PEM_read_bio_$1(void);";
879 } elsif (/^OPENSSL_DECLARE_GLOBAL\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
880 # Variant for platforms that do not
881 # have to access globale variables
882 # in shared libraries through functions
885 .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
886 .join(',',@current_algorithms).";";
887 $def .= "OPENSSL_EXTERN int _shadow_$2;";
890 .join(',',@current_platforms).":"
891 .join(',',@current_algorithms).";";
892 # Variant for platforms that have to
893 # access globale variables in shared
894 # libraries through functions
895 &$make_variant("_shadow_$2","_shadow_$2",
896 "EXPORT_VAR_AS_FUNCTION",
898 } elsif (/^\s*DECLARE_DEPRECATED\s*\(\s*(\w*(\s|\*|\w)*)/) {
899 $parens = count_parens($_);
903 $stored_multiline = $_;
904 chomp $stored_multiline;
905 print STDERR "DEBUG: Found multiline DEPRECATED starting with: $stored_multiline\n" if $debug;
908 } elsif ($tag{'CONST_STRICT'} != 1) {
909 if (/\{|\/\*|\([^\)]*$/) {
922 print STDERR "DEBUG: postprocessing ----------\n" if $debug;
923 foreach (split /;/, $def) {
924 my $s; my $k = "FUNCTION"; my $p; my $a;
928 next if(/typedef\W/);
931 # Reduce argument lists to empty ()
932 # fold round brackets recursively: (t(*v)(t),t) -> (t{}{},t) -> {}
934 s/\([^\(\)]+\)/\{\}/gs;
935 s/\(\s*\*\s*(\w+)\s*\{\}\s*\)/$1/gs; #(*f{}) -> f
937 # pretend as we didn't use curly braces: {} -> ()
940 s/STACK_OF\(\)/void/gs;
941 s/LHASH_OF\(\)/void/gs;
943 print STDERR "DEBUG: \$_ = \"$_\"\n" if $debug;
944 if (/^\#INFO:([^:]*):(.*)$/) {
947 print STDERR "DEBUG: found info on platforms ($plats) and algorithms ($algs)\n" if $debug;
949 } elsif (/^\s*OPENSSL_EXTERN\s.*?(\w+(\{[0-9]+\})?)(\[[0-9]*\])*\s*$/) {
952 print STDERR "DEBUG: found external variable $s\n" if $debug;
953 } elsif (/TYPEDEF_\w+_OF/s) {
955 } elsif (/(\w+)\s*\(\).*/s) { # first token prior [first] () is
956 $s = $1; # a function name!
957 print STDERR "DEBUG: found function $s\n" if $debug;
958 } elsif (/\(/ and not (/=/)) {
959 print STDERR "File $file: cannot parse: $_;\n";
970 $a .= ",BF" if($s =~ /EVP_bf/);
971 $a .= ",CAST" if($s =~ /EVP_cast/);
972 $a .= ",DES" if($s =~ /EVP_des/);
973 $a .= ",DSA" if($s =~ /EVP_dss/);
974 $a .= ",IDEA" if($s =~ /EVP_idea/);
975 $a .= ",MD2" if($s =~ /EVP_md2/);
976 $a .= ",MD4" if($s =~ /EVP_md4/);
977 $a .= ",MD5" if($s =~ /EVP_md5/);
978 $a .= ",RC2" if($s =~ /EVP_rc2/);
979 $a .= ",RC4" if($s =~ /EVP_rc4/);
980 $a .= ",RC5" if($s =~ /EVP_rc5/);
981 $a .= ",RMD160" if($s =~ /EVP_ripemd/);
982 $a .= ",RSA" if($s =~ /EVP_(Open|Seal)(Final|Init)/);
983 $a .= ",RSA" if($s =~ /PEM_Seal(Final|Init|Update)/);
984 $a .= ",RSA" if($s =~ /RSAPrivateKey/);
985 $a .= ",RSA" if($s =~ /SSLv23?_((client|server)_)?method/);
988 &reduce_platforms((defined($platform{$s})?$platform{$s}.',':"").$p);
989 $algorithm{$s} .= ','.$a;
991 if (defined($variant{$s})) {
992 foreach $v (split /;/,$variant{$s}) {
993 (my $r, my $p, my $k) = split(/:/,$v);
994 my $ip = join ',',map({ /^!(.*)$/ ? $1 : "!".$_ } split /,/, $p);
996 if (!defined($k)) { $k = $kind{$s}; }
997 $kind{$r} = $k."(".$s.")";
998 $algorithm{$r} = $algorithm{$s};
999 $platform{$r} = &reduce_platforms($platform{$s}.",".$p.",".$p);
1000 $platform{$s} = &reduce_platforms($platform{$s}.','.$ip.','.$ip);
1001 print STDERR "DEBUG: \$variant{\"$s\"} = ",$v,"; \$r = $r; \$p = ",$platform{$r},"; \$a = ",$algorithm{$r},"; \$kind = ",$kind{$r},"\n" if $debug;
1004 print STDERR "DEBUG: \$s = $s; \$p = ",$platform{$s},"; \$a = ",$algorithm{$s},"; \$kind = ",$kind{$s},"\n" if $debug;
1008 # Prune the returned symbols
1010 delete $syms{"bn_dump1"};
1011 $platform{"BIO_s_log"} .= ",!WIN32,!macintosh";
1013 $platform{"PEM_read_NS_CERT_SEQ"} = "VMS";
1014 $platform{"PEM_write_NS_CERT_SEQ"} = "VMS";
1015 $platform{"PEM_read_P8_PRIV_KEY_INFO"} = "VMS";
1016 $platform{"PEM_write_P8_PRIV_KEY_INFO"} = "VMS";
1017 $platform{"EVP_sha384"} = "!VMSVAX";
1018 $platform{"EVP_sha512"} = "!VMSVAX";
1019 $platform{"SHA384_Init"} = "!VMSVAX";
1020 $platform{"SHA384_Transform"} = "!VMSVAX";
1021 $platform{"SHA384_Update"} = "!VMSVAX";
1022 $platform{"SHA384_Final"} = "!VMSVAX";
1023 $platform{"SHA384"} = "!VMSVAX";
1024 $platform{"SHA512_Init"} = "!VMSVAX";
1025 $platform{"SHA512_Transform"} = "!VMSVAX";
1026 $platform{"SHA512_Update"} = "!VMSVAX";
1027 $platform{"SHA512_Final"} = "!VMSVAX";
1028 $platform{"SHA512"} = "!VMSVAX";
1031 # Info we know about
1033 push @ret, map { $_."\\".&info_string($_,"EXIST",
1036 $algorithm{$_}) } keys %syms;
1038 if (keys %unknown_algorithms) {
1039 print STDERR "WARNING: mkdef.pl doesn't know the following algorithms:\n";
1040 print STDERR "\t",join("\n\t",keys %unknown_algorithms),"\n";
1045 # Param: string of comma-separated platform-specs.
1046 sub reduce_platforms
1048 my ($platforms) = @_;
1049 my $pl = defined($platforms) ? $platforms : "";
1050 my %p = map { $_ => 0 } split /,/, $pl;
1053 print STDERR "DEBUG: Entered reduce_platforms with \"$platforms\"\n"
1055 # We do this, because if there's code like the following, it really
1056 # means the function exists in all cases and should therefore be
1057 # everywhere. By increasing and decreasing, we may attain 0:
1064 foreach $platform (split /,/, $pl) {
1065 if ($platform =~ /^!(.*)$/) {
1071 foreach $platform (keys %p) {
1072 if ($p{$platform} == 0) { delete $p{$platform}; }
1077 $ret = join(',',sort(map { $p{$_} < 0 ? "!".$_ : $_ } keys %p));
1078 print STDERR "DEBUG: Exiting reduce_platforms with \"$ret\"\n"
1084 (my $symbol, my $exist, my $platforms, my $kind, my $algorithms) = @_;
1086 my %a = defined($algorithms) ?
1087 map { $_ => 1 } split /,/, $algorithms : ();
1088 my $k = defined($kind) ? $kind : "FUNCTION";
1090 my $p = &reduce_platforms($platforms);
1097 $ret .= ":".join(',',sort keys %a);
1101 sub maybe_add_info {
1102 (my $name, *nums, my @symbols) = @_;
1107 print STDERR "Updating $name info\n";
1108 foreach $sym (@symbols) {
1109 (my $s, my $i) = split /\\/, $sym;
1110 if (defined($nums{$s})) {
1111 $i =~ s/^(.*?:.*?:\w+)(\(\w+\))?/$1/;
1112 (my $n, my $vers, my $dummy) = split /\\/, $nums{$s};
1113 if (!defined($dummy) || $i ne $dummy) {
1114 $nums{$s} = $n."\\".$vers."\\".$i;
1116 print STDERR "DEBUG: maybe_add_info for $s: \"$dummy\" => \"$i\"\n" if $debug;
1122 my @s=sort { &parse_number($nums{$a},"n") <=> &parse_number($nums{$b},"n") } keys %nums;
1124 (my $n, my $vers, my $i) = split /\\/, $nums{$sym};
1125 if (!defined($syms{$sym}) && $i !~ /^NOEXIST:/) {
1127 print STDERR "DEBUG: maybe_add_info for $sym: -> undefined\n" if $debug;
1131 print STDERR "$new_info old symbols got an info update\n";
1133 print STDERR "You should do a rewrite to fix this.\n";
1136 print STDERR "No old symbols needed info update\n";
1140 # Param: string of comma-separated keywords, each possibly prefixed with a "!"
1143 my ($keywords_txt,$platforms) = @_;
1144 my (@keywords) = split /,/,$keywords_txt;
1145 my ($falsesum, $truesum) = (0, 1);
1147 # Param: one keyword
1150 my ($keyword,$platforms) = @_;
1154 if ($keyword eq "VMSVAX" && $VMSVAX) { return 1; }
1155 if ($keyword eq "VMSNonVAX" && $VMSNonVAX) { return 1; }
1156 if ($keyword eq "VMS" && $VMS) { return 1; }
1157 if ($keyword eq "WIN32" && $W32) { return 1; }
1158 if ($keyword eq "WINNT" && $NT) { return 1; }
1159 if ($keyword eq "OS2" && $OS2) { return 1; }
1160 # Special platforms:
1161 # EXPORT_VAR_AS_FUNCTION means that global variables
1162 # will be represented as functions. This currently
1163 # only happens on VMS-VAX.
1164 if ($keyword eq "EXPORT_VAR_AS_FUNCTION" && ($VMSVAX || $W32)) {
1167 if ($keyword eq "ZLIB" && $zlib) { return 1; }
1171 if ($keyword eq "RC2" && $no_rc2) { return 0; }
1172 if ($keyword eq "RC4" && $no_rc4) { return 0; }
1173 if ($keyword eq "RC5" && $no_rc5) { return 0; }
1174 if ($keyword eq "IDEA" && $no_idea) { return 0; }
1175 if ($keyword eq "DES" && $no_des) { return 0; }
1176 if ($keyword eq "BF" && $no_bf) { return 0; }
1177 if ($keyword eq "CAST" && $no_cast) { return 0; }
1178 if ($keyword eq "MD2" && $no_md2) { return 0; }
1179 if ($keyword eq "MD4" && $no_md4) { return 0; }
1180 if ($keyword eq "MD5" && $no_md5) { return 0; }
1181 if ($keyword eq "SHA" && $no_sha) { return 0; }
1182 if ($keyword eq "RMD160" && $no_ripemd) { return 0; }
1183 if ($keyword eq "MDC2" && $no_mdc2) { return 0; }
1184 if ($keyword eq "WHIRLPOOL" && $no_whirlpool) { return 0; }
1185 if ($keyword eq "RSA" && $no_rsa) { return 0; }
1186 if ($keyword eq "DSA" && $no_dsa) { return 0; }
1187 if ($keyword eq "DH" && $no_dh) { return 0; }
1188 if ($keyword eq "EC" && $no_ec) { return 0; }
1189 if ($keyword eq "AES" && $no_aes) { return 0; }
1190 if ($keyword eq "CAMELLIA" && $no_camellia) { return 0; }
1191 if ($keyword eq "SEED" && $no_seed) { return 0; }
1192 if ($keyword eq "SCRYPT" && $no_scrypt) { return 0; }
1193 if ($keyword eq "CHACHA" && $no_chacha) { return 0; }
1194 if ($keyword eq "POLY1305" && $no_poly1305) { return 0; }
1195 if ($keyword eq "EVP" && $no_evp) { return 0; }
1196 if ($keyword eq "LHASH" && $no_lhash) { return 0; }
1197 if ($keyword eq "STACK" && $no_stack) { return 0; }
1198 if ($keyword eq "ERR" && $no_err) { return 0; }
1199 if ($keyword eq "BUFFER" && $no_buffer) { return 0; }
1200 if ($keyword eq "BIO" && $no_bio) { return 0; }
1201 if ($keyword eq "COMP" && $no_comp) { return 0; }
1202 if ($keyword eq "DSO" && $no_dso) { return 0; }
1203 if ($keyword eq "ENGINE" && $no_engine) { return 0; }
1204 if ($keyword eq "HW" && $no_hw) { return 0; }
1205 if ($keyword eq "FP_API" && $no_fp_api) { return 0; }
1206 if ($keyword eq "STATIC_ENGINE" && $no_static_engine) { return 0; }
1207 if ($keyword eq "SCT" && $no_sct) { return 0; }
1208 if ($keyword eq "RFC3779" && $no_rfc3779) { return 0; }
1209 if ($keyword eq "PSK" && $no_psk) { return 0; }
1210 if ($keyword eq "CMS" && $no_cms) { return 0; }
1211 if ($keyword eq "EC_NISTP_64_GCC_128" && $no_nistp_gcc)
1213 if ($keyword eq "EC2M" && $no_ec2m) { return 0; }
1214 if ($keyword eq "NEXTPROTONEG" && $no_nextprotoneg) { return 0; }
1215 if ($keyword eq "SSL3_METHOD" && $no_ssl3_method) { return 0; }
1216 if ($keyword eq "SSL_TRACE" && $no_ssl_trace) { return 0; }
1217 if ($keyword eq "CAPIENG" && $no_capieng) { return 0; }
1218 if ($keyword eq "JPAKE" && $no_jpake) { return 0; }
1219 if ($keyword eq "SRP" && $no_srp) { return 0; }
1220 if ($keyword eq "SCTP" && $no_sctp) { return 0; }
1221 if ($keyword eq "SRTP" && $no_srtp) { return 0; }
1222 if ($keyword eq "UNIT_TEST" && $no_unit_test) { return 0; }
1223 if ($keyword eq "DEPRECATED" && $no_deprecated) { return 0; }
1224 if ($keyword eq "OCB" && $no_ocb) { return 0; }
1226 # Nothing recognise as true
1231 foreach $k (@keywords) {
1232 if ($k =~ /^!(.*)$/) {
1233 $falsesum += &recognise($1,$platforms);
1235 $truesum *= &recognise($k,$platforms);
1238 print STDERR "DEBUG: [",$#keywords,",",$#keywords < 0,"] is_valid($keywords_txt) => (\!$falsesum) && $truesum = ",(!$falsesum) && $truesum,"\n" if $debug;
1239 return (!$falsesum) && $truesum;
1244 (*OUT,my $name,*nums,my $testall,my @symbols)=@_;
1245 my $n = 1; my @e; my @r;
1246 my $sym; my $prev = ""; my $prefSSLeay;
1248 (@e)=grep(/^SSLeay(\{[0-9]+\})?\\.*?:.*?:.*/,@symbols);
1249 (@r)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:.*/ && !/^SSLeay(\{[0-9]+\})?\\.*?:.*?:.*/,@symbols);
1250 @symbols=((sort @e),(sort @r));
1252 foreach $sym (@symbols) {
1253 (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
1255 $v = 1 if $i=~ /^.*?:.*?:VARIABLE/;
1256 my $p = ($i =~ /^[^:]*:([^:]*):/,$1);
1257 my $a = ($i =~ /^[^:]*:[^:]*:[^:]*:([^:]*)/,$1);
1258 if (!defined($nums{$s})) {
1259 print STDERR "Warning: $s does not have a number assigned\n"
1261 } elsif (is_valid($p,1) && is_valid($a,0)) {
1262 my $s2 = ($s =~ /^(.*?)(\{[0-9]+\})?$/, $1);
1264 print OUT "\t/* The following has already appeared previously */\n";
1265 print STDERR "Warning: Symbol '",$s2,"' redefined. old=",($nums{$prev} =~ /^(.*?)\\/,$1),", new=",($nums{$s2} =~ /^(.*?)\\/,$1),"\n";
1267 $prev = $s2; # To warn about duplicates...
1269 (my $nn, my $vers, my $ni) = split /\\/, $nums{$s2};
1271 print OUT "\textern int $s2; /* type unknown */ /* $nn $ni */\n";
1273 print OUT "\textern int $s2(); /* type unknown */ /* $nn $ni */\n";
1282 open MF, 'Makefile' or return $v;
1284 $v = $1, last if /^VERSION=(.*?)\s*$/;
1292 (*OUT,my $name,*nums,my @symbols)=@_;
1293 my $n = 1; my @e; my @r; my @v; my $prev="";
1295 my $libname = $name;
1296 my $http_vendor = 'www.openssl.org/';
1297 my $version = get_version();
1298 my $what = "OpenSSL: implementation of Secure Socket Layer";
1299 my $description = "$what $version, $name - http://$http_vendor";
1300 my $prevsymversion = "", $prevprevsymversion = "";
1303 my $symbolcount = 0;
1308 { # DLL names should not clash on the whole system.
1309 # However, they should not have any particular relationship
1310 # to the name of the static library. Chose descriptive names
1311 # (must be at most 8 chars).
1312 my %translate = (ssl => 'open_ssl', crypto => 'cryptssl');
1313 $libname = $translate{$name} || $name;
1314 $liboptions = <<EOO;
1316 DATA MULTIPLE NONSHARED
1318 # Vendor field can't contain colon, drat; so we omit http://
1319 $description = "\@#$http_vendor:$version#\@$what; DLL for library $name. Build for EMX -Zmtd";
1326 ; Definition file for the DLL version of the $name library from OpenSSL
1329 LIBRARY $libname $liboptions
1337 my $libref = $name eq "ssl" ? "LIBCRYPTO.EXE /SHARE" : "";
1339 IDENTIFICATION="LIB$libname V$version"
1340 LIB$libname.OLB /LIBRARY
1346 (@r)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:FUNCTION/,@symbols);
1347 (@v)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:VARIABLE/,@symbols);
1349 # VMS needs to have the symbols on slot number order
1350 @symbols=(map { $_->[1] }
1351 sort { $a->[0] <=> $b->[0] }
1352 map { (my $s, my $i) = $_ =~ /^(.*?)\\(.*)$/;
1353 die "Error: $s doesn't have a number assigned\n"
1354 if !defined($nums{$s});
1355 (my $n, my @rest) = split /\\/, $nums{$s};
1356 [ $n, $_ ] } (@e, @r, @v));
1358 @symbols=((sort @e),(sort @r), (sort @v));
1361 my ($baseversion, $currversion) = get_openssl_version();
1364 if (!defined($thisversion)) {
1365 $thisversion = $baseversion;
1367 $thisversion = get_next_version($thisversion);
1369 foreach $sym (@symbols) {
1370 (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
1372 $v = 1 if $i =~ /^.*?:.*?:VARIABLE/;
1373 if (!defined($nums{$s})) {
1374 die "Error: $s does not have a number assigned\n"
1377 (my $n, my $symversion, my $dummy) = split /\\/, $nums{$s};
1378 next if $symversion ne $thisversion;
1380 my $p = ($i =~ /^[^:]*:([^:]*):/,$1);
1381 my $a = ($i =~ /^[^:]*:[^:]*:[^:]*:([^:]*)/,$1);
1382 if (is_valid($p,1) && is_valid($a,0)) {
1383 my $s2 = ($s =~ /^(.*?)(\{[0-9]+\})?$/, $1);
1385 print STDERR "Warning: Symbol '",$s2,
1386 "' redefined. old=",($nums{$prev} =~ /^(.*?)\\/,$1),
1387 ", new=",($nums{$s2} =~ /^(.*?)\\/,$1),"\n";
1389 $prev = $s2; # To warn about duplicates...
1391 if ($symversion ne $prevsymversion) {
1392 if ($prevsymversion ne "") {
1393 if ($prevprevsymversion ne "") {
1394 print OUT "} OPENSSL_"
1395 ."$prevprevsymversion;\n\n";
1400 print OUT "OPENSSL_$symversion {\n global:\n";
1401 $prevprevsymversion = $prevsymversion;
1402 $prevsymversion = $symversion;
1404 print OUT " $s2;\n";
1406 while(++$prevnum < $n) {
1407 if ($symbolcount > 1023) {
1408 print OUT ")\nSYMBOL_VECTOR=(-\n";
1411 print OUT $symbolcount
1413 print OUT "dummy$prevnum=PRIVATE_PROCEDURE -\n";
1416 (my $s_uc = $s) =~ tr/a-z/A-Z/;
1417 if ($symbolcount > 1023) {
1418 print OUT ")\nSYMBOL_VECTOR=(-\n";
1421 print OUT $symbolcount
1423 print OUT "$s_uc/$s="
1424 , ($v ? "DATA" : "PROCEDURE"), " -\n";
1426 } elsif($v && !$OS2) {
1427 printf OUT " %s%-39s @%-8d DATA\n",
1428 ($W32)?"":"_",$s2,$n;
1430 printf OUT " %s%-39s @%d\n",
1431 ($W32||$OS2)?"":"_",$s2,$n;
1436 } while ($thisversion ne $currversion);
1438 if ($prevprevsymversion ne "") {
1439 print OUT " local: *;\n} OPENSSL_$prevprevsymversion;\n\n";
1441 print OUT " local: *;\n};\n\n";
1445 (my $libvmaj, my $libvmin, my $libvedit) =
1446 $currversion =~ /^(\d+)_(\d+)_(\d+)$/;
1447 # The reason to multiply the edit number with 100 is to make space
1448 # for the possibility that we want to encode the patch letters
1449 print OUT "GSMATCH=LEQUAL,",($libvmaj * 100 + $libvmin),",",($libvedit * 100),"\n";
1465 my ($baseversion, $currversion) = get_openssl_version();
1467 open(IN,"<$name") || die "unable to open $name:$!\n";
1473 if (defined $ret{$a[0]}) {
1474 # This is actually perfectly OK
1475 #print STDERR "Warning: Symbol '",$a[0],"' redefined. old=",$ret{$a[0]},", new=",$a[1],"\n";
1477 if ($max_num > $a[1]) {
1478 print STDERR "Warning: Number decreased from ",$max_num," to ",$a[1],"\n";
1480 elsif ($max_num == $a[1]) {
1481 # This is actually perfectly OK
1482 #print STDERR "Warning: Symbol ",$a[0]," has same number as previous ",$prev,": ",$a[1],"\n";
1483 if ($a[0] eq $prev) {
1485 $a[0] .= "{$prev_cnt}";
1492 # Existence will be proven later, in do_defs
1496 #Sanity check the version number
1497 if (defined $prevversion) {
1498 check_version_lte($prevversion, $a[2]);
1500 check_version_lte($a[2], $currversion);
1501 $prevversion = $a[2];
1502 $ret{$a[0]}=$a[1]."\\".$a[2]."\\".$a[3]; # \\ is a special marker
1504 $max_num = $a[1] if $a[1] > $max_num;
1508 print STDERR "Warning: $num_noinfo symbols were without info.";
1510 printf STDERR " The rewrite will fix this.\n";
1512 printf STDERR " You should do a rewrite to fix this.\n";
1521 (my $str, my $what) = @_;
1522 (my $n, my $v, my $i) = split(/\\/,$str);
1532 (*OUT,$name,*nums,@symbols)=@_;
1535 print STDERR "Rewriting $name\n";
1537 my @r = grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:\w+\(\w+\)/,@symbols);
1538 my $r; my %r; my %rsyms;
1540 (my $s, my $i) = split /\\/, $r;
1541 my $a = $1 if $i =~ /^.*?:.*?:\w+\((\w+)\)/;
1542 $i =~ s/^(.*?:.*?:\w+)\(\w+\)/$1/;
1543 $r{$a} = $s."\\".$i;
1548 foreach $_ (@symbols) {
1549 (my $n, my $i) = split /\\/;
1554 &parse_number($nums{$a},"n") <=> &parse_number($nums{$b},"n")
1558 (my $n, my $vers, my $i) = split /\\/, $nums{$sym};
1559 next if defined($i) && $i =~ /^.*?:.*?:\w+\(\w+\)/;
1560 next if defined($rsyms{$sym});
1561 print STDERR "DEBUG: rewrite_numbers for sym = ",$sym,": i = ",$i,", n = ",$n,", rsym{sym} = ",$rsyms{$sym},"syms{sym} = ",$syms{$sym},"\n" if $debug;
1562 $i="NOEXIST::FUNCTION:"
1563 if !defined($i) || $i eq "" || !defined($syms{$sym});
1565 $s2 =~ s/\{[0-9]+\}$//;
1566 printf OUT "%s%-39s %d\t%s\t%s\n","",$s2,$n,$vers,$i;
1567 if (exists $r{$sym}) {
1568 (my $s, $i) = split /\\/,$r{$sym};
1570 $s2 =~ s/\{[0-9]+\}$//;
1571 printf OUT "%s%-39s %d\t%s\t%s\n","",$s2,$n,$vers,$i;
1578 (*OUT,$name,*nums,my $start_num, my @symbols)=@_;
1583 ($basevers, $vers) = get_openssl_version();
1585 print STDERR "Updating $name numbers\n";
1587 my @r = grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:\w+\(\w+\)/,@symbols);
1588 my $r; my %r; my %rsyms;
1590 (my $s, my $i) = split /\\/, $r;
1591 my $a = $1 if $i =~ /^.*?:.*?:\w+\((\w+)\)/;
1592 $i =~ s/^(.*?:.*?:\w+)\(\w+\)/$1/;
1593 $r{$a} = $s."\\".$i;
1597 foreach $sym (@symbols) {
1598 (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
1599 next if $i =~ /^.*?:.*?:\w+\(\w+\)/;
1600 next if defined($rsyms{$sym});
1601 die "ERROR: Symbol $sym had no info attached to it."
1603 if (!exists $nums{$s}) {
1606 $s2 =~ s/\{[0-9]+\}$//;
1607 printf OUT "%s%-39s %d\t%s\t%s\n","",$s2, ++$start_num,$vers,$i;
1608 if (exists $r{$s}) {
1609 ($s, $i) = split /\\/,$r{$s};
1610 $s =~ s/\{[0-9]+\}$//;
1611 printf OUT "%s%-39s %d\t%s\t%s\n","",$s, $start_num,$vers,$i;
1616 print STDERR "$new_syms New symbols added\n";
1618 print STDERR "No New symbols Added\n";
1624 (*nums, my @symbols)=@_;
1625 my %existing; my @remaining;
1627 foreach $sym (@symbols) {
1628 (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
1631 foreach $sym (keys %nums) {
1632 if (!exists $existing{$sym}) {
1633 push @remaining, $sym;
1637 print STDERR "The following symbols do not seem to exist:\n";
1638 foreach $sym (@remaining) {
1639 print STDERR "\t",$sym,"\n";
1646 my $line = shift(@_);
1648 my $open = $line =~ tr/\(//;
1649 my $close = $line =~ tr/\)//;
1651 return $open - $close;
1654 #Parse opensslv.h to get the current version number. Also work out the base
1655 #version, i.e. the lowest version number that is binary compatible with this
1657 sub get_openssl_version()
1659 open (IN, "include/openssl/opensslv.h") || die "Can't open opensslv.h";
1662 if (/OPENSSL_VERSION_TEXT\s+"OpenSSL (\d\.\d\.)(\d[a-z]*)(-| )/) {
1664 my $baseversion = $1 =~ s/\./_/gr;
1666 return ($baseversion."0", $baseversion.$suffix);
1669 die "Can't find OpenSSL version number\n";
1672 #Given an OpenSSL version number, calculate the next version number. If the
1673 #version number gets to a.b.czz then we go to a.b.(c+1)
1674 sub get_next_version()
1676 my $thisversion = shift;
1678 my ($base, $letter) = $thisversion =~ /^(\d_\d_\d)([a-z]{0,2})$/;
1680 if ($letter eq "zz") {
1681 my $lastnum = substr($base, -1);
1682 return substr($base, 0, length($base)-1).(++$lastnum);
1684 return $base.get_next_letter($letter);
1687 #Given the letters off the end of an OpenSSL version string, calculate what
1688 #the letters for the next release would be.
1689 sub get_next_letter()
1691 my $thisletter = shift;
1692 my $baseletter = "";
1695 if ($thisletter eq "") {
1698 if ((length $thisletter) > 1) {
1699 ($baseletter, $endletter) = $thisletter =~ /([a-z]+)([a-z])/;
1701 $endletter = $thisletter;
1704 if ($endletter eq "z") {
1705 return $thisletter."a";
1707 return $baseletter.(++$endletter);
1711 #Check if a version is less than or equal to the current version. Its a fatal
1712 #error if not. They must also only differ in letters, or the last number (i.e.
1713 #the first two numbers must be the same)
1714 sub check_version_lte()
1716 my ($testversion, $currversion) = @_;
1721 my ($cvnums) = $currversion =~ /^(\d_\d_\d)[a-z]*$/;
1722 my ($tvnums) = $testversion =~ /^(\d_\d_\d)[a-z]*$/;
1724 #Die if we can't parse the version numbers or they don't look sane
1725 die "Invalid version number: $testversion and $currversion\n"
1726 if (!defined($cvnums) || !defined($tvnums)
1727 || length($cvnums) != 5
1728 || length($tvnums) != 5);
1730 #If the base versions (without letters) don't match check they only differ
1732 if ($cvnums ne $tvnums) {
1733 die "Invalid version number: $testversion "
1734 ."for current version $currversion\n"
1735 if (substr($cvnums, -1) < substr($tvnums, -1)
1736 || substr($cvnums, 0, 4) ne substr($tvnums, 0, 4));
1739 #If we get here then the base version (i.e. the numbers) are the same - they
1740 #only differ in the letters
1742 $lentv = length $testversion;
1743 $lencv = length $currversion;
1745 #If the testversion has more letters than the current version then it must
1746 #be later (or malformed)
1747 if ($lentv > $lencv) {
1748 die "Invalid version number: $testversion "
1749 ."is greater than $currversion\n";
1752 #Get the last letter from the current version
1753 my ($cvletter) = $currversion =~ /([a-z])$/;
1754 if (defined $cvletter) {
1755 ($cvbase) = $currversion =~ /(\d_\d_\d[a-z]*)$cvletter$/;
1757 $cvbase = $currversion;
1759 die "Unable to parse version number $currversion" if (!defined $cvbase);
1761 my ($tvletter) = $testversion =~ /([a-z])$/;
1762 if (defined $tvletter) {
1763 ($tvbase) = $testversion =~ /(\d_\d_\d[a-z]*)$tvletter$/;
1765 $tvbase = $testversion;
1767 die "Unable to parse version number $testversion" if (!defined $tvbase);
1769 if ($lencv > $lentv) {
1770 #If current version has more letters than testversion then testversion
1771 #minus the final letter must be a substring of the current version
1772 die "Invalid version number $testversion "
1773 ."is greater than $currversion or is invalid\n"
1774 if (index($cvbase, $tvbase) != 0);
1776 #If both versions have the same number of letters then they must be
1777 #equal up to the last letter, and the last letter in testversion must
1778 #be less than or equal to the last letter in current version.
1779 die "Invalid version number $testversion "
1780 ."is greater than $currversion\n"
1781 if (($cvbase ne $tvbase) && ($tvletter gt $cvletter));