Commit c279e56b authored by J.H.M. Dassen's avatar J.H.M. Dassen Committed by Niels Möller

Initial twofish support

Rev: AUTHORS:1.7
Rev: src/Makefile.am.in:1.34
Rev: src/algorithms.c:1.4
Rev: src/atoms.in:1.5
Rev: src/crypto.c:1.22
Rev: src/crypto.h:1.13
Rev: src/symmetric/Makefile.am.in:1.14
Rev: src/twofish.c:1.1
parent 655ffcdc
......@@ -3,6 +3,8 @@ conditions of the GNU General Public License (see the file COPYING for
details). But many other people have written free code which is used
in lsh.
TWOFISH implementation by Ruud de Rooij. Released under the LGPL.
BLOWFISH implementation from Werner Koch's and FSF's GNU Privacy
Guard. Released under the GPL.
......
......@@ -51,7 +51,7 @@ liblsh_a_SOURCES = abstract_io.c abstract_crypto.c abstract_compress.c \
sexp.c sexp_parser.c sexp_streamed_parser.c \
sha.c service.c ssh1_fallback.c \
string_buffer.c \
translate_signal.c tty.c unpad.c userauth.c \
translate_signal.c tty.c twofish.c unpad.c userauth.c \
werror.c write_buffer.c xalloc.c zlib.c
atoms_defines.h: atoms.in process_atoms
......
......@@ -37,7 +37,7 @@ struct alist *many_algorithms(unsigned n, ...)
va_list args;
struct alist *a
= make_alist(5
= make_alist(6
#if WITH_CAST
+1
#endif
......@@ -50,6 +50,7 @@ struct alist *many_algorithms(unsigned n, ...)
,
ATOM_ARCFOUR, &crypto_arcfour_algorithm,
ATOM_BLOWFISH_CBC, crypto_cbc(make_blowfish()),
ATOM_TWOFISH_CBC, crypto_cbc(make_twofish()),
ATOM_3DES_CBC, crypto_cbc(make_des3()),
#if WITH_CAST
ATOM_CAST128_CBC, crypto_cbc(make_cast()),
......@@ -100,6 +101,8 @@ int lookup_crypto(struct alist *algorithms, char *name)
if (strcmp_list(name, "arcfour", NULL))
atom = ATOM_ARCFOUR;
else if (strcmp_list(name, "twofish-cbc", "twofish", NULL))
atom = ATOM_TWOFISH_CBC;
else if (strcmp_list(name, "blowfish-cbc", "blowfish", NULL))
atom = ATOM_BLOWFISH_CBC;
else if (strcmp_list(name, "3des-cbc", "3des", NULL))
......
......@@ -10,6 +10,7 @@ zlib
3des-cbc REQUIRED three-key 3DES in CBC mode
blowfish-cbc RECOMMENDED Blowfish in CBC mode
twofish-cbc RECOMMENDED TwoFish cipher in CBC mode
arcfour OPTIONAL the ARCFOUR stream cipher
idea-cbc OPTIONAL IDEA in CBC mode
cast128-cbc OPTIONAL CAST-128 in CBC mode
......@@ -19,7 +20,6 @@ cast128-cbc OPTIONAL CAST-128 in CBC mode
## some of them will probably be included in an updated secsh draft.
##
#twofish-cbc OPTIONAL TwoFish cipher in CBC mode
#des-cbc OPTIONAL DES cipher in CBC mode
## NOTE: Is there any reason to ever use any chaining mode but cbc in
......
......@@ -28,6 +28,7 @@
#include "werror.h"
#include "xalloc.h"
#include "twofish.h"
#include "blowfish.h"
#include "des.h"
#include "sha.h"
......
......@@ -38,6 +38,8 @@
extern struct crypto_algorithm crypto_arcfour_algorithm;
extern struct crypto_algorithm crypto_des_algorithm;
struct crypto_algorithm *make_twofish_algorithm(UINT32 key_size);
struct crypto_algorithm *make_twofish(void);
struct crypto_algorithm *make_blowfish_algorithm(UINT32 key_size);
struct crypto_algorithm *make_blowfish(void);
struct crypto_algorithm *make_des3(void);
......
......@@ -26,7 +26,7 @@ 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
sha.c md5.c idea.c arcfour.c cast.c blowfish.c twofish.c
# Generate DES headers.
$(des_headers): desdata
......
/* 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 "twofish.h"
#include <assert.h>
#include "twofish.c.x"
/* Twofish */
/* CLASS:
(class
(name twofish_instance)
(super crypto_instance)
(vars
(ctx pointer "TWOFISH_context")))
*/
static void do_twofish_encrypt(struct crypto_instance *s,
UINT32 length, const UINT8 *src, UINT8 *dst)
{
CAST(twofish_instance, self, s);
FOR_BLOCKS(length, src, dst, TWOFISH_BLOCKSIZE)
twofish_encrypt(&self->ctx, src, dst);
}
static void do_twofish_decrypt(struct crypto_instance *s,
UINT32 length, const UINT8 *src, UINT8 *dst)
{
CAST(twofish_instance, self, s);
FOR_BLOCKS(length, src, dst, TWOFISH_BLOCKSIZE)
twofish_decrypt(&self->ctx, src, dst);
}
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_BLOCKSIZE;
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. */
self->ctx = twofish_setup(algorithm->key_size, key);
if (!self->ctx) {
werror("Twofish key setup failed!\n");
KILL(self);
return NULL;
}
return &self->super;
}
struct crypto_algorithm *make_twofish_algorithm(UINT32 key_size)
{
NEW(crypto_algorithm, algorithm);
assert(key_size <= TWOFISH_MAX_KEYSIZE);
assert(key_size >= TWOFISH_MIN_KEYSIZE);
algorithm->block_size = TWOFISH_BLOCKSIZE;
algorithm->key_size = key_size;
algorithm->iv_size = 0;
algorithm->make_crypt = make_twofish_instance;
return algorithm;
}
struct crypto_algorithm *make_twofish(void)
{
return make_twofish_algorithm(TWOFISH_KEYSIZE);
}
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