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

📄 sccom.c

📁 SecuDe是一个由安全应用程序接口组成,对验证机制、证件处理、PEM、X.400报文处理和密钥管理提供支持。SecuDe提供DES、 RSA杂凑函数、密钥生成以及数字签名的生成和核实等多种密码机制。
💻 C
📖 第 1 页 / 共 5 页
字号:
		if ((kid_1 = e_KeyId(SCREG.kid)) == -1)			return (-1);		if (SCchecklen(strlen(SCREG.fn), MAX_FILENAME))			return (-1);		lscapdu += KIDLEN + REGACVLEN + strlen(SCREG.fn);		if ((scapdu = SCalloc(lscapdu)) == NULL)			return (-1);		ptr = scapdu + 2;		e_TwoByte(&ptr, SCREG.units);		Ioput(&ptr, KIDLEN + REGACVLEN + strlen(SCREG.fn));		if (sec_mode == TRUE)			Ioput(&ptr, ssc);		Ioput(&ptr, kid_1);		Ioput(&ptr, SCREG.acv);		Ioputbuff(&ptr, SCREG.fn, strlen(SCREG.fn));		break;		/*----------------------------*/		/* create SC_READF            */		/*----------------------------*/	case SC_READF:		if ((fid = e_FileId(SCREADF.fid)) == -1)			return (-1);		if ((SCREADF.data_sel->data_struc > TRANSPARENT) ||		    (SCREADF.data_sel->data_struc < LIN_FIX) ||		    ((SCREADF.data_sel->data_struc == LIN_FIX) &&		   ((SCREADF.data_sel->data_ref.record_sel.record_id < 0) ||		(SCREADF.data_sel->data_ref.record_sel.record_id > 255))) ||		    ((SCREADF.data_sel->data_struc == LIN_VAR) &&		   ((SCREADF.data_sel->data_ref.record_sel.record_id < 0) ||		(SCREADF.data_sel->data_ref.record_sel.record_id > 254))) ||		    (SCREADF.lrddata > MAXR_W_LEN)) {			sc_errno = EPARINC;			sc_errmsg = sct_error[sc_errno].msg;			return (-1);		};		lscapdu += 2;		if ((scapdu = SCalloc(lscapdu)) == NULL)			return (-1);		ptr = scapdu + 2;		switch (SCREADF.data_sel->data_struc) {		case CYCLIC:			Ioput(&ptr, SCREADF.data_sel->data_ref.element_sel.element_ref);			Ioput(&ptr, SCREADF.data_sel->data_ref.element_sel.element_no);			break;		case TRANSPARENT:			e_TwoByte(&ptr, SCREADF.data_sel->data_ref.string_sel);			break;		case LIN_FIX:		case LIN_VAR:			Ioput(&ptr, SCREADF.data_sel->data_ref.record_sel.record_id);			Ioput(&ptr, SCREADF.data_sel->data_ref.record_sel.record_pos);			break;		};		Ioput(&ptr, 0x02);		if (sec_mode == TRUE)			Ioput(&ptr, ssc);		Ioput(&ptr, fid);		Ioput(&ptr, SCREADF.lrddata);		break;		/*----------------------------*/		/* create SC_LOCKFILE         */		/*----------------------------*/	case SC_LOCKF:		if ((fid = e_FileId(SCLOCKF.fid)) == -1)			return (-1);		lscapdu++;		if ((scapdu = SCalloc(lscapdu)) == NULL)			return (-1);		ptr = scapdu + 2;		Ioput(&ptr, LOCK_CAT);		Ioput(&ptr, SCLOCKF.co);		Ioput(&ptr, FIDLEN);		if (sec_mode == TRUE)			Ioput(&ptr, ssc);		Ioput(&ptr, fid);		break;		/*----------------------------*/		/* create SC_DELREC           */		/*----------------------------*/	case SC_DELREC:		if ((SCDELREC.rid < 0) ||		    (SCDELREC.rid > 255)) {			sc_errno = EPARINC;			sc_errmsg = sct_error[sc_errno].msg;			return (-1);		};		if ((fid = e_FileId(SCDELREC.fid)) == -1)			return (-1);		if ((scapdu = SCalloc(lscapdu)) == NULL)			return (-1);		ptr = scapdu + 2;		Ioput(&ptr, fid);		Ioput(&ptr, SCDELREC.rid);		Ioput(&ptr, SC_NOTUSED);		if (sec_mode == TRUE)			Ioput(&ptr, ssc);		break;		/*----------------------------*/		/* create SC_DELFILE          */		/*----------------------------*/	case SC_DELF:		if (SCDELFILE.filecat > EF) {			sc_errno = EPARINC;			sc_errmsg = sct_error[sc_errno].msg;			return (-1);		};		if (SCDELFILE.filecat != EF) {			if ((SCDELFILE.file_sel->file_name == NULL) ||			    (strlen(SCDELFILE.file_sel->file_name) == 0)) {				sc_errno = EPARINC;				sc_errmsg = sct_error[sc_errno].msg;				return (-1);			}			if (SCchecklen(strlen(SCDELFILE.file_sel->file_name), MAX_FILENAME) == -1)				return (-1);			len = strlen(SCDELFILE.file_sel->file_name);		} else {			if ((fid = e_FileId(&SCDELFILE.file_sel->file_id)) == -1)				return (-1);			len = 1;		}		lscapdu += len;		if ((scapdu = SCalloc(lscapdu)) == NULL)			return (-1);		ptr = scapdu + 2;		Ioput(&ptr, (int) SCDELFILE.filecat);		Ioput(&ptr, SC_NOTUSED);		Ioput(&ptr, len);		if (sec_mode == TRUE)			Ioput(&ptr, ssc);		if (SCDELFILE.filecat != EF)			Ioputbuff(&ptr, SCDELFILE.file_sel->file_name, len);		else			Ioput(&ptr, fid);		break;		/*----------------------------*/		/* create SC_CLOSE            */		/*----------------------------*/	case SC_CLOSE:		if ((SCCLOSE.filecat > EF) ||		    (SCCLOSE.filecat < MF) ||		    (SCCLOSE.context > CLOSE_SELECT)) {			sc_errno = EPARINC;			sc_errmsg = sct_error[sc_errno].msg;			return (-1);		};		if (SCCLOSE.filecat != EF) {			if ((SCCLOSE.file_sel->file_name == NULL) ||			    (strlen(SCCLOSE.file_sel->file_name) == 0)) {				sc_errno = EPARINC;				sc_errmsg = sct_error[sc_errno].msg;				return (-1);			}			if (SCchecklen(strlen(SCCLOSE.file_sel->file_name), MAX_FILENAME) == -1)				return (-1);			len = strlen(SCCLOSE.file_sel->file_name);		} else {			if ((fid = e_FileId(&SCCLOSE.file_sel->file_id)) == -1)				return (-1);			len = 1;		}		lscapdu += len;		if ((scapdu = SCalloc(lscapdu)) == NULL)			return (-1);		ptr = scapdu + 2;		Ioput(&ptr, (int) SCCLOSE.filecat);		Ioput(&ptr, (int) SCCLOSE.context);		Ioput(&ptr, len);		if (sec_mode == TRUE)			Ioput(&ptr, ssc);		if (SCCLOSE.filecat != EF)			Ioputbuff(&ptr, SCCLOSE.file_sel->file_name, len);		else			Ioput(&ptr, fid);		break;		/*----------------------------*/		/* create SC_CHG_PIN          */		/*----------------------------*/	case SC_CHG_PIN:		if ((SCCHGPIN.len_oldpin > PINLEN) ||		    (SCCHGPIN.len_newpin > PINLEN)) {			sc_errno = EPARINC;			sc_errmsg = sct_error[sc_errno].msg;			return (-1);		};		for (i = 0; i < 8; i++) {			oldpin[i] = BLANK;			newpin[i] = BLANK;		}		memcpy(oldpin, SCCHGPIN.old_pin, SCCHGPIN.len_oldpin);		memcpy(newpin, SCCHGPIN.new_pin, SCCHGPIN.len_newpin);		if ((kid_1 = e_KeyId(SCCHGPIN.kid)) == -1)			return (-1);		lscapdu += PINLEN * 2;		if ((scapdu = SCalloc(lscapdu)) == NULL)			return (-1);		ptr = scapdu + 2;		Ioput(&ptr, (int) kid_1);		Ioput(&ptr, (int) SC_NOTUSED);		Ioput(&ptr, PINLEN * 2);		if (sec_mode == TRUE)			Ioput(&ptr, ssc);		Ioputbuff(&ptr, oldpin, PINLEN);		Ioputbuff(&ptr, newpin, PINLEN);		break;		/*----------------------------*/		/* create SC_AUTH             */		/*----------------------------*/	case SC_AUTH:		if ((kid_1 = e_KeyId(SCAUTH.kid)) == -1)			return (-1);		lscapdu += SCAUTH.len_authd;		if ((scapdu = SCalloc(lscapdu)) == NULL)			return (-1);		ptr = scapdu + 2;		Ioput(&ptr, kid_1);		Ioput(&ptr, (int) SCAUTH.acp);		Ioput(&ptr, SCAUTH.len_authd);		if (sec_mode == TRUE)			Ioput(&ptr, ssc);		Ioputbuff(&ptr, SCAUTH.authd, SCAUTH.len_authd);		break;		/*--------------------------*/		/* create SC_CREATE         */		/*--------------------------*/	case SC_CREATE:		if ((SCCREATE.filecat > EF) ||		    (SCCREATE.filecat < MF) ||		    (SCCREATE.filecontrolinfo->units <= 0) ||		    ((SCCREATE.filecat == EF) &&		     (SCCREATE.filetype > ISF)) ||		    ((SCCREATE.filecat == EF) &&		     ((SCCREATE.datastruc > TRANSPARENT) ||		      (SCCREATE.datastruc < LIN_FIX))) ||		    ((SCCREATE.filecat == EF) &&		     (SCCREATE.filetype == WEF) &&		     (SCCREATE.filecontrolinfo->readwrite > WRITE_ONLY)) ||		    ((SCCREATE.filecat == EF) &&		((SCCREATE.filetype == ISF) || (SCCREATE.filetype == ACF)) &&		     (SCCREATE.filecontrolinfo->readwrite != WRITE_ONLY)) ||		    ((SCCREATE.filecat == EF) &&		((SCCREATE.filetype == ISF) || (SCCREATE.filetype == ACF)) &&		     (SCCREATE.filecontrolinfo->not_erasable == FALSE)) ||		    ((SCCREATE.filecat == EF) &&		     (SCCREATE.filetype == PEF) &&		     (SCCREATE.filecontrolinfo->readwrite != READ_ONLY)) ||		    ((SCCREATE.filecat == EF) &&		     ((SCCREATE.datastruc == LIN_VAR) ||		      (SCCREATE.datastruc == TRANSPARENT)) &&		     (SCCREATE.filecontrolinfo->recordsize > 0)) ||		    ((SCCREATE.filecat == EF) &&		     ((SCCREATE.datastruc == LIN_FIX) ||		      (SCCREATE.datastruc == CYCLIC)) &&		     (SCCREATE.filecontrolinfo->recordsize <= 0)) ||		    ((SCCREATE.filecat != EF) &&		     (SCCREATE.filecontrolinfo->recordsize > 0))) {			sc_errno = EPARINC;			sc_errmsg = sct_error[sc_errno].msg;			return (-1);		}		if (SCchecklen(SCCREATE.filecontrolinfo->addinfo.noctets,			       MAX_ADDINFO))			return (-1);		if (SCCREATE.filecat != EF) {			if ((SCCREATE.filecontrolinfo->file_sel.file_name == NULL) ||			    (strlen(SCCREATE.filecontrolinfo->file_sel.file_name) == 0)) {				sc_errno = EPARINC;				sc_errmsg = sct_error[sc_errno].msg;				return (-1);			}			if (SCchecklen(strlen(SCCREATE.filecontrolinfo->file_sel.file_name),				       MAX_FILENAME) == -1)				return (-1);			len = strlen(SCCREATE.filecontrolinfo->file_sel.file_name);		} else {			if (SCCREATE.filecontrolinfo->file_sel.file_id.file_type !=			    SCCREATE.filetype) {				sc_errno = EPARINC;				sc_errmsg = sct_error[sc_errno].msg;				return (-1);			}			if ((fid = e_FileId(&SCCREATE.filecontrolinfo->file_sel.file_id)) == -1)				return (-1);			len = 1;		}		finfolen = UNITLEN + SCILEN + OPLEN + SIZELEN +			len + 1 +			SCCREATE.filecontrolinfo->addinfo.noctets + 1;		lscapdu += finfolen;		if ((scapdu = SCalloc(lscapdu)) == NULL)			return (-1);		ptr = scapdu + 2;		file_type_cat =			e_FileTypeCat((int) SCCREATE.filetype, (int) SCCREATE.filecat);		Ioput(&ptr, file_type_cat);		if (SCCREATE.filecat == EF)			Ioput(&ptr, (int) SCCREATE.datastruc);		else			Ioput(&ptr, SC_NOTUSED);		Ioput(&ptr, finfolen);		if (sec_mode == TRUE)			Ioput(&ptr, ssc);		e_TwoByte(&ptr, SCCREATE.filecontrolinfo->units);		Ioput(&ptr, SCCREATE.filecontrolinfo->racv);		Ioput(&ptr, SCCREATE.filecontrolinfo->wacv);		Ioput(&ptr, SCCREATE.filecontrolinfo->dacv);		op_mode = e_OperationMode(SCCREATE.filecontrolinfo);		Ioput(&ptr, op_mode);		if (SCCREATE.filecat == EF)			Ioput(&ptr, SCCREATE.filecontrolinfo->recordsize);		else			Ioput(&ptr, SC_NOTUSED);		Ioput(&ptr, len);		if (SCCREATE.filecat != EF)			Ioputbuff(&ptr, SCCREATE.filecontrolinfo->file_sel.file_name, len);		else			Ioput(&ptr, fid);		Ioput(&ptr, SCCREATE.filecontrolinfo->addinfo.noctets);		Ioputbuff(&ptr, SCCREATE.filecontrolinfo->addinfo.octets,			  SCCREATE.filecontrolinfo->addinfo.noctets);		break;		/*----------------------------*/		/* create SC_WR_KEY           */		/*----------------------------*/	case SC_WR_KEY:		if ((kid_1 = e_KeyId(SCWRKEY.kid)) == -1)			return (-1);		if ((SCWRKEY.key_len > KEYLEN) ||

⌨️ 快捷键说明

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