Mayank Gupta / Mbed OS pelion-example-frdm

Dependencies:   FXAS21002 FXOS8700Q

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers pal_plat_rot_insecure.c Source File

pal_plat_rot_insecure.c

00001 /*
00002  * Copyright (c) 2016-2018 ARM Limited. All rights reserved.
00003  * SPDX-License-Identifier: Apache-2.0
00004  * Licensed under the Apache License, Version 2.0 (the License); you may
00005  * 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, WITHOUT
00012  * 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 #include "mbed-trace/mbed_trace.h"
00019 
00020 #define TRACE_GROUP "ROT"
00021 
00022 #define PAL_DEVICE_KEY_SIZE_IN_BYTES 16
00023 
00024 //THIS CODE IS FOR TESTING PURPOSES ONLY. DO NOT USE IN PRODUCTION ENVIRONMENTS. REPLACE WITH A PROPER IMPLEMENTATION BEFORE USE
00025 palStatus_t pal_plat_osGetRoTFromHW(uint8_t *keyBuf, size_t keyLenBytes)
00026 {
00027 #if defined (__CC_ARM)          /* ARM compiler. */
00028     #warning("PAL_INSECURE- You are using insecure Root Of Trust implementation, DO NOT USE IN PRODUCTION ENVIRONMENTS. REPLACE WITH A PROPER IMPLEMENTATION BEFORE USE")
00029 #else
00030     #pragma message ("You are using insecure Root Of Trust implementation, DO NOT USE IN PRODUCTION ENVIRONMENTS. REPLACE WITH A PROPER IMPLEMENTATION BEFORE USE")
00031 #endif
00032     static bool runOnce = true;
00033     if (runOnce) {
00034 
00035         tr_warn("You are using insecure Root Of Trust implementation");
00036         runOnce = false;
00037     }
00038 
00039     if (keyLenBytes < PAL_DEVICE_KEY_SIZE_IN_BYTES) {
00040         return PAL_ERR_BUFFER_TOO_SMALL ;
00041     }
00042 
00043     if (NULL == keyBuf) {
00044         return PAL_ERR_NULL_POINTER ;
00045     }
00046 
00047     for (int i=0; i < PAL_DEVICE_KEY_SIZE_IN_BYTES; i++) {
00048         keyBuf[i] = i;
00049     }
00050 
00051     return PAL_SUCCESS;
00052 }
00053