--- src/parallella_bf_fmt.c.orig 2013-07-16 11:04:39.417335815 +0000 +++ src/parallella_bf_fmt.c 2013-07-16 14:18:24.645126404 +0000 @@ -29,7 +29,7 @@ #define PLAINTEXT_LENGTH 72 #define CIPHERTEXT_LENGTH 60 -#define BINARY_SIZE 4 +#define BINARY_SIZE 8 #define BINARY_ALIGN 4 #define SALT_SIZE 22+7 #define SALT_ALIGN 4 @@ -52,7 +52,7 @@ typedef ARCH_WORD_32 BF_word; /* * Binary ciphertext type. */ -typedef BF_word BF_binary[6]; +typedef BF_word BF_binary[2]; typedef struct { @@ -369,7 +369,9 @@ static int cmp_all(void *binary, int cou static int cmp_one(void *binary, int index) { - return *(BF_word *)binary == parallella_BF_out[index][0]; + return + ((BF_word *)binary)[0] == parallella_BF_out[index][0] && + ((BF_word *)binary)[1] == parallella_BF_out[index][1]; } static int cmp_exact(char *source, int index) @@ -381,10 +383,8 @@ void *parallella_BF_std_get_binary(char { static BF_binary binary; - binary[5] = 0; - BF_decode(binary, &ciphertext[29], 23); - BF_swap(binary, 6); - binary[5] &= ~(BF_word)0xFF; + BF_decode(binary, &ciphertext[29], 8); + BF_swap(binary, 2); return &binary; } --- src/parallella_e_bcrypt.c.orig 2013-07-16 11:04:39.097056025 +0000 +++ src/parallella_e_bcrypt.c 2013-07-16 15:06:12.951716900 +0000 @@ -61,7 +61,7 @@ typedef uint32_t BF_word; typedef int32_t BF_word_signed; -typedef BF_word BF_binary[6]; +typedef BF_word BF_binary[2]; typedef struct { @@ -396,7 +396,7 @@ static const unsigned char BF_atoi64[0x6 (dst) = tmp; \ } -static int BF_decode(BF_word *dst, const char *src, int size) +static inline int BF_decode(BF_word *dst, const char *src, int size) { unsigned char *dptr = (unsigned char *)dst; unsigned char *end = dptr + size; @@ -420,6 +420,7 @@ static int BF_decode(BF_word *dst, const return 0; } +#if 0 static void BF_encode(char *dst, const BF_word *src, int size) { const unsigned char *sptr = (const unsigned char *)src; @@ -451,8 +452,9 @@ static void BF_encode(char *dst, const B *dptr++ = BF_itoa64[c2 & 0x3f]; } while (sptr < end); } +#endif -static void BF_swap(BF_word *x, int count) +static inline void BF_swap(BF_word *x, int count) { if ((union { int i; char c; }){1}.c) do { @@ -525,7 +527,7 @@ static BF_word BF_encrypt(BF_ctx *ctx, return L; } -static void BF_set_key(const char *key, BF_key expanded, BF_key initial, +static inline void BF_set_key(const char *key, BF_key expanded, BF_key initial, unsigned char flags) { const char *ptr = key; @@ -626,7 +628,7 @@ static void BF_set_key(const char *key, initial[0] ^= sign; } -static void *BF_crypt(const char *key, const char *setting, BF_word min) +static inline void *BF_crypt(const char *key, const char *setting) { static const unsigned char flags_by_subtype[26] = {2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -636,14 +638,14 @@ static void *BF_crypt(const char *key, c BF_key expanded_key; union { BF_word salt[4]; - BF_word output[6]; + BF_word output[2]; } binary; } data; BF_word count; int i; count = (BF_word)1 << ((setting[4] - '0') * 10 + (setting[5] - '0')); - if (count < min || BF_decode(data.binary.salt, &setting[7], 16)) { + if (count < 16 || BF_decode(data.binary.salt, &setting[7], 16)) { return NULL; } BF_swap(data.binary.salt, 4); @@ -678,10 +680,24 @@ static void *BF_crypt(const char *key, c do { int done; - for (i = 0; i < BF_ROUNDS + 2; i += 2) { - data.ctx.s.P[i] ^= data.expanded_key[i]; - data.ctx.s.P[i + 1] ^= data.expanded_key[i + 1]; - } + data.ctx.s.P[0] ^= data.expanded_key[0]; + data.ctx.s.P[1] ^= data.expanded_key[1]; + data.ctx.s.P[2] ^= data.expanded_key[2]; + data.ctx.s.P[3] ^= data.expanded_key[3]; + data.ctx.s.P[4] ^= data.expanded_key[4]; + data.ctx.s.P[5] ^= data.expanded_key[5]; + data.ctx.s.P[6] ^= data.expanded_key[6]; + data.ctx.s.P[7] ^= data.expanded_key[7]; + data.ctx.s.P[8] ^= data.expanded_key[8]; + data.ctx.s.P[9] ^= data.expanded_key[9]; + data.ctx.s.P[10] ^= data.expanded_key[10]; + data.ctx.s.P[11] ^= data.expanded_key[11]; + data.ctx.s.P[12] ^= data.expanded_key[12]; + data.ctx.s.P[13] ^= data.expanded_key[13]; + data.ctx.s.P[14] ^= data.expanded_key[14]; + data.ctx.s.P[15] ^= data.expanded_key[15]; + data.ctx.s.P[16] ^= data.expanded_key[16]; + data.ctx.s.P[17] ^= data.expanded_key[17]; done = 0; do { @@ -700,36 +716,52 @@ static void *BF_crypt(const char *key, c tmp2 = data.binary.salt[1]; tmp3 = data.binary.salt[2]; tmp4 = data.binary.salt[3]; - for (i = 0; i < BF_ROUNDS; i += 4) { - data.ctx.s.P[i] ^= tmp1; - data.ctx.s.P[i + 1] ^= tmp2; - data.ctx.s.P[i + 2] ^= tmp3; - data.ctx.s.P[i + 3] ^= tmp4; - } + data.ctx.s.P[0] ^= tmp1; + data.ctx.s.P[1] ^= tmp2; + data.ctx.s.P[2] ^= tmp3; + data.ctx.s.P[3] ^= tmp4; + data.ctx.s.P[4] ^= tmp1; + data.ctx.s.P[5] ^= tmp2; + data.ctx.s.P[6] ^= tmp3; + data.ctx.s.P[7] ^= tmp4; + data.ctx.s.P[8] ^= tmp1; + data.ctx.s.P[9] ^= tmp2; + data.ctx.s.P[10] ^= tmp3; + data.ctx.s.P[11] ^= tmp4; + data.ctx.s.P[12] ^= tmp1; + data.ctx.s.P[13] ^= tmp2; + data.ctx.s.P[14] ^= tmp3; + data.ctx.s.P[15] ^= tmp4; data.ctx.s.P[16] ^= tmp1; data.ctx.s.P[17] ^= tmp2; } } while (1); } while (--count); - for (i = 0; i < 6; i += 2) { + { BF_word L, LR[2]; - L = BF_magic_w[i]; - LR[1] = BF_magic_w[i + 1]; + L = BF_magic_w[0]; + LR[1] = BF_magic_w[1]; - count = 64; + count = 16; do { L = BF_encrypt(&data.ctx, L, LR[1], &LR[0], &LR[0]); + L = BF_encrypt(&data.ctx, L, LR[1], + &LR[0], &LR[0]); + L = BF_encrypt(&data.ctx, L, LR[1], + &LR[0], &LR[0]); + L = BF_encrypt(&data.ctx, L, LR[1], + &LR[0], &LR[0]); } while (--count); - data.binary.output[i] = L; - data.binary.output[i + 1] = LR[1]; + data.binary.output[0] = L; + data.binary.output[1] = LR[1]; } memcpy(BF_out, data.binary.output, sizeof(BF_binary)); - BF_out[5] &= ~(BF_word)0xFF; +// BF_out[5] &= ~(BF_word)0xFF; } @@ -749,7 +781,7 @@ int main(void) out.start[corenum] = 0; out.core_done[corenum] = 0; - BF_crypt((const char *)out.key[corenum], (const char *)out.setting[corenum], 16); + BF_crypt((const char *)out.key[corenum], (const char *)out.setting[corenum]); memcpy(out.result[corenum], BF_out, sizeof(BF_binary));