📄 des.txt
字号:
v |= k1[(v2 ) & 0x7f];
*k2++ = v;
}
direction = 0;
}
/*
* Undo an extra E selection and do final permutations
*/
ufc_long *ufc_dofinalperm(l1, l2, r1, r2)
ufc_long l1,l2,r1,r2;
{ ufc_long v1, v2, x;
static ufc_long ary[2];
x = (l1 ^ l2) & current_saltbits; l1 ^= x; l2 ^= x;
x = (r1 ^ r2) & current_saltbits; r1 ^= x; r2 ^= x;
v1=v2=0; l1 >>= 3; l2 >>= 3; r1 >>= 3; r2 >>= 3;
v1 |= efp[15][ r2 & 0x3f][0]; v2 |= efp[15][ r2 & 0x3f][1];
v1 |= efp[14][(r2 >>= 6) & 0x3f][0]; v2 |= efp[14][ r2 & 0x3f][1];
v1 |= efp[13][(r2 >>= 10) & 0x3f][0]; v2 |= efp[13][ r2 & 0x3f][1];
v1 |= efp[12][(r2 >>= 6) & 0x3f][0]; v2 |= efp[12][ r2 & 0x3f][1];
v1 |= efp[11][ r1 & 0x3f][0]; v2 |= efp[11][ r1 & 0x3f][1];
v1 |= efp[10][(r1 >>= 6) & 0x3f][0]; v2 |= efp[10][ r1 & 0x3f][1];
v1 |= efp[ 9][(r1 >>= 10) & 0x3f][0]; v2 |= efp[ 9][ r1 & 0x3f][1];
v1 |= efp[ 8][(r1 >>= 6) & 0x3f][0]; v2 |= efp[ 8][ r1 & 0x3f][1];
v1 |= efp[ 7][ l2 & 0x3f][0]; v2 |= efp[ 7][ l2 & 0x3f][1];
v1 |= efp[ 6][(l2 >>= 6) & 0x3f][0]; v2 |= efp[ 6][ l2 & 0x3f][1];
v1 |= efp[ 5][(l2 >>= 10) & 0x3f][0]; v2 |= efp[ 5][ l2 & 0x3f][1];
v1 |= efp[ 4][(l2 >>= 6) & 0x3f][0]; v2 |= efp[ 4][ l2 & 0x3f][1];
v1 |= efp[ 3][ l1 & 0x3f][0]; v2 |= efp[ 3][ l1 & 0x3f][1];
v1 |= efp[ 2][(l1 >>= 6) & 0x3f][0]; v2 |= efp[ 2][ l1 & 0x3f][1];
v1 |= efp[ 1][(l1 >>= 10) & 0x3f][0]; v2 |= efp[ 1][ l1 & 0x3f][1];
v1 |= efp[ 0][(l1 >>= 6) & 0x3f][0]; v2 |= efp[ 0][ l1 & 0x3f][1];
ary[0] = v1; ary[1] = v2;
return ary;
}
/*
* crypt only: convert from 64 bit to 11 bit ASCII
* prefixing with the salt
*/
STATIC char *output_conversion(v1, v2, salt)
ufc_long v1, v2;
char *salt;
{ static char outbuf[14];
int i, s;
outbuf[0] = salt[0];
outbuf[1] = salt[1] ? salt[1] : salt[0];
for(i = 0; i < 5; i++)
outbuf[i + 2] = bin_to_ascii((v1 >> (26 - 6 * i)) & 0x3f);
s = (v2 & 0xf) << 2;
v2 = (v2 >> 2) | ((v1 & 0x3) << 30);
for(i = 5; i < 10; i++)
outbuf[i + 2] = bin_to_ascii((v2 >> (56 - 6 * i)) & 0x3f);
outbuf[12] = bin_to_ascii(s);
outbuf[13] = 0;
return outbuf;
}
ufc_long *ufc_doit();
/*
* UNIX crypt function
*/
char *crypt(key, salt)
char *key, *salt;
{ ufc_long *s;
char ktab[9];
/*
* Hack DES tables according to salt
*/
setup_salt(salt);
/*
* Setup key schedule
*/
clearmem(ktab, sizeof ktab);
(void)strncpy(ktab, key, 8);
ufc_mk_keytab(ktab);
/*
* Go for the 25 DES encryptions
*/
s = ufc_doit((ufc_long)0, (ufc_long)0,
(ufc_long)0, (ufc_long)0, (ufc_long)25);
/*
* And convert back to 6 bit ASCII
*/
return output_conversion(s[0], s[1], salt);
}
/*
* To make fcrypt users happy.
* They don't need to call init_des.
*/
char *fcrypt(key, salt)
char *key;
char *salt;
{ return crypt(key, salt);
}
/*
* UNIX encrypt function. Takes a bitvector
* represented by one byte per bit and
* encrypt/decrypt according to edflag
*/
void encrypt(block, edflag)
char *block;
int edflag;
{ ufc_long l1, l2, r1, r2, *s;
int i;
/*
* Undo any salt changes to E expansion
*/
setup_salt("..");
/*
* Reverse key table if
* changing operation (encrypt/decrypt)
*/
if((edflag == 0) != (direction == 0)) {
for(i = 0; i < 8; i++) {
#ifdef _UFC_32_
long32 x;
x = ufc_keytab[15-i][0];
ufc_keytab[15-i][0] = ufc_keytab[i][0];
ufc_keytab[i][0] = x;
x = ufc_keytab[15-i][1];
ufc_keytab[15-i][1] = ufc_keytab[i][1];
ufc_keytab[i][1] = x;
#endif
#ifdef _UFC_64_
long64 x;
x = ufc_keytab[15-i];
ufc_keytab[15-i] = ufc_keytab[i];
ufc_keytab[i] = x;
#endif
}
direction = edflag;
}
/*
* Do initial permutation + E expansion
*/
i = 0;
for(l1 = 0; i < 24; i++) {
if(block[initial_perm[esel[i]-1]-1])
l1 |= BITMASK(i);
}
for(l2 = 0; i < 48; i++) {
if(block[initial_perm[esel[i]-1]-1])
l2 |= BITMASK(i-24);
}
i = 0;
for(r1 = 0; i < 24; i++) {
if(block[initial_perm[esel[i]-1+32]-1])
r1 |= BITMASK(i);
}
for(r2 = 0; i < 48; i++) {
if(block[initial_perm[esel[i]-1+32]-1])
r2 |= BITMASK(i-24);
}
/*
* Do DES inner loops + final conversion
*/
s = ufc_doit(l1, l2, r1, r2, (ufc_long)1);
/*
* And convert to bit array
*/
l1 = s[0]; r1 = s[1];
for(i = 0; i < 32; i++) {
*block++ = (l1 & longmask[i]) != 0;
}
for(i = 0; i < 32; i++) {
*block++ = (r1 & longmask[i]) != 0;
}
}
/*
* UNIX setkey function. Take a 64 bit DES
* key and setup the machinery.
*/
void setkey(key)
char *key;
{ int i,j;
unsigned char c;
unsigned char ktab[8];
setup_salt(".."); /* be sure we're initialized */
for(i = 0; i < 8; i++) {
for(j = 0, c = 0; j < 8; j++)
c = c << 1 | *key++;
ktab[i] = c >> 1;
}
ufc_mk_keytab(ktab);
}
/*---------------------- 这是 patchlevel.h -----------------------
/*
* UFC-crypt: ultra fast crypt(3) implementation
*
* Copyright (C) 1991, 1992, Michael Glad, email: glad@daimi.aau.dk
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* @(#)patchlevel.h 1.6 01/31/92
*
*/
#define PATCHLEVEL "UFC-crypt, patchlevel 1a, @(#)patchlevel.h 1.6 01/31/92"
/*********************** 这是 ufc-crypt.h ******************************
/*
* UFC-crypt: ultra fast crypt(3) implementation
*
* Copyright (C) 1991, 1992, Michael Glad, email: glad@daimi.aau.dk
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* @(#)ufc-crypt.h 1.11 01/20/92
*
* Definitions of datatypes
*
*/
/*
* Requirements for datatypes:
*
* A datatype 'ufc_long' of at least 32 bit
* *and*
* A type 'long32' of exactly 32 bits (_UFC_32_)
* *or*
* A type 'long64' of exactly 64 bits (_UFC_64_)
*
* 'int' is assumed to be at least 8 bit
*/
/*
* #ifdef's for various architectures
*/
#ifdef cray
/* Cray: all integer flavoured
datatypes are 64 bit wide.
Not tested -- please notify me
if you are able to test it.
*/
typedef unsigned long ufc_long;
typedef unsigned long long64;
#define _UFC_64_
#endif
#ifdef convex
/* thanks to pcl@convex.oxford.ac.uk (Paul Leyland) for testing */
typedef unsigned long ufc_long;
typedef long long long64;
#define _UFC_64_
#endif
/*
* For debugging 64 bit code etc with 'gcc'
*/
#ifdef GCC3232
typedef unsigned long ufc_long;
typedef unsigned long long32;
#define _UFC_32_
#endif
#ifdef GCC3264
typedef unsigned long ufc_long;
typedef long long long64;
#define _UFC_64_
#endif
#ifdef GCC6432
typedef long long ufc_long;
typedef unsigned long long32;
#define _UFC_32_
#endif
#ifdef GCC6464
typedef long long ufc_long;
typedef long long long64;
#define _UFC_64_
#endif
/*
* Catch all for 99.95% of all UNIX machines
*/
#ifndef _UFC_64_
#ifndef _UFC_32_
#define _UFC_32_
typedef unsigned ufc_long;
typedef unsigned long long32;
#endif
#endif
/************************ 最后是 makefile *************************/
logfile: ver
ver: crypt.o crypt_util.o
cc -o ver -g crypt.o crypt_util.o
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -