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.
9 my $crypto_num="util/libeay.num";
10 my $ssl_num= "util/ssleay.num";
20 # Set this to make typesafe STACK definitions appear in DEF
21 my $safe_stack_def = 1;
24 open(IN,"<Makefile.ssl") || die "unable to open Makefile.ssl!\n";
26 $options=$1 if (/^OPTIONS=(.*)$/);
30 # The following ciphers may be excluded (by Configure). This means functions
31 # defined with ifndef(NO_XXX) are not included in the .def file, and everything
32 # in directory xxx is ignored.
33 my $no_rc2; my $no_rc4; my $no_rc5; my $no_idea; my $no_des; my $no_bf;
34 my $no_cast; my $no_md2; my $no_md5; my $no_sha; my $no_ripemd; my $no_mdc2;
35 my $no_rsa; my $no_dsa; my $no_dh; my $no_hmac=0;
37 foreach (@ARGV, split(/ /, $options))
45 $do_ssl=1 if $_ eq "ssleay";
46 $do_ssl=1 if $_ eq "ssl";
47 $do_crypto=1 if $_ eq "libeay";
48 $do_crypto=1 if $_ eq "crypto";
49 $do_update=1 if $_ eq "update";
50 $do_ctest=1 if $_ eq "ctest";
51 $rsaref=1 if $_ eq "rsaref";
53 if (/^no-rc2$/) { $no_rc2=1; }
54 elsif (/^no-rc4$/) { $no_rc4=1; }
55 elsif (/^no-rc5$/) { $no_rc5=1; }
56 elsif (/^no-idea$/) { $no_idea=1; }
57 elsif (/^no-des$/) { $no_des=1; }
58 elsif (/^no-bf$/) { $no_bf=1; }
59 elsif (/^no-cast$/) { $no_cast=1; }
60 elsif (/^no-md2$/) { $no_md2=1; }
61 elsif (/^no-md5$/) { $no_md5=1; }
62 elsif (/^no-sha$/) { $no_sha=1; }
63 elsif (/^no-ripemd$/) { $no_ripemd=1; }
64 elsif (/^no-mdc2$/) { $no_mdc2=1; }
65 elsif (/^no-rsa$/) { $no_rsa=1; }
66 elsif (/^no-dsa$/) { $no_dsa=1; }
67 elsif (/^no-dh$/) { $no_dh=1; }
68 elsif (/^no-hmac$/) { $no_hmac=1; }
72 if (!$do_ssl && !$do_crypto)
74 print STDERR "usage: $0 ( ssl | crypto ) [ 16 | 32 | NT ] [rsaref]\n";
78 %ssl_list=&load_numbers($ssl_num);
80 %crypto_list=&load_numbers($crypto_num);
81 $max_crypto = $max_num;
85 my $crypto ="crypto/crypto.h";
86 $crypto.=" crypto/des/des.h" unless $no_des;
87 $crypto.=" crypto/idea/idea.h" unless $no_idea;
88 $crypto.=" crypto/rc4/rc4.h" unless $no_rc4;
89 $crypto.=" crypto/rc5/rc5.h" unless $no_rc5;
90 $crypto.=" crypto/rc2/rc2.h" unless $no_rc2;
91 $crypto.=" crypto/bf/blowfish.h" unless $no_bf;
92 $crypto.=" crypto/cast/cast.h" unless $no_cast;
93 $crypto.=" crypto/md2/md2.h" unless $no_md2;
94 $crypto.=" crypto/md5/md5.h" unless $no_md5;
95 $crypto.=" crypto/mdc2/mdc2.h" unless $no_mdc2;
96 $crypto.=" crypto/sha/sha.h" unless $no_sha;
97 $crypto.=" crypto/ripemd/ripemd.h" unless $no_ripemd;
99 $crypto.=" crypto/bn/bn.h";
100 $crypto.=" crypto/rsa/rsa.h" unless $no_rsa;
101 $crypto.=" crypto/dsa/dsa.h" unless $no_dsa;
102 $crypto.=" crypto/dh/dh.h" unless $no_dh;
103 $crypto.=" crypto/hmac/hmac.h" unless $no_hmac;
105 $crypto.=" crypto/stack/stack.h";
106 $crypto.=" crypto/buffer/buffer.h";
107 $crypto.=" crypto/bio/bio.h";
108 $crypto.=" crypto/dso/dso.h";
109 $crypto.=" crypto/lhash/lhash.h";
110 $crypto.=" crypto/conf/conf.h";
111 $crypto.=" crypto/txt_db/txt_db.h";
113 $crypto.=" crypto/evp/evp.h";
114 $crypto.=" crypto/objects/objects.h";
115 $crypto.=" crypto/pem/pem.h";
116 #$crypto.=" crypto/meth/meth.h";
117 $crypto.=" crypto/asn1/asn1.h";
118 $crypto.=" crypto/asn1/asn1_mac.h";
119 $crypto.=" crypto/err/err.h";
120 $crypto.=" crypto/pkcs7/pkcs7.h";
121 $crypto.=" crypto/pkcs12/pkcs12.h";
122 $crypto.=" crypto/x509/x509.h";
123 $crypto.=" crypto/x509/x509_vfy.h";
124 $crypto.=" crypto/x509v3/x509v3.h";
125 $crypto.=" crypto/rand/rand.h";
126 $crypto.=" crypto/comp/comp.h";
127 $crypto.=" crypto/tmdiff.h";
129 my @ssl_func = &do_defs("SSLEAY", $ssl);
130 my @crypto_func = &do_defs("LIBEAY", $crypto);
136 open(OUT, ">>$ssl_num");
137 &update_numbers(*OUT,"SSLEAY",*ssl_list,$max_ssl, @ssl_func);
141 if($do_crypto == 1) {
142 open(OUT, ">>$crypto_num");
143 &update_numbers(*OUT,"LIBEAY",*crypto_list,$max_crypto, @crypto_func);
147 } elsif ($do_ctest) {
151 /* Test file to check all DEF file symbols are present by trying
152 * to link to all of them. This is *not* intended to be run!
158 &print_test_file(*STDOUT,"SSLEAY",*ssl_list,@ssl_func)
161 &print_test_file(*STDOUT,"LIBEAY",*crypto_list,@crypto_func)
168 &print_def_file(*STDOUT,"SSLEAY",*ssl_list,@ssl_func)
171 &print_def_file(*STDOUT,"LIBEAY",*crypto_list,@crypto_func)
185 foreach $file (split(/\s+/,$files))
187 open(IN,"<$file") || die "unable to open $file:$!\n";
188 my $line = "", my $def= "";
216 last if (/BEGIN ERROR CODES/);
227 $cpp = 1 if /^#.*ifdef.*cplusplus/;
229 $cpp = 0 if /^#.*endif/;
233 s/\/\*.*?\*\///gs; # ignore comments
234 s/{[^{}]*}//gs; # ignore {} blocks
235 if (/^\#\s*ifndef (.*)/) {
239 } elsif (/^\#\s*if !defined\(([^\)]+)\)/) {
243 } elsif (/^\#\s*ifdef (.*)/) {
247 } elsif (/^\#\s*if defined(.*)/) {
251 } elsif (/^\#\s*endif/) {
255 } elsif (/^\#\s*else/) {
259 } elsif (/^\#\s*if\s+1/) {
264 } elsif (/^\#\s*if\s+0/) {
272 if ($safe_stack_def &&
273 /^\s*DECLARE_STACK_OF\s*\(\s*(\w*)\s*\)/) {
274 $funcs{"sk_${1}_new"} = 1;
275 $funcs{"sk_${1}_new_null"} = 1;
276 $funcs{"sk_${1}_free"} = 1;
277 $funcs{"sk_${1}_num"} = 1;
278 $funcs{"sk_${1}_value"} = 1;
279 $funcs{"sk_${1}_set"} = 1;
280 $funcs{"sk_${1}_zero"} = 1;
281 $funcs{"sk_${1}_push"} = 1;
282 $funcs{"sk_${1}_unshift"} = 1;
283 $funcs{"sk_${1}_find"} = 1;
284 $funcs{"sk_${1}_delete"} = 1;
285 $funcs{"sk_${1}_delete_ptr"} = 1;
286 $funcs{"sk_${1}_insert"} = 1;
287 $funcs{"sk_${1}_set_cmp_func"} = 1;
288 $funcs{"sk_${1}_dup"} = 1;
289 $funcs{"sk_${1}_pop_free"} = 1;
290 $funcs{"sk_${1}_shift"} = 1;
291 $funcs{"sk_${1}_pop"} = 1;
292 $funcs{"sk_${1}_sort"} = 1;
293 } elsif ($safe_stack_def &&
294 /^\s*DECLARE_ASN1_SET_OF\s*\(\s*(\w*)\s*\)/) {
295 $funcs{"d2i_ASN1_SET_OF_${1}"} = 1;
296 $funcs{"i2d_ASN1_SET_OF_${1}"} = 1;
297 } elsif (/^DECLARE_PEM_rw\s*\(\s*(\w*)\s*,/ ||
298 /^DECLARE_PEM_rw_cb\s*\(\s*(\w*)\s*,/ ) {
299 if (!($no_rsa && ($1 eq "RSAPrivateKey" ||
300 $1 eq "RSAPublicKey" ||
301 $1 eq "RSA_PUBKEY"))) {
303 $funcs{"PEM_read_${1}"} = 1;
304 $funcs{"PEM_write_${1}"} = 1;
306 $funcs{"PEM_read_bio_${1}"} = 1;
307 $funcs{"PEM_write_bio_${1}"} = 1;
309 } elsif (/^DECLARE_PEM_write\s*\(\s*(\w*)\s*,/ ||
310 /^DECLARE_PEM_write_cb\s*\(\s*(\w*)\s*,/ ) {
311 if (!($no_rsa && ($1 eq "RSAPrivateKey" ||
312 $1 eq "RSAPublicKey" ||
313 $1 eq "RSA_PUBKEY"))) {
315 $funcs{"PEM_write_${1}"} = 1;
317 $funcs{"PEM_write_bio_${1}"} = 1;
319 } elsif (/^DECLARE_PEM_read\s*\(\s*(\w*)\s*,/ ||
320 /^DECLARE_PEM_read_cb\s*\(\s*(\w*)\s*,/ ) {
322 $funcs{"PEM_read_${1}"} = 1;
324 $funcs{"PEM_read_bio_${1}"} = 1;
326 ($tag{'TRUE'} != -1) &&
327 ($tag{'FreeBSD'} != 1) &&
328 ($tag{'CONST_STRICT'} != 1) &&
329 (($W32 && ($tag{'WIN16'} != 1)) ||
330 (!$W32 && ($tag{'WIN16'} != -1))) &&
331 ($tag{'PERL5'} != 1) &&
332 # ($tag{'_WINDLL'} != -1) &&
333 ((!$W32 && $tag{'_WINDLL'} != -1) ||
334 ($W32 && $tag{'_WINDLL'} != 1)) &&
335 ((($tag{'NO_FP_API'} != 1) && $W32) ||
336 (($tag{'NO_FP_API'} != -1) && !$W32)) &&
337 ($tag{'NO_RC2'} == 0 || !$no_rc2) &&
338 ($tag{'NO_RC4'} == 0 || !$no_rc4) &&
339 ($tag{'NO_RC5'} == 0 || !$no_rc5) &&
340 ($tag{'NO_IDEA'} == 0 || !$no_idea) &&
341 ($tag{'NO_DES'} == 0 || !$no_des) &&
342 ($tag{'NO_BF'} == 0 || !$no_bf) &&
343 ($tag{'NO_CAST'} == 0 || !$no_cast) &&
344 ($tag{'NO_MD2'} == 0 || !$no_md2) &&
345 ($tag{'NO_MD5'} == 0 || !$no_md5) &&
346 ($tag{'NO_SHA'} == 0 || !$no_sha) &&
347 ($tag{'NO_RIPEMD'} == 0 || !$no_ripemd) &&
348 ($tag{'NO_MDC2'} == 0 || !$no_mdc2) &&
349 ($tag{'NO_RSA'} == 0 || !$no_rsa) &&
350 ($tag{'NO_DSA'} == 0 || !$no_dsa) &&
351 ($tag{'NO_DH'} == 0 || !$no_dh) &&
352 ($tag{'NO_HMAC'} == 0 || !$no_hmac))
363 foreach (split /;/, $def) {
366 next if(/typedef\W/);
367 next if(/EVP_bf/ and $no_bf);
368 next if(/EVP_cast/ and $no_cast);
369 next if(/EVP_des/ and $no_des);
370 next if(/EVP_dss/ and $no_dsa);
371 next if(/EVP_idea/ and $no_idea);
372 next if(/EVP_md2/ and $no_md2);
373 next if(/EVP_md5/ and $no_md5);
374 next if(/EVP_rc2/ and $no_rc2);
375 next if(/EVP_rc4/ and $no_rc4);
376 next if(/EVP_rc5/ and $no_rc5);
377 next if(/EVP_ripemd/ and $no_ripemd);
378 next if(/EVP_sha/ and $no_sha);
379 next if(/EVP_(Open|Seal)(Final|Init)/ and $no_rsa);
380 next if(/PEM_Seal(Final|Init|Update)/ and $no_rsa);
381 next if(/RSAPrivateKey/ and $no_rsa);
382 next if(/SSLv23?_((client|server)_)?method/ and $no_rsa);
384 if (/\(\*(\w*)\([^\)]+/) {
386 } elsif (/\w+\W+(\w+)\W*\(\s*\)$/s) {
389 } elsif (/\w+\W+\w+\W*\(.*\)$/s) {
390 while (not /\(\)$/s) {
392 s/\([^\(\)]*\)\)$/\)/s;
397 } elsif (/\(/ and not (/=/)) {
398 print STDERR "File $file: cannot parse: $_;\n";
403 # Prune the returned functions
405 delete $funcs{"SSL_add_dir_cert_subjects_to_stack"};
406 delete $funcs{"RSA_PKCS1_RSAref"} unless $rsaref;
407 delete $funcs{"bn_dump1"};
410 delete $funcs{"BIO_s_file_internal"};
411 delete $funcs{"BIO_new_file_internal"};
412 delete $funcs{"BIO_new_fp_internal"};
414 if(exists $funcs{"ERR_load_CRYPTO_strings"}) {
415 delete $funcs{"ERR_load_CRYPTO_strings"};
416 $funcs{"ERR_load_CRYPTOlib_strings"} = 1;
418 delete $funcs{"BIO_s_file"};
419 delete $funcs{"BIO_new_file"};
420 delete $funcs{"BIO_new_fp"};
423 delete $funcs{"BIO_s_log"};
426 push @ret, keys %funcs;
433 (*OUT,my $name,*nums,my @functions)=@_;
434 my $n = 1; my @e; my @r;
437 (@e)=grep(/^SSLeay/,@functions);
438 (@r)=grep(!/^SSLeay/,@functions);
439 @functions=((sort @e),(sort @r));
441 foreach $func (@functions) {
442 if (!defined($nums{$func})) {
443 printf STDERR "$func does not have a number assigned\n"
447 print OUT "\t$func();\n";
454 (*OUT,my $name,*nums,my @functions)=@_;
455 my $n = 1; my @e; my @r;
464 ; Definition file for the DLL version of the $name library from OpenSSL
469 DESCRIPTION 'OpenSSL $name - http://www.openssl.org/'
475 CODE PRELOAD MOVEABLE
476 DATA PRELOAD MOVEABLE SINGLE
489 (@e)=grep(/^SSLeay/,@functions);
490 (@r)=grep(!/^SSLeay/,@functions);
491 @functions=((sort @e),(sort @r));
493 foreach $func (@functions) {
494 if (!defined($nums{$func})) {
495 printf STDERR "$func does not have a number assigned\n"
499 printf OUT " %s%-40s@%d\n",($W32)?"":"_",$func,$n;
512 open(IN,"<$name") || die "unable to open $name:$!\n";
519 $max_num = $a[1] if $a[1] > $max_num;
527 (*OUT,$name,*nums,my $start_num, my @functions)=@_;
529 print STDERR "Updating $name\n";
530 foreach $func (@functions) {
531 if (!exists $nums{$func}) {
533 printf OUT "%s%-40s%d\n","",$func, ++$start_num;
537 print STDERR "$new_funcs New Functions added\n";
539 print STDERR "No New Functions Added\n";