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

📄 des3des.c

📁 OMAP1030 处理器的ARM 侧硬件测试代码 OMAP1030 是TI的双核处理器
💻 C
📖 第 1 页 / 共 2 页
字号:
    DES3DES_DES_KEY2_H = aBunch->Key2H;
    DES3DES_DES_KEY2_L = aBunch->Key2L;
    
    DES3DES_DES_KEY3_H = aBunch->Key3H;
    DES3DES_DES_KEY3_L = aBunch->Key3L;
  }
 
  return 1; // if correct
}

int DES_Load8Bytes(UWORD32 *Data ) {  // load 8 bytes into DesInputRegs (L/H)
  UWORD32 tmp;
  int w_flag = 0;
 
  
  // polling input_ready bit in order to write at the write time... must be high ()
  while (!w_flag) {
    tmp = DES3DES_DES_CTRL;
    tmp &= 0x00000002;
    w_flag = tmp;
  }

  DES3DES_DES_DATA_L = *Data ;        // Low part
  DES3DES_DES_DATA_H = *(Data + 1) ;  // higher part
  
  return 1;
}

int DES_Read8Bytes(UWORD32 *Data) {  // copy 8 bytes from DesOutputRegs (l/H)
  // NO ALLOCATION DONE!!
   UWORD32 tmp;
  int r_flag;

    // waiting for the output_ready bit.
  
  while (!r_flag) {
    tmp = DES3DES_DES_CTRL;
    tmp &= 0x1;
    r_flag = tmp;
  }
  
  *Data = DES3DES_DES_DATA_L;
  *(Data + 1) = DES3DES_DES_DATA_H;

  return 1;  
}


int DES_Start() {
  // raise bit 5 of DES_MASK
  
  //register UWORD32 tmp2, tmp;
  
  DES3DES_DES_MASK |= 0x20;   // put bit 5 to 1
  
  return 1; // if correct 
}

int DES_Soft_Reset()
{
  UWORD32 tmp, reset_flag;
  // put bit 2 to 1
  DES3DES_DES_MASK = 0x2; 
  
  tmp = 0;
  //then polling  when reset has finished
  while (!tmp) {
    tmp = DES3DES_DES_SYSSTATUS;
    tmp &= 0x1;
    //reset_flag = tmp;
  }
  return 1;
}
    
  
int DES_PIO_Test(BIT desmode, 
		 BIT direction , 
		 UWORD32 data_Loc, 
		 UWORD32 data_Dest, 
		 UWORD16 data_Size,  
		 struct Key_struct *DesKeys ) {

  // Programmed IO Test => non-DMA Test
  // data_Size is in BYTES!!!!

  int i, j, ret_val;
  BIT cbcmode;
  unsigned int size_in_word64 = data_Size / 8;
  unsigned int leak = data_Size % 4;


  // first thing to do is to transmit the desmode value in the deskey struct (transparent feature). 
  // it's to avoid unnecessary memory transfert.
  DesKeys->desmode = desmode;

  
  if (leak != 0) {   // detect uncomplete UWORD32
    size_in_word64++;
  }
  
  // DesCtrlReg Params:
  //TDes-> desmode = 1, Des -> desmode = 0;
  //cbc mode on-> cbcmode= 1
  //encryption-> direction = 1, dec -> direction = 0 
  cbcmode = 0;

  // DmaMode = 0, clkMode is 0, direct busmode is fixed also at 0

  ret_val = DES_SetMaskReg(0 , 0 , 0);
  
  // DES3DES - DES mode UT- Test Keys Loading
  
  ret_val = DES_LoadKey(DesKeys);
  
  
  // DES3DES - DES mode UT- Test DES_CTRL Reg configuration
  
  ret_val = DES_SetCtrlReg(desmode, cbcmode, direction);
  
  // DES3DES - DES mode UT- Test Loading input buffer by host - first time
  ret_val = DES_Load8Bytes( (UWORD32 *) data_Loc);
    
  // DES3DES - DES mode UT- Test Starting simple calculation with Output read--- NO DMA
  
  ret_val = DES_Start();
    
  for (i=0; i <= (size_in_word64 - 1); i++) {
    // Reading the first result then writing the next data word to compute.
    j = 8 * i;
    ret_val = DES_Read8Bytes( (UWORD32 *) (data_Dest + j));
    
    
      // read buffer to get the first enc. block
      // and fill des3des with another Long.
    if (i != (size_in_word64 - 1)) 
      ret_val = DES_Load8Bytes( (UWORD32 *) (data_Loc + j + 8));
    
  }

  return 1;
  
}

void W32copy(UWORD32 dataSrc[], UWORD32 dataDest[], UWORD16 length )
{
  register int i, UW32Length;

  UW32Length = length/4;  // length in UWORD32.
  
  for (i = 0; i < UW32Length;  i++)
    {
      (dataDest[i]) = (dataSrc[i]);
    }
  return;
}

int DES_DoDmaFetchAndFeed(UWORD32 aSource, UWORD32 aDest, UWORD16 aSize) {
  
  UWORD16 aFrame = aSize/8 ;
  UWORD16 DMA_Mem_Perif; // 1 frame is 8 bytes, 
  if (!aSize%8)             // not a perfect size
    aFrame++;
  
  DmaCount = 2;
  
  DMAT_ConfigureRheaMemTransfertFrameMode_OMAP32(
		   DMA_CHANNEL_1,		    // channel number 
		   DMA_RHEA, 			    // src port
		   (UWORD32) (&DES3DES_DES_DATA_L), // src address base 
		   DMA_EMIFF,    		    // emiff
		   aDest,	                    // Dest address    	 
		   DMA_TYPE_32_BITS,		    // type of dma word size    
		   (UWORD16) BUFFER_SIZE,    	    // frame size : BUFFER_SIZE bytes
		   (UWORD16) aFrame,                // receive N frame
		   2);                              //DES3DES OUT DMA request (56) is crossbarred to line 1
  
  
  DMAT_ConfigureRheaMemTransfertFrameMode_OMAP32( 
		   DMA_CHANNEL_0,	             // channel number
		   DMA_EMIFF,                        // SRC port
		   aSource,                          // src mem
		   DMA_RHEA, 	                     // Dest port 
		   (UWORD32) (&DES3DES_DES_DATA_L),  // UART base address 
		   DMA_TYPE_32_BITS,	             // DMA_TYPE_32_BITS or DMA_TYPE_8_BITS?
		   BUFFER_SIZE,    	             // frame size : BUFFER_SIZE bytes
		   aFrame,                           // transmit X frame
		   1);                               // DES3DES IN DMA request (32) is crossbarred to line 0
  
  
  // Enable channels
  DMA_Omap32EnableChannel(DMA_CHANNEL_0);
  DMA_Omap32EnableChannel(DMA_CHANNEL_1);
  
  
  
}


int DES_DMA_Test(BIT desMode, 
		 BIT direction, 
		 UWORD32 data_Loc, 
		 UWORD32 data_Dest, 
		 UWORD16 data_Size,  
		 struct Key_struct *DesKeys ) {

  unsigned int usable_size = data_Size;
  unsigned int leak = data_Size % 4;
  int ret_val;
  UWORD32 ptr32;


  // first thing to do is to transmit the desmode value in the deskey struct. 
  // It's to avoid unnecessary memory transfert.
  DesKeys->desmode = desMode;

  if ((data_Size % 8)) {
    usable_size++;
  }

  
    // data_size is the size in bytes!!!
    
  SetGroupBits(CONFIGURATION_FUNC_MUX_ARM_DMA_A,
	       CONFIGURATION_FUNC_MUX_ARM_DMA_A_CONF_ARM_DMA_REQ_01_POS, 
	       CONFIGURATION_FUNC_MUX_ARM_DMA_A_CONF_ARM_DMA_REQ_01_NUMB, 
	       (DES_3DES_IN_DMAREQ-1));
  
  SetGroupBits(CONFIGURATION_FUNC_MUX_ARM_DMA_A, 
	       CONFIGURATION_FUNC_MUX_ARM_DMA_A_CONF_ARM_DMA_REQ_02_POS, 
	       CONFIGURATION_FUNC_MUX_ARM_DMA_A_CONF_ARM_DMA_REQ_02_NUMB, 
	       (DES_3DES_OUT_DMAREQ-1));
  // Verification:
  
  
  // Setting up INTH for Dma if enabled...

  INTH2_InitLevel   (DMA_CH0_INT,     INTH_IRQ, DMA_CH0_INT,     INTH_LOW_LEVEL_SENSITIVE);  
  INTH2_EnableOneIt (DMA_CH0_INT,     INTH_IRQ); 
  INTH2_InitLevel   (DMA_CH1_INT,     INTH_IRQ, DMA_CH1_INT,     INTH_LOW_LEVEL_SENSITIVE);  
  INTH2_EnableOneIt (DMA_CH1_INT,     INTH_IRQ); 
  
  // First copy test data to Testram where DMA works fine.
  W32copy((UWORD32*)data_Loc, ram_Srcdata, data_Size);
  

  // Then applying good mask
  ret_val = DES_SetMaskReg(0 , 1 , 0); // direct_busmode, dmamode and clkmode
  
  // DES3DES - DES mode UT- Test Keys Loading
  
  ret_val = DES_LoadKey(DesKeys);

    
  // DES3DES - DES mode UT- Test DES_CTRL Reg configuration
  
  ret_val = DES_SetCtrlReg(desMode, 0, direction); // no cbc Mode (=0) for instance
  
  // **********  Setting  up DMA configuration
  DMA_Omap32SetupSystemDma(DMA_FREE_RUNNING);
  
  // Configuration of 2 dma channels
  DES_DoDmaFetchAndFeed((UWORD32) ram_Srcdata,(UWORD32) ram_Resdata, data_Size);
  
  // DES3DES - DES mode UT- Test Loading input buffer by DMA
  // We are expecting 'dmaCount' interrupt request from dma when it's finished.
  DmaCount = 2; 
  // Des_Start() enable dit 5 of DES_MASK that start computation.
  DES_Start();
 
  // wait for interrupt...
  while (DmaCount > 0) {}
  
  // for each loop (read results/write data), we launch 2 dma access, one to take the output data onto 
  // testram, and one that should fill input buffer with a new data to compute. The good  
  // synchronisation between these 2 operations is ensured by Des3Des core.
  
  // now enc/decryption should be finished...
  
  // last action: copy to sdram not to work in testram.
  W32copy( ram_Resdata, (UWORD32*)data_Dest, data_Size);
  
  //set start bit to 0 after completion
  ptr32 = DES3DES_DES_MASK;
  ptr32 &= 0xffffbf;
  DES3DES_DES_MASK = ptr32;

  return 1;
  
}

int hw_des3des_start(struct Des_Struct* myStruct) {
  
  int ret_val;
  //DES_Soft_Reset();
  
  if (myStruct->dmaMode == 0) {
    ret_val = DES_PIO_Test(myStruct->desMode, 
			 myStruct->direction, 
			 myStruct->data_Loc, 
			 myStruct->data_Dest, 
			 myStruct->data_Size,  
			 myStruct->KeyBunchPtr);
  }
  else{
    if (myStruct->dmaMode == 1) {  // ensure test, return -1 otherwise
    ret_val = DES_DMA_Test(myStruct->desMode, 
			 myStruct->direction, 
			 myStruct->data_Loc, 
			 myStruct->data_Dest, 
			 myStruct->data_Size,  
			 myStruct->KeyBunchPtr );
    }}
  // TBD
  
  

  //DES_Soft_Reset(); 
  return ret_val;

}

⌨️ 快捷键说明

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