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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? aes_driver.c

?? ATMEL XMEGA crypto program-task4.
?? C
?? 第 1 頁 / 共 2 頁
字號:
}



/*! \brief  Polled function that does an AES decryption on one 128-bit data block.
 *
 *  \note This code is blocking and will dead lock if no interrupt flags are set.
 *
 *  \param  ciphertext  Pointer to the ciphertext that shall be decrypted
 *  \param  plaintext   Pointer to where in memory the plaintext (answer) shall be stored.
 *  \param  key         Pointer to the DES key
 *
 *  \retval true   If the AES decryption was successful.
 *  \retval false  If the AES decryption was not successful.
 */
bool AES_decrypt(uint8_t * ciphertext, uint8_t * plaintext,
                 uint8_t * key)
{
  	bool decrypt_ok;

	/* Load key into AES key memory. */
	uint8_t * temp_key = key;
	for(uint8_t i = 0; i < AES_BLOCK_LENGTH; i++){
		AES.KEY =  *(temp_key++);
	}

	/* Load data into AES state memory. */
	uint8_t * temp_ciphertext = ciphertext;
	for(uint8_t i = 0; i < AES_BLOCK_LENGTH; i++){
		AES.STATE =  *(temp_ciphertext++);
	}

	/* Set AES in decryption mode and start the AES.*/
	AES.CTRL |= (AES_START_bm | AES_DECRYPT_bm);

	do{
		/* Wait until AES is finished or an error occurs. */
	}while((AES.STATUS & (AES_SRIF_bm|AES_ERROR_bm) ) == 0);

	/* If not error. */
	if((AES.STATUS & AES_ERROR_bm) == 0){
		/* Store the result. */
		uint8_t * temp_plaintext = plaintext;
		for(uint8_t i = 0; i < AES_BLOCK_LENGTH; i++){
			*(temp_plaintext++) = AES.STATE;
		}
		decrypt_ok = true;
	}else{
		decrypt_ok = false;

	}
	return decrypt_ok;
}




/*! \brief  Polled function that generates the last subkey of the Expanded Key
 *          needed during decryption.
 *
 *  \note This code is blocking and will dead lock if no interrupt flags are set.
 *
 *  \param  key           Pointer to AES key.
 *  \param  last_sub_key  Pointer to where the last subkey of the Expanded Key
 *                        shall be stored.
 *
 *  \retval true   If generating the last subkey was successful.
 *  \retval false  If generating the last subkey was not successful.
 */
bool AES_lastsubkey_generate(uint8_t * key, uint8_t * last_sub_key)
{
	bool keygen_ok;
	AES_software_reset();

	/* Load key into AES key memory. */
	uint8_t * temp_key = key;
	for(uint8_t i = 0; i < AES_BLOCK_LENGTH; i++){
		AES.KEY =  *(temp_key++);
	}

	/* Load dummy data into AES state memory. */
	for(uint8_t i = 0; i < AES_BLOCK_LENGTH; i++){
		AES.STATE =  0x00;
	}

	/* Set AES in encryption mode and start AES. */
	AES.CTRL = (AES.CTRL & (~AES_DECRYPT_bm)) | AES_START_bm;


	do{
		/* Wait until AES is finished or an error occurs. */
	}while((AES.STATUS & (AES_SRIF_bm|AES_ERROR_bm) ) == 0);

	/* If not error. */
	if((AES.STATUS & AES_ERROR_bm) == 0){
		/* Store the last subkey. */
		uint8_t * temp_last_sub_key = last_sub_key;
		for(uint8_t i = 0; i < AES_BLOCK_LENGTH; i++){
			*(temp_last_sub_key++) = AES.KEY;
		}
		AES.STATUS = AES_SRIF_bm;
		keygen_ok = true;
	}else{
		AES.STATUS = AES_ERROR_bm;
		keygen_ok = false;

	}
	return keygen_ok;
}



/*! \brief  Polled function that does AES CBC encryption on a given number of
 *           128-bit data block.
 *
 *  \note This code is blocking and will dead lock if no interrupt flags are set.
 *
 *  \param  plaintext    Pointer to the plaintext that shall be encrypted.
 *  \param  ciphertext   Pointer to where in memory the ciphertext (answer) shall be stored.
 *  \param  key          Pointer to the key.
 *  \param  init	        Pointer to the initialization vector used in the CBC.
 *  \param  block_count  The number of blocks to encrypt.
 *
 *	\retval true:	The AES CBC encryption was successful.
 *  \retval false:  The AES CBC encryption was not successful.
 */
bool AES_CBC_encrypt(uint8_t * plaintext, uint8_t * ciphertext,
                     uint8_t * key, uint8_t * init, uint16_t block_count)
{
  	bool CBC_ok = true;

  	/* The first encryption uses the initialization vector. */
	uint8_t * temp_init = init;
	for(uint8_t i = 0; i < AES_BLOCK_LENGTH; i++){
		AES.STATE =  *(temp_init++);
	}

	/* Set AES in encryption mode and enables the XOR feature and the AUTO start
	 * mode. */
	AES.CTRL = (AES.CTRL & (~AES_DECRYPT_bm))| AES_XOR_bm |AES_AUTO_bm;

	/* Temporary values used to reduce memory access. */
	uint8_t * temp_plaintext = plaintext;
	uint8_t * temp_ciphertext = ciphertext;

	for(uint8_t blocks_left = block_count; blocks_left > 0; blocks_left--){

		/* Load key into AES key memory. */
		uint8_t * temp_key = key;
		for(uint8_t i = 0; i < AES_BLOCK_LENGTH; i++){
			AES.KEY =  *(temp_key++);
		}

		/* Load plaintext into AES state memory. Auto starts. */
		for(uint8_t i = 0; i < AES_BLOCK_LENGTH; i++){
			AES.STATE =  *(temp_plaintext++);
		}


		do{
			/* Wait until AES is finished or an error occurs. */
		}while((AES.STATUS & (AES_SRIF_bm|AES_ERROR_bm) ) == 0);

		/* If not error. */
		if((AES.STATUS & AES_ERROR_bm) == 0){

			/* Store result. */
			uint8_t * temp = temp_ciphertext;
			for(uint8_t i = 0; i < AES_BLOCK_LENGTH; i++){
				*(temp++) = AES.STATE;
			}
			temp_ciphertext = temp;
		}else{
			CBC_ok = false;
		}
	}

	/* Turn off auto mode and xor feature. */
	AES.CTRL = (AES.CTRL & ~( AES_XOR_bm |AES_AUTO_bm));

	return CBC_ok;
}



/*! \brief  Polled function that does AES CBC decryption on a given number of
 *           128-bit data block.
 *
 *  \note This code is blocking and will dead lock if no interrupt flags are set.
 *
 *  \param  ciphertext   Pointer to the ciphertext that shall be decrypted.
 *  \param  plaintext    Pointer to where the plaintext (answer) shall be stored.
 *  \param  key          Pointer to the last subkey of the Expanded Key.
 *  \param  init	        Pointer to the initialization vector used in the CBC.
 *  \param  block_count  The number of blocks to decrypt.
 *
 *  \retval true   If the AES CBC decryption was successful.
 *  \retval false  If the AES CBC decryption was not successful.
 */
bool AES_CBC_decrypt(uint8_t * ciphertext, uint8_t * plaintext,
                     uint8_t * key, uint8_t * init, uint16_t block_count)
{
	bool CBC_ok = true;

	/* Temporary values used to reduce memory access. */
  	uint8_t * temp_plaintext = plaintext;
	uint8_t * temp_ciphertext = ciphertext;

	for(uint8_t blocks_left = block_count; blocks_left > 0; blocks_left--){

	  	/* Load key into AES key memory. */
		uint8_t * temp_key = key;
		for(uint8_t i = 0; i < AES_BLOCK_LENGTH; i++){
			AES.KEY =  *(temp_key++);
		}

		/* Load ciphertext into AES state memory. */
		uint8_t * temp = temp_ciphertext;
		for(uint8_t i = 0; i < AES_BLOCK_LENGTH; i++){
			AES.STATE =  *(temp++);
		}

		temp_ciphertext = temp;

		/* Set AES in decryption mode and enable xor feature and start the AES. */
		AES.CTRL |= (AES_DECRYPT_bm | AES_XOR_bm | AES_START_bm);

		do{
			/* Wait until AES is finished or an error occurs. */
		}while((AES.STATUS & (AES_SRIF_bm|AES_ERROR_bm) ) == 0);

				/* If not error. */
		if((AES.STATUS & AES_ERROR_bm) == 0){

			/* The first block is xored with the initialization vector. */
			if(blocks_left == block_count){
				/* Load into AES state memory. */
				uint8_t * temp_init = init;
				for(uint8_t i = 0; i < AES_BLOCK_LENGTH; i++){
					AES.STATE =  *(temp_init++);
				}
			}
			/* The other blocks is xored with the previous ciphertext block. */
			else{
				/* Load into AES state memory. */
			  	uint8_t * last_ciphertext = temp_ciphertext - (AES_BLOCK_LENGTH*2);
				for(uint8_t i = 0; i < AES_BLOCK_LENGTH; i++){
					AES.STATE =  *(last_ciphertext++);
				}
			}

			/* Disable XOR feature before next round. */
			AES.CTRL = AES.CTRL & (~AES_XOR_bm);

			/* Store the result. */
			uint8_t * temp = temp_plaintext;
			for(uint8_t i = 0; i < AES_BLOCK_LENGTH; i++){
				*(temp++) = AES.STATE;
			}
			temp_plaintext = temp;
		}else{
			CBC_ok = false;
		}

	}
	return CBC_ok;
}



/*! \brief  Function that sets AES interrupt level
 *
 *  \param  int_lvl  The AES interrupt level
 */
void AES_interruptlevel_set(AES_INTLVL_t int_lvl)
{
	AES.INTCTRL = int_lvl;
}




/*! \brief  Polled function that does an AES encryption on one 128-bit data block.
 *
 *  Function equal to the AES_encrypt function but the key is not loaded
 *  into the key memory. The function require that the key already is in the
 *  key memory. Used when encryption and decryption with the same key is
 *  done every other time.
 *
 *  \note This code is blocking and will dead lock if no interrupt flags are set.
 *
 *  \param  plaintext  Pointer to the plaintext that shall be encrypted
 *  \param  ciphertext Pointer to where in memory the ciphertext (answer) shall be stored.
 *
 *  \retval true   If the AES encryption was successful.
 *  \retval false  If the AES encryption was not successful.
 */
bool AES_encrypt_backtoback(uint8_t * plaintext, uint8_t * ciphertext)
{
  	bool encrypt_ok;

	/* Load data into AES state memory. */
	uint8_t * temp_plaintext = plaintext;
	for(uint8_t i = 0; i < AES_BLOCK_LENGTH; i++){
		AES.STATE =  *(temp_plaintext++);
	}

	/* Set AES in encryption mode and start AES. */
	AES.CTRL = (AES.CTRL & (~AES_DECRYPT_bm)) | AES_START_bm;


	do{
		/* Wait until AES is finished or an error occurs. */
	}while((AES.STATUS & (AES_SRIF_bm|AES_ERROR_bm) ) == 0);

	/* If not error. */
	if((AES.STATUS & AES_ERROR_bm) == 0){
		/* Store the result. */
		uint8_t * temp_ciphertext = ciphertext;
		for(uint8_t i = 0; i < AES_BLOCK_LENGTH; i++){
			*(temp_ciphertext++) = AES.STATE;
		}
		encrypt_ok = true;
	}else{
		encrypt_ok = false;

	}
	return encrypt_ok;
}



/*! \brief  Polled function that does an AES decryption on one 128-bit data block.
 *
 *  Function equal to the AES_decrypt function but the key is not loaded
 *  into the key memory. The function require that the key already is in the
 *  key memory. Used when encryption and decryption with the same key is
 *  done every other time.
 *
 *  \note This code is blocking and will dead lock if no interrupt flags are set.
 *
 *  \param  ciphertext  Pointer to the ciphertext that shall be decrypted
 *  \param  plaintext   Pointer to where in memory the plaintext (answer) shall be stored.
 *
 *  \retval true   If the AES decryption was successful.
 *  \retval false  If the AES decryption was not successful.
 */
bool AES_decrypt_backtoback(uint8_t * ciphertext, uint8_t * plaintext)
{
  	bool decrypt_ok;

	/* Load data into AES state memory. */
	uint8_t * temp_ciphertext = ciphertext;
	for(uint8_t i = 0; i < AES_BLOCK_LENGTH; i++){
		AES.STATE =  *(temp_ciphertext++);
	}

	/* Set AES in decryption mode and start the AES.*/
	AES.CTRL |= (AES_START_bm | AES_DECRYPT_bm);


	do{
		/* Wait until AES is finished or an error occurs. */
	}while((AES.STATUS & (AES_SRIF_bm|AES_ERROR_bm) ) == 0);

	/* If not error. */
	if((AES.STATUS & AES_ERROR_bm) == 0){
		/* Store the result. */
		uint8_t * temp_plaintext = plaintext;
		for(uint8_t i = 0; i < AES_BLOCK_LENGTH; i++){
			*(temp_plaintext++) = AES.STATE;
		}
		decrypt_ok = true;
	}else{
		decrypt_ok = false;

	}
	return decrypt_ok;
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美肥妇bbw| 日本一区二区不卡视频| 国产高清亚洲一区| 男女男精品网站| 亚洲一区二区成人在线观看| 精品国产三级a在线观看| 91高清在线观看| 成人av在线播放网址| 国产一区二区三区久久久| 日欧美一区二区| 秋霞午夜鲁丝一区二区老狼| 成人爽a毛片一区二区免费| 成人黄色大片在线观看| 日韩手机在线导航| 欧美精品一区二| 国产色一区二区| 国产精品免费丝袜| 亚洲欧美视频一区| 亚洲激情图片小说视频| 亚洲与欧洲av电影| zzijzzij亚洲日本少妇熟睡| 97久久精品人人澡人人爽| 色婷婷亚洲综合| 欧美色网一区二区| 日韩一区二区在线看| 一二三区精品福利视频| 日本女人一区二区三区| 国产精品乡下勾搭老头1| 91亚洲精品久久久蜜桃| 正在播放亚洲一区| 国产精品美女久久久久aⅴ国产馆| 卡一卡二国产精品 | 悠悠色在线精品| 成人看片黄a免费看在线| 国产午夜精品一区二区三区嫩草| 久久成人免费网站| 久久青草欧美一区二区三区| 亚洲一区二区黄色| 欧美视频中文字幕| 午夜精品久久一牛影视| 国产suv一区二区三区88区| 欧美性受极品xxxx喷水| 亚洲一区二区美女| 91麻豆精品国产91久久久使用方法 | 国产日韩v精品一区二区| 亚洲国产你懂的| 国产伦精品一区二区三区视频青涩| 日韩精品一区二区三区在线观看| 亚洲欧美日韩成人高清在线一区| 99精品视频一区二区三区| 自拍偷拍国产亚洲| 国产一区二区在线观看免费| 久久久国产精华| av福利精品导航| 亚洲制服欧美中文字幕中文字幕| 欧美日韩亚洲丝袜制服| 成人免费视频在线观看| 国产精品中文字幕一区二区三区| 久久精品人人做| 91天堂素人约啪| 日韩综合在线视频| 国产日韩欧美不卡| 91成人网在线| 国产一区二区按摩在线观看| 亚洲欧洲一区二区三区| 在线播放91灌醉迷j高跟美女 | 在线观看视频一区二区| 亚洲欧美日韩在线不卡| 欧美一区二区三区视频在线观看| 亚洲一区国产视频| xnxx国产精品| 欧美性淫爽ww久久久久无| 国产一区二区在线免费观看| 亚洲最快最全在线视频| 久久女同互慰一区二区三区| 色欧美片视频在线观看在线视频| 丝袜亚洲另类欧美| 亚洲天堂av老司机| 国产亚洲美州欧州综合国| 51精品国自产在线| 99久久精品国产麻豆演员表| 久久99精品久久久久婷婷| 久久综合久久鬼色| 欧美吞精做爰啪啪高潮| 成人丝袜18视频在线观看| 极品瑜伽女神91| 亚洲第一久久影院| 日韩一区二区三区精品视频| 色综合久久中文综合久久97 | 亚洲国产精品精华液ab| 日韩视频在线永久播放| 欧美亚洲高清一区| 99精品桃花视频在线观看| 极品少妇一区二区| 日本欧美加勒比视频| 亚洲国产中文字幕| 亚洲伦在线观看| 国产亚洲欧美激情| 久久久美女艺术照精彩视频福利播放| 欧美日韩在线亚洲一区蜜芽| 91丨国产丨九色丨pron| 成人免费毛片嘿嘿连载视频| 看电视剧不卡顿的网站| 青青草精品视频| 视频在线观看一区| 日本欧美韩国一区三区| 日本不卡123| 视频一区国产视频| 日本不卡的三区四区五区| 日本美女一区二区| 麻豆传媒一区二区三区| 国产精品高潮久久久久无| 欧美系列一区二区| 欧美性猛交xxxx乱大交退制版 | 亚洲成人在线观看视频| 一区二区三区小说| 亚洲一区二区四区蜜桃| 亚洲在线视频免费观看| 亚洲高清久久久| 天堂蜜桃91精品| 日韩成人一区二区| 久久精品国产999大香线蕉| 极品少妇一区二区| 国产精品一区免费视频| 高清日韩电视剧大全免费| 成人av资源下载| 在线亚洲高清视频| 欧美精品在欧美一区二区少妇| 91精品国产综合久久福利| 日韩欧美一区二区视频| 国产亚洲污的网站| 亚洲日本乱码在线观看| 亚洲成人av免费| 激情深爱一区二区| 丝袜亚洲另类欧美综合| 精品亚洲国产成人av制服丝袜| 高清视频一区二区| 欧美唯美清纯偷拍| 久久先锋资源网| 亚洲欧美视频在线观看视频| 日日夜夜免费精品| 国产成人欧美日韩在线电影| 色综合久久综合| 日韩精品中文字幕一区二区三区 | 一本大道综合伊人精品热热 | 麻豆一区二区在线| 丁香桃色午夜亚洲一区二区三区| 99re6这里只有精品视频在线观看 99re8在线精品视频免费播放 | 亚洲精品老司机| 日韩av一级电影| 波多野结衣中文字幕一区| 欧美精品高清视频| 亚洲国产成人午夜在线一区| 亚洲一区二区精品视频| 国产在线一区观看| 欧美日韩五月天| 国产精品亲子乱子伦xxxx裸| 亚洲www啪成人一区二区麻豆| 国产精选一区二区三区| 精品视频在线视频| 久久精品一区二区三区不卡| 亚洲国产欧美日韩另类综合 | 国产大片一区二区| 在线观看日产精品| 国产欧美一区二区精品久导航| 亚洲二区在线观看| 成人a免费在线看| 久久综合久久综合久久| 午夜精品在线视频一区| 99精品视频在线免费观看| 久久九九99视频| 久久狠狠亚洲综合| 欧美日韩另类国产亚洲欧美一级| 精品视频一区二区不卡| 亚洲欧洲日产国码二区| 国产福利一区二区三区视频在线| 欧美午夜影院一区| 亚洲欧美在线视频| 国产一区日韩二区欧美三区| 337p亚洲精品色噜噜| 亚洲欧洲制服丝袜| 国产suv一区二区三区88区| 日韩精品中文字幕一区二区三区| 性做久久久久久免费观看| 91麻豆123| 亚洲天堂a在线| www.亚洲在线| 中文字幕免费观看一区| 韩国av一区二区三区四区| 欧美一级午夜免费电影| 日韩制服丝袜先锋影音| 欧美探花视频资源| 亚洲成人手机在线| 欧美人牲a欧美精品| 亚洲电影中文字幕在线观看| 欧美午夜不卡在线观看免费| 亚洲一区在线观看网站| 91久久线看在观草草青青| 综合久久一区二区三区| 91在线国产福利|