/*! * TEE (Trusted Execution Environment) entry point. * Init CryptoCell for TEE. * * \return DX_CclibRetCode_t one of the error codes defined in dx_cclib.h */ DX_CclibRetCode_t DX_CclibInit(void) { int rc = DX_CCLIB_RET_OK; int virtMemBaseAddr = 0; PRINT_INFO("->now entrt into DX_CclibInit \n"); if(dx_cclib_init_state) { PRINT_INFO("->in DX_CclibInit :dx_cclib_init_state's value: 0x%x\n",dx_cclib_init_state); return DX_CCLIB_RET_OK; } PRINT_INFO("->in DX_CclibInit :before DX_PAL_Init \n"); virtMemBaseAddr = DX_PAL_Init(); PRINT_INFO("->in DX_CclibInit :DX_PAL_Init virtMemBaseAddr = %d\n",virtMemBaseAddr); if (NULL == (uint32_t *)virtMemBaseAddr) { PRINT_INFO("->in DX_CclibInit :DX_PAL_Init error,NULL == virtMemBaseAddr\n"); rc = DX_CCLIB_RET_EINVAL; goto InitErr; } rc = DX_HAL_Init(); PRINT_INFO("->in DX_CclibInit :DX_HAL_Init return:%d\n",rc); if (rc != DX_CCLIB_RET_OK) { PRINT_INFO("->in DX_CclibInit :DX_HAL_Init error,rc != DX_CCLIB_RET_OK\n"); rc = DX_CCLIB_RET_HAL; goto InitErr1; } /* Call sw reset to reset the CC before starting to work with it */ // DX_HAL_WriteCcRegister(DX_CC_REG_OFFSET(HOST_RGF, HOST_RGF_CC_SW_RST) , 0x1UL); /* wait for reset to be completed */ //for (i=0; i<20; i++); #ifdef BIG__ENDIAN /*initiate the Endian to BIG */ PRINT_INFO("->into BIG__ENDIAN\n"); DX_HAL_WriteCcRegister(DX_CC_REG_OFFSET(HOST_RGF, HOST_RGF_ENDIAN) , 0xCCUL); //DX_HAL_WriteCcRegister(DX_CC_REG_OFFSET(HOST_RGF, HOST_RGF_ENDIAN) , 0x00UL); #endif PRINT_INFO("->before InitHWQueue\n"); rc = InitHWQueue(NO_OS_QUEUE_ID); PRINT_INFO("->after InitHWQueue,InitHWQueue return value %d\n",rc); if (rc != DX_CCLIB_RET_OK) { PRINT_INFO("->n DX_CclibInit :InitHWQueue error,rc != DX_CCLIB_RET_OK\n"); rc = DX_CCLIB_RET_HW_Q_INIT; goto InitErr2; } PRINT_INFO("->before InitCompletion\n"); rc = InitCompletion(); PRINT_INFO("->after InitCompletion,InitCompletion return value %d\n",rc); if (rc != DX_CCLIB_RET_OK) { PRINT_INFO("->in DX_CclibInit :InitCompletion error,rc != DX_CCLIB_RET_OK\n"); rc = DX_CCLIB_RET_COMPLETION; goto InitErr2; } rc = SymDriverAdaptorModuleInit(); if (rc != DX_CCLIB_RET_OK) { rc = DX_CCLIB_RET_COMPLETION; // check goto InitErr; } #if ENABLE_RSA_DRIVER /* Initialize PKA's semaphore */ PRINT_INFO("->into ENABLE_RSA_DRIVER\n"); rc = DX_ASYM_Init(); #endif #ifndef CRYS_NO_RND_SUPPORT /* Initialize RND module */ rc = CRYS_RND_Instantiation(&workBuff_ptr); if (rc != CRYS_OK) { goto InitErr2; } #endif dx_cclib_init_state = DX_CCLIB_RET_OK; return 0; InitErr2: DX_HAL_Terminate(); InitErr1: DX_PAL_Terminate(); InitErr: PRINT_INFO("->in DX_CclibInit :at end,the rc value is:%d\n",rc); return rc; }
/*rnd_test - performs basic integration test for RND module*/ int rnd_tests(void) { uint32_t ret = 0/*,MaxVectorSize = 0*/; int test_index = 0; /*Set additional input for rng seed*/ ret = CRYS_RND_AddAdditionalInput(rndContext_ptr, rndVectors[test_index].rndTest_AddInputData, rndVectors[test_index].rndTest_AddInputSize); if (ret != SA_SILIB_RET_OK){ INTEG_TEST_PRINT("\n CRYS_RND_AddAdditionalInput failed with 0x%x \n",ret); return ret; } INTEG_TEST_PRINT("\n CRYS_RND_AddAdditionalInput passed\n"); /*Reseed rnd using added input (new seed will be generated using additional input)*/ ret = CRYS_RND_Reseeding (rndContext_ptr, rndWorkBuff_ptr); if (ret != SA_SILIB_RET_OK){ INTEG_TEST_PRINT("\n CRYS_RND_Reseeding failed with 0x%x \n",ret); return ret; } INTEG_TEST_PRINT("\n CRYS_RND_Reseeding passed\n"); /*Generate random vector 1*/ ret = CRYS_RND_GenerateVector(&rndContext_ptr->rndState, rndVectors[test_index].rndTest_RandomVectorSize, rndVectors[test_index].rndTest_RandomVectorData1); if (ret != SA_SILIB_RET_OK){ INTEG_TEST_PRINT("\n CRYS_RND_GenerateVector for vector 1 failed with 0x%x \n",ret); return ret; } INTEG_TEST_PRINT("\n CRYS_RND_GenerateVector for first vector passed\n"); /*Generate rnadom vector 2*/ ret = CRYS_RND_GenerateVector(&rndContext_ptr->rndState, rndVectors[test_index].rndTest_RandomVectorSize, rndVectors[test_index].rndTest_RandomVectorData2); if (ret != SA_SILIB_RET_OK){ INTEG_TEST_PRINT("\n CRYS_RND_GenerateVector for vector 2 failed with 0x%x \n",ret); return ret; } INTEG_TEST_PRINT("\n CRYS_RND_GenerateVector for second vector passed\n"); /*Compare two generated vectors - should not be the same value*/ ret = SaSi_PalMemCmp(rndVectors[test_index].rndTest_RandomVectorData1, rndVectors[test_index].rndTest_RandomVectorData2, rndVectors[test_index].rndTest_RandomVectorSize); if (ret == SA_SILIB_RET_OK){ INTEG_TEST_PRINT("\n Two random vectors should not are the same \n"); return ret; } INTEG_TEST_PRINT("\n Two generated vectors are different as expected\n"); /*Generate random vector in range when max value is NULL*/ ret = CRYS_RND_GenerateVectorInRange(rndContext_ptr, rndVectors[test_index].rndTest_RandomVectorInRangeSize1, NULL, rndVectors[test_index].rndTest_RandomVectorInRangeData); if (ret != SA_SILIB_RET_OK){ INTEG_TEST_PRINT("\n CRYS_RND_GenerateVectorInRange for vector with fixed size failed with 0x%x \n",ret); return ret; } INTEG_TEST_PRINT("\n CRYS_RND_GenerateVectorInRange 1 passed\n"); /*Generate random vector in range with max vector */ ret = CRYS_RND_GenerateVectorInRange(rndContext_ptr, rndVectors[test_index].rndTest_RandomVectorInRangeSize2, rndVectors[test_index].rndTest_MaxVectorInRange2, rndVectors[test_index].rndTest_RandomVectorInRangeData2); if (ret != SA_SILIB_RET_OK){ INTEG_TEST_PRINT("\n CRYS_RND_GenerateVectorInRange failed with 0x%x \n",ret); return ret; } INTEG_TEST_PRINT("\n CRYS_RND_GenerateVectorInRange 2 passed\n"); /*Perform UnInstantiation*/ ret = CRYS_RND_UnInstantiation(rndContext_ptr); if (ret != SA_SILIB_RET_OK){ INTEG_TEST_PRINT("\n CRYS_RND_UnInstantiation failed with 0x%x \n",ret); return ret; } INTEG_TEST_PRINT("\n CRYS_RND_UnInstantiation passed\n"); /*Try to create random vector without instantiation - should fail*/ ret = CRYS_RND_GenerateVector(&rndContext_ptr->rndState, rndVectors[test_index].rndTest_RandomVectorSize, rndVectors[test_index].rndTest_RandomVectorData2); if (ret != CRYS_RND_STATE_VALIDATION_TAG_ERROR){ INTEG_TEST_PRINT("\n CRYS_RND_GenerateVector returned wrong error 0x%x,\n CRYS_RND_STATE_VALIDATION_TAG_ERROR should be returned\n",ret); return ret; } INTEG_TEST_PRINT("\n CRYS_RND_GenerateVector failed as expected\n"); /*Set additional input for RND seed*/ ret = CRYS_RND_AddAdditionalInput(rndContext_ptr, rndVectors[test_index].rndTest_AddInputData, rndVectors[test_index].rndTest_AddInputSize); if (ret != SA_SILIB_RET_OK){ INTEG_TEST_PRINT("\n CRYS_RND_AddAdditionalInput failed with 0x%x \n",ret); return ret; } INTEG_TEST_PRINT("\n CRYS_RND_AddAdditionalInput passed\n"); /*Perform instantiation for new seed*/ ret = CRYS_RND_Instantiation(rndContext_ptr, rndWorkBuff_ptr); if (ret != SA_SILIB_RET_OK){ INTEG_TEST_PRINT("\n CRYS_RND_Instantiation failed with 0x%x \n",ret); return ret; } INTEG_TEST_PRINT("\n CRYS_RND_Instantiation passed\n"); /*Try to create two vectors and check that the vectors are different*/ ret = CRYS_RND_GenerateVector(&rndContext_ptr->rndState, rndVectors[test_index].rndTest_RandomVectorSize, rndVectors[test_index].rndTest_RandomVectorData1); if (ret != SA_SILIB_RET_OK){ INTEG_TEST_PRINT("\n CRYS_RND_GenerateVector for vector 1 failed with 0x%x \n",ret); return ret; } INTEG_TEST_PRINT("\n CRYS_RND_GenerateVector 1 passed\n"); ret = CRYS_RND_GenerateVector(&rndContext_ptr->rndState, rndVectors[test_index].rndTest_RandomVectorSize, rndVectors[test_index].rndTest_RandomVectorData2); if (ret != SA_SILIB_RET_OK){ INTEG_TEST_PRINT(" CRYS_RND_GenerateVector for vector 2 failed with 0x%x \n",ret); return ret; } INTEG_TEST_PRINT("\n CRYS_RND_GenerateVector 2 passed\n"); ret = SaSi_PalMemCmp(rndVectors[test_index].rndTest_RandomVectorData1, rndVectors[test_index].rndTest_RandomVectorData2, rndVectors[test_index].rndTest_RandomVectorSize); if (ret == SA_SILIB_RET_OK){ INTEG_TEST_PRINT(" Two random vectors should not are the same \n"); return ret; } INTEG_TEST_PRINT("\n Compare passed\n"); INTEG_TEST_PRINT("\n All RND tests passed\n"); INTEG_TEST_PRINT("\n==========================\n"); ret = SA_SILIB_RET_OK; return ret; }