Botan: src/block/serpent_x86_32/serp_x86_32.cpp Source File

Botan 1.10.12

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

serp_x86_32.cpp
Go to the documentation of this file.
1 /*
2 * Serpent in x86-32
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7
8 #include <botan/serp_x86_32.h>
9 #include <botan/loadstor.h>
10
11 namespace Botan {
12
13 extern "C" {
14
15 /**
16 * Entry point for Serpent encryption in x86 asm
17 * @param in the input block
18 * @param out the output block
19 * @param ks the key schedule
20 */
21 void botan_serpent_x86_32_encrypt(const byte in[16],
22 byte out[16],
23 const u32bit ks[132]);
24
25 /**
26 * Entry point for Serpent decryption in x86 asm
27 * @param in the input block
28 * @param out the output block
29 * @param ks the key schedule
30 */
31 void botan_serpent_x86_32_decrypt(const byte in[16],
32 byte out[16],
33 const u32bit ks[132]);
34
35 /**
36 * Entry point for Serpent key schedule in x86 asm
37 * @param ks holds the initial working key (padded), and is set to the
38 final key schedule
39 */
40 void botan_serpent_x86_32_key_schedule(u32bit ks[140]);
41
42 }
43
44 /*
45 * Serpent Encryption
46 */
47 void Serpent_X86_32::encrypt_n(const byte in[], byte out[], size_t blocks) const
48 {
49 for(size_t i = 0; i != blocks; ++i)
50 {
51 botan_serpent_x86_32_encrypt(in, out, this->get_round_keys());
52 in += BLOCK_SIZE;
53 out += BLOCK_SIZE;
54 }
55 }
56
57 /*
58 * Serpent Decryption
59 */
60 void Serpent_X86_32::decrypt_n(const byte in[], byte out[], size_t blocks) const
61 {
62 for(size_t i = 0; i != blocks; ++i)
63 {
64 botan_serpent_x86_32_decrypt(in, out, this->get_round_keys());
65 in += BLOCK_SIZE;
66 out += BLOCK_SIZE;
67 }
68 }
69
70 /*
71 * Serpent Key Schedule
72 */
73 void Serpent_X86_32::key_schedule(const byte key[], size_t length)
74 {
75 SecureVector<u32bit> W(140);
76 for(size_t i = 0; i != length / 4; ++i)
77 W[i] = load_le<u32bit>(key, i);
78 W[length / 4] |= u32bit(1) << ((length%4)*8);
79
80 botan_serpent_x86_32_key_schedule(W);
81 this->set_round_keys(W + 8);
82 }
83
84 }
Botan::botan_serpent_x86_32_decrypt
void botan_serpent_x86_32_decrypt(const byte in[16], byte out[16], const u32bit ks[132])
Botan::Block_Cipher_Fixed_Params< 16, 16, 32, 8 >::BLOCK_SIZE
Definition: block_cipher.h:107
Botan::Serpent_X86_32::encrypt_n
void encrypt_n(const byte in[], byte out[], size_t blocks) const
Definition: serp_x86_32.cpp:47
Botan::byte
unsigned char byte
Definition: types.h:22
Botan::load_le< u32bit >
u32bit load_le< u32bit >(const byte in[], size_t off)
Definition: loadstor.h:183
Botan::botan_serpent_x86_32_key_schedule
void botan_serpent_x86_32_key_schedule(u32bit ks[140])
Botan::Serpent::set_round_keys
void set_round_keys(const u32bit ks[132])
Definition: serpent.h:41
Botan
Definition: algo_base.h:14
Botan::Serpent::get_round_keys
const SecureVector< u32bit > & get_round_keys() const
Definition: serpent.h:34
Botan::Serpent_X86_32::decrypt_n
void decrypt_n(const byte in[], byte out[], size_t blocks) const
Definition: serp_x86_32.cpp:60
Botan::botan_serpent_x86_32_encrypt
void botan_serpent_x86_32_encrypt(const byte in[16], byte out[16], const u32bit ks[132])
Botan::SecureVector< u32bit >
Botan::u32bit
unsigned int u32bit
Definition: types.h:32