]> git.cryptolib.org Git - avr-crypto-lib.git/blob - camellia_C.c
insereated GPLv3 stub
[avr-crypto-lib.git] / camellia_C.c
1 /* camellia_C.c */
2 /*
3     This file is part of the Crypto-avr-lib/microcrypt-lib.
4     Copyright (C) 2008  Daniel Otte (daniel.otte@rub.de)
5
6     This program is free software: you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation, either version 3 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19 /**
20  * 
21  * 
22  * 
23  * 
24  */
25  
26 #include <stdint.h>
27 #include <avr/io.h>
28 #include <avr/pgmspace.h>
29 #include "camellia.h"
30 #include "uart.h"
31 #include "debug.h"
32 #include <util/delay.h>
33  
34 /*****************************************************************************/
35
36 uint8_t rol(uint8_t a, uint8_t n){return ((a<<n) | (a>>(8-n)));}
37
38 /*****************************************************************************/
39
40 uint8_t ror(uint8_t a, uint8_t n){return ((a<<(8-n)) | (a>>n));}
41
42 /*****************************************************************************/
43
44 uint32_t rol32(uint32_t a, uint8_t n){
45         return ((a<<n)|(a>>(32-n)));
46 }
47
48 /*****************************************************************************/
49
50 uint64_t rol64(uint64_t a, uint8_t n){
51         return ((a<<n)|(a>>(64-n)));
52 }
53
54 /*****************************************************************************/
55  
56 uint8_t camellia_s1_table[256] PROGMEM = {
57         112, 130,  44, 236, 179,  39, 192, 229, 228, 133,  87,  53, 234,  12, 174,  65,
58          35, 239, 107, 147,  69,  25, 165,  33, 237,  14,  79,  78,  29, 101, 146, 189,
59         134, 184, 175, 143, 124, 235,  31, 206,  62,  48, 220,  95,  94, 197,  11,  26,
60         166, 225,  57, 202, 213,  71,  93,  61, 217,   1,  90, 214,  81,  86, 108,  77,
61         139,  13, 154, 102, 251, 204, 176,  45, 116,  18,  43,  32, 240, 177, 132, 153,
62         223,  76, 203, 194,  52, 126, 118,   5, 109, 183, 169,  49, 209,  23,   4, 215,
63          20,  88,  58,  97, 222,  27,  17,  28,  50,  15, 156,  22,  83,  24, 242,  34,
64         254,  68, 207, 178, 195, 181, 122, 145,  36,   8, 232, 168,  96, 252, 105,  80,
65         170, 208, 160, 125, 161, 137,  98, 151,  84,  91,  30, 149, 224, 255, 100, 210,
66          16, 196,   0,  72, 163, 247, 117, 219, 138,   3, 230, 218,   9,  63, 221, 148,
67         135,  92, 131,   2, 205,  74, 144,  51, 115, 103, 246, 243, 157, 127, 191, 226,
68          82, 155, 216,  38, 200,  55, 198,  59, 129, 150, 111,  75,  19, 190,  99,  46,
69         233, 121, 167, 140, 159, 110, 188, 142,  41, 245, 249, 182,  47, 253, 180,  89,
70         120, 152,   6, 106, 231,  70, 113, 186, 212,  37, 171,  66, 136, 162, 141, 250,
71         114,   7, 185,  85, 248, 238, 172,  10,  54,  73,  42, 104,  60,  56, 241, 164,
72          64,  40, 211, 123, 187, 201,  67, 193,  21, 227, 173, 244, 119, 199, 128, 158
73 };
74
75 /*****************************************************************************/
76
77 uint8_t camellia_s1(uint8_t b){
78         return pgm_read_byte_near(&(camellia_s1_table[b]));
79 }
80
81 /*****************************************************************************/
82
83 uint8_t camellia_s2(uint8_t b){
84         return rol(pgm_read_byte_near(&(camellia_s1_table[b])),1);
85 }
86
87 /*****************************************************************************/
88
89 uint8_t camellia_s3(uint8_t b){
90         return ror(pgm_read_byte_near(&(camellia_s1_table[b])),1);
91 }
92
93 /*****************************************************************************/
94
95 uint8_t camellia_s4(uint8_t b){
96         return pgm_read_byte_near(&(camellia_s1_table[rol(b,1)]));
97 }
98
99 /*****************************************************************************/
100
101 uint64_t camellia_s(uint64_t d){
102 //      uart_putstr("\n\r S von "); uart_hexdump(&(d), 8);
103         #define D ((uint8_t*)(&d))
104         D[7] = camellia_s1(D[7]);
105         D[6] = camellia_s2(D[6]);
106         D[5] = camellia_s3(D[5]);
107         D[4] = camellia_s4(D[4]);
108         
109         D[3] = camellia_s2(D[3]);
110         D[2] = camellia_s3(D[2]);
111         D[1] = camellia_s4(D[1]);
112         D[0] = camellia_s1(D[0]);
113         #undef D
114 //      uart_putstr(" ist "); uart_hexdump(&(d), 8);
115         return d;
116 }
117
118 /*****************************************************************************/
119
120 uint64_t camellia_p(uint64_t d){
121         uint64_t z=0;
122         #define D ((uint8_t*)(&d))
123         #define Z ((uint8_t*)(&z))
124 /*
125         Z[0] = D[4] ^ D[3] ^ D[1];
126         Z[1] = D[5] ^ D[0] ^ D[2];
127         Z[2] = D[6] ^ D[1] ^ D[3];
128         Z[3] = D[7] ^ D[2] ^ D[0];
129         Z[4] = D[0] ^ D[6] ^ D[5];
130         Z[5] = D[1] ^ D[7] ^ D[6];
131         Z[6] = D[2] ^ D[4] ^ D[7];
132         Z[7] = D[3] ^ D[5] ^ D[4];
133 */
134 //      Z[7] = z1 z3 z4 z6 z7 z8
135 //      uart_putstr("\n\r P von "); uart_hexdump(&(d), 8);
136         
137         Z[7] = D[7] ^        D[5] ^ D[4] ^        D[2] ^ D[1] ^ D[0];
138         Z[6] = D[7] ^ D[6]        ^ D[4] ^ D[3] ^        D[1] ^ D[0];
139         Z[5] = D[7] ^ D[6] ^ D[5] ^        D[3] ^ D[2] ^        D[0];
140         Z[4] =        D[6] ^ D[5] ^ D[4] ^ D[3] ^ D[2] ^ D[1]       ;
141         Z[3] = D[7] ^ D[6] ^                      D[2] ^ D[1] ^ D[0];
142         Z[2] =        D[6] ^ D[5] ^        D[3] ^        D[1] ^ D[0];
143         Z[1] =               D[5] ^ D[4] ^ D[3] ^ D[2] ^        D[0];
144         Z[0] = D[7] ^               D[4] ^ D[3] ^ D[2] ^ D[1]       ;
145         
146 //      uart_putstr(" ist "); uart_hexdump(&(z), 8);
147                         
148         #undef Z
149         #undef D
150         return z;
151 }
152
153 /*****************************************************************************/
154
155 uint64_t camellia_f(uint64_t x, uint64_t k){
156         uint64_t y;
157         y = camellia_p(camellia_s(x ^ k));
158 /*
159         uart_putstr("\r\nEfunc X=");
160         uart_hexdump(&(x), 8);
161         uart_putstr("  K=");
162         uart_hexdump(&(k), 8);
163         uart_putstr("  Y=");
164         uart_hexdump(&(y), 8);
165 */      
166         return y;
167 }
168
169 /*****************************************************************************/
170
171 uint64_t camellia_fl(uint64_t x, uint64_t k){
172         volatile uint64_t lx[1], lk[1], y[1];
173         lx[0]=x; lk[0] = k; 
174         
175         #define Y ((uint32_t*)y)
176         #define X ((uint32_t*)lx)
177         #define K ((uint32_t*)lk)
178
179         Y[0] = rol32((X[1]) & K[1],1) ^ (X[0]); /* Yr */
180         Y[1] = (Y[0] | K[0]) ^ (X[1]);                  /* Yl */
181         
182 /*      
183         uart_putstr("\r\nFL(");
184         uart_hexdump(&(x), 8);
185         uart_putstr(", ");
186         uart_hexdump(&(k), 8);
187         uart_putstr(") = ");
188         uart_hexdump(y, 8);
189 */
190         #undef K
191         #undef X
192         #undef Y
193         return y[0];    
194 }
195
196 /*****************************************************************************/
197
198 uint64_t camellia_fl_inv(uint64_t y, uint64_t k){
199 //volatile      uint32_t xl, xr;
200         volatile uint64_t ly[1], lk[1], x[1];
201         ly[0]=y; lk[0] = k; 
202         #define Y ((uint32_t*)ly) 
203         #define X ((uint32_t*)x) 
204         #define K ((uint32_t*)lk) 
205         
206         X[1]=(Y[0] | K[0]) ^ Y[1];
207         X[0]=rol32((X[1] & K[1]),1) ^ Y[0];
208         
209 /*      
210         uart_putstr("\r\nFL_inv(");
211         uart_hexdump(&(y), 8);
212         uart_putstr(", ");
213         uart_hexdump(&(k), 8);
214         uart_putstr(") = ");
215 */      
216         #undef K
217         #undef X
218         #undef Y
219         return x[0];    
220 }
221
222 /*****************************************************************************/
223
224 uint64_t camellia_sigma[6]={
225         0xA09E667F3BCC908BLL,
226         0xB67AE8584CAA73B2LL,
227         0xC6EF372FE94F82BELL,
228         0x54FF53A5F1D36F1CLL,
229         0x10E527FADE682D1DLL,
230         0xB05688C2B3E6C1FDLL
231 };      
232
233 /*****************************************************************************/
234
235 void camellia128_ctx_dump(camellia128_ctx_t *s){
236         uart_putstr("\r\n==State Dump==");
237         uart_putstr("\n\rKAl: "); uart_hexdump(&(s->kal), 8);
238         uart_putstr("\n\rKAr: "); uart_hexdump(&(s->kar), 8);
239         uart_putstr("\n\rKLl: "); uart_hexdump(&(s->kll), 8);
240         uart_putstr("\n\rKLr: "); uart_hexdump(&(s->klr), 8);   
241         return;
242 }
243
244 /*****************************************************************************/
245
246 void camellia128_init(camellia128_ctx_t* s, uint8_t* key){
247         uint8_t i;
248         s->kll = 0; //((uint64_t*)key)[0];
249         
250         /* load the key, endian-adjusted, to kll,klr */
251         for(i=0; i<8; ++i){
252                 s->kll <<= 8;
253                 s->kll |= *key++;
254         }
255         for(i=0; i<8; ++i){
256                 s->klr <<= 8;
257                 s->klr |= *key++;
258         }
259         
260         s->kal = s->kll;
261         s->kar = s->klr;
262         
263         s->kar ^= camellia_f(s->kal, camellia_sigma[0]);
264         s->kal ^= camellia_f(s->kar, camellia_sigma[1]);
265         
266         s->kal ^= s->kll;
267         s->kar ^= s->klr;
268         
269         s->kar ^= camellia_f(s->kal, camellia_sigma[2]);
270         s->kal ^= camellia_f(s->kar, camellia_sigma[3]);
271         /**/
272 //      uart_putstr("\n\r----------------init finished--------------------");
273 }
274
275 /*****************************************************************************/
276
277 void camellia128_keyop(camellia128_ctx_t* s, int8_t q){
278         /* first we do 16 bit left-rols for kl and ka (128bit each) */
279         uint32_t temp;
280         
281         temp = (s->kal)>>(64-16-q);
282         s->kal = s->kal<<(16+q) | s->kar>>(64-16-q);
283         s->kar = s->kar<<(16+q) | temp;
284         
285         temp = (s->kll)>>(64-16-q);
286         s->kll = s->kll<<(16+q) | s->klr>>(64-16-q);
287         s->klr = s->klr<<(16+q) | temp;
288         /* after doing the 16-bit rol we have to rol 1 bit left or rigth depending on q */
289 }
290
291 /*****************************************************************************/
292
293 void camellia128_keyop_inv(camellia128_ctx_t* s, int8_t q){
294         /* first we do 16 bit right-rols for kl and ka (128bit each) */
295         uint32_t temp;
296         
297         temp = (s->kar)&(0xffffff>>(24-16-q));
298         s->kar = s->kar>>(16+q) | s->kal<<(64-16-q);
299         s->kal = s->kal>>(16+q) | ((uint64_t)temp)<<(64-16-q);
300         
301         temp = (s->klr)&(0xffffff>>(24-16-q));
302         s->klr = s->klr>>(16+q) | s->kll<<(64-16-q);
303         s->kll = s->kll>>(16+q) | ((uint64_t)temp)<<(64-16-q);
304         /* after doing the 16-bit rol we have to rol 1 bit left or rigth depending on q */
305 }
306
307 /*****************************************************************************/
308
309 #define SEL_KA 1
310 #define SEL_KL 0
311
312 #define KEY_POSTC1              0x00
313 #define KEY_POSTC2              0x01
314 #define KEY_INC2                0x02
315
316 #define KEY_DIR                 0x04
317 #define KEY_DIR_NORM    0x00
318 #define KEY_DIR_INV             0x04
319
320 #define KEY_AMMOUNT             0x08 
321 #define KEY_ROL17               0x08
322 #define KEY_ROL15               0x00
323
324 void camellia_6rounds(camellia128_ctx_t* s, uint64_t* bl, uint64_t* br, uint8_t roundop, uint8_t keychoice){
325         uint8_t i;
326         uint64_t* k[4];
327         k[0] = &(s->kll);
328         k[1] = &(s->klr);
329         k[2] = &(s->kal);
330         k[3] = &(s->kar);
331         for(i=0; i<3; ++i){ /* each cycle */
332                 br[0] ^= camellia_f(bl[0],*(k[(keychoice&1)*2+((roundop&KEY_DIR)?1:0)]));
333                 keychoice >>= 1;
334                 
335                 if((i == 1) && (roundop&KEY_INC2)){
336                         ((roundop&KEY_DIR)?camellia128_keyop_inv:camellia128_keyop)(s,(roundop&KEY_AMMOUNT)?1:-1);
337                 }
338                 
339                 bl[0] ^= camellia_f(br[0],*(k[(keychoice&1)*2+((roundop&KEY_DIR)?0:1)]));
340                 keychoice >>= 1;
341                 
342                 /* check if we should do some keyop */
343                 if((i == (roundop&1)) && (!(roundop&KEY_INC2)) ){
344                         ((roundop&KEY_DIR)?camellia128_keyop_inv:camellia128_keyop)(s,(roundop&KEY_AMMOUNT)?1:-1);
345                         /* isn't it fuckin nice what we can do in C?! */
346                 }
347         }
348 }
349
350 /*****************************************************************************/
351
352
353 void camellia128_enc(camellia128_ctx_t* s, void* block){
354
355         #define BL (((uint64_t*)block)[0])
356         #define BR (((uint64_t*)block)[1])
357         /* endian adjustment */
358          /*BL*/
359          /*     1 2 3 4 5 6 7 8
360           *             8 7 6 5 4 3 2 1
361           */
362          
363         uint64_t temp64;
364
365         temp64 = BL;
366         BL = temp64 >> 56 | temp64 << 56  /* swap the most out bytes (1 & 8) */
367                 | (temp64 & (0xffLL<<48))>>(5*8) | (temp64 & (0xffLL<< 8))<<(5*8) /* 2 & 7 */
368                 | (temp64 & (0xffLL<<40))>>(3*8) | (temp64 & (0xffLL<<16))<<(3*8) /* 3 & 6 */           
369                 | (temp64 & (0xffLL<<32))>>(1*8) | (temp64 & (0xffLL<<24))<<(1*8); /* 4 & 5 */
370         temp64 = BR;
371         BR = temp64 >> 56 | temp64 << 56  /* swap the most out bytes (1 & 8) */
372                 | (temp64 & (0xffLL<<48))>>(5*8) | (temp64 & (0xffLL<< 8))<<(5*8) /* 2 & 7 */
373                 | (temp64 & (0xffLL<<40))>>(3*8) | (temp64 & (0xffLL<<16))<<(3*8) /* 3 & 6 */           
374                 | (temp64 & (0xffLL<<32))>>(1*8) | (temp64 & (0xffLL<<24))<<(1*8); /* 4 & 5 */
375         
376         /* Prewhitening */
377         BL ^= s->kll;
378         BR ^= s->klr;
379         
380         /* the first 6 */
381 /*      
382         BR ^= camellia_f(BL, s->kal);
383         BL ^= camellia_f(BR, s->kar);
384    camellia128_keyop(s, -1);
385         BR ^= camellia_f(BL, s->kll);
386         BL ^= camellia_f(BR, s->klr);
387         BR ^= camellia_f(BL, s->kal);
388         BL ^= camellia_f(BR, s->kar);
389 */
390         camellia_6rounds(s, &BL, &BR, KEY_ROL15 | KEY_DIR_NORM | KEY_POSTC1 , 0x33);
391         /* FL injection  */
392    camellia128_keyop(s, -1);
393         BL = camellia_fl(BL, s->kal);
394         BR = camellia_fl_inv(BR, s->kar);
395    camellia128_keyop(s, -1);
396         /* middle 6 */
397 /*      BR ^= camellia_f(BL, s->kll);
398         BL ^= camellia_f(BR, s->klr);
399         BR ^= camellia_f(BL, s->kal);
400    camellia128_keyop(s, -1);
401         BL ^= camellia_f(BR, s->klr);
402         BR ^= camellia_f(BL, s->kal);
403         BL ^= camellia_f(BR, s->kar);
404 /*/
405         camellia_6rounds(s, &BL, &BR, KEY_ROL15 | KEY_DIR_NORM | KEY_INC2 , 0x34);
406         /* FL injection  */
407    camellia128_keyop(s, 1);
408         BL = camellia_fl(BL, s->kll);
409         BR = camellia_fl_inv(BR, s->klr);
410    camellia128_keyop(s, 1);
411    /* last 6 */
412 /*      BR ^= camellia_f(BL, s->kll);
413         BL ^= camellia_f(BR, s->klr);
414         BR ^= camellia_f(BL, s->kal);
415         BL ^= camellia_f(BR, s->kar);
416    camellia128_keyop(s, 1);
417   
418         BR ^= camellia_f(BL, s->kll);
419         BL ^= camellia_f(BR, s->klr);
420 */
421         camellia_6rounds(s, &BL, &BR, KEY_ROL17 | KEY_DIR_NORM | KEY_POSTC2 , 0x0C);
422         /* Postwhitening */
423         BR ^= s->kal;
424         BL ^= s->kar;
425         
426         temp64 = BR;
427         BR = BL;
428         BL = temp64;
429
430         
431         BL = temp64 >> 56 | temp64 << 56  /* swap the most out bytes (1 & 8) */
432                 | (temp64 & (0xffLL<<48))>>(5*8) | (temp64 & (0xffLL<< 8))<<(5*8) /* 2 & 7 */
433                 | (temp64 & (0xffLL<<40))>>(3*8) | (temp64 & (0xffLL<<16))<<(3*8) /* 3 & 6 */           
434                 | (temp64 & (0xffLL<<32))>>(1*8) | (temp64 & (0xffLL<<24))<<(1*8); /* 4 & 5 */
435         temp64 = BR;
436         BR = temp64 >> 56 | temp64 << 56  /* swap the most out bytes (1 & 8) */
437                 | (temp64 & (0xffLL<<48))>>(5*8) | (temp64 & (0xffLL<< 8))<<(5*8) /* 2 & 7 */
438                 | (temp64 & (0xffLL<<40))>>(3*8) | (temp64 & (0xffLL<<16))<<(3*8) /* 3 & 6 */           
439                 | (temp64 & (0xffLL<<32))>>(1*8) | (temp64 & (0xffLL<<24))<<(1*8); /* 4 & 5 */
440                 
441         #undef BL
442         #undef BR       
443 }
444
445 /*****************************************************************************/
446
447 void camellia128_dec(camellia128_ctx_t* s, void* block){
448
449         #define BL (((uint64_t*)block)[1])
450         #define BR (((uint64_t*)block)[0])
451         /* endian adjustment */
452          /*BL*/
453          /*     1 2 3 4 5 6 7 8
454           *             8 7 6 5 4 3 2 1
455           */
456          
457         uint64_t temp64;
458         
459         temp64 = BL;
460
461         BL = temp64 >> 56 | temp64 << 56  /* swap the most out bytes (1 & 8) */
462                 | (temp64 & (0xffLL<<48))>>(5*8) | (temp64 & (0xffLL<< 8))<<(5*8) /* 2 & 7 */
463                 | (temp64 & (0xffLL<<40))>>(3*8) | (temp64 & (0xffLL<<16))<<(3*8) /* 3 & 6 */           
464                 | (temp64 & (0xffLL<<32))>>(1*8) | (temp64 & (0xffLL<<24))<<(1*8); /* 4 & 5 */
465         temp64 = BR;
466         BR = temp64 >> 56 | temp64 << 56  /* swap the most out bytes (1 & 8) */
467                 | (temp64 & (0xffLL<<48))>>(5*8) | (temp64 & (0xffLL<< 8))<<(5*8) /* 2 & 7 */
468                 | (temp64 & (0xffLL<<40))>>(3*8) | (temp64 & (0xffLL<<16))<<(3*8) /* 3 & 6 */           
469                 | (temp64 & (0xffLL<<32))>>(1*8) | (temp64 & (0xffLL<<24))<<(1*8); /* 4 & 5 */
470                 
471         camellia128_keyop_inv(s, 1);
472         /* Prewhitening */
473         BR ^= s->kal; /* kw3 */
474         BL ^= s->kar; /* kw4 */
475
476         /* the first 6 */
477 /*      
478         BL ^= camellia_f(BR, s->klr); /* k18 * /
479         BR ^= camellia_f(BL, s->kll); /* k17 * /
480    camellia128_keyop_inv(s, 1);
481         BL ^= camellia_f(BR, s->kar);
482         BR ^= camellia_f(BL, s->kal);
483         BL ^= camellia_f(BR, s->klr);
484         BR ^= camellia_f(BL, s->kll);
485 */
486         camellia_6rounds(s, &BR, &BL, KEY_ROL17 | KEY_DIR_INV | KEY_POSTC1 , 0x0C);
487
488         /* FL injection  */
489    camellia128_keyop_inv(s, 1);
490         BR = camellia_fl(BR, s->klr);
491         BL = camellia_fl_inv(BL, s->kll);
492    camellia128_keyop_inv(s, 1);
493         /* middle 6 */  
494 /*      BL ^= camellia_f(BR, s->kar);
495         BR ^= camellia_f(BL, s->kal);
496         BL ^= camellia_f(BR, s->klr);
497    camellia128_keyop_inv(s, -1);
498         BR ^= camellia_f(BL, s->kal);
499         BL ^= camellia_f(BR, s->klr);
500         BR ^= camellia_f(BL, s->kll);
501 */
502         camellia_6rounds(s, &BR, &BL, KEY_ROL15 | KEY_DIR_INV | KEY_INC2 , 0x0B);
503
504         /* FL injection  */
505    camellia128_keyop_inv(s, -1);
506         BR = camellia_fl(BR, s->kar);
507         BL = camellia_fl_inv(BL, s->kal);
508    camellia128_keyop_inv(s, -1);
509    /* last 6 */
510 /*   
511         BL ^= camellia_f(BR, s->kar);
512         BR ^= camellia_f(BL, s->kal);
513         BL ^= camellia_f(BR, s->klr);
514         BR ^= camellia_f(BL, s->kll);
515    camellia128_keyop_inv(s, -1);
516         BL ^= camellia_f(BR, s->kar);
517         BR ^= camellia_f(BL, s->kal);
518 /*/
519         camellia_6rounds(s, &BR, &BL, KEY_ROL15 | KEY_DIR_INV | KEY_POSTC2 , 0x33);
520         
521         /* Postwhitening */
522         BL ^= s->kll; /* kw1 */ 
523         BR ^= s->klr; /* kw2 */
524         
525         temp64 = BR;
526         BR = BL;
527         BL = temp64;
528
529         
530         BL = temp64 >> 56 | temp64 << 56  /* swap the most out bytes (1 & 8) */
531                 | (temp64 & (0xffLL<<48))>>(5*8) | (temp64 & (0xffLL<< 8))<<(5*8) /* 2 & 7 */
532                 | (temp64 & (0xffLL<<40))>>(3*8) | (temp64 & (0xffLL<<16))<<(3*8) /* 3 & 6 */           
533                 | (temp64 & (0xffLL<<32))>>(1*8) | (temp64 & (0xffLL<<24))<<(1*8); /* 4 & 5 */
534         temp64 = BR;
535         BR = temp64 >> 56 | temp64 << 56  /* swap the most out bytes (1 & 8) */
536                 | (temp64 & (0xffLL<<48))>>(5*8) | (temp64 & (0xffLL<< 8))<<(5*8) /* 2 & 7 */
537                 | (temp64 & (0xffLL<<40))>>(3*8) | (temp64 & (0xffLL<<16))<<(3*8) /* 3 & 6 */           
538                 | (temp64 & (0xffLL<<32))>>(1*8) | (temp64 & (0xffLL<<24))<<(1*8); /* 4 & 5 */
539                 
540 }
541
542 /*****************************************************************************/
543 /*****************************************************************************/
544
545
546
547 /* EOF */