Do not insert things in syms{} and kind{} when parsing the header
[openssl.git] / util / mkdef.pl
index 961dff5b8fc9761634f4da5a7b10a4faa3204584..995e1dd27d444d4bf192ccc309a4efe1947daab8 100755 (executable)
@@ -63,7 +63,7 @@ my $do_crypto = 0;
 my $do_ssl = 0;
 my $do_ctest = 0;
 my $do_ctestall = 0;
-my $rsaref = 0;
+my $do_checkexist = 0;
 
 my $VMS=0;
 my $W32=0;
@@ -77,7 +77,7 @@ my @known_platforms = ( "__FreeBSD__", "VMS", "WIN16", "WIN32",
 my @known_algorithms = ( "RC2", "RC4", "RC5", "IDEA", "DES", "BF",
                         "CAST", "MD2", "MD4", "MD5", "SHA", "SHA0", "SHA1",
                         "RIPEMD",
-                        "MDC2", "RSA", "DSA", "DH", "HMAC", "RIJNDAEL",
+                        "MDC2", "RSA", "DSA", "DH", "HMAC", "AES",
                         # Envelope "algorithms"
                         "EVP", "X509", "ASN1_TYPEDEFS",
                         # Helper "algorithms"
@@ -99,7 +99,7 @@ close(IN);
 my $no_rc2; my $no_rc4; my $no_rc5; my $no_idea; my $no_des; my $no_bf;
 my $no_cast;
 my $no_md2; my $no_md4; my $no_md5; my $no_sha; my $no_ripemd; my $no_mdc2;
-my $no_rsa; my $no_dsa; my $no_dh; my $no_hmac=0; my $no_rijndael;
+my $no_rsa; my $no_dsa; my $no_dh; my $no_hmac=0; my $no_aes; my $no_krb5;
 my $no_fp_api;
 
 foreach (@ARGV, split(/ /, $options))
@@ -111,7 +111,6 @@ foreach (@ARGV, split(/ /, $options))
                $NT = 1;
        }
        $VMS=1 if $_ eq "VMS";
-       #$rsaref=1 if $_ eq "rsaref";
 
        $do_ssl=1 if $_ eq "ssleay";
        $do_ssl=1 if $_ eq "ssl";
@@ -121,6 +120,7 @@ foreach (@ARGV, split(/ /, $options))
        $do_rewrite=1 if $_ eq "rewrite";
        $do_ctest=1 if $_ eq "ctest";
        $do_ctestall=1 if $_ eq "ctestall";
+       $do_checkexist=1 if $_ eq "exist";
        #$safe_stack_def=1 if $_ eq "-DDEBUG_SAFESTACK";
 
        if    (/^no-rc2$/)      { $no_rc2=1; }
@@ -140,7 +140,7 @@ foreach (@ARGV, split(/ /, $options))
        elsif (/^no-dsa$/)      { $no_dsa=1; }
        elsif (/^no-dh$/)       { $no_dh=1; }
        elsif (/^no-hmac$/)     { $no_hmac=1; }
-       elsif (/^no-rijndael$/) { $no_rijndael=1; }
+       elsif (/^no-aes$/)      { $no_aes=1; }
        elsif (/^no-evp$/)      { $no_evp=1; }
        elsif (/^no-lhash$/)    { $no_lhash=1; }
        elsif (/^no-stack$/)    { $no_stack=1; }
@@ -150,6 +150,7 @@ foreach (@ARGV, split(/ /, $options))
        #elsif (/^no-locking$/) { $no_locking=1; }
        elsif (/^no-comp$/)     { $no_comp=1; }
        elsif (/^no-dso$/)      { $no_dso=1; }
+       elsif (/^no-krb5$/)     { $no_krb5=1; }
        }
 
 
@@ -191,8 +192,8 @@ $crypto.=" crypto/md5/md5.h" unless $no_md5;
 $crypto.=" crypto/mdc2/mdc2.h" unless $no_mdc2;
 $crypto.=" crypto/sha/sha.h" unless $no_sha;
 $crypto.=" crypto/ripemd/ripemd.h" unless $no_ripemd;
-$crypto.=" crypto/rijndael/rijndael.h" unless $no_rijndael;
-$crypto.=" crypto/rijndael/rd_fst.h" unless $no_rijndael;
+$crypto.=" crypto/rijndael/rijndael.h" unless $no_aes;
+$crypto.=" crypto/rijndael/rd_fst.h" unless $no_aes;
 
 $crypto.=" crypto/bn/bn.h";
 $crypto.=" crypto/rsa/rsa.h" unless $no_rsa;
@@ -261,6 +262,11 @@ if($do_crypto == 1) {
        close OUT;
 } 
 
+} elsif ($do_checkexist) {
+       &check_existing(*ssl_list, @ssl_symbols)
+               if $do_ssl == 1;
+       &check_existing(*crypto_list, @crypto_symbols)
+               if $do_crypto == 1;
 } elsif ($do_ctest || $do_ctestall) {
 
        print <<"EOF";
@@ -318,6 +324,9 @@ sub do_defs
                        TRUE            => 1,
                );
                my $symhacking = $file eq $symhacksfile;
+               my @current_platforms = ();
+               my @current_algorithms = ();
+
                while(<IN>) {
                        last if (/BEGIN ERROR CODES/);
                        if ($line ne '') {
@@ -396,32 +405,56 @@ sub do_defs
                                $rename{$s} = $a;
                        }
                        if (/^\#/) {
-                               my @p = grep(!/^$/,
-                                            map { $tag{$_} == 1 ? $_ :
-                                                      $tag{$_} == -1 ? "!".$_  : "" }
-                                            @known_platforms);
-                               my @a = grep(!/^$/,
-                                            map { $tag{"NO_".$_} == -1 ? $_ : "" }
-                                            @known_algorithms);
-                               $def .= "#INFO:".join(',',@p).":".join(',',@a).";";
+                               @current_platforms =
+                                   grep(!/^$/,
+                                        map { $tag{$_} == 1 ? $_ :
+                                                  $tag{$_} == -1 ? "!".$_  : "" }
+                                        @known_platforms);
+                               @current_algorithms =
+                                   grep(!/^$/,
+                                        map { $tag{"NO_".$_} == -1 ? $_ : "" }
+                                        @known_algorithms);
+                               $def .=
+                                   "#INFO:"
+                                       .join(',',@current_platforms).":"
+                                           .join(',',@current_algorithms).";";
                                next;
                        }
                        if (/^\s*DECLARE_STACK_OF\s*\(\s*(\w*)\s*\)/) {
                                next;
+                       } elsif (/^\s*DECLARE_ASN1_ENCODE_FUNCTIONS\s*\(\s*(\w*)\s*,\s*(\w*)\s*,\s*(\w*)\s*\)/) {
+                               $def .= "int d2i_$3(void);";
+                               $def .= "int i2d_$3(void);";
+                               $def .= "OPENSSL_EXTERN int $2_it;";
+                               next;
                        } elsif (/^\s*DECLARE_ASN1_FUNCTIONS_fname\s*\(\s*(\w*)\s*,\s*(\w*)\s*,\s*(\w*)\s*\)/) {
-                               $syms{"d2i_$3"} = 1;
-                               $syms{"i2d_$3"} = 1;
-                               $syms{"$3_new"} = 1;
-                               $syms{"$3_free"} = 1;
-                               $syms{"$2_it"} = 1;
-                               $kind{"$2_it"} = "VARIABLE";
-                       } elsif (/^\s*DECLARE_ASN1_FUNCTIONS\s*\(\s*(\w*)\s*\)/) {
-                               $syms{"d2i_$1"} = 1;
-                               $syms{"i2d_$1"} = 1;
-                               $syms{"$1_new"} = 1;
-                               $syms{"$1_free"} = 1;
-                               $syms{"$1_it"} = 1;
-                               $kind{"$1_it"} = "VARIABLE";
+                               $def .= "int d2i_$3(void);";
+                               $def .= "int i2d_$3(void);";
+                               $def .= "int $3_free(void);";
+                               $def .= "int $3_new(void);";
+                               $def .= "OPENSSL_EXTERN int $2_it;";
+                       } elsif (/^\s*DECLARE_ASN1_FUNCTIONS\s*\(\s*(\w*)\s*\)/ ||
+                               /^\s*DECLARE_ASN1_FUNCTIONS_const\s*\(\s*(\w*)\s*\)/) {
+                               $def .= "int d2i_$1(void);";
+                               $def .= "int i2d_$1(void);";
+                               $def .= "int $1_free(void);";
+                               $def .= "int $1_new(void);";
+                               $def .= "OPENSSL_EXTERN int $1_it;";
+                               next;
+                       } elsif (/^\s*DECLARE_ASN1_ENCODE_FUNCTIONS_const\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
+                               $def .= "int d2i_$2(void);";
+                               $def .= "int i2d_$2(void);";
+                               $def .= "OPENSSL_EXTERN int $2_it;";
+                               next;
+                       } elsif (/^\s*DECLARE_ASN1_FUNCTIONS_name\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
+                               $def .= "int d2i_$2(void);";
+                               $def .= "int i2d_$2(void);";
+                               $def .= "int $2_free(void);";
+                               $def .= "int $2_new(void);";
+                               $def .= "OPENSSL_EXTERN int $2_it;";
+                               next;
+                       } elsif (/^\s*DECLARE_ASN1_ITEM\s*\(\s*(\w*)\s*,(\w*)\s*\)/) {
+                               $def .= "OPENSSL_EXTERN int $1_it;";
                                next;
                        } elsif (/^\s*DECLARE_PKCS12_STACK_OF\s*\(\s*(\w*)\s*\)/) {
                                next;
@@ -430,65 +463,47 @@ sub do_defs
                        } elsif (/^DECLARE_PEM_rw\s*\(\s*(\w*)\s*,/ ||
                                 /^DECLARE_PEM_rw_cb\s*\(\s*(\w*)\s*,/ ) {
                                # Things not in Win16
-                               $syms{"PEM_read_${1}"} = 1;
-                               $platform{"PEM_read_${1}"} = "!WIN16";
-                               $syms{"PEM_write_${1}"} = 1;
-                               $platform{"PEM_write_${1}"} = "!WIN16";
+                               $def .=
+                                   "#INFO:"
+                                       .join(',',"!WIN16",@current_platforms).":"
+                                           .join(',',@current_algorithms).";";
+                               $def .= "int PEM_read_$1(void);";
+                               $def .= "int PEM_write_$1(void);";
+                               $def .=
+                                   "#INFO:"
+                                       .join(',',@current_platforms).":"
+                                           .join(',',@current_algorithms).";";
                                # Things that are everywhere
-                               $syms{"PEM_read_bio_${1}"} = 1;
-                               $syms{"PEM_write_bio_${1}"} = 1;
-                               if ($1 eq "RSAPrivateKey" ||
-                                   $1 eq "RSAPublicKey" ||
-                                   $1 eq "RSA_PUBKEY") {
-                                       $algorithm{"PEM_read_${1}"} = "RSA";
-                                       $algorithm{"PEM_write_${1}"} = "RSA";
-                                       $algorithm{"PEM_read_bio_${1}"} = "RSA";
-                                       $algorithm{"PEM_write_bio_${1}"} = "RSA";
-                               }
-                               elsif ($1 eq "DSAPrivateKey" ||
-                                      $1 eq "DSAparams" ||
-                                      $1 eq "RSA_PUBKEY") {
-                                       $algorithm{"PEM_read_${1}"} = "DSA";
-                                       $algorithm{"PEM_write_${1}"} = "DSA";
-                                       $algorithm{"PEM_read_bio_${1}"} = "DSA";
-                                       $algorithm{"PEM_write_bio_${1}"} = "DSA";
-                               }
-                               elsif ($1 eq "DHparams") {
-                                       $algorithm{"PEM_read_${1}"} = "DH";
-                                       $algorithm{"PEM_write_${1}"} = "DH";
-                                       $algorithm{"PEM_read_bio_${1}"} = "DH";
-                                       $algorithm{"PEM_write_bio_${1}"} = "DH";
-                               }
+                               $def .= "int PEM_read_bio_$1(void);";
+                               $def .= "int PEM_write_bio_$1(void);";
                        } elsif (/^DECLARE_PEM_write\s*\(\s*(\w*)\s*,/ ||
                                     /^DECLARE_PEM_write_cb\s*\(\s*(\w*)\s*,/ ) {
                                # Things not in Win16
-                               $syms{"PEM_write_${1}"} = 1;
-                               $platform{"PEM_write_${1}"} .= ",!WIN16";
+                               $def .=
+                                   "#INFO:"
+                                       .join(',',"!WIN16",@current_platforms).":"
+                                           .join(',',@current_algorithms).";";
+                               $def .= "int PEM_write_$1(void);";
+                               $def .=
+                                   "#INFO:"
+                                       .join(',',@current_platforms).":"
+                                           .join(',',@current_algorithms).";";
                                # Things that are everywhere
-                               $syms{"PEM_write_bio_${1}"} = 1;
-                               if ($1 eq "RSAPrivateKey" ||
-                                   $1 eq "RSAPublicKey" ||
-                                   $1 eq "RSA_PUBKEY") {
-                                       $algorithm{"PEM_write_${1}"} = "RSA";
-                                       $algorithm{"PEM_write_bio_${1}"} = "RSA";
-                               }
-                               elsif ($1 eq "DSAPrivateKey" ||
-                                      $1 eq "DSAparams" ||
-                                      $1 eq "RSA_PUBKEY") {
-                                       $algorithm{"PEM_write_${1}"} = "DSA";
-                                       $algorithm{"PEM_write_bio_${1}"} = "DSA";
-                               }
-                               elsif ($1 eq "DHparams") {
-                                       $algorithm{"PEM_write_${1}"} = "DH";
-                                       $algorithm{"PEM_write_bio_${1}"} = "DH";
-                               }
+                               $def .= "int PEM_write_bio_$1(void);";
                        } elsif (/^DECLARE_PEM_read\s*\(\s*(\w*)\s*,/ ||
                                     /^DECLARE_PEM_read_cb\s*\(\s*(\w*)\s*,/ ) {
                                # Things not in Win16
-                               $syms{"PEM_read_${1}"} = 1;
-                               $platform{"PEM_read_${1}"} .= ",!WIN16";
+                               $def .=
+                                   "#INFO:"
+                                       .join(',',"!WIN16",@current_platforms).":"
+                                           .join(',',@current_algorithms).";";
+                               $def .= "int PEM_read_$1(void);";
+                               $def .=
+                                   "#INFO:"
+                                       .join(',',@current_platforms).":"
+                                           .join(',',@current_algorithms).";";
                                # Things that are everywhere
-                               $syms{"PEM_read_bio_${1}"} = 1;
+                               $def .= "int PEM_read_bio_$1(void);";
                        } elsif (
                                ($tag{'TRUE'} != -1)
                                && ($tag{'CONST_STRICT'} != 1)
@@ -604,9 +619,6 @@ sub do_defs
 
        # Info we know about
 
-       $platform{"RSA_PKCS1_RSAref"} = "RSAREF";
-       $algorithm{"RSA_PKCS1_RSAref"} = "RSA";
-
        push @ret, map { $_."\\".&info_string($_,"EXIST",
                                              $platform{$_},
                                              $kind{$_},
@@ -711,8 +723,8 @@ sub print_test_file
        foreach $sym (@symbols) {
                (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
                if ($s ne $prev) {
-                       if (!defined($nums{$sym})) {
-                               printf STDERR "Warning: $sym does not have a number assigned\n"
+                       if (!defined($nums{$s})) {
+                               printf STDERR "Warning: $s does not have a number assigned\n"
                                                if(!$do_update);
                        } else {
                                $n=$nums{$s};
@@ -780,7 +792,6 @@ EOF
                        # @p_purged must contain hardware platforms only
                        my @p_purged = ();
                        foreach $ptmp (@p) {
-                               next if $ptmp =~ /^!?RSAREF$/;
                                push @p_purged, $ptmp;
                        }
                        my $negatives = !!grep(/^!/,@p);
@@ -794,11 +805,6 @@ EOF
                             || ($W16 && (!@p_purged
                                          || (!$negatives && grep(/^WIN16$/,@p))
                                          || ($negatives && !grep(/^!WIN16$/,@p)))))
-                           && (!@p
-                               || (!$negatives
-                                   && ($rsaref || !grep(/^RSAREF$/,@p)))
-                               || ($negatives
-                                   && (!$rsaref || !grep(/^!RSAREF$/,@p))))
                            && (!@a || (!$no_rc2 || !grep(/^RC2$/,@a)))
                            && (!@a || (!$no_rc4 || !grep(/^RC4$/,@a)))
                            && (!@a || (!$no_rc5 || !grep(/^RC5$/,@a)))
@@ -816,7 +822,8 @@ EOF
                            && (!@a || (!$no_dsa || !grep(/^DSA$/,@a)))
                            && (!@a || (!$no_dh || !grep(/^DH$/,@a)))
                            && (!@a || (!$no_hmac || !grep(/^HMAC$/,@a)))
-                           && (!@a || (!$no_rijndael || !grep(/^RIJNDAEL$/,@a)))
+                           && (!@a || (!$no_aes || !grep(/^AES$/,@a)))
+                           && (!@a || (!$no_krb5 || !grep(/^KRB5$/,@a)))
                            && (!@a || (!$no_fp_api || !grep(/^FP_API$/,@a)))
                            ) {
                                if($v) {