Revert "Revert "and added files""
[bcm963xx.git] / userapps / opensource / sshd / libtomcrypt / config.pl
1 #!/usr/bin/perl
2 #
3 # Generates a makefile based on user input
4 #
5 # Tom St Denis, tomstdenis@yahoo.com, http://tom.iahu.ca
6
7 @settings = (
8    "CC,Compiler,gcc",
9    "AR,Archiver,ar",
10    "LD,Linker,ld",
11    "CFLAGS,Optimizations,-Os",
12    "CFLAGS,Warnings,-Wall -Wsign-compare -W -Wno-unused -Werror",
13    "CFLAGS,Include Paths,-I./",
14    "CFLAGS,Other compiler options,",
15    "CFLAGS,XMALLOC,-DXMALLOC=malloc",
16    "CFLAGS,XREALLOC,-DXREALLOC=realloc",
17    "CFLAGS,XCALLOC,-DXCALLOC=calloc",
18    "CFLAGS,XFREE,-DXFREE=free",
19    "CFLAGS,XCLOCK,-DXCLOCK=clock",
20    "CFLAGS,XCLOCKS_PER_SEC,-DXCLOCKS_PER_SEC=CLOCKS_PER_SEC",
21 );
22
23 @opts = (
24    "SMALL_CODE,Use small code where possible (slower code),y",
25    "NO_FILE,Avoid file I/O calls,n",
26    "CLEAN_STACK,Clean the stack within functions,n",
27    "LTC_TEST,Include Test Vector Routines,y",
28
29    "BLOWFISH,Include Blowfish block cipher,y",
30    "RC2,Include RC2 block cipher,y",
31    "RC5,Include RC5 block cipher,y",
32    "RC6,Include RC6 block cipher,y",
33    "SAFERP,Include Safer+ block cipher,y",
34    "SAFER,Include Safer-64 block ciphers,y",
35    "RIJNDAEL,Include Rijndael (AES) block cipher,y",
36    "XTEA,Include XTEA block cipher,y",
37    "TWOFISH,Include Twofish block cipher,y",
38    "TWOFISH_SMALL,Include Use a low ram variant of Twofish,n",
39    "TWOFISH_TABLES,Include Use precomputed tables to speed up the low-ram variant,n",
40    "DES,Include DES and 3DES block ciphers,y",
41    "CAST5,Include CAST5 (aka CAST-128) block cipher,y",
42    "NOEKEON,Include Noekeon block cipher,y",
43
44    "CFB,Include CFB block mode of operation,y",
45    "OFB,Include OFB block mode of operation,y",
46    "ECB,Include ECB block mode of operation,y",
47    "CBC,Include CBC block mode of operation,y",
48    "CTR,Include CTR block mode of operation,y",
49
50    "SHA512,Include SHA512 one-way hash,y",
51    "SHA384,Include SHA384 one-way hash (requires SHA512),y",
52    "SHA256,Include SHA256 one-way hash,y",
53    "TIGER,Include TIGER one-way hash,y",
54    "SHA1,Include SHA1 one-way hash,y",
55    "MD5,Include MD5 one-way hash,y",
56    "MD4,Include MD4 one-way hash,y",
57    "MD2,Include MD2 one-way hash,y",
58    "HMAC,Include Hash based Message Authentication Support,y",
59
60    "BASE64,Include Base64 encoding support,y",
61
62    "YARROW,Include Yarrow PRNG,y",
63    "SPRNG,Include Secure PRNG base on RNG code,y",
64    "RC4,Include RC4 PRNG,y",
65    "DEVRANDOM,Use /dev/random or /dev/urandom if available?,y",
66    "TRY_URANDOM_FIRST,Try /dev/urandom before /dev/random?,n",
67
68    "MRSA,Include RSA public key support,y",
69    "MDH,Include Diffie-Hellman (over Z/pZ) public key support,y",
70    "MECC,Include Eliptic Curve public key crypto support,y",
71    "KR,Include Keyring support (groups all three PK systems),y",
72    
73    "DH768,768-bit DH key support,y",
74    "DH1024,1024-bit DH key support,y",
75    "DH1280,1280-bit DH key support,y",
76    "DH1536,1536-bit DH key support,y",
77    "DH1792,1792-bit DH key support,y",
78    "DH2048,2048-bit DH key support,y",
79    "DH2560,2560-bit DH key support,y",
80    "DH3072,3072-bit DH key support,y",
81    "DH4096,4096-bit DH key support,y",
82    
83    "ECC160,160-bit ECC key support,y",
84    "ECC192,192-bit ECC key support,y",
85    "ECC224,224-bit ECC key support,y",
86    "ECC256,256-bit ECC key support,y",
87    "ECC384,384-bit ECC key support,y",
88    "ECC521,521-bit ECC key support,y",
89    
90    "GF,Include GF(2^w) math support (not used internally),n",
91    
92    "MPI,Include MPI big integer math support (required by the public key code),y",
93 );
94
95 # scan for switches and make variables
96 for (@settings) {
97    @m = split(",", $_);
98    print "@m[1]: [@m[2]] ";
99    $r = <>; $r = @m[2] if ($r eq "\n");
100    chomp($r);
101    @vars{@m[0]} = @vars{@m[0]} . $r . " ";
102 }
103
104 # scan for build flags
105 for (@opts) {
106    @m = split(",", $_);
107    print "@m[1]: [@m[2]]";
108    $r = <>;  @vars{'CFLAGS'} = @vars{'CFLAGS'} . "-D" . $m[0] . " " if (($r eq "y\n") || ($r eq "\n" && @m[2] eq "y"));
109 }   
110
111 # write header
112
113 open(OUT,">mycrypt_custom.h");
114 print OUT "/* This header is meant to be included before mycrypt.h in projects where\n";
115 print OUT " * you don't want to throw all the defines in a makefile. \n";
116 print OUT " */\n\n#ifndef MYCRYPT_CUSTOM_H_\n#define MYCRYPT_CUSTOM_H_\n\n#ifdef CRYPT\n\t#error mycrypt_custom.h should be included before mycrypt.h\n#endif\n\n";
117
118 @m = split(" ", @vars{'CFLAGS'});
119 for (@m) {
120     if ($_ =~ /^-D/) {
121        $_ =~ s/-D//;
122        $_ =~ s/=/" "/ge;
123        print OUT "#define $_\n";
124     }
125 }
126
127 print OUT "\n\n#include <mycrypt.h>\n\n#endif\n\n";
128 close OUT;
129        
130 print "\n\nmycrypt_custom.h generated.\n";
131
132 open(OUT,">makefile.out");
133 print OUT "#makefile generated with config.pl\n#\n#Tom St Denis (tomstdenis\@yahoo.com, http://tom.iahu.ca) \n\n";
134
135 # output unique vars first
136 @vars{'CFLAGS'} =~ s/-D.+ /""/ge;
137
138 for (@settings) {
139    @m = split(",", $_);
140    print OUT "@m[0] = @vars{@m[0]}\n"   if (@vars{@m[0]} ne "" && @m[0] ne "CFLAGS");
141    print OUT "CFLAGS += @vars{@m[0]}\n" if (@vars{@m[0]} ne "" && @m[0] eq "CFLAGS");
142    @vars{@m[0]} = "";
143 }
144
145 # output objects
146 print OUT "\ndefault: library\n\n";
147 print OUT "OBJECTS = keyring.o gf.o mem.o sprng.o ecc.o base64.o dh.o rsa.o bits.o yarrow.o cfb.o ofb.o ecb.o ctr.o cbc.o hash.o tiger.o sha1.o md5.o md4.o md2.o sha256.o sha512.o xtea.o aes.o des.o safer_tab.o safer.o safer+.o rc4.o rc2.o rc6.o rc5.o cast5.o noekeon.o blowfish.o crypt.o mpi.o prime.o twofish.o packet.o hmac.o strings.o \n\n";
148
149 # some depends
150 print OUT "rsa.o: rsa_sys.c\ndh.o: dh_sys.c\necc.o: ecc_sys.c\n\n";
151
152 # targets
153 print OUT "library: \$(OBJECTS)\n\t \$(AR) r libtomcrypt.a \$(OBJECTS)\n\t ranlib libtomcrypt.a\n\n";
154 print OUT "clean:\n\trm -f \$(OBJECTS) libtomcrypt.a \n\n";
155
156 close OUT;
157
158 print "makefile.out generated.\n";
159
160 print "\nNow use makefile.out to build the library, e.g. `make -f makefile.out'\n";
161 print "In your project just include mycrypt_custom.h (you don't have to include mycrypt.h \n";
162 print "but if you do make sure mycrypt_custom.h appears first) your settings should be intact.\n";