Initial checkin.
[catacomb-perl] / algs.PL
1 # -*-perl-*-
2 #
3 # $Id: algs.PL,v 1.1 2004/04/02 18:04:01 mdw Exp $
4 #
5 # Create tables of algorithms
6 #
7 # (c) 2001 Straylight/Edgeware
8 #
9
10 #----- Licensing notice -----------------------------------------------------
11 #
12 # This file is part of the Perl interface to Catacomb.
13 #
14 # Catacomb/Perl is free software; you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation; either version 2 of the License, or
17 # (at your option) any later version.
18 #
19 # Catacomb/Perl is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
23 #
24 # You should have received a copy of the GNU General Public License
25 # along with Catacomb/Perl; if not, write to the Free Software Foundation,
26 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27
28 #----- Revision history -----------------------------------------------------
29 #
30 # $Log: algs.PL,v $
31 # Revision 1.1 2004/04/02 18:04:01 mdw
32 # Initial checkin.
33 #
34
35 @cipher = qw(des desx des3
36 blowfish twofish
37 cast128 cast256
38 idea safer safersk
39 rc2 rc5
40 square rijndael rijndael192 rijndael256
41 serpent
42 skipjack
43 mars
44 tea xtea);
45 @stream = qw(rc4 seal);
46 @hash = qw(md5 md4 md2 tiger
47 sha sha256 sha384 sha512
48 rmd128 rmd160 rmd256 rmd320);
49
50 sub enum {
51 $x = shift;
52 if (!ref($x)) { return $x; }
53 elsif (ref($x) eq ARRAY) { return @$x }
54 else { die "bad ref"; }
55 }
56
57 sub cross {
58 my $x = [];
59 foreach my $i (@_) {
60 my @y = enum($i);
61 if (@$x) {
62 my @x = ();
63 foreach my $j (@$x) { foreach my $k (@y) { push(@x, $j.$k); } }
64 $x = \@x;
65 } else {
66 $x = \@y;
67 }
68 }
69 return @$x;
70 }
71
72 open OUT, "> $ARGV[0]" or die "couldn't write `$ARGV[0].c': $!";
73
74 print OUT <<EOF;
75 /* -*-c-*-
76 *
77 * algs.c [generated]
78 */
79
80 #include "catacomb-perl.h"
81
82 #include <catacomb/crc32.h>
83
84 EOF
85 print OUT cross("#include <catacomb/", \@cipher, "-",
86 [qw(ecb cbc cfb counter ofb)], ".h>\n"), "\n";
87 print OUT cross("#include <catacomb/", \@stream, ".h>\n"), "\n";
88 print OUT cross("#include <catacomb/", \@hash, ".h>\n"), "\n";
89 print OUT cross("#include <catacomb/", \@hash, "-",
90 [qw(mgf hmac)], ".h>\n"), "\n";
91
92 print OUT <<EOF;
93
94 const gccipher *ciphertab[] = {
95 EOF
96 print OUT cross(" &", \@cipher, "_", [qw(ecb cbc cfb counter ofb)], ",\n");
97 print OUT cross(" &", \@hash, "_", [qw(mgf)], ",\n");
98 print OUT cross(" &", \@stream, ",\n");
99 print OUT <<EOF;
100 0
101 };
102
103 const gchash *hashtab[] = {
104 EOF
105 print OUT cross(" &", \@hash, ",\n");
106 print OUT <<EOF;
107 &gcrc32,
108 0
109 };
110
111 const gcmac *mactab[] = {
112 EOF
113 print OUT cross(" &", \@hash, "_", [qw(hmac nmac sslmac)], ",\n");
114 print OUT <<EOF;
115 0
116 };
117
118 const struct randtab mgftab[] = {
119 EOF
120 foreach my $i (@hash) { print OUT " { \"$i\", ${i}_mgfrand },\n"; }
121 print OUT <<EOF;
122 { 0, 0 }
123 };
124
125 const struct randtab ctrtab[] = {
126 EOF
127 foreach my $i (@cipher) { print OUT " { \"$i\", ${i}_counterrand },\n"; }
128 print OUT <<EOF;
129 { 0, 0 }
130 };
131
132 const struct randtab ofbtab[] = {
133 EOF
134 foreach my $i (@cipher) { print OUT " { \"$i\", ${i}_ofbrand },\n"; }
135 print OUT <<EOF;
136 { 0, 0 }
137 };
138 EOF
139
140 #----- That's all, folks ----------------------------------------------------