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

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

?? aes_driver.c

?? ATMEL XMEGA crypto program-task3.
?? 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一区二区三区免费野_久草精品视频
久久影院视频免费| 久久国产精品一区二区| 成人国产精品视频| 欧美午夜一区二区三区| 国产喂奶挤奶一区二区三区| 婷婷综合另类小说色区| 不卡一区二区中文字幕| 日韩午夜在线影院| 亚洲欧美一区二区三区国产精品| 久久国产婷婷国产香蕉| 欧美四级电影网| 亚洲美女免费视频| 国产v日产∨综合v精品视频| 精品免费视频一区二区| 午夜精品久久久久久久| 色婷婷综合久久久中文字幕| 国产喷白浆一区二区三区| 另类小说综合欧美亚洲| 在线电影一区二区三区| 亚洲午夜成aⅴ人片| 99re视频这里只有精品| 国产精品福利一区二区| 福利一区二区在线| 久久只精品国产| 极品尤物av久久免费看| 欧美一级高清大全免费观看| 天天色 色综合| 欧美视频在线一区二区三区| 亚洲精品五月天| 99久久伊人网影院| 国产精品乱人伦中文| 欧美日韩亚洲高清一区二区| 中文字幕综合网| 色婷婷国产精品综合在线观看| 国产精品福利一区| 色香蕉成人二区免费| 中文字幕一区二区三区乱码在线| aaa欧美日韩| 成人欧美一区二区三区视频网页| www.亚洲精品| 综合久久国产九一剧情麻豆| 91亚洲午夜精品久久久久久| 亚洲精品综合在线| 色狠狠色噜噜噜综合网| 亚洲电影一区二区三区| 欧美精品久久久久久久久老牛影院| 午夜欧美电影在线观看| 日韩午夜av电影| 国产精品一二一区| 亚洲品质自拍视频| 欧美日韩一区小说| 精品一区二区三区影院在线午夜| 久久久99精品免费观看| 91女神在线视频| 亚洲国产一区二区视频| 欧美一级爆毛片| 国产+成+人+亚洲欧洲自线| √…a在线天堂一区| 欧美日韩视频第一区| 久久国产精品一区二区| 亚洲欧美影音先锋| 911精品产国品一二三产区| 国产真实乱子伦精品视频| 国产精品久久毛片av大全日韩| 欧美性大战久久久久久久| 九色综合狠狠综合久久| 1区2区3区欧美| 欧美一区二区三区在| 国产激情视频一区二区在线观看 | 8x福利精品第一导航| 青青草视频一区| 国产精品亲子伦对白| 欧美日韩国产a| 丁香天五香天堂综合| 亚洲成人精品一区二区| 国产日韩综合av| 91精品黄色片免费大全| 9人人澡人人爽人人精品| 日韩精品一级二级 | a级高清视频欧美日韩| 午夜激情一区二区三区| 亚洲欧洲精品天堂一级| 日韩小视频在线观看专区| 日本久久一区二区| 国产·精品毛片| 国内精品免费**视频| 性做久久久久久免费观看欧美| 国产亚洲精品中文字幕| 日韩一区二区在线免费观看| 色综合一区二区三区| 国产精品影视天天线| 肉色丝袜一区二区| 亚洲伦在线观看| 欧美国产一区二区在线观看| 91精品国产色综合久久久蜜香臀| 色综合天天在线| 成+人+亚洲+综合天堂| 国产一区美女在线| 老鸭窝一区二区久久精品| 午夜精品久久久久久久| 亚洲综合在线五月| 亚洲欧美偷拍卡通变态| 国产欧美一区二区精品性色| 亚洲精品一区二区三区蜜桃下载| 日韩视频免费直播| 91麻豆精品国产| 3atv在线一区二区三区| 欧美日本国产视频| 制服丝袜亚洲网站| 制服丝袜亚洲播放| 777久久久精品| 日韩视频国产视频| 欧美不卡视频一区| 欧美成人国产一区二区| 日韩精品一区国产麻豆| 精品电影一区二区| 久久网这里都是精品| 国产婷婷色一区二区三区| 国产精品三级视频| 国产精品第五页| 一个色妞综合视频在线观看| 亚洲激情中文1区| 亚洲一本大道在线| 日韩国产一二三区| 久久不见久久见中文字幕免费| 全国精品久久少妇| 久久99精品久久久久久动态图| 久久精品国产精品青草| 狠狠色狠狠色综合系列| 国产精品综合网| 成人黄色网址在线观看| 99re视频这里只有精品| 欧美日韩国产综合视频在线观看 | wwwwww.欧美系列| 日韩va欧美va亚洲va久久| 久久国产人妖系列| 盗摄精品av一区二区三区| 色中色一区二区| 666欧美在线视频| 日韩一区二区三免费高清| 久久色.com| 一区二区三区精品在线| 午夜精品久久久久影视| 国产精品911| 欧美日韩一区二区三区视频| 欧美一级精品在线| 亚洲丝袜制服诱惑| 久久不见久久见免费视频7| av高清不卡在线| 日韩一区二区三区四区| 成人欧美一区二区三区1314| 五月婷婷综合网| 粉嫩aⅴ一区二区三区四区五区| 欧美中文字幕一区| 久久久亚洲午夜电影| 亚洲国产日韩综合久久精品| 国产精品123区| 欧美日韩一区在线| 欧美韩日一区二区三区四区| 丝袜亚洲另类欧美| 99久久精品国产一区二区三区| 欧美精品粉嫩高潮一区二区| 亚洲欧洲日产国码二区| 久久国产精品99精品国产| 日本韩国视频一区二区| 欧美国产日韩亚洲一区| 日韩精品电影一区亚洲| 色婷婷av一区二区三区gif | 欧美日韩国产高清一区二区三区| 久久久久久久电影| 日韩高清国产一区在线| 一本色道亚洲精品aⅴ| 中文字幕久久午夜不卡| 奇米影视在线99精品| 色婷婷亚洲综合| 国产精品天干天干在线综合| 久久国产精品露脸对白| 欧美高清视频在线高清观看mv色露露十八| 久久久国产精华| 麻豆视频一区二区| 欧美日韩一二三区| 成人免费在线播放视频| 成人午夜电影久久影院| 久久免费国产精品| 麻豆精品视频在线| 欧美一区二区三区视频在线 | 在线观看三级视频欧美| 国产精品福利一区二区三区| 国产成人午夜精品5599| 精品sm捆绑视频| 美女爽到高潮91| 欧美大片在线观看| 日本视频免费一区| 欧美一区二区在线免费播放| 亚洲444eee在线观看| 欧美男男青年gay1069videost| 亚洲国产va精品久久久不卡综合| 91理论电影在线观看| 一区二区三区在线视频免费观看| 99久久免费精品|