Ejemplo n.º 1
0
/******************************************************************************
 * RETURN SECROIMG MD PLAINTEXT DATA
 ******************************************************************************/
uint32 sec_secro_md_get_data (SECRO_USER user, uchar* buf, uint32 offset, uint32 len)
{
    uint32 ret = SEC_OK;
    const uint32 cipher_len = sizeof(AND_AC_ANDRO_T) + sizeof(AND_AC_MD_T) + sizeof(AND_AC_MD2_T);   

    osal_secro_lock();

    /* ----------------- */
    /* check             */
    /* ----------------- */

    if(FALSE == bSecroExist)
    {
        ret = ERR_SECROIMG_IS_EMPTY;
        goto _exit;
    }

    if(len == 0)
    {
        ret = ERR_SECROIMG_INVALID_BUF_LEN;
        goto _exit;
    }

    if (0 != (len % sp_hacc_blk_sz())) 
    {   
        ret = ERR_HACC_DATA_UNALIGNED;
        goto _exit;
    }    

    /* ------------------------ */       
    /* decrypt secroimg         */
    /* ------------------------ */
    if(TRUE == sec_secro_ac())
    {
        sp_hacc_dec((uchar*)&secroimg.m_andro, cipher_len, TRUE,HACC_USER1,TRUE);
    }

    /* ------------------------ */       
    /* check header             */
    /* ------------------------ */                
    if(AC_ANDRO_MAGIC != secroimg.m_andro.magic_number)
    {
        ret = ERR_SECROIMG_HACC_AP_DECRYPT_FAIL;
        goto _exit;
    }

    if(AC_MD_MAGIC != secroimg.m_md.magic_number)
    {
        ret = ERR_SECROIMG_HACC_MD_DECRYPT_FAIL;                    
        goto _exit;
    }
  
    if(AC_MD2_MAGIC != secroimg.m_md2.magic_number)
    {
        ret = ERR_SECROIMG_HACC_MD_DECRYPT_FAIL;                    
        goto _exit;
    }
    
    /* ------------------------ */       
    /* fill buffer              */
    /* ------------------------ */    
    /* only copy the data with user specified length */
    switch(user)
    {
        case SECRO_MD1:
            mcpy(buf,secroimg.m_md.reserve+offset,len);
            break;
        case SECRO_MD2:
            mcpy(buf,secroimg.m_md2.reserve+offset,len);
            break;
        default:
            SMSG(TRUE,"[%s] MD user not supported!\n",MOD);            
            break;
    }
    
    /* ------------------------ */       
    /* encrypt secro image      */
    /* ------------------------ */ 
    if(TRUE == sec_secro_ac())
    {    
        sp_hacc_enc((uchar*)&secroimg.m_andro, cipher_len, TRUE,HACC_USER1,TRUE);
    }

_exit:

    osal_secro_unlock();

    return ret;
}
Ejemplo n.º 2
0
int sec_dev_read_secroimg(void) 
{    
    int ret  = SEC_OK;  
    
    uint32 search_offset = SECRO_SEARCH_START;
    uint32 search_len = SECRO_SEARCH_LEN;

    uint32 mtd_num;
    uint32 mtd_off = SECRO_SEARCH_START;
    
    const uint32 img_len = rom_info.m_sec_ro_length;
    const uint32 cipher_len = sizeof(AND_AC_ANDRO_T) + sizeof(AND_AC_MD_T)+ sizeof(AND_AC_MD2_T);

    /* ------------------------ */    
    /* check status             */    
    /* ------------------------ */    
    if(0 == secro_img_mtd_num)
    {
        ret = ERR_SECROIMG_PART_NOT_FOUND;
        goto _end;
    }

    mtd_num = secro_img_mtd_num;

    /* ------------------------ */    
    /* check parameter          */    
    /* ------------------------ */    
    if(0 == img_len)
    {
        ret = ERR_SECROIMG_INVALID_IMG_LEN;
        goto _end;
    }    

    if(img_len != sizeof(secroimg))
    {
        ret = ERR_SECROIMG_LEN_INCONSISTENT_WITH_PL;
        goto _end;
    }

    SMSG(TRUE,"[%s] SECRO image len '0x%x'\n",MOD, sizeof(secroimg));

    /* ------------------------ */    
    /* find ac region           */
    /* ------------------------ */    

    /* read 1MB nand flash data to search rom info */
    for(search_offset = SECRO_SEARCH_START; search_offset < (search_len + SECRO_SEARCH_START); search_offset += SECRO_SEARCH_REGION)
    {
        /* search partition */
        if(mtd_off < mtd_part_map[mtd_num].sz)
        {
            if(FALSE == dump_secro_info)
            {
                SMSG(TRUE,"dev %2d, 0x%08x, 0x%08x\n", mtd_num, mtd_off, search_offset);     
                dump_secro_info = TRUE;
            }

            /* ------------------------ */    
            /* search secro image       */
            /* ------------------------ */              
            ret = read_info (mtd_num, mtd_off, SECRO_SEARCH_REGION, ROM_SEC_AC_REGION_ID, ROM_SEC_AC_REGION_ID_LEN, img_len, (uchar*)&secroimg);
            
            if(SEC_OK == ret)
            {
                SMSG(TRUE,"[%s] SECRO img is found (lock)\n",MOD);
                
                /* ------------------------ */       
                /* decrypt secro image      */
                /* ------------------------ */           
                osal_secro_lock();
                
                dump_buf((uchar*)&secroimg.m_andro,0x4);
                if(TRUE == sec_secro_ac())
                {
                    sp_hacc_dec((uchar*)&secroimg.m_andro, cipher_len, TRUE,HACC_USER1,TRUE);
                }
                dump_buf((uchar*)&secroimg.m_andro,0x4);    

                /* ------------------------ */       
                /* check integrity          */
                /* ------------------------ */
                if(SEC_OK != (ret = sec_secro_check()))
                {
                    osal_secro_unlock();
                    goto _end;
                }

                /* ------------------------ */       
                /* encrypt secro image      */
                /* ------------------------ */
                if(TRUE == sec_secro_ac())
                {                        
                    sp_hacc_enc((uchar*)&secroimg.m_andro, cipher_len, TRUE,FALSE,TRUE);
                }
                dump_buf((uchar*)&secroimg.m_andro,0x4);   

                /* ------------------------ */       
                /* SECROIMG is valid        */
                /* ------------------------ */                
                bSecroExist = TRUE;
                        
                osal_secro_unlock();
                
                goto _end;

            }
            
        }
    
        /* next should move to next partition ? */
        if(search_offset >= mtd_part_map[mtd_num+1].off)
        {
            mtd_num ++;
            mtd_off = 0;
            search_offset -= SECRO_SEARCH_REGION;
        }
        else
        {
            mtd_off += SECRO_SEARCH_REGION;            
        } 
    }

    ret = ERR_SECROIMG_MTD_NOT_FOUND;

_end:

    return ret;
}
Ejemplo n.º 3
0
/******************************************************************************
 * RETURN SECROIMG MD PLAINTEXT DATA
 ******************************************************************************/
uint32 masp_secro_md_get_data (uchar *md_info, uchar* buf, uint32 offset, uint32 len)
{
    uint32 ret = SEC_OK;
    uint32 cipher_len = sizeof(AND_AC_ANDRO_T) + sizeof(AND_AC_MD_T) + sizeof(AND_AC_MD2_T);   
    AND_AC_MD_INFO_V3a_T* cur_md_info = NULL;
    uint32 md_info_len = 0; 
    uint32 index = 0;

    osal_secro_lock();

    /* ----------------- */
    /* check             */
    /* ----------------- */

    if (NULL == md_info)
    {
        ret = ERR_SECROIMG_EMPTY_MD_INFO_STR;
        goto _exit;
    }
    else
    {
        md_info_len = strlen(md_info);    
    }

    if(FALSE == bSecroExist)
    {
        ret = ERR_SECROIMG_IS_EMPTY;
        goto _exit;
    }

    if(len == 0)
    {
        ret = ERR_SECROIMG_INVALID_BUF_LEN;
        goto _exit;
    }

    if (0 != (len % masp_hal_sp_hacc_blk_sz())) 
    {   
        ret = ERR_HACC_DATA_UNALIGNED;
        goto _exit;
    }    

    /* check if it only supports secro v3 format */
    if (0 == secroimg.m_header.world_phone_support)
    {

        SMSG(TRUE,"[%s]sro v3  \n",MOD);
    /* ------------------------ */       
    /* decrypt secroimg         */
    /* ------------------------ */
    if(TRUE == sec_secro_ac())
    {
        masp_hal_sp_hacc_dec((uchar*)&secroimg.m_andro, cipher_len, TRUE,HACC_USER1,TRUE);
    }

    /* ------------------------ */       
    /* check header             */
    /* ------------------------ */                
    if(AC_ANDRO_MAGIC != secroimg.m_andro.magic_number)
    {
        ret = ERR_SECROIMG_HACC_AP_DECRYPT_FAIL;
        goto _exit;
    }

    if(AC_MD_MAGIC != secroimg.m_md.magic_number)
    {
        ret = ERR_SECROIMG_HACC_MD_DECRYPT_FAIL;                    
        goto _exit;
    }
  
    if(AC_MD2_MAGIC != secroimg.m_md2.magic_number)
    {
        ret = ERR_SECROIMG_HACC_MD_DECRYPT_FAIL;                    
        goto _exit;
    }
    
    /* ------------------------ */       
    /* fill buffer              */
    /* ------------------------ */    
    /* only copy the data with user specified length */
        
        /* check if this image's information exist */
        if ('1' == md_info[0])
    {
            mcpy(buf,secroimg.m_md.reserve+offset,len);
        }
        else if ('2' == md_info[0])
        {
            mcpy(buf,secroimg.m_md2.reserve+offset,len);
        }
        else
        {
            SMSG(TRUE,"[%s] MD user not supported!\n",MOD);            
    }
    
    /* ------------------------ */       
    /* encrypt secro image      */
    /* ------------------------ */ 
    if(TRUE == sec_secro_ac())
    {    
        masp_hal_sp_hacc_enc((uchar*)&secroimg.m_andro, cipher_len, TRUE,HACC_USER1,TRUE);
    }
    }
    else 
    {

        SMSG(TRUE,"[%s]sro v5  \n",MOD);
        /* ----------------------------- */       
        /* if it supports v5 format      */
        /* ----------------------------- */

        /* check if this image's information exist */
        for(index=0; index<MAX_V5_SUPPORT_MD_NUM; index++)
        {   
            cur_md_info = &(secroimg.m_padding.md_v3a_info[index]);
            if(0 == strncmp(md_info,cur_md_info->md_name+strlen("SECURE_RO_"),md_info_len))
            {   
            break;
    }
        }

        /* md info dees not exist */
        if (MAX_V5_SUPPORT_MD_NUM == index)
        {
            ret = ERR_SECROIMG_MD_INFO_NOT_EXIST;
            goto _exit;
        }
    
    /* ------------------------ */       
        /* read secro v5 from flash */
        /* ------------------------ */       
        bSecroV5Exist = FALSE;
        bSecroV5Intergiy = FALSE;
        if(SEC_OK != (ret = sec_dev_read_secroimg_v5(index)))
        {
            goto _exit;
        }
        else
        {
            /* ------------------------ */       
            /* decrypt secroimg         */
    /* ------------------------ */ 
            cipher_len = sizeof(AND_AC_MD_INFO_V5a_T) + sizeof(AND_AC_MD_V5a_T);
    if(TRUE == sec_secro_ac())
    {    
        masp_hal_sp_hacc_dec((uchar*)&secroimg_v5.m_md_info_v5a, cipher_len, TRUE,HACC_USER1,TRUE);
    }

            /* ------------------------ */       
            /* check header             */
            /* ------------------------ */                
            if(AC_MD_INFO_MAGIC != secroimg_v5.m_md_info_v5a.magic_number)
            {
                ret = ERR_SECROIMG_HACC_MD_DECRYPT_FAIL;                    
                goto _exit;
            }

            if(AC_SV5_MAGIC_MD_V5a != secroimg_v5.m_md_sro_v5a.magic_number)
            {
                ret = ERR_SECROIMG_HACC_MD_DECRYPT_FAIL;                    
                goto _exit;
            }

            /* ------------------------ */       
            /* fill buffer              */
            /* ------------------------ */    
            /* only copy the data with user specified length */
            mcpy(buf,secroimg_v5.m_md_sro_v5a.reserve+offset,len);

            /* no need to encrypt since next time, we'll read it again from flash*/
        }
    }
    

_exit:

    osal_secro_unlock();

    return ret;
}