]> git.cryptolib.org Git - avr-crypto-lib.git/blobdiff - cubehash/cubehash.c
small tuning of cubehash
[avr-crypto-lib.git] / cubehash / cubehash.c
index 997378f912ef15f6ac318d85345bdbad3f802932..8b4a931093638c62d2719314e5bc012109ee8a9f 100644 (file)
 
 #include "memxor.h"
 #include "cubehash.h"
+#include "cubehash_rotates.h"
 #include <string.h>
 #include <stdint.h>
 
-static uint32_t rol32(uint32_t a, uint8_t r){
-       return (a<<r)|(a>>(32-r));
-}
 /*
 • Add    x_0jklm into    x_1jklm modulo 232 , for each (j, k, l, m).
 • Rotate x_0jklm upwards by 7 bits, for each (j, k, l, m).
@@ -52,31 +50,28 @@ static void cubehash_round(cubehash_ctx_t* ctx){
        uint32_t t;
        for(i=0; i<16; ++i){
                ctx->a[i+16] += ctx->a[i];
-       }
-       for(i=0; i<16; ++i){
-               ctx->a[i] = rol32(ctx->a[i], 7);
+               ctx->a[i] = rotate7left(ctx->a[i]);
        }
        for(i=0; i<8; ++i){
                t = ctx->a[i];
                ctx->a[i] = ctx->a[i+8];
                ctx->a[i+8] = t;
        }
-       for(i=0; i<16; ++i){
-               ctx->a[i] ^= ctx->a[i+16];
-       }
        for(i=16; i<4*4+16; i+=4){
                t = ctx->a[i];
-               ctx->a[i] = ctx->a[i+2];
-               ctx->a[i+2] = t;
+               ctx->a[i-16] ^= t;
+               ctx->a[i] = ctx->a[i+2] + ctx->a[i-16];
+               ctx->a[i-16] = rotate11left(ctx->a[i-16]);
+               ctx->a[i-14] ^= ctx->a[i+2];
+               ctx->a[i+2] = t + ctx->a[i-14];
+               ctx->a[i-14] = rotate11left(ctx->a[i-14]);
                t = ctx->a[i+1];
-               ctx->a[i+1] = ctx->a[i+3];
-               ctx->a[i+3] = t;
-       }
-       for(i=0; i<16; ++i){
-               ctx->a[i+16] += ctx->a[i];
-       }
-       for(i=0; i<16; ++i){
-               ctx->a[i] = rol32(ctx->a[i], 11);
+               ctx->a[i-15] ^= t;
+               ctx->a[i+1] = ctx->a[i+3] + ctx->a[i-15];
+               ctx->a[i-15] = rotate11left(ctx->a[i-15]);
+               ctx->a[i-13] ^= ctx->a[i+3];
+               ctx->a[i+3] = t + ctx->a[i-13];
+               ctx->a[i-13] = rotate11left(ctx->a[i-13]);
        }
        for(i=0; i<4; ++i){
                t = ctx->a[i];
@@ -88,12 +83,9 @@ static void cubehash_round(cubehash_ctx_t* ctx){
                ctx->a[i] = ctx->a[i+4];
                ctx->a[i+4] = t;
        }
-       for(i=0; i<16; ++i){
-               ctx->a[i] ^= ctx->a[i+16];
-       }
        for(i=16; i<16+16; i+=2){
-               t = ctx->a[i];
-               ctx->a[i] = ctx->a[i+1];
+               ctx->a[i-16] ^= t = ctx->a[i];
+               ctx->a[i-15] ^= ctx->a[i] = ctx->a[i+1];
                ctx->a[i+1] = t;
        }
 }