rweather / arduinolibs

Arduino Cryptography Library
444 stars 212 forks source link

TestSpeck.ino - Decryption fails for SpeckTiny with all key sizes #76

Open alve89 opened 1 year ago

alve89 commented 1 year ago

Hi!

I just tried to use your CryptoLW library on both my Arduino Nano and Arduino Uno. I only removed the performance tests, the rest is your origin code in TestSpeck.ino. Decryption fails on both boards for SpeckTiny.

This is the output of all testCipher() calls (identical for Uno and Nano):

State Sizes:
Speck ... 275
SpeckSmall ... 67
SpeckTiny ... 35

Speck Test Vectors:
Speck-128-ECB Encryption ... Passed
Speck-128-ECB Decryption ... Passed
Speck-192-ECB Encryption ... Passed
Speck-192-ECB Decryption ... Passed
Speck-256-ECB Encryption ... Passed
Speck-256-ECB Decryption ... Passed

SpeckSmall Test Vectors:
Speck-128-ECB Encryption ... Passed
Speck-128-ECB Decryption ... Passed
Speck-192-ECB Encryption ... Passed
Speck-192-ECB Decryption ... Passed
Speck-256-ECB Encryption ... Passed
Speck-256-ECB Decryption ... Passed

SpeckTiny Test Vectors:
Speck-128-ECB Encryption ... Passed
Speck-128-ECB Decryption ... Failed
Speck-192-ECB Encryption ... Passed
Speck-192-ECB Decryption ... Failed
Speck-256-ECB Encryption ... Passed
Speck-256-ECB Decryption ... Failed

I'm using the following Arduino IDE: Version: 2.0.4 Date: 2023-02-27T16:14:28.576Z CLI Version: 0.31.0

rweather commented 1 year ago

That is actually expected. SpeckTiny only implements encryption to keep the memory size as tiny as possible. Use SpeckSmall if you also need decryption. Decryption is stubbed out in the code:

void SpeckTiny::decryptBlock(uint8_t output, const uint8_t input) { // Decryption is not supported by SpeckTiny. Use SpeckSmall instead. }

It is weird though because the example should be disabling the decryption tests. I will try to figure out why it isn't.