Commit 3e7a722f authored by Niels Möller's avatar Niels Möller
Browse files

Deleted files.

Rev: src/blowfish.c:1.11(DEAD)
Rev: src/cascade.c:1.5(DEAD)
Rev: src/cast.c:1.7(DEAD)
Rev: src/cbc.c:1.8(DEAD)
Rev: src/serpent.c:1.7(DEAD)
parent 8faa4dc4
/* blowfish.c
*
* $Id$ */
/* 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 "crypto.h"
#include "werror.h"
#include "xalloc.h"
#include "nettle/blowfish.h"
#include <assert.h>
#include "blowfish.c.x"
/* Blowfish */
/* GABA:
(class
(name blowfish_instance)
(super crypto_instance)
(vars
(ctx . "struct blowfish_ctx")))
*/
static void
do_blowfish_encrypt(struct crypto_instance *s,
UINT32 length, const UINT8 *src, UINT8 *dst)
{
CAST(blowfish_instance, self, s);
blowfish_encrypt(&self->ctx, length, dst, src);
}
static void
do_blowfish_decrypt(struct crypto_instance *s,
UINT32 length, const UINT8 *src, UINT8 *dst)
{
CAST(blowfish_instance, self, s);
blowfish_decrypt(&self->ctx, length, dst, src);
}
static struct crypto_instance *
make_blowfish_instance(struct crypto_algorithm *algorithm, int mode,
const UINT8 *key, const UINT8 *iv UNUSED)
{
NEW(blowfish_instance, self);
self->super.block_size = BLOWFISH_BLOCK_SIZE;
self->super.crypt = ( (mode == CRYPTO_ENCRYPT)
? do_blowfish_encrypt
: do_blowfish_decrypt);
if (blowfish_set_key(&self->ctx, algorithm->key_size, key))
return &self->super;
else
{
werror("Detected a weak blowfish key!\n");
KILL(self);
return NULL;
}
}
struct crypto_algorithm *
make_blowfish_algorithm(UINT32 key_size)
{
NEW(crypto_algorithm, algorithm);
assert(key_size <= BLOWFISH_MAX_KEY_SIZE);
assert(key_size >= BLOWFISH_MIN_KEY_SIZE);
algorithm->block_size = BLOWFISH_BLOCK_SIZE;
algorithm->key_size = key_size;
algorithm->iv_size = 0;
algorithm->make_crypt = make_blowfish_instance;
return algorithm;
}
struct crypto_algorithm blowfish_algorithm =
{ STATIC_HEADER, BLOWFISH_BLOCK_SIZE, BLOWFISH_KEY_SIZE,
0, make_blowfish_instance};
/* cascade.c
*
* $Id$ */
/* 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 "abstract_crypto.h"
#include "list.h"
#include "werror.h"
#include "xalloc.h"
#include <assert.h>
#include "cascade.c.x"
/* GABA:
(class
(name crypto_cascade_algorithm)
(super crypto_algorithm)
(vars
(cascade object object_list)))
*/
/* GABA:
(class
(name crypto_cascade_instance)
(super crypto_instance)
(vars
(cascade object object_list)))
*/
static void do_cascade_crypt(struct crypto_instance *s,
UINT32 length, const UINT8 *src, UINT8 *dst)
{
CAST(crypto_cascade_instance, self, s);
unsigned i;
if (length % self->super.block_size)
fatal("Internal error!\n");
assert(LIST_LENGTH(self->cascade));
{
CAST_SUBTYPE(crypto_instance, o, LIST(self->cascade)[0]);
CRYPT(o, length, src, dst);
}
for (i = 1; i<LIST_LENGTH(self->cascade); i++)
{
CAST_SUBTYPE(crypto_instance, o, LIST(self->cascade)[i]);
CRYPT(o, length, dst, dst);
}
}
static struct crypto_instance *
do_make_cascade(struct crypto_algorithm *s,
int mode, const UINT8 *key, const UINT8 *iv)
{
CAST(crypto_cascade_algorithm, algorithm, s);
NEW(crypto_cascade_instance, instance);
unsigned i;
unsigned l = LIST_LENGTH(algorithm->cascade);
instance->super.block_size = algorithm->super.block_size;
instance->cascade = alloc_object_list(l);
for (i = 0; i<l; i++)
{
/* When decrypting, the crypto algorithms should be used in
* reverse order! */
unsigned j = ( (mode == CRYPTO_ENCRYPT)
? i : l - i - 1);
CAST_SUBTYPE(crypto_algorithm, a, LIST(algorithm->cascade)[i]);
struct crypto_instance *o = MAKE_CRYPT(a, mode, key, iv);
if (!o)
{
KILL(instance);
return NULL;
}
LIST(instance->cascade)[j] = (struct lsh_object *) o;
key += a->key_size;
iv += a->iv_size;
}
instance->super.crypt = do_cascade_crypt;
return &instance->super;
}
struct crypto_algorithm *crypto_cascadel(struct object_list *cascade)
{
NEW(crypto_cascade_algorithm, self);
unsigned i;
self->cascade = cascade;
self->super.key_size = self->super.iv_size = 0;
self->super.block_size = 1;
for (i = 0; i<LIST_LENGTH(self->cascade); i++)
{
CAST_SUBTYPE(crypto_algorithm, a, LIST(self->cascade)[i]);
self->super.key_size += a->key_size;
self->super.iv_size += a->iv_size;
self->super.block_size = lcm(self->super.block_size, a->block_size);
}
self->super.make_crypt = do_make_cascade;
return &self->super;
}
struct crypto_algorithm *crypto_cascade(unsigned n, ...)
{
va_list args;
struct object_list *l;
va_start(args, n);
l = make_object_listv(n, args);
va_end(args);
return crypto_cascadel(l);
}
/* cast.c - wrapper arround the CAST128 implementation
*
* $Id$ */
/* lsh, an implementation of the ssh protocol
*
* Copyright (C) 1998 Niels Mller
* Copyright (C) 1999 J.H.M. Dassen (Ray) <jdassen@wi.LeidenUniv.nl>
*
* 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 "crypto.h"
#include "werror.h"
#include "xalloc.h"
#include "nettle/cast128.h"
#include <assert.h>
#include "cast.c.x"
struct crypto_algorithm *make_cast_algorithm(UINT32 key_size);
/* Cast */
/* GABA:
(class
(name cast_instance)
(super crypto_instance)
(vars
(ctx . "struct cast128_ctx")))
*/
static void
do_cast_encrypt(struct crypto_instance *s,
UINT32 length, const UINT8 *src, UINT8 *dst)
{
CAST(cast_instance, self, s);
cast128_encrypt(&self->ctx, length, dst, src);
}
static void
do_cast_decrypt(struct crypto_instance *s,
UINT32 length, const UINT8 *src, UINT8 *dst)
{
CAST(cast_instance, self, s);
cast128_decrypt(&self->ctx, length, dst, src);
}
static struct crypto_instance *
make_cast_instance(struct crypto_algorithm *algorithm, int mode,
const UINT8 *key, const UINT8 *iv UNUSED)
{
NEW(cast_instance, self);
self->super.block_size = CAST128_BLOCK_SIZE;
self->super.crypt = ( (mode == CRYPTO_ENCRYPT)
? do_cast_encrypt
: do_cast_decrypt);
cast128_set_key(&self->ctx, algorithm->key_size, key);
return &self->super;
}
struct crypto_algorithm *make_cast_algorithm(UINT32 key_size)
{
NEW(crypto_algorithm, algorithm);
assert(key_size <= CAST128_MAX_KEY_SIZE);
assert(key_size >= CAST128_MIN_KEY_SIZE);
algorithm->block_size = CAST128_BLOCK_SIZE;
algorithm->key_size = key_size;
algorithm->iv_size = 0;
algorithm->make_crypt = make_cast_instance;
return algorithm;
}
struct crypto_algorithm cast128_algorithm =
{ STATIC_HEADER, CAST128_BLOCK_SIZE, CAST128_MAX_KEY_SIZE, 0, make_cast_instance};
/* cbc.c
*
* $Id$ */
/* 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 "crypto.h"
#include "werror.h"
#include "xalloc.h"
#include <assert.h>
#include <string.h>
#include "cbc.c.x"
#if !HAVE_MEMXOR
#include "nettle/memxor.h"
#endif
/* GABA:
(class
(name cbc_algorithm)
(super crypto_algorithm)
(vars
(inner object crypto_algorithm)))
*/
/* GABA:
(class
(name cbc_instance)
(super crypto_instance)
(vars
(inner object crypto_instance)
(iv space UINT8)))
*/
static void do_cbc_encrypt(struct crypto_instance *s,
UINT32 length, const UINT8 *src, UINT8 *dst)
{
CAST(cbc_instance, self, s);
FOR_BLOCKS(length, src, dst, self->super.block_size)
{
memxor(self->iv, src, self->super.block_size);
CRYPT(self->inner, self->super.block_size, self->iv, dst);
memcpy(self->iv, dst, self->super.block_size);
}
}
static void do_cbc_decrypt(struct crypto_instance *s,
UINT32 length, const UINT8 *src, UINT8 *dst)
{
CAST(cbc_instance, self, s);
if (length % self->super.block_size)
fatal("Internal error\n");
if (!length)
return;
if (src == dst)
{
/* Keep a copy of the ciphertext. */
UINT8 *tmp = alloca(length);
memcpy(tmp, src, length);
src = tmp;
}
/* Decrypt in ECB mode */
CRYPT(self->inner, length, src, dst);
/* XOR the cryptotext, shifted one block */
memxor(dst,
self->iv, self->super.block_size);
memxor(dst + self->super.block_size,
src, length - self->super.block_size);
memcpy(self->iv,
src + length - self->super.block_size, self->super.block_size);
}
static struct crypto_instance *
do_make_cbc_instance(struct crypto_algorithm *s,
int mode, const UINT8 *key, const UINT8 *iv)
{
CAST(cbc_algorithm, algorithm, s);
NEW(cbc_instance, instance);
instance->super.block_size = algorithm->super.block_size;
/* NOTE: We use a prefix of the iv, and pass the tail on to the
* inner block crypto. This allows nested chaining, although the
* semantics may be a little obscure.. */
instance->inner = MAKE_CRYPT(algorithm->inner, mode, key,
iv + algorithm->super.block_size);
if (!instance->inner)
{
/* Weak key */
KILL(instance);
return NULL;
}
instance->iv = lsh_space_alloc(algorithm->super.block_size);
memcpy(instance->iv, iv, algorithm->super.block_size);
instance->super.crypt = ( (mode == CRYPTO_ENCRYPT)
? do_cbc_encrypt
: do_cbc_decrypt);
return &instance->super;
}
struct crypto_algorithm *crypto_cbc(struct crypto_algorithm *inner)
{
NEW(cbc_algorithm, algorithm);
algorithm->super.block_size = inner->block_size;
algorithm->super.key_size = inner->key_size;
algorithm->super.iv_size = inner->iv_size + inner->block_size;
algorithm->inner = inner;
algorithm->super.make_crypt = do_make_cbc_instance;
return &algorithm->super;
}
/* serpent.c
*
* $Id$ */
/* lsh, an implementation of the ssh protocol
*
* Copyright (C) 1999, 2000 Niels Mller, Rafael R. Sevilla
*
* 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 "crypto.h"
#include "werror.h"
#include "xalloc.h"
#include "nettle/serpent.h"
#include <assert.h>
#include "serpent.c.x"
/* Serpent */
/* GABA:
(class
(name serpent_instance)
(super crypto_instance)
(vars
(ctx . "struct serpent_ctx")))
*/
static void
do_serpent_encrypt(struct crypto_instance *s,
UINT32 length, const UINT8 *src, UINT8 *dst)
{
CAST(serpent_instance, self, s);
serpent_encrypt(&self->ctx, length, dst, src);
}
static void
do_serpent_decrypt(struct crypto_instance *s,
UINT32 length, const UINT8 *src, UINT8 *dst)
{
CAST(serpent_instance, self, s);
serpent_decrypt(&self->ctx, length, dst, src);
}
static struct crypto_instance *
make_serpent_instance(struct crypto_algorithm *algorithm, int mode,
const UINT8 *key, const UINT8 *iv UNUSED)
{
NEW(serpent_instance, self);
self->super.block_size = SERPENT_BLOCK_SIZE;
self->super.crypt = ( (mode == CRYPTO_ENCRYPT)
? do_serpent_encrypt
: do_serpent_decrypt);
serpent_set_key(&self->ctx, algorithm->key_size, key);
return(&self->super);
}
struct crypto_algorithm *
make_serpent_algorithm(UINT32 key_size)
{
NEW(crypto_algorithm, algorithm);
assert(key_size >= SERPENT_MIN_KEY_SIZE);
assert(key_size <= SERPENT_MAX_KEY_SIZE);
algorithm->block_size = SERPENT_BLOCK_SIZE;
algorithm->key_size = key_size;
algorithm->iv_size = 0;
algorithm->make_crypt = make_serpent_instance;
return algorithm;
}
struct crypto_algorithm serpent128_algorithm =
{ STATIC_HEADER, SERPENT_BLOCK_SIZE, 16, 0, make_serpent_instance};
struct crypto_algorithm serpent192_algorithm =
{ STATIC_HEADER, SERPENT_BLOCK_SIZE, 24, 0, make_serpent_instance};
struct crypto_algorithm serpent256_algorithm =
{ STATIC_HEADER, SERPENT_BLOCK_SIZE, 32, 0, make_serpent_instance};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment