Mercurial > dropbear
comparison libtommath/dep.pl @ 1655:f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
* make key-generation compliant to FIPS 186.4
* fix includes in tommath_class.h
* update fuzzcorpus instead of error-out
* fixup fuzzing make-targets
* update Makefile.in
* apply necessary patches to ltm sources
* clean-up not required ltm files
* update to vanilla ltm 1.1.0
this already only contains the required files
* remove set/get double
author | Steffen Jaeckel <s_jaeckel@gmx.de> |
---|---|
date | Mon, 16 Sep 2019 15:50:38 +0200 |
parents | 8bba51a55704 |
children |
comparison
equal
deleted
inserted
replaced
1654:cc0fc5131c5c | 1655:f52919ffd3b1 |
---|---|
1 #!/usr/bin/perl | 1 #!/usr/bin/perl |
2 # | 2 # |
3 # Walk through source, add labels and make classes | 3 # Walk through source, add labels and make classes |
4 # | 4 # |
5 use strict; | 5 use strict; |
6 use warnings; | 6 use warnings; |
7 | 7 |
8 my %deplist; | 8 my %deplist; |
9 | 9 |
10 #open class file and write preamble | 10 #open class file and write preamble |
11 open(my $class, '>', 'tommath_class.h') or die "Couldn't open tommath_class.h for writing\n"; | 11 open(my $class, '>', 'tommath_class.h') or die "Couldn't open tommath_class.h for writing\n"; |
12 print {$class} "#if !(defined(LTM1) && defined(LTM2) && defined(LTM3))\n#if defined(LTM2)\n#define LTM3\n#endif\n#if defined(LTM1)\n#define LTM2\n#endif\n#define LTM1\n\n#if defined(LTM_ALL)\n"; | 12 print {$class} << 'EOS'; |
13 /* LibTomMath, multiple-precision integer library -- Tom St Denis | |
14 * | |
15 * LibTomMath is a library that provides multiple-precision | |
16 * integer arithmetic as well as number theoretic functionality. | |
17 * | |
18 * The library was designed directly after the MPI library by | |
19 * Michael Fromberger but has been written from scratch with | |
20 * additional optimizations in place. | |
21 * | |
22 * SPDX-License-Identifier: Unlicense | |
23 */ | |
24 | |
25 #if !(defined(LTM1) && defined(LTM2) && defined(LTM3)) | |
26 #if defined(LTM2) | |
27 # define LTM3 | |
28 #endif | |
29 #if defined(LTM1) | |
30 # define LTM2 | |
31 #endif | |
32 #define LTM1 | |
33 #if defined(LTM_ALL) | |
34 EOS | |
13 | 35 |
14 foreach my $filename (glob 'bn*.c') { | 36 foreach my $filename (glob 'bn*.c') { |
15 my $define = $filename; | 37 my $define = $filename; |
16 | 38 |
17 print "Processing $filename\n"; | 39 print "Processing $filename\n"; |
18 | 40 |
19 # convert filename to upper case so we can use it as a define | 41 # convert filename to upper case so we can use it as a define |
20 $define =~ tr/[a-z]/[A-Z]/; | 42 $define =~ tr/[a-z]/[A-Z]/; |
21 $define =~ tr/\./_/; | 43 $define =~ tr/\./_/; |
22 print {$class} "#define $define\n"; | 44 print {$class} << "EOS"; |
45 # define $define | |
46 EOS | |
23 | 47 |
24 # now copy text and apply #ifdef as required | 48 # now copy text and apply #ifdef as required |
25 my $apply = 0; | 49 my $apply = 0; |
26 open(my $src, '<', $filename); | 50 open(my $src, '<', $filename); |
27 open(my $out, '>', 'tmp'); | 51 open(my $out, '>', 'tmp'); |
28 | 52 |
29 # first line will be the #ifdef | 53 # first line will be the #ifdef |
30 my $line = <$src>; | 54 my $line = <$src>; |
31 if ($line =~ /include/) { | 55 if ($line =~ /include/) { |
32 print {$out} $line; | 56 print {$out} $line; |
33 } else { | 57 } else { |
34 print {$out} "#include <tommath.h>\n#ifdef $define\n$line"; | 58 print {$out} << "EOS"; |
59 #include "tommath_private.h" | |
60 #ifdef $define | |
61 /* LibTomMath, multiple-precision integer library -- Tom St Denis | |
62 * | |
63 * LibTomMath is a library that provides multiple-precision | |
64 * integer arithmetic as well as number theoretic functionality. | |
65 * | |
66 * The library was designed directly after the MPI library by | |
67 * Michael Fromberger but has been written from scratch with | |
68 * additional optimizations in place. | |
69 * | |
70 * SPDX-License-Identifier: Unlicense | |
71 */ | |
72 $line | |
73 EOS | |
35 $apply = 1; | 74 $apply = 1; |
36 } | 75 } |
37 while (<$src>) { | 76 while (<$src>) { |
38 if (!($_ =~ /tommath\.h/)) { | 77 if (!($_ =~ /tommath\.h/)) { |
39 print {$out} $_; | 78 print {$out} $_; |
40 } | 79 } |
41 } | 80 } |
42 if ($apply == 1) { | 81 if ($apply == 1) { |
43 print {$out} "#endif\n"; | 82 print {$out} << 'EOS'; |
83 #endif | |
84 /* ref: \\HEAD -> master, tag: v1.1.0 */ | |
85 /* git commit: \\08549ad6bc8b0cede0b357a9c341c5c6473a9c55 */ | |
86 /* commit time: \\2019-01-28 20:32:32 +0100 */ | |
87 EOS | |
44 } | 88 } |
45 close $src; | 89 close $src; |
46 close $out; | 90 close $out; |
47 | 91 |
48 unlink $filename; | 92 unlink $filename; |
49 rename 'tmp', $filename; | 93 rename 'tmp', $filename; |
50 } | 94 } |
51 print {$class} "#endif\n\n"; | 95 print {$class} << 'EOS'; |
96 #endif | |
97 EOS | |
52 | 98 |
53 # now do classes | 99 # now do classes |
54 | 100 |
55 foreach my $filename (glob 'bn*.c') { | 101 foreach my $filename (glob 'bn*.c') { |
56 open(my $src, '<', $filename) or die "Can't open source file!\n"; | 102 open(my $src, '<', $filename) or die "Can't open source file!\n"; |
57 | 103 |
58 # convert filename to upper case so we can use it as a define | 104 # convert filename to upper case so we can use it as a define |
59 $filename =~ tr/[a-z]/[A-Z]/; | 105 $filename =~ tr/[a-z]/[A-Z]/; |
60 $filename =~ tr/\./_/; | 106 $filename =~ tr/\./_/; |
61 | 107 |
62 print {$class} "#if defined($filename)\n"; | 108 print {$class} << "EOS"; |
109 #if defined($filename) | |
110 EOS | |
63 my $list = $filename; | 111 my $list = $filename; |
64 | 112 |
65 # scan for mp_* and make classes | 113 # scan for mp_* and make classes |
66 while (<$src>) { | 114 while (<$src>) { |
67 my $line = $_; | 115 my $line = $_; |
72 if (!($& eq 'mp_digit') && !($& eq 'mp_word') && !($& eq 'mp_int') && !($& eq 'mp_min_u32')) { | 120 if (!($& eq 'mp_digit') && !($& eq 'mp_word') && !($& eq 'mp_int') && !($& eq 'mp_min_u32')) { |
73 my $a = $&; | 121 my $a = $&; |
74 $a =~ tr/[a-z]/[A-Z]/; | 122 $a =~ tr/[a-z]/[A-Z]/; |
75 $a = 'BN_' . $a . '_C'; | 123 $a = 'BN_' . $a . '_C'; |
76 if (!($list =~ /$a/)) { | 124 if (!($list =~ /$a/)) { |
77 print {$class} " #define $a\n"; | 125 print {$class} << "EOS"; |
126 # define $a | |
127 EOS | |
78 } | 128 } |
79 $list = $list . ',' . $a; | 129 $list = $list . ',' . $a; |
80 } | 130 } |
81 } | 131 } |
82 } | 132 } |
83 $deplist{$filename} = $list; | 133 $deplist{$filename} = $list; |
84 | 134 |
85 print {$class} "#endif\n\n"; | 135 print {$class} << 'EOS'; |
136 #endif | |
137 | |
138 EOS | |
86 close $src; | 139 close $src; |
87 } | 140 } |
88 | 141 |
89 print {$class} "#ifdef LTM3\n#define LTM_LAST\n#endif\n#include <tommath_superclass.h>\n#include <tommath_class.h>\n#else\n#define LTM_LAST\n#endif\n"; | 142 print {$class} << 'EOS'; |
143 #ifdef LTM3 | |
144 # define LTM_LAST | |
145 #endif | |
146 | |
147 #include <tommath_superclass.h> | |
148 #include <tommath_class.h> | |
149 #else | |
150 # define LTM_LAST | |
151 #endif | |
152 | |
153 /* ref: HEAD -> master, tag: v1.1.0 */ | |
154 /* git commit: 08549ad6bc8b0cede0b357a9c341c5c6473a9c55 */ | |
155 /* commit time: 2019-01-28 20:32:32 +0100 */ | |
156 EOS | |
90 close $class; | 157 close $class; |
91 | 158 |
92 #now let's make a cool call graph... | 159 #now let's make a cool call graph... |
93 | 160 |
94 open(my $out, '>', 'callgraph.txt'); | 161 open(my $out, '>', 'callgraph.txt'); |
95 my $indent = 0; | 162 my $indent = 0; |
96 my $list; | 163 my $list; |
97 foreach (sort keys %deplist) { | 164 foreach (sort keys %deplist) { |