int get_2RSA(int index,aml_intx *n,aml_intx *e, unsigned char *key,int keylen) { int ret=-1; unsigned char szRSAPUK1[256]; int nOutLen=256; unsigned char szRSAPUK1Hash[32]; unsigned char efuseHash[32]; t_func_v3 fp_00 = (t_func_v3)m6_g_action[index][0]; t_func_r3 fp_01 = (t_func_r3)m6_g_action[index][1]; t_func_v3 fp_02 = (t_func_v3)m6_g_action[index][2]; t_func_v3 fp_05 = (t_func_v3)m6_g_action[index][5]; fp_00((int)&szRSAPUK1Hash[0],0,sizeof(szRSAPUK1Hash)); fp_00((int)&efuseHash[0],0,sizeof(efuseHash)); fp_00((int)&szRSAPUK1[0],0,sizeof(szRSAPUK1)); keylen = 256; m6_rsa_dec_pub(index,n,e,key,keylen,szRSAPUK1,&nOutLen); //fp_00((int)n,0,sizeof(*n)); //fp_00((int)e,0,sizeof(*e)); fp_05((int)&efuseHash[0],136,sizeof(efuseHash)); ret = -1; sha2_sum( szRSAPUK1Hash,szRSAPUK1,128+4); if(!fp_01((int)&szRSAPUK1Hash[0],(int)&efuseHash[0],32)){ fp_02((int)(&n->dp[0]),(int)&szRSAPUK1[0],128); n->used = 32; fp_02((int)(&e->dp[0]),(int)(&szRSAPUK1[0]+128),4); e->used = 1; ret = 0; fp_02((int)key,(int)&szRSAPUK1[0],keylen); //int i; } return ret; }
static int aml_m8_sec_boot_check(unsigned char *pSRC,unsigned char *pkey1,int nkey1Len, unsigned char *pkey2,int nkey2Len,unsigned int *pState) { #if defined(AML_SECURE_PROCESS_MSG_SHOW) char * pInfo1[2][2]={ {"Aml log : G9B-R1024 ", "Aml log : G9B-R2048 "}, {"Aml log : G9B-R1024-2X ","Aml log : G9B-R2048-2X "}, }; #if defined(CONFIG_AMLROM_SPL) #define AML_MSG_FAIL ("TPL fail!\n") #define AML_MSG_PASS ("TPL pass!\n") #define MSG_SHOW serial_puts #else #define AML_MSG_FAIL ("IMG fail!\n") #define AML_MSG_PASS ("IMG pass!\n") extern int printf(const char *fmt, ...); #define MSG_SHOW printf #endif #endif //#if defined(AML_SECURE_PROCESS_MSG_SHOW) #define AMLOGIC_CHKBLK_ID (0x434C4D41) //414D4C43 AMLC #define AMLOGIC_CHKBLK_VER (1) typedef struct { unsigned int nSizeH; ////4@0 unsigned int nLength1; ////4@4 unsigned int nLength2; ////4@8 unsigned int nLength3; ////4@12 unsigned int nLength4; ////4@16 unsigned char szkey1[116]; ////116@20 unsigned char szkey2[108]; ////108@136 unsigned int nSizeT; ////4@244 unsigned int nVer; ////4@248 unsigned int unAMLID; ////4@252 }st_aml_chk_blk; //256 typedef struct{ int ver; int len; unsigned char szBuf1[12]; unsigned char szBuf2[188]; } st_crypto_blk1; typedef struct{ int nr; unsigned int buff[80]; } st_crypto_blk2; int i; int nRet = -1; st_crypto_blk1 cb1_ctx; st_crypto_blk2 cb2_ctx; st_aml_chk_blk chk_blk; unsigned char szkey[32+16]; unsigned int *ct32 = (unsigned int *)(pSRC); unsigned char *pBuf = (unsigned char *)&chk_blk; g_nStep = 0; /* switch(* (unsigned int *)0xd9040004) { case 0x25e2: break; case 0x27ed: g_nStep = 1 ; break; case 0x74E : g_nStep = 2 ; break; case 0xb72: g_nStep = 3 ; break; default: goto exit;break; } */ for(g_nStep = 0;g_nStep<sizeof(g_action)/sizeof(g_action[0]);++g_nStep) { if(!g_action[g_nStep][0]) goto exit; if((*(unsigned int *)0xd9040004) == g_action[g_nStep][0]) break; } t_func_v3 fp_01 = (t_func_v3)g_action[g_nStep][1]; //void rsa_init(1,2,3) t_func_r3 fp_02 = (t_func_r3)g_action[g_nStep][2]; //int mpi_read_string(1,2,3) t_func_v3 fp_03 = (t_func_v3)g_action[g_nStep][3]; //void efuse_read(1,2,3) t_func_r2 fp_04 = (t_func_r2)g_action[g_nStep][4]; //int boot_rsa_read_puk(a,b) t_func_r3 fp_05 = (t_func_r3)g_action[g_nStep][5]; //int rsa_public(1,2,3) t_func_v2 fp_06 = (t_func_v2)g_action[g_nStep][6]; //void boot_aes_setkey_dec(1,2) t_func_v1 fp_07 = (t_func_v1)g_action[g_nStep][7]; //void boot_aes_setiv_init(1) t_func_v4 fp_08 = (t_func_v4)g_action[g_nStep][8]; //void boot_aes_crypt_cbc(1,2,3,4) t_func_v4 fp_09 = (t_func_v4)g_action[g_nStep][9]; //void sha2(1,2,3,4) t_func_r3 fp_10 = (t_func_r3)g_action[g_nStep][10]; //int memcpy(1,2,3) t_func_r3 fp_11 = (t_func_r3)g_action[g_nStep][11];//int memcmp(1,2,3) t_func_r1 fp_12 = (t_func_r1)g_action[g_nStep][12];//int mpi_msb(1) t_func_v3 fp_13 = (t_func_v3)g_action[g_nStep][13];//void memset(1,2,3) fp_13(g_action[g_nStep][14],0,4); fp_01((int)&cb1_ctx,0,0); if(pkey1 && pkey2) { if(fp_02((int)cb1_ctx.szBuf1,(int)pkey1,nkey1Len) || fp_02((int)cb1_ctx.szBuf2,(int)pkey2,nkey2Len)) goto exit; cb1_ctx.len = ( fp_12((int)cb1_ctx.szBuf1 ) + 7 ) >> 3; } else {
static int aml_m6tvd_sec_boot_check(unsigned char *pSRC,unsigned char *pkey1,int nkey1Len,unsigned char *pkey2,int nkey2Len) { #if defined(AML_SECURE_PROCESS_MSG_SHOW) #if defined(CONFIG_AMLROM_SPL) #define AML_MSG_FAIL ("Aml log : ERROR! TPL secure check fail!\n") #define AML_MSG_PASS ("Aml log : TPL secure check pass!\n") #define MSG_SHOW serial_puts #else #define AML_MSG_FAIL ("Aml log : ERROR! Image secure check fail!\n") #define AML_MSG_PASS ("Aml log : Image secure check pass!\n") #define MSG_SHOW printf #endif #endif //#if defined(AML_SECURE_PROCESS_MSG_SHOW) #define AMLOGIC_CHKBLK_ID (0x434C4D41) //414D4C43 AMLC #define AMLOGIC_CHKBLK_VER (1) typedef struct { unsigned int nSizeH; ////4@0 unsigned int nLength1; ////4@4 unsigned int nLength2; ////4@8 unsigned int nLength3; ////4@12 unsigned int nLength4; ////4@16 unsigned char szkey1[116]; ////116@20 unsigned char szkey2[108]; ////108@136 unsigned int nSizeT; ////4@244 unsigned int nVer; ////4@248 unsigned int unAMLID; ////4@252 }st_aml_chk_blk; //256 typedef struct{ int ver; int len; unsigned char szBuf1[12]; unsigned char szBuf2[188]; } st_crypto_blk1; typedef struct{ int nr; unsigned int buff[80]; } st_crypto_blk2; int i; int nRet = -1; st_crypto_blk1 cb1_ctx; st_crypto_blk2 cb2_ctx; st_aml_chk_blk chk_blk; unsigned char szkey[32+16]; unsigned int *ct32 = (unsigned int *)(pSRC); unsigned char *pBuf = (unsigned char *)&chk_blk; int nStep = 0; switch(* (unsigned int *)0xd9040004) { case 0x7ac: break; default: goto exit;break; } t_func_v3 fp_00 = (t_func_v3)g_action[nStep][0]; //void rsa_init(1,2,3) t_func_r3 fp_01 = (t_func_r3)g_action[nStep][1]; //int mpi_read_string(1,2,3) t_func_v3 fp_02 = (t_func_v3)g_action[nStep][2]; //void efuse_read(1,2,3) t_func_r2 fp_03 = (t_func_r2)g_action[nStep][3]; //int boot_rsa_read_puk(a,b) t_func_r3 fp_04 = (t_func_r3)g_action[nStep][4]; //int rsa_public(1,2,3) t_func_v2 fp_05 = (t_func_v2)g_action[nStep][5]; //void boot_aes_setkey_dec(1,2) t_func_v1 fp_06 = (t_func_v1)g_action[nStep][6]; //void boot_aes_setiv_init(1) t_func_v4 fp_07 = (t_func_v4)g_action[nStep][7]; //void boot_aes_crypt_cbc(1,2,3,4) t_func_v4 fp_08 = (t_func_v4)g_action[nStep][8]; //void sha2(1,2,3,4) t_func_r3 fp_09 = (t_func_r3)g_action[nStep][9]; //int memcpy(1,2,3) t_func_r3 fp_10 = (t_func_r3)g_action[nStep][10];//int memcmp(1,2,3) t_func_r1 fp_11 = (t_func_r1)g_action[nStep][11];//int mpi_msb(1) fp_00(&cb1_ctx,0,0); if(pkey1 && pkey2) { if(fp_01(cb1_ctx.szBuf1,pkey1,nkey1Len) || fp_01(cb1_ctx.szBuf2,pkey2,nkey2Len)) goto exit; cb1_ctx.len = ( fp_11( cb1_ctx.szBuf1 ) + 7 ) >> 3; } else {