9 #include <ChannelList.h>
21 #define AES_KEY_SIZE 16
24 #error No HM_DEF_KEY defined.
26 #ifndef HM_DEF_KEY_INDEX
27 #error No HM_DEF_KEY_INDEX defined.
37 uint8_t initvector[16];
43 static uint16_t size () {
44 return AES_KEY_SIZE + 1;
47 void defaults ()
const {
48 static uint8_t aes_def_key[] = {HM_DEF_KEY};
49 setIndex(HM_DEF_KEY_INDEX);
50 writeKey(aes_def_key);
53 bool readKey(uint8_t* key)
const {
54 return getData(1,key,AES_KEY_SIZE);
57 bool writeKey(uint8_t* key)
const {
58 return setData(1,key,AES_KEY_SIZE);
61 uint8_t getIndex ()
const {
65 bool setIndex (uint8_t idx)
const {
66 return setByte(0,idx);
71 void storeAuth (uint8_t c,
const uint8_t* a) {
77 if( msg.count() == count ) {
83 void fillInitVector (
const Message& msg) {
84 uint8_t n = msg.length()-10;
85 memcpy(initvector,msg.buffer()+10,n);
86 memset(initvector+n,0x00,16-n);
89 void applyVector (uint8_t* data) {
90 for( uint8_t i=0; i<16; i++ ) {
91 data[i] ^= initvector[i];
95 bool challengeKey (
const uint8_t* challenge,uint8_t index) {
96 if( hasKey(index) ==
true ) {
97 uint8_t key[AES_KEY_SIZE];
99 for( uint8_t i=0; i<6; ++i ) {
100 key[i] ^= challenge[i];
102 aes128_init(key,&ctx);
108 bool hasKey (uint8_t index) {
109 return getIndex() == index;
113 uint8_t key[AES_KEY_SIZE];
115 aes128_init(key,&ctx);
116 uint8_t* data = msg.data();
118 aes128_dec(data,&ctx);
120 if( data[0] == 0x01 ) {
121 if( (data[1] & 0x01) == 0x00 ) {
122 memcpy(keytmp,data+2,8);
125 memcpy(key,keytmp,8);
126 memcpy(key+8,data+2,8);
127 DPRINT(F(
"New Key: "));DHEX(key,16);
128 DPRINT(F(
"Index: "));DHEXLN((uint8_t)(data[1] & 0xfe));
130 setIndex(data[1] & 0xfe);
140 #define AES_KEY_SIZE 0
147 static uint16_t size () {
155 void addAuth (Message& msg) {}