Is there a crypto ported to Arduino?

I selected the AES as it had encrypt and decrypt. and I got the AES library to work :slight_smile:
I had some issues so I wanted to share the code.
The sketch below is my test program and it shows how to use the AES library.
It is long because there is plenty of checking and debugging info added because it just didn't work (I had 6 as keylength :0).

#include "AES.h"

#define KEYLENGTH 32  // this means 32 bit encryption only following values are allowed 16, 128, 24, 192, 32, 256
AES aes;
char PassString[] = "This is hard to believe but true however";// this must be at least KEYLENGTH characters long
byte key[KEYLENGTH];
void setup()
{
	Serial.begin(115200);

	Serial.println("Starting AES test");
	for (int i = 0; i < KEYLENGTH; i++)
	{
		key[i] = PassString[i];
	}

	if (aes.set_key(key, KEYLENGTH) != 0)
	{
		Serial.println(F("Failed to set key"));
	}
}

// The loop function is called in an endless loop
void loop()
{

	char Message[] = "A top secret message. 123456789012345678901234";
	byte plain[N_BLOCK];
	byte cipher[N_BLOCK];
	byte decrypted[N_BLOCK];

	Serial.print(F("message : '"));
	Serial.print(Message);
	Serial.println(F("'"));
	Serial.print(F("plain binary: '"));
	for (int i = 0; i < N_BLOCK; i++)
	{
		plain[i] = Message[i];
		cipher[i] = 0;
		decrypted[i] = 0;
		Serial.print(plain[i]);
	}
	Serial.println(F("'"));

	Serial.print(F("plain char: '"));
	for (int i = 0; i < N_BLOCK; i++)
	{
		Serial.print(char(plain[i]));
	}
	Serial.println(F("'"));

	if (aes.encrypt(plain, cipher) == 0)
	{
		Serial.print(F("encrypted : '"));
		for (int i = 0; i < N_BLOCK; i++)
		{
			Serial.print(cipher[i]);
		}
		Serial.println(F("'"));
	} else
	{
		Serial.println(F("Failed to encrypt"));
	}

	if (aes.decrypt(cipher, decrypted) == 0)
	{
		Serial.print(F("decrypted binary : '"));
		for (int i = 0; i < N_BLOCK; i++)
		{
			Serial.print(decrypted[i]);
		}
		Serial.println(F("'"));

		Serial.print(F("decrypted char : '"));
		for (int i = 0; i < N_BLOCK; i++)
		{
			Serial.print(char(decrypted[i]));
		}
		Serial.println(F("'"));
	} else
	{
		Serial.println(F("Failed to decrypt"));
	}

	delay(1000);
}

the serial monitor shows following output

Starting AES test
message : 'A top secret message. 123456789012345678901234'
plain binary: '6532116111112321151019911410111632109101115'
plain char: 'A top secret mes'
encrypted : '42123310212525483134722222673252149132239'
decrypted binary : '6532116111112321151019911410111632109101115'
decrypted char : 'A top secret mes'

Thanks for this Library
Best regards
Jan