pfodParser  3.61.0
The pfodParser library is handles commands sent from the Android pfodApp, pfodApp supports WiFi, BLE, Bluetooth and SMS connections
pfodMACClient.h
Go to the documentation of this file.
1 #ifndef pfodMACClient_h
2 #define pfodMACClient_h
9 /*
10  * (c)2014-2017 Forward Computing and Control Pty. Ltd.
11  * NSW Australia, www.forward.com.au
12  * This code is not warranted to be fit for any purpose. You may only use it at your own risk.
13  * This code may be freely used for both private and commercial use
14  * Provide this copyright is maintained.
15  */
16 
17 #include <Arduino.h>
18 #include "pfodStream.h"
19 #include "pfodMAC.h"
20 
22  public:
23 
25  boolean init();
26 
27 
28  void setSecretKey(byte *key, int len);
29 
30  void setDebugStream(Print* out);
31  boolean isValid(); // powercycles > 0
32  boolean isBigEndian(); // is 1 stored as 0x00000001 false for Atmel 8 bit micros
33 
34 
35 
36  // useful for debugging
37  void printBytesInHex(Print *out, const byte* b, size_t len);
38 
39 
40  void initHash(); // start a new hash by initializing with the secret key
41  void putByteToHash(byte b); // add a byte to the hash
42  void putBytesToHash(byte* b, int len); // add a byte array to the hash
43  void putLongToHash(uint32_t l); // add a long to the hash (in BigEndian format)
44  void finishHash(); // finish the hash and calculate the result
45  byte* getHashedResult(); // get pointer to the 8 byte result
46 
47 
55  boolean checkMsgHash(const byte* msgHash, uint16_t len);
56 
57  void reverseBytes(byte *b, int len); // swap from order of bytes upto len, converts between Endians, Big to Little, Little to Big
58 
59 // const static uint8_t msgHashByteSize = 4; // number of byte in per msg hash
60 // const static uint8_t challengeHashByteSize = 8; // number of bytes in challenge hash
61 // const static uint8_t challengeByteSize = 8; // number of bytes in challenge
62 // const static uint8_t maxKeySize = 16; // max size of key 128 bits
63 
64  unsigned char *hashChallenge(byte *challenge); // hashes challenge returns pointer to 8 byte result
65 
66  private:
67  boolean initCalled; // set true after first init() call. Stops multiple calls to get readPowerCycles
68  boolean cmpToResult(const byte* response, uint16_t len);
69  Print *debugOut;
70  byte key[pfodMAC::maxKeySize]; // the secret key after reading from EEPROM and expanding to 16 bytes
71  uint8_t keyLen; // 0 if no key, else 16 (after padding key with 0 if shorter)
72  boolean bigEndian; // true if bigEndian uC
73 
74 
75 };
76 
77 
78 #endif // pfodMACClient_h
79 
pfodMACClient for Arduino Updates power cycles, builds the Challenge, keeps track in message counts a...
Definition: pfodMACClient.h:21
boolean isBigEndian()
void printBytesInHex(Print *out, const byte *b, size_t len)
void setDebugStream(Print *out)
void putByteToHash(byte b)
byte * getHashedResult()
void finishHash()
void reverseBytes(byte *b, int len)
void setSecretKey(byte *key, int len)
boolean isValid()
void putBytesToHash(byte *b, int len)
unsigned char * hashChallenge(byte *challenge)
void putLongToHash(uint32_t l)
boolean init()
boolean checkMsgHash(const byte *msgHash, uint16_t len)
Converts msgHash from hex Digits to bytes and then compares the resulting byte[] with the current has...
static const uint8_t maxKeySize
Definition: pfodMAC.h:94