/* Encryption function for AES128-GCM without authentifications ** created by Peter (meinzaehler.com) ** free for everyone ;-) ** tested on ESP8266 ** according of example by https://www.michaelreitbauer.at/kaifa-ma309-auslesen-smart-meter-evn/ ** and explanations of https://community.symcon.de/uploads/short-url/scJg8Irz6VRWPUcftQYr5LhPWwV.pdf ** next step is to support KAIFA Current Meter for StromLog */ #include #include #include //key cotains 16 byte for encryption and the very important advice is... for GMC there is only encryption for booth (encrypt and also decrypt) functions! byte key[16] = {0x36,0xC6,0x66,0x39,0xE4,0x8A,0x8C,0xA4,0xD6,0xBC,0x8B,0x28,0x2A,0x79,0x3B,0xBB}; // this is the start frame add manufracturer of meter (it's differend by meter of manufracturer) this was the trickies solutions of decriptions! byte startFrame[16] = {0x4B,0x46,0x4D,0x67,0x50,0x00,0x00,0x09,0x00,0x00,0x00,0x23,0x00,0x00,0x00,0x02}; // save the XOR-Key for decryption (and is used the encrypt function!) byte key4Xor[16]; // those are the input data of mBus. here only put the data into memory byte cryptString[]={0x88,0xD5,0xAB,0x4F,0x97,0x51,0x5A,0xAF,0xC6,0xB8,0x8D,0x2F,0x85,0xDA,0xA7,0xA0, 0xE3,0xC0,0xC4,0x0D,0x00,0x45,0x35,0xC3,0x97,0xC9,0xD0,0x37,0xAB,0x7D,0xBD,0xA3, 0x29,0x10,0x76,0x15,0x44,0x48,0x94,0xA1,0xA0,0xDD,0x7E,0x85,0xF0,0x2D,0x49,0x6C, 0xEC,0xD3,0xFF,0x46,0xAF,0x5F,0xB3,0xC9,0x22,0x9C,0xFE,0x8F,0x3E,0xE4,0x60,0x6A, 0xB2,0xE1,0xF4,0x09,0xF3,0x6A,0xAD,0x2E,0x50,0x90,0x0A,0x43,0x96,0xFC,0x6C,0x2E, 0x08,0x3F,0x37,0x32,0x33,0xA6,0x96,0x16,0x95,0x07,0x58,0xBF,0xC7,0xD6,0x3A,0x9E, 0x9B,0x6E,0x99,0xE2,0x1B,0x2C,0xBC,0x2B,0x93,0x47,0x72,0xCA,0x51,0xFD,0x4D,0x69, 0x83,0x07,0x11,0xCA,0xB1,0xF8,0xCF,0xF2,0x5F,0x0A,0x32,0x93,0x37,0xCB,0xA5,0x19, 0x04,0xF0,0xCA,0xED,0x88,0xD6,0x19,0x68,0x74,0x3C,0x84,0x54,0xBA,0x92,0x2E,0xB0, 0x00,0x38,0x18,0x2C,0x22,0xFE,0x31,0x6D,0x16,0xF2,0xA9,0xF5,0x44,0xD6,0xF7,0x5D, 0x51,0xA4,0xE9,0x2A,0x1C,0x4E,0xF8,0xAB,0x19,0xA2,0xB7,0xFE,0xAA,0x32,0xD0,0x72, 0x6C,0x0E,0xD8,0x02,0x29,0xAE,0x6C,0x0F,0x76,0x21,0xA4,0x20,0x92,0x51,0xAC,0xE2, 0xB2,0xBC,0x66,0xFF,0x03,0x27,0xA6,0x53,0xBB,0x68,0x6C,0x75,0x6B,0xE0,0x33,0xC7, 0xA2,0x81,0xF1,0xD2,0xA7,0xE1,0xFA,0x31,0xC3,0x98,0x3E,0x15,0xF8,0xFD,0x16,0xCC, 0x57,0x87,0xE6,0xF5,0x17,0x16,0x68,0x14,0x14,0x68,0x53,0xFF,0x11,0x01,0x67,0x41, 0x9A,0x3C,0xFD,0xA4,0x4B,0xE4,0x38,0xC9,0x6F,0x0E,0x38,0xBF,0x83,0xD9}; // create an outputblock byte decryptedBlock[16]; //create an object of AES128 class AES128 aes128; void setup() { Serial.begin(115200); // set serial speed for controll of output aes128.setKey(key,16);// Setting Key for AES-GCM } void loop() { delay(500); // little wait time ;-) startFrame[15]=2; // after every whole blocks set the counter of start. Why there is number two... i dont know, but it works! for(int x=0; x