use saner default parameters for scrypt
[openssl.git] / util / mkdef.pl
index c0ca92cf21b4161a52bb934dc9439999b627d7bf..409a39019f94a26871b337b3e85a1bc63a3c4bfd 100755 (executable)
 #   exclude.
 #
 
+use lib ".";
+use configdata;
+use File::Spec::Functions;
+
 my $debug=0;
 
-my $crypto_num= "util/libeay.num";
-my $ssl_num=    "util/ssleay.num";
+my $crypto_num= catfile($config{sourcedir},"util","libeay.num");
+my $ssl_num=    catfile($config{sourcedir},"util","ssleay.num");
 my $libname;
 
 my $do_update = 0;
@@ -84,8 +88,10 @@ my @known_algorithms = ( "RC2", "RC4", "RC5", "IDEA", "DES", "BF",
                          "CRYPTO_MDEBUG",
                         # Engines
                          "STATIC_ENGINE", "ENGINE", "HW", "GMP",
-                         # X.509v3 Signed Certificate Timestamps
-                         "SCT",
+                        # Entropy Gathering
+                        "EGD",
+                        # Certificate Transparency
+                        "CT",
                         # RFC3779
                         "RFC3779",
                         # TLS
@@ -96,12 +102,12 @@ my @known_algorithms = ( "RC2", "RC4", "RC5", "IDEA", "DES", "BF",
                         "CAPIENG",
                         # SSL v3 method
                         "SSL3_METHOD",
-                        # JPAKE
-                        "JPAKE",
                         # NEXTPROTONEG
                         "NEXTPROTONEG",
                         # Deprecated functions
-                        "DEPRECATED",
+                        "DEPRECATEDIN_0_9_8",
+                        "DEPRECATEDIN_1_0_0",
+                        "DEPRECATEDIN_1_1_0",
                         # SCTP
                         "SCTP",
                         # SRTP
@@ -121,17 +127,12 @@ my %disabled_algorithms;
 foreach (@known_algorithms) {
     $disabled_algorithms{$_} = 0;
 }
-
-my $options="";
-open(IN,"<Makefile") || die "unable to open Makefile!\n";
-while(<IN>) {
-    $options=$1 if (/^OPTIONS=(.*)$/);
-}
-close(IN);
+# disabled by default
+$disabled_algorithms{"STATIC_ENGINE"} = 1;
 
 my $zlib;
 
-foreach (@ARGV, split(/ /, $options))
+foreach (@ARGV, split(/ /, $config{options}))
        {
        $debug=1 if $_ eq "debug";
        $W32=1 if $_ eq "32";
@@ -173,9 +174,23 @@ foreach (@ARGV, split(/ /, $options))
        $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 (/^(enable|disable|no)-(.*)$/) {
+       if (/^--api=(\d+)\.(\d+)\.(\d+)$/) {
+               my $apiv = sprintf "%x%02x%02x", $1, $2, $3;
+               foreach (keys %disabled_algorithms) {
+                       if (/^DEPRECATEDIN_(\d+)_(\d+)_(\d+)$/) {
+                               my $depv = sprintf "%x%02x%02x", $1, $2, $3;
+                               $disabled_algorithms{$_} = 1 if $apiv ge $depv;
+                       }
+               }
+       }
+       if (/^no-deprecated$/) {
+               foreach (keys %disabled_algorithms) {
+                       if (/^DEPRECATEDIN_/) {
+                               $disabled_algorithms{$_} = 1;
+                       }
+               }
+       }
+       elsif (/^(enable|disable|no)-(.*)$/) {
                my $alg = uc $2;
         $alg =~ tr/-/_/;
                if (exists $disabled_algorithms{$alg}) {
@@ -216,12 +231,12 @@ my $ssl="include/openssl/ssl.h";
 $ssl.=" include/openssl/tls1.h";
 $ssl.=" include/openssl/srtp.h";
 
+# We use headers found in include/openssl and include/internal only.
+# The latter is needed so libssl.so/.dll/.exe can link properly.
 my $crypto ="include/openssl/crypto.h";
-$crypto.=" crypto/include/internal/cryptlib.h";
-$crypto.=" crypto/include/internal/chacha.h"; # unless $no_chacha;
-$crypto.=" crypto/include/internal/poly1305.h"; # unless $no_poly1305;
 $crypto.=" include/internal/o_dir.h";
 $crypto.=" include/internal/o_str.h";
+$crypto.=" include/internal/threads.h";
 $crypto.=" include/openssl/des.h" ; # unless $no_des;
 $crypto.=" include/openssl/idea.h" ; # unless $no_idea;
 $crypto.=" include/openssl/rc4.h" ; # unless $no_rc4;
@@ -275,12 +290,12 @@ $crypto.=" include/openssl/comp.h" ; # unless $no_comp;
 $crypto.=" include/openssl/ocsp.h";
 $crypto.=" include/openssl/ui.h";
 #$crypto.=" include/openssl/store.h";
-$crypto.=" include/openssl/pqueue.h";
 $crypto.=" include/openssl/cms.h";
-$crypto.=" include/openssl/jpake.h";
 $crypto.=" include/openssl/srp.h";
 $crypto.=" include/openssl/modes.h";
 $crypto.=" include/openssl/async.h";
+$crypto.=" include/openssl/ct.h";
+$crypto.=" include/openssl/kdf.h";
 
 my $symhacks="include/openssl/symhacks.h";
 
@@ -368,8 +383,9 @@ sub do_defs
 
        foreach $file (split(/\s+/,$symhacksfile." ".$files))
                {
-               print STDERR "DEBUG: starting on $file:\n" if $debug;
-               open(IN,"<$file") || die "unable to open $file:$!\n";
+               my $fn = catfile($config{sourcedir},$file);
+               print STDERR "DEBUG: starting on $fn:\n" if $debug;
+               open(IN,"<$fn") || die "unable to open $fn:$!\n";
                my $line = "", my $def= "";
                my %tag = (
                        (map { $_ => 0 } @known_platforms),
@@ -439,14 +455,15 @@ sub do_defs
                print STDERR "DEBUG: parsing ----------\n" if $debug;
                while(<IN>) {
                        if($parens > 0) {
-                               #Inside a DECLARE_DEPRECATED
+                               #Inside a DEPRECATEDIN
                                $stored_multiline .= $_;
-                               chomp $stored_multiline;
-                               print STDERR "DEBUG: Continuing multiline DEPRECATED: $stored_multiline\n" if $debug;
+                               $stored_multiline =~ s|\R$||; # Better chomp
+                               print STDERR "DEBUG: Continuing multiline DEPRECATEDIN: $stored_multiline\n" if $debug;
                                $parens = count_parens($stored_multiline);
                                if ($parens == 0) {
-                                       $stored_multiline =~ /^\s*DECLARE_DEPRECATED\s*\(\s*(\w*(\s|\*|\w)*)/;
-                                       $def .= "$1(void);";
+                                       $def .= do_deprecated($stored_multiline,
+                                                       \@current_platforms,
+                                                       \@current_algorithms);
                                }
                                next;
                        }
@@ -461,9 +478,7 @@ sub do_defs
                        }
 
                        if (/\\$/) {
-                               chomp; # remove eol
-                               chop; # remove ending backslash
-                               $line = $_;
+                               $line = $`; # keep what was before the backslash
                                next;
                        }
 
@@ -480,8 +495,11 @@ sub do_defs
                                $cpp++ if /^#\s*if/;
                                $cpp-- if /^#\s*endif/;
                                next;
-                       }
-                       $cpp = 1 if /^#.*ifdef.*cplusplus/;
+                       }
+                       if (/^#.*ifdef.*cplusplus/) {
+                               $cpp = 1;
+                               next;
+                       }
 
                        s/{[^{}]*}//gs;                      # ignore {} blocks
                        print STDERR "DEBUG: \$def=\"$def\"\n" if $debug && $def ne "";
@@ -568,6 +586,7 @@ sub do_defs
                                pop(@tag);
                        } elsif (/^\#\s*else/) {
                                my $tag_i = $#tag;
+                               die "$file unmatched else\n" if $tag_i < 0;
                                while($tag[$tag_i] ne "-") {
                                        my $t=$tag[$tag_i];
                                        $tag{$t}= -$tag{$t};
@@ -586,6 +605,9 @@ sub do_defs
                                push(@tag,"TRUE");
                                $tag{"TRUE"}=-1;
                                print STDERR "DEBUG: $file: found 0\n" if $debug;
+                       } elsif (/^\#\s*if\s+/) {
+                               #Some other unrecognized "if" style
+                               push(@tag,"-");
                        } elsif (/^\#\s*define\s+(\w+)\s+(\w+)/
                                 && $symhacking && $tag{'TRUE'} != -1) {
                                # This is for aliasing.  When we find an alias,
@@ -620,7 +642,8 @@ sub do_defs
                                next;
                        }
                        if ($tag{'TRUE'} != -1) {
-                               if (/^\s*DECLARE_STACK_OF\s*\(\s*(\w*)\s*\)/) {
+                               if (/^\s*DEFINE_STACK_OF\s*\(\s*(\w*)\s*\)/
+                                               || /^\s*DEFINE_STACK_OF_CONST\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);";
@@ -840,14 +863,16 @@ sub do_defs
                                        &$make_variant("_shadow_$2","_shadow_$2",
                                                      "EXPORT_VAR_AS_FUNCTION",
                                                      "FUNCTION");
-                               } elsif (/^\s*DECLARE_DEPRECATED\s*\(\s*(\w*(\s|\*|\w)*)/) {
+                               } elsif (/^\s*DEPRECATEDIN/) {
                                        $parens = count_parens($_);
                                        if ($parens == 0) {
-                                               $def .= "$1(void);";
+                                               $def .= do_deprecated($_,
+                                                       \@current_platforms,
+                                                       \@current_algorithms);
                                        } else {
                                                $stored_multiline = $_;
-                                               chomp $stored_multiline;
-                                               print STDERR "DEBUG: Found multiline DEPRECATED starting with: $stored_multiline\n" if $debug;
+                                               $stored_multiline =~ s|\R$||;
+                                               print STDERR "DEBUG: Found multiline DEPRECATEDIN starting with: $stored_multiline\n" if $debug;
                                                next;
                                        }
                                } elsif ($tag{'CONST_STRICT'} != 1) {
@@ -860,6 +885,7 @@ sub do_defs
                        }
                }
                close(IN);
+               die "$file: Unmatched tags\n" if $#tag >= 0;
 
                my $algs;
                my $plays;
@@ -912,21 +938,6 @@ sub do_defs
 
                        $p = $plats;
                        $a = $algs;
-                       $a .= ",BF" if($s =~ /EVP_bf/);
-                       $a .= ",CAST" if($s =~ /EVP_cast/);
-                       $a .= ",DES" if($s =~ /EVP_des/);
-                       $a .= ",DSA" if($s =~ /EVP_dss/);
-                       $a .= ",IDEA" if($s =~ /EVP_idea/);
-                       $a .= ",MD2" if($s =~ /EVP_md2/);
-                       $a .= ",MD4" if($s =~ /EVP_md4/);
-                       $a .= ",MD5" if($s =~ /EVP_md5/);
-                       $a .= ",RC2" if($s =~ /EVP_rc2/);
-                       $a .= ",RC4" if($s =~ /EVP_rc4/);
-                       $a .= ",RC5" if($s =~ /EVP_rc5/);
-                       $a .= ",RMD160" if($s =~ /EVP_ripemd/);
-                       $a .= ",RSA" if($s =~ /EVP_(Open|Seal)(Final|Init)/);
-                       $a .= ",RSA" if($s =~ /RSAPrivateKey/);
-                       $a .= ",RSA" if($s =~ /SSLv23?_((client|server)_)?method/);
 
                        $platform{$s} =
                            &reduce_platforms((defined($platform{$s})?$platform{$s}.',':"").$p);
@@ -1024,7 +1035,8 @@ sub reduce_platforms
        return $ret;
 }
 
-sub info_string {
+sub info_string
+{
        (my $symbol, my $exist, my $platforms, my $kind, my $algorithms) = @_;
 
        my %a = defined($algorithms) ?
@@ -1042,13 +1054,13 @@ sub info_string {
        return $ret;
 }
 
-sub maybe_add_info {
+sub maybe_add_info
+{
        (my $name, *nums, my @symbols) = @_;
        my $sym;
        my $new_info = 0;
        my %syms=();
 
-       print STDERR "Updating $name info\n";
        foreach $sym (@symbols) {
                (my $s, my $i) = split /\\/, $sym;
                if (defined($nums{$s})) {
@@ -1072,12 +1084,11 @@ sub maybe_add_info {
                }
        }
        if ($new_info) {
-               print STDERR "$new_info old symbols got an info update\n";
+               print STDERR "$name: $new_info old symbols have updated info\n";
                if (!$do_rewrite) {
                        print STDERR "You should do a rewrite to fix this.\n";
                }
        } else {
-               print STDERR "No old symbols needed info update\n";
        }
 }
 
@@ -1167,15 +1178,9 @@ sub print_test_file
        }
 }
 
-sub get_version {
-   local *MF;
-   my $v = '?';
-   open MF, 'Makefile' or return $v;
-   while (<MF>) {
-     $v = $1, last if /^VERSION=(.*?)\s*$/;
-   }
-   close MF;
-   return $v;
+sub get_version
+{
+   return $config{version};
 }
 
 sub print_def_file
@@ -1191,7 +1196,7 @@ sub print_def_file
        my $prevsymversion = "", $prevprevsymversion = "";
         # For VMS
         my $prevnum = 0;
-        my $symbolcount = 0;
+        my $symvtextcount = 0;
 
        if ($W32)
                { $libname.="32"; }
@@ -1225,13 +1230,11 @@ EOF
                 }
         elsif ($VMS)
                 {
-                my $libref = $name eq "ssl" ? "LIBCRYPTO.EXE /SHARE" : "";
                 print OUT <<"EOF";
-IDENTIFICATION="LIB$libname V$version"
-LIB$libname.OLB /LIBRARY
-$libref
+CASE_SENSITIVE=YES
 SYMBOL_VECTOR=(-
 EOF
+                $symvtextcount = 16; # length of "SYMBOL_VECTOR=(-"
                 }
 
        (@r)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:FUNCTION/,@symbols);
@@ -1295,25 +1298,35 @@ EOF
                                                print OUT "        $s2;\n";
                                         } elsif ($VMS) {
                                             while(++$prevnum < $n) {
-                                                if ($symbolcount > 1023) {
+                                                my $symline=" ,SPARE -\n  ,SPARE -\n";
+                                                if ($symvtextcount + length($symline) - 2 > 1024) {
                                                     print OUT ")\nSYMBOL_VECTOR=(-\n";
-                                                    $symbolcount = 0;
+                                                    $symvtextcount = 16; # length of "SYMBOL_VECTOR=(-"
+                                                }
+                                                if ($symvtextcount == 16) {
+                                                    # Take away first comma
+                                                    $symline =~ s/,//;
                                                 }
-                                                print OUT $symbolcount
-                                                    ? "    ," : "    ";
-                                                print OUT "dummy$prevnum=PRIVATE_PROCEDURE -\n";
-                                                $symbolcount++;
+                                                print OUT $symline;
+                                                $symvtextcount += length($symline) - 2;
                                             }
                                             (my $s_uc = $s) =~ tr/a-z/A-Z/;
-                                            if ($symbolcount > 1023) {
+                                            my $symtype=
+                                                $v ? "DATA" : "PROCEDURE";
+                                            my $symline=
+                                                ($s_uc ne $s
+                                                 ? " ,$s_uc/$s=$symtype -\n  ,$s=$symtype -\n"
+                                                 : " ,$s=$symtype -\n  ,SPARE -\n");
+                                            if ($symvtextcount + length($symline) - 2 > 1024) {
                                                 print OUT ")\nSYMBOL_VECTOR=(-\n";
-                                                $symbolcount = 0;
+                                                $symvtextcount = 16; # length of "SYMBOL_VECTOR=(-"
                                             }
-                                            print OUT $symbolcount
-                                                ? "    ," : "    ";
-                                            print OUT "$s_uc/$s="
-                                                , ($v ? "DATA" : "PROCEDURE"), " -\n";
-                                            $symbolcount++;
+                                            if ($symvtextcount == 16) {
+                                                # Take away first comma
+                                                $symline =~ s/,//;
+                                            }
+                                            print OUT $symline;
+                                            $symvtextcount += length($symline) - 2;
                                        } elsif($v && !$OS2) {
                                                printf OUT "    %s%-39s @%-8d DATA\n",
                                                                ($W32)?"":"_",$s2,$n;
@@ -1357,7 +1370,7 @@ sub load_numbers
 
        open(IN,"<$name") || die "unable to open $name:$!\n";
        while (<IN>) {
-               chop;
+               s|\R$||;        # Better chomp
                s/#.*$//;
                next if /^\s*$/;
                @a=split;
@@ -1423,8 +1436,6 @@ sub rewrite_numbers
        (*OUT,$name,*nums,@symbols)=@_;
        my $thing;
 
-       print STDERR "Rewriting $name\n";
-
        my @r = grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:\w+\(\w+\)/,@symbols);
        my $r; my %r; my %rsyms;
        foreach $r (@r) {
@@ -1473,8 +1484,6 @@ sub update_numbers
 
        ($basevers, $vers) = get_openssl_version();
 
-       print STDERR "Updating $name numbers\n";
-
        my @r = grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:\w+\(\w+\)/,@symbols);
        my $r; my %r; my %rsyms;
        foreach $r (@r) {
@@ -1504,9 +1513,9 @@ sub update_numbers
                }
        }
        if($new_syms) {
-               print STDERR "$new_syms New symbols added\n";
+               print STDERR "$name: Added $new_syms new symbols\n";
        } else {
-               print STDERR "No New symbols Added\n";
+               print STDERR "$name: No new symbols added\n";
        }
 }
 
@@ -1547,12 +1556,13 @@ sub count_parens
 #version
 sub get_openssl_version()
 {
-       open (IN, "include/openssl/opensslv.h") || die "Can't open opensslv.h";
+       my $fn = catfile($config{sourcedir},"include","openssl","opensslv.h");
+       open (IN, "$fn") || die "Can't open opensslv.h";
 
        while(<IN>) {
                if (/OPENSSL_VERSION_TEXT\s+"OpenSSL (\d\.\d\.)(\d[a-z]*)(-| )/) {
                        my $suffix = $2;
-                       my $baseversion = $1 =~ s/\./_/gr;
+                       (my $baseversion = $1) =~ s/\./_/g;
                        close IN;
                        return ($baseversion."0", $baseversion.$suffix);
                }
@@ -1672,3 +1682,16 @@ sub check_version_lte()
                        if (($cvbase ne $tvbase) && ($tvletter gt $cvletter));
        }
 }
+
+sub do_deprecated()
+{
+       my ($decl, $plats, $algs) = @_;
+       $decl =~ /^\s*(DEPRECATEDIN_\d+_\d+_\d+)\s*\((.*)\)\s*$/
+            or die "Bad DEPRECTEDIN: $decl\n";
+       my $info1 .= "#INFO:";
+       $info1 .= join(',', @{$plats}) . ":";
+       my $info2 = $info1;
+       $info1 .= join(',',@{$algs}, $1) . ";";
+       $info2 .= join(',',@{$algs}) . ";";
+       return $info1 . $2 . ";" . $info2;
+}