Commit bf12bd66 authored by Niels Möller's avatar Niels Möller

Deleted obsolete cruft: make_am script and src/symmetric subdirectory.

parent 702a3e93
#! /bin/bash
# This program wants to recieve a list of needed headers on stdin. It
# reads Makefile.am.in and creates Makefile.am.
# How do we run this script again?
if [ -z "$BASH" ]; then
BASH=bash
fi
if [ -z "$SELF" ]; then
SELF="$BASH make_am"
fi
rethink=no
options=''
function werror () {
echo 1>&2 "$@"
}
while true; do
case $1 in
--rethink)
rethink=yes
;;
--*)
echo make_am: Unknown option $1
exit 1
;;
*)
break
esac
options="$options $1"
shift
done
if [ $# != 0 ]; then
dir=$1
top=no
else
dir=.
top=yes
fi
werror "make_am: dir='$dir', top=$top, rethink=$rethink"
# Input file on fd 3
if [ -f $dir/Makefile.am.in ]; then
exec 3<$dir/Makefile.am.in
else
# echo 1>&2 "make_am: No Makefile.am.in in $dir"
exit 0
fi
# Output file on fd 4
exec 4>$dir/Makefile.am
echo 1>&4 '##' "Automatically generated by make_am, `date`"
echo 1>&4 '##' "Process this file with automake to produce Makefile.in"
echo 1>&4
function get_header () {
keyword=''
while [ x$keyword = x ]; do
read <&3 keyword args
if [ $? != 0 ]; then
werror "make_am: Unexpected end of file"
exit 1
fi
case $keyword in
\#*)
keyword=''
;;
*:)
keyword=`echo $keyword | sed 's/^\(.*\):$/\1/'`
;;
esac ;
done
werror "get_header: '$keyword'"
}
# # Run commands with the same data on stdin
# commands=""
#
# function add_command {
# commands="$commands tee >($1 ; cat >/dev/null) |"
# }
#
# function run_commands {
# echo 1>&2 "run_commands: $commands cat >/dev/null"
# bash -c "$commands cat >/dev/null"
# }
subdirs=''
function all_used_headers () {
werror all_used_headers
if [ $rethink = yes ]; then
werror rethink
# Determining the list of used headers is a global
# operation, so use find to recurse in all the
# subdirs.
$BASH src/used_headers .h . `find . -type d`
else
cat /dev/null
fi
}
while true; do
get_header;
case $keyword in
CVS_HEADERS)
# automake expands "foo \\\n\nbar" -> "foo \\\nbar". So
# put all the files on one line, for simplicity.
# comm -12 - <($BASH src/cvs_headers $dir) | sed 's/\$/ \\\\/';
if [ $rethink = yes ]; then
( (echo $args = .dist_headers;
all_used_headers \
| comm -12 - <( $BASH src/cvs_headers $dir ) \
| tee $dir/.dist_headers) | tr '\n' ' ';
echo) 1>&4
else
( (echo $args = .dist_headers ' '
cat $dir/.dist_headers) | tr '\n' ' '
echo) 1>&4
fi
;;
CLASS_FILES)
( ( echo $args = .dist_classes;
if [ $rethink = yes ]; then
$BASH src/used_headers .x $dir | tee $dir/.dist_classes
else
cat $dir/.dist_classes
fi) | tr '\n' ' '
echo) 1>&4
;;
SUBDIRS)
subdirs=$args
echo 1>&4 "SUBDIRS = $args"
for d in $args; do
if [ x$d != x. ] ; then
$SELF $options $dir/$d || exit 1
fi
done
;;
BODY)
# if [ $top = yes ]; then
# if [ $rethink = yes ]; then
# # Determining the list of used headers is a global
# # operation, so use find to recurse in all the
# # subdirs.
# $BASH src/used_headers .h . `find $subdirs -type d` | run_commands
# else
# run_commands </dev/null
# fi
# else
# run_commands
# fi && cat <&3 >&4
cat <&3 >&4
exit 0
;;
*)
werror "make_am: Unknown keyword '$keyword'"
exit 1
;;
esac
done
*.d
*.bb
*.bbg
*.da
*.gcov
.deps
.dist_headers
Makefile
Makefile.am
Makefile.in
bf_test
config.cache
config.h.in
config.log
config.status
configure
configure.scan
desQuickCore.c
desQuickFips.c
desSmallCore.c
desSmallFips.c
desTest
desdata
generate_q
keymap.h
parity.h
rijndael_test
rotors.h
twofish_test
/*.d
/*.bb
/*.bbg
/*.da
/*.gcov
/.deps
/.dist_headers
/Makefile
/Makefile.am
/Makefile.in
/bf_test
/config.cache
/config.h.in
/config.log
/config.status
/configure
/configure.scan
/desQuickCore.c
/desQuickFips.c
/desSmallCore.c
/desSmallFips.c
/desTest
/desdata
/generate_q
/keymap.h
/parity.h
/rijndael_test
/rotors.h
/twofish_test
## Process this file with make_am to produce Makefile.am
SUBDIRS: include
CVS_HEADERS: cvs_headers
BODY:
AUTOMAKE_OPTIONS = foreign
noinst_LIBRARIES = libsymmetric.a
noinst_PROGRAMS = desTest desdata bf_test twofish_test generate_q rijndael_test
Makefile.am: Makefile.am.in
(cd $(top_srcdir) && $(MAKE) src/symmetric/Makefile.am)
# When compiling with lsh, this is set to to -DLSH -I/path/to/lsh/include
# INCLUDES = @crypto_cpp_flags@
LDADD = libsymmetric.a
desdata_LDADD =
des_headers = parity.h rotors.h keymap.h
BUILT_SOURCES = desSmallFips.c desSmallCore.c desQuickFips.c desQuickCore.c
libsymmetric_a_SOURCES = desCode.h desKerb.c desUtil.c desQuick.c \
$(BUILT_SOURCES) \
sha.c md5.c idea.c arcfour.c cast.c blowfish.c twofish.c rijndael.c \
serpent.c
# Generate DES headers.
$(des_headers): desdata
./desdata $@ > $@T
test -s $@T && mv -f $@T $@
desUtil.o: desUtil.c $(des_headers)
# Generate DES sources. Slowest to quickest.
desSmallFips.c:
@echo > $@ '#include "desCode.h"'
@echo >> $@ 'ENCRYPT(DesSmallFipsEncrypt,TEMPSMALL,\
LOADFIPS,KEYMAPSMALL,SAVEFIPS)'
@echo >> $@ 'DECRYPT(DesSmallFipsDecrypt,TEMPSMALL,\
LOADFIPS,KEYMAPSMALL,SAVEFIPS)'
desSmallCore.c:
@echo > $@ '#include "desCode.h"'
@echo >> $@ 'ENCRYPT(DesSmallCoreEncrypt,TEMPSMALL,\
LOADCORE,KEYMAPSMALL,SAVECORE)'
@echo >> $@ 'DECRYPT(DesSmallCoreDecrypt,TEMPSMALL,\
LOADCORE,KEYMAPSMALL,SAVECORE)'
desQuickFips.c:
@echo > $@ '#include "desCode.h"'
@echo >> $@ 'ENCRYPT(DesQuickFipsEncrypt,TEMPQUICK,\
LOADFIPS,KEYMAPQUICK,SAVEFIPS)'
@echo >> $@ 'DECRYPT(DesQuickFipsDecrypt,TEMPQUICK,\
LOADFIPS,KEYMAPQUICK,SAVEFIPS)'
desQuickCore.c:
@echo > $@ '#include "desCode.h"'
@echo >> $@ 'ENCRYPT(DesQuickCoreEncrypt,TEMPQUICK,\
LOADCORE,KEYMAPQUICK,SAVECORE)'
@echo >> $@ 'DECRYPT(DesQuickCoreDecrypt,TEMPQUICK,\
LOADCORE,KEYMAPQUICK,SAVECORE)'
EXTRA_DIST = $(cvs_headers) $(des_headers) Makefile.am.in descore.README
.PHONY: depend
depend:
rm -f $(DEP_FILES)
make $(DEP_FILES)
# .deps/%.P : %.c
# $(CC) $(CPPFLAGS) $(DEFS) -M -MG $< > $@
MAINTAINERCLEANFILES += $(DEP_FILES)
include $(top_srcdir)/misc/ctags.mk
/* arcfour.c
*
* This implements the Arcfour stream cipher with 128 bit keys.
*
* The Arcfour cipher is believed to be compatible with the RC4 cipher.
* RC4 is a registered trademark of RSA Data Security Inc.
*
*/
/* lsh, an implementation of the ssh protocol
*
* Copyright (C) 1998 Niels Mller
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "arcfour.h"
#include <assert.h>
#ifdef RCSID
RCSID("$Id$");
#endif
#define SWAP(a,b) do { int _t = a; a = b; b = _t; } while(0)
void arcfour_init(struct arcfour_ctx *ctx)
{
unsigned i;
/* Initialize context */
for (i = 0; i<256; i++)
ctx->S[i] = i;
}
/* This mode of operation is non-standard and possibly insecure. */
#if 0
void arcfour_update_key(struct arcfour_ctx *ctx,
UINT32 length, const UINT8 *key)
{
register UINT8 i = ctx->i;
register UINT8 j = ctx->j;
unsigned k;
for (k = 0; k<length; k++)
{
i++; i &= 0xff;
j += ctx->S[i] + key[k]; j &= 0xff;
SWAP(ctx->S[i], ctx->S[j]);
}
ctx->i = i; ctx->j = j;
}
#endif
void arcfour_stream(struct arcfour_ctx *ctx,
UINT32 length, UINT8 *dest)
{
register UINT8 i = ctx->i;
register UINT8 j = ctx->j;
unsigned k;
for (k = 0; k<length; k++)
{
i++; i &= 0xff;
j += ctx->S[i]; j &= 0xff;
SWAP(ctx->S[i], ctx->S[j]);
dest[k] = ctx->S[ (ctx->S[i] + ctx->S[j]) & 0xff ];
}
ctx->i = i; ctx->j = j;
}
void arcfour_set_key(struct arcfour_ctx *ctx, UINT32 length, const UINT8 *key)
{
register UINT8 j; /* Depends on the eight-bitness of these variables. */
unsigned i;
UINT32 k;
/* Initialize context */
arcfour_init(ctx);
assert(length);
/* Expand key */
i = j = k = 0;
for ( ; i<256; i++)
{
j += ctx->S[i] + key[k]; j &= 0xff;
SWAP(ctx->S[i], ctx->S[j]);
k = (k+1) % length; /* Repeat key if needed */
}
ctx->i = ctx->j = 0;
}
void arcfour_crypt(struct arcfour_ctx *ctx, UINT8 *dest,
UINT32 length, const UINT8 *src)
{
register UINT8 i, j;
i = ctx->i; j = ctx->j;
while(length--)
{
i++; i &= 0xff;
j += ctx->S[i]; j &= 0xff;
SWAP(ctx->S[i], ctx->S[j]);
*dest++ = *src++ ^ ctx->S[ (ctx->S[i] + ctx->S[j]) & 0xff ];
}
ctx->i = i; ctx->j = j;
}
/* bf_test.c
*
* $Id$
* Test the blow fish implementation. */
#include "blowfish.h"
#include <stdio.h>
#include <stdlib.h>
int main (int argc UNUSED, char **argv UNUSED)
{
if (bf_selftest())
{
fprintf(stderr, "Blowfish works.\n");
return EXIT_SUCCESS;
}
else
{
fprintf(stderr, "ERROR: Blowfish failed.\n");
return EXIT_FAILURE;
}
}
This diff is collapsed.
/*
* $Id$
*
* CAST-128 in C
* Written by Steve Reid <sreid@sea-to-sky.net>
* 100% Public Domain - no warranty
* Released 1997.10.11
*
* CAST-128 is documented in
* C. Adams, "The CAST-128 Encryption Algorithm", RFC 2144.
*
*/
/* Adapted to the pike cryptographic toolkit by Niels Mller */
/* Selftest added by J.H.M. Dassen (Ray) <jdassen@wi.LeidenUniv.nl>.
* Released into the public domain. */
#include <assert.h>
#include <cast.h>
#define u8 UINT8
#define u32 UINT32
#include "cast_sboxes.h"
/* Macros to access 8-bit bytes out of a 32-bit word */
#define U8a(x) ( (u8) (x>>24) )
#define U8b(x) ( (u8) ((x>>16)&255) )
#define U8c(x) ( (u8) ((x>>8)&255) )
#define U8d(x) ( (u8) ((x)&255) )
/* Circular left shift */
#define ROL(x, n) ( ((x)<<(n)) | ((x)>>(32-(n))) )
/* CAST-128 uses three different round functions */
#define F1(l, r, i) \
t = ROL(key->xkey[i] + r, key->xkey[i+16]); \
l ^= ((cast_sbox1[U8a(t)] ^ cast_sbox2[U8b(t)]) \
- cast_sbox3[U8c(t)]) + cast_sbox4[U8d(t)];
#define F2(l, r, i) \
t = ROL(key->xkey[i] ^ r, key->xkey[i+16]); \
l ^= ((cast_sbox1[U8a(t)] - cast_sbox2[U8b(t)]) \
+ cast_sbox3[U8c(t)]) ^ cast_sbox4[U8d(t)];
#define F3(l, r, i) \
t = ROL(key->xkey[i] - r, key->xkey[i+16]); \
l ^= ((cast_sbox1[U8a(t)] + cast_sbox2[U8b(t)]) \
^ cast_sbox3[U8c(t)]) - cast_sbox4[U8d(t)];
/***** Encryption Function *****/
void cast_encrypt(struct cast_key *key, const u8 * const inblock, u8 *outblock)
{
u32 t, l, r;
/* Get inblock into l,r */
l = ((u32)inblock[0] << 24) | ((u32)inblock[1] << 16)
| ((u32)inblock[2] << 8) | (u32)inblock[3];
r = ((u32)inblock[4] << 24) | ((u32)inblock[5] << 16)
| ((u32)inblock[6] << 8) | (u32)inblock[7];
/* Do the work */
F1(l, r, 0);
F2(r, l, 1);
F3(l, r, 2);
F1(r, l, 3);
F2(l, r, 4);
F3(r, l, 5);
F1(l, r, 6);
F2(r, l, 7);
F3(l, r, 8);
F1(r, l, 9);
F2(l, r, 10);
F3(r, l, 11);
/* Only do full 16 rounds if key length > 80 bits */
if (key->rounds > 12) {
F1(l, r, 12);
F2(r, l, 13);
F3(l, r, 14);
F1(r, l, 15);
}
/* Put l,r into outblock */
outblock[0] = U8a(r);
outblock[1] = U8b(r);
outblock[2] = U8c(r);
outblock[3] = U8d(r);
outblock[4] = U8a(l);
outblock[5] = U8b(l);
outblock[6] = U8c(l);
outblock[7] = U8d(l);
/* Wipe clean */
t = l = r = 0;
}
/***** Decryption Function *****/
void cast_decrypt(struct cast_key *key, const u8 * const inblock, u8 *outblock)
{
u32 t, l, r;
/* Get inblock into l,r */
r = ((u32)inblock[0] << 24) | ((u32)inblock[1] << 16)
| ((u32)inblock[2] << 8) | (u32)inblock[3];
l = ((u32)inblock[4] << 24) | ((u32)inblock[5] << 16)
| ((u32)inblock[6] << 8) | (u32)inblock[7];
/* Do the work */
/* Only do full 16 rounds if key length > 80 bits */
if (key->rounds > 12) {
F1(r, l, 15);
F3(l, r, 14);
F2(r, l, 13);
F1(l, r, 12);
}
F3(r, l, 11);
F2(l, r, 10);
F1(r, l, 9);
F3(l, r, 8);
F2(r, l, 7);
F1(l, r, 6);
F3(r, l, 5);
F2(l, r, 4);
F1(r, l, 3);
F3(l, r, 2);
F2(r, l, 1);
F1(l, r, 0);
/* Put l,r into outblock */
outblock[0] = U8a(l);
outblock[1] = U8b(l);
outblock[2] = U8c(l);
outblock[3] = U8d(l);
outblock[4] = U8a(r);
outblock[5] = U8b(r);
outblock[6] = U8c(r);
outblock[7] = U8d(r);
/* Wipe clean */
t = l = r = 0;
}
/* Sanity check using the test vectors from
* B.1. Single Plaintext-Key-Ciphertext Sets, RFC 2144
*/
int cast_selftest(void)
{
u8 testkey128[16] = {
0x01, 0x23, 0x45, 0x67, 0x12, 0x34, 0x56, 0x78,
0x23, 0x45, 0x67, 0x89, 0x34, 0x56, 0x78, 0x9A
};
u8 plaintext128[8] = {
0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF
};
u8 ciphertext128[8] = {
0x23, 0x8B, 0x4F, 0xE5, 0x84, 0x7E, 0x44, 0xB2
};
u8 testkey80[10] = {
0x01, 0x23, 0x45, 0x67, 0x12, 0x34, 0x56, 0x78,
0x23, 0x45
};
u8 plaintext80[8] = {
0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF
};
u8 ciphertext80[8] = {
0xEB, 0x6A, 0x71, 0x1A, 0x2C, 0x02, 0x27, 0x1B
};
u8 testkey40[5] = {
0x01, 0x23, 0x45, 0x67, 0x12
};
u8 plaintext40[8] = {
0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF
};
u8 ciphertext40[8] = {
0x7A, 0xC8, 0x16, 0xD1, 0x6E, 0x9B, 0x30, 0x2E
};
struct cast_key context;
u8 ciphertext[8];
cast_setkey(&context, testkey128, 16);
cast_encrypt(&context, plaintext128, ciphertext);
if (memcmp(ciphertext, ciphertext128, 8)) {
return 0;
}
cast_setkey(&context, testkey80, 10);
cast_encrypt(&context, plaintext80, ciphertext);
if (memcmp(ciphertext, ciphertext80, 8)) {
return 0;
}
cast_setkey(&context, testkey40, 5);
cast_encrypt(&context, plaintext40, ciphertext);
if (memcmp(ciphertext, ciphertext40, 8)) {
return 0;
}
return 1;
}
/***** Key Schedule *****/
void cast_setkey(struct cast_key *key, const u8 * const rawkey, unsigned keybytes)
{
u32 t[4], z[4], x[4];
unsigned i;
#ifndef NDEBUG
static int initialized = 0;
if (!initialized)
{
initialized = 1;
assert(cast_selftest());
}
#endif
/* Set number of rounds to 12 or 16, depending on key length */
key->rounds = (keybytes <= CAST_SMALL_KEY)
? CAST_SMALL_ROUNDS : CAST_FULL_ROUNDS;
/* Copy key to workspace x */
for (i = 0; i < 4; i++) {
x[i] = 0;
if ((i*4+0) < keybytes) x[i] = (u32)rawkey[i*4+0] << 24;
if ((i*4+1) < keybytes) x[i] |= (u32)rawkey[i*4+1] << 16;
if ((i*4+2) < keybytes) x[i] |= (u32)rawkey[i*4+2] << 8;
if ((i*4+3) < keybytes) x[i] |= (u32)rawkey[i*4+3];
}
/* Generate 32 subkeys, four at a time */
for (i = 0; i < 32; i+=4) {
switch (i & 4) {
case 0:
t[0] = z[0] = x[0] ^ cast_sbox5[U8b(x[3])]
^ cast_sbox6[U8d(x[3])] ^ cast_sbox7[U8a(x[3])]
^ cast_sbox8[U8c(x[3])] ^ cast_sbox7[U8a(x[2])];
t[1] = z[1] = x[2] ^ cast_sbox5[U8a(z[0])]
^ cast_sbox6[U8c(z[0])] ^ cast_sbox7[U8b(z[0])]
^ cast_sbox8[U8d(z[0])] ^ cast_sbox8[U8c(x[2])];
t[2] = z[2] = x[3] ^ cast_sbox5[U8d(z[1])]
^ cast_sbox6[U8c(z[1])] ^ cast_sbox7[U8b(z[1])]
^ cast_sbox8[U8a(z[1])] ^ cast_sbox5[U8b(x[2])];
t[3] = z[3] = x[1] ^ cast_sbox5[U8c(z[2])] ^
cast_sbox6[U8b(z[2])] ^ cast_sbox7[U8d(z[2])]
^ cast_sbox8[U8a(z[2])] ^ cast_sbox6[U8d(x[2])];
break;
case 4:
t[0] = x[0] = z[2] ^ cast_sbox5[U8b(z[1])]
^ cast_sbox6[U8d(z[1])] ^ cast_sbox7[U8a(z[1])]
^ cast_sbox8[U8c(z[1])] ^ cast_sbox7[U8a(z[0])];
t[1] = x[1] = z[0] ^ cast_sbox5[U8a(x[0])]
^ cast_sbox6[U8c(x[0])] ^ cast_sbox7[U8b(x[0])]
^ cast_sbox8[U8d(x[0])] ^ cast_sbox8[U8c(z[0])];
t[2] = x[2] = z[1] ^ cast_sbox5[U8d(x[1])]
^ cast_sbox6[U8c(x[1])] ^ cast_sbox7[U8b(x[1])]
^ cast_sbox8[U8a(x[1])] ^ cast_sbox5[U8b(z[0])];
t[3] = x[3] = z[3] ^ cast_sbox5[U8c(x[2])]
^ cast_sbox6[U8b(x[2])] ^ cast_sbox7[U8d(x[2])]
^ cast_sbox8[U8a(x[2])] ^ cast_sbox6[U8d(z[0])];
break;
}
switch (i & 12) {
case 0:
case 12:
key->xkey[i+0] = cast_sbox5[U8a(t[2])] ^ cast_sbox6[U8b(t[2])]
^ cast_sbox7[U8d(t[1])] ^ cast_sbox8[U8c(t[1])];
key->xkey[i+1] = cast_sbox5[U8c(t[2])] ^ cast_sbox6[U8d(t[2])]
^ cast_sbox7[U8b(t[1])] ^ cast_sbox8[U8a(t[1])];
key->xkey[i+2] = cast_sbox5[U8a(t[3])] ^ cast_sbox6[U8b(t[3])]
^ cast_sbox7[U8d(t[0])] ^ cast_sbox8[U8c(t[0])];