亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? twofish.c

?? 嵌入環境下Blowfish加密算法的實現
?? C
?? 第 1 頁 / 共 2 頁
字號:
/***************************************************************************
	TWOFISH.C	-- C API calls for TWOFISH AES submission

	Submitters:
		Bruce Schneier, Counterpane Systems
		Doug Whiting,	Hi/fn
		John Kelsey,	Counterpane Systems
		Chris Hall,		Counterpane Systems
		David Wagner,	UC Berkeley
			
	Code Author:		Doug Whiting,	Hi/fn
		
	Version  1.00		April 1998
		
	Copyright 1998, Hi/fn and Counterpane Systems.  All rights reserved.
		
	Notes:
		*	Pedagogical version (non-optimized)
		*	Tab size is set to 4 characters in this file

***************************************************************************/

#include	"aes.h"
#include	"table.h"

/*
+*****************************************************************************
*			Constants/Macros/Tables
-****************************************************************************/

#define		VALIDATE_PARMS	1		/* nonzero --> check all parameters */
#define		FEISTEL			0		/* nonzero --> use Feistel version (slow) */

int  tabEnable=0;					/* are we gathering stats? */
BYTE tabUsed[256];					/* one bit per table */

#if FEISTEL
CONST		char *moduleDescription="Pedagogical C code (Feistel)";
#else
CONST		char *moduleDescription="Pedagogical C code";
#endif
CONST		char *modeString = "";

#define	P0_USED		0x01
#define	P1_USED		0x02
#define	B0_USED		0x04
#define	B1_USED		0x08
#define	B2_USED		0x10
#define	B3_USED		0x20
#define	ALL_USED	0x3F

/* number of rounds for various key sizes: 128, 192, 256 */
int			numRounds[4]= {0,ROUNDS_128,ROUNDS_192,ROUNDS_256};

#ifndef	DEBUG
#ifdef GetCodeSize
#define	DEBUG	1					/* force debug */
#endif
#endif
#include	"debug.h"				/* debug display macros */

#ifdef GetCodeSize
extern DWORD Here(DWORD x);			/* return caller's address! */
DWORD TwofishCodeStart(void) { return Here(0); };
#endif

/*
+*****************************************************************************
*
* Function Name:	TableOp
*
* Function:			Handle table use checking
*
* Arguments:		op	=	what to do	(see TAB_* defns in AES.H)
*
* Return:			TRUE --> done (for TAB_QUERY)		
*
* Notes: This routine is for use in generating the tables KAT file.
*
-****************************************************************************/
int TableOp(int op)
	{
	static int queryCnt=0;
	int i;
	switch (op)
		{
		case TAB_DISABLE:
			tabEnable=0;
			break;
		case TAB_ENABLE:
			tabEnable=1;
			break;
		case TAB_RESET:
			queryCnt=0;
			for (i=0;i<256;i++)
				tabUsed[i]=0;
			break;
		case TAB_QUERY:
			queryCnt++;
			for (i=0;i<256;i++)
				if (tabUsed[i] != ALL_USED)
					return FALSE;
			if (queryCnt < TAB_MIN_QUERY)	/* do a certain minimum number */
				return FALSE;
			break;
		}
	return TRUE;
	}


/*
+*****************************************************************************
*
* Function Name:	ParseHexDword
*
* Function:			Parse ASCII hex nibbles and fill in key/iv dwords
*
* Arguments:		bit			=	# bits to read
*					srcTxt		=	ASCII source
*					d			=	ptr to dwords to fill in
*					dstTxt		=	where to make a copy of ASCII source
*									(NULL ok)
*
* Return:			Zero if no error.  Nonzero --> invalid hex or length
*
* Notes:  Note that the parameter d is a DWORD array, not a byte array.
*	This routine is coded to work both for little-endian and big-endian
*	architectures.  The character stream is interpreted as a LITTLE-ENDIAN
*	byte stream, since that is how the Pentium works, but the conversion
*	happens automatically below. 
*
-****************************************************************************/
int ParseHexDword(int bits,CONST char *srcTxt,DWORD *d,char *dstTxt)
	{
	int i;
	DWORD b;
	char c;
#if ALIGN32
	char alignDummy[3];	/* keep dword alignment */
#endif

	union	/* make sure LittleEndian is defined correctly */
		{
		BYTE  b[4];
		DWORD d[1];
		} v;
	v.d[0]=1;
	if (v.b[0 ^ ADDR_XOR] != 1)	/* sanity check on compile-time switch */
		return BAD_ENDIAN;

#if VALIDATE_PARMS
  #if ALIGN32
	if (((int)d) & 3)
		return BAD_ALIGN32;
  #endif
#endif

	for (i=0;i*32<bits;i++)
		d[i]=0;					/* first, zero the field */

	for (i=0;i*4<bits;i++)		/* parse one nibble at a time */
		{						/* case out the hexadecimal characters */
		c=srcTxt[i];
		if (dstTxt) dstTxt[i]=c;
		if ((c >= '0') && (c <= '9'))
			b=c-'0';
		else if ((c >= 'a') && (c <= 'f'))
			b=c-'a'+10;
		else if ((c >= 'A') && (c <= 'F'))
			b=c-'A'+10;
		else
			return BAD_KEY_MAT;	/* invalid hex character */
		/* works for big and little endian! */
		d[i/8] |= b << (4*((i^1)&7));		
		}

	return 0;					/* no error */
	}


/*
+*****************************************************************************
*
* Function Name:	f32
*
* Function:			Run four bytes through keyed S-boxes and apply MDS matrix
*
* Arguments:		x			=	input to f function
*					k32			=	pointer to key dwords
*					keyLen		=	total key length (k32 --> keyLey/2 bits)
*
* Return:			The output of the keyed permutation applied to x.
*
* Notes:
*	This function is a keyed 32-bit permutation.  It is the major building
*	block for the Twofish round function, including the four keyed 8x8 
*	permutations and the 4x4 MDS matrix multiply.  This function is used
*	both for generating round subkeys and within the round function on the
*	block being encrypted.  
*
*	This version is fairly slow and pedagogical, although a smartcard would
*	probably perform the operation exactly this way in firmware.   For
*	ultimate performance, the entire operation can be completed with four
*	lookups into four 256x32-bit tables, with three dword xors.
*
*	The MDS matrix is defined in TABLE.H.  To multiply by Mij, just use the
*	macro Mij(x).
*
-****************************************************************************/
DWORD f32(DWORD x,CONST DWORD *k32,int keyLen)
	{
	BYTE  b[4];
	
	/* Run each byte thru 8x8 S-boxes, xoring with key byte at each stage. */
	/* Note that each byte goes through a different combination of S-boxes.*/

	*((DWORD *)b) = Bswap(x);	/* make b[0] = LSB, b[3] = MSB */
	switch (((keyLen + 63)/64) & 3)
		{
		case 0:		/* 256 bits of key */
			b[0] = p8(04)[b[0]] ^ b0(k32[3]);
			b[1] = p8(14)[b[1]] ^ b1(k32[3]);
			b[2] = p8(24)[b[2]] ^ b2(k32[3]);
			b[3] = p8(34)[b[3]] ^ b3(k32[3]);
			/* fall thru, having pre-processed b[0]..b[3] with k32[3] */
		case 3:		/* 192 bits of key */
			b[0] = p8(03)[b[0]] ^ b0(k32[2]);
			b[1] = p8(13)[b[1]] ^ b1(k32[2]);
			b[2] = p8(23)[b[2]] ^ b2(k32[2]);
			b[3] = p8(33)[b[3]] ^ b3(k32[2]);
			/* fall thru, having pre-processed b[0]..b[3] with k32[2] */
		case 2:		/* 128 bits of key */
			b[0] = p8(00)[p8(01)[p8(02)[b[0]] ^ b0(k32[1])] ^ b0(k32[0])];
			b[1] = p8(10)[p8(11)[p8(12)[b[1]] ^ b1(k32[1])] ^ b1(k32[0])];
			b[2] = p8(20)[p8(21)[p8(22)[b[2]] ^ b2(k32[1])] ^ b2(k32[0])];
			b[3] = p8(30)[p8(31)[p8(32)[b[3]] ^ b3(k32[1])] ^ b3(k32[0])];
		}

	if (tabEnable)
		{	/* we could give a "tighter" bound, but this works acceptably well */
		tabUsed[b0(x)] |= (P_00 == 0) ? P0_USED : P1_USED;
		tabUsed[b1(x)] |= (P_10 == 0) ? P0_USED : P1_USED;
		tabUsed[b2(x)] |= (P_20 == 0) ? P0_USED : P1_USED;
		tabUsed[b3(x)] |= (P_30 == 0) ? P0_USED : P1_USED;

		tabUsed[b[0] ] |= B0_USED;
		tabUsed[b[1] ] |= B1_USED;
		tabUsed[b[2] ] |= B2_USED;
		tabUsed[b[3] ] |= B3_USED;
		}

	/* Now perform the MDS matrix multiply inline. */
	return	((M00(b[0]) ^ M01(b[1]) ^ M02(b[2]) ^ M03(b[3]))	  ) ^
			((M10(b[0]) ^ M11(b[1]) ^ M12(b[2]) ^ M13(b[3])) <<  8) ^
			((M20(b[0]) ^ M21(b[1]) ^ M22(b[2]) ^ M23(b[3])) << 16) ^
			((M30(b[0]) ^ M31(b[1]) ^ M32(b[2]) ^ M33(b[3])) << 24) ;
	}

/*
+*****************************************************************************
*
* Function Name:	RS_MDS_Encode
*
* Function:			Use (12,8) Reed-Solomon code over GF(256) to produce
*					a key S-box dword from two key material dwords.
*
* Arguments:		k0	=	1st dword
*					k1	=	2nd dword
*
* Return:			Remainder polynomial generated using RS code
*
* Notes:
*	Since this computation is done only once per reKey per 64 bits of key,
*	the performance impact of this routine is imperceptible. The RS code
*	chosen has "simple" coefficients to allow smartcard/hardware implementation
*	without lookup tables.
*
-****************************************************************************/
DWORD RS_MDS_Encode(DWORD k0,DWORD k1)
	{
	int i,j;
	DWORD r;

	for (i=r=0;i<2;i++)
		{
		r ^= (i) ? k0 : k1;			/* merge in 32 more key bits */
		for (j=0;j<4;j++)			/* shift one byte at a time */
			RS_rem(r);				
		}
	return r;
	}

/*
+*****************************************************************************
*
* Function Name:	reKey
*
* Function:			Initialize the Twofish key schedule from key32
*
* Arguments:		key			=	ptr to keyInstance to be initialized
*
* Return:			TRUE on success
*
* Notes:
*	Here we precompute all the round subkeys, although that is not actually
*	required.  For example, on a smartcard, the round subkeys can 
*	be generated on-the-fly	using f32()
*
-****************************************************************************/
int reKey(keyInstance *key)
	{
	int		i,k64Cnt;
	int		keyLen	  = key->keyLen;
	int		subkeyCnt = ROUND_SUBKEYS + 2*key->numRounds;
	DWORD	A,B;
	DWORD	k32e[MAX_KEY_BITS/64],k32o[MAX_KEY_BITS/64]; /* even/odd key dwords */

#if VALIDATE_PARMS
  #if ALIGN32
	if ((((int)key) & 3) || (((int)key->key32) & 3))
		return BAD_ALIGN32;
  #endif
	if ((key->keyLen % 64) || (key->keyLen < MIN_KEY_BITS))
		return BAD_KEY_INSTANCE;
	if (subkeyCnt > TOTAL_SUBKEYS)
		return BAD_KEY_INSTANCE;
#endif

	k64Cnt=(keyLen+63)/64;		/* round up to next multiple of 64 bits */
	for (i=0;i<k64Cnt;i++)
		{						/* split into even/odd key dwords */
		k32e[i]=key->key32[2*i  ];
		k32o[i]=key->key32[2*i+1];
		/* compute S-box keys using (12,8) Reed-Solomon code over GF(256) */
		key->sboxKeys[k64Cnt-1-i]=RS_MDS_Encode(k32e[i],k32o[i]); /* reverse order */
		}

	for (i=0;i<subkeyCnt/2;i++)					/* compute round subkeys for PHT */
		{
		A = f32(i*SK_STEP        ,k32e,keyLen);	/* A uses even key dwords */
		B = f32(i*SK_STEP+SK_BUMP,k32o,keyLen);	/* B uses odd  key dwords */
		B = ROL(B,8);
		key->subKeys[2*i  ] = A+  B;			/* combine with a PHT */
		key->subKeys[2*i+1] = ROL(A+2*B,SK_ROTL);
		}

	DebugDumpKey(key);

	return TRUE;
	}
/*
+*****************************************************************************
*

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产91高潮流白浆在线麻豆 | 粉嫩一区二区三区在线看| 成人av网站在线| 欧美一区午夜视频在线观看| 国产精品卡一卡二卡三| 久久99久国产精品黄毛片色诱| 在线观看av一区| 国产精品视频一二三区| 激情六月婷婷久久| 欧美军同video69gay| 亚洲日本免费电影| 成人午夜伦理影院| 久久毛片高清国产| 久久丁香综合五月国产三级网站| 欧美网站一区二区| 亚洲免费观看高清完整版在线观看熊 | 日韩欧美中文字幕精品| 一区二区三区小说| av电影在线观看不卡| 国产嫩草影院久久久久| 久久se精品一区精品二区| 欧美一区二区三区免费在线看| 一级中文字幕一区二区| 色菇凉天天综合网| 日韩一区在线播放| 91免费在线视频观看| 亚洲欧洲日产国产综合网| 成人黄色片在线观看| 一区二区三区在线免费| 成人综合婷婷国产精品久久免费| 久久久久久久综合狠狠综合| 精品一二三四区| 精品国产污网站| 国产一区不卡在线| 国产日韩亚洲欧美综合| 成人久久18免费网站麻豆| 欧美高清在线视频| 91色.com| 亚洲成人动漫一区| 欧美一区二区三区日韩| 麻豆成人av在线| 久久久青草青青国产亚洲免观| 国产一区二区三区高清播放| 国产人久久人人人人爽| www.亚洲精品| 亚洲一区二区三区四区在线| 欧美色网站导航| 首页国产欧美日韩丝袜| 精品国产乱码久久久久久浪潮| 国产一区二区三区视频在线播放| 中文字幕欧美日本乱码一线二线| 99久久精品99国产精品| 亚洲成人自拍偷拍| 欧美www视频| 不卡的电视剧免费网站有什么| 亚洲欧美国产毛片在线| 欧美日韩mp4| 国内一区二区在线| 亚洲日本va在线观看| 欧美区在线观看| 国产精选一区二区三区| 伊人色综合久久天天人手人婷| 欧美高清视频在线高清观看mv色露露十八 | 91网上在线视频| 日日骚欧美日韩| 日本一区二区三区电影| 欧美日韩在线免费视频| 狠狠色丁香九九婷婷综合五月| 中文字幕日韩av资源站| 欧美一区二区日韩一区二区| 东方欧美亚洲色图在线| 无码av中文一区二区三区桃花岛| 欧美精品一区二区蜜臀亚洲| 91网址在线看| 国产在线看一区| 一区二区三区精品| 国产亚洲福利社区一区| 在线不卡一区二区| 成人av免费观看| 免费在线观看成人| 一区二区三区蜜桃| 国产色一区二区| 日韩视频在线永久播放| 色综合久久综合网欧美综合网| 激情av综合网| 丝袜国产日韩另类美女| 亚洲精品写真福利| 中文一区在线播放| 久久这里只有精品6| 4hu四虎永久在线影院成人| 97久久超碰国产精品| 国产一区二区精品在线观看| 日韩国产欧美视频| 亚洲一区二区三区免费视频| 国产精品全国免费观看高清| 日韩一区二区三区视频在线| 欧洲亚洲国产日韩| 99国产欧美另类久久久精品| 国产一区二区毛片| 激情综合色综合久久综合| 五月天视频一区| 亚洲一二三四在线| 一区二区在线观看视频在线观看| 亚洲国产精品传媒在线观看| 久久日韩粉嫩一区二区三区| 欧美成人video| 精品美女一区二区三区| 日韩一区二区三区免费看| 欧美高清视频www夜色资源网| 欧美亚洲国产bt| 在线影院国内精品| 91视视频在线观看入口直接观看www | 亚洲国产精品久久一线不卡| 亚洲视频每日更新| 中文字幕在线不卡一区二区三区| 欧美国产乱子伦| 国产精品欧美久久久久无广告| 久久九九久久九九| 国产欧美精品一区二区色综合朱莉| 26uuu精品一区二区| 精品国产一区二区三区忘忧草 | 色94色欧美sute亚洲线路二 | 亚洲桃色在线一区| 一二三四区精品视频| 亚洲午夜一区二区三区| 天天综合网天天综合色| 久久疯狂做爰流白浆xx| 国产精品综合一区二区三区| 国产精品白丝av| 99热在这里有精品免费| 欧美色爱综合网| 日韩欧美国产三级电影视频| 久久久久久久久久电影| 中文字幕第一区第二区| 亚洲精品一二三区| 青青草97国产精品免费观看无弹窗版| 日本sm残虐另类| 成人性色生活片| 欧亚洲嫩模精品一区三区| 欧美一区二区三区视频在线| 亚洲精品一区二区精华| 国产精品美女久久久久久久久| 一区二区三区欧美在线观看| 男人操女人的视频在线观看欧美| 国产一区二区三区免费播放| 99re这里都是精品| 欧美久久久久久久久久| 国产欧美日韩在线视频| 一二三四社区欧美黄| 国内久久婷婷综合| 色狠狠av一区二区三区| wwwwww.欧美系列| 亚洲免费伊人电影| 久久99深爱久久99精品| 91啦中文在线观看| 久久综合色综合88| 一区二区三区国产精华| 国产美女av一区二区三区| 色94色欧美sute亚洲线路二| 久久久蜜桃精品| 午夜不卡av免费| 95精品视频在线| 亚洲精品一区二区三区精华液| 一区二区三区免费网站| 国产精品自在在线| 91精品婷婷国产综合久久| 中文字幕av在线一区二区三区| 日本aⅴ亚洲精品中文乱码| 成人高清免费在线播放| 欧美成va人片在线观看| 亚洲一区二区三区在线| av一区二区三区黑人| 精品久久久久一区| 午夜激情一区二区三区| 色欧美片视频在线观看| 国产日韩欧美精品一区| 日本亚洲一区二区| 91高清视频在线| 国产精品国产三级国产普通话蜜臀| 日韩不卡一区二区三区 | 91精品国产综合久久久久久久| 日韩毛片在线免费观看| 国产经典欧美精品| 精品国产亚洲在线| 蜜臂av日日欢夜夜爽一区| 精品视频一区 二区 三区| 国产精品初高中害羞小美女文| 国产精品一区二区久久不卡| 欧美一区二区三区系列电影| 亚洲午夜激情av| 色先锋aa成人| 亚洲区小说区图片区qvod| av影院午夜一区| 综合分类小说区另类春色亚洲小说欧美 | 91精品国产综合久久精品图片| 午夜婷婷国产麻豆精品| 欧美日韩精品欧美日韩精品| 一区二区国产视频| 欧美色综合天天久久综合精品| 亚洲高清免费在线|