/*************************************************************************** * Copyright (c) 2011, Broadcom Corporation * All Rights Reserved * Confidential Property of Broadcom Corporation * * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. * * $brcm_Workfile: $ * $brcm_Revision: $ * $brcm_Date: $ * * Module Description: SHA1 computation using SHARF block * * Revision History: * * $brcm_Log: $ * * ***************************************************************************/ //#include "cache_util.h" #include "sha1o.h" extern void clear_all_d_cache(void); struct dma_desc_t { uint32 word[8]; }; #define REG(x) ((volatile uint32 *)(0xB0000000 | (x))) #define RWRITE(addr, value) if(1){ *(REG(addr)) = (value); } else #define RREAD(addr) (*REG(addr)) void SHA1Compute_ram( uint8 * image_ptr, int len, uint32 * digest ) { uint32 value; uint32 sha1_output; uint32 i; struct dma_desc_t * pdesc; uint32 data[16]; pdesc = (0 == ((uint32)&data & 0x1f)) ? (struct dma_desc_t *)&data : (struct dma_desc_t *)(((uint32)&data[8]) & ~0x1f); for(i = 0; i < 8; i++){ pdesc[0].word[i] = 0; }; len >>= 3; /* divide by 8 as we need lenght in bytes */ pdesc[0].word[0] = ((uint32)image_ptr & (~0xA0000000)); /* field is ignored in sha1 mode */ pdesc[0].word[1] = ((uint32)0 & (~0xA0000000)); pdesc[0].word[2] = 0x40000000 | (len); /* 4 le, 0 be endian may change */ pdesc[0].word[3] = 0x0; pdesc[0].word[4] = 0x00000010; /* sha-160 */ clear_all_d_cache(); // flush_dcache((unsigned int)image_ptr, (unsigned int)image_ptr + len); // flush_dcache((unsigned int)pdesc, (unsigned int)pdesc + 8*4); value = RREAD(0x00340004); RWRITE(0x00340004, 0x00000000); RWRITE(0x00340008, 0x00000003); RWRITE(0x00340800, 0x00000001); RWRITE(0x00340100, (((uint32)pdesc) & (~0xA0000000))); RWRITE(0x00340104, 0x00000001); do{ value = RREAD(0x00340110); }while (value != 2); RWRITE(0x00340104, 0x00000000); sha1_output = 0x340018; /* end address of sha1 value */ for(i=0; i < 5; i++){ digest[i] = RREAD(sha1_output); sha1_output -= 4; } }