Azure IoT common library

Dependents:   STM32F746_iothub_client_sample_mqtt f767zi_mqtt iothub_client_sample_amqp iothub_client_sample_http ... more

Committer:
AzureIoTClient
Date:
Sat Jan 28 09:35:22 2017 -0800
Revision:
19:2e0811512ceb
Parent:
0:fa2de1b79154
1.1.6

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Azure.IoT Build 0:fa2de1b79154 1 // Copyright (c) Microsoft. All rights reserved.
Azure.IoT Build 0:fa2de1b79154 2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
Azure.IoT Build 0:fa2de1b79154 3
AzureIoTClient 19:2e0811512ceb 4 #include <stddef.h>
Azure.IoT Build 0:fa2de1b79154 5 #include "azure_c_shared_utility/hmacsha256.h"
Azure.IoT Build 0:fa2de1b79154 6 #include "azure_c_shared_utility/hmac.h"
AzureIoTClient 19:2e0811512ceb 7 #include "azure_c_shared_utility/buffer_.h"
Azure.IoT Build 0:fa2de1b79154 8
Azure.IoT Build 0:fa2de1b79154 9 HMACSHA256_RESULT HMACSHA256_ComputeHash(const unsigned char* key, size_t keyLen, const unsigned char* payload, size_t payloadLen, BUFFER_HANDLE hash)
Azure.IoT Build 0:fa2de1b79154 10 {
Azure.IoT Build 0:fa2de1b79154 11 HMACSHA256_RESULT result;
Azure.IoT Build 0:fa2de1b79154 12
Azure.IoT Build 0:fa2de1b79154 13 if (key == NULL ||
Azure.IoT Build 0:fa2de1b79154 14 keyLen == 0 ||
Azure.IoT Build 0:fa2de1b79154 15 payload == NULL ||
Azure.IoT Build 0:fa2de1b79154 16 payloadLen == 0 ||
Azure.IoT Build 0:fa2de1b79154 17 hash == NULL)
Azure.IoT Build 0:fa2de1b79154 18 {
Azure.IoT Build 0:fa2de1b79154 19 result = HMACSHA256_INVALID_ARG;
Azure.IoT Build 0:fa2de1b79154 20 }
Azure.IoT Build 0:fa2de1b79154 21 else
Azure.IoT Build 0:fa2de1b79154 22 {
Azure.IoT Build 0:fa2de1b79154 23 if ((BUFFER_enlarge(hash, 32) != 0) ||
Azure.IoT Build 0:fa2de1b79154 24 (hmac(SHA256, payload, (int)payloadLen, key, (int)keyLen, BUFFER_u_char(hash) ) != 0))
Azure.IoT Build 0:fa2de1b79154 25 {
Azure.IoT Build 0:fa2de1b79154 26 result = HMACSHA256_ERROR;
Azure.IoT Build 0:fa2de1b79154 27 }
Azure.IoT Build 0:fa2de1b79154 28 else
Azure.IoT Build 0:fa2de1b79154 29 {
Azure.IoT Build 0:fa2de1b79154 30 result = HMACSHA256_OK;
Azure.IoT Build 0:fa2de1b79154 31 }
Azure.IoT Build 0:fa2de1b79154 32 }
Azure.IoT Build 0:fa2de1b79154 33
Azure.IoT Build 0:fa2de1b79154 34 return result;
Azure.IoT Build 0:fa2de1b79154 35 }