View previous topic :: View next topic |
Author |
Message |
enniom
Joined: 20 Oct 2009 Posts: 537
|
Posted: Fri May 21, 2021 1:38 pm Post subject: Help with XTEA Encoding of an Array |
|
|
Dear Forum Members,
XTEA encoding of a message is being considered for an application in development. The message is 16 bytes long and with each update, only 1-4 of the 16 bytes need to be changed.
However, because the XTEA encoding sub in BASCOM modifies the original array, each time a message is to be sent, the complete array values need to be reloaded.
Question: is there a way to avoid this (only for the Encoding Sub)?
Code: | $regfile = "xm32e5def.dat"
$hwstack = 64
$swstack = 64
$framesize = 64
Dim Mcs_text As String * 17 , Mcs(16) As Byte At Mcs_text Overlay
Dim First_array(16) , Second_array(16) As Byte , I As Byte
For I = 1 To 16
First_array(i) = I
Next
Xteaencode First_array(1) , Mcs(1) , 16 ''this returns the encoded First_Array
End |
From the XTEA lib, the following excerpts appear to be relevant:
Code: | _Xtea_encode_repeat:
rcall _xtea_processV1
rcall _xtea_loadk
rcall _xtea_loadv0 ; load V0
rcall _xtea_add_res ; add to result
rcall _xtea_saveV0 ;save to V0 ; <--------- stores the final values back in the same array?
;.........
rcall _xtea_processv0
rcall _xtea_loadk
rcall _xtea_loadv1 ; load V1!
rcall _xtea_add_res ; add result to V1
rcall _xtea_saveV1 ; <--------- stores the final values back in the same array?
;.........
_xtea_savev0:
std y+0,r16
std y+1,r15
std y+2,r14
std y+3,r13
ret
_xtea_savev1:
std y+4,r16
std y+5,r15
std y+6,r14
std y+7,r13
ret
|
Is the answer simply to replace the "y" pointer with the RAM variable "Second_Array()" ?
Any help as to how to do this would be greatly appreciated.
[PS: for the sake a simplicity, the solution can be 'hard-wired' - if that easier to do.]
E
(BASCOM-AVR version : 2.0.8.3 ) |
|
Back to top |
|
|
laborratte
Joined: 27 Jul 2005 Posts: 299 Location: Berlin
|
Posted: Fri May 21, 2021 3:17 pm Post subject: |
|
|
Well, you could change the XTEA-Lib (or write your own) in a way that the routine will write in a second array and you have found the starting point.
But I wouldn't do it at all.
Simply copy your source array to the target array first and let XTEA run over the the second array like so:
Code: |
(...)
I = Memcopy(First_array(1) , Second_array(1), 16)
Xteaencode Second_array(1) , Mcs(1) , 16 ''this returns the encoded First_Array
(...)
|
Less headache, less potential issues and a very low cost in processortime: memcopy eats less than 0,8% of cycles compared to xteaencode in your example. |
|
Back to top |
|
|
enniom
Joined: 20 Oct 2009 Posts: 537
|
Posted: Fri May 21, 2021 4:32 pm Post subject: |
|
|
Thanks laborratte for the answer. Will use this approach for now.
Since this is a 2032 coin cell application (with about 200 mAh useable), every awake mSec consumes mAmps. The goal is not to consume any more power than necessary.
Maybe there is a better way of encoding secure messages?
E |
|
Back to top |
|
|
AdrianJ
Joined: 16 Jan 2006 Posts: 2483 Location: Queensland
|
Posted: Sat May 22, 2021 2:12 am Post subject: |
|
|
xtea has to have somewhere to do its operations, and the 'easiest' place is on the incoming array, and it does multiple operations on each byte. Even if you rewrote the xtea code, I seriously doubt it would be any faster, since it would have to move all the incoming bytes anyway. Memcopy is a very fast routine in any case. _________________ Adrian Jansen
Computer language is a framework for creativity |
|
Back to top |
|
|
enniom
Joined: 20 Oct 2009 Posts: 537
|
Posted: Sat May 22, 2021 3:52 pm Post subject: |
|
|
Thanks Adrian.
I briefly looked at the XTEA LIB - but it looks as if Mark's genius is at work here. Memcopy works well.
Next I'll test EDMA memory transfer to see if it can be done during a period of Config PowerMode = Idle.
E |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|