summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/util
diff options
context:
space:
mode:
authordjm <>2010-10-01 22:54:21 +0000
committerdjm <>2010-10-01 22:54:21 +0000
commit829fd51d4f8dde4a7f3bf54754f3c1d1a502f5e2 (patch)
treee03b9f1bd051e844b971936729e9df549a209130 /src/lib/libcrypto/util
parente6b755d2a53d3cac7a344dfdd6bf7c951cac754c (diff)
downloadopenbsd-829fd51d4f8dde4a7f3bf54754f3c1d1a502f5e2.tar.gz
openbsd-829fd51d4f8dde4a7f3bf54754f3c1d1a502f5e2.tar.bz2
openbsd-829fd51d4f8dde4a7f3bf54754f3c1d1a502f5e2.zip
import OpenSSL-1.0.0a
Diffstat (limited to 'src/lib/libcrypto/util')
-rw-r--r--src/lib/libcrypto/util/mkerr.pl113
-rw-r--r--src/lib/libcrypto/util/mkstack.pl74
2 files changed, 174 insertions, 13 deletions
diff --git a/src/lib/libcrypto/util/mkerr.pl b/src/lib/libcrypto/util/mkerr.pl
index 554bebb159..15b774f277 100644
--- a/src/lib/libcrypto/util/mkerr.pl
+++ b/src/lib/libcrypto/util/mkerr.pl
@@ -1,6 +1,7 @@
1#!/usr/local/bin/perl -w 1#!/usr/local/bin/perl -w
2 2
3my $config = "crypto/err/openssl.ec"; 3my $config = "crypto/err/openssl.ec";
4my $hprefix = "openssl/";
4my $debug = 0; 5my $debug = 0;
5my $rebuild = 0; 6my $rebuild = 0;
6my $static = 1; 7my $static = 1;
@@ -12,11 +13,16 @@ my $staticloader = "";
12my $pack_errcode; 13my $pack_errcode;
13my $load_errcode; 14my $load_errcode;
14 15
16my $errcount;
17
15while (@ARGV) { 18while (@ARGV) {
16 my $arg = $ARGV[0]; 19 my $arg = $ARGV[0];
17 if($arg eq "-conf") { 20 if($arg eq "-conf") {
18 shift @ARGV; 21 shift @ARGV;
19 $config = shift @ARGV; 22 $config = shift @ARGV;
23 } elsif($arg eq "-hprefix") {
24 shift @ARGV;
25 $hprefix = shift @ARGV;
20 } elsif($arg eq "-debug") { 26 } elsif($arg eq "-debug") {
21 $debug = 1; 27 $debug = 1;
22 shift @ARGV; 28 shift @ARGV;
@@ -38,14 +44,78 @@ while (@ARGV) {
38 } elsif($arg eq "-write") { 44 } elsif($arg eq "-write") {
39 $dowrite = 1; 45 $dowrite = 1;
40 shift @ARGV; 46 shift @ARGV;
47 } elsif($arg eq "-help" || $arg eq "-h" || $arg eq "-?" || $arg eq "--help") {
48 print STDERR <<"EOF";
49mkerr.pl [options] ...
50
51Options:
52
53 -conf F Use the config file F instead of the default one:
54 crypto/err/openssl.ec
55
56 -hprefix P Prepend the filenames in generated #include <header>
57 statements with prefix P. Default: 'openssl/' (without
58 the quotes, naturally)
59
60 -debug Turn on debugging verbose output on stderr.
61
62 -rebuild Rebuild all header and C source files, irrespective of the
63 fact if any error or function codes have been added/removed.
64 Default: only update files for libraries which saw change
65 (of course, this requires '-write' as well, or no
66 files will be touched!)
67
68 -recurse scan a preconfigured set of directories / files for error and
69 function codes:
70 (<crypto/*.c>, <crypto/*/*.c>, <ssl/*.c>, <apps/*.c>)
71 When this option is NOT specified, the filelist is taken from
72 the commandline instead. Here, wildcards may be embedded. (Be
73 sure to escape those to prevent the shell from expanding them
74 for you when you wish mkerr.pl to do so instead.)
75 Default: take file list to scan from the command line.
76
77 -reindex Discard the numeric values previously assigned to the error
78 and function codes as extracted from the scanned header files;
79 instead renumber all of them starting from 100. (Note that
80 the numbers assigned through 'R' records in the config file
81 remain intact.)
82 Default: keep previously assigned numbers. (You are warned
83 when collisions are detected.)
84
85 -nostatic Generates a different source code, where these additional
86 functions are generated for each library specified in the
87 config file:
88 void ERR_load_<LIB>_strings(void);
89 void ERR_unload_<LIB>_strings(void);
90 void ERR_<LIB>_error(int f, int r, char *fn, int ln);
91 #define <LIB>err(f,r) ERR_<LIB>_error(f,r,__FILE__,__LINE__)
92 while the code facilitates the use of these in an environment
93 where the error support routines are dynamically loaded at
94 runtime.
95 Default: 'static' code generation.
96
97 -staticloader Prefix generated functions with the 'static' scope modifier.
98 Default: don't write any scope modifier prefix.
99
100 -write Actually (over)write the generated code to the header and C
101 source files as assigned to each library through the config
102 file.
103 Default: don't write.
104
105 -help / -h / -? / --help Show this help text.
106
107 ... Additional arguments are added to the file list to scan,
108 assuming '-recurse' was NOT specified on the command line.
109
110EOF
111 exit 1;
41 } else { 112 } else {
42 last; 113 last;
43 } 114 }
44} 115}
45 116
46if($recurse) { 117if($recurse) {
47 @source = ( <crypto/*.c>, <crypto/*/*.c>, <ssl/*.c>, 118 @source = (<crypto/*.c>, <crypto/*/*.c>, <ssl/*.c>);
48 <fips/*.c>, <fips/*/*.c>);
49} else { 119} else {
50 @source = @ARGV; 120 @source = @ARGV;
51} 121}
@@ -64,8 +134,8 @@ while(<IN>)
64 $cskip{$3} = $1; 134 $cskip{$3} = $1;
65 if($3 ne "NONE") { 135 if($3 ne "NONE") {
66 $csrc{$1} = $3; 136 $csrc{$1} = $3;
67 $fmax{$1} = 99; 137 $fmax{$1} = 100;
68 $rmax{$1} = 99; 138 $rmax{$1} = 100;
69 $fassigned{$1} = ":"; 139 $fassigned{$1} = ":";
70 $rassigned{$1} = ":"; 140 $rassigned{$1} = ":";
71 $fnew{$1} = 0; 141 $fnew{$1} = 0;
@@ -191,7 +261,8 @@ while (($hdr, $lib) = each %libinc)
191 if($1 eq "R") { 261 if($1 eq "R") {
192 $rcodes{$name} = $code; 262 $rcodes{$name} = $code;
193 if ($rassigned{$lib} =~ /:$code:/) { 263 if ($rassigned{$lib} =~ /:$code:/) {
194 print STDERR "!! ERROR: $lib reason code $code assigned twice\n"; 264 print STDERR "!! ERROR: $lib reason code $code assigned twice (collision at $name)\n";
265 ++$errcount;
195 } 266 }
196 $rassigned{$lib} .= "$code:"; 267 $rassigned{$lib} .= "$code:";
197 if(!(exists $rextra{$name}) && 268 if(!(exists $rextra{$name}) &&
@@ -200,7 +271,8 @@ while (($hdr, $lib) = each %libinc)
200 } 271 }
201 } else { 272 } else {
202 if ($fassigned{$lib} =~ /:$code:/) { 273 if ($fassigned{$lib} =~ /:$code:/) {
203 print STDERR "!! ERROR: $lib function code $code assigned twice\n"; 274 print STDERR "!! ERROR: $lib function code $code assigned twice (collision at $name)\n";
275 ++$errcount;
204 } 276 }
205 $fassigned{$lib} .= "$code:"; 277 $fassigned{$lib} .= "$code:";
206 if($code > $fmax{$lib}) { 278 if($code > $fmax{$lib}) {
@@ -231,6 +303,7 @@ while (($hdr, $lib) = each %libinc)
231 if ($rmax{$lib} >= 1000) { 303 if ($rmax{$lib} >= 1000) {
232 print STDERR "!! ERROR: SSL error codes 1000+ are reserved for alerts.\n"; 304 print STDERR "!! ERROR: SSL error codes 1000+ are reserved for alerts.\n";
233 print STDERR "!! Any new alerts must be added to $config.\n"; 305 print STDERR "!! Any new alerts must be added to $config.\n";
306 ++$errcount;
234 print STDERR "\n"; 307 print STDERR "\n";
235 } 308 }
236 } 309 }
@@ -255,6 +328,9 @@ foreach $file (@source) {
255 print STDERR "File loaded: ".$file."\r" if $debug; 328 print STDERR "File loaded: ".$file."\r" if $debug;
256 open(IN, "<$file") || die "Can't open source file $file\n"; 329 open(IN, "<$file") || die "Can't open source file $file\n";
257 while(<IN>) { 330 while(<IN>) {
331 # skip obsoleted source files entirely!
332 last if(/^#error\s+obsolete/);
333
258 if(/(([A-Z0-9]+)_F_([A-Z0-9_]+))/) { 334 if(/(([A-Z0-9]+)_F_([A-Z0-9_]+))/) {
259 next unless exists $csrc{$2}; 335 next unless exists $csrc{$2};
260 next if($1 eq "BIO_F_BUFFER_CTX"); 336 next if($1 eq "BIO_F_BUFFER_CTX");
@@ -264,6 +340,7 @@ foreach $file (@source) {
264 $fnew{$2}++; 340 $fnew{$2}++;
265 } 341 }
266 $notrans{$1} = 1 unless exists $ftrans{$3}; 342 $notrans{$1} = 1 unless exists $ftrans{$3};
343 print STDERR "Function: $1\t= $fcodes{$1} (lib: $2, name: $3)\n" if $debug;
267 } 344 }
268 if(/(([A-Z0-9]+)_R_[A-Z0-9_]+)/) { 345 if(/(([A-Z0-9]+)_R_[A-Z0-9_]+)/) {
269 next unless exists $csrc{$2}; 346 next unless exists $csrc{$2};
@@ -272,6 +349,7 @@ foreach $file (@source) {
272 $rcodes{$1} = "X"; 349 $rcodes{$1} = "X";
273 $rnew{$2}++; 350 $rnew{$2}++;
274 } 351 }
352 print STDERR "Reason: $1\t= $rcodes{$1} (lib: $2)\n" if $debug;
275 } 353 }
276 } 354 }
277 close IN; 355 close IN;
@@ -313,7 +391,7 @@ foreach $lib (keys %csrc)
313 } else { 391 } else {
314 push @out, 392 push @out,
315"/* ====================================================================\n", 393"/* ====================================================================\n",
316" * Copyright (c) 2001-2008 The OpenSSL Project. All rights reserved.\n", 394" * Copyright (c) 2001-2010 The OpenSSL Project. All rights reserved.\n",
317" *\n", 395" *\n",
318" * Redistribution and use in source and binary forms, with or without\n", 396" * Redistribution and use in source and binary forms, with or without\n",
319" * modification, are permitted provided that the following conditions\n", 397" * modification, are permitted provided that the following conditions\n",
@@ -369,6 +447,10 @@ foreach $lib (keys %csrc)
369"#ifndef HEADER_${lib}_ERR_H\n", 447"#ifndef HEADER_${lib}_ERR_H\n",
370"#define HEADER_${lib}_ERR_H\n", 448"#define HEADER_${lib}_ERR_H\n",
371"\n", 449"\n",
450"#ifdef __cplusplus\n",
451"extern \"C\" {\n",
452"#endif\n",
453"\n",
372"/* BEGIN ERROR CODES */\n"; 454"/* BEGIN ERROR CODES */\n";
373 } 455 }
374 open (OUT, ">$hfile") || die "Can't Open File $hfile for writing\n"; 456 open (OUT, ">$hfile") || die "Can't Open File $hfile for writing\n";
@@ -455,14 +537,21 @@ EOF
455 if (/\b(${lib}_R_\w*)\b.*\"(.*)\"/) { 537 if (/\b(${lib}_R_\w*)\b.*\"(.*)\"/) {
456 $err_reason_strings{$1} = $2; 538 $err_reason_strings{$1} = $2;
457 } 539 }
540 if (/\b${lib}_F_(\w*)\b.*\"(.*)\"/) {
541 if (!exists $ftrans{$1} && ($1 ne $2)) {
542 print STDERR "WARNING: Mismatched function string $2\n";
543 $ftrans{$1} = $2;
544 }
545 }
458 } 546 }
459 close(IN); 547 close(IN);
460 } 548 }
461 549
550
462 my $hincf; 551 my $hincf;
463 if($static) { 552 if($static) {
464 $hfile =~ /([^\/]+)$/; 553 $hfile =~ /([^\/]+)$/;
465 $hincf = "<openssl/$1>"; 554 $hincf = "<${hprefix}$1>";
466 } else { 555 } else {
467 $hincf = "\"$hfile\""; 556 $hincf = "\"$hfile\"";
468 } 557 }
@@ -487,7 +576,7 @@ EOF
487 print OUT <<"EOF"; 576 print OUT <<"EOF";
488/* $cfile */ 577/* $cfile */
489/* ==================================================================== 578/* ====================================================================
490 * Copyright (c) 1999-2008 The OpenSSL Project. All rights reserved. 579 * Copyright (c) 1999-2010 The OpenSSL Project. All rights reserved.
491 * 580 *
492 * Redistribution and use in source and binary forms, with or without 581 * Redistribution and use in source and binary forms, with or without
493 * modification, are permitted provided that the following conditions 582 * modification, are permitted provided that the following conditions
@@ -713,3 +802,9 @@ if($debug && defined(@runref) ) {
713 print STDERR "$_\n"; 802 print STDERR "$_\n";
714 } 803 }
715} 804}
805
806if($errcount) {
807 print STDERR "There were errors, failing...\n\n";
808 exit $errcount;
809}
810
diff --git a/src/lib/libcrypto/util/mkstack.pl b/src/lib/libcrypto/util/mkstack.pl
index 2a968f395f..6a43757c95 100644
--- a/src/lib/libcrypto/util/mkstack.pl
+++ b/src/lib/libcrypto/util/mkstack.pl
@@ -21,7 +21,7 @@ while (@ARGV) {
21} 21}
22 22
23 23
24@source = (<crypto/*.[ch]>, <crypto/*/*.[ch]>, <ssl/*.[ch]>); 24@source = (<crypto/*.[ch]>, <crypto/*/*.[ch]>, <ssl/*.[ch]>, <apps/*.[ch]>);
25foreach $file (@source) { 25foreach $file (@source) {
26 next if -l $file; 26 next if -l $file;
27 27
@@ -31,11 +31,19 @@ foreach $file (@source) {
31 while(<IN>) { 31 while(<IN>) {
32 if (/^DECLARE_STACK_OF\(([^)]+)\)/) { 32 if (/^DECLARE_STACK_OF\(([^)]+)\)/) {
33 push @stacklst, $1; 33 push @stacklst, $1;
34 } if (/^DECLARE_ASN1_SET_OF\(([^)]+)\)/) { 34 }
35 if (/^DECLARE_SPECIAL_STACK_OF\(([^,\s]+)\s*,\s*([^>\s]+)\)/) {
36 push @sstacklst, [$1, $2];
37 }
38 if (/^DECLARE_ASN1_SET_OF\(([^)]+)\)/) {
35 push @asn1setlst, $1; 39 push @asn1setlst, $1;
36 } if (/^DECLARE_PKCS12_STACK_OF\(([^)]+)\)/) { 40 }
41 if (/^DECLARE_PKCS12_STACK_OF\(([^)]+)\)/) {
37 push @p12stklst, $1; 42 push @p12stklst, $1;
38 } 43 }
44 if (/^DECLARE_LHASH_OF\(([^)]+)\)/) {
45 push @lhashlst, $1;
46 }
39 } 47 }
40 close(IN); 48 close(IN);
41} 49}
@@ -65,7 +73,7 @@ while(<IN>) {
65 foreach $type_thing (sort @stacklst) { 73 foreach $type_thing (sort @stacklst) {
66 $new_stackfile .= <<EOF; 74 $new_stackfile .= <<EOF;
67 75
68#define sk_${type_thing}_new(st) SKM_sk_new($type_thing, (st)) 76#define sk_${type_thing}_new(cmp) SKM_sk_new($type_thing, (cmp))
69#define sk_${type_thing}_new_null() SKM_sk_new_null($type_thing) 77#define sk_${type_thing}_new_null() SKM_sk_new_null($type_thing)
70#define sk_${type_thing}_free(st) SKM_sk_free($type_thing, (st)) 78#define sk_${type_thing}_free(st) SKM_sk_free($type_thing, (st))
71#define sk_${type_thing}_num(st) SKM_sk_num($type_thing, (st)) 79#define sk_${type_thing}_num(st) SKM_sk_num($type_thing, (st))
@@ -88,6 +96,39 @@ while(<IN>) {
88#define sk_${type_thing}_is_sorted(st) SKM_sk_is_sorted($type_thing, (st)) 96#define sk_${type_thing}_is_sorted(st) SKM_sk_is_sorted($type_thing, (st))
89EOF 97EOF
90 } 98 }
99
100 foreach $type_thing (sort @sstacklst) {
101 my $t1 = $type_thing->[0];
102 my $t2 = $type_thing->[1];
103 $new_stackfile .= <<EOF;
104
105#define sk_${t1}_new(cmp) ((STACK_OF($t1) *)sk_new(CHECKED_SK_CMP_FUNC($t2, cmp)))
106#define sk_${t1}_new_null() ((STACK_OF($t1) *)sk_new_null())
107#define sk_${t1}_push(st, val) sk_push(CHECKED_PTR_OF(STACK_OF($t1), st), CHECKED_PTR_OF($t2, val))
108#define sk_${t1}_find(st, val) sk_find(CHECKED_PTR_OF(STACK_OF($t1), st), CHECKED_PTR_OF($t2, val))
109#define sk_${t1}_value(st, i) (($t1)sk_value(CHECKED_PTR_OF(STACK_OF($t1), st), i))
110#define sk_${t1}_num(st) SKM_sk_num($t1, st)
111#define sk_${t1}_pop_free(st, free_func) sk_pop_free(CHECKED_PTR_OF(STACK_OF($t1), st), CHECKED_SK_FREE_FUNC2($t1, free_func))
112#define sk_${t1}_insert(st, val, i) sk_insert(CHECKED_PTR_OF(STACK_OF($t1), st), CHECKED_PTR_OF($t2, val), i)
113#define sk_${t1}_free(st) SKM_sk_free(${t1}, st)
114#define sk_${t1}_set(st, i, val) sk_set((_STACK *)CHECKED_PTR_OF(STACK_OF($t1), st), i, CHECKED_PTR_OF($t2, val))
115#define sk_${t1}_zero(st) SKM_sk_zero($t1, (st))
116#define sk_${t1}_unshift(st, val) sk_unshift((_STACK *)CHECKED_PTR_OF(STACK_OF($t1), st), CHECKED_PTR_OF($t2, val))
117#define sk_${t1}_find_ex(st, val) sk_find_ex((_STACK *)CHECKED_CONST_PTR_OF(STACK_OF($t1), st), CHECKED_CONST_PTR_OF($t2, val))
118#define sk_${t1}_delete(st, i) SKM_sk_delete($t1, (st), (i))
119#define sk_${t1}_delete_ptr(st, ptr) ($t1 *)sk_delete_ptr((_STACK *)CHECKED_PTR_OF(STACK_OF($t1), st), CHECKED_PTR_OF($t2, ptr))
120#define sk_${t1}_set_cmp_func(st, cmp) \\
121 ((int (*)(const $t2 * const *,const $t2 * const *)) \\
122 sk_set_cmp_func((_STACK *)CHECKED_PTR_OF(STACK_OF($t1), st), CHECKED_SK_CMP_FUNC($t2, cmp)))
123#define sk_${t1}_dup(st) SKM_sk_dup($t1, st)
124#define sk_${t1}_shift(st) SKM_sk_shift($t1, (st))
125#define sk_${t1}_pop(st) ($t2 *)sk_pop((_STACK *)CHECKED_PTR_OF(STACK_OF($t1), st))
126#define sk_${t1}_sort(st) SKM_sk_sort($t1, (st))
127#define sk_${t1}_is_sorted(st) SKM_sk_is_sorted($t1, (st))
128
129EOF
130 }
131
91 foreach $type_thing (sort @asn1setlst) { 132 foreach $type_thing (sort @asn1setlst) {
92 $new_stackfile .= <<EOF; 133 $new_stackfile .= <<EOF;
93 134
@@ -108,6 +149,31 @@ EOF
108 SKM_PKCS12_decrypt_d2i($type_thing, (algor), (d2i_func), (free_func), (pass), (passlen), (oct), (seq)) 149 SKM_PKCS12_decrypt_d2i($type_thing, (algor), (d2i_func), (free_func), (pass), (passlen), (oct), (seq))
109EOF 150EOF
110 } 151 }
152
153 foreach $type_thing (sort @lhashlst) {
154 my $lc_tt = lc $type_thing;
155 $new_stackfile .= <<EOF;
156
157#define lh_${type_thing}_new() LHM_lh_new(${type_thing},${lc_tt})
158#define lh_${type_thing}_insert(lh,inst) LHM_lh_insert(${type_thing},lh,inst)
159#define lh_${type_thing}_retrieve(lh,inst) LHM_lh_retrieve(${type_thing},lh,inst)
160#define lh_${type_thing}_delete(lh,inst) LHM_lh_delete(${type_thing},lh,inst)
161#define lh_${type_thing}_doall(lh,fn) LHM_lh_doall(${type_thing},lh,fn)
162#define lh_${type_thing}_doall_arg(lh,fn,arg_type,arg) \\
163 LHM_lh_doall_arg(${type_thing},lh,fn,arg_type,arg)
164#define lh_${type_thing}_error(lh) LHM_lh_error(${type_thing},lh)
165#define lh_${type_thing}_num_items(lh) LHM_lh_num_items(${type_thing},lh)
166#define lh_${type_thing}_down_load(lh) LHM_lh_down_load(${type_thing},lh)
167#define lh_${type_thing}_node_stats_bio(lh,out) \\
168 LHM_lh_node_stats_bio(${type_thing},lh,out)
169#define lh_${type_thing}_node_usage_stats_bio(lh,out) \\
170 LHM_lh_node_usage_stats_bio(${type_thing},lh,out)
171#define lh_${type_thing}_stats_bio(lh,out) \\
172 LHM_lh_stats_bio(${type_thing},lh,out)
173#define lh_${type_thing}_free(lh) LHM_lh_free(${type_thing},lh)
174EOF
175 }
176
111 $new_stackfile .= "/* End of util/mkstack.pl block, you may now edit :-) */\n"; 177 $new_stackfile .= "/* End of util/mkstack.pl block, you may now edit :-) */\n";
112 $inside_block = 2; 178 $inside_block = 2;
113} 179}