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

* src/idea.c: Deleted file.

* src/des.c, src/twofish.c: Deleted files, replaced by code in
crypto.c.

Rev: src/des.c:1.13(DEAD)
Rev: src/idea.c:1.4(DEAD)
Rev: src/twofish.c:1.8(DEAD)
parent 022b990b
/* des.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"
#warning des.c is obsolete
#include "werror.h"
#include "xalloc.h"
#include "nettle/des.h"
#include <assert.h>
#include "des.c.x"
/* GABA:
(class
(name des_instance)
(super crypto_instance)
(vars
(ctx . "struct des_ctx")))
*/
static void do_des_encrypt(struct crypto_instance *s,
UINT32 length, const UINT8 *src, UINT8 *dst)
{
CAST(des_instance, self, s);
des_encrypt(&self->ctx, length, dst, src);
}
static void do_des_decrypt(struct crypto_instance *s,
UINT32 length, const UINT8 *src, UINT8 *dst)
{
CAST(des_instance, self, s);
des_decrypt(&self->ctx, length, dst, src);
}
static struct crypto_instance *
make_des_instance(struct crypto_algorithm *algorithm UNUSED, int mode,
const UINT8 *key, const UINT8 *iv UNUSED)
{
NEW(des_instance, self);
UINT8 pkey[DES_KEY_SIZE];
/* Fix odd parity */
des_fix_parity(DES_KEY_SIZE, pkey, key);
self->super.block_size = DES_BLOCK_SIZE;
self->super.crypt = ( (mode == CRYPTO_ENCRYPT)
? do_des_encrypt
: do_des_decrypt);
if (des_set_key(&self->ctx, pkey))
return &self->super;
switch(self->ctx.status)
{
case DES_BAD_PARITY:
fatal("Internal error! Bad parity in make_des_instance.\n");
case DES_WEAK_KEY:
werror("Detected weak DES key.\n");
KILL(self);
return NULL;
default:
fatal("Internal error!\n");
}
}
struct crypto_algorithm crypto_des_algorithm =
{ STATIC_HEADER,
DES_BLOCK_SIZE, DES_KEY_SIZE, 0, make_des_instance };
struct crypto_algorithm *make_des3(void)
{
return crypto_cascade(3,
&crypto_des_algorithm,
crypto_invert(&crypto_des_algorithm),
&crypto_des_algorithm,
-1);
}
/* idea.c
*
* $Id$ */
/* lsh, an implementation of the ssh protocol
*
* Copyright (C) 1998 Balzs Scheidler, 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"
#ifdef WITH_IDEA
#include "idea.h"
#include <assert.h>
#include "idea.c.x"
/* GABA:
(class
(name idea_instance)
(super crypto_instance)
(vars
(ctx array UINT16 IDEA_KEYLEN)))
*/
static void do_idea_crypt(struct crypto_instance *s,
UINT32 length, const UINT8 *src, UINT8 *dst)
{
CAST(idea_instance, self, s);
FOR_BLOCKS(length, src, dst, IDEA_BLOCKSIZE)
idea_crypt(self->ctx, dst, src);
}
static struct crypto_instance *
make_idea_instance(struct crypto_algorithm *algorithm UNUSED, int mode,
const UINT8 *key, const UINT8 *iv UNUSED)
{
NEW(idea_instance, self);
idea_expand(self->ctx, key);
if (mode == CRYPTO_DECRYPT)
idea_invert(self->ctx, self->ctx);
self->super.block_size = IDEA_BLOCKSIZE;
self->super.crypt = do_idea_crypt;
return &self->super;
}
struct crypto_algorithm idea_algorithm =
{ STATIC_HEADER, IDEA_BLOCKSIZE, IDEA_KEYSIZE, 0, make_idea_instance };
#endif /* WITH_IDEA */
/* twofish.c
*
* $Id$ */
/* lsh, an implementation of the ssh protocol
*
* Copyright (C) 1999 Niels Mller, J.H.M. Dassen (Ray)
*
* 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/twofish.h"
#include <assert.h>
#include "twofish.c.x"
/* Twofish */
/* GABA:
(class
(name twofish_instance)
(super crypto_instance)
(vars
(ctx . "struct twofish_ctx")))
*/
static void
do_twofish_encrypt(struct crypto_instance *s,
UINT32 length, const UINT8 *src, UINT8 *dst)
{
CAST(twofish_instance, self, s);
twofish_encrypt(&self->ctx, length, dst, src);
}
static void
do_twofish_decrypt(struct crypto_instance *s,
UINT32 length, const UINT8 *src, UINT8 *dst)
{
CAST(twofish_instance, self, s);
twofish_decrypt(&self->ctx, length, dst, src);
}
static struct crypto_instance *
make_twofish_instance(struct crypto_algorithm *algorithm, int mode,
const UINT8 *key, const UINT8 *iv UNUSED)
{
NEW(twofish_instance, self);
self->super.block_size = TWOFISH_BLOCK_SIZE;
self->super.crypt = ( (mode == CRYPTO_ENCRYPT)
? do_twofish_encrypt
: do_twofish_decrypt);
/* We don't have to deal with weak keys - being an AES candidate, Twofish was
* designed to have none. */
twofish_set_key(&self->ctx, algorithm->key_size, key);
return &self->super;
}
struct crypto_algorithm *
make_twofish_algorithm(UINT32 key_size)
{
NEW(crypto_algorithm, algorithm);
assert(key_size <= TWOFISH_MAX_KEY_SIZE);
assert(key_size >= TWOFISH_MIN_KEY_SIZE);
algorithm->block_size = TWOFISH_BLOCK_SIZE;
algorithm->key_size = key_size;
algorithm->iv_size = 0;
algorithm->make_crypt = make_twofish_instance;
return algorithm;
}
struct crypto_algorithm twofish128_algorithm =
{ STATIC_HEADER, TWOFISH_BLOCK_SIZE, 16, 0, make_twofish_instance};
struct crypto_algorithm twofish192_algorithm =
{ STATIC_HEADER, TWOFISH_BLOCK_SIZE, 24, 0, make_twofish_instance};
struct crypto_algorithm twofish256_algorithm =
{ STATIC_HEADER, TWOFISH_BLOCK_SIZE, 32, 0, make_twofish_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