Simulated product dispenser

Dependencies:   HTS221

Fork of mbed-cloud-workshop-connect-HTS221 by Jim Carver

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers arm_uc_test_rot.c Source File

arm_uc_test_rot.c

00001 // ----------------------------------------------------------------------------
00002 // Copyright 2018 ARM Ltd.
00003 //
00004 // SPDX-License-Identifier: Apache-2.0
00005 //
00006 // Licensed under the Apache License, Version 2.0 (the "License");
00007 // you may not use this file except in compliance with the License.
00008 // You may obtain a copy of the License at
00009 //
00010 //     http://www.apache.org/licenses/LICENSE-2.0
00011 //
00012 // Unless required by applicable law or agreed to in writing, software
00013 // distributed under the License is distributed on an "AS IS" BASIS,
00014 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015 // See the License for the specific language governing permissions and
00016 // limitations under the License.
00017 // ----------------------------------------------------------------------------
00018 
00019 #if defined(ARM_UC_TEST_DUMMY_ROT) && ARM_UC_TEST_DUMMY_ROT == 1
00020 
00021 #include <inttypes.h>
00022 #include <stddef.h>
00023 
00024 #define DEVICE_KEY_SIZE_IN_BYTES (128/8)
00025 
00026 /**
00027  * @brief Function to get the device root of trust
00028  * @details The device root of trust should be a 128 bit value. It should never leave the device.
00029  *          It should be unique to the device. It should have enough entropy to avoid contentional
00030  *          entropy attacks. The porter should implement the following device signature to provide
00031  *          device root of trust on different platforms.
00032  *
00033  * @param key_buf buffer to be filled with the device root of trust.
00034  * @param length  length of the buffer provided to make sure no overflow occurs.
00035  *
00036  * @return 0 on success, non-zero on failure.
00037  */
00038 
00039 // THIS CODE IS FOR TESTING PURPOSES ONLY. DO NOT USE IN PRODUCTION ENVIRONMENTS. REPLACE WITH A PROPER IMPLEMENTATION BEFORE USE
00040 int8_t mbed_cloud_client_get_rot_128bit(uint8_t *key_buf, uint32_t length)
00041 {
00042 #warning "You are using insecure Root Of Trust implementation, DO NOT USE IN PRODUCTION ENVIRONMENTS. REPLACE WITH A PROPER IMPLEMENTATION BEFORE USE"
00043 
00044     if (length < DEVICE_KEY_SIZE_IN_BYTES || key_buf == NULL)
00045     {
00046         return -1;
00047     }
00048 
00049     for (uint8_t i = 0; i < DEVICE_KEY_SIZE_IN_BYTES; i++)
00050     {
00051         key_buf[i] = i;
00052     }
00053 
00054     return 0;
00055 }
00056 
00057 #endif // #if !defined(ARM_UC_TEST_DUMMY_ROT) || ARM_UC_TEST_DUMMY_ROT == 0