void HomeAutomation::encryptPayload(char *data) {
    aes128_enc_single(this->key, data + 16);
    for (int i = 0; i < 16; i++) {
        data[i] = data[16 + i] ^ data[i];
    }
    aes128_enc_single(this->key, data);
}
Exemple #2
0
static word serverRequestTemperature(byte fd) {
	// filling state
	uint8_t data[16] = {0}; // 16 bytes block for encryption, which have to be send in hex
	data[0] = uint8_t(uint32_t(sharedState->currentTemperature)); // whole part 
	data[1] = uint8_t(uint32_t(sharedState->currentTemperature * 100) % 100); // fraction part
	*(uint32_t*)(data + (16 - sizeof(uint32_t))) = sharedState->lastNonce;

	sharedState->lastNonce += 1;
	
	// encrypting the state
	aes128_enc_single(encKey, data);

	printlnDebug("Sending encrypted state");
	BufferFiller bfill = ether.tcpOffset();
	bfill.emit_p(sendTemperatureHeader);
	bfill.emit_raw((char*)data, sizeof(data)); 
	temperatureSend = 1;
	sendEaseTime = millis() + SENDINGEASE;
	return bfill.position();
}