9void Blowfish::Base::UncheckedSetKey(
const byte *key_string,
unsigned int keylength,
const NameValuePairs &)
11 AssertValidKeyLength(keylength);
14 word32 data, dspace[2] = {0, 0};
16 std::memcpy(pbox, p_init,
sizeof(p_init));
17 std::memcpy(sbox, s_init,
sizeof(s_init));
20 for (i=0 ; i<
ROUNDS+2 ; ++i)
23 for (k=0 ; k<4 ; ++k )
24 data = (data << 8) | key_string[j++ % keylength];
28 crypt_block(dspace, pbox);
31 crypt_block(pbox+i, pbox+i+2);
33 crypt_block(pbox+
ROUNDS, sbox);
35 for (i=0; i<4*256-2; i+=2)
36 crypt_block(sbox+i, sbox+i+2);
38 if (!IsForwardTransformation())
39 for (i=0; i<(
ROUNDS+2)/2; i++)
40 std::swap(pbox[i], pbox[
ROUNDS+1-i]);
44void Blowfish::Base::crypt_block(
const word32 in[2],
word32 out[2])
const
49 const word32 *
const s=sbox;
54 for (
unsigned i=0; i<
ROUNDS/2; i++)
56 right ^= (((s[GETBYTE(left,3)] + s[256+GETBYTE(left,2)])
57 ^ s[2*256+GETBYTE(left,1)]) + s[3*256+GETBYTE(left,0)])
60 left ^= (((s[GETBYTE(right,3)] + s[256+GETBYTE(right,2)])
61 ^ s[2*256+GETBYTE(right,1)]) + s[3*256+GETBYTE(right,0)])
71void Blowfish::Base::ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock,
byte *outBlock)
const
76 Block::Get(inBlock)(left)(right);
78 const word32 *
const s=sbox;
83 for (
unsigned i=0; i<
ROUNDS/2; i++)
85 right ^= (((s[GETBYTE(left,3)] + s[256+GETBYTE(left,2)])
86 ^ s[2*256+GETBYTE(left,1)]) + s[3*256+GETBYTE(left,0)])
89 left ^= (((s[GETBYTE(right,3)] + s[256+GETBYTE(right,2)])
90 ^ s[2*256+GETBYTE(right,1)]) + s[3*256+GETBYTE(right,0)])
Classes for the Blowfish block cipher.
static const int ROUNDS
The number of rounds for the algorithm provided as a constant.
Interface for retrieving values given their names.
Access a block of memory.
unsigned int word32
32-bit unsigned datatype
Utility functions for the Crypto++ library.
Crypto++ library namespace.
Access a block of memory.