Mark Radbourne / Mbed 2 deprecated iothub_client_sample_amqp

Dependencies:   EthernetInterface NTPClient iothub_amqp_transport iothub_client mbed-rtos mbed

Fork of iothub_client_sample_amqp by Azure IoT

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers hmacsha256.c Source File

hmacsha256.c

00001 // Copyright (c) Microsoft. All rights reserved.
00002 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
00003 
00004 #include <stdlib.h>
00005 #ifdef _CRTDBG_MAP_ALLOC
00006 #include <crtdbg.h>
00007 #endif
00008 #include "azure_c_shared_utility/gballoc.h"
00009 
00010 #include "azure_c_shared_utility/hmacsha256.h"
00011 #include "azure_c_shared_utility/hmac.h"
00012 #include "azure_c_shared_utility/strings.h"
00013 
00014 HMACSHA256_RESULT HMACSHA256_ComputeHash(const unsigned char* key, size_t keyLen, const unsigned char* payload, size_t payloadLen, BUFFER_HANDLE hash)
00015 {
00016     HMACSHA256_RESULT result;
00017 
00018     if (key == NULL ||
00019         keyLen == 0 ||
00020         payload == NULL ||
00021         payloadLen == 0 ||
00022         hash == NULL)
00023     {
00024         result = HMACSHA256_INVALID_ARG;
00025     }
00026     else
00027     {
00028         if ((BUFFER_enlarge(hash, 32) != 0) ||
00029             (hmac(SHA256, payload, (int)payloadLen, key, (int)keyLen, BUFFER_u_char(hash) ) != 0))
00030         {
00031             result = HMACSHA256_ERROR;
00032         }
00033         else
00034         {
00035             result = HMACSHA256_OK;
00036         }
00037     }
00038 
00039     return result;
00040 }