| 1 | # -*-perl-*- |
| 2 | # |
| 3 | # $Id: algs.PL,v 1.2 2004/04/08 01:36:21 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 | @cipher = qw(des desx des3 |
| 29 | blowfish twofish |
| 30 | cast128 cast256 |
| 31 | idea safer safersk |
| 32 | rc2 rc5 |
| 33 | square rijndael rijndael192 rijndael256 |
| 34 | serpent |
| 35 | skipjack |
| 36 | mars |
| 37 | tea xtea); |
| 38 | @stream = qw(rc4 seal); |
| 39 | @hash = qw(md5 md4 md2 tiger |
| 40 | sha sha256 sha384 sha512 |
| 41 | rmd128 rmd160 rmd256 rmd320); |
| 42 | |
| 43 | sub enum { |
| 44 | $x = shift; |
| 45 | if (!ref($x)) { return $x; } |
| 46 | elsif (ref($x) eq ARRAY) { return @$x } |
| 47 | else { die "bad ref"; } |
| 48 | } |
| 49 | |
| 50 | sub cross { |
| 51 | my $x = []; |
| 52 | foreach my $i (@_) { |
| 53 | my @y = enum($i); |
| 54 | if (@$x) { |
| 55 | my @x = (); |
| 56 | foreach my $j (@$x) { foreach my $k (@y) { push(@x, $j.$k); } } |
| 57 | $x = \@x; |
| 58 | } else { |
| 59 | $x = \@y; |
| 60 | } |
| 61 | } |
| 62 | return @$x; |
| 63 | } |
| 64 | |
| 65 | open OUT, "> $ARGV[0]" or die "couldn't write `$ARGV[0].c': $!"; |
| 66 | |
| 67 | print OUT <<EOF; |
| 68 | /* -*-c-*- |
| 69 | * |
| 70 | * algs.c [generated] |
| 71 | */ |
| 72 | |
| 73 | #include "catacomb-perl.h" |
| 74 | |
| 75 | #include <catacomb/crc32.h> |
| 76 | |
| 77 | EOF |
| 78 | print OUT cross("#include <catacomb/", \@cipher, "-", |
| 79 | [qw(ecb cbc cfb counter ofb)], ".h>\n"), "\n"; |
| 80 | print OUT cross("#include <catacomb/", \@stream, ".h>\n"), "\n"; |
| 81 | print OUT cross("#include <catacomb/", \@hash, ".h>\n"), "\n"; |
| 82 | print OUT cross("#include <catacomb/", \@hash, "-", |
| 83 | [qw(mgf hmac)], ".h>\n"), "\n"; |
| 84 | |
| 85 | print OUT <<EOF; |
| 86 | |
| 87 | const gccipher *ciphertab[] = { |
| 88 | EOF |
| 89 | print OUT cross(" &", \@cipher, "_", [qw(ecb cbc cfb counter ofb)], ",\n"); |
| 90 | print OUT cross(" &", \@hash, "_", [qw(mgf)], ",\n"); |
| 91 | print OUT cross(" &", \@stream, ",\n"); |
| 92 | print OUT <<EOF; |
| 93 | 0 |
| 94 | }; |
| 95 | |
| 96 | const gchash *hashtab[] = { |
| 97 | EOF |
| 98 | print OUT cross(" &", \@hash, ",\n"); |
| 99 | print OUT <<EOF; |
| 100 | &gcrc32, |
| 101 | 0 |
| 102 | }; |
| 103 | |
| 104 | const gcmac *mactab[] = { |
| 105 | EOF |
| 106 | print OUT cross(" &", \@hash, "_", [qw(hmac nmac sslmac)], ",\n"); |
| 107 | print OUT <<EOF; |
| 108 | 0 |
| 109 | }; |
| 110 | |
| 111 | const struct randtab mgftab[] = { |
| 112 | EOF |
| 113 | foreach my $i (@hash) { print OUT " { \"$i\", ${i}_mgfrand },\n"; } |
| 114 | print OUT <<EOF; |
| 115 | { 0, 0 } |
| 116 | }; |
| 117 | |
| 118 | const struct randtab ctrtab[] = { |
| 119 | EOF |
| 120 | foreach my $i (@cipher) { print OUT " { \"$i\", ${i}_counterrand },\n"; } |
| 121 | print OUT <<EOF; |
| 122 | { 0, 0 } |
| 123 | }; |
| 124 | |
| 125 | const struct randtab ofbtab[] = { |
| 126 | EOF |
| 127 | foreach my $i (@cipher) { print OUT " { \"$i\", ${i}_ofbrand },\n"; } |
| 128 | print OUT <<EOF; |
| 129 | { 0, 0 } |
| 130 | }; |
| 131 | EOF |
| 132 | |
| 133 | #----- That's all, folks ---------------------------------------------------- |