diff options
Diffstat (limited to 'drivers/isdn/mISDN/dsp_blowfish.c')
-rw-r--r-- | drivers/isdn/mISDN/dsp_blowfish.c | 112 |
1 files changed, 56 insertions, 56 deletions
diff --git a/drivers/isdn/mISDN/dsp_blowfish.c b/drivers/isdn/mISDN/dsp_blowfish.c index 18e411e..0aa572f 100644 --- a/drivers/isdn/mISDN/dsp_blowfish.c +++ b/drivers/isdn/mISDN/dsp_blowfish.c @@ -354,8 +354,8 @@ static const u32 bf_sbox[256 * 4] = { #define GET32_1(x) (((x) >> (16)) & (0xff)) #define GET32_0(x) (((x) >> (24)) & (0xff)) -#define bf_F(x) (((S[GET32_0(x)] + S[256 + GET32_1(x)]) ^ \ - S[512 + GET32_2(x)]) + S[768 + GET32_3(x)]) +#define bf_F(x) (((S[GET32_0(x)] + S[256 + GET32_1(x)]) ^ \ + S[512 + GET32_2(x)]) + S[768 + GET32_3(x)]) #define EROUND(a, b, n) do { b ^= P[n]; a ^= bf_F(b); } while (0) #define DROUND(a, b, n) do { a ^= bf_F(b); b ^= P[n]; } while (0) @@ -388,17 +388,17 @@ dsp_bf_encrypt(struct dsp *dsp, u8 *data, int len) j = 0; /* transcode 9 samples xlaw to 8 bytes */ yl = dsp_audio_law2seven[bf_data_in[0]]; - yl = (yl<<7) | dsp_audio_law2seven[bf_data_in[1]]; - yl = (yl<<7) | dsp_audio_law2seven[bf_data_in[2]]; - yl = (yl<<7) | dsp_audio_law2seven[bf_data_in[3]]; + yl = (yl << 7) | dsp_audio_law2seven[bf_data_in[1]]; + yl = (yl << 7) | dsp_audio_law2seven[bf_data_in[2]]; + yl = (yl << 7) | dsp_audio_law2seven[bf_data_in[3]]; nibble = dsp_audio_law2seven[bf_data_in[4]]; yr = nibble; - yl = (yl<<4) | (nibble>>3); - yr = (yr<<7) | dsp_audio_law2seven[bf_data_in[5]]; - yr = (yr<<7) | dsp_audio_law2seven[bf_data_in[6]]; - yr = (yr<<7) | dsp_audio_law2seven[bf_data_in[7]]; - yr = (yr<<7) | dsp_audio_law2seven[bf_data_in[8]]; - yr = (yr<<1) | (bf_data_in[0] & 1); + yl = (yl << 4) | (nibble >> 3); + yr = (yr << 7) | dsp_audio_law2seven[bf_data_in[5]]; + yr = (yr << 7) | dsp_audio_law2seven[bf_data_in[6]]; + yr = (yr << 7) | dsp_audio_law2seven[bf_data_in[7]]; + yr = (yr << 7) | dsp_audio_law2seven[bf_data_in[8]]; + yr = (yr << 1) | (bf_data_in[0] & 1); /* fill unused bit with random noise of audio input */ /* encrypt */ @@ -423,24 +423,24 @@ dsp_bf_encrypt(struct dsp *dsp, u8 *data, int len) yr ^= P[17]; /* calculate 3-bit checksumme */ - cs = yl ^ (yl>>3) ^ (yl>>6) ^ (yl>>9) ^ (yl>>12) ^ (yl>>15) - ^ (yl>>18) ^ (yl>>21) ^ (yl>>24) ^ (yl>>27) ^ (yl>>30) - ^ (yr<<2) ^ (yr>>1) ^ (yr>>4) ^ (yr>>7) ^ (yr>>10) - ^ (yr>>13) ^ (yr>>16) ^ (yr>>19) ^ (yr>>22) ^ (yr>>25) - ^ (yr>>28) ^ (yr>>31); + cs = yl ^ (yl >> 3) ^ (yl >> 6) ^ (yl >> 9) ^ (yl >> 12) ^ (yl >> 15) + ^ (yl >> 18) ^ (yl >> 21) ^ (yl >> 24) ^ (yl >> 27) ^ (yl >> 30) + ^ (yr << 2) ^ (yr >> 1) ^ (yr >> 4) ^ (yr >> 7) ^ (yr >> 10) + ^ (yr >> 13) ^ (yr >> 16) ^ (yr >> 19) ^ (yr >> 22) ^ (yr >> 25) + ^ (yr >> 28) ^ (yr >> 31); /* * transcode 8 crypted bytes to 9 data bytes with sync * and checksum information */ - bf_crypt_out[0] = (yl>>25) | 0x80; - bf_crypt_out[1] = (yl>>18) & 0x7f; - bf_crypt_out[2] = (yl>>11) & 0x7f; - bf_crypt_out[3] = (yl>>4) & 0x7f; - bf_crypt_out[4] = ((yl<<3) & 0x78) | ((yr>>29) & 0x07); - bf_crypt_out[5] = ((yr>>22) & 0x7f) | ((cs<<5) & 0x80); - bf_crypt_out[6] = ((yr>>15) & 0x7f) | ((cs<<6) & 0x80); - bf_crypt_out[7] = ((yr>>8) & 0x7f) | (cs<<7); + bf_crypt_out[0] = (yl >> 25) | 0x80; + bf_crypt_out[1] = (yl >> 18) & 0x7f; + bf_crypt_out[2] = (yl >> 11) & 0x7f; + bf_crypt_out[3] = (yl >> 4) & 0x7f; + bf_crypt_out[4] = ((yl << 3) & 0x78) | ((yr >> 29) & 0x07); + bf_crypt_out[5] = ((yr >> 22) & 0x7f) | ((cs << 5) & 0x80); + bf_crypt_out[6] = ((yr >> 15) & 0x7f) | ((cs << 6) & 0x80); + bf_crypt_out[7] = ((yr >> 8) & 0x7f) | (cs << 7); bf_crypt_out[8] = yr; } @@ -474,45 +474,45 @@ dsp_bf_decrypt(struct dsp *dsp, u8 *data, int len) * shift upper bit and rotate data to buffer ring * send current decrypted data */ - sync = (sync<<1) | ((*data)>>7); + sync = (sync << 1) | ((*data) >> 7); bf_crypt_inring[j++ & 15] = *data; *data++ = bf_data_out[k++]; i++; if (k == 9) k = 0; /* repeat if no sync has been found */ /* check if not in sync */ - if ((sync&0x1f0) != 0x100) + if ((sync & 0x1f0) != 0x100) continue; j -= 9; /* transcode receive data to 64 bit block of encrypted data */ yl = bf_crypt_inring[j++ & 15]; - yl = (yl<<7) | bf_crypt_inring[j++ & 15]; /* bit7 = 0 */ - yl = (yl<<7) | bf_crypt_inring[j++ & 15]; /* bit7 = 0 */ - yl = (yl<<7) | bf_crypt_inring[j++ & 15]; /* bit7 = 0 */ + yl = (yl << 7) | bf_crypt_inring[j++ & 15]; /* bit7 = 0 */ + yl = (yl << 7) | bf_crypt_inring[j++ & 15]; /* bit7 = 0 */ + yl = (yl << 7) | bf_crypt_inring[j++ & 15]; /* bit7 = 0 */ nibble = bf_crypt_inring[j++ & 15]; /* bit7 = 0 */ yr = nibble; - yl = (yl<<4) | (nibble>>3); + yl = (yl << 4) | (nibble >> 3); cs2 = bf_crypt_inring[j++ & 15]; - yr = (yr<<7) | (cs2 & 0x7f); + yr = (yr << 7) | (cs2 & 0x7f); cs1 = bf_crypt_inring[j++ & 15]; - yr = (yr<<7) | (cs1 & 0x7f); + yr = (yr << 7) | (cs1 & 0x7f); cs0 = bf_crypt_inring[j++ & 15]; - yr = (yr<<7) | (cs0 & 0x7f); - yr = (yr<<8) | bf_crypt_inring[j++ & 15]; + yr = (yr << 7) | (cs0 & 0x7f); + yr = (yr << 8) | bf_crypt_inring[j++ & 15]; /* calculate 3-bit checksumme */ - cs = yl ^ (yl>>3) ^ (yl>>6) ^ (yl>>9) ^ (yl>>12) ^ (yl>>15) - ^ (yl>>18) ^ (yl>>21) ^ (yl>>24) ^ (yl>>27) ^ (yl>>30) - ^ (yr<<2) ^ (yr>>1) ^ (yr>>4) ^ (yr>>7) ^ (yr>>10) - ^ (yr>>13) ^ (yr>>16) ^ (yr>>19) ^ (yr>>22) ^ (yr>>25) - ^ (yr>>28) ^ (yr>>31); + cs = yl ^ (yl >> 3) ^ (yl >> 6) ^ (yl >> 9) ^ (yl >> 12) ^ (yl >> 15) + ^ (yl >> 18) ^ (yl >> 21) ^ (yl >> 24) ^ (yl >> 27) ^ (yl >> 30) + ^ (yr << 2) ^ (yr >> 1) ^ (yr >> 4) ^ (yr >> 7) ^ (yr >> 10) + ^ (yr >> 13) ^ (yr >> 16) ^ (yr >> 19) ^ (yr >> 22) ^ (yr >> 25) + ^ (yr >> 28) ^ (yr >> 31); /* check if frame is valid */ - if ((cs&0x7) != (((cs2>>5)&4) | ((cs1>>6)&2) | (cs0 >> 7))) { + if ((cs & 0x7) != (((cs2 >> 5) & 4) | ((cs1 >> 6) & 2) | (cs0 >> 7))) { if (dsp_debug & DEBUG_DSP_BLOWFISH) printk(KERN_DEBUG - "DSP BLOWFISH: received corrupt frame, " - "checksumme is not correct\n"); + "DSP BLOWFISH: received corrupt frame, " + "checksumme is not correct\n"); continue; } @@ -537,17 +537,17 @@ dsp_bf_decrypt(struct dsp *dsp, u8 *data, int len) DROUND(yr, yl, 0); /* transcode 8 crypted bytes to 9 sample bytes */ - bf_data_out[0] = dsp_audio_seven2law[(yl>>25) & 0x7f]; - bf_data_out[1] = dsp_audio_seven2law[(yl>>18) & 0x7f]; - bf_data_out[2] = dsp_audio_seven2law[(yl>>11) & 0x7f]; - bf_data_out[3] = dsp_audio_seven2law[(yl>>4) & 0x7f]; - bf_data_out[4] = dsp_audio_seven2law[((yl<<3) & 0x78) | - ((yr>>29) & 0x07)]; - - bf_data_out[5] = dsp_audio_seven2law[(yr>>22) & 0x7f]; - bf_data_out[6] = dsp_audio_seven2law[(yr>>15) & 0x7f]; - bf_data_out[7] = dsp_audio_seven2law[(yr>>8) & 0x7f]; - bf_data_out[8] = dsp_audio_seven2law[(yr>>1) & 0x7f]; + bf_data_out[0] = dsp_audio_seven2law[(yl >> 25) & 0x7f]; + bf_data_out[1] = dsp_audio_seven2law[(yl >> 18) & 0x7f]; + bf_data_out[2] = dsp_audio_seven2law[(yl >> 11) & 0x7f]; + bf_data_out[3] = dsp_audio_seven2law[(yl >> 4) & 0x7f]; + bf_data_out[4] = dsp_audio_seven2law[((yl << 3) & 0x78) | + ((yr >> 29) & 0x07)]; + + bf_data_out[5] = dsp_audio_seven2law[(yr >> 22) & 0x7f]; + bf_data_out[6] = dsp_audio_seven2law[(yr >> 15) & 0x7f]; + bf_data_out[7] = dsp_audio_seven2law[(yr >> 8) & 0x7f]; + bf_data_out[8] = dsp_audio_seven2law[(yr >> 1) & 0x7f]; k = 0; /* start with new decoded frame */ } @@ -631,9 +631,9 @@ dsp_bf_init(struct dsp *dsp, const u8 *key, uint keylen) /* Actual subkey generation */ for (j = 0, i = 0; i < 16 + 2; i++) { temp = (((u32)key[j] << 24) | - ((u32)key[(j + 1) % keylen] << 16) | - ((u32)key[(j + 2) % keylen] << 8) | - ((u32)key[(j + 3) % keylen])); + ((u32)key[(j + 1) % keylen] << 16) | + ((u32)key[(j + 2) % keylen] << 8) | + ((u32)key[(j + 3) % keylen])); P[i] = P[i] ^ temp; j = (j + 4) % keylen; |