Pages: [1]   Go Down
Author Topic: String Encryption for Uno (ATMega328)  (Read 2063 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Chile
Offline Offline
Edison Member
*
Karma: 32
Posts: 1233
Arduino rocks?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Maybe a simpler encryption will work? what is the purpose of encrypting strings in your project?
Logged

My website: http://ried.cl

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16514
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Edison Member
*
Karma: 31
Posts: 1417
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I have tried existing libraries without success
You haven't said what failed. Why not post some code which demonstrates the problem?

Pete
Logged

Where are the Nick Gammons of yesteryear?

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley-sad

Code:
#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 smiley


Moderator edit: session ID removed from link.
« Last Edit: January 17, 2013, 02:44:13 am by Coding Badly » Logged

Pages: [1]   Go Up
Jump to: