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

📄 destest_3des.c

📁 嵌入式linux系统下hi3510平台的osd开发源码
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <stdio.h>#include "hi_des_api.h"  static  unsigned char key_cbc[6][8]={{0x94,0xd3,0xf5,0x61,0x9c,0x63,0x65,0xf2},{0x6a,0x1e,0xca,0xbf,0x3b,0x8a,0x69,0x08},{0xd5,0x19,0xb1,0x2b,0xf4,0x6d,0x9c,0x5d},{0x12,0x34,0xbd,0xe6,0x5f,0x24,0xbc,0x62},{0xfd,0x62,0x4e,0x11,0x9f,0x1e,0x86,0x3b},{0x4f,0x86,0x91,0xd0,0xd6,0x06,0x27,0xe9}                              };  static  unsigned char pplaintext_cbc[2][8]={{0xb4,0x99,0xe2,0x34,0xef,0x2a,0xe0,0x57},{0xd7,0x25,0x53,0x3c,0x14,0xe1,0x8c,0xde}                               };  static  unsigned char ivin_cbc[2][8]={{0x17,0xe9,0xbb,0x79,0x53,0x99,0xdc,0x4a},{0x6b,0xbf,0x47,0x83,0x04,0x70,0x58,0xdf}                               };   static  unsigned char dout_cbc[2][8]={{0xae,0xb1,0x02,0x47,0x4c,0x3c,0xb7,0x0a},{0x73,0xdc,0x63,0x11,0x36,0x73,0xe5,0xc6}                              };  static  unsigned char mydout_cbc[2][8];/***********************************ecb******************************************/static  unsigned char key_ecb[3][8]={{0x16,0xac,0x15,0x1a,0xae,0xfe,0xb5,0x6d},{0x2f,0x98,0x6b,0x0c,0xb9,0xeb,0x64,0x1a},{0x9f,0xbe,0x67,0x4b,0xfa,0xa8,0x05,0xd4},                              };  static  unsigned char pplaintext_ecb[1][8]={{0xcd,0x16,0x68,0xba,0xac,0x7a,0xa6,0xf2},                               };   static  unsigned char dout_ecb[1][8]={{0x98,0xf3,0x89,0x4e,0x98,0xb7,0x7a,0x03},                              };  static  unsigned char mydout_ecb[1][8];/******************************************cfb-64***********************************/                           static  unsigned char key_cfb_64[6][8]={{0x16,0xac,0x15,0x1a,0xae,0xfe,0xb5,0x6d},{0x2f,0x98,0x6b,0x0c,0xb9,0xeb,0x64,0x1a},{0x9f,0xbe,0x67,0x4b,0xfa,0xa8,0x05,0xd4},{0xaa,0xc0,0x15,0x48,0xed,0x9f,0x5f,0x9c},{0xa1,0xcb,0xd6,0xcb,0x0e,0x7c,0x7b,0x83},{0x06,0xb0,0x9d,0xa2,0x02,0xaa,0x78,0xaf}                              };  static  unsigned char pplaintext_cfb_64[2][8]={{0xcd,0x16,0x68,0xba,0xac,0x7a,0xa6,0xf2},{0x4f,0x24,0xbc,0x86,0x4e,0x5c,0x11,0xb3}                               };  static  unsigned char ivin_cfb_64[2][8]={{0xd8,0x7e,0x88,0x45,0xe1,0xa5,0x9b,0x25},{0xe0,0xb0,0xdf,0x81,0x19,0xf7,0xa0,0x85}                               };   static  unsigned char dout_cfb_64[2][8]={{0xb7,0x4e,0xa0,0x2a,0x7f,0x5b,0xb7,0x66},{0x62,0xba,0x92,0xd3,0x60,0xfb,0xc6,0x38}                              };  static  unsigned char mydout_cfb_64[2][8];/******************************************cfb-8***********************************/                           static  unsigned char key_cfb_8[6][8]={{0x94,0xd3,0xf5,0x61,0x9c,0x63,0x65,0xf2},{0x6a,0x1e,0xca,0xbf,0x3b,0x8a,0x69,0x08},{0xd5,0x19,0xb1,0x2b,0xf4,0x6d,0x9c,0x5d},{0x4f,0x86,0x91,0xd0,0xd6,0x06,0x27,0xe9},{0xfd,0x62,0x4e,0x11,0x9f,0x1e,0x86,0x3b},{0x12,0x34,0xbd,0xe6,0x5f,0x24,0xbc,0x62}                              };  static  unsigned char pplaintext_cfb_8[2][8]={{0x57,0x00,0x00,0x00,0x00,0x00,0x00,0x00},{0xde,0x00,0x00,0x00,0x00,0x00,0x00,0x00}                          }; static  unsigned char ivin_cfb_8[2][8]={{0x17,0xe9,0xbb,0x79,0x53,0x99,0xdc,0x4a},{0x6b,0xbf,0x47,0x83,0x04,0x70,0x58,0xdf}                               };   static  unsigned char dout_cfb_8[2][8]={{0x83,0x00,0x00,0x00,0x00,0x00,0x00,0x00},{0x3c,0x00,0x00,0x00,0x00,0x00,0x00,0x00}                              };  static  unsigned char mydout_cfb_8[2][8];/******************************************cfb-1***********************************/                           static  unsigned char key_cfb_1[6][8]={{0x64,0x6b,0xfe,0x2f,0x87,0x3e,0x21,0x62},{0x29,0x28,0x30,0xb5,0xac,0xa4,0xaa,0x0e},{0xe6,0x1f,0xfe,0xfc,0x3a,0xcc,0x06,0x95},{0x42,0xef,0x35,0xf4,0xe2,0xc1,0x54,0x37},{0xab,0x0e,0x8f,0x8f,0x86,0x6d,0x3c,0xe4},{0xec,0x07,0xf3,0xf3,0x34,0xe1,0x3f,0x1b}                              };  static  unsigned char pplaintext_cfb_1[2][8]={{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}                               };  static  unsigned char ivin_cfb_1[2][8]={{0x7c,0x0c,0xb7,0xa6,0x0c,0xed,0x87,0x51},{0x81,0x9b,0x6a,0x6a,0x6c,0x3e,0x59,0x32}                               };   static  unsigned char dout_cfb_1[2][8]={ {0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00},{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}                              };  static  unsigned char mydout_cfb_1[2][8];/***********************************************ofb-64****************************/static  unsigned char key_ofb_64[6][8]={{0x01,0x11,0xd2,0x4a,0x71,0x3b,0x31,0x79},{0x25,0x0c,0x12,0xed,0x27,0x35,0x38,0x30},{0x33,0xbe,0x6b,0x9b,0x2d,0x41,0xf6,0x5b},{0xd8,0xa5,0xfd,0x6e,0x41,0xad,0x01,0x0f},{0xcd,0xcc,0xea,0x6d,0xad,0x36,0xa8,0x89},{0xd7,0x12,0xab,0x8f,0x15,0x64,0xa6,0x2a}                             };  static  unsigned char pplaintext_ofb_64[2][8]={{0xa1,0x3b,0x24,0x51,0x1f,0x1d,0x6b,0xf5},{0x2a,0x2e,0xde,0x6e,0x3b,0xd0,0x82,0x3f}                               };  static  unsigned char ivin_ofb_64[2][8]={{0x56,0x0b,0xab,0x36,0x33,0xb3,0x86,0xca},{0x65,0x77,0x87,0x8d,0xb7,0x70,0x5d,0xef}                               };   static  unsigned char dout_ofb_64[2][8]={{0x01,0x9e,0xd0,0x20,0x1d,0xcd,0x27,0x85},{0xd3,0x10,0xaa,0x0d,0xec,0x4f,0x1d,0xd3}                              };  static  unsigned char mydout_ofb_64[2][8];/********************************************ofb-8****************************/static  unsigned char key_ofb_8[6][8]={{0x30,0xa6,0x60,0xc0,0x53,0xac,0x75,0x37},{0x86,0x85,0xd4,0x7f,0x51,0x97,0x73,0x57},{0xe7,0xbe,0x24,0xed,0x23,0x87,0x95,0x23},{0xfd,0x44,0xdb,0x92,0xea,0xc4,0x5e,0xd5},{0x5c,0x05,0x7b,0x76,0x4a,0xb0,0x39,0x45},{0x1c,0x2b,0x6f,0xe1,0x3b,0x88,0x60,0xb1}                              };  static  unsigned char pplaintext_ofb_8[2][8]={{0x15,0x00,0x00,0x00,0x00,0x00,0x00,0x00},{0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00}                               };  static  unsigned char ivin_ofb_8[2][8]={{0x65,0x77,0x87,0x8d,0xb7,0x70,0x5d,0xef},{0x7c,0x57,0xf0,0x9c,0xe1,0x58,0x43,0x83}                               };   static  unsigned char dout_ofb_8[2][8]={{0x41,0x00,0x00,0x00,0x00,0x00,0x00,0x00},{0x90,0x00,0x00,0x00,0x00,0x00,0x00,0x00}                              };  static  unsigned char mydout_ofb_8[2][8];/************************************ofb-1**************************************/static  unsigned char key_ofb_1[6][8]={{0xfd,0xcb,0xa6,0x6d,0x72,0xef,0x9c,0x23},{0xfd,0x05,0x74,0x41,0x93,0xed,0xf0,0x10},{0x15,0xdd,0xbf,0xa2,0x57,0x0e,0xb0,0x01},{0x16,0xa9,0xcf,0x4d,0xf5,0x5d,0x01,0x2c},{0x00,0xfb,0xaf,0x10,0xeb,0x35,0xb2,0x55},{0xa0,0xae,0x38,0x3e,0x79,0x4e,0x21,0xc1}                              };  static  unsigned char pplaintext_ofb_1[2][8]={{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}                               };  static  unsigned char ivin_ofb_1[2][8]={{0xe1,0xf2,0xf6,0xd3,0xb8,0xe8,0xfa,0xb3},{0x74,0x5d,0x4f,0x97,0xab,0xd9,0xa3,0x4f}                               };   static  unsigned char dout_ofb_1[2][8]={{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},{0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00}                              };  static  unsigned char mydout_ofb_1[2][8];/****************************************over*********************************/int ofb_1_test();int ofb_8_test();int ofb_64_test();int cfb_1_test();int cfb_8_test();int cfb_64_test();int ecb_test();int cbc_test();     struct des_encrypt_ctrl ctrl;     struct keys  keys;    int main(void){     hi_des_init();   ofb_1_test();   ofb_8_test();   ofb_64_test();  cfb_1_test();  cfb_8_test();  cfb_64_test();  ecb_test();   cbc_test();    hi_des_exit();   return 0;}int ofb_1_test(void){     unsigned int i,k,j;     ctrl.des_endian=1; //little;     ctrl.des_shift =2; //64;     ctrl.des_type = 3; //ofb_1;     ctrl.des_alg = 1;     printf(" des_ofb_1_test begin!\n");      for(i=0;i<2;i++)     {              for(k=0;k<8;k++)           {               keys.keys1[k]=key_ofb_1[i*3][k];               keys.keys2[k]=key_ofb_1[i*3+1][k];               keys.keys3[k]=key_ofb_1[i*3+2][k];               ctrl.iv[k]=ivin_ofb_1[i][k];           }           hi_des_config(&ctrl);           if(i<1)           {                 hi_des_crypt(&pplaintext_ofb_1[i][0],&mydout_ofb_1[i][0],8,&keys);           }           else           {               hi_des_decrypt(&pplaintext_ofb_1[i][0],&mydout_ofb_1[i][0],8,&keys);           }           for(j=0;j<1;j++)           {               if((mydout_ofb_1[i][j]&0x80)!=(dout_ofb_1[i][j]&0x80))               {                   printf("des_ofb_1 test failed at: %d row!",i);                   return -1;               }           }      }         printf(" all des_ofb_1 tests passed!\n");     return 0;}int ofb_8_test(){     unsigned int i,k,j;     ctrl.des_endian=1; //little;     ctrl.des_shift =1; //64;     ctrl.des_type = 3; //ofb_8;     ctrl.des_alg = 1;     printf(" des_ofb_8_test begin!\n");      for(i=0;i<2;i++)     {                 for(k=0;k<8;k++)           {               keys.keys1[k]=key_ofb_8[i*3][k];               keys.keys2[k]=key_ofb_8[i*3+1][k];               keys.keys3[k]=key_ofb_8[i*3+2][k];               ctrl.iv[k]=ivin_ofb_8[i][k];           }           hi_des_config(&ctrl);           if(i<1)           {                 hi_des_crypt(&pplaintext_ofb_8[i][0],&mydout_ofb_8[i][0],8,&keys);

⌨️ 快捷键说明

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