Commit bf0bd554 authored by J.H.M. Dassen's avatar J.H.M. Dassen Committed by Niels Möller
Browse files

GPG blowfish implementation integrated by jdassen@wi.leidenuniv.nl.

Rev: src/crypto.c:1.16
Rev: src/crypto.h:1.8
Rev: src/symmetric/blowfish.c:1.1
Rev: src/symmetric/include/blowfish.h:1.1
Rev: src/symmetric/include/types.h:1.1
Rev: src/symmetric/util.c:1.1
Rev: src/symmetric/util.h:1.1
parent 557c3354
......@@ -30,6 +30,7 @@
#include "crypto.h"
#include "sha.h"
#include "rc4.h"
#include "blowfish.h"
#include "werror.h"
#include "xalloc.h"
......@@ -55,7 +56,7 @@ static void do_crypt_rc4(struct crypto_instance *s,
}
static struct crypto_instance *
make_rc4_instance(struct crypto_algorithm *ignored, int mode, UINT8 *key)
make_rc4_instance(UNUSED struct crypto_algorithm *ignored, int mode, UINT8 *key)
{
NEW(rc4_instance, self);
......@@ -70,6 +71,83 @@ make_rc4_instance(struct crypto_algorithm *ignored, int mode, UINT8 *key)
struct crypto_algorithm crypto_rc4_algorithm =
{ STATIC_HEADER,
8, 16, make_rc4_instance };
/* Blowfish */
/* CLASS:
(class
(name blowfish_instance)
(super crypto_instance)
(vars
(ctx simple "BLOWFISH_context")))
*/
static int (*bf_setkey)( void *c, const byte *key, unsigned keylen ) = NULL;
static void (*bf_encrypt)( void *c, byte *outbuf, const byte *inbuf ) = NULL;
static void (*bf_decrypt)( void *c, byte *outbuf, const byte *inbuf ) = NULL;
static void bf_init(void) {
size_t keylen, blocksize, contextsize;
if (!bf_setkey) {
blowfish_get_info(
CIPHER_ALGO_BLOWFISH,
&keylen,
&blocksize,
&contextsize,
&bf_setkey,
&bf_encrypt,
&bf_decrypt
);
}
}
static void blowfish_set_key(BLOWFISH_context *ctx, const UINT8 *key,
UINT32 len) {
bf_setkey((void *) ctx, key, len );
}
static void blowfish_crypt(BLOWFISH_context *ctx, UINT8 *dest,
const UINT8 *src, UINT32 len) {
bf_encrypt((void *) ctx, dest, src);
}
static void do_crypt_blowfish(struct crypto_instance *s,
UINT32 length, UINT8 *src, UINT8 *dst)
{
/* struct blowfish_instance *self = (struct blowfish_instance *) s; */
CAST(blowfish_instance, self, s);
if (length % 8)
fatal("Internal error\n");
blowfish_crypt(&self->ctx, dst, src, length);
}
static struct crypto_instance *
make_blowfish_instance(UNUSED struct crypto_algorithm *ignored, int mode,
UINT8 *key)
{
/* struct blowfish_instance *self; */
NEW(blowfish_instance, self);
bf_init();
self->super.block_size = 8;
self->super.crypt = do_crypt_blowfish;
blowfish_set_key(&self->ctx, key, 16);
return &self->super;
}
struct crypto_algorithm crypto_blowfish_algorithm =
{ STATIC_HEADER,
8, 16, make_blowfish_instance };
/* SHA1 hash */
/* CLASS:
......@@ -103,7 +181,8 @@ static struct hash_instance *do_sha_copy(struct hash_instance *s)
return &CLONE(sha_instance, s)->super;
}
static struct hash_instance *make_sha_instance(struct hash_algorithm *ignored)
static struct hash_instance *make_sha_instance(
UNUSED struct hash_algorithm *ignored)
{
NEW(sha_instance, res);
......@@ -186,7 +265,7 @@ static struct mac_instance *make_hmac_instance(struct mac_algorithm *s,
CAST(hmac_algorithm, self, s);
NEW(hmac_instance, instance);
UINT8 *pad = alloca(self->hash->block_size);
int i;
UINT32 i;
instance->super.hash_size = self->super.hash_size;
instance->super.update = do_hmac_update;
......
......@@ -29,6 +29,7 @@
#include "abstract_crypto.h"
extern struct crypto_algorithm crypto_rc4_algorithm;
extern struct crypto_algorithm crypto_blowfish_algorithm;
extern struct hash_algorithm sha_algorithm;
......
This diff is collapsed.
/* blowfish.h
* Copyright (C) 1998 Free Software Foundation, Inc.
*
* This file is part of GNUPG.
*
* GNUPG 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.
*
* GNUPG 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
*/
/*
* Modifications for lsh by Ray Dassen
*/
#ifndef G10_BLOWFISH_H
#define G10_BLOWFISH_H
#include "types.h"
#define CIPHER_ALGO_BLOWFISH 4 /* blowfish 128 bit key */
#define BLOWFISH_ROUNDS 16
typedef struct {
u32 s0[256];
u32 s1[256];
u32 s2[256];
u32 s3[256];
u32 p[BLOWFISH_ROUNDS+2];
} BLOWFISH_context;
const char *
blowfish_get_info( int algo, size_t *keylen,
size_t *blocksize, size_t *contextsize,
int (**setkey)( void *c, const byte *key, unsigned keylen ),
void (**encrypt)( void *c, byte *outbuf, const byte *inbuf ),
void (**decrypt)( void *c, byte *outbuf, const byte *inbuf )
);
#endif /*G10_BLOWFISH_H*/
#ifndef _TYPES_H
#define _TYPES_H
/* Define types for GPG code */
#include "lsh_types.h"
typedef UINT8 byte;
typedef UINT32 u32;
#endif /* _TYPES_H */
#include "util.h"
#include <stdarg.h> /* For the va_* stuff */
#include <stdlib.h> /* For EXIT_FAILURE */
#include "../werror.h"
void log_bug(const char *format, ... ) {
va_list args;
va_start(args, format);
werror(format, args);
va_end(args);
}
void log_error(const char *format, ... ) {
va_list args;
va_start(args, format);
werror(format, args);
va_end(args);
}
void log_fatal(const char *format, ... ) {
va_list args;
va_start(args, format);
log_error(format, args);
va_end(args);
exit(EXIT_FAILURE);
}
#ifndef _UTIL_H
#define _UTIL_H
/* Bridge from GPG style to lsh style */
#include "lsh_types.h"
/* Report a bug (TODO: do what afterwards? ) */
void log_bug(const char *fmt, ... ) PRINTF_STYLE(1,2);
/* Report an error */
void log_error(const char *fmt, ... ) PRINTF_STYLE(1,2);
/* Report a fatal error and die */
void log_fatal(const char *fmt, ... ) PRINTF_STYLE(1,2) NORETURN;
#ifndef G10ERR_WEAK_KEY
#define G10ERR_WEAK_KEY 43
#elif G10ERR_WEAK_KEY != 43
#error G10ERR_WEAK_KEY is defined to a wrong value.
#endif
#endif /* _UTIL_H */
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