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

📄 ic.c.bak

📁 网络中交换节点的上数据的交换和下行数据分发的硬件实现
💻 BAK
📖 第 1 页 / 共 3 页
字号:


/*本函数用于通过IC卡对密码卡进行初始化*/ 
  
  int card_init()
  {
   extern int r_IC(),inputkey();
   extern void flash_w(),secerase(),poke(),memcopy();
   extern int peek();
   int i,status;
   
   secerase(0x01440000);                     /*将flash的0x01440000扇区擦除*/
   
   status=r_IC(0x330,0x80008804,2);          /*从IC卡中读出RSA公钥模长*/
   if (status==0x30)
     {
      status=0x3;
      poke(0x80008800,0x3,2);
      goto label1;
     }
   if (status==0x32)
     {
      status=0x7;
      poke(0x80008800,0x7,2);
      goto label1;
     }                                     /*若读IC卡失败,进行相应处理*/
     
   status=r_IC(0x332,0x80008808,4);        /*从IC卡中读出RSA公钥的加密指数*/
   if (status==0x30)
     {
      status=0x3;
      poke(0x80008800,0x3,2);
      goto label1;
     }
   if (status==0x32)
     {
      status=0x7;
      poke(0x80008800,0x7,2);
      goto label1;
     }                                     /*若读IC卡失败,进行相应处理*/
   
   flash_w(0x80008804,0x01440000,2);        /*向flash中写入公钥模长和加密指数*/
   
   status=r_IC(0x436,0x80008804,2);         /*从IC卡中读出RSA私钥模长*/      
   if (status==0x30)
     {
      status=0x3;
      poke(0x80008800,0x3,2);
      goto label1;
     }
   if (status==0x32)
     {
      status=0x7;
      poke(0x80008800,0x7,2);
      goto label1;
     }                                     /*若读IC卡失败,进行相应处理*/
   
   flash_w(0x80008804,0x01440108,1);        /*向flash中写入私钥模长*/
   
   status=r_IC(0x6B8,0x80008804,2);         /*从IC卡中读出SMC公钥模长*/ 
   if (status==0x30)
     {
      status=0x3;
      poke(0x80008800,0x3,2);
      goto label1;
     }
   if (status==0x32)
     {
      status=0x7;
      poke(0x80008800,0x7,2);
      goto label1;
     }                                     /*若读IC卡失败,进行相应处理*/
   
   status=r_IC(0x6BA,0x80008808,4);         /*从IC卡中读出SMC公钥的加密指数*/   
   if (status==0x30)
     {
      status=0x3;
      poke(0x80008800,0x3,2);
      goto label1;
     }
   if (status==0x32)
     {
      status=0x7;
      poke(0x80008800,0x7,2);
      goto label1;
     }                                     /*若读IC卡失败,进行相应处理*/
   
   flash_w(0x80008804,0x0144038C,2);        /*向flash中写入SMC公钥模长和加密指数*/
   
   status=r_IC(0x320,0x80008808,16);        /*从IC卡中读出会话密钥*/
   if (status==0x30)
     {
      status=0x3;
      poke(0x80008800,0x3,2);
      goto label1;
     }
   if (status==0x32)
     {
      status=0x7;
      poke(0x80008800,0x7,2);
      goto label1;
     }                                     /*若读IC卡失败,进行相应处理*/
   
   status=r_IC(0x336,0x80008818,256);       /*从IC卡中读出RSA公钥的积(密文)*/       
   if (status==0x30)
     {
      status=0x3;
      poke(0x80008800,0x3,2);
      goto label1;
     }
   if (status==0x32)
     {
      status=0x7;
      poke(0x80008800,0x7,2);
      goto label1;
     }                                     /*若读IC卡失败,进行相应处理*/
   
   poke(0x80008804,16,2);                   /*输入待解密数据的组数*/
   inputkey(0x80008804,0x80008808,0x80008818,0x80008804,1,0);  /*用会话密钥解密RSA公钥的积*/

   for(i=0;i<16;i++)
    {
     memcopy(0x800088F4-i*16,0x80008908-i*16,4,2);
    }                                           /*移动RSA公钥的积(明文),为用kp1加密做准备*/
   status=r_IC(0x8,0x80008808,16);              /*从IC卡中读出主密钥kp1*/
   if (status==0x30)
     {
      status=0x3;
      poke(0x80008800,0x3,2);
      goto label1;
     }
   if (status==0x32)
     {
      status=0x7;
      poke(0x80008800,0x7,2);
      goto label1;
     }                                     /*若读IC卡失败,进行相应处理*/
   
   poke(0x80008804,16,2);                   /*输入待加密数据的组数*/
   inputkey(0x80008804,0x80008808,0x80008818,0x80008804,0,0);      /*用主密钥kp1加密RSA公钥的积*/
   flash_w(0x80008804,0x01440008,64);       /*向flash中写入RSA公钥的密文积*/
   
   status=r_IC(0x320,0x80008808,16);        /*从IC卡中读出会话密钥*/
   if (status==0x30)
     {
      status=0x3;
      poke(0x80008800,0x3,2);
      goto label1;
     }
   if (status==0x32)
     {
      status=0x7;
      poke(0x80008800,0x7,2);
      goto label1;
     }                                     /*若读IC卡失败,进行相应处理*/
   
   status=r_IC(0x438,0x80008818,640);       /*从IC卡中读出RSA私钥的密文部分*/
   if (status==0x30)
     {
      status=0x3;
      poke(0x80008800,0x3,2);
      goto label1;
     }
   if (status==0x32)
     {
      status=0x7;
      poke(0x80008800,0x7,2);
      goto label1;
     }                                     /*若读IC卡失败,进行相应处理*/
   
   poke(0x80008804,40,2);                   /*输入待解密数据的组数*/
   inputkey(0x80008804,0x80008808,0x80008818,0x80008804,1,0);                     /*用会话密钥解密RSA私钥的密文部分*/
   
   for(i=0;i<40;i++)
    {
     memcopy(0x80008A74-i*16,0x80008A88-i*16,4,2);
    }                                           /*移动RSA私钥,为用kp1加密做准备*/
   status=r_IC(0x8,0x80008808,16);              /*从IC卡中读出主密钥kp1*/
   if (status==0x30)
     {
      status=0x3;
      poke(0x80008800,0x3,2);
      goto label1;
     }
   if (status==0x32)
     {
      status=0x7;
      poke(0x80008800,0x7,2);
      goto label1;
     }                                     /*若读IC卡失败,进行相应处理*/
   
   poke(0x80008804,40,2);                    /*输入待加密数据的组数*/
   inputkey(0x80008804,0x80008808,0x80008818,0x80008804,0,0);                      /*用主密钥kp1加密RSA私钥*/
   flash_w(0x80008804,0x0144010C,160);       /*向flash中写入RSA私钥的密文*/
   
   status=r_IC(0x320,0x80008808,16);         /*从IC卡中读出会话密钥*/
   if (status==0x30)
     {
      status=0x3;
      poke(0x80008800,0x3,2);
      goto label1;
     }
   if (status==0x32)
     {
      status=0x7;
      poke(0x80008800,0x7,2);
      goto label1;
     }                                     /*若读IC卡失败,进行相应处理*/
   
   status=r_IC(0x6BE,0x80008818,256);        /*从IC卡中读出SMC公钥的积(密文)*/
   if (status==0x30)
     {
      status=0x3;
      poke(0x80008800,0x3,2);
      goto label1;
     }
   if (status==0x32)
     {
      status=0x7;
      poke(0x80008800,0x7,2);
      goto label1;
     }                                     /*若读IC卡失败,进行相应处理*/
   
   poke(0x80008804,16,2);                    /*输入待解密数据的组数*/
   inputkey(0x80008804,0x80008808,0x80008818,0x80008804,1,0);                      /*用会话密钥解密SMC公钥的积*/
   
   for(i=0;i<16;i++)
    {
     memcopy(0x800088F4-i*16,0x80008908-i*16,4,2);
    }                                           /*移动数据,为用kp1加密做准备*/ 
   status=r_IC(0x8,0x80008808,16);              /*从IC卡中读出主密钥kp1*/
   if (status==0x30)
     {
      status=0x3;
      poke(0x80008800,0x3,2);
      goto label1;
     }
   if (status==0x32)
     {
      status=0x7;
      poke(0x80008800,0x7,2);
      goto label1;
     }                                     /*若读IC卡失败,进行相应处理*/
   
   poke(0x80008804,16,2);                    /*输入待加密数据的组数*/
   inputkey(0x80008804,0x80008808,0x80008818,0x80008804,0,0);                             /*用主密钥加密SMC公钥的积*/
   flash_w(0x80008804,0x01440394,64);        /*向flash中写入SMC公钥的积(密文)*/
   
   secerase(0x01480000);                     /*将flash的0x01480000扇区擦除,即清空用户信息*/
   memcopy(0x01480000,0x8000C800,50,2);
   
   
   poke(0x8000BFFC,0,2);                     /*将用户状态码变为无用户使用状态*/
   
   status=0;
   poke(0x80008800,0,2);
   
label1:  return  status;
   
  }  
  
  
  /*本函数用于用所给的参数制密钥卡*/ 
  
  int keyIC_create()
  {
   extern int w_IC(),inputkey(),erandx();
   extern void poke(),memcopy();
   int i,status;
   unsigned int random[4];
   
   status=w_IC(0x80008804,0x0000,800);            /*将头信息写入IC卡中*/
   if (status==0x30)
     {
      status=0x3;
      poke(0x80008800,0x3,2);
      goto label2;
     }
   if (status==0x32)
     {
      status=0x7;
      poke(0x80008800,0x7,2);
      goto label2;
     }                                     /*若写IC卡失败,进行相应处理*/
   
   
   for (i=0;i<4;i++)
    {
     random[i]=erandx(); 
     poke(0x80008808+i*4,random[i],2);          /*产生会话密钥,并且写入相应位置,准备加密*/     
    }
    
   status=w_IC(0x80008808,0x320,16);        /*将会话密钥存入IC卡*/
   if (status==0x30)
     {
      status=0x3;
      poke(0x80008800,0x3,2);
      goto label2;
     }
   if (status==0x32)
     {
      status=0x7;
      poke(0x80008800,0x7,2);
      goto label2;
     }                                     /*若写IC卡失败,进行相应处理*/
   
   status=w_IC(0x80008B24,0x330,6);         /*将RSA公钥模长和加密指数存入IC卡*/
   if (status==0x30)
     {
      status=0x3;
      poke(0x80008800,0x3,2);
      goto label2;
     }
   if (status==0x32)
     {
      status=0x7;
      poke(0x80008800,0x7,2);
      goto label2;
     }                                     /*若写IC卡失败,进行相应处理*/
   
   memcopy(0x80008B2A,0x80008818,128,1);    /*将RSA公钥的积移到指定位置,准备加密*/
   
   poke(0x80008804,16,2);                   /*输入数据组数,准备加密*/
   
   inputkey(0x80008804,0x80008808,0x80008818,0x80008804,0,0);   /*用会话密钥加密RSA公钥的积*/ 
   
   status=w_IC(0x80008804,0x336,256);       /*将加密后的RSA公钥的积写入IC卡*/ 
   if (status==0x30)
     {
      status=0x3;
      poke(0x80008800,0x3,2);
      goto label2;
     }
   if (status==0x32)
     {
      status=0x7;
      poke(0x80008800,0x7,2);
      goto label2;
     }                                     /*若写IC卡失败,进行相应处理*/
   
   status=w_IC(0x80008C2A,0x436,2);         /*将RSA私钥的模长写入IC卡*/
   if (status==0x30)
     {
      status=0x3;
      poke(0x80008800,0x3,2);
      goto label2;
     }
   if (status==0x32)
     {
      status=0x7;
      poke(0x80008800,0x7,2);
      goto label2;
     }                                     /*若写IC卡失败,进行相应处理*/
   
   memcopy(random,0x80008808,4,2);          /*将会话密钥写入加密位置*/
   
   memcopy(0x80008C2C,0x80008818,160,2);    /*将RSA私钥的要加密部分移到加密位置*/
   
   poke(0x80008804,40,2);                   /*输入数据组数,准备加密*/ 
   
   inputkey(0x80008804,0x80008808,0x80008818,0x80008804,0,0); /*用会话密钥加密RSA私钥*/
   
   status=w_IC(0x80008804,0x438,640);       /*将加密后的RSA私钥写入IC卡*/ 
   if (status==0x30)
     {
      status=0x3;
      poke(0x80008800,0x3,2);
      goto label2;
     }
   if (status==0x32)
     {
      status=0x7;
      poke(0x80008800,0x7,2);
      goto label2;
     }                                     /*若写IC卡失败,进行相应处理*/
   
   status=w_IC(0x80008EAC,0x6B8,6);         /*将SMC公钥模长和加密指数存入IC卡*/
   if (status==0x30)
     {
      status=0x3;
      poke(0x80008800,0x3,2);
      goto label2;
     }
   if (status==0x32)
     {
      status=0x7;
      poke(0x80008800,0x7,2);
      goto label2;
     }                                     /*若写IC卡失败,进行相应处理*/
   
   memcopy(random,0x80008808,4,2);          /*将会话密钥写入加密位置*/
   
   memcopy(0x80008EB2,0x80008818,128,1);    /*将SMC公钥的积移到加密位置*/
   
   poke(0x80008804,16,2);                   /*输入数据组数,准备加密*/
   
   inputkey(0x80008804,0x80008808,0x80008818,0x80008804,0,0);   /*用会话密钥加密SMC公钥的积*/
   
   status=w_IC(0x80008804,0x6BE,256);       /*将加密后的SMC公钥的积存入IC卡*/
   if (status==0x30)
     {
      status=0x3;
      poke(0x80008800,0x3,2);
      goto label2;
     }
   if (status==0x32)
     {
      status=0x7;
      poke(0x80008800,0x7,2);
      goto label2;
     }                                     /*若写IC卡失败,进行相应处理*/
     
   status=0;
   poke(0x80008800,0,2);  
     
label2:  return  status;   
  }
  
  

⌨️ 快捷键说明

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