New files from libdes-3.23
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@515 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
35
lib/des/GNUmakefile
Normal file
35
lib/des/GNUmakefile
Normal file
@@ -0,0 +1,35 @@
|
||||
# This was GNUmakefile
|
||||
# I have changed the library a bit since I was last able to test the
|
||||
# build so this may require a little tweaking.
|
||||
# have fun.
|
||||
|
||||
ifeq ($(wildcard ../Rules),)
|
||||
# no glibc
|
||||
include Makefile.uni
|
||||
else
|
||||
# We are part of glibc
|
||||
default_cflags:= -O2
|
||||
subdir := des
|
||||
headers:= des.h rpc_des.h
|
||||
|
||||
routines:= $(destest)
|
||||
cbc3_enc cbc_cksm cbc_enc cfb64enc cfb_enc \
|
||||
ecb3_enc ecb_enc ede_enc enc_read enc_writ \
|
||||
fcrypt ncbc_enc ofb64enc ofb_enc pcbc_enc \
|
||||
qud_cksm rand_key read_pwd rpc_enc set_key \
|
||||
str2key cfb64ede ofb64ede supp
|
||||
distribute:= ARTISTIC COPYRIGHT FILES INSTALL Imakefile README VERSION \
|
||||
GNUmakefile times vms.com KERBEROS MODES.DES \
|
||||
des.man des_crypt.man \
|
||||
version.h des_locl.h podd.h sk.h spr.h \
|
||||
des.pl testdes.pl doIP doPC1 doPC2 PC1 PC2 shifts.pl \
|
||||
des.doc makefile.bc
|
||||
|
||||
tests:= destest speed
|
||||
override +gccwarn := -w
|
||||
others:= des rpw
|
||||
install:= des
|
||||
|
||||
include ../Rules
|
||||
endif
|
||||
|
155
lib/des/Makefile
Normal file
155
lib/des/Makefile
Normal file
@@ -0,0 +1,155 @@
|
||||
# You must select the correct terminal control system to be used to
|
||||
# turn character echo off when reading passwords. There a 5 systems
|
||||
# SGTTY - the old BSD system
|
||||
# TERMIO - most system V boxes
|
||||
# TERMIOS - SGI (ala IRIX).
|
||||
# VMS - the DEC operating system
|
||||
# MSDOS - we all know what it is :-)
|
||||
# read_pwd.c makes a reasonable guess at what is correct.
|
||||
|
||||
# If you are on a DEC Alpha, edit des.h and change the DES_LONG
|
||||
# define to 'unsigned int'. I have seen this give a %20 speedup.
|
||||
|
||||
OPTS0= -DRAND -DTERMIO #-DNOCONST
|
||||
|
||||
# Version 1.94 has changed the strings_to_key function so that it is
|
||||
# now compatible with MITs when the string is longer than 8 characters.
|
||||
# If you wish to keep the old version, uncomment the following line.
|
||||
# This will affect the -E/-D options on des(1).
|
||||
#OPTS1= -DOLD_STR_TO_KEY
|
||||
|
||||
# This #define specifies the use of an alternative D_ENCRYPT macro in
|
||||
# ecb_encrypt. The choice of macro can make a %20 difference in the
|
||||
# speed. Unfortunatly the choise of the best macro appears to be very
|
||||
# dependant on the compiler and the machine in question.
|
||||
# For the following combinations use the ALT_ECB option.
|
||||
# Sparc 2 (cc -O4), sun 3/260 (cc -O4)
|
||||
# For the following combinations do not use the ALT_ECB option.
|
||||
# Sparc 2 (gcc2 -O2), sun 3/260 (cc -O2), mvax2 (cc -O), MSDOS (Turbo Cv2)
|
||||
# For other machines, experiment with changing the option and run
|
||||
# ./speed to see which is faster.
|
||||
# DO NOT TURN THIS OPTION ON WHEN COMPILING THIS CODE ON A 64 BIT MACHINE
|
||||
# 12-Apr-1996 - It appears to be broken and I'm not bothering to fix
|
||||
# it right now, so don't use this option :-)
|
||||
#OPTS2= -DDES_PTR
|
||||
|
||||
OPTS= $(OPTS0) $(OPTS1) $(OPTS2)
|
||||
|
||||
#CC=cc
|
||||
#CFLAGS= -O $(OPTS) $(CFLAG)
|
||||
|
||||
CC=gcc
|
||||
CFLAGS= -O3 -fomit-frame-pointer $(OPTS) $(CFLAG)
|
||||
|
||||
LIBDIR=/usr/local/lib
|
||||
BINDIR=/usr/local/bin
|
||||
INCDIR=/usr/local/include
|
||||
MANDIR=/usr/local/man
|
||||
MAN1=1
|
||||
MAN3=3
|
||||
SHELL=/bin/sh
|
||||
OBJS= cbc3_enc.o cbc_cksm.o cbc_enc.o ncbc_enc.o pcbc_enc.o qud_cksm.o \
|
||||
cfb64ede.o cfb64enc.o cfb_enc.o ecb3_enc.o ecb_enc.o ede_enc.o \
|
||||
enc_read.o enc_writ.o fcrypt.o ofb64ede.o ofb64enc.o ofb_enc.o \
|
||||
rand_key.o read_pwd.o set_key.o rpc_enc.o str2key.o supp.o
|
||||
|
||||
GENERAL=COPYRIGHT FILES INSTALL Imakefile README VERSION Makefile \
|
||||
times vms.com KERBEROS MODES.DES GNUmakefile des.man \
|
||||
DES.pm DES.pod DES.xs Makefile.PL Makefile.uni typemap t \
|
||||
des_crypt.man Makefile.ssl des.doc makefile.bc des.org \
|
||||
des_locl.org
|
||||
DES= des.c
|
||||
TESTING=destest.c speed.c rpw.c
|
||||
HEADERS=version.h des.h des_locl.h podd.h sk.h spr.h rpc_des.h
|
||||
LIBDES= cbc3_enc.c cbc_cksm.c cbc_enc.c ncbc_enc.c pcbc_enc.c qud_cksm.c \
|
||||
cfb64ede.c cfb64enc.c cfb_enc.c ecb3_enc.c ecb_enc.c ede_enc.c \
|
||||
enc_read.c enc_writ.c fcrypt.c ofb64ede.c ofb64enc.c ofb_enc.c \
|
||||
rand_key.c read_pwd.c set_key.c rpc_enc.c str2key.c supp.c
|
||||
|
||||
PERL= des.pl testdes.pl doIP doPC1 doPC2 PC1 PC2 shifts.pl
|
||||
|
||||
ALL= $(GENERAL) $(DES) $(TESTING) $(LIBDES) $(PERL) $(HEADERS)
|
||||
|
||||
DLIB= libdes.a
|
||||
|
||||
all: $(DLIB) destest rpw des speed
|
||||
|
||||
test: all
|
||||
./destest
|
||||
|
||||
$(DLIB): $(OBJS)
|
||||
/bin/rm -f $(DLIB)
|
||||
ar cr $(DLIB) $(OBJS)
|
||||
-if test -s /bin/ranlib; then /bin/ranlib $(DLIB); \
|
||||
else if test -s /usr/bin/ranlib; then /usr/bin/ranlib $(DLIB); \
|
||||
else exit 0; fi; fi
|
||||
|
||||
destest: destest.o libdes.a
|
||||
$(CC) $(CFLAGS) -o destest destest.o libdes.a
|
||||
|
||||
rpw: rpw.o libdes.a
|
||||
$(CC) $(CFLAGS) -o rpw rpw.o libdes.a
|
||||
|
||||
speed: speed.o libdes.a
|
||||
$(CC) $(CFLAGS) -o speed speed.o libdes.a
|
||||
|
||||
des: des.o libdes.a
|
||||
$(CC) $(CFLAGS) -o des des.o libdes.a
|
||||
|
||||
tags:
|
||||
ctags $(DES) $(TESTING) $(LIBDES)
|
||||
|
||||
tar:
|
||||
tar chf libdes.tar $(ALL)
|
||||
|
||||
shar:
|
||||
shar $(ALL) >libdes.shar
|
||||
|
||||
depend:
|
||||
makedepend $(LIBDES) $(DES) $(TESTING)
|
||||
|
||||
clean:
|
||||
/bin/rm -f *.o tags core rpw destest des speed $(DLIB) .nfs* *.old \
|
||||
*.bak destest rpw des speed
|
||||
|
||||
dclean:
|
||||
sed -e '/^# DO NOT DELETE THIS LINE/ q' Makefile >Makefile.new
|
||||
mv -f Makefile.new Makefile
|
||||
|
||||
# Eric is probably going to choke when he next looks at this --tjh
|
||||
install: $(DLIB) des
|
||||
if test $(INSTALLTOP); then \
|
||||
echo SSL style install; \
|
||||
cp $(DLIB) $(INSTALLTOP)/lib; \
|
||||
if test -s /bin/ranlib; then \
|
||||
/bin/ranlib $(INSTALLTOP)/lib/$(DLIB); \
|
||||
else \
|
||||
if test -s /usr/bin/ranlib; then \
|
||||
/usr/bin/ranlib $(INSTALLTOP)/lib/$(DLIB); \
|
||||
fi; fi; \
|
||||
chmod 644 $(INSTALLTOP)/lib/$(DLIB); \
|
||||
cp des.h $(INSTALLTOP)/include; \
|
||||
chmod 644 $(INSTALLTOP)/include/des.h; \
|
||||
cp des $(INSTALLTOP)/bin; \
|
||||
chmod 755 $(INSTALLTOP)/bin/des; \
|
||||
else \
|
||||
echo Standalone install; \
|
||||
cp $(DLIB) $(LIBDIR)/$(DLIB); \
|
||||
if test -s /bin/ranlib; then \
|
||||
/bin/ranlib $(LIBDIR)/$(DLIB); \
|
||||
else \
|
||||
if test -s /usr/bin/ranlib; then \
|
||||
/usr/bin/ranlib $(LIBDIR)/$(DLIB); \
|
||||
fi; \
|
||||
fi; \
|
||||
chmod 644 $(LIBDIR)/$(DLIB); \
|
||||
cp des $(BINDIR)/des; \
|
||||
chmod 711 $(BINDIR)/des; \
|
||||
cp des_crypt.man $(MANDIR)/man$(MAN3)/des_crypt.$(MAN3); \
|
||||
chmod 644 $(MANDIR)/man$(MAN3)/des_crypt.$(MAN3); \
|
||||
cp des.man $(MANDIR)/man$(MAN1)/des.$(MAN1); \
|
||||
chmod 644 $(MANDIR)/man$(MAN1)/des.$(MAN1); \
|
||||
cp des.h $(INCDIR)/des.h; \
|
||||
chmod 644 $(INCDIR)/des.h; \
|
||||
fi
|
||||
# DO NOT DELETE THIS LINE -- make depend depends on it.
|
252
lib/des/des.org
Normal file
252
lib/des/des.org
Normal file
@@ -0,0 +1,252 @@
|
||||
/* lib/des/des.h */
|
||||
/* Copyright (C) 1995 Eric Young (eay@mincom.oz.au)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of an SSL implementation written
|
||||
* by Eric Young (eay@mincom.oz.au).
|
||||
* The implementation was written so as to conform with Netscapes SSL
|
||||
* specification. This library and applications are
|
||||
* FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
|
||||
* as long as the following conditions are aheared to.
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed. If this code is used in a product,
|
||||
* Eric Young should be given attribution as the author of the parts used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Eric Young (eay@mincom.oz.au)
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
|
||||
#ifndef HEADER_DES_H
|
||||
#define HEADER_DES_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/* If this is set to 'unsigned int' on a DEC Alpha, this gives about a
|
||||
* %20 speed up (longs are 8 bytes, int's are 4). */
|
||||
#ifndef DES_LONG
|
||||
#define DES_LONG unsigned long
|
||||
#endif
|
||||
|
||||
typedef unsigned char des_cblock[8];
|
||||
typedef struct des_ks_struct
|
||||
{
|
||||
union {
|
||||
des_cblock _;
|
||||
/* make sure things are correct size on machines with
|
||||
* 8 byte longs */
|
||||
DES_LONG pad[2];
|
||||
} ks;
|
||||
#undef _
|
||||
#define _ ks._
|
||||
} des_key_schedule[16];
|
||||
|
||||
#define DES_KEY_SZ (sizeof(des_cblock))
|
||||
#define DES_SCHEDULE_SZ (sizeof(des_key_schedule))
|
||||
|
||||
#define DES_ENCRYPT 1
|
||||
#define DES_DECRYPT 0
|
||||
|
||||
#define DES_CBC_MODE 0
|
||||
#define DES_PCBC_MODE 1
|
||||
|
||||
#define des_ecb2_encrypt(i,o,k1,k2,e) \
|
||||
des_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))
|
||||
|
||||
#define des_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \
|
||||
des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))
|
||||
|
||||
#define des_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \
|
||||
des_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e))
|
||||
|
||||
#define des_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \
|
||||
des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n))
|
||||
|
||||
#define C_Block des_cblock
|
||||
#define Key_schedule des_key_schedule
|
||||
#define ENCRYPT DES_ENCRYPT
|
||||
#define DECRYPT DES_DECRYPT
|
||||
#define KEY_SZ DES_KEY_SZ
|
||||
#define string_to_key des_string_to_key
|
||||
#define read_pw_string des_read_pw_string
|
||||
#define random_key des_random_key
|
||||
#define pcbc_encrypt des_pcbc_encrypt
|
||||
#define set_key des_set_key
|
||||
#define key_sched des_key_sched
|
||||
#define ecb_encrypt des_ecb_encrypt
|
||||
#define cbc_encrypt des_cbc_encrypt
|
||||
#define ncbc_encrypt des_ncbc_encrypt
|
||||
#define cbc_cksum des_cbc_cksum
|
||||
#define quad_cksum des_quad_cksum
|
||||
|
||||
/* For compatibility with the MIT lib - eay 20/05/92 */
|
||||
typedef des_key_schedule bit_64;
|
||||
#define des_fixup_key_parity des_set_odd_parity
|
||||
#define des_check_key_parity check_parity
|
||||
|
||||
extern int des_check_key; /* defaults to false */
|
||||
extern int des_rw_mode; /* defaults to DES_PCBC_MODE */
|
||||
|
||||
/* The next line is used to disable full ANSI prototypes, if your
|
||||
* compiler has problems with the prototypes, make sure this line always
|
||||
* evaluates to true :-) */
|
||||
#if defined(MSDOS) || defined(__STDC__)
|
||||
#undef NOPROTO
|
||||
#endif
|
||||
#ifndef NOPROTO
|
||||
void des_ecb3_encrypt(des_cblock *input,des_cblock *output,
|
||||
des_key_schedule ks1,des_key_schedule ks2,
|
||||
des_key_schedule ks3, int enc);
|
||||
DES_LONG des_cbc_cksum(des_cblock *input,des_cblock *output,
|
||||
long length,des_key_schedule schedule,des_cblock *ivec);
|
||||
void des_cbc_encrypt(des_cblock *input,des_cblock *output,long length,
|
||||
des_key_schedule schedule,des_cblock *ivec,int enc);
|
||||
void des_ncbc_encrypt(des_cblock *input,des_cblock *output,long length,
|
||||
des_key_schedule schedule,des_cblock *ivec,int enc);
|
||||
void des_3cbc_encrypt(des_cblock *input,des_cblock *output,long length,
|
||||
des_key_schedule sk1,des_key_schedule sk2,
|
||||
des_cblock *ivec1,des_cblock *ivec2,int enc);
|
||||
void des_cfb_encrypt(unsigned char *in,unsigned char *out,int numbits,
|
||||
long length,des_key_schedule schedule,des_cblock *ivec,int enc);
|
||||
void des_ecb_encrypt(des_cblock *input,des_cblock *output,
|
||||
des_key_schedule ks,int enc);
|
||||
void des_encrypt(DES_LONG *data,des_key_schedule ks, int enc);
|
||||
void des_encrypt2(DES_LONG *data,des_key_schedule ks, int enc);
|
||||
void des_ede3_cbc_encrypt(des_cblock *input, des_cblock *output,
|
||||
long length, des_key_schedule ks1, des_key_schedule ks2,
|
||||
des_key_schedule ks3, des_cblock *ivec, int enc);
|
||||
void des_ede3_cfb64_encrypt(unsigned char *in, unsigned char *out,
|
||||
long length, des_key_schedule ks1, des_key_schedule ks2,
|
||||
des_key_schedule ks3, des_cblock *ivec, int *num, int encrypt);
|
||||
void des_ede3_ofb64_encrypt(unsigned char *in, unsigned char *out,
|
||||
long length, des_key_schedule ks1, des_key_schedule ks2,
|
||||
des_key_schedule ks3, des_cblock *ivec, int *num);
|
||||
|
||||
int des_enc_read(int fd,char *buf,int len,des_key_schedule sched,
|
||||
des_cblock *iv);
|
||||
int des_enc_write(int fd,char *buf,int len,des_key_schedule sched,
|
||||
des_cblock *iv);
|
||||
#ifdef PERL5
|
||||
char *des_crypt(const char *buf,const char *salt);
|
||||
#else
|
||||
/* some stupid compilers complain because I have declared char instead
|
||||
* of const char */
|
||||
#ifdef HEADER_DES_LOCL_H
|
||||
char *crypt(const char *buf,const char *salt);
|
||||
#else
|
||||
char *crypt();
|
||||
#endif
|
||||
#endif
|
||||
void des_ofb_encrypt(unsigned char *in,unsigned char *out,
|
||||
int numbits,long length,des_key_schedule schedule,des_cblock *ivec);
|
||||
void des_pcbc_encrypt(des_cblock *input,des_cblock *output,long length,
|
||||
des_key_schedule schedule,des_cblock *ivec,int enc);
|
||||
DES_LONG des_quad_cksum(des_cblock *input,des_cblock *output,
|
||||
long length,int out_count,des_cblock *seed);
|
||||
void des_random_seed(des_cblock key);
|
||||
void des_random_key(des_cblock ret);
|
||||
int des_read_password(des_cblock *key,char *prompt,int verify);
|
||||
int des_read_2passwords(des_cblock *key1,des_cblock *key2,
|
||||
char *prompt,int verify);
|
||||
int des_read_pw_string(char *buf,int length,char *prompt,int verify);
|
||||
void des_set_odd_parity(des_cblock *key);
|
||||
int des_is_weak_key(des_cblock *key);
|
||||
int des_set_key(des_cblock *key,des_key_schedule schedule);
|
||||
int des_key_sched(des_cblock *key,des_key_schedule schedule);
|
||||
void des_string_to_key(char *str,des_cblock *key);
|
||||
void des_string_to_2keys(char *str,des_cblock *key1,des_cblock *key2);
|
||||
void des_cfb64_encrypt(unsigned char *in, unsigned char *out, long length,
|
||||
des_key_schedule schedule, des_cblock *ivec, int *num, int enc);
|
||||
void des_ofb64_encrypt(unsigned char *in, unsigned char *out, long length,
|
||||
des_key_schedule schedule, des_cblock *ivec, int *num);
|
||||
|
||||
/* Extra functions from Mark Murray <mark@grondar.za> */
|
||||
void des_cblock_print_file(des_cblock *cb, FILE *fp);
|
||||
/* The following functions are not in the normal unix build or the
|
||||
* SSLeay build. When using the SSLeay build, use RAND_seed()
|
||||
* and RAND_bytes() instead. */
|
||||
int des_new_random_key(des_cblock *key);
|
||||
void des_init_random_number_generator(des_cblock *key);
|
||||
void des_set_random_generator_seed(des_cblock *key);
|
||||
void des_set_sequence_number(des_cblock new_sequence_number);
|
||||
void des_generate_random_block(des_cblock *block);
|
||||
|
||||
#else
|
||||
|
||||
void des_ecb3_encrypt();
|
||||
DES_LONG des_cbc_cksum();
|
||||
void des_cbc_encrypt();
|
||||
void des_ncbc_encrypt();
|
||||
void des_3cbc_encrypt();
|
||||
void des_cfb_encrypt();
|
||||
void des_ede3_cfb64_encrypt();
|
||||
void des_ede3_ofb64_encrypt();
|
||||
void des_ecb_encrypt();
|
||||
void des_encrypt();
|
||||
void des_encrypt2();
|
||||
void des_ede3_cbc_encrypt();
|
||||
int des_enc_read();
|
||||
int des_enc_write();
|
||||
#ifdef PERL5
|
||||
char *des_crypt();
|
||||
#else
|
||||
char *crypt();
|
||||
#endif
|
||||
void des_ofb_encrypt();
|
||||
void des_pcbc_encrypt();
|
||||
DES_LONG des_quad_cksum();
|
||||
void des_random_seed();
|
||||
void des_random_key();
|
||||
int des_read_password();
|
||||
int des_read_2passwords();
|
||||
int des_read_pw_string();
|
||||
void des_set_odd_parity();
|
||||
int des_is_weak_key();
|
||||
int des_set_key();
|
||||
int des_key_sched();
|
||||
void des_string_to_key();
|
||||
void des_string_to_2keys();
|
||||
void des_cfb64_encrypt();
|
||||
void des_ofb64_encrypt();
|
||||
|
||||
/* Extra functions from Mark Murray <mark@grondar.za> */
|
||||
void des_cblock_print_file();
|
||||
/* The following functions are not in the normal unix build or the
|
||||
* SSLeay build. When using the SSLeay build, use RAND_seed()
|
||||
* and RAND_bytes() instead. */
|
||||
int des_new_random_key();
|
||||
void des_init_random_number_generator();
|
||||
void des_set_random_generator_seed();
|
||||
void des_set_sequence_number();
|
||||
void des_generate_random_block();
|
||||
|
||||
#endif
|
||||
#endif
|
287
lib/des/des_locl.org
Normal file
287
lib/des/des_locl.org
Normal file
@@ -0,0 +1,287 @@
|
||||
/* lib/des/des_locl.h */
|
||||
/* Copyright (C) 1995 Eric Young (eay@mincom.oz.au)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of an SSL implementation written
|
||||
* by Eric Young (eay@mincom.oz.au).
|
||||
* The implementation was written so as to conform with Netscapes SSL
|
||||
* specification. This library and applications are
|
||||
* FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
|
||||
* as long as the following conditions are aheared to.
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed. If this code is used in a product,
|
||||
* Eric Young should be given attribution as the author of the parts used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Eric Young (eay@mincom.oz.au)
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
|
||||
#ifndef HEADER_DES_LOCL_H
|
||||
#define HEADER_DES_LOCL_H
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#ifndef MSDOS
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include "des.h"
|
||||
|
||||
/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
|
||||
*
|
||||
* Always modify des_locl.org since des_locl.h is automatically generated from
|
||||
* it during SSLeay configuration.
|
||||
*
|
||||
* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
|
||||
*/
|
||||
|
||||
/* the following is tweaked from a config script, that is why it is a
|
||||
* protected undef/define */
|
||||
#ifndef DES_PTR
|
||||
#undef DES_PTR
|
||||
#endif
|
||||
|
||||
#ifdef MSDOS /* Visual C++ 2.1 (Windows NT/95) */
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <io.h>
|
||||
#ifndef RAND
|
||||
#define RAND
|
||||
#endif
|
||||
#undef NOPROTO
|
||||
#endif
|
||||
|
||||
#if defined(__STDC__) || defined(VMS) || defined(M_XENIX) || defined(MSDOS)
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
#ifndef RAND
|
||||
#define RAND
|
||||
#endif
|
||||
|
||||
#ifdef linux
|
||||
#undef RAND
|
||||
#endif
|
||||
|
||||
#ifdef MSDOS
|
||||
#define getpid() 2
|
||||
extern int errno;
|
||||
#define RAND
|
||||
#undef NOPROTO
|
||||
#endif
|
||||
|
||||
#if defined(NOCONST)
|
||||
#define const
|
||||
#endif
|
||||
|
||||
#ifdef __STDC__
|
||||
#undef NOPROTO
|
||||
#endif
|
||||
|
||||
#ifdef RAND
|
||||
#define srandom(s) srand(s)
|
||||
#define random rand
|
||||
#endif
|
||||
|
||||
#define ITERATIONS 16
|
||||
#define HALF_ITERATIONS 8
|
||||
|
||||
/* used in des_read and des_write */
|
||||
#define MAXWRITE (1024*16)
|
||||
#define BSIZE (MAXWRITE+4)
|
||||
|
||||
#define c2l(c,l) (l =((DES_LONG)(*((c)++))) , \
|
||||
l|=((DES_LONG)(*((c)++)))<< 8L, \
|
||||
l|=((DES_LONG)(*((c)++)))<<16L, \
|
||||
l|=((DES_LONG)(*((c)++)))<<24L)
|
||||
|
||||
/* NOTE - c is not incremented as per c2l */
|
||||
#define c2ln(c,l1,l2,n) { \
|
||||
c+=n; \
|
||||
l1=l2=0; \
|
||||
switch (n) { \
|
||||
case 8: l2 =((DES_LONG)(*(--(c))))<<24L; \
|
||||
case 7: l2|=((DES_LONG)(*(--(c))))<<16L; \
|
||||
case 6: l2|=((DES_LONG)(*(--(c))))<< 8L; \
|
||||
case 5: l2|=((DES_LONG)(*(--(c)))); \
|
||||
case 4: l1 =((DES_LONG)(*(--(c))))<<24L; \
|
||||
case 3: l1|=((DES_LONG)(*(--(c))))<<16L; \
|
||||
case 2: l1|=((DES_LONG)(*(--(c))))<< 8L; \
|
||||
case 1: l1|=((DES_LONG)(*(--(c)))); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
|
||||
*((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
|
||||
*((c)++)=(unsigned char)(((l)>>16L)&0xff), \
|
||||
*((c)++)=(unsigned char)(((l)>>24L)&0xff))
|
||||
|
||||
/* replacements for htonl and ntohl since I have no idea what to do
|
||||
* when faced with machines with 8 byte longs. */
|
||||
#define HDRSIZE 4
|
||||
|
||||
#define n2l(c,l) (l =((DES_LONG)(*((c)++)))<<24L, \
|
||||
l|=((DES_LONG)(*((c)++)))<<16L, \
|
||||
l|=((DES_LONG)(*((c)++)))<< 8L, \
|
||||
l|=((DES_LONG)(*((c)++))))
|
||||
|
||||
#define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
|
||||
*((c)++)=(unsigned char)(((l)>>16L)&0xff), \
|
||||
*((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
|
||||
*((c)++)=(unsigned char)(((l) )&0xff))
|
||||
|
||||
/* NOTE - c is not incremented as per l2c */
|
||||
#define l2cn(l1,l2,c,n) { \
|
||||
c+=n; \
|
||||
switch (n) { \
|
||||
case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \
|
||||
case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \
|
||||
case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \
|
||||
case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \
|
||||
case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \
|
||||
case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \
|
||||
case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \
|
||||
case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \
|
||||
} \
|
||||
}
|
||||
|
||||
/* The changes to this macro may help or hinder, depending on the
|
||||
* compiler and the achitecture. gcc2 always seems to do well :-).
|
||||
* Inspired by Dana How <how@isl.stanford.edu>
|
||||
* DO NOT use the alternative version on machines with 8 byte longs.
|
||||
* It does not seem to work on the Alpha, even when DES_LONG is 4
|
||||
* bytes, probably an issue of accessing non-word aligned objects :-( */
|
||||
#ifdef DES_PTR
|
||||
|
||||
#define D_ENCRYPT(L,R,S) { \
|
||||
u=((R^s[S ])<<2); \
|
||||
t= R^s[S+1]; \
|
||||
t=((t>>2)+(t<<30)); \
|
||||
L^= (\
|
||||
*(DES_LONG *)(&(des_SPtrans[1])+((t )&0xfc))+ \
|
||||
*(DES_LONG *)(&(des_SPtrans[3])+((t>> 8)&0xfc))+ \
|
||||
*(DES_LONG *)(&(des_SPtrans[5])+((t>>16)&0xfc))+ \
|
||||
*(DES_LONG *)(&(des_SPtrans[7])+((t>>24)&0xfc))+ \
|
||||
*(DES_LONG *)(&(des_SPtrans[0])+((u )&0xfc))+ \
|
||||
*(DES_LONG *)(&(des_SPtrans[2])+((u>> 8)&0xfc))+ \
|
||||
*(DES_LONG *)(&(des_SPtrans[4])+((u>>16)&0xfc))+ \
|
||||
*(DES_LONG *)(&(des_SPtrans[6])+((u>>24)&0xfc))); }
|
||||
#else /* original version */
|
||||
#ifdef MSDOS
|
||||
#define D_ENCRYPT(L,R,S) \
|
||||
U.l=R^s[S+1]; \
|
||||
T.s[0]=((U.s[0]>>4)|(U.s[1]<<12))&0x3f3f; \
|
||||
T.s[1]=((U.s[1]>>4)|(U.s[0]<<12))&0x3f3f; \
|
||||
U.l=(R^s[S ])&0x3f3f3f3fL; \
|
||||
L^= des_SPtrans[1][(T.c[0])]| \
|
||||
des_SPtrans[3][(T.c[1])]| \
|
||||
des_SPtrans[5][(T.c[2])]| \
|
||||
des_SPtrans[7][(T.c[3])]| \
|
||||
des_SPtrans[0][(U.c[0])]| \
|
||||
des_SPtrans[2][(U.c[1])]| \
|
||||
des_SPtrans[4][(U.c[2])]| \
|
||||
des_SPtrans[6][(U.c[3])];
|
||||
#else
|
||||
#define D_ENCRYPT(Q,R,S) {\
|
||||
u=(R^s[S ]); \
|
||||
t=R^s[S+1]; \
|
||||
t=((t>>4L)+(t<<28L)); \
|
||||
Q^= des_SPtrans[1][(t )&0x3f]| \
|
||||
des_SPtrans[3][(t>> 8L)&0x3f]| \
|
||||
des_SPtrans[5][(t>>16L)&0x3f]| \
|
||||
des_SPtrans[7][(t>>24L)&0x3f]| \
|
||||
des_SPtrans[0][(u )&0x3f]| \
|
||||
des_SPtrans[2][(u>> 8L)&0x3f]| \
|
||||
des_SPtrans[4][(u>>16L)&0x3f]| \
|
||||
des_SPtrans[6][(u>>24L)&0x3f]; }
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* IP and FP
|
||||
* The problem is more of a geometric problem that random bit fiddling.
|
||||
0 1 2 3 4 5 6 7 62 54 46 38 30 22 14 6
|
||||
8 9 10 11 12 13 14 15 60 52 44 36 28 20 12 4
|
||||
16 17 18 19 20 21 22 23 58 50 42 34 26 18 10 2
|
||||
24 25 26 27 28 29 30 31 to 56 48 40 32 24 16 8 0
|
||||
|
||||
32 33 34 35 36 37 38 39 63 55 47 39 31 23 15 7
|
||||
40 41 42 43 44 45 46 47 61 53 45 37 29 21 13 5
|
||||
48 49 50 51 52 53 54 55 59 51 43 35 27 19 11 3
|
||||
56 57 58 59 60 61 62 63 57 49 41 33 25 17 9 1
|
||||
|
||||
The output has been subject to swaps of the form
|
||||
0 1 -> 3 1 but the odd and even bits have been put into
|
||||
2 3 2 0
|
||||
different words. The main trick is to remember that
|
||||
t=((l>>size)^r)&(mask);
|
||||
r^=t;
|
||||
l^=(t<<size);
|
||||
can be used to swap and move bits between words.
|
||||
|
||||
So l = 0 1 2 3 r = 16 17 18 19
|
||||
4 5 6 7 20 21 22 23
|
||||
8 9 10 11 24 25 26 27
|
||||
12 13 14 15 28 29 30 31
|
||||
becomes (for size == 2 and mask == 0x3333)
|
||||
t = 2^16 3^17 -- -- l = 0 1 16 17 r = 2 3 18 19
|
||||
6^20 7^21 -- -- 4 5 20 21 6 7 22 23
|
||||
10^24 11^25 -- -- 8 9 24 25 10 11 24 25
|
||||
14^28 15^29 -- -- 12 13 28 29 14 15 28 29
|
||||
|
||||
Thanks for hints from Richard Outerbridge - he told me IP&FP
|
||||
could be done in 15 xor, 10 shifts and 5 ands.
|
||||
When I finally started to think of the problem in 2D
|
||||
I first got ~42 operations without xors. When I remembered
|
||||
how to use xors :-) I got it to its final state.
|
||||
*/
|
||||
#define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\
|
||||
(b)^=(t),\
|
||||
(a)^=((t)<<(n)))
|
||||
|
||||
#define IP(l,r) \
|
||||
{ \
|
||||
register DES_LONG tt; \
|
||||
PERM_OP(r,l,tt, 4,0x0f0f0f0fL); \
|
||||
PERM_OP(l,r,tt,16,0x0000ffffL); \
|
||||
PERM_OP(r,l,tt, 2,0x33333333L); \
|
||||
PERM_OP(l,r,tt, 8,0x00ff00ffL); \
|
||||
PERM_OP(r,l,tt, 1,0x55555555L); \
|
||||
}
|
||||
|
||||
#define FP(l,r) \
|
||||
{ \
|
||||
register DES_LONG tt; \
|
||||
PERM_OP(l,r,tt, 1,0x55555555L); \
|
||||
PERM_OP(r,l,tt, 8,0x00ff00ffL); \
|
||||
PERM_OP(l,r,tt, 2,0x33333333L); \
|
||||
PERM_OP(r,l,tt,16,0x0000ffffL); \
|
||||
PERM_OP(l,r,tt, 4,0x0f0f0f0fL); \
|
||||
}
|
||||
#endif
|
Reference in New Issue
Block a user