Go Down

Topic: String Encryption for Uno (ATMega328) (Read 2907 times) previous topic - next topic

dauhee

Hi All,

I have tried unsuccessfully to perform string encryption. My grasp of the C language is not good. I have tried existing libraries without success, such as skipjack from avr-crypto, and also AES from another source.

If anybody was able to provide some assistance, I would be much appreciative!

Thanks,

Dauhee.

eried

Maybe a simpler encryption will work? what is the purpose of encrypting strings in your project?
My website: http://ried.cl

dauhee

It is for transmission over virtualwire between arduino units. I had looked at XOR but its very weak. XTEA, SKipjack, DES, AES, anything will do!

Thanks.

retrolefty


It is for transmission over virtualwire between arduino units. I had looked at XOR but its very weak. XTEA, SKipjack, DES, AES, anything will do!

Thanks.


XOR used with a one-time key pad is unbreakable.

Lefty

el_supremo

Quote
I have tried existing libraries without success

You haven't said what failed. Why not post some code which demonstrates the problem?

Pete

dauhee

#5
Jan 16, 2013, 11:28 pm Last Edit: Jan 17, 2013, 08:44 am by Coding Badly Reason: 1
if there was example code for XOR one time pad that would be fantastic!

The code I have been working with is as below. It only works for N_BLOCK chars which is 16. Any chars after that are ignored and don't get encrypted. I've tried to use multi-dimentional byte arrays and its getting ugly :(

Code: [Select]
#include <AES.h>

AES aes ;


void loop ()
{
}


void setup ()
{
  Serial.begin (57600) ;


  const int KEYLENGTH = 32;

  char PassString[] = "This is hard to believe but true however";// this must be at least KEYLENGTH characters long
  byte key[KEYLENGTH];


  char Message[] = "A top secret message. 123456789012345678901234";
  byte plain[strlen(Message)];
  byte cipher[strlen(Message)];
  byte decrypted[strlen(Message)];
 
  String strData = "";

  Serial.println("Starting AES test");


  for (int i = 0; i < KEYLENGTH; i++)
  {
    key[i] = PassString[i];
  }
 
    for (int i = 0; i < strlen(Message); i++)
  {
    plain[i] = Message[i];
    cipher[i] = 0;
    decrypted[i] = 0;
  }

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

    for (int a = 0; a < (int)ceil((float)strlen(Message)/(float)N_BLOCK); a++)
    {
      //Serial.println(a);
    }

  if (aes.encrypt(plain, cipher) == 0)
  {

    Serial.print(F("encrypted char: '"));
    for (int i = 0; i < strlen(Message); i++)
    {
      Serial.print(char(cipher[i]));
    }
    Serial.println(F("'"));
  }
  else
  {
    Serial.println(F("Failed to encrypt"));
  }

  if (aes.decrypt(cipher, decrypted) == 0)
  {

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


This is using the AES library under:
http://arduino.cc/forum/index.php/topic,88890.0.html

And additional help from:
http://arduino.cc/forum/index.php/topic,96197.0.html

Any assistance would help minimise my hair loss :)


Moderator edit: session ID removed from link.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy