hmac sha256 hashing - multiple parameters

Hi all, I need to send sensor data to a web page with timestream plugin, which authenticates data, read them and displays graph. Authenticated data must involve multiple parameters - public key (generated by timestream plugin), sensor reading (from analogRead), unix timestamp and, optionally, some other parameters (predefined by timestream plugin on the web page). These parameters must be hashed using pre-shared secret key and sent over HTTP to the timestream enabled web page. As I see from Arduino cryptographic suite library, there is a Sha256.print method (from sha256.h), which takes a string message to be hashed, Sha256.initHmac method, which takes secret key as an argument, and based on the previous two, ha256.resultHmac() generates hashed HMAC. But, I'm wondering how can I produce HMAC on multiple parameters (sensor reading, unix timestamp, public key, etc.), each possible of different type? Thank you,

merge them into a byte array ...

"how can I produce HMAC on multiple parameters (sensor reading, unix timestamp, public key, etc.), each possible of different type? "

The parameters are concatenated to produce the "message" that the HMAC algorithm uses. The message can be any length and format because it is used as a binary value. The order of the parameters can be any order to produce a message. The message is then processed to make a smaller result from HMAC.

Since, I'm newcomer, is there an example how can I do that, i.e. how to concatenate different variables into byte array? Many thanks,

robtillaart: merge them into a byte array ...

Concatenation is ambiguous. "abc" || "xyz" is the same as "a" || "bcxyz". So the normal approach is to define some syntax for combining the elements unambiguously before passing to the hash function. "abc,xyz" is different from "a,bcxyz", if its the case that the input strings cannot contain commas.

“Concatenation is ambiguous.”

The HMAC Hashed Message Authentication Code is sent with the Message. The Message is not ambiguous, it is delivered to the recipient along with the HMAC. The message can contain text instructions about parsing the rest of the message.

Examples of the HMAC are available from several sources. FIPS Pub 198 is the normal resource, but with the USA government shutdown, it is inaccessible today. The sci.crypt newsgroup covers this HMAC with old forum discussions.

Test vectors are listed here
http://www.ietf.org/rfc/rfc2104.txt

alexe:
Since, I’m newcomer, is there an example how can I do that, i.e. how to concatenate different variables into byte array?
Many thanks,

Presumably you’re planning to send the data somewhere, and inevitably it will eventually be reduced to a sequence of bytes. How you encode the values into that sequence of bytes is for you to decide (and agree with the designer of the code at the far end which has to receive and make sense of them). If you’re sending it over HTTP it’s quite likely that this will use a text-based encoding system, for example you could just have a comma-separated sequence of decimal value - it would be easy to print that. However, one way or the other you have to decide how you’re going to encode your data into a message before you can hash or encrypt that message.