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

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

?? cryptmch.c

?? 提供了很多種加密算法和CA認證及相關服務如CMP、OCSP等的開發
?? C
?? 第 1 頁 / 共 4 頁
字號:
/****************************************************************************
*																			*
*						  cryptlib Mechanism Routines						*
*						Copyright Peter Gutmann 1992-2002					*
*																			*
****************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "crypt.h"
#ifdef INC_ALL
  #include "asn1.h"
  #include "asn1objs.h"
  #include "pgp.h"
#else
  #include "keymgmt/asn1.h"
  #include "keymgmt/asn1objs.h"
  #include "envelope/pgp.h"
#endif /* Compiler-specific includes */

/****************************************************************************
*																			*
*								Utility Routines							*
*																			*
****************************************************************************/

/* The length of the input data for PKCS #1 transformations is usually
   determined by the key size, however sometimes we can be passed data which
   has been zero-padded (for example data coming from an ASN.1 INTEGER in
   which the high bit is a sign bit) making it longer than the key size, or
   which has zero high byte(s), making it shorter than the key size.  The
   best place to handle this is somewhat uncertain, it's an encoding issue
   so it probably shouldn't be visible to the raw crypto routines, but
   putting it at the mechanism layer removes the algorithm-independence of
   that layer, and putting it at the mid-level sign/key-exchange routine
   layer both removes the algorithm-independence and requires duplication of
   the code for signatures and encryption.  The best place to put it seems to
   be at the mechanism layer, since an encoding issue really shouldn't be
   visible at the crypto layer, and because it would require duplicating the
   handling every time a new PKC implementation is plugged in.

   The intent of the size adjustment is to make the data size match the key
   length.  If it's longer, we try to strip leading zero bytes.  If it's
   shorter, we pad it with zero bytes to match the key size.  The result is
   either the data adjusted to match the key size, or CRYPT_ERROR_BADDATA if
   this isn't possible */

static int adjustPKCS1Data( BYTE *outData, const BYTE *inData,
							const int inLength, const int keySize )
	{
	int length = inLength;

	assert( outData != inData );

	/* If it's suspiciously short, don't try and process it */
	if( length < 56 )
		return( CRYPT_ERROR_BADDATA );

	/* If it's of the correct size, exit */
	if( length == keySize )
		{
		memcpy( outData, inData, keySize );
		return( CRYPT_OK );
		}

	/* If it's too long, try and strip leading zero bytes.  If it's still too
	   long, complain */
	while( length > keySize && !*inData )
		{
		length--;
		inData++;
		}
	if( length > keySize )
		return( CRYPT_ERROR_BADDATA );

	/* We've adjusted the size to account for zero-padding during encoding,
	   now we have to move the data into a fixed-length format to match the
	   key size.  To do this we copy the payload into the output buffer with
	   enough leading-zero bytes to bring the total size up to the key size */
	memset( outData, 0, keySize );
	memcpy( outData + ( keySize - length ), inData, length );

	return( CRYPT_OK );
	}

/* PGP checksums the PKCS #1 wrapped data (even though this doesn't really
   serve any purpose), the following routine calculates this checksum and
   either appends it to the data or checks it against the stored value */

static BOOLEAN calculatePGPchecksum( BYTE *dataPtr, const int length,
									 const BOOLEAN writeChecksum )
	{
	BYTE *checksumPtr = dataPtr + length;
	int checksum = 0, i;

	for( i = 0; i < length; i++ )
		checksum += dataPtr[ i ];
	if( !writeChecksum )
		{
		int storedChecksum = mgetBWord( checksumPtr );

		return( storedChecksum == checksum );
		}
	mputBWord( checksumPtr, checksum );
	return( TRUE );
	}

/* PGP includes the session key information alongside the encrypted key so
   it's not really possible to import the key into a context in the
   conventional sense.  Instead, the import code has to create the context
   as part of the import process and return it to the caller.  This is ugly,
   but less ugly than doing a raw import and handling the key directly in
   the calling code */

static int extractPGPKey( CRYPT_CONTEXT *iCryptContext, STREAM *stream,
						  const int length )
	{
	CRYPT_ALGO cryptAlgo = CRYPT_ALGO_NONE;
	MESSAGE_CREATEOBJECT_INFO createInfo;
	static const CRYPT_MODE mode = CRYPT_MODE_CFB;
	const int pgpAlgoID = sgetc( stream );
	int status;

	/* Get the session key algorithm.  We delay checking the algorithm ID
	   until after the checksum calculation to reduce the chance of being
	   used as an oracle */
	switch( pgpAlgoID )
		{
		case PGP_ALGO_3DES:
			cryptAlgo = CRYPT_ALGO_3DES;
			break;

		case PGP_ALGO_BLOWFISH:
			cryptAlgo = CRYPT_ALGO_BLOWFISH;
			break;

		case PGP_ALGO_CAST5:
			cryptAlgo = CRYPT_ALGO_CAST;
			break;

		case PGP_ALGO_IDEA:
			cryptAlgo = CRYPT_ALGO_IDEA;
			break;

		case PGP_ALGO_AES_128:
		case PGP_ALGO_AES_192:
		case PGP_ALGO_AES_256:
			cryptAlgo = CRYPT_ALGO_AES;
		}

	/* Checksum the session key (this is actually superfluous since any
	   decryption error will be caught by corrupted PKCS #1 padding with
	   vastly higher probability than this simple checksum, but we do it
	   anyway because PGP does it too */
	if( !calculatePGPchecksum( sMemBufPtr( stream ), length, FALSE ) )
		return( CRYPT_ERROR_BADDATA );

	/* Make sure the algorithm ID is valid.  We only perform the check at
	   this point because this returns a different error code than the usual
	   bad-data, we want to be absolutely sure that the problem really is an
	   unknown algorithm and not the result of scrambled decrypted data */
	if( cryptAlgo == CRYPT_ALGO_NONE )
		return( CRYPT_ERROR_NOTAVAIL );

	/* Create the context and load the key into it */
	setMessageCreateObjectInfo( &createInfo, cryptAlgo );
	status = krnlSendMessage( SYSTEM_OBJECT_HANDLE,
							  RESOURCE_IMESSAGE_DEV_CREATEOBJECT,
							  &createInfo, OBJECT_TYPE_CONTEXT );
	if( cryptStatusError( status ) )
		return( status );
	krnlSendMessage( createInfo.cryptHandle, RESOURCE_IMESSAGE_SETATTRIBUTE,
					 ( void * ) &mode, CRYPT_CTXINFO_MODE );
	*iCryptContext = createInfo.cryptHandle;

	return( CRYPT_OK );
	}

/****************************************************************************
*																			*
*							Key Derivation Mechanisms						*
*																			*
****************************************************************************/

/* HMAC-based PRF used for PKCS #5 v2 and TLS */

#define HMAC_DATASIZE		64

static void prfInit( HASHFUNCTION hashFunction, void *hashState,
					 const int hashSize, void *processedKey,
					 int *processedKeyLength, const void *key,
					 const int keyLength )
	{
	BYTE hashBuffer[ HMAC_DATASIZE ], *keyPtr = processedKey;
	int i;

	/* If the key size is larger than tha SHA data size, reduce it to the
	   SHA hash size before processing it (yuck.  You're required to do this
	   though) */
	if( keyLength > HMAC_DATASIZE )
		{
		/* Hash the user key down to the hash size and use the hashed form of
		   the key */
		hashFunction( NULL, processedKey, ( void * ) key, keyLength, HASH_ALL );
		*processedKeyLength = hashSize;
		}
	else
		{
		/* Copy the key to internal storage */
		memcpy( processedKey, key, keyLength );
		*processedKeyLength = keyLength;
		}

	/* Perform the start of the inner hash using the zero-padded key XOR'd
	   with the ipad value */
	memset( hashBuffer, HMAC_IPAD, HMAC_DATASIZE );
	for( i = 0; i < *processedKeyLength; i++ )
		hashBuffer[ i ] ^= *keyPtr++;
	hashFunction( hashState, NULL, hashBuffer, HMAC_DATASIZE, HASH_START );
	zeroise( hashBuffer, HMAC_DATASIZE );
	}

static void prfEnd( HASHFUNCTION hashFunction, void *hashState,
					const int hashSize, void *hash,
					const void *processedKey, const int processedKeyLength )
	{
	BYTE hashBuffer[ HMAC_DATASIZE ], digestBuffer[ CRYPT_MAX_HASHSIZE ];
	int i;

	/* Complete the inner hash and extract the digest */
	hashFunction( hashState, digestBuffer, NULL, 0, HASH_END );

	/* Perform the outer hash using the zero-padded key XOR'd with the opad
	   value followed by the digest from the inner hash */
	memset( hashBuffer, HMAC_OPAD, HMAC_DATASIZE );
	memcpy( hashBuffer, processedKey, processedKeyLength );
	for( i = 0; i < processedKeyLength; i++ )
		hashBuffer[ i ] ^= HMAC_OPAD;
	hashFunction( hashState, NULL, hashBuffer, HMAC_DATASIZE, HASH_START );
	zeroise( hashBuffer, HMAC_DATASIZE );
	hashFunction( hashState, hash, digestBuffer, hashSize, HASH_END );
	zeroise( digestBuffer, CRYPT_MAX_HASHSIZE );
	}

/* Perform PKCS #5 v2 derivation */

int derivePKCS5( void *dummy, MECHANISM_DERIVE_INFO *mechanismInfo )
	{
	HASHFUNCTION hashFunction;
	BYTE hashInfo[ MAX_HASHINFO_SIZE ], initialHashInfo[ MAX_HASHINFO_SIZE ];
	BYTE processedKey[ HMAC_DATASIZE ], block[ CRYPT_MAX_HASHSIZE ];
	BYTE countBuffer[ 4 ];
	BYTE *dataOutPtr = mechanismInfo->dataOut;
	int hashSize, keyIndex, processedKeyLength, blockCount = 1;

	UNUSED( dummy );

	/* Set up the block counter buffer.  This will never have more than the
	   last few bits set (8 bits = 5100 bytes of key) so we only change the
	   last byte */
	memset( countBuffer, 0, 4 );

	/* Initialise the SHA-1 information with the user key.  This is reused
	   for any future hashing since it's constant */
	getHashParameters( mechanismInfo->hashAlgo, &hashFunction, &hashSize );
	prfInit( hashFunction, initialHashInfo, hashSize,
			 processedKey, &processedKeyLength,
			 mechanismInfo->dataIn, mechanismInfo->dataInLength );

	/* Produce enough blocks of output to fill the key */
	for( keyIndex = 0; keyIndex < mechanismInfo->dataOutLength;
		 keyIndex += hashSize, dataOutPtr += hashSize )
		{
		const int noKeyBytes = \
			( mechanismInfo->dataOutLength - keyIndex > hashSize ) ? \
			hashSize : mechanismInfo->dataOutLength - keyIndex;
		int i;

		/* Calculate HMAC( salt || counter ) */
		countBuffer[ 3 ] = ( BYTE ) blockCount++;
		memcpy( hashInfo, initialHashInfo, MAX_HASHINFO_SIZE );
		hashFunction( hashInfo, NULL, mechanismInfo->salt,
					  mechanismInfo->saltLength, HASH_CONTINUE );
		hashFunction( hashInfo, NULL, countBuffer, 4, HASH_CONTINUE );
		prfEnd( hashFunction, hashInfo, hashSize, block, processedKey,
				processedKeyLength );
		memcpy( dataOutPtr, block, noKeyBytes );

		/* Calculate HMAC( T1 ) ^ HMAC( T1 ) ^ ... HMAC( Tc ) */
		for( i = 0; i < mechanismInfo->iterations - 1; i++ )
			{
			int j;

			/* Generate the PRF output for the current iteration */
			memcpy( hashInfo, initialHashInfo, MAX_HASHINFO_SIZE );
			hashFunction( hashInfo, NULL, block, hashSize, HASH_CONTINUE );
			prfEnd( hashFunction, hashInfo, hashSize, block, processedKey,
					processedKeyLength );

			/* Xor the new PRF output into the existing PRF output */
			for( j = 0; j < noKeyBytes; j++ )
				dataOutPtr[ j ] ^= block[ j ];
			}
		}
	zeroise( hashInfo, MAX_HASHINFO_SIZE );
	zeroise( initialHashInfo, MAX_HASHINFO_SIZE );
	zeroise( processedKey, HMAC_DATASIZE );
	zeroise( block, CRYPT_MAX_HASHSIZE );

	return( CRYPT_OK );
	}

/* Perform SSL key derivation */

int deriveSSL( void *dummy, MECHANISM_DERIVE_INFO *mechanismInfo )
	{
	HASHFUNCTION md5HashFunction, shaHashFunction;
	BYTE hashInfo[ MAX_HASHINFO_SIZE ], hash[ CRYPT_MAX_HASHSIZE ];
	BYTE counterData[ 16 ];
	int md5HashSize, shaHashSize, counter = 0, keyIndex;

	UNUSED( dummy );

	getHashParameters( CRYPT_ALGO_MD5, &md5HashFunction, &md5HashSize );
	getHashParameters( CRYPT_ALGO_SHA, &shaHashFunction, &shaHashSize );

	/* Produce enough blocks of output to fill the key */
	for( keyIndex = 0; keyIndex < mechanismInfo->dataOutLength;
		 keyIndex += md5HashSize )
		{
		const int noKeyBytes = \
			( mechanismInfo->dataOutLength - keyIndex > md5HashSize ) ? \
			md5HashSize : mechanismInfo->dataOutLength - keyIndex;
		int i;

		/* Set up the counter data */
		for( i = 0; i <= counter; i++ )
			counterData[ i ] = 'A' + counter;
		counter++;

		/* Calculate SHA1( 'A'/'BB'/'CCC'/... || keyData || salt ) */
		shaHashFunction( hashInfo, NULL, counterData, counter, HASH_START );
		shaHashFunction( hashInfo, NULL, mechanismInfo->dataIn,
						 mechanismInfo->dataInLength, HASH_CONTINUE );
		shaHashFunction( hashInfo, hash, mechanismInfo->salt,
						 mechanismInfo->saltLength, HASH_END );

		/* Calculate MD5( keyData || SHA1-hash ) */
		md5HashFunction( hashInfo, NULL, mechanismInfo->dataIn,
						 mechanismInfo->dataInLength, HASH_START );
		md5HashFunction( hashInfo, hash, hash, shaHashSize, HASH_END );

		/* Copy the result to the output */
		memcpy( ( BYTE * )( mechanismInfo->dataOut ) + keyIndex, hash, noKeyBytes );
		}
	zeroise( hashInfo, MAX_HASHINFO_SIZE );
	zeroise( hash, CRYPT_MAX_HASHSIZE );

	return( CRYPT_OK );
	}

/* Perform TLS key derivation (this is the function described as PRF() in the
   TLS spec */

int deriveTLS( void *dummy, MECHANISM_DERIVE_INFO *mechanismInfo )
	{
	HASHFUNCTION md5HashFunction, shaHashFunction;
	BYTE md5HashInfo[ MAX_HASHINFO_SIZE ];
	BYTE md5InitialHashInfo[ MAX_HASHINFO_SIZE ];
	BYTE md5AnHashInfo[ MAX_HASHINFO_SIZE ];
	BYTE shaHashInfo[ MAX_HASHINFO_SIZE ];
	BYTE shaInitialHashInfo[ MAX_HASHINFO_SIZE ];
	BYTE shaAnHashInfo[ MAX_HASHINFO_SIZE ];
	BYTE md5ProcessedKey[ HMAC_DATASIZE ], shaProcessedKey[ HMAC_DATASIZE ];
	BYTE md5A[ CRYPT_MAX_HASHSIZE ], shaA[ CRYPT_MAX_HASHSIZE ];
	BYTE md5Hash[ CRYPT_MAX_HASHSIZE ], shaHash[ CRYPT_MAX_HASHSIZE ];
	BYTE *md5DataOutPtr = mechanismInfo->dataOut;
	BYTE *shaDataOutPtr = mechanismInfo->dataOut;
	const BYTE *dataEndPtr = ( BYTE * ) mechanismInfo->dataOut + \
							 mechanismInfo->dataOutLength;
	const void *s1, *s2;
	const int sLen = ( mechanismInfo->dataInLength + 1 ) / 2;
	int md5ProcessedKeyLength, shaProcessedKeyLength;
	int md5HashSize, shaHashSize, counter = 0, keyIndex;

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日本欧美韩国一区三区| 欧美久久一区二区| 欧美午夜不卡视频| 亚洲日本护士毛茸茸| 丝袜国产日韩另类美女| 国产寡妇亲子伦一区二区| 在线免费观看视频一区| 久久蜜桃av一区精品变态类天堂 | 亚洲欧洲av在线| 日本伊人色综合网| 日本韩国精品在线| 欧美极品少妇xxxxⅹ高跟鞋| 婷婷开心激情综合| 色综合天天综合| 国产色一区二区| 男女性色大片免费观看一区二区 | 亚洲一区二区三区美女| 风间由美一区二区av101| 7777精品伊人久久久大香线蕉的 | 久久亚洲影视婷婷| 日本欧洲一区二区| 日本乱人伦aⅴ精品| 欧美极品xxx| 国产盗摄精品一区二区三区在线 | 久久色在线观看| 国产精品自拍一区| 日韩一卡二卡三卡| 日韩不卡手机在线v区| 欧美综合欧美视频| 亚洲综合激情另类小说区| 福利视频网站一区二区三区| 欧美精品一区二区不卡| 麻豆一区二区在线| 欧美成人三级在线| 麻豆成人91精品二区三区| 欧美高清你懂得| 日韩精品一级二级| 日韩一级大片在线| 国产资源在线一区| 欧美精品一区二区三区高清aⅴ | 欧美日韩精品福利| 香蕉久久一区二区不卡无毒影院| 色菇凉天天综合网| 亚洲成人黄色影院| 欧美一区二区三区视频免费播放| 亚洲a一区二区| 91精品国产综合久久久久久久久久 | 99久久精品一区二区| 亚洲欧洲日本在线| 欧美最猛性xxxxx直播| 天天综合色天天综合色h| 欧美精品一级二级| 国内国产精品久久| 中文字幕成人av| 日本高清不卡一区| 日本亚洲电影天堂| 久久精品视频免费| 91浏览器在线视频| 日本成人中文字幕在线视频| 精品国产一区二区三区久久久蜜月 | 国产精品毛片无遮挡高清| av在线播放成人| 亚洲高清视频的网址| 日韩一卡二卡三卡| 成人免费视频caoporn| 亚洲综合一区二区| 欧美mv和日韩mv的网站| 成人禁用看黄a在线| 亚洲v日本v欧美v久久精品| 精品三级在线观看| 欧美在线三级电影| 麻豆精品新av中文字幕| 中文字幕乱码一区二区免费| 在线观看免费成人| 国产成人综合在线| 亚洲一区二区欧美激情| 欧美精品一区在线观看| 欧美综合久久久| 国产精品亚洲专一区二区三区 | 亚洲精品一区二区三区香蕉| 一本色道久久综合亚洲91 | 成人天堂资源www在线| 亚洲高清免费在线| 国产精品久久看| 日韩一级黄色片| 91久久国产最好的精华液| 国产在线不卡一卡二卡三卡四卡| 一区二区三区四区不卡在线| www久久精品| 在线播放中文字幕一区| 99精品国产91久久久久久| 九色综合狠狠综合久久| 亚洲一级片在线观看| 国产精品毛片高清在线完整版| 欧美日韩欧美一区二区| 91丨porny丨国产入口| 国产麻豆精品在线| 热久久国产精品| 亚洲一区二区精品久久av| 亚洲欧洲在线观看av| 久久日韩粉嫩一区二区三区 | 99久久国产免费看| 国产精品99久久久| 国产自产视频一区二区三区| 人人狠狠综合久久亚洲| 天天综合天天综合色| 亚洲高清久久久| 亚洲自拍偷拍图区| 一区二区成人在线| 亚洲欧洲综合另类在线 | 精品日韩99亚洲| 欧美三区免费完整视频在线观看| 99精品欧美一区二区蜜桃免费| 国产麻豆精品95视频| 韩日av一区二区| 精品一区二区三区免费| 国产在线播放一区三区四| 裸体一区二区三区| 久久99热国产| 国产一区不卡精品| 懂色av一区二区三区免费观看| 国产剧情一区在线| 国产精品一区二区在线观看不卡| 欧美综合天天夜夜久久| 一本大道av伊人久久综合| 色婷婷av一区二区三区之一色屋| 色综合久久综合网97色综合| 一本一道久久a久久精品 | 国产一区二区精品久久| 国产精品中文字幕日韩精品| 风间由美一区二区三区在线观看 | 国产精品无人区| 亚洲欧洲精品一区二区三区| 亚洲欧美一区二区三区久本道91 | 国产欧美精品国产国产专区| 欧美激情一区二区三区全黄| 综合亚洲深深色噜噜狠狠网站| 一区二区三区久久久| 天天亚洲美女在线视频| 九色综合国产一区二区三区| 国产99久久久国产精品免费看| av日韩在线网站| 欧美色精品天天在线观看视频| 欧美日韩高清在线播放| 精品国产精品一区二区夜夜嗨 | 欧美一级片在线| 欧美精品一区二区高清在线观看 | 日韩精品一区二区在线观看| 国产欧美一区在线| 一区二区久久久久| 韩日欧美一区二区三区| 色悠悠久久综合| 日韩久久久久久| 综合中文字幕亚洲| 91在线观看一区二区| 欧美精品一二三| 中文字幕不卡三区| 婷婷国产在线综合| 成人免费视频网站在线观看| 欧美日韩国产中文| 国产精品色呦呦| 日韩激情视频网站| 顶级嫩模精品视频在线看| 欧美日韩在线播放一区| 国产三级精品在线| 日日嗨av一区二区三区四区| 成人激情校园春色| 精品欧美久久久| 亚洲一区二区三区激情| 国产成人精品免费看| 欧美日韩一区二区三区视频| 欧美极品aⅴ影院| 久久精品国产澳门| 欧美亚洲综合在线| 国产精品国产a| 国产尤物一区二区在线| 欧美三级午夜理伦三级中视频| 国产精品视频观看| 蜜桃av噜噜一区二区三区小说| 色婷婷综合在线| 久久美女高清视频| 日韩电影在线一区二区| 91成人免费网站| 国产精品久久久久久久久晋中 | 日本一区二区三区高清不卡| 日韩和欧美一区二区| 91成人在线精品| 日韩毛片高清在线播放| 国产在线视频一区二区| 884aa四虎影成人精品一区| 一区二区三区av电影| 99国产精品视频免费观看| 国产午夜久久久久| 国产一区二区网址| 精品国内二区三区| 久久精品国产亚洲高清剧情介绍| 欧美日韩视频专区在线播放| 一区二区三区精品在线观看| 色婷婷亚洲精品| 亚洲乱码中文字幕|