WIN32DLL_DEFINE int _mcrypt_set_key(cast256_key * key, const word32 * in_key, const int key_len) { word32 i, j, t, u, cm, cr, lk[8], tm[8], tr[8]; for (i = 0; i < key_len / sizeof(word32); ++i) #ifdef WORDS_BIGENDIAN lk[i] = byteswap32(in_key[i]); #else lk[i] = in_key[i]; #endif for (; i < 8; ++i) lk[i] = 0; cm = 0x5a827999; cr = 19; for (i = 0; i < 96; i += 8) { for (j = 0; j < 8; ++j) { tm[j] = cm; cm += 0x6ed9eba1; tr[j] = cr; cr += 17; } k_rnd(lk, tr, tm); for (j = 0; j < 8; ++j) { tm[j] = cm; cm += 0x6ed9eba1; tr[j] = cr; cr += 17; } k_rnd(lk, tr, tm); key->l_key[i + 0] = lk[0]; key->l_key[i + 1] = lk[2]; key->l_key[i + 2] = lk[4]; key->l_key[i + 3] = lk[6]; key->l_key[i + 4] = lk[7]; key->l_key[i + 5] = lk[5]; key->l_key[i + 6] = lk[3]; key->l_key[i + 7] = lk[1]; } return 0; }
u4byte * set_key (const u4byte in_key[], const u4byte key_len) { u4byte i, j, t, u, cm, cr, lk[8], tm[8], tr[8]; for (i = 0; i < key_len / 32; ++i) lk[i] = io_swap (in_key[i]); for (; i < 8; ++i) lk[i] = 0; cm = 0x5a827999; cr = 19; for (i = 0; i < 96; i += 8) { for (j = 0; j < 8; ++j) { tm[j] = cm; cm += 0x6ed9eba1; tr[j] = cr; cr += 17; } k_rnd (lk, tr, tm); for (j = 0; j < 8; ++j) { tm[j] = cm; cm += 0x6ed9eba1; tr[j] = cr; cr += 17; } k_rnd (lk, tr, tm); l_key[i + 0] = lk[0]; l_key[i + 1] = lk[2]; l_key[i + 2] = lk[4]; l_key[i + 3] = lk[6]; l_key[i + 4] = lk[7]; l_key[i + 5] = lk[5]; l_key[i + 6] = lk[3]; l_key[i + 7] = lk[1]; } return l_key; }