Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve CRC performance #412

Merged
merged 20 commits into from
Mar 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pytest_cache/v/cache/lastfailed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Binary file modified data/decodings/homematic
Binary file not shown.
8 changes: 4 additions & 4 deletions data/decodings/homematic.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ int main(int argc, char **argv)
dec[offset+0] = enc[offset+0];

dec[offset+1] = (~enc[offset+1])^0x89;
for(i = offset+2; i < max; i++)
for(i = offset + 2; i < max - 3; i++)
dec[i] = (enc[i-1]+0xdc) ^ enc[i];
dec[offset+i] = enc[offset+i] ^ dec[offset+2];
dec[i] = enc[i] ^ dec[offset+2];

dec[max-1]=0; // Set CRC to 0x0000
dec[max-2]=0;
Expand Down Expand Up @@ -85,9 +85,9 @@ int main(int argc, char **argv)
enc[offset+0] = dec[offset+0];

enc[offset+1] = ~(dec[offset+1]^0x89);
for(i = offset+2; i < max; i++)
for(i = offset + 2; i < max - 3; i++)
enc[i] = (enc[i-1]+0xdc) ^ dec[i];
enc[offset+i] = dec[offset+i] ^ dec[offset+2];
enc[i] = dec[i] ^ dec[offset+2];

enc[max-1]=0; // Set CRC to 0x0000
enc[max-2]=0;
Expand Down
Binary file modified data/decodings/homematic_complete
Binary file not shown.
18 changes: 8 additions & 10 deletions data/decodings/homematic_complete.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,11 @@ int main(int argc, char **argv)
*/

// Decrypt
dec[offset+0] = enc[offset+0];

dec[offset+1] = (~enc[offset+1])^0x89;
for(i = offset+2; i < max; i++)
dec[offset+0] = enc[offset+0];
dec[offset+1] = (~enc[offset+1])^0x89;
for(i = offset + 2; i < max - 3; i++)
dec[i] = (enc[i-1]+0xdc) ^ enc[i];
dec[offset+i] = enc[offset+i] ^ dec[offset+2];
dec[i] = enc[i] ^ dec[offset+2];

// Recompute CRC and overwrite with FAKE-CRC, if CRC was OK before
if(crc_ok)
Expand Down Expand Up @@ -190,12 +189,11 @@ int main(int argc, char **argv)
*/

// Encrypt
enc[offset+0] = dec[offset+0];

enc[offset+1] = ~(dec[offset+1]^0x89);
for(i = offset+2; i < max; i++)
enc[offset+0] = dec[offset+0];
enc[offset+1] = ~(dec[offset+1])^0x89;
for(i = offset + 2; i < max - 3; i++)
enc[i] = (enc[i-1]+0xdc) ^ dec[i];
enc[offset+i] = dec[offset+i] ^ dec[offset+2];
enc[i] = dec[i] ^ dec[offset+2];

// Overwrite with correct CRC
crcvalue = crc(&enc[8], max-2-8);
Expand Down
Loading