Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FXAS21002 FXOS8700Q
pal_SOTP_test.c
00001 /******************************************************************************* 00002 * Copyright 2016, 2017 ARM Ltd. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 *******************************************************************************/ 00016 00017 #include "pal.h" 00018 00019 #include "unity.h" 00020 #include "unity_fixture.h" 00021 #include "test_runners.h" 00022 00023 #ifndef MBED_CONF_MBED_CLOUD_CLIENT_EXTERNAL_SST_SUPPORT 00024 00025 #include "sotp.h" 00026 00027 00028 #define SOTP_DIR "/sotp" 00029 #define ROT_KEY_SIZE 16 00030 00031 //add 5 years to minimum time 00032 #define PAL_TEST_START_TIME (PAL_MIN_SEC_FROM_EPOCH + ((PAL_SECONDS_PER_DAY * PAL_DAYS_IN_A_YEAR) * 5)) 00033 #define ACCEPTABLE_DELAY_IN_SEC (10) 00034 #define PAL_SOTP_TEST_DELAY_IN_SEC (5 * 1000) 00035 00036 #define TRACE_GROUP "PAL" 00037 00038 extern palTestsStatusData_t palTestStatus; 00039 00040 #endif //MBED_CONF_MBED_CLOUD_CLIENT_EXTERNAL_SST_SUPPORT 00041 00042 00043 TEST_GROUP(pal_SOTP); 00044 00045 00046 #ifndef MBED_CONF_MBED_CLOUD_CLIENT_EXTERNAL_SST_SUPPORT 00047 00048 #if (PAL_USE_HW_RTC) 00049 static uint64_t systemRealRTC = 0; 00050 static uint64_t systemStartTickCount = 0; 00051 #endif 00052 00053 PAL_PRIVATE palCtrDrbgCtxHandle_t g_drbgCtx = NULLPTR; 00054 00055 #endif //MBED_CONF_MBED_CLOUD_CLIENT_EXTERNAL_SST_SUPPORT 00056 00057 TEST_SETUP(pal_SOTP) 00058 { 00059 00060 #ifndef MBED_CONF_MBED_CLOUD_CLIENT_EXTERNAL_SST_SUPPORT 00061 00062 palStatus_t status = PAL_SUCCESS; 00063 status = pal_init(); 00064 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status); 00065 00066 status = pal_initTime(); 00067 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status); 00068 00069 #if (PAL_USE_HW_RTC == 1) 00070 uint64_t sysTicks = 0; 00071 status = pal_plat_osGetRtcTime(&systemRealRTC); 00072 if (systemRealRTC < (uint64_t)PAL_MIN_RTC_SET_TIME) 00073 { 00074 systemRealRTC = PAL_MIN_RTC_SET_TIME; 00075 } 00076 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status); 00077 systemStartTickCount = pal_osKernelSysTick(); 00078 #endif 00079 00080 #endif //MBED_CONF_MBED_CLOUD_CLIENT_EXTERNAL_SST_SUPPORT 00081 00082 } 00083 00084 00085 00086 TEST_TEAR_DOWN(pal_SOTP) 00087 { 00088 00089 #ifndef MBED_CONF_MBED_CLOUD_CLIENT_EXTERNAL_SST_SUPPORT 00090 00091 palStatus_t status = PAL_SUCCESS; 00092 #if (PAL_USE_HW_RTC == 1) 00093 uint64_t sysTicks = 0; 00094 uint64_t endTickCount = 0; 00095 uint64_t timeToAddInSec = 0; 00096 uint64_t timeToAddInMiliSec = 0; 00097 endTickCount = pal_osKernelSysTick(); 00098 timeToAddInMiliSec = pal_osKernelSysMilliSecTick(endTickCount - systemStartTickCount); //switch from mili to seconds 00099 timeToAddInSec = PAL_MILISEC_TO_SEC(timeToAddInMiliSec); 00100 00101 // XXX: This code expected the pal_init() having been called, even though it is not on all branches! 00102 status = pal_plat_rtcInit(); 00103 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status); 00104 00105 status = pal_plat_osSetRtcTime(systemRealRTC + timeToAddInSec); 00106 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status); 00107 #endif 00108 if (g_drbgCtx) 00109 { 00110 pal_CtrDRBGFree(&g_drbgCtx); 00111 } 00112 status = pal_destroy(); 00113 00114 #if (PAL_INITIALIZED_BEFORE_TESTS == 0) 00115 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status); 00116 #endif 00117 00118 #endif //MBED_CONF_MBED_CLOUD_CLIENT_EXTERNAL_SST_SUPPORT 00119 00120 } 00121 00122 00123 #ifndef MBED_CONF_MBED_CLOUD_CLIENT_EXTERNAL_SST_SUPPORT 00124 00125 static palStatus_t writeDataInFS(uint8_t* data, size_t dataSize, char* dataName) 00126 { 00127 palStatus_t status = PAL_SUCCESS, status2 = PAL_SUCCESS; 00128 char filePath[PAL_MAX_FILE_AND_FOLDER_LENGTH] = {0}; 00129 palFileDescriptor_t fd = 0; 00130 size_t dataSizeWritten = 0; 00131 00132 status = pal_fsGetMountPoint(PAL_FS_PARTITION_PRIMARY, PAL_MAX_FILE_AND_FOLDER_LENGTH, filePath); 00133 strncat(filePath,SOTP_DIR,PAL_MAX_FILE_AND_FOLDER_LENGTH - strlen(filePath)); 00134 if (PAL_SUCCESS == status) 00135 { 00136 status = pal_fsMkDir(filePath); 00137 if ((PAL_SUCCESS == status) || (PAL_ERR_FS_NAME_ALREADY_EXIST == status)) 00138 { 00139 strncat(filePath,"/",PAL_MAX_FILE_AND_FOLDER_LENGTH - strlen(filePath)); 00140 strncat(filePath,dataName,PAL_MAX_FILE_AND_FOLDER_LENGTH - strlen(filePath)); 00141 status = pal_fsFopen(filePath,PAL_FS_FLAG_READWRITETRUNC,&fd); 00142 if (PAL_SUCCESS == status) 00143 { 00144 status = pal_fsFwrite(&fd, (void *)data, dataSize, &dataSizeWritten); 00145 status2 = pal_fsFclose(&fd); 00146 if (PAL_SUCCESS != status2) 00147 { 00148 PAL_LOG_ERR("Failed to close data file of sotp pal testing after write"); 00149 } 00150 } 00151 } 00152 00153 } 00154 return status; 00155 } 00156 00157 static palStatus_t readDataFromFS(uint8_t* data, size_t dataSize, char* dataName) 00158 { 00159 palStatus_t status= PAL_SUCCESS, status2 = PAL_SUCCESS; 00160 char filePath[PAL_MAX_FILE_AND_FOLDER_LENGTH] = {0}; 00161 palFileDescriptor_t fd = 0; 00162 size_t dataSizeWritten = 0; 00163 00164 status = pal_fsGetMountPoint(PAL_FS_PARTITION_PRIMARY, PAL_MAX_FILE_AND_FOLDER_LENGTH, filePath); 00165 strncat(filePath,SOTP_DIR,PAL_MAX_FILE_AND_FOLDER_LENGTH - strlen(filePath)); 00166 if (PAL_SUCCESS == status) 00167 { 00168 strncat(filePath,"/",PAL_MAX_FILE_AND_FOLDER_LENGTH - strlen(filePath)); 00169 strncat(filePath,dataName,PAL_MAX_FILE_AND_FOLDER_LENGTH - strlen(filePath)); 00170 status = pal_fsFopen(filePath, PAL_FS_FLAG_READONLY, &fd); 00171 if (PAL_SUCCESS == status) 00172 { 00173 status = pal_fsFread(&fd, (void *)data, dataSize, &dataSizeWritten); 00174 status2 = pal_fsFclose(&fd); 00175 if (PAL_SUCCESS != status2) 00176 { 00177 PAL_LOG_ERR("Failed to close data file of sotp pal testing after read"); 00178 } 00179 status2 = pal_fsUnlink(filePath); 00180 if (PAL_SUCCESS != status2) 00181 { 00182 PAL_LOG_ERR("Failed to delete data file of sotp pal testing after read"); 00183 } 00184 } 00185 00186 } 00187 return status; 00188 } 00189 00190 #endif //MBED_CONF_MBED_CLOUD_CLIENT_EXTERNAL_SST_SUPPORT 00191 00192 00193 TEST(pal_SOTP, SW_HW_RoT) 00194 { 00195 00196 #ifndef MBED_CONF_MBED_CLOUD_CLIENT_EXTERNAL_SST_SUPPORT 00197 00198 uint32_t rotLength = ROT_KEY_SIZE; 00199 palDevKeyType_t ketType = palOsStorageEncryptionKey128Bit; 00200 uint8_t rotA[ROT_KEY_SIZE] = {0}; 00201 uint8_t rotB[ROT_KEY_SIZE] = {0}; 00202 sotp_result_e sotpStatus = SOTP_SUCCESS; 00203 palStatus_t status = PAL_SUCCESS; 00204 (void)sotpStatus; 00205 if (palTestStatus.inner == -1) { 00206 status = pal_osGetDeviceKey(ketType, rotA, rotLength); 00207 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status); 00208 #if(PAL_USE_HW_ROT == 0) // test SW RoT 00209 status = pal_osGetDeviceKey(ketType, rotB, rotLength); 00210 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status); 00211 00212 TEST_ASSERT_TRUE(0 == memcmp(rotA,rotB,rotLength)) 00213 00214 sotpStatus = sotp_delete(SOTP_TYPE_ROT); 00215 TEST_ASSERT_EQUAL_HEX(SOTP_SUCCESS, sotpStatus); 00216 00217 memset(rotA,0,sizeof(rotA)); 00218 00219 status = pal_osGetDeviceKey(ketType, rotA, rotLength); 00220 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status); 00221 00222 /** 00223 * if there is no HW RoT, The Rot is generated from random. 00224 * So, if deleted and re generated there is no chance that the 00225 * ols RoT and the New will bw the same 00226 **/ 00227 TEST_ASSERT_TRUE(0 != memcmp(rotA,rotB,rotLength)) 00228 #endif 00229 status = writeDataInFS(rotA, rotLength,"RoT"); 00230 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status); 00231 status = palTestReboot(PAL_TEST_MODULE_SOTP, PAL_TEST_SOTP_TEST_SW_HW_ROT); 00232 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status); 00233 }//start here after the reboot 00234 else 00235 { 00236 updatePalTestStatusAfterReboot(); 00237 00238 memset(rotA,0,sizeof(rotA)); 00239 memset(rotB,0,sizeof(rotB)); 00240 00241 status = pal_osGetDeviceKey(ketType, rotA, rotLength); 00242 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status); 00243 00244 status = readDataFromFS(rotB, rotLength, "RoT"); 00245 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status); 00246 00247 TEST_ASSERT_TRUE(0 == memcmp(rotA,rotB,rotLength)) 00248 } 00249 00250 #else 00251 TEST_IGNORE_MESSAGE("Ignored, MBED_CONF_MBED_CLOUD_CLIENT_EXTERNAL_SST_SUPPORT is defined"); 00252 #endif //MBED_CONF_MBED_CLOUD_CLIENT_EXTERNAL_SST_SUPPORT 00253 00254 } 00255 00256 TEST(pal_SOTP, timeInit) 00257 { 00258 00259 #ifndef MBED_CONF_MBED_CLOUD_CLIENT_EXTERNAL_SST_SUPPORT 00260 00261 // call pal destroy as this test need to start before pal_init() 00262 00263 palStatus_t status = PAL_SUCCESS; 00264 00265 status = pal_destroy(); 00266 #if (PAL_INITIALIZED_BEFORE_TESTS == 0) 00267 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status); 00268 #endif 00269 00270 /** 00271 this is is splited to 2 different parts because of the ifdefs 00272 if the end of this if is inside the #if (PAL_USE_HW_RTC == 1) 00273 in any other case, if this was a single if this had casue 00274 compilation error 00275 **/ 00276 00277 00278 if (palTestStatus.inner == -1) 00279 { 00280 #if ((PAL_USE_HW_RTC == 1) && (PAL_USE_INTERNAL_FLASH == 1) && (PAL_INT_FLASH_NUM_SECTION ==2)) 00281 { 00282 uint64_t currentTime = 0; 00283 sotpStatus = sotp_delete(SOTP_TYPE_SAVED_TIME); 00284 TEST_ASSERT_TRUE((SOTP_SUCCESS == sotpStatus) || (SOTP_NOT_FOUND == sotpStatus)) 00285 status = pal_plat_osSetRtcTime((uint64_t)PAL_TEST_START_TIME); 00286 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status); 00287 status = pal_init(); 00288 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status); 00289 currentTime = pal_osGetTime(); 00290 TEST_ASSERT_TRUE((currentTime - ACCEPTABLE_DELAY_IN_SEC) <= PAL_TEST_START_TIME); 00291 status = pal_destroy(); 00292 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status); 00293 status = pal_plat_osSetRtcTime((uint64_t)0); 00294 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status); 00295 status = pal_init(); 00296 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status); 00297 status = pal_osDelay(PAL_SOTP_TEST_DELAY_IN_SEC); 00298 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status); 00299 currentTime = pal_osGetTime(); 00300 TEST_ASSERT_EQUAL_HEX(0, currentTime); 00301 status = pal_destroy(); 00302 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status); 00303 currentTime = PAL_TEST_START_TIME; 00304 sotpStatus = sotp_set(SOTP_TYPE_SAVED_TIME, sizeof(uint64_t), (uint32_t *)¤tTime); 00305 TEST_ASSERT_EQUAL_HEX(SOTP_SUCCESS, status); 00306 currentTime -= (PAL_SECONDS_PER_DAY * PAL_DAYS_IN_A_YEAR); // remove an year 00307 status = pal_plat_osSetRtcTime(currentTime); 00308 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status); 00309 status = pal_init(); 00310 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status); 00311 currentTime = pal_osGetTime(); 00312 TEST_ASSERT_TRUE((PAL_TEST_START_TIME - ACCEPTABLE_DELAY_IN_SEC) <= currentTime); 00313 status = pal_destroy(); 00314 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status); 00315 currentTime = PAL_TEST_START_TIME; 00316 status = pal_plat_osSetRtcTime(currentTime); 00317 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status); 00318 currentTime -= (PAL_SECONDS_PER_DAY * PAL_DAYS_IN_A_YEAR); // remove an year 00319 sotpStatus = sotp_set(SOTP_TYPE_SAVED_TIME, sizeof(uint64_t), (uint32_t *)¤tTime); 00320 TEST_ASSERT_EQUAL_HEX(SOTP_SUCCESS, status); 00321 status = pal_init(); 00322 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status); 00323 currentTime = pal_osGetTime(); 00324 TEST_ASSERT_TRUE((currentTime - ACCEPTABLE_DELAY_IN_SEC) <= PAL_TEST_START_TIME); 00325 #endif 00326 00327 00328 #if ((PAL_USE_HW_RTC == 0) && (PAL_USE_INTERNAL_FLASH == 1) && (PAL_INT_FLASH_NUM_SECTION ==2)) 00329 { 00330 uint64_t currentTime = 0; 00331 currentTime = PAL_TEST_START_TIME; // remove an year 00332 sotpStatus = sotp_set(SOTP_TYPE_SAVED_TIME, sizeof(uint64_t), (uint32_t *)¤tTime); 00333 TEST_ASSERT_EQUAL_HEX(SOTP_SUCCESS, status); 00334 status = pal_init(); 00335 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status); 00336 currentTime = pal_osGetTime(); 00337 TEST_ASSERT_TRUE((PAL_TEST_START_TIME - ACCEPTABLE_DELAY_IN_SEC) <= currentTime); 00338 status = pal_destroy(); 00339 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status); 00340 } 00341 #endif 00342 } 00343 #if (PAL_USE_HW_RTC == 1) 00344 { 00345 uint64_t currentTime = 0; 00346 if (palTestStatus.inner == -1) 00347 { 00348 00349 // XXX: This code expected the pal_init() having been called, even though it is not on all branches! 00350 status = pal_plat_rtcInit(); 00351 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status); 00352 00353 currentTime = PAL_TEST_START_TIME; // remove an year 00354 status = pal_plat_osSetRtcTime(currentTime); 00355 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status); 00356 00357 status = palTestReboot(PAL_TEST_MODULE_SOTP, PAL_TEST_SOTP_TEST_TIME_INIT); 00358 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status); 00359 }//start here after reboot 00360 else 00361 { 00362 updatePalTestStatusAfterReboot(); 00363 status = pal_plat_osGetRtcTime(¤tTime); 00364 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status); 00365 00366 TEST_ASSERT_TRUE((currentTime - ACCEPTABLE_DELAY_IN_SEC) <= PAL_TEST_START_TIME); 00367 } 00368 } 00369 #endif 00370 00371 #else 00372 TEST_IGNORE_MESSAGE("Ignored, MBED_CONF_MBED_CLOUD_CLIENT_EXTERNAL_SST_SUPPORT is defined"); 00373 #endif //MBED_CONF_MBED_CLOUD_CLIENT_EXTERNAL_SST_SUPPORT 00374 00375 } 00376 00377 // the following function is not part of PAL's external API hence extern 00378 extern palStatus_t pal_plat_noiseRead(int32_t buffer[PAL_NOISE_BUFFER_LEN], bool partial, uint16_t* bitsRead); 00379 00380 /*! \brief Test random buffer generation with sotp 00381 * 00382 * | # | Step | Expected | 00383 * |---|----------------------------------------------------------------|-------------| 00384 * | 1 | Save a fixed seed to sotp or read current value is exists. | PAL_SUCCESS | 00385 * | 2 | Generate short & long term seed. | PAL_SUCCESS | 00386 * | 3 | Generate expected random. | PAL_SUCCESS | 00387 * | 4 | Call pal_osRandomBuffer and compare expected to actual random. | PAL_SUCCESS | 00388 * | 5 | Validate counter and next (boot) long term seed. | PAL_SUCCESS | 00389 */ 00390 TEST(pal_SOTP, random) 00391 { 00392 00393 #ifndef MBED_CONF_MBED_CLOUD_CLIENT_EXTERNAL_SST_SUPPORT 00394 00395 palStatus_t status; 00396 sotp_result_e res; 00397 uint16_t bytesRead = 0; 00398 uint32_t counter = 0; 00399 uint32_t counterCopy = 0; 00400 uint8_t buf[(PAL_INITIAL_RANDOM_SIZE * 2 + sizeof(counter))] PAL_PTR_ADDR_ALIGN_UINT8_TO_UINT32 = { 0 }; 00401 bool sotpRandomExists = false; 00402 00403 #if !PAL_USE_HW_TRNG 00404 uint16_t bitsRead = 0; 00405 int32_t noiseBuffer[PAL_NOISE_BUFFER_LEN] = { 0 }; 00406 pal_plat_noiseRead(noiseBuffer, true, &bitsRead); 00407 #endif // !PAL_USE_HW_TRNG 00408 00409 /*#1*/ 00410 res = sotp_get(SOTP_TYPE_RANDOM_SEED, (PAL_INITIAL_RANDOM_SIZE + sizeof(counter)), (uint32_t*)buf, &bytesRead); // read 48 drbg bytes + 4 counter bytes 00411 TEST_ASSERT_TRUE(SOTP_SUCCESS == res || SOTP_NOT_FOUND == res); 00412 if (SOTP_SUCCESS == res) 00413 { 00414 memcpy((void*)&counter, (void*)&buf[PAL_INITIAL_RANDOM_SIZE], sizeof(counter)); 00415 sotpRandomExists = true; 00416 } 00417 else if (SOTP_NOT_FOUND == res) 00418 { 00419 memset((void*)buf, 7, PAL_INITIAL_RANDOM_SIZE); // fixed dummy seed 00420 res = sotp_set(SOTP_TYPE_RANDOM_SEED, PAL_INITIAL_RANDOM_SIZE, (uint32_t*)buf); 00421 TEST_ASSERT_EQUAL_HEX(SOTP_SUCCESS, res); 00422 } 00423 00424 /*#2*/ 00425 status = pal_CtrDRBGInit(&g_drbgCtx, (void*)buf, PAL_INITIAL_RANDOM_SIZE); 00426 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status); 00427 memset((void*)buf, 0, sizeof(buf)); 00428 status = pal_CtrDRBGGenerate(g_drbgCtx, (unsigned char*)buf, PAL_INITIAL_RANDOM_SIZE * 2); // generate 48 bytes long term & 48 bytes short term seed 00429 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status); 00430 status = pal_CtrDRBGFree(&g_drbgCtx); 00431 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status); 00432 g_drbgCtx = NULLPTR; 00433 00434 /*#3*/ 00435 status = pal_CtrDRBGInit(&g_drbgCtx, (void*)buf, PAL_INITIAL_RANDOM_SIZE); 00436 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status); 00437 memset((void*)buf, 0, PAL_INITIAL_RANDOM_SIZE); 00438 status = pal_CtrDRBGGenerate(g_drbgCtx, (unsigned char*)buf, PAL_INITIAL_RANDOM_SIZE); // generate expected random buffer 00439 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status); 00440 status = pal_CtrDRBGFree(&g_drbgCtx); 00441 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status); 00442 g_drbgCtx = NULLPTR; 00443 00444 /*#4*/ 00445 uint8_t random[PAL_INITIAL_RANDOM_SIZE] = { 0 }; 00446 status = pal_osRandomBuffer(random, PAL_INITIAL_RANDOM_SIZE); // get the actual random buffer 00447 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status); 00448 #if !PAL_USE_HW_TRNG 00449 TEST_ASSERT_EQUAL_MEMORY(buf, random, PAL_INITIAL_RANDOM_SIZE); 00450 #endif // !PAL_USE_HW_TRNG 00451 00452 /*#5*/ 00453 memmove(&buf[(PAL_INITIAL_RANDOM_SIZE + sizeof(counter))], &buf[PAL_INITIAL_RANDOM_SIZE], PAL_INITIAL_RANDOM_SIZE); // make space for the counter while preserving next seed bytes 00454 memset((void*)buf, 0, (PAL_INITIAL_RANDOM_SIZE + sizeof(counter))); 00455 counterCopy = counter; 00456 res = sotp_get(SOTP_TYPE_RANDOM_SEED, (PAL_INITIAL_RANDOM_SIZE + sizeof(counter)), (uint32_t*)buf, &bytesRead); 00457 TEST_ASSERT_EQUAL_HEX(SOTP_SUCCESS, res); 00458 TEST_ASSERT_EQUAL((PAL_INITIAL_RANDOM_SIZE + sizeof(counter)), bytesRead); 00459 memcpy((void*)&counter, (void*)&buf[PAL_INITIAL_RANDOM_SIZE], sizeof(counter)); // read the counter from sotp data 00460 TEST_ASSERT_EQUAL(counterCopy + 1, counter); 00461 #if !PAL_USE_HW_TRNG 00462 TEST_ASSERT_EQUAL_MEMORY(&buf[(PAL_INITIAL_RANDOM_SIZE + sizeof(counter))], buf, PAL_INITIAL_RANDOM_SIZE); 00463 #endif // !PAL_USE_HW_TRNG 00464 00465 if (false == sotpRandomExists) 00466 { 00467 res = sotp_delete(SOTP_TYPE_RANDOM_SEED); 00468 TEST_ASSERT_EQUAL_HEX(SOTP_SUCCESS, res); 00469 } 00470 00471 #else 00472 TEST_IGNORE_MESSAGE("Ignored, MBED_CONF_MBED_CLOUD_CLIENT_EXTERNAL_SST_SUPPORT is defined"); 00473 #endif //MBED_CONF_MBED_CLOUD_CLIENT_EXTERNAL_SST_SUPPORT 00474 00475 } 00476
Generated on Tue Jul 12 2022 20:21:02 by
