PDA

View Full Version : xtea encryption



toalan
- 16th July 2005, 01:11
I just implemented xtea for the AVR MCU using C, it might be hard to implement in Picbasic since 32 bit unsigned long integers are not supported (I think).

I just copied from http://www.answers.com/topic/xtea into my C compiler (IAR embedded workbench)and was able to use it without modification for AVR.

xtea is supposed to be one of the most secure ( I do not think it has been cracked yet) and fastest algorithims. I looked into DES and AES and they seemed to time consuming to implement. I think xtea or one of its variants is used for the xbox.

I am using xtea to encrypt firmware so people can flash upgrade stuff without me worrying that they will steal my work.

mister_e
- 16th July 2005, 09:52
xtea is supposed to be one of the most secure ( I do not think it has been cracked yet)


LMAO well since you have a code and the explanation can be found somewhere... what is the big deal to crack something with it???

BTW all alrgorithm are still human made... another can bypass it easy... really easy



I think xtea or one of its variants is used for the xbox.

no comments, some are in jail now...

toalan
- 16th July 2005, 15:59
Sorry I am not following you, my implementation is to supply people with encrypted firmware, they send it to the MCU and the MCU will decrypt the data and write it to flash memory.

If you can bypass encryption easily then you are one of the few geniuses and perhaps your work has been undocumented. As of 2004 there is been no officially successful attempts at breaking the xtea algorithim.

The xtea algorithim in xbox was never really borken, people exploited flaws in the hardware design to run unsigned code, most notably the big font flaw.

toalan
- 20th July 2005, 00:30
if you guys are interested in my XTEA bootloader here it is http://www.14point7.com/AVR.htm

Ron Marcus
- 20th April 2008, 21:40
I will need to use encryption in a wireless stream for an upcoming product. XTEA looks good, and compact. I will write in assembly, but I wondered if anyone has played with this in PBP? It looks like a fun excercise, especially with the version 2.5 longs! Any other ideas for good encryption without a lot of overhead? It needs to stand up to that .01% of attacks.
Thanks,
Ron

tenaja
- 21st April 2008, 01:50
Go to the Swordfish Basic compiler site and download their demo program; it has XTEA with it. Surely you can convert it.
http://www.sfcompiler.co.uk/swordfish/

Ron Marcus
- 21st April 2008, 19:54
Go to the Swordfish Basic compiler site and download their demo program; it has XTEA with it. Surely you can convert it.
http://www.sfcompiler.co.uk/swordfish/
I downloaded Swordfish, but cannot find any mention of TEA, XTEA, or TEA-N. Where did you find it?

mister_e
- 21st April 2008, 20:54
Should be in "\Sample\encryption" folder.

Ron Marcus
- 2nd May 2008, 17:15
OK, here it is. These subs will take an eight byte block of code, and encrypt it, then decrypt it. The key must be exactly the same for encrypt and decrypt, and don't mess with "Delta". This is only for the PIC18s and PBPL(2.50a)




;************************************************* *********************
; XTEA VARIABLES ************************************************** ***
;************************************************* *********************
roundin con 32 ;number of loops
Delta con $9E3779B9 ;5/4/2 * 2power32

round var byte
Sumin var long
vy var Long
text_byte var byte[8] ;text coming in, going out.
vz var Long
tb var byte
Sum var long
temp var long
tmp0 var temp.byte0
tmp1 var temp.byte1
tmp2 var temp.byte2
tmp3 var temp.byte3
key var long[4]
ka var key[0]

kb var key[1]
kc var key[2]
kd var key[3]
limit var long
block var long[2]
index var word
key[0] = $31323334 ;128 bit key
key[1] = $93D8E9AF ;don't use mine
key[2] = $275FC2BA ;must be
key[3] = $95E20110 ;random


;************************************************* *********************



main:



hserout [str text_byte\8,13] ;the unchanged block of 8 bytes
gosub beep
;pause 1000
GOsub TEAenc ;scramble well
hserout [str text_byte\8,13] ;show mess
gosub teadec ;unscramble
hserout [str text_byte\8,13] ;No s--t, it works!
pause 100
stop
TEAenc: for tb = 0 to 3 ; convert string into code
vy.byte0[tb] = text_byte[tb]
vz.byte0[tb] = text_byte[tb+4]
next tb
sum = 0
Limit = Delta * roundin
while Sum <> limit
vy = vy + (((vz<<4) ^ (vz >>5))^(Sum + Key[sum & 3]))
sum = sum + Delta
vz = vz + (((vy<<4) ^ (vy >>5))^(Sum + Key[sum>>11 & 3]))
wend
for tb = 0 to 3
text_byte[tb]= vy.byte0[tb]
text_byte[tb+4] = vz.byte0[tb]
next tb
return

;************************************************* **************************
TEAdec: ;Convert code into string
for tb = 0 to 3
vy.byte0[tb] = text_byte[tb]
vz.byte0[tb] = text_byte[tb+4]
next tb

sum = Delta * roundin
while sum <> 0
vz = vz - (((vy<<4) ^ (vy >>5))^(Sum + Key[(sum>>11) & 3]))
sum = sum - Delta
vy = vy - (((vz<<4) ^ (vz >>5))^(Sum + Key[sum & 3]))
wend
for tb = 0 to 3
text_byte[tb]= vy.byte0[tb]
text_byte[tb+4] = vz.byte0[tb]
next tb
return

mister_e
- 2nd May 2008, 22:13
Looks good to me at first glance. Sure some will use it.