Botan  1.11.15
src/lib/block/serpent_x86_32/serp_x86_32.cpp
Go to the documentation of this file.
00001 /*
00002 * Serpent in x86-32
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/serp_x86_32.h>
00010 
00011 namespace Botan {
00012 
00013 BOTAN_REGISTER_NAMED_T_NOARGS(BlockCipher, Serpent_X86_32, "Serpent", "x86-32");
00014 
00015 extern "C" {
00016 
00017 /**
00018 * Entry point for Serpent encryption in x86 asm
00019 * @param in the input block
00020 * @param out the output block
00021 * @param ks the key schedule
00022 */
00023 void botan_serpent_x86_32_encrypt(const byte in[16],
00024                                 byte out[16],
00025                                 const u32bit ks[132]);
00026 
00027 /**
00028 * Entry point for Serpent decryption in x86 asm
00029 * @param in the input block
00030 * @param out the output block
00031 * @param ks the key schedule
00032 */
00033 void botan_serpent_x86_32_decrypt(const byte in[16],
00034                                 byte out[16],
00035                                 const u32bit ks[132]);
00036 
00037 /**
00038 * Entry point for Serpent key schedule in x86 asm
00039 * @param ks holds the initial working key (padded), and is set to the
00040             final key schedule
00041 */
00042 void botan_serpent_x86_32_key_schedule(u32bit ks[140]);
00043 
00044 }
00045 
00046 /*
00047 * Serpent Encryption
00048 */
00049 void Serpent_X86_32::encrypt_n(const byte in[], byte out[], size_t blocks) const
00050    {
00051    auto keys = this->get_round_keys();
00052 
00053    for(size_t i = 0; i != blocks; ++i)
00054       {
00055       botan_serpent_x86_32_encrypt(in, out, &keys[0]);
00056       in += BLOCK_SIZE;
00057       out += BLOCK_SIZE;
00058       }
00059    }
00060 
00061 /*
00062 * Serpent Decryption
00063 */
00064 void Serpent_X86_32::decrypt_n(const byte in[], byte out[], size_t blocks) const
00065    {
00066    auto keys = this->get_round_keys();
00067 
00068    for(size_t i = 0; i != blocks; ++i)
00069       {
00070       botan_serpent_x86_32_decrypt(in, out, &keys[0]);
00071       in += BLOCK_SIZE;
00072       out += BLOCK_SIZE;
00073       }
00074    }
00075 
00076 /*
00077 * Serpent Key Schedule
00078 */
00079 void Serpent_X86_32::key_schedule(const byte key[], size_t length)
00080    {
00081    secure_vector<u32bit> W(140);
00082    for(size_t i = 0; i != length / 4; ++i)
00083       W[i] = load_le<u32bit>(key, i);
00084    W[length / 4] |= u32bit(1) << ((length%4)*8);
00085 
00086    botan_serpent_x86_32_key_schedule(&W[0]);
00087    this->set_round_keys(&W[8]);
00088    }
00089 
00090 }