XTEADECODE

From MCS Wiki AVR
Revision as of 00:23, 13 December 2014 by Admin (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Contents

Action

Decrypts a variable or array using the XTEA protocol.

 

 

Syntax

XTEADECODE  Msg , Key , size

 

 

Remarks

Msg

The variable to decrypt. Decryption is performed in blocks of 8 bytes. This means that you need to specify an array that has a minimal size of 8 bytes. For example, 2 Longs will be 8 bytes in size.

 

After the decryption is performed, Msg will contain the original unencrypted data.

Key

The 128 bit key which is used to decrypt the message data.

You need to pass this as an array of 16 bytes.

Size

The number of bytes to decrypt. This must be a multiple of 8.

 

The XTEA encryption/decryption is described well at http://en.wikipedia.org/wiki/XTEA

The XTEA is an enhanced version of the TEA encryption protocol.

 

The XTEA encoding/decoding routines have a small footprint. You could use the XTEADECODE in a bootloader and encrypt your firmware.


When you use other tools to encode your data, you will find differences because of memory order. You can use the xtea2.lib for using the same memory order.

Include it in your code like :  $LIB  "xtea2.lib"

 

See also

XTEAENCODE$LOADER

 

 

 

Example


'----------------------------------------------------------
' XTEA.BAS
' This sample demonstrates the XTEA encryption/decryption
' statements
' (c) 1995-2011 MCS Electronics
'----------------------------------------------------------
$regfile = "m88def.dat"
$hwstack = 40
$swstack = 32
 
 
'The XTEA encryption/decryption has a small footprint
'XTEA processes data in blocks of 8 bytes. So the minimum length of the data is 8 bytes.
'A 128 bit key is used to encrypt/decrypt the data. You need to supply this in an array of 8 bytes.
 
'Using the encoding on a string can cause problems when the data contains a 0. This is the end of the string marker.
 
Dim Key(16) As Byte '128 bit key
Dim Msg(32) As Byte ' this need to be a multiple of 8
 
Dim B As Byte ' counter byte
 
For B = 1 To 16 ' create a simple key and also fill the data
 Key(b) = B
 Msg(b) = B
Next
 
 
Xteaencode Msg(1) , Key(1) , 32 ' encode the data
 
For B = 1 To 16
Print Hex(msg(b)) ; " , " ;
Next
Print
 
 
Xteadecode Msg(1) , Key(1) , 32 ' decode the data
 
For B = 1 To 16
Print Hex(msg(b)) ; " , " ;
Next 'it should print 1-16 now
Print
 
End

Languages   English Deutsch  
Personal tools
Namespaces
Variants
Actions
Navigation
In other languages
Language