00001 /* blowfish.hpp 00002 * 00003 * Copyright (C) 2003 Sawtooth Consulting Ltd. 00004 * 00005 * This file is part of yaSSL. 00006 * 00007 * yaSSL is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * There are special exceptions to the terms and conditions of the GPL as it 00013 * is applied to yaSSL. View the full text of the exception in the file 00014 * FLOSS-EXCEPTIONS in the directory of this software distribution. 00015 * 00016 * yaSSL is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU General Public License 00022 * along with this program; if not, write to the Free Software 00023 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 00024 */ 00025 00026 /* blowfish.hpp defines Blowfish 00027 */ 00028 00029 00030 #ifndef TAO_CRYPT_BLOWFISH_HPP 00031 #define TAO_CRYPT_BLOWFISH_HPP 00032 00033 #include "misc.hpp" 00034 #include "modes.hpp" 00035 #include "algorithm.hpp" 00036 00037 namespace TaoCrypt { 00038 00039 enum { BLOWFISH_BLOCK_SIZE = 8 }; 00040 00041 00042 // Blowfish encryption and decryption, see 00043 class Blowfish : public Mode_BASE { 00044 public: 00045 enum { BLOCK_SIZE = BLOWFISH_BLOCK_SIZE, ROUNDS = 16 }; 00046 00047 Blowfish(CipherDir DIR, Mode MODE) 00048 : Mode_BASE(BLOCK_SIZE), dir_(DIR), mode_(MODE) {} 00049 00050 void Process(byte*, const byte*, word32); 00051 void SetKey(const byte* key, word32 sz, CipherDir fake = ENCRYPTION); 00052 void SetIV(const byte* iv) { memcpy(r_, iv, BLOCK_SIZE); } 00053 private: 00054 CipherDir dir_; 00055 Mode mode_; 00056 00057 static const word32 p_init_[ROUNDS + 2]; 00058 static const word32 s_init_[4 * 256]; 00059 00060 word32 pbox_[ROUNDS + 2]; 00061 word32 sbox_[4 * 256]; 00062 00063 void crypt_block(const word32 in[2], word32 out[2]) const; 00064 void AsmProcess(const byte* in, byte* out) const; 00065 void ProcessAndXorBlock(const byte*, const byte*, byte*) const; 00066 00067 Blowfish(const Blowfish&); // hide copy 00068 Blowfish& operator=(const Blowfish&); // and assign 00069 }; 00070 00071 00072 typedef BlockCipher<ENCRYPTION, Blowfish, ECB> Blowfish_ECB_Encryption; 00073 typedef BlockCipher<DECRYPTION, Blowfish, ECB> Blowfish_ECB_Decryption; 00074 00075 typedef BlockCipher<ENCRYPTION, Blowfish, CBC> Blowfish_CBC_Encryption; 00076 typedef BlockCipher<DECRYPTION, Blowfish, CBC> Blowfish_CBC_Decryption; 00077 00078 00079 00080 } // naemspace 00081 00082 #endif // TAO_CRYPT_BLOWFISH_HPP 00083
1.4.7

