I really want to understand how can I use this library for my purposes.
I'm trying to encrypt a message that comes through the serial port of the Arduino, and send it through another serial port. But I'm having issues understanding how to use the library. I have read the documentation of the library, but I still get errors, I need a little help with this.
This is the code I have (without involving the serial ports), initially I wanted to check if I could define my strings and use them in another way instead of using the TestVector Function:
#include <Crypto.h>
#include <Speck.h>
#include <SpeckSmall.h>
#include <SpeckTiny.h>
#include <string.h>
struct EncryptText
{
const char *name;
byte key[32];
byte plaintext[16];
byte ciphertext[16];
};
EncryptText test ;
static TestCipher {
test.name = "Speck-128-ECB";
test.key = {0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08,
0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00};
test.plaintext = {0x6c, 0x61, 0x76, 0x69, 0x75, 0x71, 0x65, 0x20,
0x74, 0x69, 0x20, 0x65, 0x64, 0x61, 0x6d, 0x20};
test.ciphertext = {0xa6, 0x5d, 0x98, 0x51, 0x79, 0x78, 0x32, 0x65,
0x78, 0x60, 0xfe, 0xdf, 0x5c, 0x57, 0x0d, 0x18};
}
Speck speck;
SpeckSmall speckSmall;
SpeckTiny speckTiny;
byte buffer[16];
//void testCipher(BlockCipher *cipher, const struct TestVector *test, size_t keySize, bool decryption = true)
void testCipher(BlockCipher *cipher, size_t keySize, bool decryption = true)
{
Serial.print(" Encryption ... ");
cipher->setKey(key, keySize);
cipher->encryptBlock(buffer, plaintext);
for(byte b=0; b<16; b++)
{
Serial.print(buffer[b], HEX);
}
if (memcmp(buffer, ciphertext, 16) == 0)
Serial.println("Passed");
else
Serial.println("Failed");
if (!decryption)
return;
Serial.print(" Decryption ... ");
cipher->decryptBlock(buffer, ciphertext);
for(byte b=0; b<16; b++)
{
Serial.print(buffer[b], HEX);
}
if (memcmp(buffer, plaintext, 16) == 0)
Serial.println("Passed");
else
Serial.println("Failed");
}
I'm getting the error: "exit status 1 'TestCipher' does not name a type"
EDIT: The full error that I get is:
Speck_4-08-2017:27: error: 'TestCipher' does not name a type static
TestCipher {
^ Speck_4-08-2017.ino: In function 'void testCipher(BlockCipher*, size_t, bool)': Speck_4-08-2017:62: error:
'key' was not declared in this scope
cipher->setKey(key, keySize);
^ Speck_4-08-2017:63: error: 'plaintext' was not declared in this scope
cipher->encryptBlock(buffer, plaintext);
^ Speck_4-08-2017:70: error: 'ciphertext' was not declared in this scope
if (memcmp(buffer, ciphertext, 16) == 0)
^ Speck_4-08-2017:80: error: 'ciphertext' was not declared in this scope
cipher->decryptBlock(buffer, ciphertext);
^ Speck_4-08-2017.ino: In function 'void perfCipher(BlockCipher*, const TestVector*, size_t, bool)':
Speck_4-08-2017:104: error: 'key2' was not declared in this scope
cipher->setKey(key2, keySize);
^ Speck_4-08-2017.ino: In function 'void setup()': Speck_4-08-2017:158: error: 'testVectorSpeck128' was not
declared in this scope
testCipher(&speck, &testVectorSpeck128, 16);
^ exit status 1 'TestCipher' does not name a type
Any guidance would be very helpful.