Пример #1
0
static void
reinit_pmt (Table * t, int sz)
{
  clear_tbl (t);
  init_pmt (t, sz);
}
Пример #2
0
/*
 *DES加密
 *输入:plainText 16位明文(16进制), key 16位密钥(16进制)
 *输出:加密后的结果 解密后的结果 16位明文(16进制)
 */
void deDES(char* ciperText,char* key,char* result){
	printf("解密数据开始!\n");

	char*  dataL=(char*) malloc(32*sizeof(char));//数据左半部分
	char*  dataR=(char*) malloc(32*sizeof(char));//数据右半部分
	char*  dataL_cp=(char*) malloc(32*sizeof(char));//数据左半部分拷贝
	char*  dataR_cp=(char*) malloc(32*sizeof(char));//数据右半部分拷贝
	char*  data_48=(char*) malloc(48*sizeof(char));//48位中间数据
	char*  data_64=(char*) malloc(64*sizeof(char));//64位初始数据初始置换后数据
	char*  data_64_I=(char*) malloc(64*sizeof(char));//64位初始数据
	//16个48位密钥空间
	char**  keys =(char**) malloc(16*sizeof(char*));
	for(int i=0;i<16;i++){
		*(keys+i) = (char*) malloc(48*sizeof(char));
	}
	//得到16个48位密钥
	gen_key(key,keys);
	//16进制明文转换成2进制
	hex2Binary(ciperText,16,data_64_I);
	//初始置换
	init_pmt(data_64_I,data_64);
	strCopy(data_64,dataL,32);
	strCopy(data_64+32,dataR,32);

	//轮变换,循环16轮
	for(int rc=1;rc<=16;rc++){
		//printf("第%d轮数据:",rc);
		//扩展置换E
		pmt_E(dataR,data_48);
		strCopy(dataL,dataL_cp,32);
		strCopy(dataR,dataL,32);
		//异或
		for(int i = 0 ;i < 48;i++){
			data_48[i] = data_48[i]^keys[16-rc][i];
		}
		//S盒置换/选择
		pmt_S(data_48,dataR_cp);
		//P置换
		pmt_P(dataR_cp,dataR);
		//异或
		for(int i = 0 ;i < 32;i++){
			dataR[i] = dataL_cp[i]^dataR[i];
		}
		binary2Hex(dataL,32);//打印左半部分
		printf("  ");
		binary2Hex(dataR,32);//打印右半部分
		printf("\n");
	}

	//32位互换
	strCopy(dataR,data_64_I,32);
	strCopy(dataL,data_64_I+32,32);
	//逆初始置换
	init_pmt_reverse(data_64_I,data_64);
	printf("明文为: ");
	binary2Hex(data_64,result,64);

	free(data_64);
	free(dataL);
	free(dataR);
	free(dataL_cp);
	free(dataR_cp);
	free(data_48);
	free(data_64_I);
	free(keys);
}
Пример #3
0
/*
 * Starting point for MMC card init.
 */
int mmc_attach_mmc(struct mmc_host *host)
{
	int err;
	u32 ocr;

	BUG_ON(!host);
	WARN_ON(!host->claimed);
	mt6575_mmc_info( "+%s--Liu\n", __func__);
	err = mmc_send_op_cond(host, 0, &ocr);
	if (err)
		return err;

	mmc_attach_bus_ops(host);
	if (host->ocr_avail_mmc)
		host->ocr_avail = host->ocr_avail_mmc;

	/*
	 * We need to get OCR a different way for SPI.
	 */
	if (mmc_host_is_spi(host)) {
		err = mmc_spi_read_ocr(host, 1, &ocr);
		if (err)
			goto err;
	}

	/*
	 * Sanity check the voltages that the card claims to
	 * support.
	 */
	if (ocr & 0x7F) {
		printk(KERN_WARNING "%s: card claims to support voltages "
		       "below the defined range. These will be ignored.\n",
		       mmc_hostname(host));
		ocr &= ~0x7F;
	}

	host->ocr = mmc_select_voltage(host, ocr);

	/*
	 * Can we support the voltage of the card?
	 */
	if (!host->ocr) {
		mt6575_mmc_info("%s: error, ocr is NULL--Liu\n", __func__);
		err = -EINVAL;
		goto err;
	}

	/*
	 * Detect and init the card.
	 */
	err = mmc_init_card(host, host->ocr, NULL);
	if (err)
		goto err;

	mmc_release_host(host);
	err = mmc_add_card(host->card);
#ifdef MTK_EMMC_SUPPORT
	err = init_pmt();
	host->card_init_complete(host);
#endif
	mmc_claim_host(host);
	if (err)
		goto remove_card;
	mt6575_mmc_info( "-%s--Liu\n", __func__);
	return 0;

remove_card:
	mmc_release_host(host);
	mmc_remove_card(host->card);
	mmc_claim_host(host);
	host->card = NULL;
err:
	mmc_detach_bus(host);

	printk(KERN_ERR "%s: error %d whilst initialising MMC card\n",
		mmc_hostname(host), err);

	return err;
}