mirror of
https://git.openafs.org/openafs.git
synced 2025-01-18 06:50:12 +00:00
Remove local crypto
This change removes all of the local crypto use in userspace, in favour of using our shiny new afshcrypto library. Change-Id: Iac21b42e49bac424cc28c449a31f2da44121b7e5 Reviewed-on: http://gerrit.openafs.org/2577 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Derrick Brashear <shadow@dementia.org>
This commit is contained in:
parent
a17bf58c08
commit
a9b8fd81bf
32
Makefile.in
32
Makefile.in
@ -109,7 +109,7 @@ packages: dest
|
||||
echo Not building packages for ${SYS_NAME} ;; \
|
||||
esac
|
||||
|
||||
${TOP_INCDIR}/afs ${TOP_INCDIR}/rx ${TOP_INCDIR}/des ${TOP_INCDIR}/hcrypto ${TOP_LIBDIR} ${TOP_JLIBDIR}:
|
||||
${TOP_INCDIR}/afs ${TOP_INCDIR}/rx ${TOP_INCDIR}/hcrypto ${TOP_LIBDIR} ${TOP_JLIBDIR}:
|
||||
mkdir -p $@
|
||||
|
||||
install_dirs: force
|
||||
@ -135,7 +135,7 @@ dest_dirs: force
|
||||
mkdir -p ${DEST}/root.server/etc
|
||||
mkdir -p ${DEST}/root.server/usr/afs/bin
|
||||
|
||||
prelude: ${TOP_INCDIR}/afs ${TOP_INCDIR}/rx ${TOP_INCDIR}/des ${TOP_INCDIR}/hcrypto ${TOP_LIBDIR}
|
||||
prelude: ${TOP_INCDIR}/afs ${TOP_INCDIR}/rx ${TOP_INCDIR}/hcrypto ${TOP_LIBDIR}
|
||||
|
||||
project: cmd comerr
|
||||
|
||||
@ -148,7 +148,7 @@ config: prelude
|
||||
procmgmt: config
|
||||
+${COMPILE_PART1} procmgmt ${COMPILE_PART2}
|
||||
|
||||
util: $(DIR_roken) procmgmt des lwp_depinstall rx_depinstall
|
||||
util: $(DIR_roken) procmgmt hcrypto lwp_depinstall rx_depinstall
|
||||
+${COMPILE_PART1} util ${COMPILE_PART2}
|
||||
|
||||
audit: util rx rxkad fsint
|
||||
@ -204,16 +204,13 @@ export_build: fsint
|
||||
afs: config export comerr afs_depinstall
|
||||
+${COMPILE_PART1} afs ${COMPILE_PART2}
|
||||
|
||||
des: config
|
||||
+${COMPILE_PART1} des ${COMPILE_PART2}
|
||||
|
||||
sys: cmd comerr afs des rx rxstat fsint auth sys_depinstall
|
||||
sys: cmd comerr afs hcrypto rx rxstat fsint auth sys_depinstall
|
||||
+${COMPILE_PART1} sys ${COMPILE_PART2}
|
||||
|
||||
rxkad: cmd comerr des rx rxkad_depinstall
|
||||
rxkad: cmd comerr hcrypto rx rxkad_depinstall
|
||||
+${COMPILE_PART1} rxkad ${COMPILE_PART2}
|
||||
|
||||
auth: cmd comerr des lwp rx rxkad audit sys_depinstall auth_depinstall
|
||||
auth: cmd comerr hcrypto lwp rx rxkad audit sys_depinstall auth_depinstall
|
||||
+${COMPILE_PART1} auth ${COMPILE_PART2}
|
||||
|
||||
ubik: cmd comerr auth ubik_depinstall sys
|
||||
@ -357,7 +354,7 @@ fsprobe: cmd comerr util fsint volser
|
||||
scout: cmd comerr gtx fsprobe
|
||||
+${COMPILE_PART1} scout ${COMPILE_PART2}
|
||||
|
||||
uss: des kauth cmd comerr rx vlserver vol volser
|
||||
uss: hcrypto kauth cmd comerr rx vlserver vol volser
|
||||
+${COMPILE_PART1} uss ${COMPILE_PART2}
|
||||
|
||||
bozo: cmd comerr audit auth kauth volser
|
||||
@ -491,17 +488,13 @@ libafs_tree: export lwp_depinstall rx_depinstall vlserver_depinstall tvlserver_d
|
||||
# libuafs build targets
|
||||
#
|
||||
|
||||
UKERNELDIR= \
|
||||
des \
|
||||
afsweb
|
||||
|
||||
libuafs_setup: config export
|
||||
src/config/config src/libuafs/MakefileProto.${MKAFS_OSTYPE} src/libuafs/Makefile ${SYS_NAME}
|
||||
|
||||
libuafs: libuafs_setup vlserver_depinstall tvlserver_depinstall rx_depinstall fsint_depinstall \
|
||||
auth_depinstall dir_depinstall libacl_depinstall rxkad_depinstall \
|
||||
ubik_depinstall afs_depinstall kauth_depinstall ptserver_depinstall \
|
||||
rxstat_depinstall lwp_depinstall sys_depinstall des cmd
|
||||
rxstat_depinstall lwp_depinstall sys_depinstall cmd hcrypto
|
||||
+set -x; \
|
||||
case ${SYS_NAME} in \
|
||||
hp_ux102* | *_obsd* | sun*_4* | *_nbsd*| hp_ux11i | hp_ux112* | ia64_hpux112*) \
|
||||
@ -569,7 +562,7 @@ afsmonitor: cmd comerr gtx xstat
|
||||
tests: rxtests ubiktests rpctestlib
|
||||
|
||||
# pthread based user space RX library
|
||||
libafsrpc: rx rxkad rxstat fsint des
|
||||
libafsrpc: rx rxkad rxstat fsint hcrypto
|
||||
+case ${SYS_NAME} in \
|
||||
alpha_dux*|sgi_*|sun4x_*|sunx86_*|rs_aix*|*linux*|hp_ux11*|ia64_hpux*|*[of]bsd*|*nbsd[234]*) \
|
||||
${COMPILE_PART1} libafsrpc ${COMPILE_PART2} ;; \
|
||||
@ -594,7 +587,7 @@ libafsauthent: ubik auth kauth libafsrpc
|
||||
esac
|
||||
|
||||
# pthread based user space RX library
|
||||
shlibafsrpc: rx rxstat fsint rxkad des
|
||||
shlibafsrpc: rx rxstat fsint rxkad hcrypto
|
||||
+case ${SYS_NAME} in \
|
||||
alpha_dux*|sgi_*|sun4x_*|sunx86_*|rs_aix*|*linux*|hp_ux11*|ia64_hpux*|*_darwin_1*|*nbsd*|*obsd*|*fbsd*) \
|
||||
${COMPILE_PART1} shlibafsrpc ${COMPILE_PART2} ;; \
|
||||
@ -709,7 +702,6 @@ clean2:
|
||||
-${COMPILE_PART1} fsint ${COMPILE_CLEAN}
|
||||
-${COMPILE_PART1} export ${COMPILE_CLEAN}
|
||||
-${COMPILE_PART1} afs ${COMPILE_CLEAN}
|
||||
-${COMPILE_PART1} des ${COMPILE_CLEAN}
|
||||
-${COMPILE_PART1} sys ${COMPILE_CLEAN}
|
||||
-${COMPILE_PART1} rxkad ${COMPILE_CLEAN}
|
||||
-${COMPILE_PART1} auth ${COMPILE_CLEAN}
|
||||
@ -784,7 +776,7 @@ clean2:
|
||||
-${COMPILE_PART1} crypto/hcrypto ${COMPILE_CLEAN}
|
||||
-${COMPILE_PART1} roken ${COMPILE_CLEAN}
|
||||
-(cd src/libafs; /bin/rm -rf afs afsint config rx)
|
||||
-(cd src/libuafs; /bin/rm -rf afs afsint config rx des)
|
||||
-(cd src/libuafs; /bin/rm -rf afs afsint config rx)
|
||||
-/bin/rm -rf ${TOP_INCDIR} ${TOP_LIBDIR} ${TOP_JLIBDIR}
|
||||
-/bin/rm -rf libafs_tree ${SYS_NAME}
|
||||
|
||||
@ -827,8 +819,6 @@ distclean: clean
|
||||
src/config/shlib-build \
|
||||
src/config/shlib-install \
|
||||
src/crypto/hcrypto/Makefile \
|
||||
src/des/Makefile \
|
||||
src/des/test/Makefile \
|
||||
src/dir/Makefile \
|
||||
src/dir/test/Makefile \
|
||||
src/dviced/Makefile \
|
||||
|
@ -166,13 +166,6 @@ rxgen: lwp
|
||||
$(NTMAKE)
|
||||
$(CD) ..\..
|
||||
|
||||
des: rxgen
|
||||
@echo ***** $@
|
||||
$(DOCD) $(SRC)\des
|
||||
$(CD) $(SRC)\des
|
||||
$(NTMAKE)
|
||||
$(CD) ..\..
|
||||
|
||||
hcrypto: roken
|
||||
@echo ***** $@
|
||||
$(DOCD) $(SRC)\crypto\hcrypto
|
||||
@ -180,7 +173,7 @@ hcrypto: roken
|
||||
$(NTMAKE)
|
||||
$(CD) ..\..\..
|
||||
|
||||
roken: des
|
||||
roken: rxgen
|
||||
@echo ***** $@
|
||||
$(DOCD) $(SRC)\roken
|
||||
$(CD) $(SRC)\roken
|
||||
|
@ -139,8 +139,6 @@ src/config/Makefile.version-NOCML \
|
||||
src/config/shlib-build \
|
||||
src/config/shlib-install \
|
||||
src/crypto/hcrypto/Makefile \
|
||||
src/des/Makefile \
|
||||
src/des/test/Makefile \
|
||||
src/dir/Makefile \
|
||||
src/dir/test/Makefile \
|
||||
src/dviced/Makefile \
|
||||
|
@ -155,7 +155,6 @@ CLIENTADMINLIB = ${TOP_LIBDIR}/libclientadmin.a
|
||||
LIBJAFS_LIBS =\
|
||||
${TOP_LIBDIR}/libjuafs.a \
|
||||
${TOP_LIBDIR}/libafsutil.a \
|
||||
${TOP_LIBDIR}/libdes.a \
|
||||
-lresolv \
|
||||
-lpthread
|
||||
|
||||
|
@ -359,11 +359,11 @@ EXELIBS = \
|
||||
$(DESTDIR)\lib\afs\afsvldb.lib \
|
||||
$(DESTDIR)\lib\afsubik.lib \
|
||||
$(DESTDIR)\lib\afsrxkad.lib \
|
||||
$(DESTDIR)\lib\afsdes.lib \
|
||||
$(DESTDIR)\lib\afsrx.lib \
|
||||
$(DESTDIR)\lib\afslwp.lib \
|
||||
$(DESTDIR)\lib\libosi.lib \
|
||||
$(DESTDIR)\lib\libafsconf.lib \
|
||||
$(DESTDIR)\lib\afshcrypto.lib \
|
||||
$(DESTDIR)\lib\afsroken.lib
|
||||
|
||||
EXELIBS2 = \
|
||||
@ -375,15 +375,17 @@ EXELIBS2 = \
|
||||
$(DESTDIR)\lib\afs\afsutil.lib \
|
||||
$(DESTDIR)\lib\afsubik.lib \
|
||||
$(DESTDIR)\lib\afsrxkad.lib \
|
||||
$(DESTDIR)\lib\afsdes.lib \
|
||||
$(DESTDIR)\lib\afslwp.lib \
|
||||
$(DESTDIR)\lib\libosi.lib \
|
||||
$(DESTDIR)\lib\libafsconf.lib \
|
||||
$(DESTDIR)\lib\afshcrypto.lib \
|
||||
$(DESTDIR)\lib\afsroken.lib
|
||||
|
||||
EXELIBS3 = \
|
||||
$(DESTDIR)\lib\afs\afscmd.lib \
|
||||
$(DESTDIR)\lib\afsrxkad.lib
|
||||
$(DESTDIR)\lib\afsrxkad.lib \
|
||||
$(DESTDIR)\lib\afshcrypto.lib \
|
||||
$(DESTDIR)\lib\afsroken.lib
|
||||
|
||||
|
||||
# klog.exe
|
||||
@ -517,8 +519,9 @@ KPASSWD_LIBS =\
|
||||
$(DESTDIR)\lib\afsauthent.lib \
|
||||
$(DESTDIR)\lib\afsrpc.lib \
|
||||
$(DESTDIR)\lib\afs\afscmd.lib \
|
||||
$(DESTDIR)\lib\afsdes.lib \
|
||||
$(DESTDIR)\lib\afs\mtafsutil.lib
|
||||
$(DESTDIR)\lib\afs\mtafsutil.lib \
|
||||
$(DESTDIR)\lib\afshcrypto.lib \
|
||||
$(DESTDIR)\lib\afsroken.lib
|
||||
|
||||
$(OUT)\kpasswd.obj: $(KAUTH)/kpasswd.c
|
||||
$(C2OBJ) -DAFS_PTHREAD_ENV /Fo$@ $**
|
||||
|
@ -25,7 +25,7 @@
|
||||
#define KRB_DEFS
|
||||
|
||||
/* Need some defs from des.h */
|
||||
#include <des.h>
|
||||
#include <hcrypto/des.h>
|
||||
|
||||
/* General definitions */
|
||||
#define KSUCCESS 0
|
||||
|
@ -97,7 +97,6 @@ EXELIBS = \
|
||||
$(DESTDIR)\lib\afsauthent.lib \
|
||||
$(DESTDIR)\lib\libafsconf.lib \
|
||||
$(DESTDIR)\lib\afsrxkad.lib \
|
||||
$(DESTDIR)\lib\afsdes.lib \
|
||||
$(DESTDIR)\lib\afskfw.lib \
|
||||
$(DESTDIR)\lib\afs\AfsClass.lib \
|
||||
$(DESTDIR)\lib\afs\TaAfsAppLib.lib
|
||||
|
@ -64,7 +64,6 @@ EXELIBS = \
|
||||
$(DESTDIR)\lib\afs\TaAfsAppLib.lib \
|
||||
$(DESTDIR)\lib\lanahelper.lib \
|
||||
$(DESTDIR)\lib\afsrxkad.lib \
|
||||
$(DESTDIR)\lib\afsdes.lib \
|
||||
$(DESTDIR)\lib\afsauthent.lib \
|
||||
$(DESTDIR)\lib\libafsconf.lib \
|
||||
$(DESTDIR)\lib\afs\afsreg.lib \
|
||||
|
@ -1403,17 +1403,12 @@
|
||||
<Directory Id="dirInclude" Name="Include">
|
||||
<Component Id="cmp_SDK_Include" Guid="2229E5F7-1D23-4088-AF85-917CCDB2634D">
|
||||
<File Id="filebasic_H" Name="basic.h" LongName="basic.h" DiskId="1" src="$(var.IncDir)basic.h" />
|
||||
<File Id="filecrypt_H" Name="crypt.h" LongName="crypt.h" DiskId="1" src="$(var.IncDir)crypt.h" />
|
||||
<File Id="filedbrpc_H" Name="dbrpc.h" LongName="dbrpc.h" DiskId="1" src="$(var.IncDir)dbrpc.h" />
|
||||
<File Id="filedes_H" Name="des.h" LongName="des.h" DiskId="1" src="$(var.IncDir)des.h" />
|
||||
<File Id="filedes_conf_H" Name="des_conf.h" LongName="des_conf.h" DiskId="1" src="$(var.IncDir)des_conf.h" />
|
||||
<File Id="filedes_odd_H" Name="des_odd.h" LongName="des_odd.h" DiskId="1" src="$(var.IncDir)des_odd.h" />
|
||||
<File Id="filedirent_H" Name="dirent.h" LongName="dirent.h" DiskId="1" src="$(var.IncDir)dirent.h" />
|
||||
<File Id="filelargeint_H" Name="largeint.h" LongName="largeint.h" DiskId="1" src="$(var.IncDir)largeint.h" />
|
||||
<File Id="filelock_H" Name="lock.h" LongName="lock.h" DiskId="1" src="$(var.IncDir)lock.h" />
|
||||
<File Id="filelwp_H" Name="lwp.h" LongName="lwp.h" DiskId="1" src="$(var.IncDir)lwp.h" />
|
||||
<File Id="filemain_H" Name="main.h" LongName="main.h" DiskId="1" src="$(var.IncDir)main.h" />
|
||||
<File Id="filemit_cpyright_H" Name="MIT-CP~1.h" LongName="mit-cpyright.h" DiskId="1" src="$(var.IncDir)mit-cpyright.h" />
|
||||
<File Id="fileosi_H" Name="osi.h" LongName="osi.h" DiskId="1" src="$(var.IncDir)osi.h" />
|
||||
<File Id="fileosibasel_H" Name="osibasel.h" LongName="osibasel.h" DiskId="1" src="$(var.IncDir)osibasel.h" />
|
||||
<File Id="fileosidb_H" Name="osidb.h" LongName="osidb.h" DiskId="1" src="$(var.IncDir)osidb.h" />
|
||||
@ -1571,9 +1566,6 @@
|
||||
<Component Id="cmp_SDK_Include_rx" Guid="2E215D10-C080-42A3-B692-AFF94C7A1A2B">
|
||||
<File Id="fileasn1_err_H" Name="asn1_err.h" LongName="asn1_err.h" DiskId="1" src="$(var.IncDir)rx\asn1_err.h" />
|
||||
<File Id="filefcrypt_H" Name="fcrypt.h" LongName="fcrypt.h" DiskId="1" src="$(var.IncDir)rx\fcrypt.h" />
|
||||
<File Id="filehash_H" Name="hash.h" LongName="hash.h" DiskId="1" src="$(var.IncDir)rx\hash.h" />
|
||||
<File Id="filemd4_H" Name="md4.h" LongName="md4.h" DiskId="1" src="$(var.IncDir)rx\md4.h" />
|
||||
<File Id="filemd5_H" Name="md5.h" LongName="md5.h" DiskId="1" src="$(var.IncDir)rx\md5.h" />
|
||||
<File Id="filerx_H" Name="rx.h" LongName="rx.h" DiskId="1" src="$(var.IncDir)rx\rx.h" />
|
||||
<File Id="filerxkad_H" Name="rxkad.h" LongName="rxkad.h" DiskId="1" src="$(var.IncDir)rx\rxkad.h" />
|
||||
<File Id="filerxkad_prototypes_H" Name="RXKAD_~1.h" LongName="rxkad_prototypes.h" DiskId="1" src="$(var.IncDir)rx\rxkad_prototypes.h" />
|
||||
@ -1651,7 +1643,6 @@
|
||||
<Directory Id="dirLib" Name="lib">
|
||||
<Component Win64="$(var.Win64)" Id="cmp_SDK_Lib" Guid="$(var.cmp_SDK_Lib_guid)">
|
||||
<File Id="fileafsauthent_LIB" Name="AFSAUT~1.lib" LongName="afsauthent.lib" DiskId="1" src="$(var.LibDir)afsauthent.lib" />
|
||||
<File Id="fileafsdes_LIB" Name="afsdes.lib" LongName="afsdes.lib" DiskId="1" src="$(var.LibDir)afsdes.lib" />
|
||||
<File Id="fileafskfw_LIB" Name="afskfw.lib" LongName="afskfw.lib" DiskId="1" src="$(var.LibDir)afskfw.lib" />
|
||||
<File Id="fileafslogon_LIB" Name="afslogon.lib" LongName="afslogon.lib" DiskId="1" src="$(var.LibDir)afslogon.lib" />
|
||||
<File Id="fileafslwp_LIB" Name="afslwp.lib" LongName="afslwp.lib" DiskId="1" src="$(var.LibDir)afslwp.lib" />
|
||||
|
@ -25,7 +25,7 @@ all: afsd vsys @ENABLE_FUSE_CLIENT@
|
||||
#
|
||||
|
||||
AFSLIBS=${TOP_LIBDIR}/libauth.a ${TOP_LIBDIR}/libcmd.a ${TOP_LIBDIR}/libsys.a ${TOP_LIBDIR}/util.a ${TOP_LIBDIR}/librx.a ${TOP_LIBDIR}/liblwp.a ${TOP_LIBDIR}/util.a
|
||||
UAFSLIBS=${TOP_LIBDIR}/libuafs.a ${TOP_LIBDIR}/libdes.a ${TOP_LIBDIR}/libafsutil.a ${TOP_LIBDIR}/libcmd.a ${TOP_LIBDIR}/libafsutil.a
|
||||
UAFSLIBS=${TOP_LIBDIR}/libuafs.a ${TOP_LIBDIR}/libafsutil.a ${TOP_LIBDIR}/libcmd.a ${TOP_LIBDIR}/libafsutil.a
|
||||
|
||||
FUSE_LIBS=@FUSE_LIBS@
|
||||
|
||||
|
@ -17,7 +17,7 @@ AFSLIBS = ${TOP_LIBDIR}/libprot.a ${TOP_LIBDIR}/libauth.a \
|
||||
${TOP_LIBDIR}/libubik.a ${TOP_LIBDIR}/librxkad.a \
|
||||
${TOP_LIBDIR}/libsys.a ${TOP_LIBDIR}/librx.a \
|
||||
${TOP_LIBDIR}/libsys.a ${TOP_LIBDIR}/liblwp.a \
|
||||
${TOP_LIBDIR}/libdes.a ${TOP_LIBDIR}/libcom_err.a \
|
||||
${TOP_LIBDIR}/libafshcrypto_lwp.a ${TOP_LIBDIR}/libcom_err.a \
|
||||
${TOP_LIBDIR}/libcmd.a ${TOP_LIBDIR}/libafsutil.a
|
||||
|
||||
SRCS= aklog.c krb_util.c linked_list.c
|
||||
|
@ -20,9 +20,12 @@ KOBJS= cellconfig.o ktc.krb.o userok.o writeconfig.o authcon.o \
|
||||
acfg_errors.o ktc_errors.o token.xdr.o token.o
|
||||
|
||||
LIBS=libauth.a \
|
||||
${TOP_LIBDIR}/librxkad.a ${TOP_LIBDIR}/libdes.a \
|
||||
${TOP_LIBDIR}/librx.a ${TOP_LIBDIR}/libsys.a \
|
||||
${TOP_LIBDIR}/liblwp.a ${TOP_LIBDIR}/util.a
|
||||
${TOP_LIBDIR}/librxkad.a \
|
||||
${TOP_LIBDIR}/librx.a \
|
||||
${TOP_LIBDIR}/libsys.a \
|
||||
${TOP_LIBDIR}/liblwp.a \
|
||||
${TOP_LIBDIR}/util.a
|
||||
|
||||
INCLS=cellconfig.h auth.h keys.h
|
||||
KSRCS=auth.h
|
||||
UKSRCS=${KSRCS} cellconfig.h acfg_errors.c keys.h cellconfig.c \
|
||||
|
@ -87,13 +87,13 @@ EXELIBDIR = $(DESTDIR)\lib
|
||||
EXELIBS =\
|
||||
$(EXELIBDIR)\afs\afsauth.lib \
|
||||
$(EXELIBDIR)\afsrxkad.lib \
|
||||
$(EXELIBDIR)\afsdes.lib \
|
||||
$(EXELIBDIR)\afsrx.lib \
|
||||
$(EXELIBDIR)\afslwp.lib \
|
||||
$(EXELIBDIR)\afs\afsutil.lib \
|
||||
$(EXELIBDIR)\afs\afseventlog.lib \
|
||||
$(EXELIBDIR)\afs\afsreg.lib \
|
||||
$(EXELIBDIR)\libafsconf.lib \
|
||||
$(EXELIBDIR)\afshcrypto.lib \
|
||||
$(EXELIBDIR)\afsroken.lib
|
||||
|
||||
$(SETKEY_EXEFILE): $(SETKEY_EXEOBJS) $(EXELIBS)
|
||||
|
@ -12,6 +12,10 @@
|
||||
|
||||
#include <roken.h>
|
||||
|
||||
#ifdef IGNORE_SOME_GCC_WARNINGS
|
||||
# pragma GCC diagnostic warning "-Wdeprecated-declarations"
|
||||
#endif
|
||||
|
||||
#include <afs/stds.h>
|
||||
#include <afs/pthread_glock.h>
|
||||
#include <sys/types.h>
|
||||
@ -25,10 +29,13 @@
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <des.h>
|
||||
#include <des_prototypes.h>
|
||||
|
||||
#define HC_DEPRECATED
|
||||
#include <hcrypto/des.h>
|
||||
|
||||
#include <rx/rxkad.h>
|
||||
#include <rx/rx.h>
|
||||
|
||||
#include "cellconfig.h"
|
||||
#include "keys.h"
|
||||
#include "ktc.h"
|
||||
@ -90,8 +97,8 @@ GenericAuth(struct afsconf_dir *adir,
|
||||
}
|
||||
|
||||
/* next create random session key, using key for seed to good random */
|
||||
des_init_random_number_generator(ktc_to_cblock(&key));
|
||||
code = des_random_key(ktc_to_cblock(&session));
|
||||
DES_init_random_number_generator((DES_cblock *) &key);
|
||||
code = DES_new_random_key((DES_cblock *) &session);
|
||||
if (code) {
|
||||
return QuickAuth(astr, aindex);
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ INCLS=bnode.h \
|
||||
${TOP_INCDIR}/afs/ktime.h
|
||||
|
||||
# EH 12/18/90 - have to search librx.a twice on Ultrix 4.0
|
||||
LIBS=${TOP_LIBDIR}/librx.a \
|
||||
LIBS= ${TOP_LIBDIR}/librx.a \
|
||||
${TOP_LIBDIR}/liblwp.a \
|
||||
${TOP_LIBDIR}/libcmd.a \
|
||||
${TOP_LIBDIR}/libkauth.a \
|
||||
@ -34,13 +34,13 @@ LIBS=${TOP_LIBDIR}/librx.a \
|
||||
${TOP_LIBDIR}/libauth.a \
|
||||
${TOP_LIBDIR}/librxstat.a \
|
||||
${TOP_LIBDIR}/librxkad.a \
|
||||
${TOP_LIBDIR}/libdes.a \
|
||||
${TOP_LIBDIR}/libubik.a \
|
||||
${TOP_LIBDIR}/librx.a \
|
||||
${TOP_LIBDIR}/libcom_err.a \
|
||||
${TOP_LIBDIR}/util.a \
|
||||
${TOP_LIBDIR}/libsys.a \
|
||||
${TOP_LIBDIR}/libprocmgmt.a
|
||||
${TOP_LIBDIR}/libprocmgmt.a \
|
||||
${TOP_LIBDIR}/libafshcrypto_lwp.a \
|
||||
|
||||
OBJS=bosserver.o bnode.o ezbnodeops.o fsbnodeops.o bosint.ss.o bosint.xdr.o \
|
||||
bosoprocs.o cronbnodeops.o
|
||||
@ -97,12 +97,12 @@ bosoprocs.o: bosoprocs.c ${INCLS}
|
||||
bos.o: bos.c ${INCLS} AFS_component_version_number.o
|
||||
|
||||
bos: bos.o $(LIBS) libbos.a
|
||||
$(AFS_LDRULE) bos.o libbos.a $(LIBS) $(LIB_roken) ${XLIBS}
|
||||
$(AFS_LDRULE) bos.o libbos.a $(LIBS) $(LIB_roken) $(LIB_crypt) ${XLIBS}
|
||||
|
||||
bos_util.o: bos_util.c ${INCLS} AFS_component_version_number.o ${TOP_INCDIR}/afs/bnode.h
|
||||
|
||||
bos_util: bos_util.o $(LIBS)
|
||||
$(AFS_LDRULE) bos_util.o $(LIBS) $(LIB_roken) ${XLIBS}
|
||||
$(AFS_LDRULE) bos_util.o $(LIBS) $(LIB_roken) $(LIB_crypt) ${XLIBS}
|
||||
|
||||
ezbnodeops.o: ezbnodeops.c ${INCLS}
|
||||
|
||||
@ -115,7 +115,7 @@ libbos.a: bosint.xdr.o bosint.cs.o boserr.o AFS_component_version_number.o
|
||||
|
||||
bosserver: $(OBJS) $(LIBS)
|
||||
$(AFS_LDRULE) $(OBJS) ${TOP_LIBDIR}/libaudit.a \
|
||||
$(LIBS) $(LIB_roken) ${XLIBS}
|
||||
$(LIBS) $(LIB_roken) $(LIB_crypt) ${XLIBS}
|
||||
|
||||
#
|
||||
# Install targets
|
||||
|
@ -57,7 +57,6 @@ BOSSERVER_EXELIBS =\
|
||||
$(DESTDIR)\lib\afs\afsauth.lib \
|
||||
$(DESTDIR)\lib\afsrxkad.lib \
|
||||
$(DESTDIR)\lib\afsrxstat.lib \
|
||||
$(DESTDIR)\lib\afsdes.lib \
|
||||
$(DESTDIR)\lib\afsrx.lib \
|
||||
$(DESTDIR)\lib\afsubik.lib \
|
||||
$(DESTDIR)\lib\afs\afscom_err.lib \
|
||||
@ -69,6 +68,7 @@ BOSSERVER_EXELIBS =\
|
||||
$(DESTDIR)\lib\afs\afsprocmgmt.lib \
|
||||
$(DESTDIR)\lib\libafsconf.lib \
|
||||
$(DESTDIR)\lib\afs\afspioctl.lib \
|
||||
$(DESTDIR)\lib\afshcrypto.lib \
|
||||
$(DESTDIR)\lib\afsroken.lib
|
||||
|
||||
$(BOSSERVER_EXEFILE): $(BOSSERVER_EXEOBJS) $(BOSSERVER_EXELIBS)
|
||||
@ -97,7 +97,6 @@ BOS_EXELIBS =\
|
||||
$(DESTDIR)\lib\afs\afsvldb.lib \
|
||||
$(DESTDIR)\lib\afs\afsauth.lib \
|
||||
$(DESTDIR)\lib\afsrxkad.lib \
|
||||
$(DESTDIR)\lib\afsdes.lib \
|
||||
$(DESTDIR)\lib\afsrx.lib \
|
||||
$(DESTDIR)\lib\afsubik.lib \
|
||||
$(DESTDIR)\lib\afs\afscom_err.lib \
|
||||
@ -107,6 +106,7 @@ BOS_EXELIBS =\
|
||||
$(DESTDIR)\lib\afs\afsprocmgmt.lib \
|
||||
$(DESTDIR)\lib\afs\afspioctl.lib \
|
||||
$(DESTDIR)\lib\libafsconf.lib \
|
||||
$(DESTDIR)\lib\afshcrypto.lib \
|
||||
$(DESTDIR)\lib\afsroken.lib
|
||||
|
||||
|
||||
|
@ -45,8 +45,7 @@
|
||||
#include <afs/com_err.h>
|
||||
#include <ubik.h>
|
||||
#include <afs/ktime.h>
|
||||
#include <des.h>
|
||||
#include <des_prototypes.h>
|
||||
#include <hcrypto/ui.h>
|
||||
#include <afs/kautils.h>
|
||||
#include <afs/volser.h>
|
||||
|
||||
@ -816,12 +815,12 @@ AddKey(struct cmd_syndesc *as, void *arock)
|
||||
strcpy(buf, as->parms[1].items->data);
|
||||
else {
|
||||
/* prompt for key */
|
||||
code = des_read_pw_string(buf, sizeof(buf), "input key: ", 0);
|
||||
code = UI_UTIL_read_pw_string(buf, sizeof(buf), "input key: ", 0);
|
||||
if (code || strlen(buf) == 0) {
|
||||
fprintf(stderr, "Bad key: \n");
|
||||
exit(1);
|
||||
}
|
||||
code = des_read_pw_string(ver, sizeof(ver), "Retype input key: ", 0);
|
||||
code = UI_UTIL_read_pw_string(ver, sizeof(ver), "Retype input key: ", 0);
|
||||
if (code || strlen(ver) == 0) {
|
||||
fprintf(stderr, "Bad key: \n");
|
||||
exit(1);
|
||||
|
@ -31,12 +31,11 @@
|
||||
|
||||
#include <afs/stds.h>
|
||||
#include <afs/afsutil.h>
|
||||
#include <rx/rxkad.h>
|
||||
#include <afs/keys.h>
|
||||
#include <afs/cellconfig.h>
|
||||
#include <afs/kautils.h>
|
||||
#include <des.h>
|
||||
#include <des_prototypes.h>
|
||||
#include <hcrypto/ui.h>
|
||||
#include <hcrypto/des.h>
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
@ -76,12 +75,12 @@ main(int argc, char **argv)
|
||||
memset(&tkey, 0, sizeof(struct ktc_encryptionKey));
|
||||
|
||||
/* prompt for key */
|
||||
code = des_read_pw_string(buf, sizeof(buf), "input key: ", 0);
|
||||
code = UI_UTIL_read_pw_string(buf, sizeof(buf), "input key: ", 0);
|
||||
if (code || strlen(buf) == 0) {
|
||||
printf("Bad key: \n");
|
||||
exit(1);
|
||||
}
|
||||
code = des_read_pw_string(ver, sizeof(ver), "Retype input key: ", 0);
|
||||
code = UI_UTIL_read_pw_string(ver, sizeof(ver), "Retype input key: ", 0);
|
||||
if (code || strlen(ver) == 0) {
|
||||
printf("Bad key: \n");
|
||||
exit(1);
|
||||
@ -97,7 +96,7 @@ main(int argc, char **argv)
|
||||
exit(1);
|
||||
}
|
||||
} else if (strcmp(argv[1], "adddes") == 0) {
|
||||
struct ktc_encryptionKey tkey;
|
||||
DES_cblock tkey;
|
||||
int kvno;
|
||||
afs_int32 code;
|
||||
char buf[BUFSIZ], ver[BUFSIZ];
|
||||
@ -110,12 +109,12 @@ main(int argc, char **argv)
|
||||
memset(&tkey, 0, sizeof(struct ktc_encryptionKey));
|
||||
|
||||
/* prompt for key */
|
||||
code = des_read_pw_string(buf, sizeof(buf), "input key: ", 0);
|
||||
code = UI_UTIL_read_pw_string(buf, sizeof(buf), "input key: ", 0);
|
||||
if (code || strlen(buf) == 0) {
|
||||
printf("Bad key: \n");
|
||||
exit(1);
|
||||
}
|
||||
code = des_read_pw_string(ver, sizeof(ver), "Retype input key: ", 0);
|
||||
code = UI_UTIL_read_pw_string(ver, sizeof(ver), "Retype input key: ", 0);
|
||||
if (code || strlen(ver) == 0) {
|
||||
printf("Bad key: \n");
|
||||
exit(1);
|
||||
@ -124,8 +123,8 @@ main(int argc, char **argv)
|
||||
printf("\nInput key mismatch\n");
|
||||
exit(1);
|
||||
}
|
||||
des_string_to_key(buf, ktc_to_cblockptr(&tkey));
|
||||
code = afsconf_AddKey(tdir, kvno, ktc_to_charptr(&tkey), 0);
|
||||
DES_string_to_key(buf, &tkey);
|
||||
code = afsconf_AddKey(tdir, kvno, (char *) &tkey, 0);
|
||||
if (code) {
|
||||
printf("bos_util: failed to set key, code %d.\n", code);
|
||||
exit(1);
|
||||
|
@ -29,7 +29,6 @@
|
||||
#include <afs/cellconfig.h>
|
||||
#include <afs/keys.h>
|
||||
#include <sys/stat.h>
|
||||
#include <des.h>
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
#ifdef HAVE_STDINT_H
|
||||
|
@ -19,10 +19,12 @@ LIBS=${TOP_LIBDIR}/libbudb.a ${TOP_LIBDIR}/libbubasics.a \
|
||||
${TOP_LIBDIR}/libvldb.a ${TOP_LIBDIR}/vlib.a \
|
||||
${TOP_LIBDIR}/libkauth.a ${TOP_LIBDIR}/libubik.a \
|
||||
${TOP_LIBDIR}/libauth.a ${TOP_LIBDIR}/librxkad.a \
|
||||
${TOP_LIBDIR}/libsys.a ${TOP_LIBDIR}/libdes.a \
|
||||
${TOP_LIBDIR}/libsys.a \
|
||||
${TOP_LIBDIR}/librx.a ${TOP_LIBDIR}/libsys.a \
|
||||
${TOP_LIBDIR}/liblwp.a ${TOP_LIBDIR}/libcmd.a \
|
||||
${TOP_LIBDIR}/libcom_err.a ${TOP_LIBDIR}/util.a
|
||||
${TOP_LIBDIR}/libcom_err.a \
|
||||
${TOP_LIBDIR}/libafshcrypto_lwp.a \
|
||||
${TOP_LIBDIR}/util.a
|
||||
|
||||
all: ${TOP_LIBDIR}/libbxdb.a ${TOP_INCDIR}/afs/bucoord_prototypes.h ${TOP_INCDIR}/afs/bc.h backup
|
||||
|
||||
|
@ -81,7 +81,6 @@ EXELIBS =\
|
||||
$(DESTDIR)\lib\afsubik.lib \
|
||||
$(DESTDIR)\lib\afs\afsauth.lib \
|
||||
$(DESTDIR)\lib\afsrxkad.lib \
|
||||
$(DESTDIR)\lib\afsdes.lib \
|
||||
$(DESTDIR)\lib\afsrx.lib \
|
||||
$(DESTDIR)\lib\afslwp.lib \
|
||||
$(DESTDIR)\lib\afs\afscmd.lib \
|
||||
@ -92,6 +91,7 @@ EXELIBS =\
|
||||
$(DESTDIR)\lib\afs\afspioctl.lib \
|
||||
$(DESTDIR)\lib\afs\afsreg.lib \
|
||||
$(DESTDIR)\lib\libafsconf.lib \
|
||||
$(DESTDIR)\lib\afshcrypto.lib \
|
||||
$(DESTDIR)\lib\afsroken.lib
|
||||
|
||||
|
||||
|
@ -19,7 +19,6 @@ INCLS=\
|
||||
${TOP_INCDIR}/lock.h \
|
||||
${TOP_INCDIR}/ubik.h \
|
||||
${TOP_INCDIR}/lwp.h \
|
||||
${TOP_INCDIR}/des.h \
|
||||
${TOP_INCDIR}/rx/rx.h \
|
||||
${TOP_INCDIR}/rx/xdr.h \
|
||||
${TOP_INCDIR}/rx/rxkad.h \
|
||||
@ -38,12 +37,12 @@ LIBS=${TOP_LIBDIR}/libbubasics.a \
|
||||
${TOP_LIBDIR}/libauth.a \
|
||||
${TOP_LIBDIR}/librxkad.a \
|
||||
${TOP_LIBDIR}/libsys.a \
|
||||
${TOP_LIBDIR}/libdes.a \
|
||||
${TOP_LIBDIR}/librx.a \
|
||||
${TOP_LIBDIR}/libsys.a \
|
||||
${TOP_LIBDIR}/liblwp.a \
|
||||
${TOP_LIBDIR}/libcmd.a \
|
||||
${TOP_LIBDIR}/libcom_err.a \
|
||||
${TOP_LIBDIR}/libafshcrypto_lwp.a \
|
||||
${TOP_LIBDIR}/util.a
|
||||
|
||||
COMMON_OBJS = database.o db_alloc.o db_dump.o db_hash.o struct_ops.o ol_verify.o
|
||||
|
@ -68,7 +68,6 @@ EXELIBS =\
|
||||
$(DESTDIR)\lib\afslwp.lib \
|
||||
$(DESTDIR)\lib\afs\afscom_err.lib \
|
||||
$(DESTDIR)\lib\afs\afsaudit.lib \
|
||||
$(DESTDIR)\lib\afsdes.lib \
|
||||
$(DESTDIR)\lib\afsrxkad.lib \
|
||||
$(DESTDIR)\lib\afs\afskauth.lib \
|
||||
$(DESTDIR)\lib\afs\afsauth.lib \
|
||||
@ -80,6 +79,7 @@ EXELIBS =\
|
||||
$(DESTDIR)\lib\afs\afsprocmgmt.lib \
|
||||
$(DESTDIR)\lib\libafsconf.lib \
|
||||
$(DESTDIR)\lib\afs\afspioctl.lib \
|
||||
$(DESTDIR)\lib\afshcrypto.lib \
|
||||
$(DESTDIR)\lib\afsroken.lib
|
||||
|
||||
$(EXEFILE): $(EXEOBJS) $(EXELIBS)
|
||||
|
@ -36,7 +36,6 @@
|
||||
#include <rx/rx.h>
|
||||
#include <rx/rxkad.h>
|
||||
#include <string.h>
|
||||
#include <des.h>
|
||||
#include <afs/cellconfig.h>
|
||||
#include <errno.h>
|
||||
#include "budb.h"
|
||||
|
@ -39,7 +39,6 @@
|
||||
#include <rx/xdr.h>
|
||||
#include <rx/rx.h>
|
||||
#include <rx/rxkad.h>
|
||||
#include <des.h>
|
||||
#include <afs/cellconfig.h>
|
||||
#include <afs/auth.h>
|
||||
#include <errno.h>
|
||||
|
@ -40,12 +40,12 @@ LIBS=${TOP_LIBDIR}/libbudb.a \
|
||||
${TOP_LIBDIR}/libauth.a \
|
||||
${TOP_LIBDIR}/librxkad.a \
|
||||
${TOP_LIBDIR}/libsys.a \
|
||||
${TOP_LIBDIR}/libdes.a \
|
||||
${TOP_LIBDIR}/librx.a \
|
||||
${TOP_LIBDIR}/libsys.a \
|
||||
${TOP_LIBDIR}/liblwp.a \
|
||||
${TOP_LIBDIR}/libcmd.a \
|
||||
${TOP_LIBDIR}/libcom_err.a \
|
||||
${TOP_LIBDIR}/libafshcrypto_lwp.a \
|
||||
${TOP_LIBDIR}/libusd.a \
|
||||
${TOP_LIBDIR}/util.a \
|
||||
${TOP_LIBDIR}/libprocmgmt.a
|
||||
|
@ -42,7 +42,6 @@ EXELIBS =\
|
||||
$(DESTDIR)\lib\afsubik.lib \
|
||||
$(DESTDIR)\lib\afs\afsauth.lib \
|
||||
$(DESTDIR)\lib\afsrxkad.lib \
|
||||
$(DESTDIR)\lib\afsdes.lib \
|
||||
$(DESTDIR)\lib\afsrx.lib \
|
||||
$(DESTDIR)\lib\afslwp.lib \
|
||||
$(DESTDIR)\lib\afs\afscmd.lib \
|
||||
@ -54,6 +53,7 @@ EXELIBS =\
|
||||
$(DESTDIR)\lib\afs\afseventlog.lib \
|
||||
$(DESTDIR)\lib\afs\afsreg.lib \
|
||||
$(DESTDIR)\lib\libafsconf.lib \
|
||||
$(DESTDIR)\lib\afshcrypto.lib \
|
||||
$(DESTDIR)\lib\afsroken.lib
|
||||
|
||||
$(EXERES): butc.rc AFS_component_version_number.h
|
||||
|
@ -88,12 +88,6 @@ idirs: doclink
|
||||
! IF (!EXIST($(OJT)\crypto\hcrypto))
|
||||
$(MKDIR) $(OJT)\crypto\hcrypto
|
||||
! ENDIF
|
||||
! IF (!EXIST($(OJT)\des))
|
||||
$(MKDIR) $(OJT)\des
|
||||
! ENDIF
|
||||
! IF (!EXIST($(OJT)\des\test))
|
||||
$(MKDIR) $(OJT)\des\test
|
||||
! ENDIF
|
||||
! IF (!EXIST($(OJT)\dir))
|
||||
$(MKDIR) $(OJT)\dir
|
||||
! ENDIF
|
||||
@ -424,9 +418,6 @@ idirs: doclink
|
||||
! IF (!EXIST($(DESTDIR)\include\afs))
|
||||
$(MKDIR) $(DESTDIR)\include\afs
|
||||
! ENDIF
|
||||
! IF (!EXIST($(DESTDIR)\include\des))
|
||||
$(MKDIR) $(DESTDIR)\include\des
|
||||
! ENDIF
|
||||
! IF (!EXIST($(DESTDIR)\include\hcrypto))
|
||||
$(MKDIR) $(DESTDIR)\include\hcrypto
|
||||
! ENDIF
|
||||
|
@ -15,3 +15,5 @@ EXPORTS
|
||||
hc_MD5_Init @14
|
||||
hc_MD5_Update @15
|
||||
hc_UI_UTIL_read_pw_string @16
|
||||
hc_DES_is_weak_key @17
|
||||
hc_DES_check_key_parity @18
|
||||
|
19
src/des/.gitignore
vendored
19
src/des/.gitignore
vendored
@ -1,19 +0,0 @@
|
||||
# After changing this file, please run
|
||||
# git ls-files -i --exclude-standard
|
||||
# to check that you haven't inadvertently ignored any tracked files.
|
||||
|
||||
/fp.c
|
||||
/ip.c
|
||||
/key_perm.h
|
||||
/make_fp
|
||||
/make_ip
|
||||
/make_keyperm
|
||||
/make_odd
|
||||
/make_p
|
||||
/make_p_table
|
||||
/make_s_table
|
||||
/odd.h
|
||||
/p.c
|
||||
/p_table.h
|
||||
/s_table.h
|
||||
/s.c
|
@ -1,235 +0,0 @@
|
||||
#
|
||||
# Copyright 1987 by the Massachusetts Institute of Technology.
|
||||
#
|
||||
# For copying and distribution information,
|
||||
# please see the file <mit-cpyright.h>.
|
||||
#
|
||||
# Makefile for BSD DES library
|
||||
#
|
||||
# First define machine type, compiler, and object file suffix
|
||||
# Could be for VAX or PC-DOS
|
||||
#
|
||||
# Some of these files are cross compiled on the vax for the pc8086,
|
||||
# using the MIT LCS cross-compilation environment
|
||||
# Others are always executed on the vax(host).
|
||||
#
|
||||
# A machine, e.g. Vax, pc8086, IBM experimental workstation, is
|
||||
# described in terms of defines for its word length
|
||||
# (BITS32 or BITS16), byte ordering (LSBFIRST or MSBFIRST) and
|
||||
# operating system (BSDUNIX or CROSSMSDOS).
|
||||
#
|
||||
# Make sure these are properly defined for any new machine types.
|
||||
# target machine for run-time code (may cross-compile),
|
||||
# override as needed
|
||||
|
||||
srcdir=@srcdir@
|
||||
include @TOP_OBJDIR@/src/config/Makefile.config
|
||||
include @TOP_OBJDIR@/src/config/Makefile.lwp
|
||||
|
||||
INSTALL = @INSTALL@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@
|
||||
INSTALL_SCRIPT = @INSTALL_SCRIPT@
|
||||
|
||||
OBJS = \
|
||||
des.o \
|
||||
cbc_encrypt.o \
|
||||
pcbc_encrypt.o \
|
||||
cksum.o \
|
||||
new_rnd_key.o \
|
||||
key_sched.o \
|
||||
debug_decl.o \
|
||||
quad_cksum.o \
|
||||
key_parity.o \
|
||||
weak_key.o \
|
||||
read_pssword.o \
|
||||
strng_to_key.o \
|
||||
misc.o \
|
||||
crypt.o \
|
||||
util.o
|
||||
|
||||
all: \
|
||||
${TOP_LIBDIR}/libdes.a \
|
||||
${TOP_INCDIR}/des.h \
|
||||
${TOP_INCDIR}/des_prototypes.h \
|
||||
${TOP_INCDIR}/des_conf.h \
|
||||
${TOP_INCDIR}/mit-cpyright.h \
|
||||
${TOP_INCDIR}/des_odd.h
|
||||
|
||||
buildtools: \
|
||||
make_p \
|
||||
make_keyperm \
|
||||
make_s_table \
|
||||
make_p_table \
|
||||
make_ip \
|
||||
make_fp \
|
||||
make_odd \
|
||||
${TOP_INCDIR}/des.h \
|
||||
${TOP_INCDIR}/mit-cpyright.h \
|
||||
|
||||
generated: \
|
||||
p.c \
|
||||
key_perm.h \
|
||||
s_table.h \
|
||||
p_table.h \
|
||||
ip.c \
|
||||
fp.c \
|
||||
odd.h
|
||||
|
||||
${TOP_LIBDIR}/libdes.a: libdes.a
|
||||
${INSTALL_DATA} $? $@
|
||||
|
||||
${TOP_INCDIR}/des.h: des.h
|
||||
${INSTALL_DATA} $? $@
|
||||
|
||||
${TOP_INCDIR}/des_prototypes.h: des_prototypes.h
|
||||
${INSTALL_DATA} $? $@
|
||||
|
||||
${TOP_INCDIR}/des_conf.h: des_conf.h
|
||||
${INSTALL_DATA} $? $@
|
||||
|
||||
${TOP_INCDIR}/mit-cpyright.h: mit-cpyright.h
|
||||
${INSTALL_DATA} $? $@
|
||||
|
||||
${TOP_INCDIR}/des_odd.h: odd.h
|
||||
${INSTALL_DATA} $? $@
|
||||
|
||||
#
|
||||
# Build rules
|
||||
#
|
||||
libdes.a: ${OBJS} AFS_component_version_number.o
|
||||
$(RM) -f libdes.a
|
||||
$(AR) crv libdes.a ${OBJS} AFS_component_version_number.o
|
||||
$(RANLIB) libdes.a
|
||||
|
||||
make_ip: make_ip.o misc.o main.o
|
||||
$(AFS_LDRULE) make_ip.o misc.o main.o
|
||||
|
||||
make_fp: make_fp.o misc.o main.o
|
||||
$(AFS_LDRULE) make_fp.o misc.o main.o
|
||||
|
||||
make_odd: make_odd.o misc.o main.o
|
||||
$(AFS_LDRULE) make_odd.o misc.o main.o
|
||||
|
||||
make_s_table: make_s_table.o misc.o main.o
|
||||
$(AFS_LDRULE) make_s_table.o misc.o main.o
|
||||
|
||||
make_p_table: make_p_table.o misc.o main.o
|
||||
$(AFS_LDRULE) make_p_table.o misc.o main.o
|
||||
|
||||
make_keyperm: make_keyperm.o misc.o main.o
|
||||
$(AFS_LDRULE) make_keyperm.o misc.o main.o
|
||||
|
||||
make_e: make_e.o misc.o main.o
|
||||
$(AFS_LDRULE) make_e.o misc.o main.o
|
||||
|
||||
make_p: make_p.o misc.o main.o
|
||||
$(AFS_LDRULE) make_p.o misc.o main.o
|
||||
|
||||
make_s: make_s.o misc.o main.o
|
||||
$(AFS_LDRULE) make_s.o misc.o main.o
|
||||
|
||||
crypt.o: ${srcdir}/crypt.c
|
||||
case ${SYS_NAME} in \
|
||||
rs_aix*)\
|
||||
${CCOBJ} -c ${COMMON_INCL} -o crypt.o ${srcdir}/crypt.c ;;\
|
||||
*)\
|
||||
$(AFS_CCRULE) ${srcdir}/crypt.c ;;\
|
||||
esac
|
||||
#
|
||||
# Table/code generation targets
|
||||
#
|
||||
odd.h: make_odd
|
||||
./make_odd odd.h
|
||||
|
||||
s_table.h: make_s_table
|
||||
./make_s_table s_table.h
|
||||
|
||||
p_table.h: make_p_table
|
||||
./make_p_table p_table.h
|
||||
|
||||
key_perm.h: make_keyperm
|
||||
./make_keyperm key_perm.h
|
||||
|
||||
ip.c: make_ip
|
||||
./make_ip ip.c
|
||||
|
||||
p.c: make_p
|
||||
./make_p p.c
|
||||
|
||||
s.c: make_s
|
||||
./make_s s.c
|
||||
|
||||
fp.c: make_fp
|
||||
./make_fp fp.c
|
||||
|
||||
#
|
||||
# Dependency rules
|
||||
#
|
||||
INCLS=des.h des_prototypes.h mit-cpyright.h des_conf.h des_internal.h conf.h
|
||||
|
||||
make_keyperm.o: make_keyperm.c ${INCLS}
|
||||
make_ip.o: make_ip.c tables.h ${INCLS}
|
||||
make_fp.o: make_fp.c tables.h ${INCLS}
|
||||
make_p.o: make_p.c tables.h ${INCLS}
|
||||
make_s.o: make_s.c s_table.h ${INCLS}
|
||||
make_s_table.o: make_s_table.c tables.h ${INCLS}
|
||||
make_p_table.o: make_p_table.c tables.h ${INCLS}
|
||||
make_odd.o: make_odd.c ${INCLS}
|
||||
misc.o: misc.c AFS_component_version_number.c ${INCLS}
|
||||
main.o: main.c AFS_component_version_number.c ${INCLS}
|
||||
key_sched.o: key_sched.c key_perm.h odd.h ${INCLS}
|
||||
key_test.o: key_test.c ${INCLS}
|
||||
testit.o: testit.c ${INCLS}
|
||||
des.o: s_table.h p_table.h ip.c p.c fp.c ${INCLS}
|
||||
cbc_encrypt.o: cbc_encrypt.c ${INCLS}
|
||||
verify.o: verify.c ${INCLS}
|
||||
read_pssword.o: read_pssword.c ${INCLS}
|
||||
pcbc_encrypt.o: pcbc_encrypt.c ${INCLS}
|
||||
cksum.o: cksum.c ${INCLS}
|
||||
quad_cksum.o: quad_cksum.c ${INCLS}
|
||||
key_parity.o: key_parity.c odd.h ${INCLS}
|
||||
weak_key.o: weak_key.c ${INCLS}
|
||||
new_rnd_key.o: new_rnd_key.c ${INCLS}
|
||||
util.o: util.c ${INCLS}
|
||||
strng_to_key.o: strng_to_key.c ${INCLS}
|
||||
debug_decl.o: debug_decl.c ${INCLS}
|
||||
make_e.o: make_e.c ${INCLS}
|
||||
|
||||
#
|
||||
# Install targets
|
||||
#
|
||||
install: libdes.a des.h des_prototypes.h des_conf.h mit-cpyright.h odd.h
|
||||
${INSTALL} -d ${DESTDIR}${libdir}
|
||||
${INSTALL} -d ${DESTDIR}${includedir}
|
||||
${INSTALL_DATA} libdes.a ${DESTDIR}${libdir}/libdes.a
|
||||
${INSTALL_DATA} ${srcdir}/des.h ${DESTDIR}${includedir}/des.h
|
||||
${INSTALL_DATA} ${srcdir}/des_prototypes.h ${DESTDIR}${includedir}/des_prototypes.h
|
||||
${INSTALL_DATA} ${srcdir}/des_conf.h ${DESTDIR}${includedir}/des_conf.h
|
||||
${INSTALL_DATA} ${srcdir}/mit-cpyright.h ${DESTDIR}${includedir}/mit-cpyright.h
|
||||
${INSTALL_DATA} odd.h ${DESTDIR}${includedir}/des_odd.h
|
||||
|
||||
dest: libdes.a des.h des_prototypes.h des_conf.h mit-cpyright.h odd.h
|
||||
${INSTALL} -d ${DEST}/lib
|
||||
${INSTALL} -d ${DEST}/include
|
||||
${INSTALL_DATA} libdes.a ${DEST}/lib/libdes.a
|
||||
${INSTALL_DATA} ${srcdir}/des.h ${DEST}/include/des.h
|
||||
${INSTALL_DATA} ${srcdir}/des_prototypes.h ${DEST}/include/des_prototypes.h
|
||||
${INSTALL_DATA} ${srcdir}/des_conf.h ${DEST}/include/des_conf.h
|
||||
${INSTALL_DATA} ${srcdir}/mit-cpyright.h ${DEST}/include/mit-cpyright.h
|
||||
${INSTALL_DATA} odd.h ${DEST}/include/des_odd.h
|
||||
|
||||
#
|
||||
# Misc. targets
|
||||
#
|
||||
test: libdes.a
|
||||
cd test; $(MAKE)
|
||||
|
||||
clean:
|
||||
$(RM) -f *.a *.s *.o *.b core *~ *.com *.ld
|
||||
$(RM) -f make_fp make_ip make_keyperm make_odd make_p \
|
||||
make_p_table make_s_table key_perm.h p_table.h \
|
||||
s_table.h odd.h p.c s.c fp.c ip.c AFS_component_version_number.c
|
||||
cd test; $(MAKE) clean
|
||||
|
||||
include ../config/Makefile.version
|
@ -1,184 +0,0 @@
|
||||
#
|
||||
# Copyright 1987 by the Massachusetts Institute of Technology.
|
||||
#
|
||||
# For copying and distribution information,
|
||||
# please see the file <mit-cpyright.h>.
|
||||
#
|
||||
# Makefile for BSD DES library
|
||||
#
|
||||
# First define machine type, compiler, and object file suffix
|
||||
# Could be for VAX or PC-DOS
|
||||
#
|
||||
# Some of these files are cross compiled on the vax for the pc8086,
|
||||
# using the MIT LCS cross-compilation environment
|
||||
# Others are always executed on the vax(host).
|
||||
#
|
||||
# A machine, e.g. Vax, pc8086, IBM experimental workstation, is
|
||||
# described in terms of defines for its word length
|
||||
# (BITS32 or BITS16), byte ordering (LSBFIRST or MSBFIRST) and
|
||||
# operating system (BSDUNIX or CROSSMSDOS).
|
||||
#
|
||||
# Make sure these are properly defined for any new machine types.
|
||||
# target machine for run-time code (may cross-compile),
|
||||
# override as needed
|
||||
#
|
||||
|
||||
RELDIR=des
|
||||
!INCLUDE ..\config\NTMakefile.$(SYS_NAME)
|
||||
!INCLUDE ..\config\NTMakefile.version
|
||||
|
||||
INCFILEDIR = $(DESTDIR)\include
|
||||
|
||||
INCFILES =\
|
||||
$(INCFILEDIR)\des.h \
|
||||
$(INCFILEDIR)\des_conf.h \
|
||||
$(INCFILEDIR)\des_prototypes.h \
|
||||
$(INCFILEDIR)\mit-cpyright.h \
|
||||
$(INCFILEDIR)\des_odd.h \
|
||||
$(INCFILEDIR)\crypt.h
|
||||
|
||||
$(INCFILEDIR)\des_odd.h: odd.h
|
||||
$(COPY) odd.h $@
|
||||
|
||||
# Library component lists.
|
||||
|
||||
LIBOBJS = \
|
||||
$(OUT)\des.obj \
|
||||
$(OUT)\cbc_encrypt.obj \
|
||||
$(OUT)\pcbc_encrypt.obj \
|
||||
$(OUT)\cksum.obj \
|
||||
$(OUT)\new_rnd_key.obj \
|
||||
$(OUT)\key_sched.obj \
|
||||
$(OUT)\debug_decl.obj \
|
||||
$(OUT)\quad_cksum.obj \
|
||||
$(OUT)\key_parity.obj \
|
||||
$(OUT)\weak_key.obj \
|
||||
$(OUT)\read_pssword.obj \
|
||||
$(OUT)\strng_to_key.obj \
|
||||
$(OUT)\misc.obj \
|
||||
$(OUT)\util.obj \
|
||||
$(OUT)\crypt.obj
|
||||
|
||||
$(LIBOBJS): $$(@B).c
|
||||
$(C2OBJ) $**
|
||||
|
||||
LIBFILE = $(DESTDIR)\lib\afsdes.lib
|
||||
|
||||
$(LIBFILE): $(LIBOBJS)
|
||||
$(LIBARCH)
|
||||
|
||||
#####################
|
||||
# Generator Files ###
|
||||
#####################
|
||||
|
||||
GENERATED_FILES = \
|
||||
$(VERSFILE).c \
|
||||
key_perm.h \
|
||||
p_table.h \
|
||||
s_table.h \
|
||||
odd.h \
|
||||
p.c \
|
||||
s.c \
|
||||
fp.c \
|
||||
ip.c
|
||||
|
||||
# Make generated files.
|
||||
MAKETARG = $** $@
|
||||
|
||||
key_perm.h: $(OUT)\make_keyperm.exe
|
||||
$(MAKETARG)
|
||||
|
||||
p_table.h: $(OUT)\make_p_table.exe
|
||||
$(MAKETARG)
|
||||
|
||||
s_table.h: $(OUT)\make_s_table.exe
|
||||
$(MAKETARG)
|
||||
|
||||
odd.h: $(OUT)\make_odd.exe
|
||||
$(MAKETARG)
|
||||
|
||||
p.c: $(OUT)\make_p.exe
|
||||
$(MAKETARG)
|
||||
|
||||
s.c: $(OUT)\make_s.exe
|
||||
$(MAKETARG)
|
||||
|
||||
fp.c: $(OUT)\make_fp.exe
|
||||
$(MAKETARG)
|
||||
|
||||
ip.c: $(OUT)\make_ip.exe
|
||||
$(MAKETARG)
|
||||
|
||||
# Make generators.
|
||||
$(OUT)\main.obj: main.c
|
||||
$(C2OBJ) $**
|
||||
|
||||
$(OUT)\make_keyperm.exe: $(OUT)\make_keyperm.obj $(OUT)\misc.obj $(OUT)\main.obj
|
||||
$(EXECONLINK)
|
||||
$(_VC_MANIFEST_EMBED_EXE)
|
||||
$(CODESIGN_USERLAND)
|
||||
$(SYMSTORE_IMPORT)
|
||||
|
||||
$(OUT)\make_p_table.exe: $(OUT)\make_p_table.obj $(OUT)\misc.obj $(OUT)\main.obj
|
||||
$(EXECONLINK)
|
||||
$(_VC_MANIFEST_EMBED_EXE)
|
||||
$(CODESIGN_USERLAND)
|
||||
$(SYMSTORE_IMPORT)
|
||||
|
||||
$(OUT)\make_s_table.exe: $(OUT)\make_s_table.obj $(OUT)\misc.obj $(OUT)\main.obj
|
||||
$(EXECONLINK)
|
||||
$(_VC_MANIFEST_EMBED_EXE)
|
||||
$(CODESIGN_USERLAND)
|
||||
$(SYMSTORE_IMPORT)
|
||||
|
||||
$(OUT)\make_odd.exe: $(OUT)\make_odd.obj $(OUT)\misc.obj $(OUT)\main.obj
|
||||
$(EXECONLINK)
|
||||
$(_VC_MANIFEST_EMBED_EXE)
|
||||
$(CODESIGN_USERLAND)
|
||||
$(SYMSTORE_IMPORT)
|
||||
|
||||
$(OUT)\make_p.exe: $(OUT)\make_p.obj $(OUT)\misc.obj $(OUT)\main.obj
|
||||
$(EXECONLINK)
|
||||
$(_VC_MANIFEST_EMBED_EXE)
|
||||
$(CODESIGN_USERLAND)
|
||||
$(SYMSTORE_IMPORT)
|
||||
|
||||
$(OUT)\make_s.exe: $(OUT)\make_s.obj $(OUT)\misc.obj $(OUT)\main.obj
|
||||
$(EXECONLINK)
|
||||
$(_VC_MANIFEST_EMBED_EXE)
|
||||
$(CODESIGN_USERLAND)
|
||||
$(SYMSTORE_IMPORT)
|
||||
|
||||
$(OUT)\make_fp.exe: $(OUT)\make_fp.obj $(OUT)\misc.obj $(OUT)\main.obj
|
||||
$(EXECONLINK)
|
||||
$(_VC_MANIFEST_EMBED_EXE)
|
||||
$(CODESIGN_USERLAND)
|
||||
$(SYMSTORE_IMPORT)
|
||||
|
||||
$(OUT)\make_ip.exe: $(OUT)\make_ip.obj $(OUT)\misc.obj $(OUT)\main.obj
|
||||
$(EXECONLINK)
|
||||
$(_VC_MANIFEST_EMBED_EXE)
|
||||
$(CODESIGN_USERLAND)
|
||||
$(SYMSTORE_IMPORT)
|
||||
|
||||
GENOBJS = $(OUT)\make_keyperm.obj \
|
||||
$(OUT)\make_p_table.obj \
|
||||
$(OUT)\make_s_table.obj \
|
||||
$(OUT)\make_odd.obj \
|
||||
$(OUT)\make_p.obj \
|
||||
$(OUT)\make_s.obj \
|
||||
$(OUT)\make_fp.obj \
|
||||
$(OUT)\make_ip.obj
|
||||
|
||||
$(GENOBJS): $$(@B).c
|
||||
$(C2OBJ) $**
|
||||
|
||||
install: $(GENERATED_FILES) $(LIBFILE) $(INCFILES)
|
||||
|
||||
install9x: install
|
||||
|
||||
clean::
|
||||
$(DEL) $(LIBFILE) $(GENERATED_FILES)
|
||||
|
||||
mkdir:
|
||||
|
@ -1,21 +0,0 @@
|
||||
This directory contains the sources for the DES encryption library and
|
||||
test programs.
|
||||
|
||||
Two precautions--
|
||||
|
||||
1) under US law, DES software and hardware may not be
|
||||
exported without license from the US Dept of Commerce.
|
||||
|
||||
2) The only way to get a significant speedup of the algorithm is to
|
||||
use considerably more space, traded against time. Dont play
|
||||
with the code -- there is a high probability you will either
|
||||
make it slower, or wrong, or both. This implementation was
|
||||
optimized for the UVAX 2. Other architectures could benefit from
|
||||
some "asm" tweaking.
|
||||
|
||||
3) If you do play with the code, make sure that the test program
|
||||
"verify" still yields the expected answers. Otherwise, your
|
||||
ciphertext will not decrypt under a standard implementation, such
|
||||
as on the VLSI chips that have been certified.
|
||||
|
||||
Project Athena Steve Miller 3/86
|
@ -1,119 +0,0 @@
|
||||
/*
|
||||
* Andrew configuration.
|
||||
*/
|
||||
|
||||
#ifdef vax
|
||||
#include "conf-bsdvax.h"
|
||||
#else
|
||||
#if mips && !defined(sgi)
|
||||
#include "conf-mips.h"
|
||||
#else
|
||||
#if defined(sun) && !defined(AFS_X86_ENV)
|
||||
#include "conf-bsd-sun.h"
|
||||
#else
|
||||
#ifdef AFS_AIX_ENV
|
||||
#include "conf-aix-ibm.h"
|
||||
#else
|
||||
#ifdef mac2
|
||||
#include "conf-bsd-mac.h"
|
||||
#else
|
||||
#ifdef AFS_HPUX_ENV
|
||||
#ifdef hp9000s300
|
||||
#include "conf-hp9000s300.h"
|
||||
#else
|
||||
#include "conf-hp9000s700.h"
|
||||
#endif
|
||||
#else
|
||||
#ifdef NeXT
|
||||
#include "conf-next.h"
|
||||
#else
|
||||
#if defined(sgi)
|
||||
#include "conf-sgi.h"
|
||||
#else
|
||||
#ifdef AFS_OSF_ENV
|
||||
#if defined(__alpha)
|
||||
#include "conf-bsd-alpha.h"
|
||||
#else
|
||||
#error unknown osf
|
||||
#endif
|
||||
#else
|
||||
#if defined(AFS_X86_ENV) && !defined(AFS_DARWIN_ENV)
|
||||
#include "conf-bsd-ncr.h"
|
||||
#else
|
||||
#ifdef AFS_NT40_ENV
|
||||
#include "conf-winnt.h"
|
||||
#else
|
||||
|
||||
#ifdef AFS_XBSD_ENV
|
||||
#ifdef AFS_X86_XBSD_ENV
|
||||
#include "conf-i386-obsd.h"
|
||||
#elif defined(AFS_ALPHA_ENV)
|
||||
#include "conf-alpha-bsd.h"
|
||||
#else
|
||||
#error unknown bsd
|
||||
#endif
|
||||
#else /* AFS_XBSD_ENV */
|
||||
|
||||
#if defined(AFS_LINUX20_ENV)
|
||||
#ifdef AFS_PARISC_LINUX20_ENV
|
||||
#include "conf-parisc-linux.h"
|
||||
#else
|
||||
#ifdef AFS_PPC_LINUX20_ENV
|
||||
#include "conf-ppc-linux.h"
|
||||
#else
|
||||
#ifdef AFS_SPARC_LINUX20_ENV
|
||||
#include "conf-sparc-linux.h"
|
||||
#else
|
||||
#ifdef AFS_SPARC64_LINUX20_ENV
|
||||
#include "conf-sparc64-linux.h"
|
||||
#else
|
||||
#ifdef AFS_S390_LINUX20_ENV
|
||||
#include "conf-s390-linux.h"
|
||||
#else
|
||||
#ifdef AFS_ALPHA_LINUX20_ENV
|
||||
#include "conf-alpha-linux.h"
|
||||
#else
|
||||
#ifdef AFS_IA64_LINUX20_ENV
|
||||
#include "conf-ia64-linux.h"
|
||||
#else
|
||||
#ifdef AFS_AMD64_LINUX20_ENV
|
||||
#include "conf-amd64-linux.h"
|
||||
#else
|
||||
#ifdef AFS_PPC64_LINUX20_ENV
|
||||
#include "conf-ppc64-linux.h"
|
||||
#else
|
||||
#ifdef AFS_ARM_LINUX20_ENV
|
||||
#include "conf-arm-linux.h"
|
||||
#else
|
||||
#include "conf-i386-linux.h"
|
||||
#endif /* AFS_ARM_LINUX20_ENV */
|
||||
#endif /* AFS_PPC64_LINUX20_ENV */
|
||||
#endif /* AFS_AMD64_LINUX20_ENV */
|
||||
#endif /* AFS_IA64_LINUX20_ENV */
|
||||
#endif /* AFS_ALPHA_LINUX20_ENV */
|
||||
#endif /* AFS_S390_LINUX20_ENV */
|
||||
#endif /* AFS_SPARC64_LINUX20_ENV */
|
||||
#endif /* AFS_SPARC_LINUX20_ENV */
|
||||
#endif /* AFS_PPC_LINUX20_ENV */
|
||||
#endif /* AFS_PARISC_LINUX24_ENV */
|
||||
#else
|
||||
#if defined(AFS_DARWIN_ENV)
|
||||
#include "conf-darwin.h"
|
||||
#else
|
||||
Sorry,
|
||||
you lose.
|
||||
Figure out what the machine looks like and fix this file to include it.
|
||||
#endif
|
||||
#endif /* AFS_LINUX20_ENV */
|
||||
#endif /* AFS_NT40_ENV */
|
||||
#endif /* AFS_XBSD_ENV */
|
||||
#endif /* NCR || X86 */
|
||||
#endif /* __alpha */
|
||||
#endif /* SGI */
|
||||
#endif /* NeXT */
|
||||
#endif /* HP/UX */
|
||||
#endif /* mac */
|
||||
#endif /* aix */
|
||||
#endif /* sun */
|
||||
#endif /* mips */
|
||||
#endif /* not vax */
|
@ -1,210 +0,0 @@
|
||||
/*
|
||||
* Copyright 1985, 1986, 1987, 1988 by the Massachusetts Institute
|
||||
* of Technology.
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <mit-cpyright.h>.
|
||||
*
|
||||
* These routines perform encryption and decryption using the DES
|
||||
* private key algorithm, or else a subset of it -- fewer inner loops.
|
||||
* (AUTH_DES_ITER defaults to 16, may be less.)
|
||||
*
|
||||
* Under U.S. law, this software may not be exported outside the US
|
||||
* without license from the U.S. Commerce department.
|
||||
*
|
||||
* These routines form the library interface to the DES facilities.
|
||||
*
|
||||
* Originally written 8/85 by Steve Miller, MIT Project Athena.
|
||||
*/
|
||||
|
||||
#include "mit-cpyright.h"
|
||||
#include <afsconfig.h>
|
||||
#include <afs/param.h>
|
||||
|
||||
#ifndef KERNEL
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#include "des.h"
|
||||
#include "des_prototypes.h"
|
||||
|
||||
|
||||
|
||||
#define XPRT_CBC_ENCRYPT
|
||||
|
||||
/*
|
||||
* This routine performs DES cipher-block-chaining operation, either
|
||||
* encrypting from cleartext to ciphertext, if encrypt != 0 or
|
||||
* decrypting from ciphertext to cleartext, if encrypt == 0.
|
||||
*
|
||||
* The key schedule is passed as an arg, as well as the cleartext or
|
||||
* ciphertext. The cleartext and ciphertext should be in host order.
|
||||
*
|
||||
* NOTE-- the output is ALWAYS an multiple of 8 bytes long. If not
|
||||
* enough space was provided, your program will get trashed.
|
||||
*
|
||||
* For encryption, the cleartext string is null padded, at the end, to
|
||||
* an integral multiple of eight bytes.
|
||||
*
|
||||
* For decryption, the ciphertext will be used in integral multiples
|
||||
* of 8 bytes, but only the first "length" bytes returned into the
|
||||
* cleartext.
|
||||
*/
|
||||
/*
|
||||
des_cblock *in; * >= length bytes of input text *
|
||||
des_cblock *out; * >= length bytes of output text *
|
||||
afs_int32 length; * in bytes *
|
||||
int encrypt; * 0 ==> decrypt, else encrypt *
|
||||
des_key_schedule key; * precomputed key schedule *
|
||||
des_cblock *iv; * 8 bytes of ivec *
|
||||
*/
|
||||
afs_int32
|
||||
des_cbc_encrypt(void * in, void * out, afs_int32 length,
|
||||
des_key_schedule key, des_cblock * iv, int encrypt)
|
||||
{
|
||||
afs_uint32 *input = (afs_uint32 *) in;
|
||||
afs_uint32 *output = (afs_uint32 *) out;
|
||||
afs_uint32 *ivec = (afs_uint32 *) iv;
|
||||
|
||||
afs_uint32 i, j;
|
||||
afs_uint32 t_input[2];
|
||||
afs_uint32 t_output[2];
|
||||
unsigned char *t_in_p = (unsigned char *)t_input;
|
||||
afs_uint32 xor_0, xor_1;
|
||||
|
||||
if (encrypt) {
|
||||
#ifdef MUSTALIGN
|
||||
if ((afs_int32) ivec & 3) {
|
||||
memcpy((char *)&t_output[0], (char *)ivec++, sizeof(t_output[0]));
|
||||
memcpy((char *)&t_output[1], (char *)ivec, sizeof(t_output[1]));
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
t_output[0] = *ivec++;
|
||||
t_output[1] = *ivec;
|
||||
}
|
||||
|
||||
for (i = 0; length > 0; i++, length -= 8) {
|
||||
/* get input */
|
||||
#ifdef MUSTALIGN
|
||||
if ((afs_int32) input & 3) {
|
||||
memcpy((char *)&t_input[0], (char *)input++,
|
||||
sizeof(t_input[0]));
|
||||
memcpy((char *)&t_input[1], (char *)input++,
|
||||
sizeof(t_input[1]));
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
t_input[0] = *input++;
|
||||
t_input[1] = *input++;
|
||||
}
|
||||
|
||||
/* zero pad */
|
||||
if (length < 8)
|
||||
for (j = length; j <= 7; j++)
|
||||
*(t_in_p + j) = 0;
|
||||
|
||||
#ifdef DEBUG
|
||||
if (des_debug)
|
||||
des_debug_print("clear", length, t_input[0], t_input[1]);
|
||||
#endif
|
||||
/* do the xor for cbc into the temp */
|
||||
t_input[0] ^= t_output[0];
|
||||
t_input[1] ^= t_output[1];
|
||||
/* encrypt */
|
||||
(void)des_ecb_encrypt(t_input, t_output, key, encrypt);
|
||||
/* copy temp output and save it for cbc */
|
||||
#ifdef MUSTALIGN
|
||||
if ((afs_int32) output & 3) {
|
||||
memcpy((char *)output++, (char *)&t_output[0],
|
||||
sizeof(t_output[0]));
|
||||
memcpy((char *)output++, (char *)&t_output[1],
|
||||
sizeof(t_output[1]));
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
*output++ = t_output[0];
|
||||
*output++ = t_output[1];
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
if (des_debug) {
|
||||
des_debug_print("xor'ed", i, t_input[0], t_input[1]);
|
||||
des_debug_print("cipher", i, t_output[0], t_output[1]);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
else {
|
||||
/* decrypt */
|
||||
#ifdef MUSTALIGN
|
||||
if ((afs_int32) ivec & 3) {
|
||||
memcpy((char *)&xor_0, (char *)ivec++, sizeof(xor_0));
|
||||
memcpy((char *)&xor_1, (char *)ivec, sizeof(xor_1));
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
xor_0 = *ivec++;
|
||||
xor_1 = *ivec;
|
||||
}
|
||||
|
||||
for (i = 0; length > 0; i++, length -= 8) {
|
||||
/* get input */
|
||||
#ifdef MUSTALIGN
|
||||
if ((afs_int32) input & 3) {
|
||||
memcpy((char *)&t_input[0], (char *)input++,
|
||||
sizeof(t_input[0]));
|
||||
memcpy((char *)&t_input[1], (char *)input++,
|
||||
sizeof(t_input[0]));
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
t_input[0] = *input++;
|
||||
t_input[1] = *input++;
|
||||
}
|
||||
|
||||
/* no padding for decrypt */
|
||||
#ifdef DEBUG
|
||||
if (des_debug)
|
||||
des_debug_print("cipher", i, t_input[0], t_input[1]);
|
||||
#else
|
||||
#ifdef lint
|
||||
i = i;
|
||||
#endif
|
||||
#endif
|
||||
/* encrypt */
|
||||
(void)des_ecb_encrypt(t_input, t_output, key, encrypt);
|
||||
#ifdef DEBUG
|
||||
if (des_debug)
|
||||
des_debug_print("out pre xor", i, t_output[0], t_output[1]);
|
||||
#endif
|
||||
/* do the xor for cbc into the output */
|
||||
t_output[0] ^= xor_0;
|
||||
t_output[1] ^= xor_1;
|
||||
/* copy temp output */
|
||||
#ifdef MUSTALIGN
|
||||
if ((afs_int32) output & 3) {
|
||||
memcpy((char *)output++, (char *)&t_output[0],
|
||||
sizeof(t_output[0]));
|
||||
memcpy((char *)output++, (char *)&t_output[1],
|
||||
sizeof(t_output[1]));
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
*output++ = t_output[0];
|
||||
*output++ = t_output[1];
|
||||
}
|
||||
|
||||
/* save xor value for next round */
|
||||
xor_0 = t_input[0];
|
||||
xor_1 = t_input[1];
|
||||
#ifdef DEBUG
|
||||
if (des_debug)
|
||||
des_debug_print("clear", i, t_output[0], t_output[1]);
|
||||
#endif
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
139
src/des/cksum.c
139
src/des/cksum.c
@ -1,139 +0,0 @@
|
||||
/*
|
||||
* Copyright 1985, 1986, 1987, 1988 by the Massachusetts Institute
|
||||
* of Technology.
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <mit-cpyright.h>.
|
||||
*
|
||||
* These routines perform encryption and decryption using the DES
|
||||
* private key algorithm, or else a subset of it-- fewer inner loops.
|
||||
* (AUTH_DES_ITER defaults to 16, may be less.)
|
||||
*
|
||||
* Under U.S. law, this software may not be exported outside the US
|
||||
* without license from the U.S. Commerce department.
|
||||
*
|
||||
* These routines form the library interface to the DES facilities.
|
||||
*
|
||||
* spm 8/85 MIT project athena
|
||||
*/
|
||||
|
||||
#include <afsconfig.h>
|
||||
#include <afs/param.h>
|
||||
|
||||
|
||||
#include "mit-cpyright.h"
|
||||
#ifndef KERNEL
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#else
|
||||
#ifdef HAVE_STRINGS_H
|
||||
#include <strings.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "des.h"
|
||||
#include "des_internal.h"
|
||||
#include "des_prototypes.h"
|
||||
|
||||
#define XPRT_CKSUM
|
||||
|
||||
/*
|
||||
* This routine performs DES cipher-block-chaining checksum operation,
|
||||
* a.k.a. Message Authentication Code. It ALWAYS encrypts from input
|
||||
* to a single 64 bit output MAC checksum.
|
||||
*
|
||||
* The key schedule is passed as an arg, as well as the cleartext or
|
||||
* ciphertext. The cleartext and ciphertext should be in host order.
|
||||
*
|
||||
* NOTE-- the output is ALWAYS 8 bytes long. If not enough space was
|
||||
* provided, your program will get trashed.
|
||||
*
|
||||
* The input is null padded, at the end (highest addr), to an integral
|
||||
* multiple of eight bytes.
|
||||
*/
|
||||
/*
|
||||
des_cblock *in; * >= length bytes of inputtext *
|
||||
des_cblock *out; * >= length bytes of outputtext *
|
||||
afs_int32 length; * in bytes *
|
||||
des_key_schedule key; * precomputed key schedule *
|
||||
des_cblock *iv; * 8 bytes of ivec *
|
||||
*/
|
||||
|
||||
afs_uint32
|
||||
des_cbc_cksum(des_cblock * in, des_cblock * out, afs_int32 length,
|
||||
des_key_schedule key, des_cblock * iv)
|
||||
{
|
||||
afs_uint32 *input = (afs_uint32 *) in;
|
||||
afs_uint32 *output = (afs_uint32 *) out;
|
||||
afs_uint32 *ivec = (afs_uint32 *) iv;
|
||||
|
||||
afs_uint32 i, j;
|
||||
afs_uint32 t_input[2];
|
||||
afs_uint32 t_output[8];
|
||||
unsigned char *t_in_p = (unsigned char *)t_input;
|
||||
|
||||
#ifdef MUSTALIGN
|
||||
if (afs_pointer_to_int(ivec) & 3) {
|
||||
memcpy((char *)&t_output[0], (char *)ivec++, sizeof(t_output[0]));
|
||||
memcpy((char *)&t_output[1], (char *)ivec, sizeof(t_output[1]));
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
t_output[0] = *ivec++;
|
||||
t_output[1] = *ivec;
|
||||
}
|
||||
|
||||
for (i = 0; length > 0; i++, length -= 8) {
|
||||
/* get input */
|
||||
#ifdef MUSTALIGN
|
||||
if (afs_pointer_to_int(input) & 3) {
|
||||
memcpy((char *)&t_input[0], (char *)input++, sizeof(t_input[0]));
|
||||
memcpy((char *)&t_input[1], (char *)input++, sizeof(t_input[1]));
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
t_input[0] = *input++;
|
||||
t_input[1] = *input++;
|
||||
}
|
||||
|
||||
/* zero pad */
|
||||
if (length < 8)
|
||||
for (j = length; j <= 7; j++)
|
||||
*(t_in_p + j) = 0;
|
||||
|
||||
#ifdef DEBUG
|
||||
if (des_debug)
|
||||
des_debug_print("clear", length, t_input[0], t_input[1]);
|
||||
#endif
|
||||
/* do the xor for cbc into the temp */
|
||||
t_input[0] ^= t_output[0];
|
||||
t_input[1] ^= t_output[1];
|
||||
/* encrypt */
|
||||
(void)des_ecb_encrypt(t_input, t_output, key, 1);
|
||||
#ifdef DEBUG
|
||||
if (des_debug) {
|
||||
des_debug_print("xor'ed", i, t_input[0], t_input[1]);
|
||||
des_debug_print("cipher", i, t_output[0], t_output[1]);
|
||||
}
|
||||
#else
|
||||
#ifdef lint
|
||||
i = i;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
/* copy temp output and save it for checksum */
|
||||
#ifdef MUSTALIGN
|
||||
if (afs_pointer_to_int(output) & 3) {
|
||||
memcpy((char *)output++, (char *)&t_output[0], sizeof(t_output[0]));
|
||||
memcpy((char *)output, (char *)&t_output[1], sizeof(t_output[1]));
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
*output++ = t_output[0];
|
||||
*output = t_output[1];
|
||||
}
|
||||
|
||||
return (afs_uint32) t_output[1];
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
/*
|
||||
* Copyright 1988 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <mit-copyright.h>.
|
||||
*
|
||||
* Machine-type definitions: IBM AIX 2.2.1 (RT/PC)
|
||||
*/
|
||||
|
||||
#include <mit-cpyright.h>
|
||||
|
||||
/* WARNING: This is currently identical to conf-bsd-ibm032.h and should probably change for AIX!! */
|
||||
#define BSDUNIX /* This screwes us up in read_pssword */
|
||||
#define IBMWS
|
||||
#define IBMWSASM
|
||||
#define BITS32
|
||||
#define BIG
|
||||
#define MSBFIRST
|
||||
#define MUSTALIGN
|
@ -1,20 +0,0 @@
|
||||
/*
|
||||
* Copyright 1988 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <mit-copyright.h>.
|
||||
*
|
||||
* Machine-type definitions: Alpha
|
||||
*/
|
||||
|
||||
#include <mit-cpyright.h>
|
||||
|
||||
#define ALPHA
|
||||
|
||||
/* 'course this is a joke, but I am not going to rewrite this mess */
|
||||
#define BITS32
|
||||
|
||||
#define BIG
|
||||
#define LSBFIRST
|
||||
#define BSDUNIX
|
||||
#define MUSTALIGN
|
@ -1,18 +0,0 @@
|
||||
/*
|
||||
* Copyright 1988 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <mit-copyright.h>.
|
||||
*
|
||||
* Machine-type definitions: Alpha
|
||||
*/
|
||||
|
||||
#include <mit-cpyright.h>
|
||||
|
||||
#define ALPHA
|
||||
|
||||
/* 'course this is a joke, but I am not going to rewrite this mess */
|
||||
#define BITS32
|
||||
|
||||
#define BIG
|
||||
#define LSBFIRST
|
@ -1,13 +0,0 @@
|
||||
/*
|
||||
* Copyright 1988 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <mit-copyright.h>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <mit-cpyright.h>
|
||||
|
||||
#define BITS32
|
||||
#define BIG
|
||||
#define LSBFIRST
|
@ -1,14 +0,0 @@
|
||||
/*
|
||||
* Copyright 1988 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <mit-copyright.h>.
|
||||
*
|
||||
* Machine-type definitions: Linux on Intel
|
||||
*/
|
||||
|
||||
#include <mit-cpyright.h>
|
||||
|
||||
#define BITS32
|
||||
#define BIG
|
||||
#define LSBFIRST
|
@ -1,19 +0,0 @@
|
||||
/*
|
||||
* Copyright 1988 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <mit-copyright.h>.
|
||||
*
|
||||
* Machine-type definitions: Alpha
|
||||
*/
|
||||
|
||||
#include <mit-cpyright.h>
|
||||
|
||||
#define ALPHA
|
||||
|
||||
/* 'course this is a joke, but I am not going to rewrite this mess */
|
||||
#define BITS32
|
||||
|
||||
#define BIG
|
||||
#define LSBFIRST
|
||||
#define BSDUNIX
|
@ -1,18 +0,0 @@
|
||||
/*
|
||||
* Copyright 1988 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <mit-copyright.h>.
|
||||
*
|
||||
* Machine-type definitions: IBM 032 (RT/PC)
|
||||
*/
|
||||
|
||||
#include <mit-cpyright.h>
|
||||
|
||||
#define BSDUNIX
|
||||
#define IBMWS
|
||||
#define IBMWSASM
|
||||
#define BITS32
|
||||
#define BIG
|
||||
#define MSBFIRST
|
||||
#define MUSTALIGN
|
@ -1,5 +0,0 @@
|
||||
#define BITS32
|
||||
#define BIG
|
||||
#define BSDUNIX
|
||||
#define LSBFIRST
|
||||
/*#define MUSTALIGN*/
|
@ -1,5 +0,0 @@
|
||||
#define BITS32
|
||||
#define BIG
|
||||
#define BSDUNIX
|
||||
#define MSBFIRST
|
||||
#define MUSTALIGN
|
@ -1,22 +0,0 @@
|
||||
/*
|
||||
* Copyright 1988 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <mit-copyright.h>.
|
||||
*
|
||||
* Machine-type definitions: VAX
|
||||
*/
|
||||
|
||||
#include <mit-cpyright.h>
|
||||
|
||||
#define VAX
|
||||
#define BITS32
|
||||
#define BIG
|
||||
#define LSBFIRST
|
||||
#define BSDUNIX
|
||||
|
||||
#ifndef __STDC__
|
||||
#ifndef NOASM
|
||||
#define VAXASM
|
||||
#endif /* no assembly */
|
||||
#endif /* standard C */
|
@ -1,16 +0,0 @@
|
||||
#define BITS32
|
||||
#define BIG
|
||||
#undef BSDUNIX
|
||||
#if defined(__ppc__) || defined(__ppc64__)
|
||||
#define MSBFIRST
|
||||
#elif defined(__i386__) || defined(__amd64__) || defined(__arm__)
|
||||
#define LSBFIRST
|
||||
#else
|
||||
#error "MSBFIRST or LSBFIRST undefined"
|
||||
#endif
|
||||
#define MUSTALIGN
|
||||
#if !defined(KERNEL) && defined(AFS_DARWIN80_ENV)
|
||||
extern int _darwin_swap_long_bytes_bit_number(afs_uint32 x);
|
||||
extern char *_darwin_whichstr[];
|
||||
extern int _darwin_which;
|
||||
#endif /* !KERNEL && AFS_DARWIN80_ENV */
|
@ -1,5 +0,0 @@
|
||||
#define BITS32
|
||||
#define BIG
|
||||
#define MSBFIRST
|
||||
#define BSDUNIX
|
||||
#define MUSTALIGN
|
@ -1,5 +0,0 @@
|
||||
#define BITS32
|
||||
#define BIG
|
||||
#define MSBFIRST
|
||||
#define BSDUNIX
|
||||
#define MUSTALIGN
|
@ -1,4 +0,0 @@
|
||||
#define BITS32
|
||||
#define BIG
|
||||
#define MSBFIRST
|
||||
#define BSDUNIX
|
@ -1,14 +0,0 @@
|
||||
/*
|
||||
* Copyright 1988 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <mit-copyright.h>.
|
||||
*
|
||||
* Machine-type definitions: Linux on Intel
|
||||
*/
|
||||
|
||||
#include <mit-cpyright.h>
|
||||
|
||||
#define BITS32
|
||||
#define BIG
|
||||
#define LSBFIRST
|
@ -1,5 +0,0 @@
|
||||
#define NOASM
|
||||
#define BITS32
|
||||
#define BIG
|
||||
#define BSDUNIX
|
||||
#define LSBFIRST
|
@ -1,13 +0,0 @@
|
||||
/*
|
||||
* Copyright 1988 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <mit-copyright.h>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <mit-cpyright.h>
|
||||
|
||||
#define BITS32
|
||||
#define BIG
|
||||
#define LSBFIRST
|
@ -1,15 +0,0 @@
|
||||
/*
|
||||
* Copyright 1988 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <mit-copyright.h>.
|
||||
*
|
||||
* Machine-type definitions: IBM 370
|
||||
*/
|
||||
|
||||
#include <mit-cpyright.h>
|
||||
|
||||
/* What else? */
|
||||
#define BIG
|
||||
#define NONASCII
|
||||
#define SHORTNAMES
|
@ -1,17 +0,0 @@
|
||||
/*
|
||||
* Copyright 1988 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <mit-copyright.h>.
|
||||
*
|
||||
* Machine-type definitions: MIPS
|
||||
*/
|
||||
|
||||
#include <mit-cpyright.h>
|
||||
|
||||
#define MIPS
|
||||
#define BITS32
|
||||
#define BIG
|
||||
#define LSBFIRST
|
||||
#define BSDUNIX
|
||||
#define MUSTALIGN
|
@ -1,10 +0,0 @@
|
||||
/*
|
||||
** Institutional File System Project
|
||||
** University of Michigan
|
||||
**
|
||||
*/
|
||||
#define BITS32
|
||||
#define BIG
|
||||
#define BSDUNIX
|
||||
#define MSBFIRST
|
||||
#define MUSTALIGN
|
@ -1,4 +0,0 @@
|
||||
#define BITS32
|
||||
#define BIG
|
||||
#define MSBFIRST
|
||||
#define MUSTALIGN
|
@ -1,15 +0,0 @@
|
||||
/*
|
||||
* Copyright 1988 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <mit-copyright.h>.
|
||||
*
|
||||
* Machine-type definitions: IBM PC 8086
|
||||
*/
|
||||
|
||||
#include <mit-cpyright.h>
|
||||
|
||||
#define IBMPC
|
||||
#define BITS16
|
||||
#define CROSSMSDOS
|
||||
#define LSBFIRST
|
@ -1,5 +0,0 @@
|
||||
#define BITS32
|
||||
#define BIG
|
||||
#undef BSDUNIX
|
||||
#define MSBFIRST
|
||||
#define MUSTALIGN
|
@ -1,4 +0,0 @@
|
||||
#define BITS32
|
||||
#define BIG
|
||||
#define MSBFIRST
|
||||
#define MUSTALIGN
|
@ -1,4 +0,0 @@
|
||||
#define BITS32
|
||||
#define BIG
|
||||
#define MSBFIRST
|
||||
#define MUSTALIGN
|
@ -1,15 +0,0 @@
|
||||
/*
|
||||
* Copyright 1988 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <mit-copyright.h>.
|
||||
*
|
||||
* Machine-type definitions: Linux on Intel
|
||||
*/
|
||||
|
||||
#include <mit-cpyright.h>
|
||||
|
||||
#define BITS32
|
||||
#define BIG
|
||||
#define MSBFIRST
|
||||
#define MUSTALIGN
|
@ -1,15 +0,0 @@
|
||||
/*
|
||||
* Copyright 1988 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <mit-copyright.h>.
|
||||
*
|
||||
* Machine-type definitions: SGI
|
||||
*/
|
||||
|
||||
#include <mit-cpyright.h>
|
||||
|
||||
#define BITS32
|
||||
#define BIG
|
||||
#define MSBFIRST
|
||||
#define MUSTALIGN
|
@ -1,15 +0,0 @@
|
||||
/*
|
||||
* Copyright 1988 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <mit-copyright.h>.
|
||||
*
|
||||
* Machine-type definitions: Linux on Intel
|
||||
*/
|
||||
|
||||
#include <mit-cpyright.h>
|
||||
|
||||
#define BITS32
|
||||
#define BIG
|
||||
#define MSBFIRST
|
||||
#define MUSTALIGN
|
@ -1,15 +0,0 @@
|
||||
/*
|
||||
* Copyright 1988 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <mit-copyright.h>.
|
||||
*
|
||||
* Machine-type definitions: Linux on Intel
|
||||
*/
|
||||
|
||||
#include <mit-cpyright.h>
|
||||
|
||||
#define BITS32
|
||||
#define BIG
|
||||
#define MSBFIRST
|
||||
#define MUSTALIGN
|
@ -1,24 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000, International Business Machines Corporation and others.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* This software has been released under the terms of the IBM Public
|
||||
* License. For details, see the LICENSE file in the top-level source
|
||||
* directory or online at http://www.openafs.org/dl/license10.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright 1988 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <mit-copyright.h>.
|
||||
*
|
||||
* Machine-type definitions: IBM PC windows NT
|
||||
*/
|
||||
|
||||
#include <mit-cpyright.h>
|
||||
|
||||
#define LSBFIRST 1
|
||||
#define BITS32 1
|
||||
#define MOASM 1
|
||||
#define BIG 1
|
@ -1,71 +0,0 @@
|
||||
/*
|
||||
* Copyright 1988 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <mit-copyright.h>.
|
||||
*
|
||||
* Configuration info for operating system, hardware description,
|
||||
* language implementation, C library, etc.
|
||||
*
|
||||
* This file should be included in (almost) every file in the Kerberos
|
||||
* sources, and probably should *not* be needed outside of those
|
||||
* sources. (How do we deal with /usr/include/des.h and
|
||||
* /usr/include/krb.h?)
|
||||
*/
|
||||
|
||||
#ifndef _CONF_H_
|
||||
|
||||
#include "mit-cpyright.h"
|
||||
|
||||
#include "andrew-conf.h"
|
||||
|
||||
#ifdef SHORTNAMES
|
||||
#include "names.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Language implementation-specific definitions
|
||||
*/
|
||||
|
||||
/* special cases */
|
||||
#ifdef __HIGHC__
|
||||
/* broken implementation of ANSI C */
|
||||
#undef __STDC__
|
||||
#endif
|
||||
|
||||
#ifndef __STDC__
|
||||
#define const
|
||||
#define volatile
|
||||
#define signed
|
||||
typedef char *pointer; /* pointer to generic data */
|
||||
#define PROTOTYPE(p) ()
|
||||
#else
|
||||
typedef void *pointer;
|
||||
#define PROTOTYPE(p) p
|
||||
#endif
|
||||
|
||||
/* Does your compiler understand "void"? */
|
||||
#ifdef notdef
|
||||
#define void int
|
||||
#endif
|
||||
|
||||
/*
|
||||
* A few checks to see that necessary definitions are included.
|
||||
*/
|
||||
|
||||
/* byte order */
|
||||
|
||||
#ifndef MSBFIRST
|
||||
#ifndef LSBFIRST
|
||||
/* #error byte order not defined */
|
||||
Error:byte order not defined.
|
||||
#endif
|
||||
#endif
|
||||
/* machine size */
|
||||
#ifndef BITS16
|
||||
#ifndef BITS32
|
||||
Error:how big is this machine anyways ?
|
||||
#endif
|
||||
#endif
|
||||
/* end of checks */
|
||||
#endif /* _CONF_H_ */
|
@ -1,4 +0,0 @@
|
||||
#define BITS32
|
||||
#define BIG
|
||||
#define BSDUNIX
|
||||
#define MSBFIRST
|
@ -1,15 +0,0 @@
|
||||
/*
|
||||
* Copyright 1988 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <mit-cpyright.h>.
|
||||
*
|
||||
* Declaration of debugging flag.
|
||||
*/
|
||||
|
||||
#include <afsconfig.h>
|
||||
#include <afs/param.h>
|
||||
|
||||
|
||||
#include "mit-cpyright.h"
|
||||
int des_debug = 0;
|
460
src/des/des.c
460
src/des/des.c
@ -1,460 +0,0 @@
|
||||
/*
|
||||
* Copyright 1985, 1986, 1987, 1988 by the Massachusetts Institute
|
||||
* of Technology.
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <mit-cpyright.h>.
|
||||
*
|
||||
* These routines perform encryption and decryption using the DES
|
||||
* private key algorithm, or else a subset of it-- fewer inner loops.
|
||||
* (AUTH_DES_ITER defaults to 16, may be less.)
|
||||
*
|
||||
* Under U.S. law, this software may not be exported outside the US
|
||||
* without license from the U.S. Commerce department.
|
||||
*
|
||||
* The key schedule is passed as an arg, as well as the cleartext or
|
||||
* ciphertext.
|
||||
*
|
||||
* All registers labeled imply Vax using the Ultrix or 4.2bsd
|
||||
* compiler.
|
||||
*
|
||||
*
|
||||
* NOTE: bit and byte numbering:
|
||||
* DES algorithm is defined in terms of bits of L
|
||||
* followed by bits of R.
|
||||
|
||||
* bit 0 ==> lsb of L
|
||||
* bit 63 ==> msb of R
|
||||
*
|
||||
* Always work in register pairs, FROM L1,R1 TO L2,R2 to make
|
||||
* bookkeeping easier.
|
||||
*
|
||||
* originally written by Steve Miller, MIT Project Athena
|
||||
*/
|
||||
#include "mit-cpyright.h"
|
||||
|
||||
#include <afsconfig.h>
|
||||
#include <afs/param.h>
|
||||
|
||||
|
||||
#ifndef KERNEL
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#endif
|
||||
#ifdef AFS_PTHREAD_ENV
|
||||
#include <pthread.h>
|
||||
#endif /* AFS_PTHREAD_ENV */
|
||||
#include "des.h"
|
||||
#include "des_internal.h"
|
||||
#include "s_table.h"
|
||||
#ifdef BIG
|
||||
#include "p_table.h"
|
||||
#endif
|
||||
|
||||
#include "des_prototypes.h"
|
||||
|
||||
#define XPRT_DES
|
||||
|
||||
#ifdef DEBUG
|
||||
#define DBG_PRINT(s) if (des_debug & 2) \
|
||||
des_debug_print(s,i,L1&0xffff,(L1>>16)&0xffff, \
|
||||
R1&0xffff,(R1>>16)&0xffff)
|
||||
#else
|
||||
#define DBG_PRINT(s)
|
||||
#endif
|
||||
|
||||
/* encrypt == 0 ==> decrypt, else encrypt */
|
||||
|
||||
afs_int32
|
||||
des_ecb_encrypt(void * clear, void * cipher,
|
||||
des_key_schedule schedule, int encrypt)
|
||||
{
|
||||
/* better pass 8 bytes, length not checked here */
|
||||
|
||||
afs_uint32 R1 = 0;
|
||||
afs_uint32 L1 = 0; /* R1 = r10, L1 = r9 */
|
||||
afs_uint32 R2 = 0, L2 = 0; /* R2 = r8, L2 = r7 */
|
||||
afs_int32 i;
|
||||
/* one more registers left on VAX, see below P_temp_p */
|
||||
#ifdef BITS16
|
||||
sbox_in_16_a S_in_16_a;
|
||||
sbox_in_16_b S_in_16_b;
|
||||
sbox_in_16_c S_in_16_c;
|
||||
unsigned int *S_in_a_16_p = (unsigned int *)&S_in_16_a;
|
||||
unsigned int *S_in_b_16_p = (unsigned int *)&S_in_16_b;
|
||||
unsigned int *S_in_c_16_p = (unsigned int *)&S_in_16_c;
|
||||
#endif
|
||||
#ifndef BITS32
|
||||
#ifndef BITS16
|
||||
#error dunno how to do this machine type, you lose;
|
||||
#endif
|
||||
#endif
|
||||
volatile afs_uint32 P_temp;
|
||||
volatile unsigned char *P_temp_p = (unsigned char *)&P_temp;
|
||||
#ifdef BITS16
|
||||
sbox_out S_out;
|
||||
afs_uint32 *S_out_p = (afs_uint32 *) & S_out;
|
||||
#endif
|
||||
afs_uint32 R_save, L_save;
|
||||
#ifdef DEBUG
|
||||
afs_uint32 dbg_tmp[2];
|
||||
#endif
|
||||
/*
|
||||
* Use L1,R1 and L2,R2 as two sets of "64-bit" registers always
|
||||
* work from L1,R1 input to L2,R2 output; initialize the cleartext
|
||||
* into registers.
|
||||
*/
|
||||
#ifdef MUSTALIGN
|
||||
#ifdef DEBUG
|
||||
/*
|
||||
* If the alignment is wrong, the programmer really screwed up --
|
||||
* we aren't even getting the right data type. His problem. Keep
|
||||
* this code for debugging.
|
||||
*/
|
||||
/* Make sure schedule is ok */
|
||||
if ((afs_int32) schedule & 3) {
|
||||
fprintf(stderr, "des.c schedule arg pointer not aligned\n");
|
||||
abort();
|
||||
}
|
||||
#endif
|
||||
if (afs_pointer_to_int(clear) & 3) {
|
||||
memcpy((char *)(&L_save), (char *)clear, sizeof(L_save));
|
||||
clear=((afs_uint32*)clear)+1;
|
||||
memcpy((char *)(&R_save), (char *)clear, sizeof(R_save));
|
||||
L1 = L_save;
|
||||
R1 = R_save;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
if (clear) {
|
||||
L1 = *((afs_uint32 *)clear);
|
||||
clear=((afs_uint32*)clear)+1;
|
||||
} else
|
||||
L1 = 0;
|
||||
if (clear)
|
||||
R1 = *((afs_uint32 *)clear);
|
||||
else
|
||||
R1 = 0;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
if (des_debug & 2) {
|
||||
printf("All values printed from low byte (bit 0)");
|
||||
printf(" --> high byte (bit 63)\n");
|
||||
i = 0;
|
||||
dbg_tmp[0] = L1;
|
||||
dbg_tmp[1] = R1;
|
||||
printf("iter = %2d before IP\n\t\tL1 R1 = ", i);
|
||||
des_cblock_print_file(dbg_tmp, stdout);
|
||||
}
|
||||
|
||||
DBG_PRINT("before IP");
|
||||
#endif
|
||||
|
||||
/* IP_start:*/
|
||||
|
||||
/* all the Initial Permutation code is in the include file */
|
||||
#include "ip.c"
|
||||
/* reset input to L1,R1 */
|
||||
L1 = L2;
|
||||
R1 = R2;
|
||||
|
||||
/* iterate through the inner loop */
|
||||
for (i = 0; i <= (AUTH_DES_ITER - 1); i++) {
|
||||
|
||||
#ifdef DEBUG
|
||||
if (des_debug & 2) {
|
||||
dbg_tmp[0] = L1;
|
||||
dbg_tmp[1] = R1;
|
||||
printf("iter = %2d start loop\n\t\tL1 R1 = ", i);
|
||||
des_cblock_print_file(dbg_tmp, stdout);
|
||||
DBG_PRINT("start loop");
|
||||
}
|
||||
#endif
|
||||
|
||||
R_save = R1;
|
||||
L_save = L1;
|
||||
|
||||
/* E_start:*/
|
||||
/* apply the E permutation from R1 to L2, R2 */
|
||||
#ifndef VAXASM
|
||||
#ifdef SLOW_E
|
||||
#include "e.c"
|
||||
#else /* Bill's fast E */
|
||||
L2 = (R1 << 1);
|
||||
if (R1 & (1 << 31))
|
||||
L2 |= 1 << 0;
|
||||
L2 &= 077;
|
||||
L2 |= (R1 << 3) & 07700;
|
||||
L2 |= (R1 << 5) & 0770000;
|
||||
L2 |= (R1 << 7) & 077000000;
|
||||
L2 |= (R1 << 9) & 07700000000;
|
||||
L2 |= (R1 << 11) & 030000000000;
|
||||
|
||||
/* now from right to right */
|
||||
|
||||
R2 = ((R1 >> 17) & 0176000);
|
||||
if (R1 & (1 << 0))
|
||||
R2 |= 1 << 15;
|
||||
|
||||
R2 |= ((R1 >> 21) & 017);
|
||||
R2 |= ((R1 >> 19) & 01760);
|
||||
#endif /* SLOW_E */
|
||||
#else /* VAXASM */
|
||||
/* E operations */
|
||||
/* right to left */
|
||||
asm(" rotl $1,r10,r7");
|
||||
L2 &= 077;
|
||||
L2 |= (R1 << 3) & 07700;
|
||||
L2 |= (R1 << 5) & 0770000;
|
||||
L2 |= (R1 << 7) & 077000000;
|
||||
L2 |= (R1 << 9) & 07700000000;
|
||||
L2 |= (R1 << 11) & 030000000000;
|
||||
|
||||
asm(" rotl $-17,r10,r8");
|
||||
R2 &= 0176000;
|
||||
asm(" rotl $-21,r10,r0");
|
||||
asm(" bicl2 $-16,r0");
|
||||
asm(" bisl2 r0,r8");
|
||||
asm(" rotl $-19,r10,r0");
|
||||
asm(" bicl2 $-1009,r0");
|
||||
asm(" bisl2 r0,r8");
|
||||
|
||||
#endif
|
||||
|
||||
/* reset input to L1,R1 */
|
||||
L1 = L2;
|
||||
R1 = R2;
|
||||
|
||||
#ifdef DEBUG
|
||||
if (des_debug & 2) {
|
||||
dbg_tmp[0] = L1;
|
||||
dbg_tmp[1] = R1;
|
||||
DBG_PRINT("after e");
|
||||
printf("iter = %2d after e\n\t\tL1 R1 = ", i);
|
||||
des_cblock_print_file(dbg_tmp, stdout);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* XOR_start:*/
|
||||
/*
|
||||
* XOR with the key schedule, "schedule"
|
||||
*
|
||||
* If this is an encryption operation, use schedule[i],
|
||||
* otherwise use schedule [AUTH_DES_ITER-i-1]
|
||||
*
|
||||
* First XOR left half.
|
||||
*/
|
||||
if (encrypt) {
|
||||
L1 ^= *(((afs_uint32 *) & schedule[i]) + 0);
|
||||
/* now right half */
|
||||
R1 ^= *(((afs_uint32 *) & schedule[i]) + 1);
|
||||
} else {
|
||||
L1 ^= *(((afs_uint32 *) & schedule[AUTH_DES_ITER - i - 1]) + 0);
|
||||
/* now right half */
|
||||
R1 ^= *(((afs_uint32 *) & schedule[AUTH_DES_ITER - i - 1]) + 1);
|
||||
}
|
||||
|
||||
/* dont have to reset input to L1, R1 */
|
||||
|
||||
#ifdef DEBUG
|
||||
if (des_debug & 2) {
|
||||
dbg_tmp[0] = L1;
|
||||
dbg_tmp[1] = R1;
|
||||
DBG_PRINT("after xor");
|
||||
printf("iter = %2d after xor\n\t\tL1 R1 =", i);
|
||||
des_cblock_print_file(dbg_tmp, stdout);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* S_start:*/
|
||||
/* apply the S selection from L1, R1 to R2 */
|
||||
|
||||
#ifdef notdef
|
||||
#include "s.c"
|
||||
#endif
|
||||
|
||||
/* S operations , cant use registers for bit field stuff */
|
||||
/* from S_in to S_out */
|
||||
|
||||
#ifdef BITS16
|
||||
*S_in_a_16_p = L1 & 0xffff;
|
||||
*S_in_b_16_p = (L1 >> 16) & 0xffff;
|
||||
*S_in_c_16_p = R1 & 0xffff;
|
||||
(*(afs_uint32 *) & S_out) = (unsigned)S_adj[0][S_in_16_a.b0];
|
||||
S_out.b1 = (unsigned)S_adj[1][S_in_16_a.b1];
|
||||
/* b2 spans two words */
|
||||
S_out.b2 = (unsigned)
|
||||
S_adj[2][(unsigned)S_in_16_a.b2 +
|
||||
(((unsigned)S_in_16_b.b2) << 4)];
|
||||
S_out.b3 = (unsigned)S_adj[3][S_in_16_b.b3];
|
||||
S_out.b4 = (unsigned)S_adj[4][S_in_16_b.b4];
|
||||
/* b5 spans both parts */
|
||||
S_out.b5 = (unsigned)
|
||||
S_adj[5][(unsigned)S_in_16_b.b5 +
|
||||
(((unsigned)S_in_16_c.b5) << 2)];
|
||||
S_out.b6 = (unsigned)S_adj[6][S_in_16_c.b6];
|
||||
S_out.b7 = (unsigned)S_adj[7][S_in_16_c.b7];
|
||||
R1 = *S_out_p;
|
||||
#else
|
||||
/* is a 32 bit sys */
|
||||
#ifndef VAXASM
|
||||
R2 = (unsigned)S_adj[0][L1 & 077];
|
||||
L2 = (unsigned)S_adj[1][(L1 >> 6) & 077];
|
||||
R2 |= (L2 << 4);
|
||||
L2 = (unsigned)S_adj[2][(L1 >> 12) & 077];
|
||||
R2 |= (L2 << 8);
|
||||
L2 = (unsigned)S_adj[3][(L1 >> 18) & 077];
|
||||
R2 |= (L2 << 12);
|
||||
L2 = (unsigned)S_adj[4][(L1 >> 24) & 077];
|
||||
R2 |= (L2 << 16);
|
||||
/* b5 spans both parts */
|
||||
L2 = (unsigned)
|
||||
S_adj[5][(unsigned)((L1 >> 30) & 03) + ((R1 & 017) << 2)];
|
||||
R2 |= (L2 << 20);
|
||||
L2 = (unsigned)S_adj[6][(R1 >> 4) & 077];
|
||||
R2 |= (L2 << 24);
|
||||
L2 = (unsigned)S_adj[7][(R1 >> 10) & 077];
|
||||
R1 = R2 | (L2 << 28);
|
||||
/* reset input to L1, R1 */
|
||||
#else /* vaxasm */
|
||||
/*
|
||||
* this is the c code produced above, with
|
||||
* extzv replaced by rotl
|
||||
*/
|
||||
asm("bicl3 $-64,r9,r0");
|
||||
asm("movzbl _S_adj[r0],r8");
|
||||
asm("rotl $-6,r9,r0");
|
||||
asm("bicl2 $-64,r0");
|
||||
asm("movzbl _S_adj+64[r0],r7");
|
||||
asm("ashl $4,r7,r0");
|
||||
asm("bisl2 r0,r8");
|
||||
asm("rotl $-12,r9,r0");
|
||||
asm("bicl2 $-64,r0");
|
||||
asm("movzbl _S_adj+128[r0],r7");
|
||||
asm("ashl $8,r7,r0");
|
||||
asm("bisl2 r0,r8");
|
||||
asm("rotl $-18,r9,r0");
|
||||
asm("bicl2 $-64,r0");
|
||||
asm("movzbl _S_adj+192[r0],r7");
|
||||
asm("ashl $12,r7,r0");
|
||||
asm("bisl2 r0,r8");
|
||||
asm("rotl $-24,r9,r0");
|
||||
asm("bicl2 $-64,r0");
|
||||
asm("movzbl _S_adj+256[r0],r7");
|
||||
asm("ashl $16,r7,r0");
|
||||
asm("bisl2 r0,r8");
|
||||
asm("rotl $-30,r9,r0");
|
||||
asm("bicl2 $-4,r0");
|
||||
asm("bicl3 $-16,r10,r1");
|
||||
asm("ashl $2,r1,r1");
|
||||
asm("addl2 r1,r0");
|
||||
asm("movzbl _S_adj+320[r0],r7");
|
||||
asm("ashl $20,r7,r0");
|
||||
asm("bisl2 r0,r8");
|
||||
asm("rotl $-4,r10,r0");
|
||||
asm("bicl2 $-64,r0");
|
||||
asm("movzbl _S_adj+384[r0],r7");
|
||||
asm("ashl $24,r7,r0");
|
||||
asm("bisl2 r0,r8");
|
||||
asm("rotl $-10,r10,r0");
|
||||
asm("bicl2 $-64,r0");
|
||||
asm("movzbl _S_adj+448[r0],r7");
|
||||
asm("ashl $28,r7,r0");
|
||||
asm("bisl2 r8,r0");
|
||||
asm("movl r0,r10");
|
||||
|
||||
#endif /* vaxasm */
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
if (des_debug & 2) {
|
||||
dbg_tmp[0] = L1;
|
||||
dbg_tmp[1] = R1;
|
||||
DBG_PRINT("after s");
|
||||
printf("iter = %2d after s\n\t\tL1 R1 = ", i);
|
||||
des_cblock_print_file(dbg_tmp, stdout);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* P_start:*/
|
||||
/* and then the p permutation from R1 into R2 */
|
||||
#include "p.c"
|
||||
/* reset the input to L1, R1 */
|
||||
R1 = R2;
|
||||
|
||||
#ifdef DEBUG
|
||||
if (des_debug & 2) {
|
||||
dbg_tmp[0] = L1;
|
||||
dbg_tmp[1] = R1;
|
||||
DBG_PRINT("after p");
|
||||
printf("iter = %2d after p\n\t\tL1 R1 = ", i);
|
||||
des_cblock_print_file(dbg_tmp, stdout);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* R1 is the output value from the f() */
|
||||
/* move R[iter] to L[iter+1] */
|
||||
/* XOR_2_start:*/
|
||||
L1 = R_save;
|
||||
/* xor with left */
|
||||
R1 = L_save ^ R1;
|
||||
/* reset the input */
|
||||
}
|
||||
|
||||
/* flip left and right before final permutation */
|
||||
L2 = R1; /* flip */
|
||||
R2 = L1;
|
||||
/* reset the input */
|
||||
L1 = L2;
|
||||
R1 = R2;
|
||||
|
||||
#ifdef DEBUG
|
||||
if (des_debug & 2) {
|
||||
dbg_tmp[0] = L1;
|
||||
dbg_tmp[1] = R1;
|
||||
DBG_PRINT("before FP");
|
||||
printf("iter = %2d before FP\n\t\tL1 R1 = ", i);
|
||||
des_cblock_print_file(dbg_tmp, stdout);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*FP_start:*/
|
||||
/* do the final permutation from L1R1 to L2R2 */
|
||||
/* all the fp code is in the include file */
|
||||
#include "fp.c"
|
||||
|
||||
/* copy the output to the ciphertext string;
|
||||
* can be same as cleartext
|
||||
*/
|
||||
|
||||
#ifdef MUSTALIGN
|
||||
if (afs_pointer_to_int(cipher) & 3) {
|
||||
L_save = L2; /* cant bcopy a reg */
|
||||
R_save = R2;
|
||||
memcpy((char *)cipher, (char *)&L_save, sizeof(L_save));
|
||||
cipher=((afs_uint32*)cipher)+1;
|
||||
memcpy((char *)cipher, (char *)&R_save, sizeof(R_save));
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
*((afs_uint32*)cipher)= L2;
|
||||
cipher = ((afs_int32 *)cipher)+1;
|
||||
*((afs_uint32 *)cipher) = R2;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
if (des_debug & 2) {
|
||||
L1 = L2;
|
||||
R1 = R2;
|
||||
dbg_tmp[0] = L1;
|
||||
dbg_tmp[1] = R1;
|
||||
DBG_PRINT("done");
|
||||
printf("iter = %2d done\n\t\tL1 R1 = ", i);
|
||||
des_cblock_print_file(dbg_tmp, stdout);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* that's it, no errors can be returned */
|
||||
return 0;
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright 1987, 1988 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <mit-cpyright.h>.
|
||||
*
|
||||
* Include file for the Data Encryption Standard library.
|
||||
*/
|
||||
|
||||
/* only do the whole thing once */
|
||||
#ifndef DES_DEFS
|
||||
#define DES_DEFS
|
||||
|
||||
#include "mit-cpyright.h"
|
||||
|
||||
typedef unsigned char des_cblock[8]; /* crypto-block size */
|
||||
/* Key schedule */
|
||||
typedef struct des_ks_struct {
|
||||
union {
|
||||
afs_uint32 i[2];
|
||||
des_cblock _;
|
||||
} _;
|
||||
} des_key_schedule[16];
|
||||
|
||||
#define DES_KEY_SZ (sizeof(des_cblock))
|
||||
#define DES_ENCRYPT 1
|
||||
#define DES_DECRYPT 0
|
||||
|
||||
#ifndef NCOMPAT
|
||||
#define C_Block des_cblock
|
||||
#define Key_schedule des_key_schedule
|
||||
#ifndef ENCRYPT
|
||||
#define ENCRYPT DES_ENCRYPT
|
||||
#define DECRYPT DES_DECRYPT
|
||||
#endif
|
||||
#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
|
||||
#ifdef AFS_DUX40_ENV
|
||||
/* This is done to avoid name space collision with dtlogin and SIA. */
|
||||
#define des_key_sched afs_des_key_sched
|
||||
#endif
|
||||
#define key_sched des_key_sched
|
||||
#define cbc_encrypt des_cbc_encrypt
|
||||
#define ecb_encrypt des_ecb_encrypt
|
||||
#define cbc_cksum des_cbc_cksum
|
||||
#define C_Block_print des_cblock_print
|
||||
#define quad_cksum des_quad_cksum
|
||||
typedef struct des_ks_struct bit_64;
|
||||
#endif
|
||||
|
||||
#define des_cblock_print(x) des_cblock_print_file(x, stdout)
|
||||
|
||||
#endif /* DES_DEFS */
|
@ -1,83 +0,0 @@
|
||||
/*
|
||||
* Copyright 1988 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <mit-copyright.h>.
|
||||
*
|
||||
* This file contains configuration information for the DES library
|
||||
* which is machine specific; currently, this file contains
|
||||
* configuration information for the vax, the "ibm032" (RT), and
|
||||
* the "PC8086" (IBM PC).
|
||||
*
|
||||
* Note: cross-compiled targets must appear BEFORE their corresponding
|
||||
* cross-compiler host. Otherwise, both will be defined when running
|
||||
* the native compiler on the programs that construct cross-compiled
|
||||
* sources.
|
||||
*/
|
||||
|
||||
#include <afs/param.h>
|
||||
#include <mit-cpyright.h>
|
||||
|
||||
/* Machine-type and OS-type based configuration */
|
||||
|
||||
#ifdef PC8086
|
||||
#define IBMPC
|
||||
#define BITS16
|
||||
/* #define BIG */
|
||||
#define CROSSMSDOS
|
||||
#define LSBFIRST
|
||||
|
||||
#else
|
||||
|
||||
#ifdef vax
|
||||
#define VAX
|
||||
#ifndef __STDC__ /* not Berkeley PCC */
|
||||
#ifndef __GNU__ /* ditto */
|
||||
#ifndef NOASM /* are we doing C-only? */
|
||||
#define VAXASM
|
||||
#endif /* NOASM */
|
||||
#endif /* __GNU__ */
|
||||
#endif /* __STDC__ */
|
||||
#define BITS32
|
||||
#define BIG
|
||||
#define BSDUNIX
|
||||
#define LSBFIRST
|
||||
|
||||
#else
|
||||
|
||||
#ifdef sun
|
||||
#define BITS32
|
||||
#define BIG
|
||||
#define BSDUNIX
|
||||
#define MSBFIRST
|
||||
|
||||
#else
|
||||
|
||||
#ifdef AFS_AIX_ENV
|
||||
#define IBMWS
|
||||
#define IBMWSASM
|
||||
#define BITS32
|
||||
#define BIG
|
||||
#define BSDUNIX /*Does it mean the default us S5? NO */
|
||||
#define MSBFIRST
|
||||
#define MUSTALIGN
|
||||
#else
|
||||
#ifdef multimax
|
||||
#define BITS32
|
||||
#define BIG
|
||||
#define BSDUNIX
|
||||
#define LSBFIRST
|
||||
#else
|
||||
|
||||
Sorry,
|
||||
you lose.
|
||||
Figure out what the machine looks like and fix this file to include it.
|
||||
#endif /* multimax */
|
||||
#endif /* AFS_AIX_ENV */
|
||||
#endif /* sun */
|
||||
#endif /* vax */
|
||||
#endif /* pc8086 */
|
||||
/* Language configuration -- are we ANSI or are we Berkeley? */
|
||||
#ifndef __STDC__
|
||||
#define const
|
||||
#endif
|
@ -1,90 +0,0 @@
|
||||
/*
|
||||
* Copyright 1987, 1988 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <mit-cpyright.h>.
|
||||
*
|
||||
* Private include file for the Data Encryption Standard library.
|
||||
*/
|
||||
|
||||
/* only do the whole thing once */
|
||||
#ifndef DES_INTERNAL_DEFS
|
||||
#define DES_INTERNAL_DEFS
|
||||
|
||||
#include "conf.h"
|
||||
|
||||
/*
|
||||
* number of iterations of the inner
|
||||
* loop of the DES algorithm. The
|
||||
* standard is 16, but in case that is
|
||||
* too slow, we might do less. Of
|
||||
* course, less also means less
|
||||
* security.
|
||||
*/
|
||||
#define AUTH_DES_ITER 16
|
||||
|
||||
#ifdef BITS32
|
||||
/* these are for 32 bit machines */
|
||||
|
||||
typedef struct {
|
||||
unsigned b0:6;
|
||||
unsigned b1:6;
|
||||
unsigned b2:6;
|
||||
unsigned b3:6;
|
||||
unsigned b4:6;
|
||||
unsigned b5:2;
|
||||
} sbox_in_a;
|
||||
|
||||
typedef struct {
|
||||
unsigned b5:4;
|
||||
unsigned b6:6;
|
||||
unsigned b7:6;
|
||||
} sbox_in_b;
|
||||
|
||||
typedef struct {
|
||||
unsigned b0:4;
|
||||
unsigned b1:4;
|
||||
unsigned b2:4;
|
||||
unsigned b3:4;
|
||||
unsigned b4:4;
|
||||
unsigned b5:4;
|
||||
unsigned b6:4;
|
||||
unsigned b7:4;
|
||||
} sbox_out;
|
||||
|
||||
#else /* BITS32 */
|
||||
/* for sixteen bit machines */
|
||||
|
||||
typedef struct {
|
||||
unsigned b0:6;
|
||||
unsigned b1:6;
|
||||
unsigned b2:4;
|
||||
} sbox_in_16_a;
|
||||
|
||||
typedef struct {
|
||||
unsigned b2:2;
|
||||
unsigned b3:6;
|
||||
unsigned b4:6;
|
||||
unsigned b5:2;
|
||||
} sbox_in_16_b;
|
||||
|
||||
typedef struct {
|
||||
unsigned b5:4;
|
||||
unsigned b6:6;
|
||||
unsigned b7:6;
|
||||
} sbox_in_16_c;
|
||||
|
||||
typedef struct {
|
||||
unsigned b0:4;
|
||||
unsigned b1:4;
|
||||
unsigned b2:4;
|
||||
unsigned b3:4;
|
||||
unsigned b4:4;
|
||||
unsigned b5:4;
|
||||
unsigned b6:4;
|
||||
unsigned b7:4;
|
||||
} sbox_out;
|
||||
#endif /* BITS32 */
|
||||
|
||||
|
||||
#endif /* DES_INTERNAL_DEFS */
|
@ -1,97 +0,0 @@
|
||||
#ifndef DES_PROTOTYPES_H
|
||||
#define DES_PROTOTYPES_H
|
||||
|
||||
/* misc.c */
|
||||
extern afs_uint32 long_swap_bits(afs_uint32 x);
|
||||
extern afs_uint32 swap_six_bits_to_ansi(afs_uint32 old);
|
||||
extern afs_uint32 swap_four_bits_to_ansi(afs_uint32 old);
|
||||
extern afs_uint32 swap_bit_pos_1(afs_uint32 x);
|
||||
extern afs_uint32 swap_bit_pos_0(afs_uint32 x);
|
||||
extern afs_uint32 swap_bit_pos_0_to_ansi(afs_uint32 x);
|
||||
extern afs_uint32 rev_swap_bit_pos_0(afs_uint32 x);
|
||||
extern afs_uint32 swap_byte_bits(afs_uint32 x);
|
||||
extern int swap_long_bytes_bit_number(afs_uint32 x);
|
||||
#if !defined(KERNEL)
|
||||
extern void test_set(FILE * stream, const char *src, int testbit,
|
||||
const char *dest, int setbit);
|
||||
#endif
|
||||
extern int des_debug;
|
||||
|
||||
static_inline unsigned char *
|
||||
cblockptr_to_cblock(des_cblock *key) {
|
||||
return (unsigned char *)key;
|
||||
}
|
||||
|
||||
static_inline unsigned char *
|
||||
charptr_to_cblock(char *key) {
|
||||
return (unsigned char *)key;
|
||||
}
|
||||
|
||||
static_inline des_cblock *
|
||||
charptr_to_cblockptr(char *key) {
|
||||
return (unsigned char (*)[])key;
|
||||
}
|
||||
|
||||
/* cbc_encrypt.c */
|
||||
extern afs_int32 des_cbc_encrypt(void * in, void * out,
|
||||
afs_int32 length,
|
||||
des_key_schedule key, des_cblock * iv,
|
||||
int encrypt);
|
||||
|
||||
/* pcbc_encrypt.c */
|
||||
extern afs_int32 des_pcbc_encrypt(void * in, void * out,
|
||||
afs_int32 length,
|
||||
des_key_schedule key, des_cblock * iv,
|
||||
int encrypt);
|
||||
|
||||
/* des.c */
|
||||
extern afs_int32 des_ecb_encrypt(void * clear, void * cipher,
|
||||
des_key_schedule schedule,
|
||||
int encrypt);
|
||||
|
||||
/* util.c */
|
||||
#if !defined(KERNEL)
|
||||
extern int des_cblock_print_file(des_cblock * x, FILE * fp);
|
||||
#endif
|
||||
|
||||
/* make_*.c */
|
||||
#if !defined(KERNEL)
|
||||
extern void gen(FILE * stream);
|
||||
#endif
|
||||
|
||||
/* weak_key.c */
|
||||
extern int des_is_weak_key(des_cblock key);
|
||||
|
||||
/* key_parity.c */
|
||||
extern void des_fixup_key_parity(des_cblock key);
|
||||
extern int des_check_key_parity(des_cblock key);
|
||||
|
||||
/* cksum.c */
|
||||
extern afs_uint32 des_cbc_cksum(des_cblock * in, des_cblock * out,
|
||||
afs_int32 length,
|
||||
des_key_schedule key, des_cblock * iv);
|
||||
|
||||
/* quad_cksum.c */
|
||||
extern afs_uint32 des_quad_cksum(unsigned char *in, afs_uint32 * out,
|
||||
afs_int32 length, int out_count,
|
||||
des_cblock * c_seed);
|
||||
|
||||
/* key_sched.c */
|
||||
extern int afs_des_key_sched(des_cblock k,
|
||||
des_key_schedule schedule);
|
||||
extern int des_key_sched(des_cblock k, des_key_schedule schedule);
|
||||
|
||||
|
||||
/* strng_to_key.c */
|
||||
extern void des_string_to_key(char *str, des_cblock * key);
|
||||
|
||||
/* new_rnd_key.c */
|
||||
extern int des_random_key(des_cblock key);
|
||||
extern void des_init_random_number_generator(des_cblock key);
|
||||
extern void des_set_random_generator_seed(des_cblock key);
|
||||
|
||||
/* read_pssword.c */
|
||||
extern int des_read_password(des_cblock * k, char *prompt, int verify);
|
||||
extern int des_read_pw_string(char *, int, char *, int);
|
||||
|
||||
#endif
|
118
src/des/enc.c
118
src/des/enc.c
@ -1,118 +0,0 @@
|
||||
/*
|
||||
* Copyright 1988 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <mit-copyright.h>.
|
||||
*/
|
||||
|
||||
#include <afsconfig.h>
|
||||
#include <afs/param.h>
|
||||
|
||||
|
||||
#include "mit-cpyright.h"
|
||||
#include "des.h"
|
||||
#ifdef BSDUNIX
|
||||
#include <sys/file.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
|
||||
Key_schedule KEYSCHED;
|
||||
C_Block key = { 0, 1, 2, 3, 4, 5, 6, 7 };
|
||||
C_Block sum;
|
||||
char inbuf[512 + 8]; /* leave room for cksum and len */
|
||||
char oubuf[512 + 8];
|
||||
int debug;
|
||||
int ind;
|
||||
int oud;
|
||||
afs_int32 orig_size;
|
||||
|
||||
#include "AFS_component_version_number.c"
|
||||
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
int encrypt;
|
||||
afs_int32 length;
|
||||
int *p;
|
||||
afs_int32 ivec[2];
|
||||
if (argc != 4) {
|
||||
fprintf(stderr, "%s: Usage: %s infile outfile mode.\n", argv[0],
|
||||
argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
if (!strcmp(argv[3], "e"))
|
||||
encrypt = 1;
|
||||
else if (!strcmp(argv[3], "d"))
|
||||
encrypt = 0;
|
||||
else {
|
||||
fprintf(stderr, "%s: Mode must be e (encrypt) or d (decrypt).\n",
|
||||
argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
if ((ind = open(argv[1], O_RDONLY, 0666)) < 0) {
|
||||
fprintf(stderr, "%s: Cannot open %s for input.\n", argv[0], argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
if (!strcmp(argv[2], "-"))
|
||||
oud = dup(1);
|
||||
else if ((oud = open(argv[2], O_CREAT | O_WRONLY, 0666)) < 0) {
|
||||
fprintf(stderr, "%s: Cannot open %s for output.\n", argv[0], argv[2]);
|
||||
exit(1);
|
||||
}
|
||||
#ifdef notdef
|
||||
(void)freopen("/dev/tty", "r", stdin);
|
||||
(void)freopen("/dev/tty", "w", stdout);
|
||||
#endif
|
||||
read_password(key, "\n\07\07Enter Key> ", 1);
|
||||
if (key_sched(key, KEYSCHED) < 0) {
|
||||
fprintf(stderr, "%s: Key parity error\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
ivec[0] = 0;
|
||||
ivec[1] = 0;
|
||||
memcpy(sum, key, sizeof(C_Block));
|
||||
for (;;) {
|
||||
if ((length = read(ind, inbuf, 512)) < 0) {
|
||||
fprintf(stderr, "%s: Error reading from input.\n", argv[0]);
|
||||
exit(1);
|
||||
} else if (length == 0) {
|
||||
fprintf(stderr, "\n");
|
||||
break;
|
||||
}
|
||||
if (encrypt) {
|
||||
#ifdef notdef
|
||||
sum = quad_cksum(inbuf, NULL, length, 1, sum);
|
||||
#endif
|
||||
quad_cksum(inbuf, sum, length, 1, sum);
|
||||
orig_size += length;
|
||||
fprintf(stderr, "\nlength = %d tot length = %d quad_sum = %X %X",
|
||||
length, orig_size, *(afs_uint32 *) sum,
|
||||
*((afs_uint32 *) sum + 1));
|
||||
fflush(stderr);
|
||||
}
|
||||
pcbc_encrypt(inbuf, oubuf, (afs_int32) length, KEYSCHED, ivec,
|
||||
encrypt);
|
||||
if (!encrypt) {
|
||||
#ifdef notdef
|
||||
sum = quad_cksum(oubuf, NULL, length, 1, sum);
|
||||
#endif
|
||||
quad_cksum(oubuf, sum, length, 1, sum);
|
||||
orig_size += length;
|
||||
fprintf(stderr, "\nlength = %d tot length = %d quad_sum = %X ",
|
||||
length, orig_size, *(afs_uint32 *) sum,
|
||||
*((afs_uint32 *) sum + 1));
|
||||
}
|
||||
length = (length + 7) & ~07;
|
||||
write(oud, oubuf, length);
|
||||
if (!encrypt)
|
||||
p = (int *)&oubuf[length - 8];
|
||||
else
|
||||
p = (int *)&inbuf[length - 8];
|
||||
ivec[0] = *p++;
|
||||
ivec[1] = *p;
|
||||
}
|
||||
|
||||
fprintf(stderr, "\ntot length = %d quad_sum = %X\n", orig_size, sum);
|
||||
/* if encrypting, now put the original length and checksum in */
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
/*
|
||||
* Copyright 1989 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <mit-cpyright.h>.
|
||||
*
|
||||
* These routines check and fix parity of encryption keys for the DES
|
||||
* algorithm.
|
||||
*
|
||||
* Under U.S. law, this software may not be exported outside the US
|
||||
* without license from the U.S. Commerce department.
|
||||
*
|
||||
* These routines form the library interface to the DES facilities.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <afsconfig.h>
|
||||
#include <afs/param.h>
|
||||
|
||||
|
||||
#include "mit-cpyright.h"
|
||||
#include <stdio.h>
|
||||
#include "des.h"
|
||||
#include "des_internal.h"
|
||||
#include "des_prototypes.h"
|
||||
|
||||
#include "odd.h" /* Load compile-time generated odd_parity table */
|
||||
|
||||
/*
|
||||
* des_fixup_key_parity: Forces odd parity per byte; parity is bits
|
||||
* 8,16,...64 in des order, implies 0, 8, 16, ...
|
||||
* vax order.
|
||||
*/
|
||||
void
|
||||
des_fixup_key_parity(des_cblock key)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < sizeof(des_cblock); i++)
|
||||
key[i] = odd_parity[key[i]];
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* des_check_key_parity: returns true iff key has the correct des parity.
|
||||
* See des_fix_key_parity for the definition of
|
||||
* correct des parity.
|
||||
*/
|
||||
int
|
||||
des_check_key_parity(des_cblock key)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < sizeof(des_cblock); i++)
|
||||
if (key[i] != odd_parity[key[i]])
|
||||
return (0);
|
||||
|
||||
return (1);
|
||||
}
|
@ -1,295 +0,0 @@
|
||||
/*
|
||||
* Copyright 1985, 1986, 1987, 1988 by the Massachusetts Institute
|
||||
* of Technology.
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <mit-cpyright.h>.
|
||||
*
|
||||
* This routine computes the DES key schedule given a key. The
|
||||
* permutations and shifts have been done at compile time, resulting
|
||||
* in a direct one-step mapping from the input key to the key
|
||||
* schedule.
|
||||
*
|
||||
* Also checks parity and weak keys.
|
||||
*
|
||||
* Watch out for the subscripts -- most effectively start at 1 instead
|
||||
* of at zero. Maybe some bugs in that area.
|
||||
*
|
||||
* DON'T change the data types for arrays and such, or it will either
|
||||
* break or run slower. This was optimized for Uvax2.
|
||||
*
|
||||
* In case the user wants to cache the computed key schedule, it is
|
||||
* passed as an arg. Also implies that caller has explicit control
|
||||
* over zeroing both the key schedule and the key.
|
||||
*
|
||||
* All registers labeled imply Vax using the Ultrix or 4.2bsd compiler.
|
||||
*
|
||||
* Originally written 6/85 by Steve Miller, MIT Project Athena.
|
||||
*/
|
||||
|
||||
#include <afsconfig.h>
|
||||
#include <afs/param.h>
|
||||
|
||||
|
||||
#include "mit-cpyright.h"
|
||||
#include "des_internal.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#include "des.h"
|
||||
#include "key_perm.h"
|
||||
#include "des_prototypes.h"
|
||||
|
||||
typedef char key[64];
|
||||
|
||||
/* the following are really void but cc86 doesnt allow it */
|
||||
static int make_key_sched(key Key, des_key_schedule Schedule);
|
||||
|
||||
#ifdef AFS_DUX40_ENV
|
||||
#pragma weak des_key_sched = afs_des_key_sched
|
||||
int
|
||||
afs_des_key_sched(des_cblock k, des_key_schedule schedule)
|
||||
#else
|
||||
int
|
||||
des_key_sched(des_cblock k, des_key_schedule schedule)
|
||||
#endif
|
||||
{
|
||||
/* better pass 8 bytes, length not checked here */
|
||||
|
||||
int i, j, n; /* i = r10, j = r9, n = r8 */
|
||||
unsigned int temp; /* r7 */
|
||||
char *p_char; /* r6 */
|
||||
key k_char;
|
||||
i = 8;
|
||||
n = 0;
|
||||
p_char = k_char;
|
||||
|
||||
#ifdef lint
|
||||
n = n; /* fool it in case of VAXASM */
|
||||
#endif
|
||||
#ifdef DEBUG
|
||||
if (des_debug)
|
||||
fprintf(stderr, "\n\ninput key, left to right = ");
|
||||
#endif
|
||||
|
||||
if (!des_check_key_parity(k)) /* bad parity --> return -1 */
|
||||
return (-1);
|
||||
|
||||
do {
|
||||
/* get next input key byte */
|
||||
#ifdef DEBUG
|
||||
if (des_debug)
|
||||
fprintf(stderr, "%02x ", *k & 0xff);
|
||||
#endif
|
||||
temp = (unsigned int)((unsigned char)*k++);
|
||||
j = 8;
|
||||
|
||||
do {
|
||||
#ifndef VAXASM
|
||||
*p_char++ = (int)temp & 01;
|
||||
temp = temp >> 1;
|
||||
#else
|
||||
asm("bicb3 $-2,r7,(r8)+[r6]");
|
||||
asm("rotl $-1,r7,r7");
|
||||
#endif
|
||||
} while (--j > 0);
|
||||
} while (--i > 0);
|
||||
|
||||
#ifdef DEBUG
|
||||
if (des_debug) {
|
||||
p_char = k_char;
|
||||
fprintf(stderr, "\nKey bits, from zero to 63");
|
||||
for (i = 0; i <= 7; i++) {
|
||||
fprintf(stderr, "\n\t");
|
||||
for (j = 0; j <= 7; j++)
|
||||
fprintf(stderr, "%d ", *p_char++);
|
||||
}
|
||||
}
|
||||
#else
|
||||
#ifdef lint
|
||||
p_char = p_char;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* check against weak keys */
|
||||
k -= sizeof(des_cblock);
|
||||
|
||||
if (des_is_weak_key(k))
|
||||
return (-2);
|
||||
|
||||
make_key_sched(k_char, schedule);
|
||||
|
||||
/* if key was good, return 0 */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
make_key_sched(key Key, des_key_schedule Schedule)
|
||||
{
|
||||
/*
|
||||
* The key has been converted to an array to make this run faster;
|
||||
* on a microvax 2, this routine takes about 3.5ms. The code and
|
||||
* size of the arrays has been played with to get it as fast as
|
||||
* possible.
|
||||
*
|
||||
* Don't change the order of the declarations below without
|
||||
* checking the assembler code to make sure that things are still
|
||||
* where it expects them.
|
||||
*/
|
||||
|
||||
/* r10, unroll by AUTH_DES_ITER */
|
||||
int iter = AUTH_DES_ITER;
|
||||
afs_uint32 *k; /* r9 */
|
||||
int *kp; /* r8 */
|
||||
afs_uint32 temp; /* r7 */
|
||||
|
||||
kp = (int *)key_perm;
|
||||
k = (afs_uint32 *) Schedule;
|
||||
|
||||
do {
|
||||
/*
|
||||
* create the Key schedule
|
||||
*
|
||||
* put into lsb first order (lsb is bit 0)
|
||||
*/
|
||||
|
||||
/*
|
||||
* On the uvax2, this C code below is as fast as straight
|
||||
* assembler, so just use C code below.
|
||||
*/
|
||||
temp = 0;
|
||||
#ifdef LSBFIRST
|
||||
#define BIT(x) x
|
||||
#else
|
||||
#ifdef notdef
|
||||
#define BIT(x) rev_swap_bit_pos_0(x)
|
||||
#else
|
||||
#define BIT(x) x
|
||||
#endif
|
||||
#endif
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(0));
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(1));
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(2));
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(3));
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(4));
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(5));
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(6));
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(7));
|
||||
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(8));
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(9));
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(10));
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(11));
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(12));
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(13));
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(14));
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(15));
|
||||
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(16));
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(17));
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(18));
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(19));
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(20));
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(21));
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(22));
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(23));
|
||||
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(24));
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(25));
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(26));
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(27));
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(28));
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(29));
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(30));
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(31));
|
||||
|
||||
*k++ = temp;
|
||||
temp = 0;
|
||||
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(0));
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(1));
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(2));
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(3));
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(4));
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(5));
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(6));
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(7));
|
||||
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(8));
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(9));
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(10));
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(11));
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(12));
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(13));
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(14));
|
||||
if ((unsigned)Key[(int)*kp++])
|
||||
temp |= (1 << BIT(15));
|
||||
|
||||
*k++ = temp;
|
||||
|
||||
} while (--iter > 0);
|
||||
|
||||
#ifdef DEBUG
|
||||
if (des_debug) {
|
||||
int i;
|
||||
char *n;
|
||||
int q;
|
||||
fprintf(stderr, "\nKey Schedule, left to right");
|
||||
for (i = 0; i < AUTH_DES_ITER; i++) {
|
||||
n = (char *)&Schedule[i];
|
||||
fprintf(stderr, "\n");
|
||||
for (q = 0; q <= 7; q++)
|
||||
fprintf(stderr, "%02x ", *n++ & 0xff);
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
return (0);
|
||||
}
|
@ -1,91 +0,0 @@
|
||||
/*
|
||||
* Copyright 1988 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* For copying and distribution information,
|
||||
* please seethe file <mit-cpyright.h>.
|
||||
*
|
||||
* This file contains most of the routines needed by the various
|
||||
* make_foo programs, to account for bit- and byte-ordering on
|
||||
* different machine types. It also contains other routines useful in
|
||||
* generating the intermediate source files.
|
||||
*/
|
||||
|
||||
#include <afsconfig.h>
|
||||
#include <afs/param.h>
|
||||
|
||||
|
||||
#include "mit-cpyright.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#else
|
||||
#ifdef HAVE_STRINGS_H
|
||||
#include <strings.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "des.h"
|
||||
#include "des_internal.h"
|
||||
#include "des_prototypes.h"
|
||||
|
||||
char const *whoami;
|
||||
|
||||
#ifndef DONT_INCL_MAIN
|
||||
|
||||
#include "AFS_component_version_number.c"
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
char *filename;
|
||||
char *arg;
|
||||
FILE *stream;
|
||||
|
||||
whoami = argv[0];
|
||||
filename = (char *)NULL;
|
||||
|
||||
while (argc--, *++argv) {
|
||||
arg = *argv;
|
||||
if (*arg == '-') {
|
||||
if (!strcmp(arg, "-d") && !strcmp(arg, "-debug"))
|
||||
des_debug++;
|
||||
else {
|
||||
fprintf(stderr, "%s: unknown control argument %s\n", whoami,
|
||||
arg);
|
||||
goto usage;
|
||||
}
|
||||
} else if (filename) {
|
||||
fprintf(stderr, "%s: multiple file names provided: %s, %s\n",
|
||||
whoami, filename, arg);
|
||||
goto usage;
|
||||
} else
|
||||
filename = arg;
|
||||
}
|
||||
|
||||
if (!filename) {
|
||||
fprintf(stderr, "%s: no file name provided\n", whoami);
|
||||
goto usage;
|
||||
}
|
||||
|
||||
stream = fopen(filename, "w");
|
||||
if (!stream) {
|
||||
perror(filename);
|
||||
usage:
|
||||
fprintf(stderr, "usage: %s [-debug] filename\n", whoami);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fputs("/* This file is automatically generated. Do not edit it. */\n",
|
||||
stream);
|
||||
|
||||
/* This routine will generate the contents of the file. */
|
||||
gen(stream);
|
||||
if (fclose(stream) == EOF) {
|
||||
perror(filename);
|
||||
exit(1);
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
#endif /* DONT_INCL_MAIN */
|
@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright 1987, 1988 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <mit-copyright.h>.
|
||||
*
|
||||
* Part of the MIT Project Athena Kerberos encryption system,
|
||||
* originally written 8/85 by Steve Miller.
|
||||
*/
|
||||
|
||||
#include <afsconfig.h>
|
||||
#include <afs/param.h>
|
||||
|
||||
|
||||
#include "mit-cpyright.h"
|
||||
#include <stdio.h>
|
||||
#include "tables.h"
|
||||
|
||||
#include "AFS_component_version_number.c"
|
||||
|
||||
main()
|
||||
{
|
||||
int i;
|
||||
|
||||
/* clear the output */
|
||||
fprintf(stdout, "\n\tL2 = 0; R2 = 0;");
|
||||
|
||||
/* only take bits from R1, put into either L2 or R2 */
|
||||
/* first setup E */
|
||||
fprintf(stdout, "\n/* E operations */\n/* right to left */\n");
|
||||
/* first list mapping from left to left */
|
||||
|
||||
for (i = 0; i <= 31; i++)
|
||||
if (E[i] < 32)
|
||||
fprintf(stdout, "\n\tif (R1 & (1<<%d)) L2 |= 1<<%d;", E[i], i);
|
||||
|
||||
fprintf(stdout, "\n\n/* now from right to right */\n");
|
||||
/* list mapping from left to right */
|
||||
for (i = 32; i <= 47; i++)
|
||||
if (E[i] < 32)
|
||||
fprintf(stdout, "\n\tif (R1 & (1<<%d)) R2 |= 1<<%d;", E[i],
|
||||
i - 32);
|
||||
|
||||
fprintf(stdout, "\n");
|
||||
}
|
@ -1,83 +0,0 @@
|
||||
/*
|
||||
* Copyright 1988 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* For copying and distribution information,
|
||||
* please see the file <mit-cpyright.h>.
|
||||
*
|
||||
* This file contains a generation routine for source code
|
||||
* implementing the final permutation of the DES.
|
||||
*/
|
||||
|
||||
#include <afsconfig.h>
|
||||
#include <afs/param.h>
|
||||
|
||||
|
||||
#include "mit-cpyright.h"
|
||||
#include <stdio.h>
|
||||
#include "des.h"
|
||||
#include "des_internal.h"
|
||||
#include "des_prototypes.h"
|
||||
|
||||
#define WANT_FP_TABLE
|
||||
#include "tables.h"
|
||||
|
||||
void
|
||||
gen(FILE * stream)
|
||||
{
|
||||
int i;
|
||||
#ifdef AFS_DARWIN80_ENV
|
||||
int j;
|
||||
|
||||
#define swap_long_bytes_bit_number _darwin_swap_long_bytes_bit_number
|
||||
#endif /* AFS_DARWIN80_ENV */
|
||||
|
||||
/* clear the output */
|
||||
fprintf(stream, " L2 = 0; R2 = 0;\n");
|
||||
|
||||
/*
|
||||
* NOTE: As part of the final permutation, we also have to adjust
|
||||
* for host bit order via "swap_bit_pos_0()". Since L2,R2 are
|
||||
* the output from this, we adjust the bit positions written into
|
||||
* L2,R2.
|
||||
*/
|
||||
|
||||
#define SWAP(i,j) \
|
||||
swap_long_bytes_bit_number(swap_bit_pos_0_to_ansi((unsigned)i)-j)
|
||||
|
||||
#ifdef AFS_DARWIN80_ENV
|
||||
for(j = 0;; j++) {
|
||||
fprintf(stream, "%s", _darwin_whichstr[j]);
|
||||
if (j == 2)
|
||||
break;
|
||||
#endif /* AFS_DARWIN80_ENV */
|
||||
/* first setup FP */
|
||||
fprintf(stream, "/* FP operations */\n/* first left to left */\n");
|
||||
|
||||
/* first list mapping from left to left */
|
||||
for (i = 0; i <= 31; i++)
|
||||
if (FP[i] < 32)
|
||||
test_set(stream, "L1", FP[i], "L2", SWAP(i, 0));
|
||||
|
||||
/* now mapping from right to left */
|
||||
fprintf(stream, "\n\n/* now from right to left */\n");
|
||||
for (i = 0; i <= 31; i++)
|
||||
if (FP[i] >= 32)
|
||||
test_set(stream, "R1", FP[i] - 32, "L2", SWAP(i, 0));
|
||||
|
||||
fprintf(stream, "\n/* now from left to right */\n");
|
||||
|
||||
/* list mapping from left to right */
|
||||
for (i = 32; i <= 63; i++)
|
||||
if (FP[i] < 32)
|
||||
test_set(stream, "L1", FP[i], "R2", SWAP(i, 32));
|
||||
|
||||
/* now mapping from right to right */
|
||||
fprintf(stream, "\n/* last from right to right */\n");
|
||||
for (i = 32; i <= 63; i++)
|
||||
if (FP[i] >= 32)
|
||||
test_set(stream, "R1", FP[i] - 32, "R2", SWAP(i, 32));
|
||||
#ifdef AFS_DARWIN80_ENV
|
||||
_darwin_which = !_darwin_which;
|
||||
}
|
||||
#endif /* AFS_DARWIN80_ENV */
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
/*
|
||||
* Copyright 1987, 1988 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <mit-cpyright.h>.
|
||||
*
|
||||
* This routine generates source code implementing the initial
|
||||
* permutation of the DES.
|
||||
*/
|
||||
|
||||
#include <afsconfig.h>
|
||||
#include <afs/param.h>
|
||||
|
||||
|
||||
#include "mit-cpyright.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "des.h"
|
||||
#include "des_internal.h"
|
||||
|
||||
#define WANT_IP_TABLE
|
||||
#include "tables.h"
|
||||
|
||||
#include "des_prototypes.h"
|
||||
|
||||
#define SWAP(x) swap_long_bytes_bit_number(swap_bit_pos_0_to_ansi(x))
|
||||
|
||||
void
|
||||
gen(FILE * stream)
|
||||
{
|
||||
int i;
|
||||
#ifdef AFS_DARWIN80_ENV
|
||||
int j;
|
||||
|
||||
#define swap_long_bytes_bit_number _darwin_swap_long_bytes_bit_number
|
||||
#endif /* AFS_DARWIN80_ENV */
|
||||
|
||||
/* clear the output */
|
||||
fprintf(stream, " L2 = 0; R2 = 0;\n");
|
||||
|
||||
#ifdef AFS_DARWIN80_ENV
|
||||
for(j = 0;; j++) {
|
||||
fprintf(stream, "%s", _darwin_whichstr[j]);
|
||||
if (j == 2)
|
||||
break;
|
||||
#endif /* AFS_DARWIN80_ENV */
|
||||
/* first setup IP */
|
||||
fprintf(stream, "/* IP operations */\n/* first left to left */\n");
|
||||
|
||||
/* first list mapping from left to left */
|
||||
for (i = 0; i <= 31; i++)
|
||||
if (IP[i] < 32)
|
||||
test_set(stream, "L1", SWAP(IP[i]), "L2", i);
|
||||
|
||||
/* now mapping from right to left */
|
||||
fprintf(stream, "\n/* now from right to left */\n");
|
||||
for (i = 0; i <= 31; i++)
|
||||
if (IP[i] >= 32)
|
||||
test_set(stream, "R1", SWAP(IP[i] - 32), "L2", i);
|
||||
|
||||
fprintf(stream, "\n/* now from left to right */\n");
|
||||
/* list mapping from left to right */
|
||||
for (i = 32; i <= 63; i++)
|
||||
if (IP[i] < 32)
|
||||
test_set(stream, "L1", SWAP(IP[i]), "R2", i - 32);
|
||||
|
||||
/* now mapping from right to right */
|
||||
fprintf(stream, "\n/* last from right to right */\n");
|
||||
for (i = 32; i <= 63; i++)
|
||||
if (IP[i] >= 32)
|
||||
test_set(stream, "R1", SWAP(IP[i] - 32), "R2", i - 32);
|
||||
#ifdef AFS_DARWIN80_ENV
|
||||
_darwin_which = !_darwin_which;
|
||||
}
|
||||
#endif /* AFS_DARWIN80_ENV */
|
||||
exit(0);
|
||||
}
|
@ -1,210 +0,0 @@
|
||||
/*
|
||||
* Copyright 1988 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <mit-cpyright.h>.
|
||||
*
|
||||
* This routine calculates an effective Key schedule set of
|
||||
* permutations for des. Beginning with the pre-defined key schedule
|
||||
* algorithm, it reduces it to a set of 16 permutations upon the
|
||||
* initial key. Only needs to execute once to produce a header file.
|
||||
* Note that we subtract one from the values ouput to fix up for C
|
||||
* subscripts starting at 0.
|
||||
*/
|
||||
|
||||
#include <afsconfig.h>
|
||||
#include <afs/param.h>
|
||||
|
||||
|
||||
#include "mit-cpyright.h"
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include "des.h"
|
||||
#include "des_internal.h"
|
||||
#include "des_prototypes.h"
|
||||
|
||||
char *progname;
|
||||
|
||||
static int key_position[64 + 1];
|
||||
static int C[28 + 1];
|
||||
static int D[28 + 1];
|
||||
static int C_temp, D_temp;
|
||||
|
||||
/*
|
||||
* CONVENTIONS for numbering the bits
|
||||
* bit 0 ==> lsb
|
||||
* L starts at bit 0
|
||||
* R starts at bit 64
|
||||
*
|
||||
* BEWARE-- some stuff starts at 0, some at 1; perhaps some bugs still?
|
||||
*/
|
||||
|
||||
/*
|
||||
* Sequence of shifts used for the key schedule.
|
||||
*/
|
||||
static int const shift[16 + 1] = { 0,
|
||||
1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1,
|
||||
};
|
||||
|
||||
static int const pc_1[56 + 1] = { 0,
|
||||
|
||||
57, 49, 41, 33, 25, 17, 9,
|
||||
1, 58, 50, 42, 34, 26, 18,
|
||||
10, 2, 59, 51, 43, 35, 27,
|
||||
19, 11, 3, 60, 52, 44, 36,
|
||||
|
||||
63, 55, 47, 39, 31, 23, 15,
|
||||
7, 62, 54, 46, 38, 30, 22,
|
||||
14, 6, 61, 53, 45, 37, 29,
|
||||
21, 13, 5, 28, 20, 12, 4,
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Permuted-choice 2, to pick out the bits from
|
||||
* the CD array that generate the key schedule.
|
||||
*/
|
||||
static int const pc_2[48 + 1] = { 0,
|
||||
|
||||
14, 17, 11, 24, 1, 5,
|
||||
3, 28, 15, 6, 21, 10,
|
||||
23, 19, 12, 4, 26, 8,
|
||||
16, 7, 27, 20, 13, 2,
|
||||
|
||||
41, 52, 31, 37, 47, 55,
|
||||
30, 40, 51, 45, 33, 48,
|
||||
44, 49, 39, 56, 34, 53,
|
||||
46, 42, 50, 36, 29, 32,
|
||||
};
|
||||
|
||||
static int ks_perm[16 + 1][48 + 1];
|
||||
|
||||
int des_debug;
|
||||
|
||||
void
|
||||
gen(FILE * stream)
|
||||
{
|
||||
/* Local Declarations */
|
||||
int i, j, iter;
|
||||
|
||||
/*
|
||||
* initialize the key_position array s.t. key_position[i] = i;
|
||||
* that is, each element is equal to its starting position.
|
||||
*
|
||||
* Also adjust for the bit order within bytes.
|
||||
*/
|
||||
|
||||
for (i = 0; i < 65; i++)
|
||||
key_position[i] = swap_bit_pos_1(i);
|
||||
|
||||
fprintf(stream, "static int const key_perm[16][48] = {\n");
|
||||
|
||||
/*
|
||||
* apply pc_1 to initial key_position to create C[0] and D[0]
|
||||
* Start at pc_1[1], not pc_1[0]
|
||||
*/
|
||||
for (i = 1; i <= 28; i++) {
|
||||
C[i] = key_position[pc_1[i]];
|
||||
D[i] = key_position[pc_1[i + 28]];
|
||||
}
|
||||
|
||||
/*
|
||||
* major loop over the 16 iterations
|
||||
* start at iter = 1, not zero.
|
||||
*/
|
||||
for (iter = 1; iter <= 16; iter++) {
|
||||
if (des_debug) {
|
||||
/* for debugging */
|
||||
printf("/* DEBUG-- start iteration = %d shifts = %d", iter,
|
||||
shift[iter]);
|
||||
printf("\nC array");
|
||||
for (i = 1; i <= 4; i++) {
|
||||
printf("\n");
|
||||
for (j = 1; j <= 7; j++)
|
||||
printf("%d, ", C[(i - 1) * 7 + j]);
|
||||
}
|
||||
printf("\n\nD array");
|
||||
for (i = 1; i <= 4; i++) {
|
||||
printf("\n");
|
||||
for (j = 1; j <= 7; j++)
|
||||
printf("%d, ", D[(i - 1) * 7 + j]);
|
||||
}
|
||||
printf("\n */");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
/* apply the appropriate left shifts */
|
||||
for (i = 1; i <= shift[iter]; i++) {
|
||||
C_temp = C[1];
|
||||
D_temp = D[1];
|
||||
for (j = 1; j <= 27; j++) {
|
||||
C[j] = C[j + 1];
|
||||
D[j] = D[j + 1];
|
||||
}
|
||||
C[j] = C_temp;
|
||||
D[j] = D_temp;
|
||||
}
|
||||
|
||||
|
||||
if (des_debug) {
|
||||
/* for debugging */
|
||||
printf("/* DEBUG:\n");
|
||||
printf(" * after shifts, iteration = %d shifts = %d", iter,
|
||||
shift[iter]);
|
||||
printf("\nC array");
|
||||
for (i = 1; i <= 4; i++) {
|
||||
printf("\n");
|
||||
for (j = 1; j <= 7; j++)
|
||||
printf("%d, ", C[(i - 1) * 7 + j]);
|
||||
}
|
||||
printf("\n\nD array");
|
||||
for (i = 1; i <= 4; i++) {
|
||||
printf("\n");
|
||||
for (j = 1; j <= 7; j++)
|
||||
printf("%d, ", D[(i - 1) * 7 + j]);
|
||||
}
|
||||
printf("\n */");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
/*
|
||||
* apply pc_2
|
||||
* Start at pc_2[1], not pc_2[0]
|
||||
*
|
||||
* Start stuffing ks_perm[1][1], not ks_perm[0][0]
|
||||
*
|
||||
* Adjust ks_perm for bit order if needed.
|
||||
*/
|
||||
for (i = 1; i <= 48; i++) {
|
||||
if (pc_2[i] <= 28)
|
||||
ks_perm[iter][(i)] = C[pc_2[i]];
|
||||
else
|
||||
ks_perm[iter][(i)] = D[pc_2[i] - 28];
|
||||
}
|
||||
|
||||
/* now output the resulting key permutation */
|
||||
fprintf(stream, "\n /* ks permutation iteration = %2d */", iter);
|
||||
for (i = 1; i <= 6; i++) {
|
||||
if (i == 1)
|
||||
fprintf(stream, "\n {");
|
||||
fprintf(stream, "\n ");
|
||||
for (j = 1; j <= 8; j++) {
|
||||
/*
|
||||
* IMPORTANT -- subtract one from value to adjust to a
|
||||
* zero-based subscript for key
|
||||
*/
|
||||
fprintf(stream, "%d", ks_perm[iter][(i - 1) * 8 + j] - 1);
|
||||
/* omit last comma */
|
||||
if ((j != 8) || (i != 6)) {
|
||||
fprintf(stream, ", ");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (iter != 16) {
|
||||
fprintf(stream, "\n }, ");
|
||||
} else {
|
||||
fprintf(stream, "\n }");
|
||||
}
|
||||
}
|
||||
fprintf(stream, "\n};\n");
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Copyright 1988 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* For copying and distribution information, please see
|
||||
* the file <mit-cpyright.h>.
|
||||
*
|
||||
* This routine generates an odd-parity table for use in key generation.
|
||||
*/
|
||||
|
||||
#include <afsconfig.h>
|
||||
#include <afs/param.h>
|
||||
|
||||
|
||||
#include "mit-cpyright.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void
|
||||
gen(FILE *stream)
|
||||
{
|
||||
/*
|
||||
* map a byte into its equivalent with odd parity, where odd
|
||||
* parity is in the least significant bit
|
||||
*/
|
||||
int i, j, k, odd;
|
||||
|
||||
fprintf(stream, "static unsigned char const odd_parity[256] = {\n");
|
||||
|
||||
for (i = 0; i < 256; i++) {
|
||||
odd = 0;
|
||||
/* shift out the lsb parity bit */
|
||||
k = i >> 1;
|
||||
/* then count the other bits */
|
||||
for (j = 0; j < 7; j++) {
|
||||
odd ^= (k & 1);
|
||||
k = k >> 1;
|
||||
}
|
||||
k = i & ~1;
|
||||
if (!odd)
|
||||
k |= 1;
|
||||
fprintf(stream, "%3d", k);
|
||||
if (i < 255)
|
||||
fprintf(stream, ", ");
|
||||
if (i % 8 == 0)
|
||||
fprintf(stream, "\n");
|
||||
}
|
||||
fprintf(stream, "};\n");
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Copyright 1985, 1988 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* For copying and distribution information, please
|
||||
* see the file <mit-cpyright.h>.
|
||||
*
|
||||
* This routine generates the P permutation code for the DES.
|
||||
*/
|
||||
|
||||
#include <afsconfig.h>
|
||||
#include <afs/param.h>
|
||||
|
||||
|
||||
#include "mit-cpyright.h"
|
||||
#include <stdio.h>
|
||||
#include "des.h"
|
||||
#include "des_internal.h"
|
||||
#include "tables.h"
|
||||
#include "des_prototypes.h"
|
||||
|
||||
void
|
||||
gen(FILE * stream)
|
||||
{
|
||||
/* P permutes 32 bit input R1 into 32 bit output R2 */
|
||||
|
||||
/* clear the output */
|
||||
fprintf(stream, " L2 = 0;\n");
|
||||
#ifndef BIG
|
||||
fprintf(stream, " R2 = 0;\n");
|
||||
fprintf(stream, "/* P operations */\n/* from right to right */\n");
|
||||
/* first list mapping from left to left */
|
||||
for (i = 0; i <= 31; i++)
|
||||
if (P[i] < 32)
|
||||
fprintf(stream, " if (R1 & (1<<%d)) R2 |= 1<<%d;\n", P[i], i);
|
||||
#else /* BIG */
|
||||
/* flip p into p_temp */
|
||||
fprintf(stream, " P_temp = R1;\n");
|
||||
fprintf(stream, " P_temp_p = (unsigned char *) &P_temp;\n");
|
||||
|
||||
#ifdef AFS_DARWIN80_ENV
|
||||
fprintf(stream, "#if defined(__i386__) || defined(__amd64__) || defined(__arm__)\n");
|
||||
fprintf(stream, " R2 = P_prime[0][*P_temp_p++];\n");
|
||||
fprintf(stream, " R2 |= P_prime[1][*P_temp_p++];\n");
|
||||
fprintf(stream, " R2 |= P_prime[2][*P_temp_p++];\n");
|
||||
fprintf(stream, " R2 |= P_prime[3][*P_temp_p];\n");
|
||||
fprintf(stream, "#elif defined(__ppc__) || defined(__ppc64__)\n");
|
||||
fprintf(stream, " R2 = P_prime[3][*P_temp_p++];\n");
|
||||
fprintf(stream, " R2 |= P_prime[2][*P_temp_p++];\n");
|
||||
fprintf(stream, " R2 |= P_prime[1][*P_temp_p++];\n");
|
||||
fprintf(stream, " R2 |= P_prime[0][*P_temp_p];\n");
|
||||
fprintf(stream, "#else\n#error Unsupported architecture\n#endif\n");
|
||||
#else /* !AFS_DARWIN80_ENV */
|
||||
#ifdef LSBFIRST
|
||||
fprintf(stream, " R2 = P_prime[0][*P_temp_p++];\n");
|
||||
fprintf(stream, " R2 |= P_prime[1][*P_temp_p++];\n");
|
||||
fprintf(stream, " R2 |= P_prime[2][*P_temp_p++];\n");
|
||||
fprintf(stream, " R2 |= P_prime[3][*P_temp_p];\n");
|
||||
#else /* MSBFIRST */
|
||||
fprintf(stream, " R2 = P_prime[3][*P_temp_p++];\n");
|
||||
fprintf(stream, " R2 |= P_prime[2][*P_temp_p++];\n");
|
||||
fprintf(stream, " R2 |= P_prime[1][*P_temp_p++];\n");
|
||||
fprintf(stream, " R2 |= P_prime[0][*P_temp_p];\n");
|
||||
#endif /* MSBFIRST */
|
||||
#endif /* !AFS_DARWIN80_ENV */
|
||||
#endif /* BIG */
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
/*
|
||||
* Copyright 1985, 1988 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* For copying and distribution information, please
|
||||
* see the file <mit-cpyright.h>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <afsconfig.h>
|
||||
#include <afs/param.h>
|
||||
|
||||
|
||||
#include "mit-cpyright.h"
|
||||
#include <stdio.h>
|
||||
#include "des.h"
|
||||
#include "des_internal.h"
|
||||
#include "des_prototypes.h"
|
||||
|
||||
#define WANT_P_TABLE
|
||||
#include "tables.h"
|
||||
|
||||
static unsigned char P_temp[32];
|
||||
static afs_uint32 P_prime[4][256];
|
||||
|
||||
void
|
||||
gen(FILE * stream)
|
||||
{
|
||||
int i, j, k, m;
|
||||
/* P permutes 32 bit input R1 into 32 bit output R2 */
|
||||
|
||||
#ifdef BIG
|
||||
/* flip p into p_temp */
|
||||
for (i = 0; i < 32; i++)
|
||||
P_temp[(int)P[rev_swap_bit_pos_0(i)]] = rev_swap_bit_pos_0(i);
|
||||
|
||||
/*
|
||||
* now for each byte of input, figure out all possible combinations
|
||||
*/
|
||||
for (i = 0; i < 4; i++) { /* each input byte */
|
||||
for (j = 0; j < 256; j++) { /* each possible byte value */
|
||||
/* flip bit order */
|
||||
k = j;
|
||||
/* swap_byte_bits(j); */
|
||||
for (m = 0; m < 8; m++) { /* each bit */
|
||||
if (k & (1 << m)) {
|
||||
/* set output values */
|
||||
P_prime[i][j] |= 1 << P_temp[(i * 8) + m];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(stream, "\n\tstatic afs_uint32 const P_prime[4][256] = {\n\t");
|
||||
for (i = 0; i < 4; i++) {
|
||||
fprintf(stream, "\n{ ");
|
||||
for (j = 0; j < 64; j++) {
|
||||
fprintf(stream, "\n");
|
||||
for (k = 0; k < 4; k++) {
|
||||
fprintf(stream, "0x%08lX",
|
||||
(unsigned long)P_prime[i][j * 4 + k]);
|
||||
if ((j == 63) && (k == 3))
|
||||
fprintf(stream, "}");
|
||||
if ((i == 3) && (j == 63) && (k == 3))
|
||||
fprintf(stream, "\n};");
|
||||
else
|
||||
fprintf(stream, ", ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
fprintf(stream, "\n");
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright 1985, 1988 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* For copying and distribution information, please
|
||||
* see the file <mit-cpyright.h>.
|
||||
*/
|
||||
|
||||
#include <afsconfig.h>
|
||||
#include <afs/param.h>
|
||||
|
||||
|
||||
#include "mit-cpyright.h"
|
||||
#include <stdio.h>
|
||||
#include "des_internal.h"
|
||||
#include "s_table.h"
|
||||
|
||||
void
|
||||
gen(stream)
|
||||
FILE *stream;
|
||||
{
|
||||
/* clear the output */
|
||||
fprintf(stream, "\n\tL2 = 0; R2 = 0;");
|
||||
|
||||
#ifdef notdef
|
||||
/* P permutes 32 bit input R1 into 32 bit output R2 */
|
||||
|
||||
fprintf(stream, "\n/* P operations */\n/* first left to left */\n");
|
||||
/* first list mapping from left to left */
|
||||
for (i = 0; i <= 31; i++)
|
||||
if (S[i] < 32)
|
||||
fprintf(stream, "\n\tif (R1 & (1<<%d)) R2 |= 1<<%d;", S[i], i);
|
||||
#endif
|
||||
fprintf(stream, "\n");
|
||||
}
|
@ -1,76 +0,0 @@
|
||||
/*
|
||||
* Copyright 1985, 1988 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* For copying and distribution information, please
|
||||
* see the file <mit-cpyright.h>.
|
||||
*/
|
||||
|
||||
#include <afsconfig.h>
|
||||
#include <afs/param.h>
|
||||
|
||||
|
||||
#include "mit-cpyright.h"
|
||||
#include <stdio.h>
|
||||
#include "des.h"
|
||||
#include "des_internal.h"
|
||||
#include "des_prototypes.h"
|
||||
|
||||
#define WANT_S_TABLE
|
||||
#include "tables.h"
|
||||
|
||||
char temp[8][64];
|
||||
int des_debug;
|
||||
|
||||
void
|
||||
gen(FILE * stream)
|
||||
{
|
||||
afs_uint32 i, j, k, l, m, n;
|
||||
|
||||
/* rearrange the S table entries, and adjust for host bit order */
|
||||
|
||||
fprintf(stream, "static unsigned char const S_adj[8][64] = {");
|
||||
fprintf(stream, " /* adjusted */\n");
|
||||
|
||||
for (i = 0; i <= 7; i++) {
|
||||
for (j = 0; j <= 63; j++) {
|
||||
/*
|
||||
* figure out which one to put in the new S[i][j]
|
||||
*
|
||||
* start by assuming the value of the input bits is "j" in
|
||||
* host order, then figure out what it means in standard
|
||||
* form.
|
||||
*/
|
||||
k = swap_six_bits_to_ansi(j);
|
||||
/* figure out the index for k */
|
||||
l = (((k >> 5) & 01) << 5)
|
||||
+ ((k & 01) << 4) + ((k >> 1) & 0xf);
|
||||
m = S[i][l];
|
||||
/* restore in host order */
|
||||
n = swap_four_bits_to_ansi(m);
|
||||
if (des_debug)
|
||||
fprintf(stderr,
|
||||
"i = %ld, j = %ld, k = %ld, l = %ld, m = %ld, n = %ld\n",
|
||||
(long)i, (long)j, (long)k, (long)l, (long)m, (long)n);
|
||||
temp[i][j] = n;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i <= 7; i++) {
|
||||
fprintf(stream, "\n{ ");
|
||||
k = 0;
|
||||
for (j = 0; j <= 3; j++) {
|
||||
fprintf(stream, "\n");
|
||||
for (m = 0; m <= 15; m++) {
|
||||
fprintf(stream, "%2d", temp[i][k]);
|
||||
if (k == 63) {
|
||||
fprintf(stream, "\n}");
|
||||
}
|
||||
if ((k++ != 63) || (i != 7)) {
|
||||
fprintf(stream, ", ");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(stream, "\n};\n");
|
||||
}
|
315
src/des/misc.c
315
src/des/misc.c
@ -1,315 +0,0 @@
|
||||
/*
|
||||
* Copyright 1988 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* For copying and distribution information,
|
||||
* please seethe file <mit-cpyright.h>.
|
||||
*
|
||||
* This file contains most of the routines needed by the various
|
||||
* make_foo programs, to account for bit- and byte-ordering on
|
||||
* different machine types. It also contains other routines useful in
|
||||
* generating the intermediate source files.
|
||||
*/
|
||||
|
||||
#include <afsconfig.h>
|
||||
#include <afs/param.h>
|
||||
|
||||
|
||||
#include "mit-cpyright.h"
|
||||
#ifndef KERNEL
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
#include "des.h"
|
||||
#include "des_internal.h"
|
||||
#include "des_prototypes.h"
|
||||
|
||||
int des_debug;
|
||||
|
||||
/*
|
||||
* The DES algorithm is defined in terms of MSBFIRST, so sometimes,
|
||||
* e.g. VAXes, we need to fix it up. ANSI order means the DES
|
||||
* MSBFIRST order.
|
||||
*/
|
||||
|
||||
#if 0 /* These don't seem to get used anywhere.... */
|
||||
void
|
||||
swap_bits(char *array)
|
||||
{
|
||||
#ifdef MSBFIRST
|
||||
/* just return */
|
||||
return;
|
||||
#else /* LSBFIRST */
|
||||
int old, new, i, j;
|
||||
|
||||
/* for an eight byte block-- */
|
||||
/* flips the bit order within each byte from 0 lsb to 0 msb */
|
||||
for (i = 0; i <= 7; i++) {
|
||||
old = *array;
|
||||
new = 0;
|
||||
for (j = 0; j <= 7; j++) {
|
||||
new |= old & 01; /* copy a bit */
|
||||
if (j < 7) {
|
||||
/* rotate in opposite directions */
|
||||
old = old >> 1;
|
||||
new = new << 1;
|
||||
}
|
||||
}
|
||||
*array++ = new;
|
||||
}
|
||||
#endif /* MSBFIRST */
|
||||
}
|
||||
|
||||
afs_uint32
|
||||
long_swap_bits(afs_uint32 x)
|
||||
{
|
||||
#ifdef MSBFIRST
|
||||
return x;
|
||||
#else
|
||||
char *array = (char *)&x;
|
||||
int old, new, i, j;
|
||||
|
||||
/* flips the bit order within each byte from 0 lsb to 0 msb */
|
||||
for (i = 0; i <= (sizeof(afs_int32) - 1); i++) {
|
||||
old = *array;
|
||||
new = 0;
|
||||
for (j = 0; j <= 7; j++) {
|
||||
if (old & 01)
|
||||
new = new | 01;
|
||||
if (j < 7) {
|
||||
old = old >> 1;
|
||||
new = new << 1;
|
||||
}
|
||||
}
|
||||
*array++ = new;
|
||||
}
|
||||
return x;
|
||||
#endif /* LSBFIRST */
|
||||
}
|
||||
#endif /* 0 */
|
||||
|
||||
afs_uint32
|
||||
swap_six_bits_to_ansi(afs_uint32 old)
|
||||
{
|
||||
afs_uint32 new, j;
|
||||
|
||||
/* flips the bit order within each byte from 0 lsb to 0 msb */
|
||||
new = 0;
|
||||
for (j = 0; j <= 5; j++) {
|
||||
new |= old & 01; /* copy a bit */
|
||||
if (j < 5) {
|
||||
/* rotate in opposite directions */
|
||||
old = old >> 1;
|
||||
new = new << 1;
|
||||
}
|
||||
}
|
||||
return new;
|
||||
}
|
||||
|
||||
afs_uint32
|
||||
swap_four_bits_to_ansi(afs_uint32 old)
|
||||
{
|
||||
afs_uint32 new, j;
|
||||
|
||||
/* flips the bit order within each byte from 0 lsb to 0 msb */
|
||||
new = 0;
|
||||
for (j = 0; j <= 3; j++) {
|
||||
new |= (old & 01); /* copy a bit */
|
||||
if (j < 3) {
|
||||
old = old >> 1;
|
||||
new = new << 1;
|
||||
}
|
||||
}
|
||||
return new;
|
||||
}
|
||||
|
||||
afs_uint32
|
||||
swap_bit_pos_1(afs_uint32 x)
|
||||
{
|
||||
/*
|
||||
* This corrects for the bit ordering of the algorithm, e.g.
|
||||
* bit 0 ==> msb, bit 7 lsb.
|
||||
*
|
||||
* given the number of a bit position, >=1, flips the bit order
|
||||
* each byte. e.g. bit 3 --> bit 6, bit 13 --> bit 12
|
||||
*/
|
||||
int y, z;
|
||||
|
||||
/* always do it, only used by des_make_key_perm.c so far */
|
||||
y = (x - 1) / 8;
|
||||
z = (x - 1) % 8;
|
||||
|
||||
x = (8 - z) + (y * 8);
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
afs_uint32
|
||||
swap_bit_pos_0(afs_uint32 x)
|
||||
{
|
||||
/* zero based version */
|
||||
|
||||
/*
|
||||
* This corrects for the bit ordering of the algorithm, e.g.
|
||||
* bit 0 ==> msb, bit 7 lsb.
|
||||
*/
|
||||
|
||||
#ifdef MSBFIRST
|
||||
return x;
|
||||
#else /* LSBFIRST */
|
||||
int y, z;
|
||||
|
||||
/*
|
||||
* given the number of a bit position, >=0, flips the bit order
|
||||
* each byte. e.g. bit 3 --> bit 6, bit 13 --> bit 12
|
||||
*/
|
||||
y = x / 8;
|
||||
z = x % 8;
|
||||
|
||||
x = (7 - z) + (y * 8);
|
||||
|
||||
return x;
|
||||
#endif /* LSBFIRST */
|
||||
}
|
||||
|
||||
afs_uint32
|
||||
swap_bit_pos_0_to_ansi(afs_uint32 x)
|
||||
{
|
||||
/* zero based version */
|
||||
|
||||
/*
|
||||
* This corrects for the bit ordering of the algorithm, e.g.
|
||||
* bit 0 ==> msb, bit 7 lsb.
|
||||
*/
|
||||
|
||||
int y, z;
|
||||
/*
|
||||
* given the number of a bit position, >=0, flips the bit order each
|
||||
* byte. e.g. bit 3 --> bit 6, bit 13 --> bit 12
|
||||
*/
|
||||
y = x / 8;
|
||||
z = x % 8;
|
||||
|
||||
x = (7 - z) + (y * 8);
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
afs_uint32
|
||||
rev_swap_bit_pos_0(afs_uint32 x)
|
||||
{
|
||||
/* zero based version */
|
||||
|
||||
/*
|
||||
* This corrects for the bit ordering of the algorithm, e.g.
|
||||
* bit 0 ==> msb, bit 7 lsb.
|
||||
*
|
||||
* Role of LSB and MSB flipped from the swap_bit_pos_0()
|
||||
*/
|
||||
|
||||
#ifdef LSBFIRST
|
||||
return x;
|
||||
#else /* MSBFIRST */
|
||||
|
||||
int y, z;
|
||||
|
||||
/*
|
||||
* given the number of a bit position, >=0, flips the bit order each
|
||||
* byte. e.g. bit 3 --> bit 6, bit 13 --> bit 12
|
||||
*/
|
||||
y = x / 8;
|
||||
z = x % 8;
|
||||
|
||||
x = (7 - z) + (y * 8);
|
||||
|
||||
return x;
|
||||
#endif /* MSBFIRST */
|
||||
}
|
||||
|
||||
afs_uint32
|
||||
swap_byte_bits(afs_uint32 x)
|
||||
{
|
||||
#ifdef MSBFIRST
|
||||
return x;
|
||||
#else /* LSBFIRST */
|
||||
|
||||
char *array = (char *)&x;
|
||||
afs_uint32 old, new, j;
|
||||
|
||||
/* flips the bit order within each byte from 0 lsb to 0 msb */
|
||||
old = *array;
|
||||
new = 0;
|
||||
for (j = 0; j <= 7; j++) {
|
||||
new |= (old & 01); /* copy a bit */
|
||||
if (j < 7) {
|
||||
old = old >> 1;
|
||||
new = new << 1;
|
||||
}
|
||||
}
|
||||
return new;
|
||||
#endif /* LSBFIRST */
|
||||
}
|
||||
|
||||
int
|
||||
swap_long_bytes_bit_number(afs_uint32 x)
|
||||
{
|
||||
/*
|
||||
* given a bit number (0-31) from a vax, swap the byte part of the
|
||||
* bit number to change the byte ordering to mSBFIRST type
|
||||
*/
|
||||
#ifdef LSBFIRST
|
||||
return x;
|
||||
#else /* MSBFIRST */
|
||||
afs_uint32 y, z;
|
||||
|
||||
y = x / 8; /* initial byte component */
|
||||
z = x % 8; /* bit within byte */
|
||||
|
||||
x = (3 - y) * 8 + z;
|
||||
return x;
|
||||
#endif /* MSBFIRST */
|
||||
}
|
||||
|
||||
#if !defined(KERNEL) && defined(AFS_DARWIN80_ENV)
|
||||
char *_darwin_whichstr[] = {
|
||||
"#if defined(__ppc__) || defined(__ppc64__)\n",
|
||||
"#elif defined(__i386__) || defined(__amd64__) || defined(__arm__)\n",
|
||||
"#else\n#error architecture unsupported\n#endif\n"
|
||||
};
|
||||
int _darwin_which = 1;
|
||||
|
||||
int
|
||||
_darwin_swap_long_bytes_bit_number(afs_uint32 x)
|
||||
{
|
||||
/*
|
||||
* given a bit number (0-31) from a vax, swap the byte part of the
|
||||
* bit number to change the byte ordering to mSBFIRST type
|
||||
*/
|
||||
|
||||
afs_uint32 y, z;
|
||||
|
||||
if (!_darwin_which)
|
||||
return x;
|
||||
|
||||
y = x / 8; /* initial byte component */
|
||||
z = x % 8; /* bit within byte */
|
||||
|
||||
x = (3 - y) * 8 + z;
|
||||
return x;
|
||||
}
|
||||
#endif /* !KERNEL && AFS_DARWIN80_ENV */
|
||||
|
||||
void
|
||||
test_set(FILE * stream, const char *src, int testbit, const char *dest,
|
||||
int setbit)
|
||||
{
|
||||
#ifdef DES_SHIFT_SHIFT
|
||||
if (testbit == setbit)
|
||||
fprintf(stream, " %s |= %s & (1<<%2d);\n", dest, src, testbit);
|
||||
else
|
||||
fprintf(stream, " %s |= (%s & (1<<%2d)) %s %2d;\n", dest, src,
|
||||
testbit, (testbit < setbit) ? "<<" : ">>",
|
||||
abs(testbit - setbit));
|
||||
#else
|
||||
fprintf(stream, " if (%s & (1<<%2d)) %s |= 1<<%2d;\n", src, testbit,
|
||||
dest, setbit);
|
||||
#endif
|
||||
}
|
@ -1 +0,0 @@
|
||||
/* All rights reserved. */
|
@ -1,282 +0,0 @@
|
||||
/*
|
||||
* Copyright 1988 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <mit-cpyright.h>.
|
||||
*
|
||||
* New pseudo-random key generator, using DES encryption to make the
|
||||
* pseudo-random cycle as hard to break as DES.
|
||||
*
|
||||
* Written by Mark Lillibridge, MIT Project Athena
|
||||
*
|
||||
* Under U.S. law, this software may not be exported outside the US
|
||||
* without license from the U.S. Commerce department.
|
||||
*/
|
||||
|
||||
#include "mit-cpyright.h"
|
||||
|
||||
#include <afsconfig.h>
|
||||
#include <afs/param.h>
|
||||
|
||||
|
||||
#ifndef KERNEL
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
#include "des.h"
|
||||
#include "des_internal.h"
|
||||
#include "des_prototypes.h"
|
||||
|
||||
#ifdef AFS_PTHREAD_ENV
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#else
|
||||
#ifdef HAVE_STRINGS_H
|
||||
#include <strings.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static afs_int32 des_set_sequence_number(des_cblock new_sequence_number);
|
||||
static afs_int32 des_generate_random_block(des_cblock block);
|
||||
|
||||
#define XPRT_NEW_RND_KEY
|
||||
|
||||
static int is_inited = 0;
|
||||
#ifdef AFS_PTHREAD_ENV
|
||||
/*
|
||||
* This mutex protects the following global variables:
|
||||
* is_inited
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
pthread_mutex_t des_init_mutex
|
||||
#ifdef PTHREAD_MUTEX_INITIALIZER
|
||||
= PTHREAD_MUTEX_INITIALIZER
|
||||
#endif
|
||||
;
|
||||
#define LOCK_INIT assert(pthread_mutex_lock(&des_init_mutex)==0)
|
||||
#define UNLOCK_INIT assert(pthread_mutex_unlock(&des_init_mutex)==0)
|
||||
#else
|
||||
#define LOCK_INIT
|
||||
#define UNLOCK_INIT
|
||||
#endif
|
||||
/*
|
||||
* des_random_key: create a random des key
|
||||
*
|
||||
* You should call des_set_random_number_generater_seed at least
|
||||
* once before this routine is called. If you haven't, I'll try
|
||||
* to add a little randomness to the start point anyway. Yes,
|
||||
* it recurses. Deal with it.
|
||||
*
|
||||
* Notes: the returned key has correct parity and is guarenteed not
|
||||
* to be a weak des key. Des_generate_random_block is used to
|
||||
* provide the random bits.
|
||||
*/
|
||||
int
|
||||
des_random_key(des_cblock key)
|
||||
{
|
||||
LOCK_INIT;
|
||||
if (!is_inited) {
|
||||
des_init_random_number_generator(key);
|
||||
}
|
||||
UNLOCK_INIT;
|
||||
do {
|
||||
des_generate_random_block(key);
|
||||
des_fixup_key_parity(key);
|
||||
} while (des_is_weak_key(key));
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* des_init_random_number_generator:
|
||||
*
|
||||
* This routine takes a secret key possibly shared by a number
|
||||
* of servers and uses it to generate a random number stream that is
|
||||
* not shared by any of the other servers. It does this by using the current
|
||||
* process id, host id, and the current time to the nearest second. The
|
||||
* resulting stream seed is not useful information for cracking the secret
|
||||
* key. Moreover, this routine keeps no copy of the secret key.
|
||||
* This routine is used for example, by the kerberos server(s) with the
|
||||
* key in question being the kerberos master key.
|
||||
*
|
||||
* Note: this routine calls des_set_random_generator_seed.
|
||||
*/
|
||||
#if !defined(BSDUNIX) && !defined(AFS_SGI_ENV) && !defined(AFS_NT40_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV)
|
||||
you lose ... (aka, you get to implement an analog of this for your system ...)
|
||||
#else
|
||||
|
||||
#ifdef AFS_NT40_ENV
|
||||
#include <winsock2.h>
|
||||
#include <process.h>
|
||||
#include <afs/afsutil.h>
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
void
|
||||
des_init_random_number_generator(des_cblock key)
|
||||
{
|
||||
struct { /* This must be 64 bits exactly */
|
||||
afs_int32 process_id;
|
||||
afs_int32 host_id;
|
||||
} seed;
|
||||
struct timeval time; /* this must also be 64 bits exactly */
|
||||
des_cblock new_key;
|
||||
|
||||
is_inited = 1;
|
||||
/*
|
||||
* use a host id and process id in generating the seed to ensure
|
||||
* that different servers have different streams:
|
||||
*/
|
||||
#if !defined(AFS_HPUX_ENV) && !defined(AFS_NT40_ENV)
|
||||
seed.host_id = gethostid();
|
||||
#endif
|
||||
seed.process_id = getpid();
|
||||
|
||||
/*
|
||||
* Generate a tempory value that depends on the key, host_id, and
|
||||
* process_id such that it gives no useful information about the key:
|
||||
*/
|
||||
des_set_random_generator_seed(key);
|
||||
des_set_sequence_number((unsigned char *)&seed);
|
||||
des_random_key(new_key);
|
||||
|
||||
/*
|
||||
* use it to select a random stream:
|
||||
*/
|
||||
des_set_random_generator_seed(new_key);
|
||||
|
||||
/*
|
||||
* use a time stamp to ensure that a server started later does not reuse
|
||||
* an old stream:
|
||||
*/
|
||||
gettimeofday(&time, NULL);
|
||||
des_set_sequence_number((unsigned char *)&time);
|
||||
|
||||
/*
|
||||
* use the time stamp finally to select the final seed using the
|
||||
* current random number stream:
|
||||
*/
|
||||
des_random_key(new_key);
|
||||
des_set_random_generator_seed(new_key);
|
||||
}
|
||||
|
||||
#endif /* ifdef BSDUNIX */
|
||||
|
||||
/*
|
||||
* This module implements a random number generator faculty such that the next
|
||||
* number in any random number stream is very hard to predict without knowing
|
||||
* the seed for that stream even given the preceeding random numbers.
|
||||
*/
|
||||
|
||||
/*
|
||||
* The secret des key schedule for the current stream of random numbers:
|
||||
*/
|
||||
static union {
|
||||
afs_int32 align;
|
||||
des_key_schedule d;
|
||||
} random_sequence_key;
|
||||
|
||||
/*
|
||||
* The sequence # in the current stream of random numbers:
|
||||
*/
|
||||
static unsigned char sequence_number[8];
|
||||
|
||||
#ifdef AFS_PTHREAD_ENV
|
||||
/*
|
||||
* This mutex protects the following global variables:
|
||||
* random_sequence_key
|
||||
* sequence_number
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
pthread_mutex_t des_random_mutex
|
||||
#ifdef PTHREAD_MUTEX_INITIALIZER
|
||||
= PTHREAD_MUTEX_INITIALIZER
|
||||
#endif
|
||||
;
|
||||
#define LOCK_RANDOM assert(pthread_mutex_lock(&des_random_mutex)==0)
|
||||
#define UNLOCK_RANDOM assert(pthread_mutex_unlock(&des_random_mutex)==0)
|
||||
#else
|
||||
#define LOCK_RANDOM
|
||||
#define UNLOCK_RANDOM
|
||||
#endif
|
||||
|
||||
/*
|
||||
* des_set_random_generator_seed: this routine is used to select a random
|
||||
* number stream. The stream that results is
|
||||
* totally determined by the passed in key.
|
||||
* (I.e., calling this routine again with the
|
||||
* same key allows repeating a sequence of
|
||||
* random numbers)
|
||||
*
|
||||
* Requires: key is a valid des key. I.e., has correct parity and is not a
|
||||
* weak des key.
|
||||
*/
|
||||
void
|
||||
des_set_random_generator_seed(des_cblock key)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* select the new stream: (note errors are not possible here...) */
|
||||
LOCK_RANDOM;
|
||||
des_key_sched(key, random_sequence_key.d);
|
||||
|
||||
/* "seek" to the start of the stream: */
|
||||
for (i = 0; i < 8; i++)
|
||||
sequence_number[i] = 0;
|
||||
UNLOCK_RANDOM;
|
||||
}
|
||||
|
||||
/*
|
||||
* des_set_sequence_number: this routine is used to set the sequence number
|
||||
* of the current random number stream. This routine
|
||||
* may be used to "seek" within the current random
|
||||
* number stream.
|
||||
*
|
||||
* Note that des_set_random_generator_seed resets the sequence number to 0.
|
||||
*/
|
||||
static afs_int32
|
||||
des_set_sequence_number(des_cblock new_sequence_number)
|
||||
{
|
||||
LOCK_RANDOM;
|
||||
memcpy((char *)sequence_number, (char *)new_sequence_number,
|
||||
sizeof(sequence_number));
|
||||
UNLOCK_RANDOM;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* des_generate_random_block: routine to return the next random number
|
||||
* from the current random number stream.
|
||||
* The returned number is 64 bits long.
|
||||
*
|
||||
* Requires: des_set_random_generator_seed must have been called at least once
|
||||
* before this routine is called.
|
||||
*/
|
||||
static afs_int32
|
||||
des_generate_random_block(des_cblock block)
|
||||
{
|
||||
int i;
|
||||
|
||||
/*
|
||||
* Encrypt the sequence number to get the new random block:
|
||||
*/
|
||||
LOCK_RANDOM;
|
||||
des_ecb_encrypt(sequence_number, block, random_sequence_key.d, 1);
|
||||
|
||||
/*
|
||||
* Increment the sequence number as an 8 byte unsigned number with wrap:
|
||||
* (using LSB here)
|
||||
*/
|
||||
for (i = 0; i < 8; i++) {
|
||||
sequence_number[i] = (sequence_number[i] + 1) & 0xff;
|
||||
if (sequence_number[i])
|
||||
break;
|
||||
}
|
||||
UNLOCK_RANDOM;
|
||||
return 0;
|
||||
}
|
@ -1,249 +0,0 @@
|
||||
/*
|
||||
* Copyright 1985, 1986, 1987, 1988 by the Massachusetts Institute
|
||||
* of Technology.
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <mit-cpyright.h>.
|
||||
*
|
||||
* These routines perform encryption and decryption using the DES
|
||||
* private key algorithm, or else a subset of it-- fewer inner loops.
|
||||
* ( AUTH_DES_ITER defaults to 16, may be less)
|
||||
*
|
||||
* Under U.S. law, this software may not be exported outside the US
|
||||
* without license from the U.S. Commerce department.
|
||||
*
|
||||
* The key schedule is passed as an arg, as well as the cleartext or
|
||||
* ciphertext. The cleartext and ciphertext should be in host order.
|
||||
*
|
||||
* These routines form the library interface to the des facilities.
|
||||
*
|
||||
* spm 8/85 MIT project athena
|
||||
*/
|
||||
|
||||
#include "mit-cpyright.h"
|
||||
#ifndef KERNEL
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#endif
|
||||
#include <afsconfig.h>
|
||||
#include <afs/param.h>
|
||||
#include "des.h"
|
||||
#include "des_prototypes.h"
|
||||
|
||||
|
||||
#include "des_internal.h"
|
||||
|
||||
#define XPRT_PCBC_ENCRYPT
|
||||
|
||||
/*
|
||||
* pcbc_encrypt is an "error propagation chaining" encrypt operation
|
||||
* for DES, similar to CBC, but that, on encryption, "xor"s the
|
||||
* plaintext of block N with the ciphertext resulting from block N,
|
||||
* then "xor"s that result with the plaintext of block N+1 prior to
|
||||
* encrypting block N+1. (decryption the appropriate inverse. This
|
||||
* "pcbc" mode propagates a single bit error anywhere in either the
|
||||
* cleartext or ciphertext chain all the way through to the end. In
|
||||
* contrast, CBC mode limits a single bit error in the ciphertext to
|
||||
* affect only the current (8byte) block and the subsequent block.
|
||||
*
|
||||
* performs pcbc error-propagation chaining operation by xor-ing block
|
||||
* N+1 with both the plaintext (block N) and the ciphertext from block
|
||||
* N. Either encrypts from cleartext to ciphertext, if encrypt != 0
|
||||
* or decrypts from ciphertext to cleartext, if encrypt == 0
|
||||
*
|
||||
* NOTE-- the output is ALWAYS an multiple of 8 bytes long. If not
|
||||
* enough space was provided, your program will get trashed.
|
||||
*
|
||||
* For encryption, the cleartext string is null padded, at the end, to
|
||||
* an integral multiple of eight bytes.
|
||||
*
|
||||
* For decryption, the ciphertext will be used in integral multiples
|
||||
* of 8 bytes, but only the first "length" bytes returned into the
|
||||
* cleartext.
|
||||
*
|
||||
* This is NOT a standard mode of operation.
|
||||
*
|
||||
*/
|
||||
/*
|
||||
des_cblock *in; * >= length bytes of input text *
|
||||
des_cblock *out; * >= length bytes of output text *
|
||||
afs_int32 length; * in bytes *
|
||||
int encrypt; * 0 ==> decrypt, else encrypt *
|
||||
des_key_schedule key; * precomputed key schedule *
|
||||
des_cblock *iv; * 8 bytes of ivec *
|
||||
*/
|
||||
afs_int32
|
||||
des_pcbc_encrypt(void * in, void * out, afs_int32 length,
|
||||
des_key_schedule key, des_cblock * iv, int encrypt)
|
||||
{
|
||||
afs_uint32 *input = (afs_uint32 *) in;
|
||||
afs_uint32 *output = (afs_uint32 *) out;
|
||||
afs_uint32 *ivec = (afs_uint32 *) iv;
|
||||
|
||||
afs_uint32 i, j;
|
||||
afs_uint32 t_input[2];
|
||||
afs_uint32 t_output[2];
|
||||
unsigned char *t_in_p = (unsigned char *)t_input;
|
||||
afs_uint32 xor_0, xor_1;
|
||||
|
||||
if (encrypt) {
|
||||
#ifdef MUSTALIGN
|
||||
if (afs_pointer_to_int(ivec) & 3) {
|
||||
memcpy((char *)&xor_0, (char *)ivec++, sizeof(xor_0));
|
||||
memcpy((char *)&xor_1, (char *)ivec, sizeof(xor_1));
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
xor_0 = *ivec++;
|
||||
xor_1 = *ivec;
|
||||
}
|
||||
|
||||
for (i = 0; length > 0; i++, length -= 8) {
|
||||
/* get input */
|
||||
#ifdef MUSTALIGN
|
||||
if (afs_pointer_to_int(input) & 3) {
|
||||
memcpy((char *)&t_input[0], (char *)input,
|
||||
sizeof(t_input[0]));
|
||||
memcpy((char *)&t_input[1], (char *)(input + 1),
|
||||
sizeof(t_input[1]));
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
t_input[0] = *input;
|
||||
t_input[1] = *(input + 1);
|
||||
}
|
||||
|
||||
/* zero pad */
|
||||
if (length < 8) {
|
||||
for (j = length; j <= 7; j++)
|
||||
*(t_in_p + j) = 0;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
if (des_debug)
|
||||
des_debug_print("clear", length, t_input[0], t_input[1]);
|
||||
#endif
|
||||
/* do the xor for cbc into the temp */
|
||||
t_input[0] ^= xor_0;
|
||||
t_input[1] ^= xor_1;
|
||||
/* encrypt */
|
||||
(void)des_ecb_encrypt(t_input, t_output, key, encrypt);
|
||||
|
||||
/*
|
||||
* We want to XOR with both the plaintext and ciphertext
|
||||
* of the previous block, before we write the output, in
|
||||
* case both input and output are the same space.
|
||||
*/
|
||||
#ifdef MUSTALIGN
|
||||
if (afs_pointer_to_int(input) & 3) {
|
||||
memcpy((char *)&xor_0, (char *)input++, sizeof(xor_0));
|
||||
xor_0 ^= t_output[0];
|
||||
memcpy((char *)&xor_1, (char *)input++, sizeof(xor_1));
|
||||
xor_1 ^= t_output[1];
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
xor_0 = *input++ ^ t_output[0];
|
||||
xor_1 = *input++ ^ t_output[1];
|
||||
}
|
||||
|
||||
|
||||
/* copy temp output and save it for cbc */
|
||||
#ifdef MUSTALIGN
|
||||
if (afs_pointer_to_int(output) & 3) {
|
||||
memcpy((char *)output++, (char *)&t_output[0],
|
||||
sizeof(t_output[0]));
|
||||
memcpy((char *)output++, (char *)&t_output[1],
|
||||
sizeof(t_output[1]));
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
*output++ = t_output[0];
|
||||
*output++ = t_output[1];
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
if (des_debug) {
|
||||
des_debug_print("xor'ed", i, t_input[0], t_input[1]);
|
||||
des_debug_print("cipher", i, t_output[0], t_output[1]);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
t_output[0] = 0;
|
||||
t_output[1] = 0;
|
||||
xor_0 = 0;
|
||||
xor_1 = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
else {
|
||||
/* decrypt */
|
||||
#ifdef MUSTALIGN
|
||||
if (afs_pointer_to_int(ivec) & 3) {
|
||||
memcpy((char *)&xor_0, (char *)ivec++, sizeof(xor_0));
|
||||
memcpy((char *)&xor_1, (char *)ivec, sizeof(xor_1));
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
xor_0 = *ivec++;
|
||||
xor_1 = *ivec;
|
||||
}
|
||||
|
||||
for (i = 0; length > 0; i++, length -= 8) {
|
||||
/* get input */
|
||||
#ifdef MUSTALIGN
|
||||
if (afs_pointer_to_int(input) & 3) {
|
||||
memcpy((char *)&t_input[0], (char *)input++,
|
||||
sizeof(t_input[0]));
|
||||
memcpy((char *)&t_input[1], (char *)input++,
|
||||
sizeof(t_input[1]));
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
t_input[0] = *input++;
|
||||
t_input[1] = *input++;
|
||||
}
|
||||
|
||||
/* no padding for decrypt */
|
||||
#ifdef DEBUG
|
||||
if (des_debug)
|
||||
des_debug_print("cipher", i, t_input[0], t_input[1]);
|
||||
#else
|
||||
#ifdef lint
|
||||
i = i;
|
||||
#endif
|
||||
#endif
|
||||
/* encrypt */
|
||||
(void)des_ecb_encrypt(t_input, t_output, key, encrypt);
|
||||
#ifdef DEBUG
|
||||
if (des_debug)
|
||||
des_debug_print("out pre xor", i, t_output[0], t_output[1]);
|
||||
#endif
|
||||
/* do the xor for cbc into the output */
|
||||
t_output[0] ^= xor_0;
|
||||
t_output[1] ^= xor_1;
|
||||
/* copy temp output */
|
||||
#ifdef MUSTALIGN
|
||||
if (afs_pointer_to_int(output) & 3) {
|
||||
memcpy((char *)output++, (char *)&t_output[0],
|
||||
sizeof(t_output[0]));
|
||||
memcpy((char *)output++, (char *)&t_output[1],
|
||||
sizeof(t_output[1]));
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
*output++ = t_output[0];
|
||||
*output++ = t_output[1];
|
||||
}
|
||||
|
||||
/* save xor value for next round */
|
||||
xor_0 = t_output[0] ^ t_input[0];
|
||||
xor_1 = t_output[1] ^ t_input[1];
|
||||
|
||||
#ifdef DEBUG
|
||||
if (des_debug)
|
||||
des_debug_print("clear", i, t_output[0], t_output[1]);
|
||||
#endif
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -1,191 +0,0 @@
|
||||
/*
|
||||
* Copyright 1985, 1986, 1987, 1988 by the Massachusetts Institute
|
||||
* of Technology.
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <mit-cpyright.h>.
|
||||
*
|
||||
* Quadratic Congruential Manipulation Dectection Code
|
||||
*
|
||||
* ref: "Message Authentication"
|
||||
* R.R. Jueneman, S. M. Matyas, C.H. Meyer
|
||||
* IEEE Communications Magazine,
|
||||
* Sept 1985 Vol 23 No 9 p 29-40
|
||||
*
|
||||
* This routine, part of the Athena DES library built for the Kerberos
|
||||
* authentication system, calculates a manipulation detection code for
|
||||
* a message. It is a much faster alternative to the DES-checksum
|
||||
* method. No guarantees are offered for its security. Refer to the
|
||||
* paper noted above for more information
|
||||
*
|
||||
* Implementation for 4.2bsd
|
||||
* by S.P. Miller Project Athena/MIT
|
||||
*/
|
||||
|
||||
/*
|
||||
* Algorithm (per paper):
|
||||
* define:
|
||||
* message to be composed of n m-bit blocks X1,...,Xn
|
||||
* optional secret seed S in block X1
|
||||
* MDC in block Xn+1
|
||||
* prime modulus N
|
||||
* accumulator Z
|
||||
* initial (secret) value of accumulator C
|
||||
* N, C, and S are known at both ends
|
||||
* C and , optionally, S, are hidden from the end users
|
||||
* then
|
||||
* (read array references as subscripts over time)
|
||||
* Z[0] = c;
|
||||
* for i = 1...n
|
||||
* Z[i] = (Z[i+1] + X[i])**2 modulo N
|
||||
* X[n+1] = Z[n] = MDC
|
||||
*
|
||||
* Then pick
|
||||
* N = 2**31 -1
|
||||
* m = 16
|
||||
* iterate 4 times over plaintext, also use Zn
|
||||
* from iteration j as seed for iteration j+1,
|
||||
* total MDC is then a 128 bit array of the four
|
||||
* Zn;
|
||||
*
|
||||
* return the last Zn and optionally, all
|
||||
* four as output args.
|
||||
*
|
||||
* Modifications:
|
||||
* To inhibit brute force searches of the seed space, this
|
||||
* implementation is modified to have
|
||||
* Z = 64 bit accumulator
|
||||
* C = 64 bit C seed
|
||||
* N = 2**63 - 1
|
||||
* S = S seed is not implemented here
|
||||
* arithmetic is not quite real double integer precision, since we
|
||||
* cant get at the carry or high order results from multiply,
|
||||
* but nontheless is 64 bit arithmetic.
|
||||
*/
|
||||
|
||||
#include <afsconfig.h>
|
||||
#include <afs/param.h>
|
||||
#include <afs/stds.h>
|
||||
|
||||
|
||||
#include "mit-cpyright.h"
|
||||
|
||||
/* System include files */
|
||||
#ifndef KERNEL
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
#include <errno.h>
|
||||
|
||||
/* Application include files */
|
||||
#include "des.h"
|
||||
#include "des_internal.h"
|
||||
#include "des_prototypes.h"
|
||||
|
||||
/* Definitions for byte swapping */
|
||||
|
||||
#ifdef LSBFIRST
|
||||
#define vaxtohl(x) (*((afs_uint32 *)(x)))
|
||||
#define vaxtohs(x) (*((unsigned short *)(x)))
|
||||
#else
|
||||
#define vaxtohl(x) four_bytes_vax_to_nets((char *)(x))
|
||||
#define vaxtohs(x) two_bytes_vax_to_nets((char *)(x))
|
||||
#endif
|
||||
|
||||
/*** Routines ***************************************************** */
|
||||
|
||||
#ifdef MSBFIRST
|
||||
|
||||
static unsigned short
|
||||
two_bytes_vax_to_nets(char *p)
|
||||
{
|
||||
union {
|
||||
char pieces[2];
|
||||
unsigned short result;
|
||||
} short_conv;
|
||||
|
||||
short_conv.pieces[0] = p[1];
|
||||
short_conv.pieces[1] = p[0];
|
||||
return (short_conv.result);
|
||||
}
|
||||
|
||||
static afs_uint32
|
||||
four_bytes_vax_to_nets(char *p)
|
||||
{
|
||||
union {
|
||||
char pieces[4];
|
||||
afs_uint32 result;
|
||||
} long_conv;
|
||||
|
||||
long_conv.pieces[0] = p[3];
|
||||
long_conv.pieces[1] = p[2];
|
||||
long_conv.pieces[2] = p[1];
|
||||
long_conv.pieces[3] = p[0];
|
||||
return (long_conv.result);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
des_cblock *c_seed; * secret seed, 8 bytes *
|
||||
unsigned char *in; * input block *
|
||||
afs_uint32 *out; * optional longer output *
|
||||
int out_count; * number of iterations *
|
||||
afs_int32 length; * original length in bytes *
|
||||
*/
|
||||
|
||||
afs_uint32
|
||||
des_quad_cksum(unsigned char *in, afs_uint32 * out, afs_int32 length,
|
||||
int out_count, des_cblock * c_seed)
|
||||
{
|
||||
|
||||
/*
|
||||
* this routine both returns the low order of the final (last in
|
||||
* time) 32bits of the checksum, and if "out" is not a null
|
||||
* pointer, a longer version, up to entire 32 bytes of the
|
||||
* checksum is written unto the address pointed to.
|
||||
*/
|
||||
|
||||
afs_uint32 z;
|
||||
afs_uint32 z2;
|
||||
afs_uint32 x;
|
||||
afs_uint32 x2;
|
||||
unsigned char *p;
|
||||
afs_int32 len;
|
||||
int i;
|
||||
|
||||
/* use all 8 bytes of seed */
|
||||
|
||||
z = vaxtohl(c_seed);
|
||||
z2 = vaxtohl((char *)c_seed + 4);
|
||||
if (out == NULL)
|
||||
out_count = 1; /* default */
|
||||
|
||||
/* This is repeated n times!! */
|
||||
for (i = 1; i <= 4 && i <= out_count; i++) {
|
||||
len = length;
|
||||
p = in;
|
||||
while (len) {
|
||||
if (len > 1) {
|
||||
x = (z + vaxtohs(p));
|
||||
p += 2;
|
||||
len -= 2;
|
||||
} else {
|
||||
x = (z + *(char *)p++);
|
||||
len = 0;
|
||||
}
|
||||
x2 = z2;
|
||||
z = ((x * x) + (x2 * x2)) % 0x7fffffff;
|
||||
z2 = (x * (x2 + 83653421)) % 0x7fffffff; /* modulo */
|
||||
if (des_debug & 8)
|
||||
printf("%ld %ld\n", afs_printable_int32_ld(z),
|
||||
afs_printable_int32_ld(z2));
|
||||
}
|
||||
|
||||
if (out != NULL) {
|
||||
*out++ = z;
|
||||
*out++ = z2;
|
||||
}
|
||||
}
|
||||
/* return final z value as 32 bit version of checksum */
|
||||
return z;
|
||||
}
|
@ -1,402 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 1985, 1986, 1987, 1988 by the Massachusetts Institute
|
||||
* of Technology.
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <mit-cpyright.h>.
|
||||
*
|
||||
* This routine prints the supplied string to standard
|
||||
* output as a prompt, and reads a password string without
|
||||
* echoing.
|
||||
*/
|
||||
|
||||
#include <afsconfig.h>
|
||||
#include <afs/param.h>
|
||||
|
||||
|
||||
#include "mit-cpyright.h"
|
||||
#include "des.h"
|
||||
#include "conf.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#else
|
||||
#ifdef HAVE_STRINGS_H
|
||||
#include <strings.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef BSDUNIX
|
||||
#ifdef AFS_SUN5_ENV
|
||||
#define BSD_COMP
|
||||
#endif
|
||||
#include <sys/ioctl.h>
|
||||
#include <signal.h>
|
||||
#include <setjmp.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SIGNAL_H
|
||||
#include <signal.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifdef AFS_HPUX_ENV
|
||||
#include <bsdtty.h>
|
||||
#include <sys/ttold.h>
|
||||
#include <termios.h>
|
||||
static int intrupt;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_TERMIOS_H
|
||||
#include <termios.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_WINDOWS_H
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
static int intrupt;
|
||||
#if defined(AFS_SGI_ENV) || defined (AFS_AIX_ENV) || defined(AFS_XBSD_ENV) /*|| defined (AFS_HPUX_ENV) || defined(AFS_SUN5_ENV) */
|
||||
#undef BSDUNIX
|
||||
#endif
|
||||
|
||||
#ifdef BSDUNIX
|
||||
static jmp_buf env;
|
||||
#endif
|
||||
|
||||
#ifdef BSDUNIX
|
||||
#define POSIX
|
||||
#ifdef POSIX
|
||||
typedef void sigtype;
|
||||
#else
|
||||
typedef int sigtype;
|
||||
#endif
|
||||
static sigtype sig_restore();
|
||||
static push_signals(), pop_signals();
|
||||
#endif
|
||||
|
||||
#include "des_prototypes.h"
|
||||
|
||||
/*** Routines ****************************************************** */
|
||||
int
|
||||
des_read_password(des_cblock * k, char *prompt, int verify)
|
||||
{
|
||||
int ok;
|
||||
char key_string[BUFSIZ];
|
||||
|
||||
#ifdef BSDUNIX
|
||||
if (setjmp(env)) {
|
||||
ok = -1;
|
||||
goto lose;
|
||||
}
|
||||
#endif
|
||||
|
||||
ok = des_read_pw_string(key_string, BUFSIZ, prompt, verify);
|
||||
if (ok == 0)
|
||||
des_string_to_key(key_string, k);
|
||||
|
||||
#ifdef BSDUNIX
|
||||
lose:
|
||||
#endif
|
||||
memset(key_string, 0, sizeof(key_string));
|
||||
return ok;
|
||||
}
|
||||
|
||||
#if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV) || defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
|
||||
static void catch(int);
|
||||
#endif
|
||||
|
||||
#if !defined(BSDUNIX) && (defined(AFS_AIX_ENV) || defined (AFS_HPUX_ENV) || defined(AFS_SGI_ENV) || defined(AFS_LINUX20_ENV))
|
||||
#include <termio.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This version just returns the string, doesn't map to key.
|
||||
*
|
||||
* Returns 0 on success, non-zero on failure.
|
||||
*/
|
||||
int
|
||||
des_read_pw_string(char *s, int maxa, char *prompt, int verify)
|
||||
{
|
||||
int ok = 0, cnt1 = 0;
|
||||
char *ptr;
|
||||
#if defined(AFS_HPUX_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
|
||||
int fno;
|
||||
struct sigaction newsig, oldsig;
|
||||
struct termios save_ttyb, ttyb;
|
||||
#endif
|
||||
#if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
|
||||
FILE *fi;
|
||||
#endif
|
||||
#if defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV)
|
||||
struct termios ttyb;
|
||||
struct sigaction osa, sa;
|
||||
#endif
|
||||
#ifdef BSDUNIX
|
||||
jmp_buf old_env;
|
||||
unsigned long flags;
|
||||
struct sgttyb tty_state, echo_off_tty_state;
|
||||
FILE *fi;
|
||||
#else
|
||||
#if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV) || defined(AFS_SGI_ENV) || defined(AFS_LINUX20_ENV)
|
||||
struct termio ttyb;
|
||||
FILE *fi;
|
||||
char savel, flags;
|
||||
void (*sig) (int);
|
||||
#endif
|
||||
#endif
|
||||
#ifdef AFS_NT40_ENV
|
||||
HANDLE hConStdin;
|
||||
DWORD oldConMode, newConMode;
|
||||
BOOL resetConMode = FALSE;
|
||||
#endif
|
||||
char key_string[BUFSIZ];
|
||||
|
||||
if (maxa > BUFSIZ) {
|
||||
return -1;
|
||||
}
|
||||
#if defined(AFS_HPUX_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
|
||||
if ((fi = fopen("/dev/tty", "r")) == NULL)
|
||||
return -1;
|
||||
setbuf(fi, (char *)NULL); /* We don't want any buffering for our i/o. */
|
||||
/*
|
||||
* Install signal handler for SIGINT so that we can restore
|
||||
* the tty settings after we change them. The handler merely
|
||||
* increments the variable "intrupt" to tell us that an
|
||||
* interrupt signal was received.
|
||||
*/
|
||||
newsig.sa_handler = catch;
|
||||
sigemptyset(&newsig.sa_mask);
|
||||
newsig.sa_flags = 0;
|
||||
sigaction(SIGINT, &newsig, &oldsig);
|
||||
intrupt = 0;
|
||||
|
||||
/*
|
||||
* Get the terminal characters (save for later restoration) and
|
||||
* reset them so that echo is off
|
||||
*/
|
||||
fno = fileno(fi);
|
||||
tcgetattr(fno, &ttyb);
|
||||
save_ttyb = ttyb;
|
||||
ttyb.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
|
||||
tcsetattr(fno, TCSAFLUSH, &ttyb);
|
||||
#else
|
||||
#if defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV)
|
||||
if ((fi = fopen("/dev/tty", "r")) == NULL) {
|
||||
return (-1);
|
||||
} else
|
||||
setbuf(fi, (char *)NULL);
|
||||
sa.sa_handler = catch;
|
||||
sa.sa_mask = 0;
|
||||
sa.sa_flags = SA_INTERRUPT;
|
||||
(void)sigaction(SIGINT, &sa, &osa);
|
||||
intrupt = 0;
|
||||
(void)ioctl(fileno(fi), TCGETS, &ttyb);
|
||||
flags = ttyb.c_lflag;
|
||||
ttyb.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
|
||||
(void)ioctl(fileno(fi), TCSETSF, &ttyb);
|
||||
#else
|
||||
#ifdef BSDUNIX
|
||||
/* XXX assume jmp_buf is typedef'ed to an array */
|
||||
memcpy((char *)env, (char *)old_env, sizeof(env));
|
||||
if (setjmp(env))
|
||||
goto lose;
|
||||
/* save terminal state */
|
||||
if (ioctl(0, TIOCGETP, (char *)&tty_state) == -1)
|
||||
return -1;
|
||||
push_signals();
|
||||
/* Turn off echo */
|
||||
memcpy(&echo_off_tty_state, &tty_state, sizeof(tty_state));
|
||||
echo_off_tty_state.sg_flags &= ~ECHO;
|
||||
if (ioctl(0, TIOCSETP, (char *)&echo_off_tty_state) == -1)
|
||||
return -1;
|
||||
#else
|
||||
#if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV) || defined(AFS_SGI_ENV) || defined(AFS_LINUX20_ENV)
|
||||
if ((fi = fopen("/dev/tty", "r+")) == NULL)
|
||||
return (-1);
|
||||
else
|
||||
setbuf(fi, (char *)NULL);
|
||||
sig = signal(SIGINT, catch);
|
||||
intrupt = 0;
|
||||
(void)ioctl(fileno(fi), TCGETA, &ttyb);
|
||||
savel = ttyb.c_line;
|
||||
ttyb.c_line = 0;
|
||||
flags = ttyb.c_lflag;
|
||||
ttyb.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
|
||||
(void)ioctl(fileno(fi), TCSETAF, &ttyb);
|
||||
#else
|
||||
#ifdef AFS_NT40_ENV
|
||||
/* turn off console input echoing */
|
||||
if ((hConStdin = GetStdHandle(STD_INPUT_HANDLE)) != INVALID_HANDLE_VALUE) {
|
||||
if (GetConsoleMode(hConStdin, &oldConMode)) {
|
||||
newConMode = (oldConMode & ~(ENABLE_ECHO_INPUT));
|
||||
if (SetConsoleMode(hConStdin, newConMode)) {
|
||||
resetConMode = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
while (!ok) {
|
||||
(void)printf("%s", prompt);
|
||||
(void)fflush(stdout);
|
||||
#ifdef CROSSMSDOS
|
||||
h19line(s, sizeof(s), 0);
|
||||
if (!strlen(s))
|
||||
continue;
|
||||
#else
|
||||
if (!fgets(s, maxa, stdin)) {
|
||||
clearerr(stdin);
|
||||
printf("\n");
|
||||
if (cnt1++ > 1) {
|
||||
/*
|
||||
* Otherwise hitting ctrl-d will always leave us inside this loop forever!
|
||||
*/
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if ((ptr = strchr(s, '\n')))
|
||||
*ptr = '\0';
|
||||
#endif
|
||||
if (verify) {
|
||||
printf("\nVerifying, please re-enter %s", prompt);
|
||||
(void)fflush(stdout);
|
||||
#ifdef CROSSMSDOS
|
||||
h19line(key_string, sizeof(key_string), 0);
|
||||
if (!strlen(key_string))
|
||||
continue;
|
||||
#else
|
||||
if (!fgets(key_string, sizeof(key_string), stdin)) {
|
||||
clearerr(stdin);
|
||||
continue;
|
||||
}
|
||||
if ((ptr = strchr(key_string, '\n')))
|
||||
*ptr = '\0';
|
||||
#endif
|
||||
if (strcmp(s, key_string)) {
|
||||
printf("\n\07\07Mismatch - try again\n");
|
||||
(void)fflush(stdout);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
ok = 1;
|
||||
}
|
||||
|
||||
#ifdef BSDUNIX
|
||||
lose:
|
||||
#endif
|
||||
if (!ok)
|
||||
memset(s, 0, maxa);
|
||||
printf("\n");
|
||||
#if defined(AFS_HPUX_ENV) || defined(AFS_XBSD_ENV) || defined(AFS_DARWIN_ENV)
|
||||
/*
|
||||
* Restore the terminal to its previous characteristics.
|
||||
* Restore the old signal handler for SIGINT.
|
||||
*/
|
||||
tcsetattr(fno, TCSANOW, &save_ttyb);
|
||||
sigaction(SIGINT, &oldsig, NULL);
|
||||
if (fi != stdin)
|
||||
fclose(fi);
|
||||
|
||||
/*
|
||||
* If we got a SIGINT while we were doing things, send the SIGINT
|
||||
* to ourselves so that the calling program receives it (since we
|
||||
* were intercepting it for a period of time.)
|
||||
*/
|
||||
if (intrupt)
|
||||
kill(getpid(), SIGINT);
|
||||
#else
|
||||
#if defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV)
|
||||
ttyb.c_lflag = flags;
|
||||
(void)ioctl(fileno(fi), TCSETSW, &ttyb);
|
||||
(void)sigaction(SIGINT, &osa, (struct sigaction *)NULL);
|
||||
if (fi != stdin)
|
||||
(void)fclose(fi);
|
||||
#else
|
||||
#ifdef BSDUNIX
|
||||
if (ioctl(0, TIOCSETP, (char *)&tty_state))
|
||||
ok = 0;
|
||||
pop_signals();
|
||||
memcpy((char *)old_env, (char *)env, sizeof(env));
|
||||
#else
|
||||
#if defined (AFS_AIX_ENV) /*|| defined (AFS_HPUX_ENV)*/ || defined(AFS_SGI_ENV) || defined(AFS_LINUX20_ENV)
|
||||
ttyb.c_lflag = flags;
|
||||
ttyb.c_line = savel;
|
||||
(void)ioctl(fileno(fi), TCSETAW, &ttyb);
|
||||
(void)signal(SIGINT, sig);
|
||||
if (fi != stdin)
|
||||
(void)fclose(fi);
|
||||
if (intrupt)
|
||||
(void)kill(getpid(), SIGINT);
|
||||
#else
|
||||
#ifdef AFS_NT40_ENV
|
||||
/* restore console to original mode settings */
|
||||
if (resetConMode) {
|
||||
(void)SetConsoleMode(hConStdin, oldConMode);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
if (verify)
|
||||
memset(key_string, 0, sizeof(key_string));
|
||||
s[maxa - 1] = 0; /* force termination */
|
||||
return !ok; /* return nonzero if not okay */
|
||||
}
|
||||
|
||||
#ifdef BSDUNIX
|
||||
/*
|
||||
* this can be static since we should never have more than
|
||||
* one set saved....
|
||||
*/
|
||||
#ifdef mips
|
||||
void static (*old_sigfunc[NSIG]) ();
|
||||
#else
|
||||
static sigtype(*old_sigfunc[NSIG]) ();
|
||||
#endif
|
||||
|
||||
static
|
||||
push_signals()
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < NSIG; i++)
|
||||
old_sigfunc[i] = signal(i, sig_restore);
|
||||
}
|
||||
|
||||
static
|
||||
pop_signals()
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < NSIG; i++)
|
||||
(void)signal(i, old_sigfunc[i]);
|
||||
}
|
||||
|
||||
static sigtype
|
||||
sig_restore()
|
||||
{
|
||||
longjmp(env, 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV) || defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
|
||||
static void
|
||||
catch(int junk)
|
||||
{
|
||||
++intrupt;
|
||||
}
|
||||
#endif
|
@ -1,47 +0,0 @@
|
||||
|
||||
/* des_s_tables.h
|
||||
* derived from des_make_s_tables.c
|
||||
*/
|
||||
static unsigned char S_adj[8][64] = /* adjusted */
|
||||
{
|
||||
|
||||
14, 0, 4, 15, 13, 7, 1, 4, 2, 14, 15, 2, 11, 13, 8, 1,
|
||||
3, 10, 10, 6, 6, 12, 12, 11, 5, 9, 9, 5, 0, 3, 7, 8,
|
||||
4, 15, 1, 12, 14, 8, 8, 2, 13, 4, 6, 9, 2, 1, 11, 7,
|
||||
15, 5, 12, 11, 9, 3, 7, 14, 3, 10, 10, 0, 5, 6, 0, 13,
|
||||
|
||||
15, 3, 1, 13, 8, 4, 14, 7, 6, 15, 11, 2, 3, 8, 4, 14,
|
||||
9, 12, 7, 0, 2, 1, 13, 10, 12, 6, 0, 9, 5, 11, 10, 5,
|
||||
0, 13, 14, 8, 7, 10, 11, 1, 10, 3, 4, 15, 13, 4, 1, 2,
|
||||
5, 11, 8, 6, 12, 7, 6, 12, 9, 0, 3, 5, 2, 14, 15, 9,
|
||||
|
||||
10, 13, 0, 7, 9, 0, 14, 9, 6, 3, 3, 4, 15, 6, 5, 10,
|
||||
1, 2, 13, 8, 12, 5, 7, 14, 11, 12, 4, 11, 2, 15, 8, 1,
|
||||
13, 1, 6, 10, 4, 13, 9, 0, 8, 6, 15, 9, 3, 8, 0, 7,
|
||||
11, 4, 1, 15, 2, 14, 12, 3, 5, 11, 10, 5, 14, 2, 7, 12,
|
||||
|
||||
7, 13, 13, 8, 14, 11, 3, 5, 0, 6, 6, 15, 9, 0, 10, 3,
|
||||
1, 4, 2, 7, 8, 2, 5, 12, 11, 1, 12, 10, 4, 14, 15, 9,
|
||||
10, 3, 6, 15, 9, 0, 0, 6, 12, 10, 11, 1, 7, 13, 13, 8,
|
||||
15, 9, 1, 4, 3, 5, 14, 11, 5, 12, 2, 7, 8, 2, 4, 14,
|
||||
|
||||
2, 14, 12, 11, 4, 2, 1, 12, 7, 4, 10, 7, 11, 13, 6, 1,
|
||||
8, 5, 5, 0, 3, 15, 15, 10, 13, 3, 0, 9, 14, 8, 9, 6,
|
||||
4, 11, 2, 8, 1, 12, 11, 7, 10, 1, 13, 14, 7, 2, 8, 13,
|
||||
15, 6, 9, 15, 12, 0, 5, 9, 6, 10, 3, 4, 0, 5, 14, 3,
|
||||
|
||||
12, 10, 1, 15, 10, 4, 15, 2, 9, 7, 2, 12, 6, 9, 8, 5,
|
||||
0, 6, 13, 1, 3, 13, 4, 14, 14, 0, 7, 11, 5, 3, 11, 8,
|
||||
9, 4, 14, 3, 15, 2, 5, 12, 2, 9, 8, 5, 12, 15, 3, 10,
|
||||
7, 11, 0, 14, 4, 1, 10, 7, 1, 6, 13, 0, 11, 8, 6, 13,
|
||||
|
||||
4, 13, 11, 0, 2, 11, 14, 7, 15, 4, 0, 9, 8, 1, 13, 10,
|
||||
3, 14, 12, 3, 9, 5, 7, 12, 5, 2, 10, 15, 6, 8, 1, 6,
|
||||
1, 6, 4, 11, 11, 13, 13, 8, 12, 1, 3, 4, 7, 10, 14, 7,
|
||||
10, 9, 15, 5, 6, 0, 8, 15, 0, 14, 5, 2, 9, 3, 2, 12,
|
||||
|
||||
13, 1, 2, 15, 8, 13, 4, 8, 6, 10, 15, 3, 11, 7, 1, 4,
|
||||
10, 12, 9, 5, 3, 6, 14, 11, 5, 0, 0, 14, 12, 9, 7, 2,
|
||||
7, 2, 11, 1, 4, 14, 1, 7, 9, 4, 12, 10, 14, 8, 2, 13,
|
||||
0, 15, 6, 12, 10, 9, 13, 0, 15, 3, 3, 5, 5, 6, 8, 11
|
||||
};
|
@ -1,122 +0,0 @@
|
||||
/*
|
||||
* Copyright 1985, 1986, 1987, 1988, 1989 by the Massachusetts Institute
|
||||
* of Technology.
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <mit-cpyright.h>.
|
||||
*
|
||||
* These routines perform encryption and decryption using the DES
|
||||
* private key algorithm, or else a subset of it-- fewer inner loops.
|
||||
* (AUTH_DES_ITER defaults to 16, may be less.)
|
||||
*
|
||||
* Under U.S. law, this software may not be exported outside the US
|
||||
* without license from the U.S. Commerce department.
|
||||
*
|
||||
* The key schedule is passed as an arg, as well as the cleartext or
|
||||
* ciphertext. The cleartext and ciphertext should be in host order.
|
||||
*
|
||||
* These routines form the library interface to the DES facilities.
|
||||
*
|
||||
* spm 8/85 MIT project athena
|
||||
*/
|
||||
|
||||
#include "mit-cpyright.h"
|
||||
#include <afsconfig.h>
|
||||
#include <afs/param.h>
|
||||
|
||||
|
||||
#ifndef KERNEL
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#include "des.h"
|
||||
#include "des_internal.h"
|
||||
#include "des_prototypes.h"
|
||||
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#else
|
||||
#ifdef HAVE_STRINGS_H
|
||||
#include <strings.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* convert an arbitrary length string to a DES key
|
||||
*/
|
||||
void
|
||||
des_string_to_key(char *str, des_cblock * key)
|
||||
{
|
||||
char *in_str;
|
||||
unsigned temp, i, j;
|
||||
afs_int32 length;
|
||||
unsigned char *k_p;
|
||||
int forward;
|
||||
char *p_char;
|
||||
char k_char[64];
|
||||
des_key_schedule key_sked;
|
||||
|
||||
in_str = str;
|
||||
forward = 1;
|
||||
p_char = k_char;
|
||||
length = strlen(str);
|
||||
|
||||
/* init key array for bits */
|
||||
memset(k_char, 0, sizeof(k_char));
|
||||
|
||||
#ifdef DEBUG
|
||||
if (des_debug)
|
||||
fprintf(stdout,
|
||||
"\n\ninput str length = %d string = %s\nstring = 0x ",
|
||||
length, str);
|
||||
#endif
|
||||
|
||||
/* get next 8 bytes, strip parity, xor */
|
||||
for (i = 1; i <= length; i++) {
|
||||
/* get next input key byte */
|
||||
temp = (unsigned int)*str++;
|
||||
#ifdef DEBUG
|
||||
if (des_debug)
|
||||
fprintf(stdout, "%02x ", temp & 0xff);
|
||||
#endif
|
||||
/* loop through bits within byte, ignore parity */
|
||||
for (j = 0; j <= 6; j++) {
|
||||
if (forward)
|
||||
*p_char++ ^= (int)temp & 01;
|
||||
else
|
||||
*--p_char ^= (int)temp & 01;
|
||||
temp = temp >> 1;
|
||||
} while (--j > 0);
|
||||
|
||||
/* check and flip direction */
|
||||
if ((i % 8) == 0)
|
||||
forward = !forward;
|
||||
}
|
||||
|
||||
/* now stuff into the key des_cblock, and force odd parity */
|
||||
p_char = k_char;
|
||||
k_p = (unsigned char *)key;
|
||||
|
||||
for (i = 0; i <= 7; i++) {
|
||||
temp = 0;
|
||||
for (j = 0; j <= 6; j++)
|
||||
temp |= *p_char++ << (1 + j);
|
||||
*k_p++ = (unsigned char)temp;
|
||||
}
|
||||
|
||||
/* fix key parity */
|
||||
des_fixup_key_parity(cblockptr_to_cblock(key));
|
||||
|
||||
/* Now one-way encrypt it with the folded key */
|
||||
des_key_sched(cblockptr_to_cblock(key), key_sked);
|
||||
des_cbc_cksum(charptr_to_cblockptr(in_str), key, length, key_sked, key);
|
||||
/* erase key_sked */
|
||||
memset(key_sked, 0, sizeof(key_sked));
|
||||
|
||||
/* now fix up key parity again */
|
||||
des_fixup_key_parity(cblockptr_to_cblock(key));
|
||||
|
||||
if (des_debug)
|
||||
fprintf(stdout, "\nResulting string_to_key = 0x%x 0x%x\n",
|
||||
*((afs_uint32 *) key), *((afs_uint32 *) key + 1));
|
||||
}
|
115
src/des/tables.h
115
src/des/tables.h
@ -1,115 +0,0 @@
|
||||
/*
|
||||
* Copyright 1988 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <mit-copyright.h>.
|
||||
*
|
||||
* part of the Athena Kerberos encryption system
|
||||
*
|
||||
* spm 8/85
|
||||
*/
|
||||
|
||||
/*
|
||||
* Initial permutation, adjust to zero based subscript
|
||||
*/
|
||||
#ifdef WANT_IP_TABLE
|
||||
static char IP[] = {
|
||||
58 - 1, 50 - 1, 42 - 1, 34 - 1, 26 - 1, 18 - 1, 10 - 1, 2 - 1,
|
||||
60 - 1, 52 - 1, 44 - 1, 36 - 1, 28 - 1, 20 - 1, 12 - 1, 4 - 1,
|
||||
62 - 1, 54 - 1, 46 - 1, 38 - 1, 30 - 1, 22 - 1, 14 - 1, 6 - 1,
|
||||
64 - 1, 56 - 1, 48 - 1, 40 - 1, 32 - 1, 24 - 1, 16 - 1, 8 - 1,
|
||||
57 - 1, 49 - 1, 41 - 1, 33 - 1, 25 - 1, 17 - 1, 9 - 1, 1 - 1,
|
||||
59 - 1, 51 - 1, 43 - 1, 35 - 1, 27 - 1, 19 - 1, 11 - 1, 3 - 1,
|
||||
61 - 1, 53 - 1, 45 - 1, 37 - 1, 29 - 1, 21 - 1, 13 - 1, 5 - 1,
|
||||
63 - 1, 55 - 1, 47 - 1, 39 - 1, 31 - 1, 23 - 1, 15 - 1, 7 - 1,
|
||||
};
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Final permutation, FP = IP^(-1) adjust to zero based subscript
|
||||
*/
|
||||
#ifdef WANT_FP_TABLE
|
||||
static char FP[] = {
|
||||
40 - 1, 8 - 1, 48 - 1, 16 - 1, 56 - 1, 24 - 1, 64 - 1, 32 - 1,
|
||||
39 - 1, 7 - 1, 47 - 1, 15 - 1, 55 - 1, 23 - 1, 63 - 1, 31 - 1,
|
||||
38 - 1, 6 - 1, 46 - 1, 14 - 1, 54 - 1, 22 - 1, 62 - 1, 30 - 1,
|
||||
37 - 1, 5 - 1, 45 - 1, 13 - 1, 53 - 1, 21 - 1, 61 - 1, 29 - 1,
|
||||
36 - 1, 4 - 1, 44 - 1, 12 - 1, 52 - 1, 20 - 1, 60 - 1, 28 - 1,
|
||||
35 - 1, 3 - 1, 43 - 1, 11 - 1, 51 - 1, 19 - 1, 59 - 1, 27 - 1,
|
||||
34 - 1, 2 - 1, 42 - 1, 10 - 1, 50 - 1, 18 - 1, 58 - 1, 26 - 1,
|
||||
33 - 1, 1 - 1, 41 - 1, 9 - 1, 49 - 1, 17 - 1, 57 - 1, 25 - 1,
|
||||
};
|
||||
#endif
|
||||
|
||||
/* the E selection function, adjusted to zero based subscripts */
|
||||
#ifdef WANT_E_TABLE
|
||||
static char E[] = {
|
||||
32 - 1, 1 - 1, 2 - 1, 3 - 1, 4 - 1, 5 - 1,
|
||||
4 - 1, 5 - 1, 6 - 1, 7 - 1, 8 - 1, 9 - 1,
|
||||
8 - 1, 9 - 1, 10 - 1, 11 - 1, 12 - 1, 13 - 1,
|
||||
12 - 1, 13 - 1, 14 - 1, 15 - 1, 16 - 1, 17 - 1,
|
||||
16 - 1, 17 - 1, 18 - 1, 19 - 1, 20 - 1, 21 - 1,
|
||||
20 - 1, 21 - 1, 22 - 1, 23 - 1, 24 - 1, 25 - 1,
|
||||
24 - 1, 25 - 1, 26 - 1, 27 - 1, 28 - 1, 29 - 1,
|
||||
28 - 1, 29 - 1, 30 - 1, 31 - 1, 32 - 1, 1 - 1,
|
||||
};
|
||||
#endif
|
||||
|
||||
/* the P permutation, adjusted to zero based subscripts */
|
||||
#ifdef WANT_P_TABLE
|
||||
static char P[] = {
|
||||
16 - 1, 7 - 1, 20 - 1, 21 - 1,
|
||||
29 - 1, 12 - 1, 28 - 1, 17 - 1,
|
||||
1 - 1, 15 - 1, 23 - 1, 26 - 1,
|
||||
5 - 1, 18 - 1, 31 - 1, 10 - 1,
|
||||
2 - 1, 8 - 1, 24 - 1, 14 - 1,
|
||||
32 - 1, 27 - 1, 3 - 1, 9 - 1,
|
||||
19 - 1, 13 - 1, 30 - 1, 6 - 1,
|
||||
22 - 1, 11 - 1, 4 - 1, 25 - 1,
|
||||
};
|
||||
#endif
|
||||
|
||||
/* S tables, original form */
|
||||
#ifdef WANT_S_TABLE
|
||||
static char S[8][64] = {
|
||||
{14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7,
|
||||
0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8,
|
||||
4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0,
|
||||
15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13,},
|
||||
|
||||
{15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10,
|
||||
3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5,
|
||||
0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15,
|
||||
13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9,},
|
||||
|
||||
{10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8,
|
||||
13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1,
|
||||
13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7,
|
||||
1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12,},
|
||||
|
||||
{7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15,
|
||||
13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9,
|
||||
10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4,
|
||||
3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14,},
|
||||
|
||||
{2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9,
|
||||
14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6,
|
||||
4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14,
|
||||
11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3,},
|
||||
|
||||
{12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11,
|
||||
10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8,
|
||||
9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6,
|
||||
4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13,},
|
||||
|
||||
{4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1,
|
||||
13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6,
|
||||
1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2,
|
||||
6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12,},
|
||||
|
||||
{13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7,
|
||||
1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2,
|
||||
7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8,
|
||||
2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11}
|
||||
};
|
||||
#endif
|
@ -1,32 +0,0 @@
|
||||
srcdir=@srcdir@
|
||||
include @TOP_OBJDIR@/src/config/Makefile.config
|
||||
include @TOP_OBJDIR@/src/config/Makefile.lwp
|
||||
|
||||
INSTALL = @INSTALL@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@
|
||||
INSTALL_SCRIPT = @INSTALL_SCRIPT@
|
||||
|
||||
# Test programs
|
||||
PROGS = \
|
||||
key_test \
|
||||
testit \
|
||||
verify
|
||||
|
||||
LIBS=\
|
||||
${TOP_LIBDIR}/libdes.a \
|
||||
|
||||
all test: $(PROGS)
|
||||
|
||||
clean:
|
||||
$(RM) -f *.o *.a testit verify key_test core
|
||||
|
||||
install:
|
||||
|
||||
testit: testit.o
|
||||
$(AFS_LDRULE) testit.o ${LIBS}
|
||||
verify: verify.o ../libdes.a
|
||||
$(AFS_LDRULE) verify.o ${LIBS}
|
||||
key_test: key_test.o ../libdes.a
|
||||
$(AFS_LDRULE) key_test.o ${LIBS}
|
||||
|
@ -1,23 +0,0 @@
|
||||
# Copyright 2000, International Business Machines Corporation and others.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# This software has been released under the terms of the IBM Public
|
||||
# License. For details, see the LICENSE file in the top-level source
|
||||
# directory or online at http://www.openafs.org/dl/license10.html
|
||||
|
||||
RELDIR=des\test
|
||||
!include ..\..\config\NTMakefile.$(SYS_NAME)
|
||||
|
||||
$(OUT)\testit.exe: $(OUT)\testit.obj $(DESTDIR)\lib\afsdes.lib $(DESTDIR)\lib\afs\afsutil.lib
|
||||
$(EXECONLINK)
|
||||
|
||||
$(OUT)\verify.exe: $(OUT)\verify.obj $(DESTDIR)\lib\afsdes.lib $(DESTDIR)\lib\afs\afsutil.lib
|
||||
$(EXECONLINK)
|
||||
|
||||
$(OUT)\key_test.exe: $(OUT)\key_test.obj $(DESTDIR)\lib\afsdes.lib $(DESTDIR)\lib\afs\afsutil.lib
|
||||
$(EXECONLINK)
|
||||
|
||||
$(OUT)\tests: $(OUT)\testit.exe $(OUT)\verify.exe $(OUT)\key_test.exe
|
||||
|
||||
mkdir:
|
||||
|
@ -1,211 +0,0 @@
|
||||
/*
|
||||
* Copyright 1988 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <mit-cpyright.h>.
|
||||
*
|
||||
* exit status: 0 ==> success
|
||||
* -1 ==> error
|
||||
*/
|
||||
|
||||
#include <afsconfig.h>
|
||||
#include <afs/param.h>
|
||||
|
||||
|
||||
#include <mit-cpyright.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <des.h>
|
||||
|
||||
#define MIN_ARGC 0 /* min # args, not incl flags */
|
||||
#define MAX_ARGC 99 /* max # args, not incl flags */
|
||||
|
||||
extern char *errmsg();
|
||||
extern int des_key_sched();
|
||||
char *progname;
|
||||
int sflag;
|
||||
int vflag;
|
||||
int kflag;
|
||||
int mflag;
|
||||
int pid;
|
||||
extern int des_debug;
|
||||
|
||||
afs_int32 dummy[2];
|
||||
unsigned char dum_c[8] = { 0x80, 1, 1, 1, 1, 1, 1, 1 };
|
||||
des_key_schedule KS;
|
||||
des_cblock kk;
|
||||
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
/* Local Declarations */
|
||||
|
||||
int i;
|
||||
progname = argv[0]; /* salt away invoking program */
|
||||
|
||||
while (--argc > 0 && (*++argv)[0] == '-')
|
||||
for (i = 1; argv[0][i] != '\0'; i++) {
|
||||
switch (argv[0][i]) {
|
||||
|
||||
/* debug flag */
|
||||
case 'd':
|
||||
des_debug = 1;
|
||||
continue;
|
||||
|
||||
/* keys flag */
|
||||
case 'k':
|
||||
kflag = 1;
|
||||
continue;
|
||||
|
||||
/* test ANSI msb only key */
|
||||
case 'm':
|
||||
mflag = 1;
|
||||
continue;
|
||||
|
||||
default:
|
||||
printf("%s: illegal flag \"%c\" ", progname, argv[0][i]);
|
||||
exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
if (argc < MIN_ARGC || argc > MAX_ARGC) {
|
||||
printf("Usage: xxx [-xxx] xxx xxx\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* argv[0] now points to first non-option arg, if any */
|
||||
|
||||
|
||||
if (des_debug) {
|
||||
if (mflag) {
|
||||
fprintf(stderr, "\nChecking a key 0x 80 01 01 01 01 01 01 01 ");
|
||||
fprintf(stderr, "\nKey = ");
|
||||
des_key_sched(dum_c, KS);
|
||||
des_cblock_print(dum_c);
|
||||
return;
|
||||
}
|
||||
|
||||
if (kflag) {
|
||||
printf("\nCHecking a weak key...");
|
||||
dummy[0] = 0x01fe01fe;
|
||||
dummy[1] = 0x01fe01fe;
|
||||
des_key_sched(dummy, KS);
|
||||
#ifdef BSDUNIX
|
||||
fprintf(stderr, "\nKey[0] = %x Key[1] = %x", dummy[0], dummy[1]);
|
||||
#endif
|
||||
#ifdef CROSSMSDOS
|
||||
fprintf(stderr, "\nKey[0] = %X Key[1] = %X", dummy[0], dummy[1]);
|
||||
#endif
|
||||
|
||||
dummy[0] = 0x01010101;
|
||||
dummy[1] = 0x01010101;
|
||||
#ifdef BSDUNIX
|
||||
fprintf(stderr, "\nKey[0] = %x Key[1] = %x", dummy[0], dummy[1]);
|
||||
#endif
|
||||
#ifdef CROSSMSDOS
|
||||
fprintf(stderr, "\nKey[0] = %X Key[1] = %X", dummy[0], dummy[1]);
|
||||
#endif
|
||||
des_key_sched(dummy, KS);
|
||||
#ifdef BSDUNIX
|
||||
fprintf(stderr, "\nKS= %x", *(afs_int32 *) KS);
|
||||
#endif
|
||||
#ifdef CROSSMSDOS
|
||||
fprintf(stderr, "\nKS= %X", *(afs_int32 *) KS);
|
||||
#endif
|
||||
dummy[0] = 0x01010101;
|
||||
dummy[1] = 0x01010101;
|
||||
#ifdef BSDUNIX
|
||||
fprintf(stderr, "\nKey[0] = %x Key[1] = %x", dummy[0], dummy[1]);
|
||||
#endif
|
||||
#ifdef CROSSMSDOS
|
||||
fprintf(stderr, "\nKey[0] = %X Key[1] = %X", dummy[0], dummy[1]);
|
||||
#endif
|
||||
des_key_sched(dummy, KS);
|
||||
#ifdef BSDUNIX
|
||||
fprintf(stderr, "\nKS= %x", *(afs_int32 *) KS);
|
||||
#endif
|
||||
#ifdef CROSSMSDOS
|
||||
fprintf(stderr, "\nKS= %X", *(afs_int32 *) KS);
|
||||
#endif
|
||||
|
||||
dummy[0] = 0x80808080;
|
||||
dummy[1] = 0x80808080;
|
||||
#ifdef BSDUNIX
|
||||
fprintf(stderr, "\nKey[0] = %x Key[1] = %x", dummy[0], dummy[1]);
|
||||
#endif
|
||||
#ifdef CROSSMSDOS
|
||||
fprintf(stderr, "\nKey[0] = %X Key[1] = %X", dummy[0], dummy[1]);
|
||||
#endif
|
||||
des_key_sched(dummy, KS);
|
||||
#ifdef BSDUNIX
|
||||
fprintf(stderr, "\nKS[0]= %x", *(afs_int32 *) KS);
|
||||
#endif
|
||||
#ifdef CROSSMSDOS
|
||||
fprintf(stderr, "\nKS[0]= %X", *(afs_int32 *) KS);
|
||||
#endif
|
||||
|
||||
printf("\nstring to key 'a'");
|
||||
des_string_to_key("a", dummy);
|
||||
#ifdef BSDUNIX
|
||||
fprintf(stderr, "\nKey[0] = %x Key[1] = %x", dummy[0], dummy[1]);
|
||||
#endif
|
||||
#ifdef CROSSMSDOS
|
||||
fprintf(stderr, "\nKey[0] = %X Key[1] = %X", dummy[0], dummy[1]);
|
||||
#endif
|
||||
des_key_sched(dummy, KS);
|
||||
#ifdef BSDUNIX
|
||||
fprintf(stderr, "\nKS= %x", *(afs_int32 *) KS);
|
||||
#endif
|
||||
#ifdef CROSSMSDOS
|
||||
fprintf(stderr, "\nKS= %X", *(afs_int32 *) KS);
|
||||
#endif
|
||||
|
||||
printf("\nstring to key 'c'");
|
||||
des_string_to_key("c", dummy);
|
||||
#ifdef BSDUNIX
|
||||
fprintf(stderr, "\nKey[0] = %x Key[1] = %x", dummy[0], dummy[1]);
|
||||
#endif
|
||||
#ifdef CROSSMSDOS
|
||||
fprintf(stderr, "\nKey[0] = %X Key[1] = %X", dummy[0], dummy[1]);
|
||||
#endif
|
||||
des_key_sched(dummy, KS);
|
||||
#ifdef BSDUNIX
|
||||
fprintf(stderr, "\nKS= %x", *(afs_int32 *) KS);
|
||||
#endif
|
||||
#ifdef CROSSMSDOS
|
||||
fprintf(stderr, "\nKS= %X", *(afs_int32 *) KS);
|
||||
#endif
|
||||
}
|
||||
|
||||
printf("\nstring to key 'e'");
|
||||
des_string_to_key("e", dummy);
|
||||
#ifdef BSDUNIX
|
||||
fprintf(stderr, "\nKey[0] = %x Key[1] = %x", dummy[0], dummy[1]);
|
||||
#endif
|
||||
#ifdef CROSSMSDOS
|
||||
fprintf(stderr, "\nKey[0] = %X Key[1] = %X", dummy[0], dummy[1]);
|
||||
#endif
|
||||
des_key_sched(dummy, KS);
|
||||
#ifdef BSDUNIX
|
||||
fprintf(stderr, "\nKS= %x", KS[0]);
|
||||
#endif
|
||||
#ifdef CROSSMSDOS
|
||||
fprintf(stderr, "\nKS= %X", KS[0]);
|
||||
#endif
|
||||
|
||||
printf("\ndes_string_to_key '%s'", argv[0]);
|
||||
des_string_to_key(argv[0], dummy);
|
||||
#ifdef notdef
|
||||
des_string_to_key(argv[0], dummy);
|
||||
|
||||
for (i = 0; i < 1; i++)
|
||||
des_key_sched(dummy, KS);
|
||||
} else {
|
||||
for (i = 0; i < 1000; i++) {
|
||||
des_string_to_key(argv[0], kk);
|
||||
des_key_sched(kk, KS);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
@ -1,230 +0,0 @@
|
||||
/*
|
||||
* Copyright 1988 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* For copying and distribution information, please see the file
|
||||
* <mit-cpyright.h>.
|
||||
*
|
||||
* exit returns 0 ==> success
|
||||
* -1 ==> error
|
||||
*/
|
||||
|
||||
#include <mit-cpyright.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <des.h>
|
||||
#include <afsconfig.h>
|
||||
#include <afs/param.h>
|
||||
|
||||
|
||||
|
||||
#define MIN_ARGC 0 /* min # args, not incl flags */
|
||||
#define MAX_ARGC 2 /* max # args, not incl flags */
|
||||
|
||||
/* MIN_ARGC == MAX_ARGC ==> required # args */
|
||||
|
||||
extern char *errmsg();
|
||||
extern void des_string_to_key();
|
||||
extern int des_key_sched();
|
||||
extern int des_ecb_encrypt();
|
||||
extern int des_cbc_encrypt();
|
||||
extern int des_pcbc_encrypt();
|
||||
|
||||
char *progname;
|
||||
int sflag;
|
||||
int vflag;
|
||||
int tflag;
|
||||
int nflag = 1000;
|
||||
int cflag;
|
||||
int des_debug;
|
||||
des_key_schedule KS;
|
||||
unsigned char cipher_text[64];
|
||||
unsigned char clear_text[64] = "Now is the time for all ";
|
||||
unsigned char clear_text2[64] = "7654321 Now is the time for ";
|
||||
unsigned char clear_text3[64] = { 2, 0, 0, 0, 1, 0, 0, 0 };
|
||||
unsigned char *input;
|
||||
|
||||
/* 0x0123456789abcdef */
|
||||
des_cblock default_key = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
|
||||
des_cblock s_key;
|
||||
des_cblock default_ivec = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef };
|
||||
unsigned char *ivec;
|
||||
des_cblock zero_key = { 1 };
|
||||
int i, j;
|
||||
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
/* Local Declarations */
|
||||
|
||||
long in_length;
|
||||
|
||||
progname = argv[0]; /* salt away invoking program */
|
||||
|
||||
while (--argc > 0 && (*++argv)[0] == '-')
|
||||
for (i = 1; argv[0][i] != '\0'; i++) {
|
||||
switch (argv[0][i]) {
|
||||
|
||||
/* debug flag */
|
||||
case 'd':
|
||||
des_debug = 1;
|
||||
continue;
|
||||
|
||||
/* verbose flag */
|
||||
case 'v':
|
||||
vflag = 1;
|
||||
continue;
|
||||
|
||||
/* cbc flag */
|
||||
case 'c':
|
||||
cflag = 1;
|
||||
continue;
|
||||
|
||||
/* string to key only flag */
|
||||
case 's':
|
||||
sflag = 1;
|
||||
continue;
|
||||
|
||||
/* test flag - use known key and cleartext */
|
||||
case 't':
|
||||
tflag = 1;
|
||||
continue;
|
||||
|
||||
/* iteration count */
|
||||
case 'n':
|
||||
sscanf(&argv[0][i + 1], "%d", &nflag);
|
||||
argv[0][i + 1] = '\0'; /* force it to stop */
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("%s: illegal flag \"%c\" ", progname, argv[0][i]);
|
||||
exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
if (argc < MIN_ARGC || argc > MAX_ARGC) {
|
||||
printf("Usage: xxx [-xxx] xxx xxx\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* argv[0] now points to first non-option arg, if any */
|
||||
|
||||
if (tflag) {
|
||||
/* use known input and key */
|
||||
des_key_sched(default_key, KS);
|
||||
input = clear_text;
|
||||
ivec = (unsigned char *)default_ivec;
|
||||
} else {
|
||||
/*des_string_to_key(argv[0],s_key); */
|
||||
des_string_to_key("test", s_key);
|
||||
if (vflag) {
|
||||
input = (unsigned char *)s_key;
|
||||
fprintf(stdout, "\nstring = %s, key = ", argv[0]);
|
||||
for (i = 0; i <= 7; i++)
|
||||
fprintf(stdout, "%02x ", *input++);
|
||||
}
|
||||
des_string_to_key("test", s_key);
|
||||
if (vflag) {
|
||||
input = (unsigned char *)s_key;
|
||||
fprintf(stdout, "\nstring = %s, key = ", argv[0]);
|
||||
for (i = 0; i <= 7; i++)
|
||||
fprintf(stdout, "%02x ", *input++);
|
||||
}
|
||||
des_key_sched(s_key, KS);
|
||||
input = (unsigned char *)argv[1];
|
||||
ivec = (unsigned char *)argv[2];
|
||||
}
|
||||
|
||||
|
||||
if (cflag) {
|
||||
fprintf(stdout, "\nclear %s\n", input);
|
||||
in_length = strlen(input);
|
||||
des_cbc_encrypt(input, cipher_text, (long)in_length, KS, ivec, 1);
|
||||
fprintf(stdout, "\n\nencrypted ciphertext = (low to high bytes)");
|
||||
for (i = 0; i <= 7; i++) {
|
||||
fprintf(stdout, "\n");
|
||||
for (j = 0; j <= 7; j++)
|
||||
fprintf(stdout, "%02x ", cipher_text[i * 8 + j]);
|
||||
}
|
||||
des_cbc_encrypt(cipher_text, clear_text, (long)in_length, KS, ivec,
|
||||
0);
|
||||
fprintf(stdout, "\n\ndecrypted clear_text = %s", clear_text);
|
||||
|
||||
fprintf(stdout, "\nclear %s\n", input);
|
||||
input = clear_text2;
|
||||
des_cbc_cksum(input, cipher_text, (long)strlen(input), KS, ivec, 1);
|
||||
fprintf(stdout, "\n\nencrypted cksum = (low to high bytes)\n");
|
||||
for (j = 0; j <= 7; j++)
|
||||
fprintf(stdout, "%02x ", cipher_text[j]);
|
||||
|
||||
/* test out random number generator */
|
||||
for (i = 0; i <= 7; i++) {
|
||||
des_random_key(cipher_text);
|
||||
des_key_sched(cipher_text, KS);
|
||||
fprintf(stdout, "\n\nrandom key = (low to high bytes)\n");
|
||||
for (j = 0; j <= 7; j++)
|
||||
fprintf(stdout, "%02x ", cipher_text[j]);
|
||||
}
|
||||
} else {
|
||||
if (vflag)
|
||||
fprintf(stdout, "\nclear %s\n", input);
|
||||
do_encrypt(input, cipher_text);
|
||||
do_decrypt(clear_text, cipher_text);
|
||||
}
|
||||
}
|
||||
|
||||
flip(array)
|
||||
char *array;
|
||||
{
|
||||
int old, new, i, j;
|
||||
/* flips the bit order within each byte from 0 lsb to 0 msb */
|
||||
for (i = 0; i <= 7; i++) {
|
||||
old = *array;
|
||||
new = 0;
|
||||
for (j = 0; j <= 7; j++) {
|
||||
if (old & 01)
|
||||
new = new | 01;
|
||||
if (j < 7) {
|
||||
old = old >> 1;
|
||||
new = new << 1;
|
||||
}
|
||||
}
|
||||
*array = new;
|
||||
array++;
|
||||
}
|
||||
}
|
||||
|
||||
do_encrypt(in, out)
|
||||
char *in;
|
||||
char *out;
|
||||
{
|
||||
for (i = 1; i <= nflag; i++) {
|
||||
des_ecb_encrypt(in, out, KS, 1);
|
||||
if (vflag) {
|
||||
fprintf(stdout, "\nclear %s\n", in);
|
||||
for (j = 0; j <= 7; j++)
|
||||
fprintf(stdout, "%02 X ", in[j] & 0xff);
|
||||
fprintf(stdout, "\tcipher ");
|
||||
for (j = 0; j <= 7; j++)
|
||||
fprintf(stdout, "%02X ", out[j] & 0xff);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
do_decrypt(in, out)
|
||||
char *out;
|
||||
char *in;
|
||||
/* try to invert it */
|
||||
{
|
||||
for (i = 1; i <= nflag; i++) {
|
||||
des_ecb_encrypt(out, in, KS, 0);
|
||||
if (vflag) {
|
||||
fprintf(stdout, "\nclear %s\n", in);
|
||||
for (j = 0; j <= 7; j++)
|
||||
fprintf(stdout, "%02X ", in[j] & 0xff);
|
||||
fprintf(stdout, "\tcipher ");
|
||||
for (j = 0; j <= 7; j++)
|
||||
fprintf(stdout, "%02X ", out[j] & 0xff);
|
||||
}
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user