mbed TLS upgraded to 2.6.0
Fork of mbedtls by
scripts/generate_errors.pl@2:bbdeda018a3c, 2017-09-29 (annotated)
- Committer:
- Jasper Wallace
- Date:
- Fri Sep 29 19:50:30 2017 +0100
- Revision:
- 2:bbdeda018a3c
- Parent:
- 1:9ebc941037d5
Update to mbedtls 2.6.0, many changes.
Changes to mbedtls sources made:
in include/mbedtls/config.h comment out:
#define MBEDTLS_FS_IO
#define MBEDTLS_NET_C
#define MBEDTLS_TIMING_C
uncomment:
#define MBEDTLS_NO_PLATFORM_ENTROPY
remove the following directorys:
programs
yotta
visualc
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Jasper Wallace |
1:9ebc941037d5 | 1 | #!/usr/bin/perl |
Jasper Wallace |
1:9ebc941037d5 | 2 | |
Jasper Wallace |
1:9ebc941037d5 | 3 | # Generate error.c |
Jasper Wallace |
1:9ebc941037d5 | 4 | # |
Jasper Wallace |
1:9ebc941037d5 | 5 | # Usage: ./generate_errors.pl or scripts/generate_errors.pl without arguments, |
Jasper Wallace |
1:9ebc941037d5 | 6 | # or generate_errors.pl include_dir data_dir error_file |
Jasper Wallace |
1:9ebc941037d5 | 7 | |
Jasper Wallace |
1:9ebc941037d5 | 8 | use strict; |
Jasper Wallace |
1:9ebc941037d5 | 9 | |
Jasper Wallace |
1:9ebc941037d5 | 10 | my ($include_dir, $data_dir, $error_file); |
Jasper Wallace |
1:9ebc941037d5 | 11 | |
Jasper Wallace |
1:9ebc941037d5 | 12 | if( @ARGV ) { |
Jasper Wallace |
1:9ebc941037d5 | 13 | die "Invalid number of arguments" if scalar @ARGV != 3; |
Jasper Wallace |
1:9ebc941037d5 | 14 | ($include_dir, $data_dir, $error_file) = @ARGV; |
Jasper Wallace |
1:9ebc941037d5 | 15 | |
Jasper Wallace |
1:9ebc941037d5 | 16 | -d $include_dir or die "No such directory: $include_dir\n"; |
Jasper Wallace |
1:9ebc941037d5 | 17 | -d $data_dir or die "No such directory: $data_dir\n"; |
Jasper Wallace |
1:9ebc941037d5 | 18 | } else { |
Jasper Wallace |
1:9ebc941037d5 | 19 | $include_dir = 'include/mbedtls'; |
Jasper Wallace |
1:9ebc941037d5 | 20 | $data_dir = 'scripts/data_files'; |
Jasper Wallace |
1:9ebc941037d5 | 21 | $error_file = 'library/error.c'; |
Jasper Wallace |
1:9ebc941037d5 | 22 | |
Jasper Wallace |
1:9ebc941037d5 | 23 | unless( -d $include_dir && -d $data_dir ) { |
Jasper Wallace |
1:9ebc941037d5 | 24 | chdir '..' or die; |
Jasper Wallace |
1:9ebc941037d5 | 25 | -d $include_dir && -d $data_dir |
Jasper Wallace |
1:9ebc941037d5 | 26 | or die "Without arguments, must be run from root or scripts\n" |
Jasper Wallace |
1:9ebc941037d5 | 27 | } |
Jasper Wallace |
1:9ebc941037d5 | 28 | } |
Jasper Wallace |
1:9ebc941037d5 | 29 | |
Jasper Wallace |
1:9ebc941037d5 | 30 | my $error_format_file = $data_dir.'/error.fmt'; |
Jasper Wallace |
1:9ebc941037d5 | 31 | |
Jasper Wallace |
1:9ebc941037d5 | 32 | my @low_level_modules = ( "AES", "ASN1", "BLOWFISH", "CAMELLIA", "BIGNUM", |
Jasper Wallace |
1:9ebc941037d5 | 33 | "BASE64", "XTEA", "PBKDF2", "OID", |
Jasper Wallace |
1:9ebc941037d5 | 34 | "PADLOCK", "DES", "NET", "CTR_DRBG", "ENTROPY", |
Jasper Wallace |
1:9ebc941037d5 | 35 | "HMAC_DRBG", "MD2", "MD4", "MD5", "RIPEMD160", |
Jasper Wallace |
1:9ebc941037d5 | 36 | "SHA1", "SHA256", "SHA512", "GCM", "THREADING", "CCM" ); |
Jasper Wallace |
1:9ebc941037d5 | 37 | my @high_level_modules = ( "PEM", "X509", "DHM", "RSA", "ECP", "MD", "CIPHER", "SSL", |
Jasper Wallace |
1:9ebc941037d5 | 38 | "PK", "PKCS12", "PKCS5" ); |
Jasper Wallace |
1:9ebc941037d5 | 39 | |
Jasper Wallace |
1:9ebc941037d5 | 40 | my $line_separator = $/; |
Jasper Wallace |
1:9ebc941037d5 | 41 | undef $/; |
Jasper Wallace |
1:9ebc941037d5 | 42 | |
Jasper Wallace |
1:9ebc941037d5 | 43 | open(FORMAT_FILE, "$error_format_file") or die "Opening error format file '$error_format_file': $!"; |
Jasper Wallace |
1:9ebc941037d5 | 44 | my $error_format = <FORMAT_FILE>; |
Jasper Wallace |
1:9ebc941037d5 | 45 | close(FORMAT_FILE); |
Jasper Wallace |
1:9ebc941037d5 | 46 | |
Jasper Wallace |
1:9ebc941037d5 | 47 | $/ = $line_separator; |
Jasper Wallace |
1:9ebc941037d5 | 48 | |
Jasper Wallace |
1:9ebc941037d5 | 49 | open(GREP, "grep \"define MBEDTLS_ERR_\" $include_dir/* |") || die("Failure when calling grep: $!"); |
Jasper Wallace |
1:9ebc941037d5 | 50 | |
Jasper Wallace |
1:9ebc941037d5 | 51 | my $ll_old_define = ""; |
Jasper Wallace |
1:9ebc941037d5 | 52 | my $hl_old_define = ""; |
Jasper Wallace |
1:9ebc941037d5 | 53 | |
Jasper Wallace |
1:9ebc941037d5 | 54 | my $ll_code_check = ""; |
Jasper Wallace |
1:9ebc941037d5 | 55 | my $hl_code_check = ""; |
Jasper Wallace |
1:9ebc941037d5 | 56 | |
Jasper Wallace |
1:9ebc941037d5 | 57 | my $headers = ""; |
Jasper Wallace |
1:9ebc941037d5 | 58 | |
Jasper Wallace |
1:9ebc941037d5 | 59 | my %error_codes_seen; |
Jasper Wallace |
1:9ebc941037d5 | 60 | |
Jasper Wallace |
1:9ebc941037d5 | 61 | while (my $line = <GREP>) |
Jasper Wallace |
1:9ebc941037d5 | 62 | { |
Jasper Wallace |
1:9ebc941037d5 | 63 | next if ($line =~ /compat-1.2.h/); |
Jasper Wallace |
1:9ebc941037d5 | 64 | my ($error_name, $error_code) = $line =~ /(MBEDTLS_ERR_\w+)\s+\-(0x\w+)/; |
Jasper Wallace |
1:9ebc941037d5 | 65 | my ($description) = $line =~ /\/\*\*< (.*?)\.? \*\//; |
Jasper Wallace |
1:9ebc941037d5 | 66 | |
Jasper Wallace |
1:9ebc941037d5 | 67 | die "Duplicated error code: $error_code ($error_name)\n" |
Jasper Wallace |
1:9ebc941037d5 | 68 | if( $error_codes_seen{$error_code}++ ); |
Jasper Wallace |
1:9ebc941037d5 | 69 | |
Jasper Wallace |
1:9ebc941037d5 | 70 | $description =~ s/\\/\\\\/g; |
Jasper Wallace |
1:9ebc941037d5 | 71 | if ($description eq "") { |
Jasper Wallace |
1:9ebc941037d5 | 72 | $description = "DESCRIPTION MISSING"; |
Jasper Wallace |
1:9ebc941037d5 | 73 | warn "Missing description for $error_name\n"; |
Jasper Wallace |
1:9ebc941037d5 | 74 | } |
Jasper Wallace |
1:9ebc941037d5 | 75 | |
Jasper Wallace |
1:9ebc941037d5 | 76 | my ($module_name) = $error_name =~ /^MBEDTLS_ERR_([^_]+)/; |
Jasper Wallace |
1:9ebc941037d5 | 77 | |
Jasper Wallace |
1:9ebc941037d5 | 78 | # Fix faulty ones |
Jasper Wallace |
1:9ebc941037d5 | 79 | $module_name = "BIGNUM" if ($module_name eq "MPI"); |
Jasper Wallace |
1:9ebc941037d5 | 80 | $module_name = "CTR_DRBG" if ($module_name eq "CTR"); |
Jasper Wallace |
1:9ebc941037d5 | 81 | $module_name = "HMAC_DRBG" if ($module_name eq "HMAC"); |
Jasper Wallace |
1:9ebc941037d5 | 82 | |
Jasper Wallace |
1:9ebc941037d5 | 83 | my $define_name = $module_name; |
Jasper Wallace |
1:9ebc941037d5 | 84 | $define_name = "X509_USE,X509_CREATE" if ($define_name eq "X509"); |
Jasper Wallace |
1:9ebc941037d5 | 85 | $define_name = "ASN1_PARSE" if ($define_name eq "ASN1"); |
Jasper Wallace |
1:9ebc941037d5 | 86 | $define_name = "SSL_TLS" if ($define_name eq "SSL"); |
Jasper Wallace |
1:9ebc941037d5 | 87 | $define_name = "PEM_PARSE,PEM_WRITE" if ($define_name eq "PEM"); |
Jasper Wallace |
1:9ebc941037d5 | 88 | |
Jasper Wallace |
1:9ebc941037d5 | 89 | my $include_name = $module_name; |
Jasper Wallace |
1:9ebc941037d5 | 90 | $include_name =~ tr/A-Z/a-z/; |
Jasper Wallace |
1:9ebc941037d5 | 91 | $include_name = "" if ($include_name eq "asn1"); |
Jasper Wallace |
1:9ebc941037d5 | 92 | |
Jasper Wallace |
1:9ebc941037d5 | 93 | # Fix faulty ones |
Jasper Wallace |
1:9ebc941037d5 | 94 | $include_name = "net_sockets" if ($module_name eq "NET"); |
Jasper Wallace |
1:9ebc941037d5 | 95 | |
Jasper Wallace |
1:9ebc941037d5 | 96 | my $found_ll = grep $_ eq $module_name, @low_level_modules; |
Jasper Wallace |
1:9ebc941037d5 | 97 | my $found_hl = grep $_ eq $module_name, @high_level_modules; |
Jasper Wallace |
1:9ebc941037d5 | 98 | if (!$found_ll && !$found_hl) |
Jasper Wallace |
1:9ebc941037d5 | 99 | { |
Jasper Wallace |
1:9ebc941037d5 | 100 | printf("Error: Do not know how to handle: $module_name\n"); |
Jasper Wallace |
1:9ebc941037d5 | 101 | exit 1; |
Jasper Wallace |
1:9ebc941037d5 | 102 | } |
Jasper Wallace |
1:9ebc941037d5 | 103 | |
Jasper Wallace |
1:9ebc941037d5 | 104 | my $code_check; |
Jasper Wallace |
1:9ebc941037d5 | 105 | my $old_define; |
Jasper Wallace |
1:9ebc941037d5 | 106 | my $white_space; |
Jasper Wallace |
1:9ebc941037d5 | 107 | my $first; |
Jasper Wallace |
1:9ebc941037d5 | 108 | |
Jasper Wallace |
1:9ebc941037d5 | 109 | if ($found_ll) |
Jasper Wallace |
1:9ebc941037d5 | 110 | { |
Jasper Wallace |
1:9ebc941037d5 | 111 | $code_check = \$ll_code_check; |
Jasper Wallace |
1:9ebc941037d5 | 112 | $old_define = \$ll_old_define; |
Jasper Wallace |
1:9ebc941037d5 | 113 | $white_space = ' '; |
Jasper Wallace |
1:9ebc941037d5 | 114 | } |
Jasper Wallace |
1:9ebc941037d5 | 115 | else |
Jasper Wallace |
1:9ebc941037d5 | 116 | { |
Jasper Wallace |
1:9ebc941037d5 | 117 | $code_check = \$hl_code_check; |
Jasper Wallace |
1:9ebc941037d5 | 118 | $old_define = \$hl_old_define; |
Jasper Wallace |
1:9ebc941037d5 | 119 | $white_space = ' '; |
Jasper Wallace |
1:9ebc941037d5 | 120 | } |
Jasper Wallace |
1:9ebc941037d5 | 121 | |
Jasper Wallace |
1:9ebc941037d5 | 122 | if ($define_name ne ${$old_define}) |
Jasper Wallace |
1:9ebc941037d5 | 123 | { |
Jasper Wallace |
1:9ebc941037d5 | 124 | if (${$old_define} ne "") |
Jasper Wallace |
1:9ebc941037d5 | 125 | { |
Jasper Wallace |
1:9ebc941037d5 | 126 | ${$code_check} .= "#endif /* "; |
Jasper Wallace |
1:9ebc941037d5 | 127 | $first = 0; |
Jasper Wallace |
1:9ebc941037d5 | 128 | foreach my $dep (split(/,/, ${$old_define})) |
Jasper Wallace |
1:9ebc941037d5 | 129 | { |
Jasper Wallace |
1:9ebc941037d5 | 130 | ${$code_check} .= " || " if ($first++); |
Jasper Wallace |
1:9ebc941037d5 | 131 | ${$code_check} .= "MBEDTLS_${dep}_C"; |
Jasper Wallace |
1:9ebc941037d5 | 132 | } |
Jasper Wallace |
1:9ebc941037d5 | 133 | ${$code_check} .= " */\n\n"; |
Jasper Wallace |
1:9ebc941037d5 | 134 | } |
Jasper Wallace |
1:9ebc941037d5 | 135 | |
Jasper Wallace |
1:9ebc941037d5 | 136 | ${$code_check} .= "#if "; |
Jasper Wallace |
1:9ebc941037d5 | 137 | $headers .= "#if " if ($include_name ne ""); |
Jasper Wallace |
1:9ebc941037d5 | 138 | $first = 0; |
Jasper Wallace |
1:9ebc941037d5 | 139 | foreach my $dep (split(/,/, ${define_name})) |
Jasper Wallace |
1:9ebc941037d5 | 140 | { |
Jasper Wallace |
1:9ebc941037d5 | 141 | ${$code_check} .= " || " if ($first); |
Jasper Wallace |
1:9ebc941037d5 | 142 | $headers .= " || " if ($first++); |
Jasper Wallace |
1:9ebc941037d5 | 143 | |
Jasper Wallace |
1:9ebc941037d5 | 144 | ${$code_check} .= "defined(MBEDTLS_${dep}_C)"; |
Jasper Wallace |
1:9ebc941037d5 | 145 | $headers .= "defined(MBEDTLS_${dep}_C)" if |
Jasper Wallace |
1:9ebc941037d5 | 146 | ($include_name ne ""); |
Jasper Wallace |
1:9ebc941037d5 | 147 | } |
Jasper Wallace |
1:9ebc941037d5 | 148 | ${$code_check} .= "\n"; |
Jasper Wallace |
1:9ebc941037d5 | 149 | $headers .= "\n#include \"mbedtls/${include_name}.h\"\n". |
Jasper Wallace |
1:9ebc941037d5 | 150 | "#endif\n\n" if ($include_name ne ""); |
Jasper Wallace |
1:9ebc941037d5 | 151 | ${$old_define} = $define_name; |
Jasper Wallace |
1:9ebc941037d5 | 152 | } |
Jasper Wallace |
1:9ebc941037d5 | 153 | |
Jasper Wallace |
1:9ebc941037d5 | 154 | if ($error_name eq "MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE") |
Jasper Wallace |
1:9ebc941037d5 | 155 | { |
Jasper Wallace |
1:9ebc941037d5 | 156 | ${$code_check} .= "${white_space}if( use_ret == -($error_name) )\n". |
Jasper Wallace |
1:9ebc941037d5 | 157 | "${white_space}\{\n". |
Jasper Wallace |
1:9ebc941037d5 | 158 | "${white_space} mbedtls_snprintf( buf, buflen, \"$module_name - $description\" );\n". |
Jasper Wallace |
1:9ebc941037d5 | 159 | "${white_space} return;\n". |
Jasper Wallace |
1:9ebc941037d5 | 160 | "${white_space}}\n" |
Jasper Wallace |
1:9ebc941037d5 | 161 | } |
Jasper Wallace |
1:9ebc941037d5 | 162 | else |
Jasper Wallace |
1:9ebc941037d5 | 163 | { |
Jasper Wallace |
1:9ebc941037d5 | 164 | ${$code_check} .= "${white_space}if( use_ret == -($error_name) )\n". |
Jasper Wallace |
1:9ebc941037d5 | 165 | "${white_space} mbedtls_snprintf( buf, buflen, \"$module_name - $description\" );\n" |
Jasper Wallace |
1:9ebc941037d5 | 166 | } |
Jasper Wallace |
1:9ebc941037d5 | 167 | }; |
Jasper Wallace |
1:9ebc941037d5 | 168 | |
Jasper Wallace |
1:9ebc941037d5 | 169 | if ($ll_old_define ne "") |
Jasper Wallace |
1:9ebc941037d5 | 170 | { |
Jasper Wallace |
1:9ebc941037d5 | 171 | $ll_code_check .= "#endif /* "; |
Jasper Wallace |
1:9ebc941037d5 | 172 | my $first = 0; |
Jasper Wallace |
1:9ebc941037d5 | 173 | foreach my $dep (split(/,/, $ll_old_define)) |
Jasper Wallace |
1:9ebc941037d5 | 174 | { |
Jasper Wallace |
1:9ebc941037d5 | 175 | $ll_code_check .= " || " if ($first++); |
Jasper Wallace |
1:9ebc941037d5 | 176 | $ll_code_check .= "MBEDTLS_${dep}_C"; |
Jasper Wallace |
1:9ebc941037d5 | 177 | } |
Jasper Wallace |
1:9ebc941037d5 | 178 | $ll_code_check .= " */\n"; |
Jasper Wallace |
1:9ebc941037d5 | 179 | } |
Jasper Wallace |
1:9ebc941037d5 | 180 | if ($hl_old_define ne "") |
Jasper Wallace |
1:9ebc941037d5 | 181 | { |
Jasper Wallace |
1:9ebc941037d5 | 182 | $hl_code_check .= "#endif /* "; |
Jasper Wallace |
1:9ebc941037d5 | 183 | my $first = 0; |
Jasper Wallace |
1:9ebc941037d5 | 184 | foreach my $dep (split(/,/, $hl_old_define)) |
Jasper Wallace |
1:9ebc941037d5 | 185 | { |
Jasper Wallace |
1:9ebc941037d5 | 186 | $hl_code_check .= " || " if ($first++); |
Jasper Wallace |
1:9ebc941037d5 | 187 | $hl_code_check .= "MBEDTLS_${dep}_C"; |
Jasper Wallace |
1:9ebc941037d5 | 188 | } |
Jasper Wallace |
1:9ebc941037d5 | 189 | $hl_code_check .= " */\n"; |
Jasper Wallace |
1:9ebc941037d5 | 190 | } |
Jasper Wallace |
1:9ebc941037d5 | 191 | |
Jasper Wallace |
1:9ebc941037d5 | 192 | $error_format =~ s/HEADER_INCLUDED\n/$headers/g; |
Jasper Wallace |
1:9ebc941037d5 | 193 | $error_format =~ s/LOW_LEVEL_CODE_CHECKS\n/$ll_code_check/g; |
Jasper Wallace |
1:9ebc941037d5 | 194 | $error_format =~ s/HIGH_LEVEL_CODE_CHECKS\n/$hl_code_check/g; |
Jasper Wallace |
1:9ebc941037d5 | 195 | |
Jasper Wallace |
1:9ebc941037d5 | 196 | open(ERROR_FILE, ">$error_file") or die "Opening destination file '$error_file': $!"; |
Jasper Wallace |
1:9ebc941037d5 | 197 | print ERROR_FILE $error_format; |
Jasper Wallace |
1:9ebc941037d5 | 198 | close(ERROR_FILE); |