# Reset VPATH
SRCDIR=@srcdir@
-VPATH=$(SRCDIR):$(SRCDIR)/../include
-
-CRYPTO_INCLUDES=$(SRCDIR)/../include
-
-# Additional C preprocessor flags
-PREFLAGS=$(EXTRA_CPP_FLAGS) -I$(CRYPTO_INCLUDES) -I. -I$(SRCDIR) $(DEFINES)
+VPATH=$(SRCDIR):$(EXTRA_VPATH)
# The flags to generate a shared library
-CFLAGS=$(PREFLAGS) $(OTHERFLAGS) $(EXTRA_CFLAGS)
+CPPFLAGS=$(PREFLAGS) $(DEFS) $(EXTRA_CPPFLAGS)
LDFLAGS=@LDFLAGS@
default: algorithms.a
# test all performance enhancement flags
sure:
- make clean ; make desTest 'CPPFLAGS=-Di386 -Umc68000 -Usparc'
- make clean ; make desTest 'CPPFLAGS=-Dvax -Umc68000 -Usparc'
+ make clean ; make desTest 'CPPFLAGS=-Di386 -Umc68000 -Usparc'
+ make clean ; make desTest 'CPPFLAGS=-Dvax -Umc68000 -Usparc'
make clean ; make desTest 'CPPFLAGS=-Dmc68000 -Usparc'
make clean ; make desTest 'CPPFLAGS=-Dsparc -Umc68000'
make clean ; make desTest
### End of rules for desCore
-# BEGIN NATIONAL SECURITY
-MASS_DESTRUCTION_OBJS = idea.o rc4.o cast.o $(O)
-# END NATIONAL SECURITY
-
-OBJS = $(MASS_DESTRUCTION_OBJS) sha.o md5.o
+SRCS = sha.c md5.c idea.c rc4.c cast.c $(SC) $(GC)
+OBJS = $(SRCS:.c=.o)
algorithms.a: $(OBJS)
rm -f algorithms.a
$(AR) cru algorithms.a $(OBJS)
$(RANLIB) algorithms.a
-Makefile: $(SRCDIR)/Makefile.in config.status
- CONFIG_FILES=Makefile CONFIG_HEADERS="" ./config.status
- @echo "Run make again"
- @exit 1
+#### Remaking the Makefile and configure scripts. ####
+
+#${srcdir}/configure: configure.in aclocal.m4
+${srcdir}/configure: configure.in
+ cd ${srcdir} && autoconf
+
+# autoheader might not change config.h.in, so touch a stamp file.
+${srcdir}/config.h.in: stamp-h.in
+
+#${srcdir}/stamp-h.in: configure.in aclocal.m4 acconfig.h \
+# config.h.top config.h.bot
+
+${srcdir}/stamp-h.in: configure.in
+ cd ${srcdir} && autoheader
+ echo timestamp > ${srcdir}/stamp-h.in
+
+config.h: stamp-h
+
+stamp-h: config.h.in config.status
+ ./config.status
+
+Makefile: Makefile.in config.status
+ ./config.status
+
+config.status: configure
+ ./config.status --recheck
+%.d: %.c
+ $(SHELL) -ec '$(CC) -MM -MG $(CPPFLAGS) $(DEFS) $< \
+ | sed '\''s/\($*\)\.o:/\1\.o $@ : /g'\'' > $@'
#include <cast.h>
-#define u8 unsigned INT8
-#define u32 unsigned INT32
+#define u8 UINT8
+#define u32 UINT32
#include "cast_sboxes.h"
+dnl Process this file with autoconf to produce a configure script.
+
# $Id$
AC_INIT(sha.c)
+AC_PROG_MAKE_SET
+
AC_PROG_CC
AC_PROG_CPP
AC_PROG_RANLIB
+dnl Checks for libraries.
+
+dnl Checks for header files.
+AC_HEADER_STDC
+AC_CHECK_HEADERS(sys/time.h)
+
+dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
+dnl Checks for library functions.
+AC_FUNC_MEMCMP
+
AC_OUTPUT(Makefile)
#include "RCSID.h"
RCSID2(desCode_hRcs, "$Id$");
-extern unsigned INT32 des_keymap[], des_bigmap[];
+extern UINT32 des_keymap[], des_bigmap[];
/* optional customization:
* the idea here is to alter the code so it will still run correctly
* a macro definition that the users of the function doesn't
* know about. - Niels */
#if 0 /* didn't feel like deleting */
-#define SREGFREE ; s = (unsigned INT8 *) D
+#define SREGFREE ; s = (UINT8 *) D
#define DEST s
#define D m0
-#define BYTE unsigned INT32
+#define BYTE UINT32
#else
#define SREGFREE
#define DEST d
#define D d
-#define BYTE unsigned INT8
+#define BYTE UINT8
#endif
/* handle constants in the optimal way for 386 & vax */
#define LS2(z) k1 & z
#define LS3(z) k2 & z
#define REGQUICK \
- register unsigned INT32 k0, k1; \
- register unsigned INT32 *m0, *m1, *m2, *m3;
+ register UINT32 k0, k1; \
+ register UINT32 *m0, *m1, *m2, *m3;
#define SETQUICK \
; k0 = 0XFCFC \
; k1 = 16 \
; m2 = m1 + 64 \
; m3 = m2 + 64
#define REGSMALL \
- register unsigned INT32 k0, k1, k2; \
- register unsigned INT32 *m0, *m1, *m2, *m3;
+ register UINT32 k0, k1, k2; \
+ register UINT32 *m0, *m1, *m2, *m3;
#define SETSMALL \
; k0 = 0X01000100L \
; k1 = 0X0FC \
#define LS2(z) 0XFC & z
#define LS3(z) 0XFC & z
#define REGQUICK \
- register unsigned INT32 k0; \
- register unsigned INT32 *m0, *m1, *m2, *m3;
+ register UINT32 k0; \
+ register UINT32 *m0, *m1, *m2, *m3;
#define SETQUICK \
; k0 = 0XFCFC \
; m0 = des_bigmap \
; m2 = m1 + 64 \
; m3 = m2 + 64
#define REGSMALL \
- register unsigned INT32 *m0, *m1, *m2, *m3, *m4, *m5, *m6, *m7;
+ register UINT32 *m0, *m1, *m2, *m3, *m4, *m5, *m6, *m7;
#define SETSMALL \
; m0 = des_keymap \
; m1 = m0 + 64 \
/* some basic stuff */
/* generate addresses from a base and an index */
-#define ADD(b,x) (unsigned INT32 *) ((unsigned INT8 *)b + (x))
+#define ADD(b,x) (UINT32 *) ((UINT8 *)b + (x))
/* low level rotate operations */
#define NOP(d,c,o)
\
void \
NAME(REGISTER BYTE *D, \
- REGISTER unsigned INT32 *r, \
- REGISTER unsigned INT8 *s) \
+ REGISTER UINT32 *r, \
+ REGISTER UINT8 *s) \
{ \
- register unsigned INT32 x, y, z; \
+ register UINT32 x, y, z; \
\
/* declare temps & load data */ \
TEMP(LOAD); \
\
void \
NAME(REGISTER BYTE *D, \
- REGISTER unsigned INT32 *r, \
- REGISTER unsigned INT8 *s) \
+ REGISTER UINT32 *r, \
+ REGISTER UINT8 *s) \
{ \
- register unsigned INT32 x, y, z; \
+ register UINT32 x, y, z; \
\
/* declare temps & load data */ \
TEMP(LOAD); \
/* kerberos-compatible key schedule function */
int
-des_key_sched(unsigned INT8 *k, unsigned INT32 *s)
+des_key_sched(UINT8 *k, UINT32 *s)
{
return DesMethod(s, k);
}
/* kerberos-compatible des coding function */
int
-des_ecb_encrypt(unsigned INT8 *s, unsigned INT8 *d, unsigned INT32 *r, int e)
+des_ecb_encrypt(UINT8 *s, UINT8 *d, UINT32 *r, int e)
{
(*DesCryptFuncs[e])(d, r, s);
return 0;
#include "RCSID.h"
RCSID2(desQuick_cRcs, "$Id$");
-extern unsigned INT32 des_keymap[];
+extern UINT32 des_keymap[];
/* static information */
static int depth = 0; /* keep track of the request depth */
-unsigned INT32 des_bigmap[0x4000]; /* big lookup table */
+UINT32 des_bigmap[0x4000]; /* big lookup table */
/* fill in the 64k table used by the `quick' option */
DesQuickInit(void)
{
int s1, s3, x;
- unsigned INT32 * t0, * t1, * t2, * t3;
+ UINT32 * t0, * t1, * t2, * t3;
if ( depth++ )
return;
/* various tables */
-unsigned INT32 des_keymap[] = {
+UINT32 des_keymap[] = {
#include "keymap.h"
};
-static unsigned INT8 rotors[] = {
+static UINT8 rotors[] = {
#include "rotors.h"
};
static char parity[] = {
/* set up the method list from the key */
int
-DesMethod(unsigned INT32 *method, unsigned INT8 *k)
+DesMethod(UINT32 *method, UINT8 *k)
{
- register unsigned INT32 n, w;
+ register UINT32 n, w;
register char * b0, * b1;
char bits0[56], bits1[56];
int
main(int argc, char **argv)
{
- unsigned INT32 d, i, j, k, l, m, n, s;
+ UINT32 d, i, j, k, l, m, n, s;
char b[256], ksr[56];
switch ( argv[1][0] ) {
* compiler doesn't schedule branches.
*/
#ifdef SMALL_CACHE
-const static unsigned INT16
-mul(unsigned INT16 a, unsigned INT16 b)
+const static UINT16
+mul(UINT16 a, UINT16 b)
{
- register unsigned INT32 p;
+ register UINT32 p;
- p = (unsigned INT32)a * b;
+ p = (UINT32)a * b;
if (p)
{
b = low16(p);
* algorithm. It is unrolled twice to avoid swapping the registers each
* iteration, and some subtracts of t have been changed to adds.
*/
-static const unsigned INT16
-inv(unsigned INT16 x)
+static const UINT16
+inv(UINT16 x)
{
- unsigned INT16 t0, t1;
- unsigned INT16 q, y;
+ UINT16 t0, t1;
+ UINT16 q, y;
if (x <= 1)
return x; /* 0 and 1 are self-inverse */
* Expand a 128-bit user key to a working encryption key ctx
*/
void
-idea_expand(unsigned INT16 *ctx,
- const unsigned INT8 *userkey)
+idea_expand(UINT16 *ctx,
+ const UINT8 *userkey)
{
int i,j;
* inverted into an internal buffer, and then copied to the output.
*/
void
-idea_invert(unsigned INT16 *d,
- const unsigned INT16 *e)
+idea_invert(UINT16 *d,
+ const UINT16 *e)
{
int i;
- unsigned INT16 t1, t2, t3;
- unsigned INT16 temp[IDEA_KEYLEN];
- unsigned INT16 *p = temp + IDEA_KEYLEN;
+ UINT16 t1, t2, t3;
+ UINT16 temp[IDEA_KEYLEN];
+ UINT16 *p = temp + IDEA_KEYLEN;
t1 = inv(*e++);
t2 = -*e++;
#else /* !SMALL_CACHE */
#ifdef AVOID_JUMPS
#define MUL(x,y) (x = low16(x-1), t16 = low16((y)-1), \
- t32 = (unsigned INT32)x*t16 + x + t16 + 1, x = low16(t32), \
+ t32 = (UINT32)x*t16 + x + t16 + 1, x = low16(t32), \
t16 = t32>>16, x = (x-t16) + (x<t16) )
#else /* !AVOID_JUMPS (default) */
#define MUL(x,y) \
((t16 = (y)) ? \
(x=low16(x)) ? \
- t32 = (unsigned INT32)x*t16, \
+ t32 = (UINT32)x*t16, \
x = low16(t32), \
t16 = t32>>16, \
x = (x-t16)+(x<t16) \
/* IDEA encryption/decryption algorithm */
/* Note that in and out can be the same buffer */
void
-idea_crypt(const unsigned INT16 *key,
- unsigned INT8 *dest,
- const unsigned INT8 *src)
+idea_crypt(const UINT16 *key,
+ UINT8 *dest,
+ const UINT8 *src)
{
- register unsigned INT16 x1, x2, x3, x4, s2, s3;
+ register UINT16 x1, x2, x3, x4, s2, s3;
/* Setup */
/* Encrypt */
{
#ifndef SMALL_CACHE
- register unsigned INT16 t16; /* Temporaries needed by MUL macro */
- register unsigned INT32 t32;
+ register UINT16 t16; /* Temporaries needed by MUL macro */
+ register UINT32 t32;
#endif
int r = IDEA_ROUNDS;
do
#include "crypto_types.h"
struct cast_key {
- unsigned INT32 xkey[32]; /* Key, after expansion */
+ UINT32 xkey[32]; /* Key, after expansion */
unsigned rounds; /* Number of rounds to use, 12 or 16 */
};
-void cast_setkey(struct cast_key *key, unsigned INT8 *rawkey,
+void cast_setkey(struct cast_key *key, UINT8 *rawkey,
unsigned keybytes);
-void cast_encrypt(struct cast_key *key, unsigned INT8 *inblock,
- unsigned INT8 *outblock);
-void cast_decrypt(struct cast_key *key, unsigned INT8 *inblock,
- unsigned INT8* outblock);
+void cast_encrypt(struct cast_key *key, UINT8 *inblock,
+ UINT8 *outblock);
+void cast_decrypt(struct cast_key *key, UINT8 *inblock,
+ UINT8* outblock);
#endif /* ifndef _CAST_H_INCLUDED */
/* $Id$
*
- * Defines the types INT32 and INT8 */
+ * Defines the types UINT32, UINT16 and UINT8 */
#ifndef CRYPTO_TYPES_H_INCLUDED
#define CRYPTO_TYPES_H_INCLUDED
#ifdef PIKE
#include "pike_types.h"
#include "global.h"
-#else /* !PIKE */
-#define INT32 long
-#define INT16 short
-#define INT8 char
+#define UINT32 unsigned INT32
+#define UINT16 unsigned INT16
+#define UINT8 unsigned INT8
+#else /* !PIKE */
+#ifdef LSH
+#include "lsh_types.h"
+#else /* !LSH */
+#define UINT32 unsigned long
+#define UINT16 unsigned short
+#define UINT8 unsigned char
+#endif
#endif
#endif /* CRYPTO_TYPES_H_INCLUDED */
#define DES_BLOCKSIZE 8
#define DES_EXPANDED_KEYLEN 32
-typedef unsigned INT8 DesData[DES_BLOCKSIZE];
-typedef unsigned INT32 DesKeys[DES_EXPANDED_KEYLEN];
-typedef void DesFunc(unsigned INT8 *d, unsigned INT32 *r, unsigned INT8 *s);
+typedef UINT8 DesData[DES_BLOCKSIZE];
+typedef UINT32 DesKeys[DES_EXPANDED_KEYLEN];
+typedef void DesFunc(UINT8 *d, UINT32 *r, UINT8 *s);
-extern int DesMethod(unsigned INT32 *method, unsigned INT8 *k);
+extern int DesMethod(UINT32 *method, UINT8 *k);
extern void DesQuickInit(void);
extern void DesQuickDone(void);
extern DesFunc DesQuickCoreEncrypt;
extern DesFunc DesSmallFipsDecrypt;
extern DesFunc *DesCryptFuncs[2];
-extern int des_key_sched(unsigned INT8 *k, unsigned INT32 *s);
-extern int des_ecb_encrypt(unsigned INT8 *s, unsigned INT8 *d, unsigned INT32 *r, int e);
+extern int des_key_sched(UINT8 *k, UINT32 *s);
+extern int des_ecb_encrypt(UINT8 *s, UINT8 *d, UINT32 *r, int e);
#endif /* DES_H_INCLUDED */
#include "crypto_types.h"
-void idea_expand(unsigned INT16 *ctx,
- const unsigned INT8 *key);
+void idea_expand(UINT16 *ctx,
+ const UINT8 *key);
-void idea_invert(unsigned INT16 *d,
- const unsigned INT16 *e);
+void idea_invert(UINT16 *d,
+ const UINT16 *e);
-void idea_crypt(const unsigned INT16 *ctx,
- unsigned INT8 *dest,
- const unsigned INT8 *src);
+void idea_crypt(const UINT16 *ctx,
+ UINT8 *dest,
+ const UINT8 *src);
#endif /* IDEA_H_INCLUDED */
#define MD5_DIGESTLEN 4
struct md5_ctx {
- unsigned INT32 digest[MD5_DIGESTLEN]; /* Digest */
- unsigned INT32 count_l, count_h; /* Block count */
- unsigned INT8 block[MD5_DATASIZE]; /* One block buffer */
+ UINT32 digest[MD5_DIGESTLEN]; /* Digest */
+ UINT32 count_l, count_h; /* Block count */
+ UINT8 block[MD5_DATASIZE]; /* One block buffer */
int index; /* index into buffer */
};
void md5_init(struct md5_ctx *ctx);
-void md5_update(struct md5_ctx *ctx, unsigned INT8 *buffer, unsigned INT32 len);
+void md5_update(struct md5_ctx *ctx, UINT8 *buffer, UINT32 len);
void md5_final(struct md5_ctx *ctx);
-void md5_digest(struct md5_ctx *ctx, INT8 *s);
+void md5_digest(struct md5_ctx *ctx, UINT8 *s);
void md5_copy(struct md5_ctx *dest, struct md5_ctx *src);
#include "crypto_types.h"
struct rc4_ctx {
- unsigned INT8 S[256];
- unsigned INT8 i, j;
+ UINT8 S[256];
+ UINT8 i, j;
};
#if 0
void rc4_init(struct rc4_ctx *ctx);
#endif
-void rc4_set_key(struct rc4_ctx *ctx, const unsigned INT8 *key, INT32 len);
-void rc4_crypt(struct rc4_ctx *ctx, unsigned INT8 *dest, const unsigned INT8 *src, INT32 len);
+void rc4_set_key(struct rc4_ctx *ctx, const UINT8 *key, UINT32 len);
+void rc4_crypt(struct rc4_ctx *ctx, UINT8 *dest, const UINT8 *src, UINT32 len);
#endif /* RC4_H_INCLUDED */
/* The structure for storing SHA info */
struct sha_ctx {
- unsigned INT32 digest[SHA_DIGESTLEN]; /* Message digest */
- unsigned INT32 count_l, count_h; /* 64-bit block count */
- unsigned INT8 block[SHA_DATASIZE]; /* SHA data buffer */
+ UINT32 digest[SHA_DIGESTLEN]; /* Message digest */
+ UINT32 count_l, count_h; /* 64-bit block count */
+ UINT8 block[SHA_DATASIZE]; /* SHA data buffer */
int index; /* index into buffer */
};
void sha_init(struct sha_ctx *ctx);
-void sha_update(struct sha_ctx *ctx, unsigned INT8 *buffer, unsigned INT32 len);
+void sha_update(struct sha_ctx *ctx, UINT8 *buffer, UINT32 len);
void sha_final(struct sha_ctx *ctx);
-void sha_digest(struct sha_ctx *ctx, INT8 *s);
+void sha_digest(struct sha_ctx *ctx, UINT8 *s);
void sha_copy(struct sha_ctx *dest, struct sha_ctx *src);
/* Perform the MD5 transformation on one full block of 16 32-bit words. */
-static void md5_transform(struct md5_ctx *ctx, unsigned INT32 *data)
+static void md5_transform(struct md5_ctx *ctx, UINT32 *data)
{
- unsigned INT32 a, b, c, d;
+ UINT32 a, b, c, d;
a = ctx->digest[0];
b = ctx->digest[1];
c = ctx->digest[2];
| EXTRACT_UCHAR(s+1)) << 8) \
| EXTRACT_UCHAR(s))
-static void md5_block(struct md5_ctx *ctx, unsigned INT8 *block)
+static void md5_block(struct md5_ctx *ctx, UINT8 *block)
{
- unsigned INT32 data[MD5_DATALEN];
+ UINT32 data[MD5_DATALEN];
int i;
/* Update block count */
}
void md5_update(struct md5_ctx *ctx,
- unsigned INT8 *buffer,
- unsigned INT32 len)
+ UINT8 *buffer,
+ UINT32 len)
{
if (ctx->index)
{ /* Try to fill partial block */
void md5_final(struct md5_ctx *ctx)
{
- unsigned INT32 data[MD5_DATALEN];
+ UINT32 data[MD5_DATALEN];
int i;
int words;
md5_transform(ctx, data);
}
-void md5_digest(struct md5_ctx *ctx, INT8 *s)
+void md5_digest(struct md5_ctx *ctx, UINT8 *s)
{
int i;
#define SWAP(a,b) do { int _t = a; a = b; b = _t; } while(0)
-void rc4_set_key(struct rc4_ctx *ctx, const unsigned INT8 *key, INT32 len)
+void rc4_set_key(struct rc4_ctx *ctx, const UINT8 *key, UINT32 len)
{
- register unsigned INT8 j; /* Depends on the eight-bitness of these variables. */
+ register UINT8 j; /* Depends on the eight-bitness of these variables. */
unsigned i;
- INT32 k;
+ UINT32 k;
/* Initialize context */
i = 0;
ctx->i = ctx->j = 0;
}
-void rc4_crypt(struct rc4_ctx *ctx, unsigned INT8 *dest, const unsigned INT8 *src, INT32 len)
+void rc4_crypt(struct rc4_ctx *ctx, UINT8 *dest, const UINT8 *src, UINT32 len)
{
- register unsigned INT8 i, j; /* Depends on the eight-bitness of these variables */
+ register UINT8 i, j;
i = ctx->i; j = ctx->j;
while(len--)
{
- i++;
- j += ctx->S[i];
+ i++; i &= 0xff;
+ j += ctx->S[i]; j &= 0xff;
SWAP(ctx->S[i], ctx->S[j]);
*dest++ = *src++ ^ ctx->S[ (ctx->S[i] + ctx->S[j]) & 0xff ];
}
Note that this function destroys the data area */
-static void sha_transform(struct sha_ctx *ctx, unsigned INT32 *data )
+static void sha_transform(struct sha_ctx *ctx, UINT32 *data )
{
- unsigned INT32 A, B, C, D, E; /* Local vars */
+ UINT32 A, B, C, D, E; /* Local vars */
/* Set up first buffer and local data buffer */
A = ctx->digest[0];
| EXTRACT_UCHAR(s+2)) << 8) \
| EXTRACT_UCHAR(s+3))
#else
-unsigned INT32 STRING2INT(unsigned INT8 *s)
+UINT32 STRING2INT(UINT8 *s)
{
- unsigned INT32 r;
+ UINT32 r;
int i;
for (i = 0, r = 0; i < 4; i++, s++)
}
#endif
-static void sha_block(struct sha_ctx *ctx, unsigned INT8 *block)
+static void sha_block(struct sha_ctx *ctx, UINT8 *block)
{
- unsigned INT32 data[SHA_DATALEN];
+ UINT32 data[SHA_DATALEN];
int i;
/* Update block count */
sha_transform(ctx, data);
}
-void sha_update(struct sha_ctx *ctx, unsigned INT8 *buffer, unsigned INT32 len)
+void sha_update(struct sha_ctx *ctx, UINT8 *buffer, UINT32 len)
{
if (ctx->index)
{ /* Try to fill partial block */
void sha_final(struct sha_ctx *ctx)
{
- unsigned INT32 data[SHA_DATALEN];
+ UINT32 data[SHA_DATALEN];
int i;
int words;
sha_transform(ctx, data);
}
-void sha_digest(struct sha_ctx *ctx, INT8 *s)
+void sha_digest(struct sha_ctx *ctx, UINT8 *s)
{
int i;