X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;f=bmw%2Fbmw_small_speed.c;h=148b2f7535cd0d4704c09509ee89d9b08c21fe30;hb=f59c19cdaa2b415ea72a30083ee7df085c2a6ae9;hp=982cb13e83964dec3f011772e5420537585b3e14;hpb=5f46191d2615ebe2caa6e111b478031a34f20b9e;p=arm-crypto-lib.git diff --git a/bmw/bmw_small_speed.c b/bmw/bmw_small_speed.c index 982cb13..148b2f7 100644 --- a/bmw/bmw_small_speed.c +++ b/bmw/bmw_small_speed.c @@ -105,6 +105,7 @@ #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]); @@ -203,61 +204,34 @@ 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 void* 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]; - } +void bmw_small_f2(uint32_t* h, uint32_t* q, const uint32_t* m){ + 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); cli_putstr("\r\n XH = "); cli_hexdump_rev(&xh, 4); #endif - memcpy(h, m, 16*4); - h[0] ^= SHL32(xh, 5) ^ SHR32(q[16], 5); - h[1] ^= SHR32(xh, 7) ^ SHL32(q[17], 8); - h[2] ^= SHR32(xh, 5) ^ SHL32(q[18], 5); - h[3] ^= SHR32(xh, 1) ^ SHL32(q[19], 5); - h[4] ^= SHR32(xh, 3) ^ q[20]; - h[5] ^= SHL32(xh, 6) ^ SHR32(q[21], 6); - h[6] ^= SHR32(xh, 4) ^ SHL32(q[22], 6); - h[7] ^= SHR32(xh,11) ^ SHL32(q[23], 2); - for(i=0; i<8; ++i){ - h[i] += xl ^ q[24+i] ^ q[i]; - } - for(i=0; i<8; ++i){ - h[8+i] ^= xh ^ q[24+i]; - h[8+i] += ROTL32(h[(4+i)%8],i+9); - } -/* - h[ 8] += SHL32(xl, 8) ^ q[23] ^ q[ 8]; - h[ 9] += SHR32(xl, 6) ^ q[16] ^ q[ 9]; - h[10] += SHL32(xl, 6) ^ q[17] ^ q[10]; - h[11] += SHL32(xl, 4) ^ q[18] ^ q[11]; - h[12] += SHR32(xl, 3) ^ q[19] ^ q[12]; - h[13] += SHR32(xl, 4) ^ q[20] ^ q[13]; - h[14] += SHR32(xl, 7) ^ q[21] ^ q[14]; - h[15] += SHR32(xl, 2) ^ q[22] ^ q[15]; -*/ - i=6; - do{ - q[9+i] ^= q[16+i]; - }while(i--); - q[8] ^= q[23]; - h[ 8] += SHL32(xl, 8) ^ q[ 8]; - h[ 9] += SHR32(xl, 6) ^ q[ 9]; - h[10] += SHL32(xl, 6) ^ q[10]; - h[11] += SHL32(xl, 4) ^ q[11]; - h[12] += SHR32(xl, 3) ^ q[12]; - h[13] += SHR32(xl, 4) ^ q[13]; - h[14] += SHR32(xl, 7) ^ q[14]; - h[15] += SHR32(xl, 2) ^ q[15]; + + h[0] = (SHL32(xh, 5) ^ SHR32(q[16], 5) ^ m[ 0]) + (xl ^ q[24] ^ q[ 0]); + h[1] = (SHR32(xh, 7) ^ SHL32(q[17], 8) ^ m[ 1]) + (xl ^ q[25] ^ q[ 1]); + h[2] = (SHR32(xh, 5) ^ SHL32(q[18], 5) ^ m[ 2]) + (xl ^ q[26] ^ q[ 2]); + h[3] = (SHR32(xh, 1) ^ SHL32(q[19], 5) ^ m[ 3]) + (xl ^ q[27] ^ q[ 3]); + h[4] = (SHR32(xh, 3) ^ q[20] ^ m[ 4]) + (xl ^ q[28] ^ q[ 4]); + h[5] = (SHL32(xh, 6) ^ SHR32(q[21], 6) ^ m[ 5]) + (xl ^ q[29] ^ q[ 5]); + h[6] = (SHR32(xh, 4) ^ SHL32(q[22], 6) ^ m[ 6]) + (xl ^ q[30] ^ q[ 6]); + h[7] = (SHR32(xh,11) ^ SHL32(q[23], 2) ^ m[ 7]) + (xl ^ q[31] ^ q[ 7]); + + h[ 8] = ROTL32(h[4], 9) + (xh ^ q[24] ^ m[ 8]) + (SHL32(xl, 8) ^ q[23] ^ q[ 8]); + h[ 9] = ROTL32(h[5], 10) + (xh ^ q[25] ^ m[ 9]) + (SHR32(xl, 6) ^ q[16] ^ q[ 9]); + h[10] = ROTL32(h[6], 11) + (xh ^ q[26] ^ m[10]) + (SHL32(xl, 6) ^ q[17] ^ q[10]); + h[11] = ROTL32(h[7], 12) + (xh ^ q[27] ^ m[11]) + (SHL32(xl, 4) ^ q[18] ^ q[11]); + h[12] = ROTL32(h[0], 13) + (xh ^ q[28] ^ m[12]) + (SHR32(xl, 3) ^ q[19] ^ q[12]); + 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){