#include <twofishcipher.h>
Inheritance diagram for TwoFishCipher:
Public Member Functions | |
TwoFishCipher () | |
Construct a twofish cipher; key must be set separately. | |
~TwoFishCipher () | |
Destructor: Cleans up the key data. | |
const Parameters * | GetPar () const |
Return pointer to static parameters. | |
int | SetKey (char *userkey, size_t len) |
Set the key for the following encryption/decryption. | |
int | CheckWeakKey () |
Weak key check not supported - don't know of weak keys. | |
int | CopyFrom (BlockCipherBase *from) |
Copy the prepared keys from another TwoFishCipher. | |
void | EncryptBlock (char *ibuf, char *obuf) |
void | DecryptBlock (char *ibuf, char *obuf) |
Static Public Attributes | |
const BlockCipherBase::Parameters | par |
Parameters of the block cipher. | |
Private Member Functions | |
void | _reset () |
Clean up the key data. | |
TwoFishCipher (const TwoFishCipher &) | |
Do not use these:. | |
void | operator= (const TwoFishCipher &) |
Private Attributes | |
uint32 | c_w [8] |
uint32 | c_k [32] |
uint32 | c_s [4][256] |
I fiddled around with the code for several hours to make it smaller (as of executable size) than the original implementation. while not slowing down (too) much. The original author(s) thought unrolling all loops by hand would make the code very fast.
WRONG! I decreased runtime from 0.69sec to 0.48sec by inserting the decryption for() loop (see where DECCYCLE(i) is called)!!!
Originally: about 32kb stripped object code; now: 13kb
While decryption was speed up (0.69 -> 0.48 sec), decrpytion got slower (0.74 -> 0.85 sec) (grrr)
ADVANTAGE: FAST
Definition at line 66 of file twofishcipher.h.
|
Do not use these:.
|
|
Construct a twofish cipher; key must be set separately.
Definition at line 94 of file twofishcipher.h. |
|
Destructor: Cleans up the key data.
Definition at line 96 of file twofishcipher.h. References _reset(). |
|
Clean up the key data.
Definition at line 838 of file twofishcipher.cc. References c_k, c_s, c_w, and uint32. Referenced by ~TwoFishCipher(). |
|
Weak key check not supported - don't know of weak keys. This function will currently never return 1.
Reimplemented from BlockCipherBase. Definition at line 698 of file twofishcipher.cc. |
|
Copy the prepared keys from another TwoFishCipher.
Reimplemented from BlockCipherBase. Definition at line 851 of file twofishcipher.cc. References c_k, c_s, c_w, BlockCipherBase::Parameters::cipher_ID, BlockCipherBase::GetPar(), par, and uint32. |
|
Reimplemented from BlockCipherBase. Definition at line 779 of file twofishcipher.cc. References c_k, c_s, INPACK, OUTPACK, and uint32. Referenced by test_twofish(). |
|
ibuf and obuf do not have to be aligned. Reimplemented from BlockCipherBase. Definition at line 721 of file twofishcipher.cc. References c_k, c_s, INPACK, OUTPACK, and uint32. Referenced by test_twofish(). |
|
Return pointer to static parameters.
Reimplemented from BlockCipherBase. Definition at line 99 of file twofishcipher.h. References par. |
|
|
|
Set the key for the following encryption/decryption. userkey must be 128 or 256 bits long (see BlockCipher::KeyLength()).
The key does not have to be aligned. Make sure, len is a value as returned by BlockCipher::KeyLength() or the functin fails.
Reimplemented from BlockCipherBase. Definition at line 520 of file twofishcipher.cc. References c_k, c_s, c_w, calc_sb_tbl, CALC_Sx, uint32, Xmds(), Xq0(), and Xq1(). Referenced by test_twofish(). |
|
Definition at line 82 of file twofishcipher.h. Referenced by _reset(), CopyFrom(), DecryptBlock(), EncryptBlock(), and SetKey(). |
|
Definition at line 83 of file twofishcipher.h. Referenced by _reset(), CopyFrom(), DecryptBlock(), EncryptBlock(), and SetKey(). |
|
Structure for an expanded Twofish key. Definition at line 81 of file twofishcipher.h. Referenced by _reset(), CopyFrom(), and SetKey(). |
|
Initial value: { INIT_FIELD(block_size) 16, INIT_FIELD(n_key_lengths) 2, INIT_FIELD(key_length) twofish_par_kl, INIT_FIELD(cipher_ID) 0x2F15, INIT_FIELD(name) "twofish" }
Reimplemented from BlockCipherBase. Definition at line 867 of file twofishcipher.cc. Referenced by CopyFrom(), and GetPar(). |