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

* src/crypto.c (crypto_blowfish_cbc_algorithm): New algorithm,

replacing the code in blowfish.c.

Rev: src/algorithms.c:1.26
Rev: src/crypto.c:1.29
Rev: src/crypto.h:1.28
parent c8ee3687
......@@ -51,7 +51,7 @@ all_symmetric_algorithms()
#endif
,
ATOM_ARCFOUR, &crypto_arcfour_algorithm,
ATOM_BLOWFISH_CBC, crypto_cbc(&blowfish_algorithm),
ATOM_BLOWFISH_CBC, &crypto_blowfish_cbc_algorithm,
ATOM_TWOFISH_CBC, &crypto_twofish256_cbc_algorithm,
ATOM_AES256_CBC, &crypto_aes256_cbc_algorithm,
ATOM_RIJNDAEL_CBC_LOCAL, &crypto_aes256_cbc_algorithm,
......
......@@ -30,6 +30,7 @@
#include "nettle/arcfour.h"
#include "nettle/aes.h"
#include "nettle/blowfish.h"
#include "nettle/des.h"
#include "nettle/twofish.h"
......@@ -242,3 +243,59 @@ struct crypto_algorithm crypto_twofish256_cbc_algorithm =
{ STATIC_HEADER,
TWOFISH_BLOCK_SIZE, 32, TWOFISH_BLOCK_SIZE, make_twofish_cbc_instance};
/* Blowfish */
/* GABA:
(class
(name blowfish_instance)
(super crypto_instance)
(vars
(ctx . "struct CBC_CTX(struct blowfish_ctx, BLOWFISH_BLOCK_SIZE)")))
*/
static void
do_blowfish_encrypt(struct crypto_instance *s,
UINT32 length, const UINT8 *src, UINT8 *dst)
{
CAST(blowfish_instance, self, s);
CBC_ENCRYPT(&self->ctx, blowfish_encrypt, length, dst, src);
}
static void
do_blowfish_decrypt(struct crypto_instance *s,
UINT32 length, const UINT8 *src, UINT8 *dst)
{
CAST(blowfish_instance, self, s);
CBC_DECRYPT(&self->ctx, blowfish_decrypt, length, dst, src);
}
static struct crypto_instance *
make_blowfish_cbc_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);
CBC_SET_IV(&self->ctx, iv);
if (blowfish_set_key(&self->ctx.ctx, algorithm->key_size, key))
return(&self->super);
else
{
werror("Detected a weak blowfish key!\n");
KILL(self);
return NULL;
}
}
struct crypto_algorithm crypto_blowfish_cbc_algorithm =
{ STATIC_HEADER,
BLOWFISH_BLOCK_SIZE, BLOWFISH_KEY_SIZE, BLOWFISH_BLOCK_SIZE,
make_blowfish_cbc_instance};
......@@ -47,8 +47,12 @@ extern struct crypto_algorithm crypto_des3_cbc_algorithm;
struct crypto_algorithm *make_cast_algorithm(UINT32 key_size);
extern struct crypto_algorithm cast128_algorithm;
#if 0
struct crypto_algorithm *make_blowfish_algorithm(UINT32 key_size);
extern struct crypto_algorithm blowfish_algorithm;
#endif
extern struct crypto_algorithm crypto_blowfish_cbc_algorithm;
#if 0
struct crypto_algorithm *make_twofish_algorithm(UINT32 key_size);
......
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