CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

XXTEA / Correct Block TEA need help porting to CCSC

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
iso9001



Joined: 02 Dec 2003
Posts: 262

View user's profile Send private message

XXTEA / Correct Block TEA need help porting to CCSC
PostPosted: Thu Mar 13, 2008 12:12 pm     Reply with quote

Hi,

I know there is are XTEA examples already here. But, I figured since the code was available I would switch to its successor Corrected Block TEA or XXTEA

The problem I'm having is I don't exactly understand what they are doing with 'n'. And why is has to be a signed int32


Code in C
Code:

/* #define MX (z>>5^y<<2) + (y>>3^z<<4)^(sum^y) + (k[p&3^e]^z) */
  #define MX  ( (((z>>5)^(y<<2))+((y>>3)^(z<<4)))^((sum^y)+(k[(p&3)^e]^z)) )
 
  long btea(long* v, long n, long* k) {
    unsigned long z /* = v[n-1] */, y=v[0], sum=0, e, DELTA=0x9e3779b9;
    long p, q ;
    if (n > 1) {          /* Coding Part */
      z=v[n-1];           /* Moved z=v[n-1] to here, else [[Segmentation fault|segfaults]] in decode when n < 0 */
      q = 6+52/n ;
      while (q-- > 0) {
        sum += DELTA;
        e = sum >> 2&3 ;
        for (p=0; p<n-1; p++) y = v[p+1], z = v[p] += MX;
        y = v[0];
        z = v[n-1] += MX;
      }
      return 0 ;
    } else if (n < -1) {  /* Decoding Part */
      n = -n ;
      q = 6+52/n ;
      sum = q*DELTA ;
      while (sum != 0) {
        e = sum>>2 & 3;
        for (p=n-1; p>0; p--) z = v[p-1], y = v[p] -= MX;
        z = v[n-1];
        y = v[0] -= MX;
        sum -= DELTA;
      }
      return 0;
    }
    return 1;
  }


Anyone care to explain so I can try and port this over ?
Thanks
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

Re: XXTEA / Correct Block TEA need help porting to CCSC
PostPosted: Fri Mar 14, 2008 7:58 am     Reply with quote

It does not appear reasonable that n needs to be signed int32 for the algorithm to work. Since it mostly is used to index an array, you would think that it must be limited in range, especially for small microcontroller implementations. Can you provide a link to the original source for this code so we can see how this one function fits into the larger picture?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group