Botan  1.11.15
src/lib/block/des/desx.cpp
Go to the documentation of this file.
00001 /*
00002 * DES
00003 * (C) 1999-2007 Jack Lloyd
00004 *
00005 * Botan is released under the Simplified BSD License (see license.txt)
00006 */
00007 
00008 #include <botan/internal/block_utils.h>
00009 #include <botan/desx.h>
00010 
00011 namespace Botan {
00012 
00013 BOTAN_REGISTER_BLOCK_CIPHER_NOARGS(DESX);
00014 
00015 /*
00016 * DESX Encryption
00017 */
00018 void DESX::encrypt_n(const byte in[], byte out[], size_t blocks) const
00019    {
00020    for(size_t i = 0; i != blocks; ++i)
00021       {
00022       xor_buf(out, in, &K1[0], BLOCK_SIZE);
00023       des.encrypt(out);
00024       xor_buf(out, &K2[0], BLOCK_SIZE);
00025 
00026       in += BLOCK_SIZE;
00027       out += BLOCK_SIZE;
00028       }
00029    }
00030 
00031 /*
00032 * DESX Decryption
00033 */
00034 void DESX::decrypt_n(const byte in[], byte out[], size_t blocks) const
00035    {
00036    for(size_t i = 0; i != blocks; ++i)
00037       {
00038       xor_buf(out, in, &K2[0], BLOCK_SIZE);
00039       des.decrypt(out);
00040       xor_buf(out, &K1[0], BLOCK_SIZE);
00041 
00042       in += BLOCK_SIZE;
00043       out += BLOCK_SIZE;
00044       }
00045    }
00046 
00047 /*
00048 * DESX Key Schedule
00049 */
00050 void DESX::key_schedule(const byte key[], size_t)
00051    {
00052    K1.assign(key, key + 8);
00053    des.set_key(key + 8, 8);
00054    K2.assign(key + 16, key + 24);
00055    }
00056 
00057 void DESX::clear()
00058    {
00059    des.clear();
00060    zap(K1);
00061    zap(K2);
00062    }
00063 
00064 }