⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 crypt.c

📁 MPICH是MPI的重要研究,提供了一系列的接口函数,为并行计算的实现提供了编程环境.
💻 C
📖 第 1 页 / 共 2 页
字号:
0x01000000L,0x01000100L,0x01080000L,0x01080100L,0x00000010L,0x00000110L,0x00080010L,0x00080110L,0x01000010L,0x01000110L,0x01080010L,0x01080110L,0x00200000L,0x00200100L,0x00280000L,0x00280100L,0x01200000L,0x01200100L,0x01280000L,0x01280100L,0x00200010L,0x00200110L,0x00280010L,0x00280110L,0x01200010L,0x01200110L,0x01280010L,0x01280110L,0x00000200L,0x00000300L,0x00080200L,0x00080300L,0x01000200L,0x01000300L,0x01080200L,0x01080300L,0x00000210L,0x00000310L,0x00080210L,0x00080310L,0x01000210L,0x01000310L,0x01080210L,0x01080310L,0x00200200L,0x00200300L,0x00280200L,0x00280300L,0x01200200L,0x01200300L,0x01280200L,0x01280300L,0x00200210L,0x00200310L,0x00280210L,0x00280310L,0x01200210L,0x01200310L,0x01280210L,0x01280310L,},{/* for D bits (numbered as per FIPS 46) 22 23 24 25 27 28 */0x00000000L,0x04000000L,0x00040000L,0x04040000L,0x00000002L,0x04000002L,0x00040002L,0x04040002L,0x00002000L,0x04002000L,0x00042000L,0x04042000L,0x00002002L,0x04002002L,0x00042002L,0x04042002L,0x00000020L,0x04000020L,0x00040020L,0x04040020L,0x00000022L,0x04000022L,0x00040022L,0x04040022L,0x00002020L,0x04002020L,0x00042020L,0x04042020L,0x00002022L,0x04002022L,0x00042022L,0x04042022L,0x00000800L,0x04000800L,0x00040800L,0x04040800L,0x00000802L,0x04000802L,0x00040802L,0x04040802L,0x00002800L,0x04002800L,0x00042800L,0x04042800L,0x00002802L,0x04002802L,0x00042802L,0x04042802L,0x00000820L,0x04000820L,0x00040820L,0x04040820L,0x00000822L,0x04000822L,0x00040822L,0x04040822L,0x00002820L,0x04002820L,0x00042820L,0x04042820L,0x00002822L,0x04002822L,0x00042822L,0x04042822L,} };/* See ecb_encrypt.c for a pseudo description of these macros. */#define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\	(b)^=(t),\	(a)^=((t)<<(n)))#define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\	(a)=(a)^(t)^(t>>(16-(n))))\#endif #ifdef PARA#define STATIC#else#define STATIC	static#endif#ifndef NOPROTOSTATIC int fcrypt_body(DES_LONG *out0, DES_LONG *out1,	des_key_schedule ks, DES_LONG Eswap0, DES_LONG Eswap1);#ifndef HEADER_DES_LOCL_HSTATIC int fcrypt_set_key(des_cblock (*key), des_key_schedule schedule);#endif#elseSTATIC int fcrypt_body();#ifndef HEADER_DES_LOCL_HSTATIC int fcrypt_set_key();#endif#endif#ifdef HEADER_DES_LOCL_H#define fcrypt_set_key(a,b)	des_set_key(a,b)#elseSTATIC int fcrypt_set_key(key, schedule)des_cblock (*key);des_key_schedule schedule;	{	static const int shifts2[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0};	register DES_LONG c,d,t,s;	register unsigned char *in;	register DES_LONG *k;	register int i;	k=(DES_LONG *)schedule;	in=(unsigned char *)key;	c2l(in,c);	c2l(in,d);	/* I now do it in 47 simple operations :-)	 * Thanks to John Fletcher (john_fletcher@lccmail.ocf.llnl.gov)	 * for the inspiration. :-) */	PERM_OP (d,c,t,4,0x0f0f0f0fL);	HPERM_OP(c,t,-2,0xcccc0000L);	HPERM_OP(d,t,-2,0xcccc0000L);	PERM_OP (d,c,t,1,0x55555555L);	PERM_OP (c,d,t,8,0x00ff00ffL);	PERM_OP (d,c,t,1,0x55555555L);	d=	(((d&0x000000ffL)<<16)| (d&0x0000ff00L)     |		 ((d&0x00ff0000L)>>16)|((c&0xf0000000L)>>4));	c&=0x0fffffffL;	for (i=0; i<ITERATIONS; i++)		{		if (shifts2[i])			{ c=((c>>2)|(c<<26)); d=((d>>2)|(d<<26)); }		else			{ c=((c>>1)|(c<<27)); d=((d>>1)|(d<<27)); }		c&=0x0fffffffL;		d&=0x0fffffffL;		/* could be a few less shifts but I am to lazy at this		 * point in time to investigate */		s=	skb[0][ (c     )&0x3f                 ]|			skb[1][((c>> 6L)&0x03)|((c>> 7L)&0x3c)]|			skb[2][((c>>13L)&0x0f)|((c>>14L)&0x30)]|			skb[3][((c>>20L)&0x01)|((c>>21L)&0x06) |					       ((c>>22L)&0x38)];		t=	skb[4][ (d     )&0x3f                 ]|			skb[5][((d>> 7L)&0x03)|((d>> 8L)&0x3c)]|			skb[6][ (d>>15L)&0x3f                 ]|			skb[7][((d>>21L)&0x0f)|((d>>22L)&0x30)];		/* table contained 0213 4657 */		*(k++)=((t<<16)|(s&0x0000ffffL))&0xffffffffL;		s=     ((s>>16)|(t&0xffff0000L));				s=(s<<4)|(s>>28);		*(k++)=s&0xffffffffL;		}	return(0);	}#endif/****************************************************************** * modified stuff for crypt. ******************************************************************//* The changes to this macro may help or hinder, depending on the * compiler and the achitecture.  gcc2 always seems to do well :-).  * Inspired by Dana How <how@isl.stanford.edu> * DO NOT use the alternative version on machines with 8 byte longs. */#ifdef DES_PTR#define CR_ENCRYPT(L,R,S) \	t=(R^(R>>16)); \	u=(t&E0); \	t=(t&E1); \	u=((u^(u<<16))^R^s[S  ])<<2; \	t=(t^(t<<16))^R^s[S+1]; \	t=(t>>2)|(t<<30); \	L^= *(DES_LONG *)((unsigned char *)des_SP+0x0100+((t    )&0xfc)); \	L^= *(DES_LONG *)((unsigned char *)des_SP+0x0300+((t>> 8)&0xfc)); \	L^= *(DES_LONG *)((unsigned char *)des_SP+0x0500+((t>>16)&0xfc)); \	L^= *(DES_LONG *)((unsigned char *)des_SP+0x0700+((t>>24)&0xfc)); \	L^= *(DES_LONG *)((unsigned char *)des_SP+       ((u    )&0xfc)); \  	L^= *(DES_LONG *)((unsigned char *)des_SP+0x0200+((u>> 8)&0xfc)); \  	L^= *(DES_LONG *)((unsigned char *)des_SP+0x0400+((u>>16)&0xfc)); \ 	L^= *(DES_LONG *)((unsigned char *)des_SP+0x0600+((u>>24)&0xfc));#else /* original version */#define CR_ENCRYPT(L,R,S)	\	t=(R^(R>>16)); \	u=(t&E0); \	t=(t&E1); \	u=(u^(u<<16))^R^s[S  ]; \	t=(t^(t<<16))^R^s[S+1]; \	t=(t>>4)|(t<<28); \	L^=	des_SPtrans[1][(t    )&0x3f]; \	L^=	des_SPtrans[3][(t>> 8)&0x3f]; \	L^=	des_SPtrans[5][(t>>16)&0x3f]; \	L^=	des_SPtrans[7][(t>>24)&0x3f]; \	L^=	des_SPtrans[0][(u    )&0x3f]; \	L^=	des_SPtrans[2][(u>> 8)&0x3f]; \	L^=	des_SPtrans[4][(u>>16)&0x3f]; \	L^=	des_SPtrans[6][(u>>24)&0x3f];#endif/* Added more values to handle illegal salt values the way normal * crypt() implementations do.  The patch was sent by  * Bjorn Gronvall <bg@sics.se> */static unsigned const char con_salt[128]={0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF,0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,0x20,0x21,0x22,0x23,0x24,0x25,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,0x40,0x41,0x42,0x43,0x44,};static unsigned const char cov_2char[64]={0x2E,0x2F,0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A};#ifndef NOPROTO#ifdef PERL5char *des_crypt(const char *buf,const char *salt);#elsechar *crypt(const char *buf,const char *salt);#endif#else#ifdef PERL5char *des_crypt();#elsechar *crypt();#endif#endif#ifdef PERL5char *des_crypt(buf,salt)#elsechar *crypt(buf,salt)#endifconst char *buf;const char *salt;	{	static char buff[14];	return(des_fcrypt(buf,salt,buff));	}char *des_fcrypt(buf,salt,ret)const char *buf;const char *salt;char *ret;{	unsigned int i,j,x,y;	DES_LONG Eswap0,Eswap1;	DES_LONG out[2],ll;	des_cblock key;	des_key_schedule ks;	unsigned char bb[9];	unsigned char *b=bb;	unsigned char c,u;	/* eay 25/08/92	 * If you call crypt("pwd","*") as often happens when you	 * have * as the pwd field in /etc/passwd, the function	 * returns *\0XXXXXXXXX	 * The \0 makes the string look like * so the pwd "*" would	 * crypt to "*".  This was found when replacing the crypt in	 * our shared libraries.  People found that the disbled	 * accounts effectivly had no passwd :-(. */	x=ret[0]=((salt[0] == '\0')?'A':salt[0]);	Eswap0=con_salt[x];	x=ret[1]=((salt[1] == '\0')?'A':salt[1]);	Eswap1=con_salt[x]<<4;/* EAYr=strlen(buf);r=(r+7)/8;*/	for (i=0; i<8; i++)		{		c= *(buf++);		if (!c) break;		key[i]=(c<<1);		}	for (; i<8; i++)		key[i]=0;	fcrypt_set_key((des_cblock *)(key),ks);	fcrypt_body(&(out[0]),&(out[1]),ks,Eswap0,Eswap1);	ll=out[0]; l2c(ll,b);	ll=out[1]; l2c(ll,b);	y=0;	u=0x80;	bb[8]=0;	for (i=2; i<13; i++)		{		c=0;		for (j=0; j<6; j++)			{			c<<=1;			if (bb[y] & u) c|=1;			u>>=1;			if (!u)				{				y++;				u=0x80;				}			}		ret[i]=cov_2char[c];		}	ret[13]='\0';	return(ret);	}STATIC int fcrypt_body(out0, out1, ks, Eswap0, Eswap1)DES_LONG *out0;DES_LONG *out1;des_key_schedule ks;DES_LONG Eswap0;DES_LONG Eswap1;	{	register DES_LONG l,r,t,u;#ifdef DES_PTR	register unsigned char *des_SP=(unsigned char *)des_SPtrans;#endif	register DES_LONG *s;	register int i,j;	register DES_LONG E0,E1;	l=0;	r=0;	s=(DES_LONG *)ks;	E0=Eswap0;	E1=Eswap1;	for (j=0; j<25; j++)		{		for (i=0; i<(ITERATIONS*2); i+=4)			{			CR_ENCRYPT(l,r,  i);	/*  1 */			CR_ENCRYPT(r,l,  i+2);	/*  2 */			}		t=l;		l=r;		r=t;		}	t=r;	r=(l>>1L)|(l<<31L);	l=(t>>1L)|(t<<31L);	/* clear the top bits on machines with 8byte longs */	l&=0xffffffffL;	r&=0xffffffffL;	PERM_OP(r,l,t, 1,0x55555555L);	PERM_OP(l,r,t, 8,0x00ff00ffL);	PERM_OP(r,l,t, 2,0x33333333L);	PERM_OP(l,r,t,16,0x0000ffffL);	PERM_OP(r,l,t, 4,0x0f0f0f0fL);	*out0=l;	*out1=r;	return(0);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -