1 | /*
|
---|
2 | ###############################################################################
|
---|
3 | #
|
---|
4 | # Temboo Arduino library
|
---|
5 | #
|
---|
6 | # Copyright 2014, Temboo Inc.
|
---|
7 | #
|
---|
8 | # Licensed under the Apache License, Version 2.0 (the "License");
|
---|
9 | # you may not use this file except in compliance with the License.
|
---|
10 | # You may obtain a copy of the License at
|
---|
11 | #
|
---|
12 | # http://www.apache.org/licenses/LICENSE-2.0
|
---|
13 | #
|
---|
14 | # Unless required by applicable law or agreed to in writing,
|
---|
15 | # software distributed under the License is distributed on an
|
---|
16 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
---|
17 | # either express or implied. See the License for the specific
|
---|
18 | # language governing permissions and limitations under the License.
|
---|
19 | #
|
---|
20 | ###############################################################################
|
---|
21 | */
|
---|
22 |
|
---|
23 | #ifndef TMBHMAC_H_
|
---|
24 | #define TMBHMAC_H_
|
---|
25 | #include "tmbmd5.h"
|
---|
26 | #include "TembooGlobal.h"
|
---|
27 |
|
---|
28 | #define HMAC_HASH_SIZE_BYTES (MD5_HASH_SIZE_BYTES)
|
---|
29 | #define HMAC_BLOCK_SIZE_BYTES (MD5_BLOCK_SIZE_BYTES)
|
---|
30 |
|
---|
31 | #define HMAC_HEX_SIZE_BYTES (HMAC_HASH_SIZE_BYTES * 2)
|
---|
32 |
|
---|
33 | class HMAC
|
---|
34 | {
|
---|
35 | public:
|
---|
36 | HMAC();
|
---|
37 | HMAC(const uint8_t* key, uint32_t keyLength);
|
---|
38 | void init(const uint8_t* key, uint32_t keyLength);
|
---|
39 | void process(const uint8_t* msg, uint32_t msgLength);
|
---|
40 | void finish(uint8_t* dest);
|
---|
41 | void finishHex(char* dest);
|
---|
42 | enum {
|
---|
43 | HMAC_OK = 0,
|
---|
44 | HMAC_ERROR,
|
---|
45 | HMAC_FAIL_TESTVECTOR
|
---|
46 | };
|
---|
47 |
|
---|
48 | private:
|
---|
49 | MD5 m_md5;
|
---|
50 | const uint8_t* m_key;
|
---|
51 | uint32_t m_keyLength;
|
---|
52 |
|
---|
53 | void constructKeyPad(uint8_t* dest, const uint8_t* key, uint32_t keyLength, uint8_t padByte);
|
---|
54 | void toHex(uint8_t* hmac, char* dest);
|
---|
55 | };
|
---|
56 | #endif
|
---|
57 |
|
---|