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

📄 main.c

📁 网络中交换节点的上数据的交换和下行数据分发的硬件实现
💻 C
字号:
#include "reg.h"

 /*本函数是CBB-001加密卡的主程序,即调度程序*/

       void main()
       {
        
        extern int peek(),IC_Start(),poke(),dtopi(),ini(),memcopy();
        extern int random_create(),RSAkey_create(),SMCRSAkey_read(),cardRSAkey_read();
        extern int KW_read(),KW_add(),KW_delete();
        extern int inputkey(),ssp02_update();
        extern int ssp02_set(),makeICHead();
        extern int ssp02_hash_update(),hash_read(),inputkey_hash(),inputkey_hash_edn();
        extern int card_init(),keyIC_create(),IC_read(),IC_write(),IC_clean(),operatorIC_create(),user_authen();
        extern int user_delete(),IChead_read(),logout(),log_in(),read_flash(),write_flash();
        
        extern int inputkey_hash(), ipsec_single_en(),ipsec_single_de();
        extern int ipsec_multi_en(),ipsec_multi_de(),rsapub_inputkey_ende(),rsapri_ende();
        extern int rsapri_inputkey_ende(),read_flash(),write_flash(),cardserial_write(),cardserial_read();
        extern int softrev_read();
        
        
        
        
  
        int com,status,temp; 
        
  
    /*    on_IC();    */                          /*IC卡上电*/ 
 
       ini();                                    /*对加密卡进行初始化*/
        
        memcopy(0x01460000,0x8000C000,160,2);     /*将用户使用的扇区读到内存*/ 
        
        memcopy(0x01480000,0x8000C800,50,2);      /*将用户信息读到内存*/
        
                                           
        status=0x0;                               /*预置状态值*/
        
        
       // poke(0x80008800,0x10000,2);               /*设置加密卡准备好标志字,表示主机可以发命令*/
        
 
  
        
             
        

chaxun:   if ((peek(0x01A40008,2)&0x40)==0x40)
            {
             //主机读DMA开始
             if (*(unsigned volatile int *)0x018C0018==0x20)
                {
             //设置读完成标志   // 
                 *(unsigned volatile int *)0x018C0018=0x21;
                 *(unsigned volatile int *)0x8000fffc=0x12345678;
                 int_host();
                 goto chaxun;
                 
                 } 
             
             //    poke(0x01A40008,8,2);
            }
          else { goto chaxun; }      
          com=peek(0x80008800,2);   
             
         /***********用国密芯片实现的功能**********/ 

         if((com>0x2100)&&(com<0x2200))
          switch(com)
           {
            case 0x2101 : status=inputkey(0x80008804,0x80008808,0x80008818,0x80008804,0,1); break;     /*用输入的对称密钥加密数据*/  
          
            case 0x2102 : status=inputkey(0x80008804,0x80008808,0x80008818,0x80008804,1,1); break;     /*用输入的对称密钥解密数据*/
            
           // case 0x2103 : status=kw_en(); break;            	/*一次一密报文加密   NEW !!*/
          
            //case 0x2104 : status=kw_de(); break;            	/*一次一密报文解密   NEW !!*/
            
            case 0x2105 : status=ssp02_set(0); break;     	/*设置ssp02为加密状态*/
            
            case 0x2106 : status=ssp02_update(0); break;    	/*将要加密的数据写入ssp02*/
            
            case 0x2107 : status=ssp02_set(1); break;     	/*设置ssp02为解密状态*/
            
            case 0x2108 : status=ssp02_update(0); break;    	/*将要解密的数据写入ssp02*/
          
            default     : poke(0x80008800,0x4F1,2);status=0x4F1;  /*若命令非法,通知主机*/
           }  
         /***************密钥管理*****************/
         else if((com>0x1100)&&(com<0x1200))
          switch(com)
           {
            case 0x1101 : status=random_create(); break;        /*产生指定长度的随机数*/
    
            case 0x1102 : status=RSAkey_create(); break;        /*产生RSA公私钥对*/
          
            case 0x1103 : status=cardRSAkey_read(); break;      /*读出加密卡内的RSA公钥*/
          
            case 0x1104 : status=SMCRSAkey_read(); break;       /*读出加密卡内SMC公钥*/
            
            case 0x1105 : status=KW_read(); break;        	    /*读出工作密钥KW new!!*/
            
            case 0x1106 : status=KW_add(); break;         		/*添加工作密钥KW new!!*/
            
            case 0x1107 : status=KW_delete(); break;      	    /*添加工作密钥KW new!!*/
            
            default     : poke(0x80008800,0x4F2,2);status=0x4F2;  /*若命令非法,通知主机*/
           }
         /****************IC卡操作*****************/ 
         else if((com>0x1200)&&(com<0x1300)) 
          {
         //  status=IC_Start();                                      /*IC卡上电*/ 
           
          if(peek(0x80008800,2)==0x4)
            {
             dtopi();
             goto chaxun;
            }
           if(com==0x1201) status=card_init();              	/*通过IC卡对密码卡进行初始化*/
      
           else if(com==0x1202) status=keyIC_create();        	/*用所给参数制密钥卡*/
            
           else if(com==0x1203) status=IC_read();             	/*从IC卡的指定地址读取指定长度的数据*/
           
           else if(com==0x1204) status=IC_write();            	/*向IC卡的指定地址写入指定长度的数据*/
            
           else if(com==0x1205) status=IC_clean();            	/*清除IC卡中的内容*/
            
           else if(com==0x1206) status=operatorIC_create();   	/*制操作员IC卡*/
            
           else if(com==0x1207) status=log_in();         	/*验证用户身份*/
                 	/*验证用户身份*/
            
           else if(com==0x1208) status=user_delete();         	/*清除密码卡内某个操作员信息*/
            
           else if(com==0x1209) status=IChead_read();         	/*读出密钥卡或身份卡头信息内容*/
           
           else if(com==0x1210) status=logout();        	/*复位密码卡*/
            
           else if(com==0x1211) status=makeICHead();  
            
            
           else {poke(0x80008800,0x4F3,2);status=0x4F3; }    		/*若命令非法,通知主机*/
          }
             
         /***************与HASH相关的功能**************/     
         else if((com>0x2200)&&(com<0x2300))
          switch(com)
           {
            case 0x2201 : status=ssp02_hash_update(0x80008804,0x80008808,1); break;         /*向ssp02写入要产生hash值的数据*/
          
            case 0x2202 : status=hash_read(0x80008804,1); break;         /*读取报文的hash值*/
          
            case 0x2203 : status=inputkey_hash(peek(0x80008804,2),0x80008808,0x80008818,0x80008804,1); break;  /*产生数据摘要*/
            
            case 0x2204 : status=kw_hashSet(); break;
           
             default     : poke(0x80008800,0x4F4,2);status=0x4F4;  /*若命令非法,通知主机*/
           }
         
         else if((com>0x2300)&&(com<0x2400))
          switch(com)
           {
            case 0x2301 : status=inputkey_hash_edn(0x80008804,0x80008808,0x80008818,0x80008804,0); break;     /*带hash认证的对称加密函数*/   
          
            case 0x2302 : status=inputkey_hash_edn(0x80008804,0x80008808,0x80008818,0x80008804,1); break;     /*带hash认证的对称解密函数*/
            
            //case 0x2303 : status=kw_hash_en(); break;  				 /*带HASH认证一次一密加密new!!  new!!*/
            
           // case 0x2304 : status=kw_hash_de(); break;  				 /*带HASH认证一次一密解密new!!  new!!*/
                        
           case 0x2305 : status=ssp02_update(1); break;         		     /*数据直接进入数据通道,并读取产生的杂凑值*/
            
            case 0x2306 : status=ipsec_single_en(); break;     		 /*用同一密钥的基于IPSec的IP报文加密*/
            
            case 0x2307 : status=ipsec_multi_en(); break;         	 /*用不同密钥的基于IPSec的IP报文加密*/ 
            
            case 0x2308 : status=ipsec_single_de(); break;         	 /*用同一密钥的基于IPSec的IP报文解密*/ 
            
            case 0x2309 : status= ipsec_multi_de(); break;         	 /*用不同密钥的基于IPSec的IP报文解密*/
             
            default     : poke(0x80008800,0x4F5,2);status=0x4F5;       /*若命令非法,通知主机*/
           }
           
            /****************RSA加解密运算****************/
         else if((com>0x3100)&&(com<0x3200))
          switch(com)
           {
            case 0x3101 : status=rsapub_inputkey_ende(); break;      /*用输入的RSA公钥加、解密*/
          
            case 0x3102 : status=rsapri_ende(); break;         		 /*用卡内的私钥加解密数据*/
          
            case 0x3103 : status=rsapri_inputkey_ende(); break;      /*用输入的私钥解密数据*/
            
            default     : poke(0x80008800,0x4F6,2);status=0x4F6;       /*若命令非法,通知主机*/ 
           }
            
            /****************系统维护*********************/
         else if((com>0x4100)&&(com<0x4200)) 
          switch(com)
           {
           case 0x4101 : status=read_flash(); break;        		 /*从flash的指定扇区读取指定长度的数据*/
          
           case 0x4102 : status=write_flash(); break;        		 /*向flash中的指定扇区写入指定长度的数据*/
          
            case 0x4103 : status=cardserial_write(); break;          /*写入密码卡的ID号(密码卡制造商提供)*/
          
            case 0x4104 : status=cardserial_read(); break;           /*读取密码卡的ID号(密码卡制造商提供)*/
          
            case 0x4105 : status=softrev_read(); break;              /*读取程序版本号(密码卡制造商提供)*/
          
            default     : poke(0x80008800,0x4F7,2);status=0x4F7;       /*若命令非法,通知主机*/
           }
         
         else {poke(0x80008800,0x4F8,2);status=0x4F8;}     	         /*若命令非法,通知主机*/
         *(unsigned volatile int *)0x018C0018=0x41;
         int_host();
       
        goto chaxun;
 
       }
       
       
       
 

⌨️ 快捷键说明

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