2 # Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
4 # Licensed under the OpenSSL license (the "License"). You may not use
5 # this file except in compliance with the License. You can obtain a copy
6 # in the file LICENSE in the source distribution or at
7 # https://www.openssl.org/source/license.html
10 # generate a .def file
12 # It does this by parsing the header files and looking for the
13 # prototyped functions: it then prunes the output.
15 # Intermediary files are created, call libcrypto.num and libssl.num,
16 # The format of these files is:
18 # routine-name nnnn vers info
20 # The "nnnn" and "vers" fields are the numeric id and version for the symbol
21 # respectively. The "info" part is actually a colon-separated string of fields
22 # with the following meaning:
24 # existence:platform:kind:algorithms
26 # - "existence" can be "EXIST" or "NOEXIST" depending on if the symbol is
27 # found somewhere in the source,
28 # - "platforms" is empty if it exists on all platforms, otherwise it contains
29 # comma-separated list of the platform, just as they are if the symbol exists
30 # for those platforms, or prepended with a "!" if not. This helps resolve
31 # symbol name variants for platforms where the names are too long for the
32 # compiler or linker, or if the systems is case insensitive and there is a
33 # clash, or the symbol is implemented differently (see
34 # EXPORT_VAR_AS_FUNCTION). This script assumes renaming of symbols is found
35 # in the file crypto/symhacks.h.
36 # The semantics for the platforms is that every item is checked against the
37 # environment. For the negative items ("!FOO"), if any of them is false
38 # (i.e. "FOO" is true) in the environment, the corresponding symbol can't be
39 # used. For the positive itms, if all of them are false in the environment,
40 # the corresponding symbol can't be used. Any combination of positive and
41 # negative items are possible, and of course leave room for some redundancy.
42 # - "kind" is "FUNCTION" or "VARIABLE". The meaning of that is obvious.
43 # - "algorithms" is a comma-separated list of algorithm names. This helps
44 # exclude symbols that are part of an algorithm that some user wants to
50 use File::Spec::Functions;
54 my $crypto_num= catfile($config{sourcedir},"util","libcrypto.num");
55 my $ssl_num= catfile($config{sourcedir},"util","libssl.num");
64 my $do_checkexist = 0;
70 # Set this to make typesafe STACK definitions appear in DEF
71 my $safe_stack_def = 0;
73 my @known_platforms = ( "__FreeBSD__", "PERL5",
74 "EXPORT_VAR_AS_FUNCTION", "ZLIB", "_WIN32"
76 my @known_ossl_platforms = ( "VMS", "WIN32", "WINNT", "OS2" );
77 my @known_algorithms = ( "RC2", "RC4", "RC5", "IDEA", "DES", "BF",
78 "CAST", "MD2", "MD4", "MD5", "SHA", "SHA0", "SHA1",
79 "SHA256", "SHA512", "RMD160",
80 "MDC2", "WHIRLPOOL", "RSA", "DSA", "DH", "EC", "EC2M",
81 "HMAC", "AES", "CAMELLIA", "SEED", "GOST", "ARIA",
82 "SCRYPT", "CHACHA", "POLY1305", "BLAKE2",
85 "EC_NISTP_64_GCC_128",
86 # Envelope "algorithms"
87 "EVP", "X509", "ASN1_TYPEDEFS",
89 "BIO", "COMP", "BUFFER", "LHASH", "STACK", "ERR",
91 # External "algorithms"
92 "FP_API", "STDIO", "SOCK", "DGRAM",
95 "STATIC_ENGINE", "ENGINE", "HW", "GMP",
98 # Certificate Transparency
103 "PSK", "SRP", "HEARTBEATS",
110 "SSL3_METHOD", "TLS1_METHOD", "TLS1_1_METHOD", "TLS1_2_METHOD", "DTLS1_METHOD", "DTLS1_2_METHOD",
113 # Deprecated functions
114 "DEPRECATEDIN_0_9_8",
115 "DEPRECATEDIN_1_0_0",
116 "DEPRECATEDIN_1_1_0",
117 "DEPRECATEDIN_1_2_0",
133 # APPLINK (win build feature?)
137 my %disabled_algorithms;
139 foreach (@known_algorithms) {
140 $disabled_algorithms{$_} = 0;
142 # disabled by default
143 $disabled_algorithms{"STATIC_ENGINE"} = 1;
145 my $apiv = sprintf "%x%02x%02x", split(/\./, $config{api});
146 foreach (keys %disabled_algorithms) {
147 if (/^DEPRECATEDIN_(\d+)_(\d+)_(\d+)$/) {
148 my $depv = sprintf "%x%02x%02x", $1, $2, $3;
149 $disabled_algorithms{$_} = 1 if $apiv ge $depv;
155 foreach (@ARGV, split(/ /, $config{options}))
157 $debug=1 if $_ eq "debug";
158 $W32=1 if $_ eq "32";
159 die "win16 not supported" if $_ eq "16";
167 $VMS=1 if $_ eq "VMS";
168 if ($_ eq "zlib" || $_ eq "enable-zlib" || $_ eq "zlib-dynamic"
169 || $_ eq "enable-zlib-dynamic") {
173 $do_ssl=1 if $_ eq "libssl";
178 $do_crypto=1 if $_ eq "libcrypto";
179 if ($_ eq "crypto") {
183 $do_update=1 if $_ eq "update";
184 $do_rewrite=1 if $_ eq "rewrite";
185 $do_ctest=1 if $_ eq "ctest";
186 $do_ctestall=1 if $_ eq "ctestall";
187 $do_checkexist=1 if $_ eq "exist";
188 if (/^(enable|disable|no)-(.*)$/) {
191 if (exists $disabled_algorithms{$alg}) {
192 $disabled_algorithms{$alg} = $1 eq "enable" ? 0 : 1;
203 $libname="LIBCRYPTO";
207 # If no platform is given, assume WIN32
208 if ($W32 + $VMS + $linux == 0) {
211 die "Please, only one platform at a time"
212 if ($W32 + $VMS + $linux > 1);
214 if (!$do_ssl && !$do_crypto)
216 print STDERR "usage: $0 ( ssl | crypto ) [ 16 | 32 | NT | OS2 | linux | VMS ]\n";
220 %ssl_list=&load_numbers($ssl_num);
222 %crypto_list=&load_numbers($crypto_num);
223 $max_crypto = $max_num;
225 my $ssl="include/openssl/ssl.h";
226 $ssl.=" include/openssl/tls1.h";
227 $ssl.=" include/openssl/srtp.h";
229 # We use headers found in include/openssl and include/internal only.
230 # The latter is needed so libssl.so/.dll/.exe can link properly.
231 my $crypto ="include/openssl/crypto.h";
232 $crypto.=" include/internal/o_dir.h";
233 $crypto.=" include/internal/o_str.h";
234 $crypto.=" include/internal/err.h";
235 $crypto.=" include/openssl/des.h" ; # unless $no_des;
236 $crypto.=" include/openssl/idea.h" ; # unless $no_idea;
237 $crypto.=" include/openssl/rc4.h" ; # unless $no_rc4;
238 $crypto.=" include/openssl/rc5.h" ; # unless $no_rc5;
239 $crypto.=" include/openssl/rc2.h" ; # unless $no_rc2;
240 $crypto.=" include/openssl/blowfish.h" ; # unless $no_bf;
241 $crypto.=" include/openssl/cast.h" ; # unless $no_cast;
242 $crypto.=" include/openssl/whrlpool.h" ;
243 $crypto.=" include/openssl/md2.h" ; # unless $no_md2;
244 $crypto.=" include/openssl/md4.h" ; # unless $no_md4;
245 $crypto.=" include/openssl/md5.h" ; # unless $no_md5;
246 $crypto.=" include/openssl/mdc2.h" ; # unless $no_mdc2;
247 $crypto.=" include/openssl/sha.h" ; # unless $no_sha;
248 $crypto.=" include/openssl/ripemd.h" ; # unless $no_ripemd;
249 $crypto.=" include/openssl/aes.h" ; # unless $no_aes;
250 $crypto.=" include/openssl/camellia.h" ; # unless $no_camellia;
251 $crypto.=" include/openssl/seed.h"; # unless $no_seed;
253 $crypto.=" include/openssl/bn.h";
254 $crypto.=" include/openssl/rsa.h" ; # unless $no_rsa;
255 $crypto.=" include/openssl/dsa.h" ; # unless $no_dsa;
256 $crypto.=" include/openssl/dh.h" ; # unless $no_dh;
257 $crypto.=" include/openssl/ec.h" ; # unless $no_ec;
258 $crypto.=" include/openssl/hmac.h" ; # unless $no_hmac;
259 $crypto.=" include/openssl/cmac.h" ;
261 $crypto.=" include/openssl/engine.h"; # unless $no_engine;
262 $crypto.=" include/openssl/stack.h" ; # unless $no_stack;
263 $crypto.=" include/openssl/buffer.h" ; # unless $no_buffer;
264 $crypto.=" include/openssl/bio.h" ; # unless $no_bio;
265 $crypto.=" include/internal/dso.h" ; # unless $no_dso;
266 $crypto.=" include/openssl/lhash.h" ; # unless $no_lhash;
267 $crypto.=" include/openssl/conf.h";
268 $crypto.=" include/openssl/txt_db.h";
270 $crypto.=" include/openssl/evp.h" ; # unless $no_evp;
271 $crypto.=" include/openssl/objects.h";
272 $crypto.=" include/openssl/pem.h";
273 #$crypto.=" include/openssl/meth.h";
274 $crypto.=" include/openssl/asn1.h";
275 $crypto.=" include/openssl/asn1t.h";
276 $crypto.=" include/openssl/err.h" ; # unless $no_err;
277 $crypto.=" include/openssl/pkcs7.h";
278 $crypto.=" include/openssl/pkcs12.h";
279 $crypto.=" include/openssl/x509.h";
280 $crypto.=" include/openssl/x509_vfy.h";
281 $crypto.=" include/openssl/x509v3.h";
282 $crypto.=" include/openssl/ts.h";
283 $crypto.=" include/openssl/rand.h";
284 $crypto.=" include/openssl/comp.h" ; # unless $no_comp;
285 $crypto.=" include/openssl/ocsp.h";
286 $crypto.=" include/openssl/ui.h";
287 #$crypto.=" include/openssl/store.h";
288 $crypto.=" include/openssl/cms.h";
289 $crypto.=" include/openssl/srp.h";
290 $crypto.=" include/openssl/modes.h";
291 $crypto.=" include/openssl/async.h";
292 $crypto.=" include/openssl/ct.h";
293 $crypto.=" include/openssl/kdf.h";
295 my $symhacks="include/openssl/symhacks.h";
297 my @ssl_symbols = &do_defs("LIBSSL", $ssl, $symhacks);
298 my @crypto_symbols = &do_defs("LIBCRYPTO", $crypto, $symhacks);
304 &maybe_add_info("LIBSSL",*ssl_list,@ssl_symbols);
305 if ($do_rewrite == 1) {
306 open(OUT, ">$ssl_num");
307 &rewrite_numbers(*OUT,"LIBSSL",*ssl_list,@ssl_symbols);
309 open(OUT, ">>$ssl_num");
311 &update_numbers(*OUT,"LIBSSL",*ssl_list,$max_ssl,@ssl_symbols);
315 if($do_crypto == 1) {
317 &maybe_add_info("LIBCRYPTO",*crypto_list,@crypto_symbols);
318 if ($do_rewrite == 1) {
319 open(OUT, ">$crypto_num");
320 &rewrite_numbers(*OUT,"LIBCRYPTO",*crypto_list,@crypto_symbols);
322 open(OUT, ">>$crypto_num");
324 &update_numbers(*OUT,"LIBCRYPTO",*crypto_list,$max_crypto,@crypto_symbols);
328 } elsif ($do_checkexist) {
329 &check_existing(*ssl_list, @ssl_symbols)
331 &check_existing(*crypto_list, @crypto_symbols)
333 } elsif ($do_ctest || $do_ctestall) {
337 /* Test file to check all DEF file symbols are present by trying
338 * to link to all of them. This is *not* intended to be run!
344 &print_test_file(*STDOUT,"LIBSSL",*ssl_list,$do_ctestall,@ssl_symbols)
347 &print_test_file(*STDOUT,"LIBCRYPTO",*crypto_list,$do_ctestall,@crypto_symbols)
354 &print_def_file(*STDOUT,$libname,*ssl_list,@ssl_symbols)
357 &print_def_file(*STDOUT,$libname,*crypto_list,@crypto_symbols)
365 my($name,$files,$symhacksfile)=@_;
369 my %platform; # For anything undefined, we assume ""
370 my %kind; # For anything undefined, we assume "FUNCTION"
371 my %algorithm; # For anything undefined, we assume ""
373 my %variant_cnt; # To be able to allocate "name{n}" if "name"
374 # is the same name as the original.
376 my %unknown_algorithms = ();
379 foreach $file (split(/\s+/,$symhacksfile." ".$files))
381 my $fn = catfile($config{sourcedir},$file);
382 print STDERR "DEBUG: starting on $fn:\n" if $debug;
383 open(IN,"<$fn") || die "unable to open $fn:$!\n";
384 my $line = "", my $def= "";
386 (map { $_ => 0 } @known_platforms),
387 (map { "OPENSSL_SYS_".$_ => 0 } @known_ossl_platforms),
388 (map { "OPENSSL_NO_".$_ => 0 } @known_algorithms),
389 (map { "OPENSSL_USE_".$_ => 0 } @known_algorithms),
390 (grep /^DEPRECATED_/, @known_algorithms),
397 my $symhacking = $file eq $symhacksfile;
398 my @current_platforms = ();
399 my @current_algorithms = ();
401 # params: symbol, alias, platforms, kind
402 # The reason to put this subroutine in a variable is that
403 # it will otherwise create it's own, unshared, version of
404 # %tag and %variant...
405 my $make_variant = sub
407 my ($s, $a, $p, $k) = @_;
410 print STDERR "DEBUG: make_variant: Entered with ",$s,", ",$a,", ",(defined($p)?$p:""),", ",(defined($k)?$k:""),"\n" if $debug;
415 map { $tag{$_} == 1 ? $_ : "" }
422 map { $tag{$_} == 1 ? $_ : "" }
427 map { $tag{"OPENSSL_SYS_".$_} == 1 ? $_ : "" }
428 @known_ossl_platforms));
429 print STDERR "DEBUG: make_variant: a1 = $a1; a2 = $a2\n" if $debug;
430 if ($a1 eq "") { $a1 = $a2; }
431 elsif ($a1 ne "" && $a2 ne "") { $a1 .= ",".$a2; }
434 if (!defined($variant_cnt{$s}))
436 $variant_cnt{$s} = 0;
439 $a .= "{$variant_cnt{$s}}";
441 my $toadd = $a.":".$a1.(defined($k)?":".$k:"");
442 my $togrep = $s.'(\{[0-9]+\})?:'.$a1.(defined($k)?":".$k:"");
443 if (!grep(/^$togrep$/,
444 split(/;/, defined($variant{$s})?$variant{$s}:""))) {
445 if (defined($variant{$s})) { $variant{$s} .= ";"; }
446 $variant{$s} .= $toadd;
448 print STDERR "DEBUG: make_variant: Exit with variant of ",$s," = ",$variant{$s},"\n" if $debug;
451 print STDERR "DEBUG: parsing ----------\n" if $debug;
454 #Inside a DEPRECATEDIN
455 $stored_multiline .= $_;
456 $stored_multiline =~ s|\R$||; # Better chomp
457 print STDERR "DEBUG: Continuing multiline DEPRECATEDIN: $stored_multiline\n" if $debug;
458 $parens = count_parens($stored_multiline);
460 $def .= do_deprecated($stored_multiline,
462 \@current_algorithms);
466 if (/\/\* Error codes for the \w+ functions\. \*\//)
477 $line = $`; # keep what was before the backslash
482 if (not /\*\//) { # multiline comment...
483 $line = $_; # ... just accumulate
486 s/\/\*.*?\*\///gs;# wipe it
492 $cpp-- if /^#\s*endif/;
495 if (/^#.*ifdef.*cplusplus/) {
500 s/{[^{}]*}//gs; # ignore {} blocks
501 print STDERR "DEBUG: \$def=\"$def\"\n" if $debug && $def ne "";
502 print STDERR "DEBUG: \$_=\"$_\"\n" if $debug;
503 if (/^\#\s*if\s+OPENSSL_API_COMPAT\s*(\S)\s*(0x[0-9a-fA-F]{8})L\s*$/) {
506 if ($op ne '<' && $op ne '>=') {
507 die "$file unacceptable operator $op: $_\n";
509 my ($one, $major, $minor) =
513 my $t = "DEPRECATEDIN_${one}_${major}_${minor}";
516 $tag{$t}=($op eq '<' ? 1 : -1);
517 print STDERR "DEBUG: $file: found tag $t = $tag{$t}\n" if $debug;
518 } elsif (/^\#\s*ifndef\s+(.*)/) {
522 print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
523 } elsif (/^\#\s*if\s+!defined\(([^\)]+)\)/) {
525 if (/^\#\s*if\s+(!defined\(([^\)]+)\)(\s+\&\&\s+!defined\(([^\)]+)\))*)$/) {
528 foreach $tmp_ (split '\&\&',$tmp_1) {
529 $tmp_ =~ /!defined\(([^\)]+)\)/;
530 print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
535 print STDERR "Warning: $file: complicated expression: $_" if $debug; # because it is O...
536 print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
540 } elsif (/^\#\s*ifdef\s+(\S*)/) {
544 print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
545 } elsif (/^\#\s*if\s+defined\(([^\)]+)\)/) {
547 if (/^\#\s*if\s+(defined\(([^\)]+)\)(\s+\|\|\s+defined\(([^\)]+)\))*)$/) {
550 foreach $tmp_ (split '\|\|',$tmp_1) {
551 $tmp_ =~ /defined\(([^\)]+)\)/;
552 print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
557 print STDERR "Warning: $file: complicated expression: $_\n" if $debug; # because it is O...
558 print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
562 } elsif (/^\#\s*error\s+(\w+) is disabled\./) {
564 while($tag[$tag_i] ne "-") {
565 if ($tag[$tag_i] eq "OPENSSL_NO_".$1) {
566 $tag{$tag[$tag_i]}=2;
567 print STDERR "DEBUG: $file: chaged tag $1 = 2\n" if $debug;
571 } elsif (/^\#\s*endif/) {
573 while($tag_i > 0 && $tag[$tag_i] ne "-") {
575 print STDERR "DEBUG: \$t=\"$t\"\n" if $debug;
581 print STDERR "DEBUG: $file: changed tag ",$t," = ",$tag{$t},"\n" if $debug;
583 if ($t =~ /^OPENSSL_NO_([A-Z0-9_]+)$/) {
585 } elsif($t =~ /^OPENSSL_USE_([A-Z0-9_]+)$/) {
591 && !grep(/^$t$/, @known_algorithms)) {
592 $unknown_algorithms{$t} = 1;
593 #print STDERR "DEBUG: Added as unknown algorithm: $t\n" if $debug;
598 } elsif (/^\#\s*else/) {
600 die "$file unmatched else\n" if $tag_i < 0;
601 while($tag[$tag_i] ne "-") {
604 print STDERR "DEBUG: $file: changed tag ",$t," = ",$tag{$t},"\n" if $debug;
607 } elsif (/^\#\s*if\s+1/) {
612 print STDERR "DEBUG: $file: found 1\n" if $debug;
613 } elsif (/^\#\s*if\s+0/) {
618 print STDERR "DEBUG: $file: found 0\n" if $debug;
619 } elsif (/^\#\s*if\s+/) {
620 #Some other unrecognized "if" style
622 } elsif (/^\#\s*define\s+(\w+)\s+(\w+)/
623 && $symhacking && $tag{'TRUE'} != -1) {
624 # This is for aliasing. When we find an alias,
626 &$make_variant($1,$2);
627 print STDERR "DEBUG: $file: defined $1 = $2\n" if $debug;
632 map { $tag{$_} == 1 ? $_ :
633 $tag{$_} == -1 ? "!".$_ : "" }
635 push @current_platforms
637 map { $tag{"OPENSSL_SYS_".$_} == 1 ? $_ :
638 $tag{"OPENSSL_SYS_".$_} == -1 ? "!".$_ : "" }
639 @known_ossl_platforms);
640 @current_algorithms = ();
641 @current_algorithms =
643 map { $tag{"OPENSSL_NO_".$_} == -1 ? $_ : "" }
645 push @current_algorithms
647 map { $tag{"OPENSSL_USE_".$_} == 1 ? $_ : "" }
649 push @current_algorithms,
650 grep { /^DEPRECATEDIN_/ && $tag{$_} == 1 }
654 .join(',',@current_platforms).":"
655 .join(',',@current_algorithms).";";
658 if ($tag{'TRUE'} != -1) {
659 if (/^\s*DEFINE_STACK_OF\s*\(\s*(\w*)\s*\)/
660 || /^\s*DEFINE_STACK_OF_CONST\s*\(\s*(\w*)\s*\)/) {
662 } elsif (/^\s*DECLARE_ASN1_ENCODE_FUNCTIONS\s*\(\s*(\w*)\s*,\s*(\w*)\s*,\s*(\w*)\s*\)/) {
663 $def .= "int d2i_$3(void);";
664 $def .= "int i2d_$3(void);";
665 # Variant for platforms that do not
666 # have to access globale variables
667 # in shared libraries through functions
670 .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
671 .join(',',@current_algorithms).";";
672 $def .= "OPENSSL_EXTERN int $2_it;";
675 .join(',',@current_platforms).":"
676 .join(',',@current_algorithms).";";
677 # Variant for platforms that have to
678 # access globale variables in shared
679 # libraries through functions
680 &$make_variant("$2_it","$2_it",
681 "EXPORT_VAR_AS_FUNCTION",
684 } elsif (/^\s*DECLARE_ASN1_FUNCTIONS_fname\s*\(\s*(\w*)\s*,\s*(\w*)\s*,\s*(\w*)\s*\)/) {
685 $def .= "int d2i_$3(void);";
686 $def .= "int i2d_$3(void);";
687 $def .= "int $3_free(void);";
688 $def .= "int $3_new(void);";
689 # Variant for platforms that do not
690 # have to access globale variables
691 # in shared libraries through functions
694 .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
695 .join(',',@current_algorithms).";";
696 $def .= "OPENSSL_EXTERN int $2_it;";
699 .join(',',@current_platforms).":"
700 .join(',',@current_algorithms).";";
701 # Variant for platforms that have to
702 # access globale variables in shared
703 # libraries through functions
704 &$make_variant("$2_it","$2_it",
705 "EXPORT_VAR_AS_FUNCTION",
708 } elsif (/^\s*DECLARE_ASN1_FUNCTIONS\s*\(\s*(\w*)\s*\)/ ||
709 /^\s*DECLARE_ASN1_FUNCTIONS_const\s*\(\s*(\w*)\s*\)/) {
710 $def .= "int d2i_$1(void);";
711 $def .= "int i2d_$1(void);";
712 $def .= "int $1_free(void);";
713 $def .= "int $1_new(void);";
714 # Variant for platforms that do not
715 # have to access globale variables
716 # in shared libraries through functions
719 .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
720 .join(',',@current_algorithms).";";
721 $def .= "OPENSSL_EXTERN int $1_it;";
724 .join(',',@current_platforms).":"
725 .join(',',@current_algorithms).";";
726 # Variant for platforms that have to
727 # access globale variables in shared
728 # libraries through functions
729 &$make_variant("$1_it","$1_it",
730 "EXPORT_VAR_AS_FUNCTION",
733 } elsif (/^\s*DECLARE_ASN1_ENCODE_FUNCTIONS_const\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
734 $def .= "int d2i_$2(void);";
735 $def .= "int i2d_$2(void);";
736 # Variant for platforms that do not
737 # have to access globale variables
738 # in shared libraries through functions
741 .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
742 .join(',',@current_algorithms).";";
743 $def .= "OPENSSL_EXTERN int $2_it;";
746 .join(',',@current_platforms).":"
747 .join(',',@current_algorithms).";";
748 # Variant for platforms that have to
749 # access globale variables in shared
750 # libraries through functions
751 &$make_variant("$2_it","$2_it",
752 "EXPORT_VAR_AS_FUNCTION",
755 } elsif (/^\s*DECLARE_ASN1_ALLOC_FUNCTIONS\s*\(\s*(\w*)\s*\)/) {
756 $def .= "int $1_free(void);";
757 $def .= "int $1_new(void);";
759 } elsif (/^\s*DECLARE_ASN1_FUNCTIONS_name\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
760 $def .= "int d2i_$2(void);";
761 $def .= "int i2d_$2(void);";
762 $def .= "int $2_free(void);";
763 $def .= "int $2_new(void);";
764 # Variant for platforms that do not
765 # have to access globale variables
766 # in shared libraries through functions
769 .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
770 .join(',',@current_algorithms).";";
771 $def .= "OPENSSL_EXTERN int $2_it;";
774 .join(',',@current_platforms).":"
775 .join(',',@current_algorithms).";";
776 # Variant for platforms that have to
777 # access globale variables in shared
778 # libraries through functions
779 &$make_variant("$2_it","$2_it",
780 "EXPORT_VAR_AS_FUNCTION",
783 } elsif (/^\s*DECLARE_ASN1_ITEM\s*\(\s*(\w*)\s*\)/) {
784 # Variant for platforms that do not
785 # have to access globale variables
786 # in shared libraries through functions
789 .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
790 .join(',',@current_algorithms).";";
791 $def .= "OPENSSL_EXTERN int $1_it;";
794 .join(',',@current_platforms).":"
795 .join(',',@current_algorithms).";";
796 # Variant for platforms that have to
797 # access globale variables in shared
798 # libraries through functions
799 &$make_variant("$1_it","$1_it",
800 "EXPORT_VAR_AS_FUNCTION",
803 } elsif (/^\s*DECLARE_ASN1_NDEF_FUNCTION\s*\(\s*(\w*)\s*\)/) {
804 $def .= "int i2d_$1_NDEF(void);";
805 } elsif (/^\s*DECLARE_ASN1_SET_OF\s*\(\s*(\w*)\s*\)/) {
807 } elsif (/^\s*DECLARE_ASN1_PRINT_FUNCTION\s*\(\s*(\w*)\s*\)/) {
808 $def .= "int $1_print_ctx(void);";
810 } elsif (/^\s*DECLARE_ASN1_PRINT_FUNCTION_name\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
811 $def .= "int $2_print_ctx(void);";
813 } elsif (/^\s*DECLARE_PKCS12_STACK_OF\s*\(\s*(\w*)\s*\)/) {
815 } elsif (/^DECLARE_PEM_rw\s*\(\s*(\w*)\s*,/ ||
816 /^DECLARE_PEM_rw_cb\s*\(\s*(\w*)\s*,/ ||
817 /^DECLARE_PEM_rw_const\s*\(\s*(\w*)\s*,/ ) {
820 .join(',',@current_platforms).":"
821 .join(',',"STDIO",@current_algorithms).";";
822 $def .= "int PEM_read_$1(void);";
823 $def .= "int PEM_write_$1(void);";
826 .join(',',@current_platforms).":"
827 .join(',',@current_algorithms).";";
828 # Things that are everywhere
829 $def .= "int PEM_read_bio_$1(void);";
830 $def .= "int PEM_write_bio_$1(void);";
832 } elsif (/^DECLARE_PEM_write\s*\(\s*(\w*)\s*,/ ||
833 /^DECLARE_PEM_write_const\s*\(\s*(\w*)\s*,/ ||
834 /^DECLARE_PEM_write_cb\s*\(\s*(\w*)\s*,/ ) {
837 .join(',',@current_platforms).":"
838 .join(',',"STDIO",@current_algorithms).";";
839 $def .= "int PEM_write_$1(void);";
842 .join(',',@current_platforms).":"
843 .join(',',@current_algorithms).";";
844 # Things that are everywhere
845 $def .= "int PEM_write_bio_$1(void);";
847 } elsif (/^DECLARE_PEM_read\s*\(\s*(\w*)\s*,/ ||
848 /^DECLARE_PEM_read_cb\s*\(\s*(\w*)\s*,/ ) {
851 .join(',',@current_platforms).":"
852 .join(',',"STDIO",@current_algorithms).";";
853 $def .= "int PEM_read_$1(void);";
856 .join(',',@current_platforms).":"
857 .join(',',"STDIO",@current_algorithms).";";
858 # Things that are everywhere
859 $def .= "int PEM_read_bio_$1(void);";
861 } elsif (/^OPENSSL_DECLARE_GLOBAL\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
862 # Variant for platforms that do not
863 # have to access globale variables
864 # in shared libraries through functions
867 .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
868 .join(',',@current_algorithms).";";
869 $def .= "OPENSSL_EXTERN int _shadow_$2;";
872 .join(',',@current_platforms).":"
873 .join(',',@current_algorithms).";";
874 # Variant for platforms that have to
875 # access globale variables in shared
876 # libraries through functions
877 &$make_variant("_shadow_$2","_shadow_$2",
878 "EXPORT_VAR_AS_FUNCTION",
880 } elsif (/^\s*DEPRECATEDIN/) {
881 $parens = count_parens($_);
883 $def .= do_deprecated($_,
885 \@current_algorithms);
887 $stored_multiline = $_;
888 $stored_multiline =~ s|\R$||;
889 print STDERR "DEBUG: Found multiline DEPRECATEDIN starting with: $stored_multiline\n" if $debug;
892 } elsif ($tag{'CONST_STRICT'} != 1) {
893 if (/\{|\/\*|\([^\)]*$/) {
902 die "$file: Unmatched tags\n" if $#tag >= 0;
907 print STDERR "DEBUG: postprocessing ----------\n" if $debug;
908 foreach (split /;/, $def) {
909 my $s; my $k = "FUNCTION"; my $p; my $a;
913 next if(/typedef\W/);
916 # Reduce argument lists to empty ()
917 # fold round brackets recursively: (t(*v)(t),t) -> (t{}{},t) -> {}
919 s/\([^\(\)]+\)/\{\}/gs;
920 s/\(\s*\*\s*(\w+)\s*\{\}\s*\)/$1/gs; #(*f{}) -> f
922 # pretend as we didn't use curly braces: {} -> ()
925 s/STACK_OF\(\)/void/gs;
926 s/LHASH_OF\(\)/void/gs;
928 print STDERR "DEBUG: \$_ = \"$_\"\n" if $debug;
929 if (/^\#INFO:([^:]*):(.*)$/) {
932 print STDERR "DEBUG: found info on platforms ($plats) and algorithms ($algs)\n" if $debug;
934 } elsif (/^\s*OPENSSL_EXTERN\s.*?(\w+(\{[0-9]+\})?)(\[[0-9]*\])*\s*$/) {
937 print STDERR "DEBUG: found external variable $s\n" if $debug;
938 } elsif (/TYPEDEF_\w+_OF/s) {
940 } elsif (/(\w+)\s*\(\).*/s) { # first token prior [first] () is
941 $s = $1; # a function name!
942 print STDERR "DEBUG: found function $s\n" if $debug;
943 } elsif (/\(/ and not (/=/)) {
944 print STDERR "File $file: cannot parse: $_;\n";
957 &reduce_platforms((defined($platform{$s})?$platform{$s}.',':"").$p);
958 $algorithm{$s} .= ','.$a;
960 if (defined($variant{$s})) {
961 foreach $v (split /;/,$variant{$s}) {
962 (my $r, my $p, my $k) = split(/:/,$v);
963 my $ip = join ',',map({ /^!(.*)$/ ? $1 : "!".$_ } split /,/, $p);
965 if (!defined($k)) { $k = $kind{$s}; }
966 $kind{$r} = $k."(".$s.")";
967 $algorithm{$r} = $algorithm{$s};
968 $platform{$r} = &reduce_platforms($platform{$s}.",".$p.",".$p);
969 $platform{$s} = &reduce_platforms($platform{$s}.','.$ip.','.$ip);
970 print STDERR "DEBUG: \$variant{\"$s\"} = ",$v,"; \$r = $r; \$p = ",$platform{$r},"; \$a = ",$algorithm{$r},"; \$kind = ",$kind{$r},"\n" if $debug;
973 print STDERR "DEBUG: \$s = $s; \$p = ",$platform{$s},"; \$a = ",$algorithm{$s},"; \$kind = ",$kind{$s},"\n" if $debug;
977 # Prune the returned symbols
979 delete $syms{"bn_dump1"};
980 $platform{"BIO_s_log"} .= ",!WIN32,!macintosh";
982 $platform{"PEM_read_NS_CERT_SEQ"} = "VMS";
983 $platform{"PEM_write_NS_CERT_SEQ"} = "VMS";
984 $platform{"PEM_read_P8_PRIV_KEY_INFO"} = "VMS";
985 $platform{"PEM_write_P8_PRIV_KEY_INFO"} = "VMS";
989 push @ret, map { $_."\\".&info_string($_,"EXIST",
992 $algorithm{$_}) } keys %syms;
994 if (keys %unknown_algorithms) {
995 print STDERR "WARNING: mkdef.pl doesn't know the following algorithms:\n";
996 print STDERR "\t",join("\n\t",keys %unknown_algorithms),"\n";
1001 # Param: string of comma-separated platform-specs.
1002 sub reduce_platforms
1004 my ($platforms) = @_;
1005 my $pl = defined($platforms) ? $platforms : "";
1006 my %p = map { $_ => 0 } split /,/, $pl;
1009 print STDERR "DEBUG: Entered reduce_platforms with \"$platforms\"\n"
1011 # We do this, because if there's code like the following, it really
1012 # means the function exists in all cases and should therefore be
1013 # everywhere. By increasing and decreasing, we may attain 0:
1020 foreach $platform (split /,/, $pl) {
1021 if ($platform =~ /^!(.*)$/) {
1027 foreach $platform (keys %p) {
1028 if ($p{$platform} == 0) { delete $p{$platform}; }
1033 $ret = join(',',sort(map { $p{$_} < 0 ? "!".$_ : $_ } keys %p));
1034 print STDERR "DEBUG: Exiting reduce_platforms with \"$ret\"\n"
1041 (my $symbol, my $exist, my $platforms, my $kind, my $algorithms) = @_;
1043 my %a = defined($algorithms) ?
1044 map { $_ => 1 } split /,/, $algorithms : ();
1045 my $k = defined($kind) ? $kind : "FUNCTION";
1047 my $p = &reduce_platforms($platforms);
1054 $ret .= ":".join(',',sort keys %a);
1060 (my $name, *nums, my @symbols) = @_;
1065 foreach $sym (@symbols) {
1066 (my $s, my $i) = split /\\/, $sym;
1067 if (defined($nums{$s})) {
1068 $i =~ s/^(.*?:.*?:\w+)(\(\w+\))?/$1/;
1069 (my $n, my $vers, my $dummy) = split /\\/, $nums{$s};
1070 if (!defined($dummy) || $i ne $dummy) {
1071 $nums{$s} = $n."\\".$vers."\\".$i;
1073 print STDERR "DEBUG: maybe_add_info for $s: \"$dummy\" => \"$i\"\n" if $debug;
1079 my @s=sort { &parse_number($nums{$a},"n") <=> &parse_number($nums{$b},"n") } keys %nums;
1081 (my $n, my $vers, my $i) = split /\\/, $nums{$sym};
1082 if (!defined($syms{$sym}) && $i !~ /^NOEXIST:/) {
1084 print STDERR "DEBUG: maybe_add_info for $sym: -> undefined\n" if $debug;
1088 print STDERR "$name: $new_info old symbols have updated info\n";
1090 print STDERR "You should do a rewrite to fix this.\n";
1096 # Param: string of comma-separated keywords, each possibly prefixed with a "!"
1099 my ($keywords_txt,$platforms) = @_;
1100 my (@keywords) = split /,/,$keywords_txt;
1101 my ($falsesum, $truesum) = (0, 1);
1103 # Param: one keyword
1106 my ($keyword,$platforms) = @_;
1110 if ($keyword eq "VMS" && $VMS) { return 1; }
1111 if ($keyword eq "WIN32" && $W32) { return 1; }
1112 if ($keyword eq "_WIN32" && $W32) { return 1; }
1113 if ($keyword eq "WINNT" && $NT) { return 1; }
1114 # Special platforms:
1115 # EXPORT_VAR_AS_FUNCTION means that global variables
1116 # will be represented as functions.
1117 if ($keyword eq "EXPORT_VAR_AS_FUNCTION" && $W32) {
1120 if ($keyword eq "ZLIB" && $zlib) { return 1; }
1124 if ($disabled_algorithms{$keyword} == 1) { return 0;}
1126 # Nothing recognise as true
1131 foreach $k (@keywords) {
1132 if ($k =~ /^!(.*)$/) {
1133 $falsesum += &recognise($1,$platforms);
1135 $truesum *= &recognise($k,$platforms);
1138 print STDERR "DEBUG: [",$#keywords,",",$#keywords < 0,"] is_valid($keywords_txt) => (\!$falsesum) && $truesum = ",(!$falsesum) && $truesum,"\n" if $debug;
1139 return (!$falsesum) && $truesum;
1144 (*OUT,my $name,*nums,my $testall,my @symbols)=@_;
1145 my $n = 1; my @e; my @r;
1146 my $sym; my $prev = ""; my $prefSSLeay;
1148 (@e)=grep(/^SSLeay(\{[0-9]+\})?\\.*?:.*?:.*/,@symbols);
1149 (@r)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:.*/ && !/^SSLeay(\{[0-9]+\})?\\.*?:.*?:.*/,@symbols);
1150 @symbols=((sort @e),(sort @r));
1152 foreach $sym (@symbols) {
1153 (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
1155 $v = 1 if $i=~ /^.*?:.*?:VARIABLE/;
1156 my $p = ($i =~ /^[^:]*:([^:]*):/,$1);
1157 my $a = ($i =~ /^[^:]*:[^:]*:[^:]*:([^:]*)/,$1);
1158 if (!defined($nums{$s})) {
1159 print STDERR "Warning: $s does not have a number assigned\n"
1161 } elsif (is_valid($p,1) && is_valid($a,0)) {
1162 my $s2 = ($s =~ /^(.*?)(\{[0-9]+\})?$/, $1);
1164 print OUT "\t/* The following has already appeared previously */\n";
1165 print STDERR "Warning: Symbol '",$s2,"' redefined. old=",($nums{$prev} =~ /^(.*?)\\/,$1),", new=",($nums{$s2} =~ /^(.*?)\\/,$1),"\n";
1167 $prev = $s2; # To warn about duplicates...
1169 (my $nn, my $vers, my $ni) = split /\\/, $nums{$s2};
1171 print OUT "\textern int $s2; /* type unknown */ /* $nn $ni */\n";
1173 print OUT "\textern int $s2(); /* type unknown */ /* $nn $ni */\n";
1181 return $config{version};
1186 (*OUT,my $name,*nums,my @symbols)=@_;
1187 my $n = 1; my @e; my @r; my @v; my $prev="";
1189 my $libname = $name;
1190 my $http_vendor = 'www.openssl.org/';
1191 my $version = get_version();
1192 my $what = "OpenSSL: implementation of Secure Socket Layer";
1193 my $description = "$what $version, $name - http://$http_vendor";
1194 my $prevsymversion = "", $prevprevsymversion = "";
1197 my $symvtextcount = 0;
1206 ; Definition file for the DLL version of the $name library from OpenSSL
1209 LIBRARY $libname $liboptions
1221 $symvtextcount = 16; # length of "SYMBOL_VECTOR=(-"
1224 (@r)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:FUNCTION/,@symbols);
1225 (@v)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:VARIABLE/,@symbols);
1227 # VMS needs to have the symbols on slot number order
1228 @symbols=(map { $_->[1] }
1229 sort { $a->[0] <=> $b->[0] }
1230 map { (my $s, my $i) = $_ =~ /^(.*?)\\(.*)$/;
1231 die "Error: $s doesn't have a number assigned\n"
1232 if !defined($nums{$s});
1233 (my $n, my @rest) = split /\\/, $nums{$s};
1234 [ $n, $_ ] } (@e, @r, @v));
1236 @symbols=((sort @e),(sort @r), (sort @v));
1239 my ($baseversion, $currversion) = get_openssl_version();
1242 if (!defined($thisversion)) {
1243 $thisversion = $baseversion;
1245 $thisversion = get_next_version($thisversion);
1247 foreach $sym (@symbols) {
1248 (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
1250 $v = 1 if $i =~ /^.*?:.*?:VARIABLE/;
1251 if (!defined($nums{$s})) {
1252 die "Error: $s does not have a number assigned\n"
1255 (my $n, my $symversion, my $dummy) = split /\\/, $nums{$s};
1256 next if $symversion ne $thisversion;
1258 my $p = ($i =~ /^[^:]*:([^:]*):/,$1);
1259 my $a = ($i =~ /^[^:]*:[^:]*:[^:]*:([^:]*)/,$1);
1260 if (is_valid($p,1) && is_valid($a,0)) {
1261 my $s2 = ($s =~ /^(.*?)(\{[0-9]+\})?$/, $1);
1263 print STDERR "Warning: Symbol '",$s2,
1264 "' redefined. old=",($nums{$prev} =~ /^(.*?)\\/,$1),
1265 ", new=",($nums{$s2} =~ /^(.*?)\\/,$1),"\n";
1267 $prev = $s2; # To warn about duplicates...
1269 if ($symversion ne $prevsymversion) {
1270 if ($prevsymversion ne "") {
1271 if ($prevprevsymversion ne "") {
1272 print OUT "} OPENSSL_"
1273 ."$prevprevsymversion;\n\n";
1278 print OUT "OPENSSL_$symversion {\n global:\n";
1279 $prevprevsymversion = $prevsymversion;
1280 $prevsymversion = $symversion;
1282 print OUT " $s2;\n";
1284 while(++$prevnum < $n) {
1285 my $symline=" ,SPARE -\n ,SPARE -\n";
1286 if ($symvtextcount + length($symline) - 2 > 1024) {
1287 print OUT ")\nSYMBOL_VECTOR=(-\n";
1288 $symvtextcount = 16; # length of "SYMBOL_VECTOR=(-"
1290 if ($symvtextcount == 16) {
1291 # Take away first comma
1295 $symvtextcount += length($symline) - 2;
1297 (my $s_uc = $s) =~ tr/a-z/A-Z/;
1299 $v ? "DATA" : "PROCEDURE";
1302 ? " ,$s_uc/$s=$symtype -\n ,$s=$symtype -\n"
1303 : " ,$s=$symtype -\n ,SPARE -\n");
1304 if ($symvtextcount + length($symline) - 2 > 1024) {
1305 print OUT ")\nSYMBOL_VECTOR=(-\n";
1306 $symvtextcount = 16; # length of "SYMBOL_VECTOR=(-"
1308 if ($symvtextcount == 16) {
1309 # Take away first comma
1313 $symvtextcount += length($symline) - 2;
1315 printf OUT " %s%-39s DATA\n",
1318 printf OUT " %s%s\n",
1324 } while ($thisversion ne $currversion);
1326 if ($prevprevsymversion ne "") {
1327 print OUT " local: *;\n} OPENSSL_$prevprevsymversion;\n\n";
1329 print OUT " local: *;\n};\n\n";
1333 (my $libvmaj, my $libvmin, my $libvedit) =
1334 $currversion =~ /^(\d+)_(\d+)_(\d+)$/;
1335 # The reason to multiply the edit number with 100 is to make space
1336 # for the possibility that we want to encode the patch letters
1337 print OUT "GSMATCH=LEQUAL,",($libvmaj * 100 + $libvmin),",",($libvedit * 100),"\n";
1353 my ($baseversion, $currversion) = get_openssl_version();
1355 open(IN,"<$name") || die "unable to open $name:$!\n";
1357 s|\R$||; # Better chomp
1361 if (defined $ret{$a[0]}) {
1362 # This is actually perfectly OK
1363 #print STDERR "Warning: Symbol '",$a[0],"' redefined. old=",$ret{$a[0]},", new=",$a[1],"\n";
1365 if ($max_num > $a[1]) {
1366 print STDERR "Warning: Number decreased from ",$max_num," to ",$a[1],"\n";
1368 elsif ($max_num == $a[1]) {
1369 # This is actually perfectly OK
1370 #print STDERR "Warning: Symbol ",$a[0]," has same number as previous ",$prev,": ",$a[1],"\n";
1371 if ($a[0] eq $prev) {
1373 $a[0] .= "{$prev_cnt}";
1380 # Existence will be proven later, in do_defs
1384 #Sanity check the version number
1385 if (defined $prevversion) {
1386 check_version_lte($prevversion, $a[2]);
1388 check_version_lte($a[2], $currversion);
1389 $prevversion = $a[2];
1390 $ret{$a[0]}=$a[1]."\\".$a[2]."\\".$a[3]; # \\ is a special marker
1392 $max_num = $a[1] if $a[1] > $max_num;
1396 print STDERR "Warning: $num_noinfo symbols were without info.";
1398 printf STDERR " The rewrite will fix this.\n";
1400 printf STDERR " You should do a rewrite to fix this.\n";
1409 (my $str, my $what) = @_;
1410 (my $n, my $v, my $i) = split(/\\/,$str);
1420 (*OUT,$name,*nums,@symbols)=@_;
1423 my @r = grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:\w+\(\w+\)/,@symbols);
1424 my $r; my %r; my %rsyms;
1426 (my $s, my $i) = split /\\/, $r;
1427 my $a = $1 if $i =~ /^.*?:.*?:\w+\((\w+)\)/;
1428 $i =~ s/^(.*?:.*?:\w+)\(\w+\)/$1/;
1429 $r{$a} = $s."\\".$i;
1434 foreach $_ (@symbols) {
1435 (my $n, my $i) = split /\\/;
1440 &parse_number($nums{$a},"n") <=> &parse_number($nums{$b},"n")
1444 (my $n, my $vers, my $i) = split /\\/, $nums{$sym};
1445 next if defined($i) && $i =~ /^.*?:.*?:\w+\(\w+\)/;
1446 next if defined($rsyms{$sym});
1447 print STDERR "DEBUG: rewrite_numbers for sym = ",$sym,": i = ",$i,", n = ",$n,", rsym{sym} = ",$rsyms{$sym},"syms{sym} = ",$syms{$sym},"\n" if $debug;
1448 $i="NOEXIST::FUNCTION:"
1449 if !defined($i) || $i eq "" || !defined($syms{$sym});
1451 $s2 =~ s/\{[0-9]+\}$//;
1452 printf OUT "%s%-39s %d\t%s\t%s\n","",$s2,$n,$vers,$i;
1453 if (exists $r{$sym}) {
1454 (my $s, $i) = split /\\/,$r{$sym};
1456 $s2 =~ s/\{[0-9]+\}$//;
1457 printf OUT "%s%-39s %d\t%s\t%s\n","",$s2,$n,$vers,$i;
1464 (*OUT,$name,*nums,my $start_num, my @symbols)=@_;
1469 ($basevers, $vers) = get_openssl_version();
1471 my @r = grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:\w+\(\w+\)/,@symbols);
1472 my $r; my %r; my %rsyms;
1474 (my $s, my $i) = split /\\/, $r;
1475 my $a = $1 if $i =~ /^.*?:.*?:\w+\((\w+)\)/;
1476 $i =~ s/^(.*?:.*?:\w+)\(\w+\)/$1/;
1477 $r{$a} = $s."\\".$i;
1481 foreach $sym (@symbols) {
1482 (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
1483 next if $i =~ /^.*?:.*?:\w+\(\w+\)/;
1484 next if defined($rsyms{$sym});
1485 die "ERROR: Symbol $sym had no info attached to it."
1487 if (!exists $nums{$s}) {
1490 $s2 =~ s/\{[0-9]+\}$//;
1491 printf OUT "%s%-39s %d\t%s\t%s\n","",$s2, ++$start_num,$vers,$i;
1492 if (exists $r{$s}) {
1493 ($s, $i) = split /\\/,$r{$s};
1494 $s =~ s/\{[0-9]+\}$//;
1495 printf OUT "%s%-39s %d\t%s\t%s\n","",$s, $start_num,$vers,$i;
1500 print STDERR "$name: Added $new_syms new symbols\n";
1502 print STDERR "$name: No new symbols added\n";
1508 (*nums, my @symbols)=@_;
1509 my %existing; my @remaining;
1511 foreach $sym (@symbols) {
1512 (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
1515 foreach $sym (keys %nums) {
1516 if (!exists $existing{$sym}) {
1517 push @remaining, $sym;
1521 print STDERR "The following symbols do not seem to exist:\n";
1522 foreach $sym (@remaining) {
1523 print STDERR "\t",$sym,"\n";
1530 my $line = shift(@_);
1532 my $open = $line =~ tr/\(//;
1533 my $close = $line =~ tr/\)//;
1535 return $open - $close;
1538 #Parse opensslv.h to get the current version number. Also work out the base
1539 #version, i.e. the lowest version number that is binary compatible with this
1541 sub get_openssl_version()
1543 my $fn = catfile($config{sourcedir},"include","openssl","opensslv.h");
1544 open (IN, "$fn") || die "Can't open opensslv.h";
1547 if (/OPENSSL_VERSION_TEXT\s+"OpenSSL (\d\.\d\.)(\d[a-z]*)(-| )/) {
1549 (my $baseversion = $1) =~ s/\./_/g;
1551 return ($baseversion."0", $baseversion.$suffix);
1554 die "Can't find OpenSSL version number\n";
1557 #Given an OpenSSL version number, calculate the next version number. If the
1558 #version number gets to a.b.czz then we go to a.b.(c+1)
1559 sub get_next_version()
1561 my $thisversion = shift;
1563 my ($base, $letter) = $thisversion =~ /^(\d_\d_\d)([a-z]{0,2})$/;
1565 if ($letter eq "zz") {
1566 my $lastnum = substr($base, -1);
1567 return substr($base, 0, length($base)-1).(++$lastnum);
1569 return $base.get_next_letter($letter);
1572 #Given the letters off the end of an OpenSSL version string, calculate what
1573 #the letters for the next release would be.
1574 sub get_next_letter()
1576 my $thisletter = shift;
1577 my $baseletter = "";
1580 if ($thisletter eq "") {
1583 if ((length $thisletter) > 1) {
1584 ($baseletter, $endletter) = $thisletter =~ /([a-z]+)([a-z])/;
1586 $endletter = $thisletter;
1589 if ($endletter eq "z") {
1590 return $thisletter."a";
1592 return $baseletter.(++$endletter);
1596 #Check if a version is less than or equal to the current version. Its a fatal
1597 #error if not. They must also only differ in letters, or the last number (i.e.
1598 #the first two numbers must be the same)
1599 sub check_version_lte()
1601 my ($testversion, $currversion) = @_;
1606 my ($cvnums) = $currversion =~ /^(\d_\d_\d)[a-z]*$/;
1607 my ($tvnums) = $testversion =~ /^(\d_\d_\d)[a-z]*$/;
1609 #Die if we can't parse the version numbers or they don't look sane
1610 die "Invalid version number: $testversion and $currversion\n"
1611 if (!defined($cvnums) || !defined($tvnums)
1612 || length($cvnums) != 5
1613 || length($tvnums) != 5);
1615 #If the base versions (without letters) don't match check they only differ
1617 if ($cvnums ne $tvnums) {
1618 die "Invalid version number: $testversion "
1619 ."for current version $currversion\n"
1620 if (substr($cvnums, 0, 4) ne substr($tvnums, 0, 4));
1623 #If we get here then the base version (i.e. the numbers) are the same - they
1624 #only differ in the letters
1626 $lentv = length $testversion;
1627 $lencv = length $currversion;
1629 #If the testversion has more letters than the current version then it must
1630 #be later (or malformed)
1631 if ($lentv > $lencv) {
1632 die "Invalid version number: $testversion "
1633 ."is greater than $currversion\n";
1636 #Get the last letter from the current version
1637 my ($cvletter) = $currversion =~ /([a-z])$/;
1638 if (defined $cvletter) {
1639 ($cvbase) = $currversion =~ /(\d_\d_\d[a-z]*)$cvletter$/;
1641 $cvbase = $currversion;
1643 die "Unable to parse version number $currversion" if (!defined $cvbase);
1645 my ($tvletter) = $testversion =~ /([a-z])$/;
1646 if (defined $tvletter) {
1647 ($tvbase) = $testversion =~ /(\d_\d_\d[a-z]*)$tvletter$/;
1649 $tvbase = $testversion;
1651 die "Unable to parse version number $testversion" if (!defined $tvbase);
1653 if ($lencv > $lentv) {
1654 #If current version has more letters than testversion then testversion
1655 #minus the final letter must be a substring of the current version
1656 die "Invalid version number $testversion "
1657 ."is greater than $currversion or is invalid\n"
1658 if (index($cvbase, $tvbase) != 0);
1660 #If both versions have the same number of letters then they must be
1661 #equal up to the last letter, and the last letter in testversion must
1662 #be less than or equal to the last letter in current version.
1663 die "Invalid version number $testversion "
1664 ."is greater than $currversion\n"
1665 if (($cvbase ne $tvbase) && ($tvletter gt $cvletter));
1671 my ($decl, $plats, $algs) = @_;
1672 $decl =~ /^\s*(DEPRECATEDIN_\d+_\d+_\d+)\s*\((.*)\)\s*$/
1673 or die "Bad DEPRECTEDIN: $decl\n";
1674 my $info1 .= "#INFO:";
1675 $info1 .= join(',', @{$plats}) . ":";
1677 $info1 .= join(',',@{$algs}, $1) . ";";
1678 $info2 .= join(',',@{$algs}) . ";";
1679 return $info1 . $2 . ";" . $info2;