00001 /* aes.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 /* aes.hpp defines AES 00027 */ 00028 00029 00030 #ifndef TAO_CRYPT_AES_HPP 00031 #define TAO_CRYPT_AES_HPP 00032 00033 #include "misc.hpp" 00034 #include "modes.hpp" 00035 00036 00037 namespace TaoCrypt { 00038 00039 00040 enum { AES_BLOCK_SIZE = 16 }; 00041 00042 00043 // AES encryption and decryption, see FIPS-197 00044 class AES : public Mode_BASE { 00045 public: 00046 enum { BLOCK_SIZE = AES_BLOCK_SIZE }; 00047 00048 AES(CipherDir DIR, Mode MODE) 00049 : Mode_BASE(BLOCK_SIZE), dir_(DIR), mode_(MODE) {} 00050 00051 void Process(byte*, const byte*, word32); 00052 void SetKey(const byte* key, word32 sz, CipherDir fake = ENCRYPTION); 00053 void SetIV(const byte* iv) { memcpy(r_, iv, BLOCK_SIZE); } 00054 private: 00055 CipherDir dir_; 00056 Mode mode_; 00057 00058 static const word32 rcon_[]; 00059 00060 word32 rounds_; 00061 word32 key_[60]; // max size 00062 00063 static const word32 Te[5][256]; 00064 static const word32 Td[5][256]; 00065 00066 static const word32* Te0; 00067 static const word32* Te1; 00068 static const word32* Te2; 00069 static const word32* Te3; 00070 static const word32* Te4; 00071 00072 static const word32* Td0; 00073 static const word32* Td1; 00074 static const word32* Td2; 00075 static const word32* Td3; 00076 static const word32* Td4; 00077 00078 void encrypt(const byte*, const byte*, byte*) const; 00079 void AsmEncrypt(const byte*, byte*, void*) const; 00080 void decrypt(const byte*, const byte*, byte*) const; 00081 void AsmDecrypt(const byte*, byte*, void*) const; 00082 00083 void ProcessAndXorBlock(const byte*, const byte*, byte*) const; 00084 00085 AES(const AES&); // hide copy 00086 AES& operator=(const AES&); // and assign 00087 }; 00088 00089 00090 typedef BlockCipher<ENCRYPTION, AES, ECB> AES_ECB_Encryption; 00091 typedef BlockCipher<DECRYPTION, AES, ECB> AES_ECB_Decryption; 00092 00093 typedef BlockCipher<ENCRYPTION, AES, CBC> AES_CBC_Encryption; 00094 typedef BlockCipher<DECRYPTION, AES, CBC> AES_CBC_Decryption; 00095 00096 00097 00098 } // naemspace 00099 00100 #endif // TAO_CRYPT_AES_HPP
1.4.7

