📄 iccapp.lst
字号:
}
else
{
command.P1 = key->type;
command.Lc = key->keylen;
command.DAT = key->key;
}
command.P2 = key->id;
command.Le = 0;
if(!SamSendCommand(&command, &response))
return -1;
else
return response.ISW;
}
C51 COMPILER V7.07 ICCAPP 12/06/2003 18:49:10 PAGE 20
/*****************************************
* creat file *
* CLA: 80, INS: E0 *
* Secret and protect mode: NO *
* Suport: TimeCOS only *
*****************************************/
int ICC_creat_file(ICC_FILE *file)
{
unsigned char buf[25];
memset(buf, 0, sizeof(buf));
command.CLA = 0x80;
command.INS = 0xE0;
command.DAT = buf;
if(file->type == 0x38) // 0x38: DF type
{
command.P1 = file->id >> 8;
command.P2 = file->id & 0x00ff;
command.Lc = 1 + 2 + 1 + 1 + 3 + file->name_len;
/*type + size + cprw + epru + rsv + name*/
buf[0] = file->type;
buf[1] = file->size >> 8;
buf[2] = file->size & 0x00ff;
buf[3] = file->c_r_purview;
buf[4] = file->e_w_purview;
if(file->id == 0x3f00) // MF
{
memset(buf+5, 0xff, 8);
command.Lc = 1 + 2 + 1 + 1 + 8;
}
else
{
memset(buf+5, 0xff, 3); // reserved 1,2,3
strcpy(buf+8, file->name);
}
command.Le = 0;
}
else if(1)
{
command.P1 = file->id >> 8;
command.P2 = file->id & 0x00ff;
command.Lc = 7; // sizeof(p1 & p2)
buf[0] = file->type;
buf[1] = file->size >> 8;
buf[2] = file->size & 0x00ff;
buf[3] = file->c_r_purview;
buf[4] = file->e_w_purview;
buf[5] = 0xff; // reserved1
buf[6] = file->reserved2;
}
else return -1;
if(!SamSendCommand(&command, &response))
return -1;
else
return response.ISW;
}
C51 COMPILER V7.07 ICCAPP 12/06/2003 18:49:10 PAGE 21
/*****************************************
* Erase df(directory) *
* CLA: 80, INS: 0E *
* Secret and protect mode: NO *
* Suport: TimeCOS only *
*****************************************/
int ICC_erase_df(void)
{
int iret;
command.CLA = 0x80;
command.INS = 0x0e;
command.P1 = 0x00;
command.P2 = 0x00;
command.Lc = 0x00;
command.Le = 0x00;
command.DAT = NULL;
if(!SamSendCommand(&command, &response))
return -1;
else
return response.ISW;
}
/*****************************************
* Set protocol *
* CLA: 80, INS: 14 *
* Secret and protect mode: NO *
* Suport: TimeCOS only *
*****************************************/
int ICC_set_protocol()
{
return 0;
}
/********************************************************************
* The functions below is defined for lantoon use. *
* DES, MAC, store master key, store working key, ... *
********************************************************************/
#define ltmk_offset 0 /* lantoon master key, in slot 0 */
#define enmk_offset 1 /* bank encrypt master key, in slot 1 to 10 */
#define demk_offset 11 /* bank discrypt master key, in slot 11 to 20 */
#define enwk_offset 21 /* bank encrypt working key, in slot 21 to 30 */
#define dewk_offset 31 /* bank discrypt working key, int slot 31 to 40 */
#define maxk_id 40
static int ICC_store_key(char *skey, int keylen, int keyid, int keytype/*, int mode*/)
{
int iret;
int trytimes;
ICC_FILE file;
KEY key;
if(keyid > 9) return -1;
if(keylen != 8 && keylen != 16) return -1;
trytimes = 5;
write_des_de_key:
if(keytype == masterkey)
C51 COMPILER V7.07 ICCAPP 12/06/2003 18:49:10 PAGE 22
{
key.id = keyid + demk_offset;
}
else
{
key.id = keyid + dewk_offset;
}
key.type = DES_DE;
key.use_purview = 0xff;
key.update_purview = 0xf0;
key.edition_state = 0x01;
key.cid_cnt = 0x01;
key.keylen = keylen;
memcpy(key.key, skey, keylen);
iret = ICC_write_key(&key, UPDATE);
if(iret == 0x6a86)
{
iret = ICC_write_key(&key, LOAD);
/*
if(iret == SUCCESS)
{
trytimes = 5;
goto write_des_de_key;
}
*/
}
if(iret != SUCCESS)
{
trytimes --;
if(trytimes <= 0)
{
return iret;
}
goto write_des_de_key;
}
trytimes = 5;
write_des_en_key:
if(keytype == masterkey)
{
key.id = keyid + enmk_offset;
}
else
{
key.id = keyid + enwk_offset;
}
key.type = DES_EN;
key.use_purview = 0xff;
key.update_purview = 0xf0;
key.edition_state = 0x01;
key.cid_cnt = 0x01;
key.keylen = keylen;
memcpy(key.key, skey, keylen);
iret = ICC_write_key(&key, UPDATE);
if(iret == 0x6a86)
{
iret = ICC_write_key(&key, LOAD);
if(iret == SUCCESS)
{
trytimes = 5;
goto write_des_en_key;
}
C51 COMPILER V7.07 ICCAPP 12/06/2003 18:49:10 PAGE 23
}
if(iret != SUCCESS)
{
trytimes --;
if(trytimes <= 0)
{
return iret;
}
goto write_des_en_key;
}
return SUCCESS;
}
/********************************************************************
* 文件结构 *
* ,-----------------------------. *
* | MF-+-MFkeyEF | *
* | | +-LTkey(mkey) (1) | *
* | | +-bank_mkey(en_key)| *
* | | | (1 ~10) | *
* | | +-bank_mkey(de_key)| *
* | | | (11~20) | size of Key EF: *
* | | +-bank_wkey(en_key)| number of record(210*3+1max)*
* | | | (21~30) | * record length *
* | | +-bank_wkey(de_key)| record length: *
* | | | (31~40) | TAG(1)+len(1)+head(5) *
* | | + ... | +Key(8 or 16). *
* | +-DF01 | *
* | +-DF02 | SIZE >= 61*(1+1+5+8) *
* | +- ... | = 915 *
* `-----------------------------' set to maxsize 960 *
********************************************************************/
int ICC_creat_ltfs(void)
{
ICC_FILE file;
KEY key;
int iret;
int i, j;
int trytimes;
int trytimes1;
unsigned char ikey[8] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef};
#if 0
trytimes = 3;
// 验证口令, 如果口令正确, 退出, 否则继续.
verify_pin:
iret = ICC_verify_pin(ltkey, 8, 0);
if(iret == SUCCESS) return SUCCESS;
else
{
trytimes --;
if(trytimes)
goto verify_pin;
}
#endif
trytimes = 5;
/* 创建主文件(目录) */
creat_mf:
file.id = 0x3f00;
C51 COMPILER V7.07 ICCAPP 12/06/2003 18:49:10 PAGE 24
file.type = 0x38;
file.size = 0xffff;
file.c_r_purview = 0xf0;
file.e_w_purview = 0xf0;
memset(file.name, 0, sizeof(file.name));
file.name_len = 0;
iret = ICC_creat_file(&file);
if((iret != SUCCESS) && (iret != FILE_EXIST))
{
trytimes --;
if(trytimes <= 0)
return iret;
goto creat_mf;
}
trytimes = 5;
/* 选择主文件(目录) */
select_mf:
iret = ICC_select_file(NULL, 0, 0x3f00, 0);
if(iret != SUCCESS)
{
trytimes --;
if(trytimes <= 0)
return iret;
g
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -