]> git.cryptolib.org Git - avr-crypto-lib.git/blobdiff - twister.c
big bug fixed, still some problems with flow control
[avr-crypto-lib.git] / twister.c
index 9eae239609c390d68a70e2b98ddab150f1230acc..c82e22ea5dec05a9373eb67f87ac338bb2e86796 100644 (file)
--- a/twister.c
+++ b/twister.c
@@ -1,6 +1,6 @@
 /* twister.c */
 /*
-    This file is part of the Crypto-avr-lib/microcrypt-lib.
+    This file is part of the AVR-Crypto-Lib.
     Copyright (C) 2008  Daniel Otte (daniel.otte@rub.de)
 
     This program is free software: you can redistribute it and/or modify
 #include "twister_tables.h"
 #include "memxor.h"
 
-#ifndef TWISTER_MUL_TABLE
+//#ifndef TWISTER_MUL_TABLE
 # include "gf256mul.h"
-#endif
-                                                                                                                                                                                                                                                               
-static
-void shiftrow(void* row, uint8_t shift){
-       *((uint64_t*)row) = *((uint64_t*)row)>>(8*shift) | *((uint64_t*)row)<<(64-8*shift);
-}
+//#endif
 
 #define MDS(a,b)  pgm_read_byte(&(twister_mds[(a)][(b)]))
 
-#ifdef TWISTER_MUL_TABLE
-# define MULT(a,b) pgm_read_byte(&(twister_multab[a][b]))
-#else
+//#ifdef TWISTER_MUL_TABLE
+//# define MULT(a,b) pgm_read_byte(&(twister_multab[(a)][(b)]))
+//#else
 # define MULT(a,b) gf256mul((a),(b), 0x4D)
-#endif
+//#endif
+
 void twister_blank_round(twister_state_t* ctx){
-       uint8_t i,j,k=0;
+       uint8_t i,j,k;
        uint8_t tmp[8][8];
        /* add twist counter */
        for(i=0; i<8; ++i){
@@ -55,30 +51,32 @@ void twister_blank_round(twister_state_t* ctx){
                        tmp[i][j] = pgm_read_byte(twister_sbox+ctx->s[i][j]);
                }
        }
-       /* shift rows */
-//     for(i=1;i<8; ++i){
-//             shiftrow(&(tmp[i][0]), i);
-//     }
-       /* mix columns */
+       /* mix columns with integrates shift rows */
        for( i=0; i<8; i++ ){
                // multiply with mds matrix
                for( j=0; j<8; j++ ){
                        k=(i+1)&7;
                        ctx->s[j][i] =
-                               MULT( MDS(j,0), tmp[0][i] ) ^
-                               MULT( MDS(j,1), tmp[1][k] ) ^
-                               MULT( MDS(j,2), tmp[2][(++k)&7] ) ^
-                               MULT( MDS(j,3), tmp[3][(++k)&7] ) ^
-                               MULT( MDS(j,4), tmp[4][(++k)&7] ) ^
-                               MULT( MDS(j,5), tmp[5][(++k)&7] ) ^
-                               MULT( MDS(j,6), tmp[6][(++k)&7] ) ^
-                               MULT( MDS(j,7), tmp[7][(++k)&7] ) ;
+                               MULT( MDS(j,0), (tmp[0][i]) );
+                       ctx->s[j][i] ^=  
+                               MULT( MDS(j,1), (tmp[1][k]) );
+                       ctx->s[j][i] ^=  
+                               MULT( MDS(j,2), (tmp[2][((++k)&7)]) );
+                       ctx->s[j][i] ^=  
+                               MULT( MDS(j,3), (tmp[3][((++k)&7)]) );
+                       ctx->s[j][i] ^=  
+                               MULT( MDS(j,4), (tmp[4][((++k)&7)]) );
+                       ctx->s[j][i] ^=  
+                               MULT( MDS(j,5), (tmp[5][((++k)&7)]) );
+                       ctx->s[j][i] ^=  
+                               MULT( MDS(j,6), (tmp[6][((++k)&7)]) );
+                       ctx->s[j][i] ^=  
+                               MULT( MDS(j,7), (tmp[7][((++k)&7)]) );
                                
                }       
        }
 }
-
-void twister_mini_round(twister_state_t* ctx, void* msg){
+void twister_mini_round(twister_state_t* ctx, const void* msg){
        /* inject message */
        uint8_t i;
        for(i=0; i<8; ++i){