⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loadkey.c

📁 开发源代码的CPU卡的COS源程序。
💻 C
字号:
/* ============================================================================   Project Name : jayaCard   Module Name  : proto/bios/crypto/loadkey.c   Version : $Id: loadkey.c,v 1.10 2004/01/11 09:56:30 dgil Exp $	Description: Crypto BIOS / Load Key    The Original Code is jayaCard code.    The Initial Developer of the Original Code is Gilles Dumortier.	Portions created by the Initial Developer are Copyright (C) 2002-2004 the    Initial Developer. All Rights Reserved.    Contributor(s):    This program is free software; you can redistribute it and/or modify    it under the terms of the GNU General Public License as published by    the Free Software Foundation; either version 2 of the License, or    (at your option) any later version.    This program is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    GNU General Public License for more details.    You should have received a copy of the GNU General Public License    along with this program; see http://www.gnu.org/licenses/gpl.html   History Rev	Description   051103 dgil	wrote it from crypto.c   ============================================================================*/#include "precomp.h"/* =========================================================================	__bios_loadkey(adr_in_eeprom,keylen)	security:		. check the following CRC		. check loop invariant		. check re-read equal first read 		. increment the global semaphore	in case of error, reset the cryptographic context.	review __x XXX		CRCing the key could be use to read some bits of the key from the 		outside world if the CRC coprocessor not well protected :-(   ========================================================================= */void __bios_loadkey_from_eeprom(jword adr,jbyte keylen){	LOCAL(jbyte,i);	LOCAL(jbyte,crclo);	LOCAL(jbyte,crchi);	LOG2("KEY","__bios_loadkey_from_eeprom() adr=%.4X keylen=%d",adr,keylen);	HAL_CRC_INIT();	/* store also the CRC at the end of the register buffer so we can re-check	   at key usage that the key is always valid !		__x XXX implement check mechanism just before cryptoing with this key!	*/	crclo = 0x00;	crchi = 0x00;	keylen += 2;	/* copy the key to the register area */	i = JAYA_BCRYPTO_KEYCRC;	while (keylen>0) {		/* write the dest with the src */		r.bBlock[i] = HAL_EEPROM_READ_BYTE(adr);		/* then re-read to check the read is correct ! */		if (r.bBlock[i]!=HAL_EEPROM_READ_BYTE(adr)) goto attack;		adr++;		/* CRC this byte */		if (i==0) {			crclo = r.bBlock[i];		} else if (i==1) {			crchi = r.bBlock[i];		} else {			HAL_CRC_COMPUTE(r.bBlock[i]);		}		i++;		keylen--;	}	/* loop invariant checking */	if (keylen>0) {attack:		/* under attack */		BIOS_RESET_CONTEXT(ERR_FAULT);		HAL_HALT();		return;	}	gGlobalSem++;	/* CRC checking */	if ((HAL_CRC_LO()!=crclo) || (HAL_CRC_HI()!=crchi)) {		LOG("BIOS","__bios_loadkey_from_eeprom(): invalid CRC !");		BIOS_RESET_CONTEXT(ERR_INVALID_CRC);	}}/* =========================================================================	That's all folks !   ========================================================================= */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -