diff options
Diffstat (limited to 'extra/yassl/taocrypt/src/aes.cpp')
-rw-r--r-- | extra/yassl/taocrypt/src/aes.cpp | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/extra/yassl/taocrypt/src/aes.cpp b/extra/yassl/taocrypt/src/aes.cpp index f92a67ac724..3b09c5280bf 100644 --- a/extra/yassl/taocrypt/src/aes.cpp +++ b/extra/yassl/taocrypt/src/aes.cpp @@ -11,8 +11,9 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + along with this program; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, + MA 02110-1301 USA. */ /* C++ based on Wei Dai's aes.cpp from CryptoPP */ @@ -78,7 +79,7 @@ void AES::Process(byte* out, const byte* in, word32 sz) out += BLOCK_SIZE; in += BLOCK_SIZE; } - } + } } #endif // DO_AES_ASM @@ -86,8 +87,13 @@ void AES::Process(byte* out, const byte* in, word32 sz) void AES::SetKey(const byte* userKey, word32 keylen, CipherDir /*dummy*/) { - assert( (keylen == 16) || (keylen == 24) || (keylen == 32) ); - + if (keylen <= 16) + keylen = 16; + else if (keylen >= 32) + keylen = 32; + else if (keylen != 24) + keylen = 24; + rounds_ = keylen/4 + 6; word32 temp, *rk = key_; @@ -245,34 +251,34 @@ void AES::encrypt(const byte* inBlock, const byte* xorBlock, for (;;) { t0 = Te0[GETBYTE(s0, 3)] ^ - Te1[GETBYTE(s1, 2)] ^ - Te2[GETBYTE(s2, 1)] ^ - Te3[GETBYTE(s3, 0)] ^ + Te1[GETBYTE(s1, 2)] ^ + Te2[GETBYTE(s2, 1)] ^ + Te3[GETBYTE(s3, 0)] ^ rk[4]; t1 = Te0[GETBYTE(s1, 3)] ^ - Te1[GETBYTE(s2, 2)] ^ - Te2[GETBYTE(s3, 1)] ^ - Te3[GETBYTE(s0, 0)] ^ + Te1[GETBYTE(s2, 2)] ^ + Te2[GETBYTE(s3, 1)] ^ + Te3[GETBYTE(s0, 0)] ^ rk[5]; t2 = Te0[GETBYTE(s2, 3)] ^ - Te1[GETBYTE(s3, 2)] ^ - Te2[GETBYTE(s0, 1)] ^ - Te3[GETBYTE(s1, 0)] ^ + Te1[GETBYTE(s3, 2)] ^ + Te2[GETBYTE(s0, 1)] ^ + Te3[GETBYTE(s1, 0)] ^ rk[6]; t3 = Te0[GETBYTE(s3, 3)] ^ - Te1[GETBYTE(s0, 2)] ^ - Te2[GETBYTE(s1, 1)] ^ - Te3[GETBYTE(s2, 0)] ^ + Te1[GETBYTE(s0, 2)] ^ + Te2[GETBYTE(s1, 1)] ^ + Te3[GETBYTE(s2, 0)] ^ rk[7]; rk += 8; if (--r == 0) { break; } - + s0 = Te0[GETBYTE(t0, 3)] ^ Te1[GETBYTE(t1, 2)] ^ @@ -421,7 +427,7 @@ void AES::decrypt(const byte* inBlock, const byte* xorBlock, (Td4[GETBYTE(t3, 2)] & 0x00ff0000) ^ (Td4[GETBYTE(t2, 1)] & 0x0000ff00) ^ (Td4[GETBYTE(t1, 0)] & 0x000000ff) ^ - rk[0]; + rk[0]; s1 = (Td4[GETBYTE(t1, 3)] & 0xff000000) ^ (Td4[GETBYTE(t0, 2)] & 0x00ff0000) ^ |