Simulated product dispenser
Fork of mbed-cloud-workshop-connect-HTS221 by
cs_hash.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 "pv_error_handling.h" 00018 #include "cs_hash.h" 00019 #include "pal_Crypto.h" 00020 #include "cs_utils.h" 00021 00022 kcm_status_e cs_hash(cs_hash_mode_e mode, const uint8_t *data, size_t data_size, uint8_t *digest, size_t digest_size) 00023 { 00024 palStatus_t pal_status = PAL_SUCCESS; 00025 00026 SA_PV_ERR_RECOVERABLE_RETURN_IF((data == NULL), KCM_STATUS_INVALID_PARAMETER, "Invalid data pointer"); 00027 SA_PV_ERR_RECOVERABLE_RETURN_IF((digest == NULL), KCM_STATUS_INVALID_PARAMETER, "Invalid digest pointer"); 00028 00029 switch (mode) { 00030 case CS_SHA256: 00031 SA_PV_ERR_RECOVERABLE_RETURN_IF((digest_size != CS_SHA256_SIZE), KCM_STATUS_INVALID_PARAMETER, "Invalid digest size"); 00032 pal_status = pal_sha256 (data, data_size, digest); 00033 break; 00034 default: 00035 SA_PV_ERR_RECOVERABLE_RETURN_IF((true), KCM_CRYPTO_STATUS_UNSUPPORTED_HASH_MODE, "Hash mode not supported"); 00036 } 00037 00038 return cs_error_handler(pal_status); 00039 }
Generated on Tue Jul 12 2022 19:12:12 by 1.7.2