]> git.cryptolib.org Git - arm-crypto-lib.git/blobdiff - bmw/bmw_small_speed.c
some importannt files
[arm-crypto-lib.git] / bmw / bmw_small_speed.c
index a2265872dccf68673e76450c63779587d1c4f066..148b2f7535cd0d4704c09509ee89d9b08c21fe30 100644 (file)
 #define R32_5(x)   (ROTR32((x), 13))
 #define R32_6(x)   (ROTR32((x),  9))
 #define R32_7(x)   (ROTR32((x),  5))
+
 /*
 #define K 0x05555555L
 static
@@ -166,21 +167,21 @@ void bmw_small_f0(uint32_t* q, uint32_t* h, const void* m){
        }while(i--);
        dump_x(h, 16, 'T');
        q[ 0] = (h[ 5] - h[ 7] + h[10] + h[13] + h[14]);
-       q[ 1] = (h[ 6] - h[ 8] + h[11] + h[14] - h[15]);
-       q[ 2] = (h[ 0] + h[ 7] + h[ 9] - h[12] + h[15]);
        q[ 3] = (h[ 0] - h[ 1] + h[ 8] - h[10] + h[13]);
-       q[ 4] = (h[ 1] + h[ 2] + h[ 9] - h[11] - h[14]);
-       q[ 5] = (h[ 3] - h[ 2] + h[10] - h[12] + h[15]);
        q[ 6] = (h[ 4] - h[ 0] - h[ 3] - h[11] + h[13]);
-       q[ 7] = (h[ 1] - h[ 4] - h[ 5] - h[12] - h[14]);
-       q[ 8] = (h[ 2] - h[ 5] - h[ 6] + h[13] - h[15]);
        q[ 9] = (h[ 0] - h[ 3] + h[ 6] - h[ 7] + h[14]);
-       q[10] = (h[ 8] - h[ 1] - h[ 4] - h[ 7] + h[15]);
-       q[11] = (h[ 8] - h[ 0] - h[ 2] - h[ 5] + h[ 9]);
        q[12] = (h[ 1] + h[ 3] - h[ 6] - h[ 9] + h[10]);
-       q[13] = (h[ 2] + h[ 4] + h[ 7] + h[10] + h[11]);
-       q[14] = (h[ 3] - h[ 5] + h[ 8] - h[11] - h[12]);
        q[15] = (h[12] - h[ 4] - h[ 6] - h[ 9] + h[13]);
+       q[ 2] = (h[ 0] + h[ 7] + h[ 9] - h[12] + h[15]);
+       q[ 5] = (h[ 3] - h[ 2] + h[10] - h[12] + h[15]);
+       q[ 8] = (h[ 2] - h[ 5] - h[ 6] + h[13] - h[15]);
+       q[11] = (h[ 8] - h[ 0] - h[ 2] - h[ 5] + h[ 9]);
+       q[14] = (h[ 3] - h[ 5] + h[ 8] - h[11] - h[12]);
+       q[ 1] = (h[ 6] - h[ 8] + h[11] + h[14] - h[15]);
+       q[ 4] = (h[ 1] + h[ 2] + h[ 9] - h[11] - h[14]);
+       q[ 7] = (h[ 1] - h[ 4] - h[ 5] - h[12] - h[14]);
+       q[10] = (h[ 8] - h[ 1] - h[ 4] - h[ 7] + h[15]);
+       q[13] = (h[ 2] + h[ 4] + h[ 7] + h[10] + h[11]);
        dump_x(q, 16, 'W');
        q[ 0] = S32_0(q[ 0]); q[ 1] = S32_1(q[ 1]); q[ 2] = S32_2(q[ 2]); q[ 3] = S32_3(q[ 3]); q[ 4] = S32_4(q[ 4]);
        q[ 5] = S32_0(q[ 5]); q[ 6] = S32_1(q[ 6]); q[ 7] = S32_2(q[ 7]); q[ 8] = S32_3(q[ 8]); q[ 9] = S32_4(q[ 9]);
@@ -204,15 +205,9 @@ void bmw_small_f1(uint32_t* q, const void* m, const void* h){
 
 static
 void bmw_small_f2(uint32_t* h, uint32_t* q, const uint32_t* m){
-       uint32_t xl=0, xh;
-       uint8_t i;
-       for(i=16;i<24;++i){
-               xl ^= q[i];
-       }
-       xh = xl;
-       for(i=24;i<32;++i){
-               xh ^= q[i];
-       }
+       uint32_t xl, xh;
+       xl =      q[16] ^ q[17] ^ q[18] ^ q[19] ^ q[20] ^ q[21] ^ q[22] ^ q[23];
+       xh = xl ^ q[24] ^ q[25] ^ q[26] ^ q[27] ^ q[28] ^ q[29] ^ q[30] ^ q[31];
 #if DEBUG
        cli_putstr("\r\n XL = ");
        cli_hexdump_rev(&xl, 4);
@@ -237,7 +232,6 @@ void bmw_small_f2(uint32_t* h, uint32_t* q, const uint32_t* m){
        h[13] = ROTL32(h[1], 14) + (xh ^ q[29] ^ m[13]) + (SHR32(xl, 4) ^ q[20] ^ q[13]);
        h[14] = ROTL32(h[2], 15) + (xh ^ q[30] ^ m[14]) + (SHR32(xl, 7) ^ q[21] ^ q[14]);
        h[15] = ROTL32(h[3], 16) + (xh ^ q[31] ^ m[15]) + (SHR32(xl, 2) ^ q[22] ^ q[15]);
-
 }
 
 void bmw_small_nextBlock(bmw_small_ctx_t* ctx, const void* block){