Botan
1.11.15
|
#include <rc2.h>
Public Types | |
enum | |
typedef SCAN_Name | Spec |
Public Member Functions | |
size_t | block_size () const |
void | clear () |
BlockCipher * | clone () const |
void | decrypt (const byte in[], byte out[]) const |
void | decrypt (byte block[]) const |
template<typename Alloc > | |
void | decrypt (std::vector< byte, Alloc > &block) const |
template<typename Alloc , typename Alloc2 > | |
void | decrypt (const std::vector< byte, Alloc > &in, std::vector< byte, Alloc2 > &out) const |
void | decrypt_n (const byte in[], byte out[], size_t blocks) const |
void | encrypt (const byte in[], byte out[]) const |
void | encrypt (byte block[]) const |
template<typename Alloc > | |
void | encrypt (std::vector< byte, Alloc > &block) const |
template<typename Alloc , typename Alloc2 > | |
void | encrypt (const std::vector< byte, Alloc > &in, std::vector< byte, Alloc2 > &out) const |
void | encrypt_n (const byte in[], byte out[], size_t blocks) const |
Key_Length_Specification | key_spec () const |
size_t | maximum_keylength () const |
size_t | minimum_keylength () const |
std::string | name () const |
size_t | parallel_bytes () const |
virtual size_t | parallelism () const |
void | set_key (const SymmetricKey &key) |
template<typename Alloc > | |
void | set_key (const std::vector< byte, Alloc > &key) |
void | set_key (const byte key[], size_t length) |
bool | valid_keylength (size_t length) const |
Static Public Member Functions | |
static byte | EKB_code (size_t bits) |
typedef SCAN_Name Botan::BlockCipher::Spec [inherited] |
Definition at line 22 of file block_cipher.h.
anonymous enum [inherited] |
Definition at line 153 of file block_cipher.h.
{ BLOCK_SIZE = BS };
size_t Botan::Block_Cipher_Fixed_Params< BS, KMIN, KMAX, 1 >::block_size | ( | ) | const [inline, virtual, inherited] |
Implements Botan::BlockCipher.
Definition at line 154 of file block_cipher.h.
{ return BS; }
void Botan::RC2::clear | ( | ) | [virtual] |
Implements Botan::SymmetricAlgorithm.
Definition at line 143 of file rc2.cpp.
References Botan::zap().
{ zap(K); }
BlockCipher* Botan::RC2::clone | ( | ) | const [inline, virtual] |
Implements Botan::BlockCipher.
Definition at line 33 of file rc2.h.
{ return new RC2; }
void Botan::BlockCipher::decrypt | ( | const byte | in[], |
byte | out[] | ||
) | const [inline, inherited] |
Decrypt a block.
in | The ciphertext block to be decypted as a byte array. Must be of length block_size(). |
out | The byte array designated to hold the decrypted block. Must be of length block_size(). |
Definition at line 59 of file block_cipher.h.
Referenced by Botan::Camellia_128::decrypt_n(), Botan::DESX::decrypt_n(), Botan::Camellia_192::decrypt_n(), Botan::Camellia_256::decrypt_n(), Botan::XTS_Decryption::finish(), and Botan::CTS_Decryption::finish().
{ decrypt_n(in, out, 1); }
void Botan::BlockCipher::decrypt | ( | byte | block[] | ) | const [inline, inherited] |
Decrypt a block.
block | the ciphertext block to be decrypted Must be of length block_size(). Will hold the result when the function has finished. |
Definition at line 76 of file block_cipher.h.
{ decrypt_n(block, block, 1); }
void Botan::BlockCipher::decrypt | ( | std::vector< byte, Alloc > & | block | ) | const [inline, inherited] |
Decrypt one or more blocks
block | the input/output buffer (multiple of block_size()) |
Definition at line 93 of file block_cipher.h.
{ return decrypt_n(&block[0], &block[0], block.size() / block_size()); }
void Botan::BlockCipher::decrypt | ( | const std::vector< byte, Alloc > & | in, |
std::vector< byte, Alloc2 > & | out | ||
) | const [inline, inherited] |
Decrypt one or more blocks
in | the input buffer (multiple of block_size()) |
out | the output buffer (same size as in) |
Definition at line 116 of file block_cipher.h.
{ return decrypt_n(&in[0], &out[0], in.size() / block_size()); }
void Botan::RC2::decrypt_n | ( | const byte | in[], |
byte | out[], | ||
size_t | blocks | ||
) | const [virtual] |
Decrypt one or more blocks
in | the input buffer (multiple of block_size()) |
out | the output buffer (same size as in) |
blocks | the number of blocks to process |
Implements Botan::BlockCipher.
Definition at line 60 of file rc2.cpp.
References Botan::Block_Cipher_Fixed_Params< 8, 1, 32 >::BLOCK_SIZE, Botan::load_le< u16bit >(), R0, R1, R2, R3, Botan::rotate_right(), and Botan::store_le().
{ for(size_t i = 0; i != blocks; ++i) { u16bit R0 = load_le<u16bit>(in, 0); u16bit R1 = load_le<u16bit>(in, 1); u16bit R2 = load_le<u16bit>(in, 2); u16bit R3 = load_le<u16bit>(in, 3); for(size_t j = 0; j != 16; ++j) { R3 = rotate_right(R3, 5); R3 -= (R0 & ~R2) + (R1 & R2) + K[63 - (4*j + 0)]; R2 = rotate_right(R2, 3); R2 -= (R3 & ~R1) + (R0 & R1) + K[63 - (4*j + 1)]; R1 = rotate_right(R1, 2); R1 -= (R2 & ~R0) + (R3 & R0) + K[63 - (4*j + 2)]; R0 = rotate_right(R0, 1); R0 -= (R1 & ~R3) + (R2 & R3) + K[63 - (4*j + 3)]; if(j == 4 || j == 10) { R3 -= K[R2 % 64]; R2 -= K[R1 % 64]; R1 -= K[R0 % 64]; R0 -= K[R3 % 64]; } } store_le(out, R0, R1, R2, R3); in += BLOCK_SIZE; out += BLOCK_SIZE; } }
byte Botan::RC2::EKB_code | ( | size_t | bits | ) | [static] |
Return the code of the effective key bits
bits | key length |
Definition at line 151 of file rc2.cpp.
{ const byte EKB[256] = { 0xBD, 0x56, 0xEA, 0xF2, 0xA2, 0xF1, 0xAC, 0x2A, 0xB0, 0x93, 0xD1, 0x9C, 0x1B, 0x33, 0xFD, 0xD0, 0x30, 0x04, 0xB6, 0xDC, 0x7D, 0xDF, 0x32, 0x4B, 0xF7, 0xCB, 0x45, 0x9B, 0x31, 0xBB, 0x21, 0x5A, 0x41, 0x9F, 0xE1, 0xD9, 0x4A, 0x4D, 0x9E, 0xDA, 0xA0, 0x68, 0x2C, 0xC3, 0x27, 0x5F, 0x80, 0x36, 0x3E, 0xEE, 0xFB, 0x95, 0x1A, 0xFE, 0xCE, 0xA8, 0x34, 0xA9, 0x13, 0xF0, 0xA6, 0x3F, 0xD8, 0x0C, 0x78, 0x24, 0xAF, 0x23, 0x52, 0xC1, 0x67, 0x17, 0xF5, 0x66, 0x90, 0xE7, 0xE8, 0x07, 0xB8, 0x60, 0x48, 0xE6, 0x1E, 0x53, 0xF3, 0x92, 0xA4, 0x72, 0x8C, 0x08, 0x15, 0x6E, 0x86, 0x00, 0x84, 0xFA, 0xF4, 0x7F, 0x8A, 0x42, 0x19, 0xF6, 0xDB, 0xCD, 0x14, 0x8D, 0x50, 0x12, 0xBA, 0x3C, 0x06, 0x4E, 0xEC, 0xB3, 0x35, 0x11, 0xA1, 0x88, 0x8E, 0x2B, 0x94, 0x99, 0xB7, 0x71, 0x74, 0xD3, 0xE4, 0xBF, 0x3A, 0xDE, 0x96, 0x0E, 0xBC, 0x0A, 0xED, 0x77, 0xFC, 0x37, 0x6B, 0x03, 0x79, 0x89, 0x62, 0xC6, 0xD7, 0xC0, 0xD2, 0x7C, 0x6A, 0x8B, 0x22, 0xA3, 0x5B, 0x05, 0x5D, 0x02, 0x75, 0xD5, 0x61, 0xE3, 0x18, 0x8F, 0x55, 0x51, 0xAD, 0x1F, 0x0B, 0x5E, 0x85, 0xE5, 0xC2, 0x57, 0x63, 0xCA, 0x3D, 0x6C, 0xB4, 0xC5, 0xCC, 0x70, 0xB2, 0x91, 0x59, 0x0D, 0x47, 0x20, 0xC8, 0x4F, 0x58, 0xE0, 0x01, 0xE2, 0x16, 0x38, 0xC4, 0x6F, 0x3B, 0x0F, 0x65, 0x46, 0xBE, 0x7E, 0x2D, 0x7B, 0x82, 0xF9, 0x40, 0xB5, 0x1D, 0x73, 0xF8, 0xEB, 0x26, 0xC7, 0x87, 0x97, 0x25, 0x54, 0xB1, 0x28, 0xAA, 0x98, 0x9D, 0xA5, 0x64, 0x6D, 0x7A, 0xD4, 0x10, 0x81, 0x44, 0xEF, 0x49, 0xD6, 0xAE, 0x2E, 0xDD, 0x76, 0x5C, 0x2F, 0xA7, 0x1C, 0xC9, 0x09, 0x69, 0x9A, 0x83, 0xCF, 0x29, 0x39, 0xB9, 0xE9, 0x4C, 0xFF, 0x43, 0xAB }; if(ekb < 256) return EKB[ekb]; else throw Encoding_Error("RC2::EKB_code: EKB is too large"); }
void Botan::BlockCipher::encrypt | ( | const byte | in[], |
byte | out[] | ||
) | const [inline, inherited] |
Encrypt a block.
in | The plaintext block to be encrypted as a byte array. Must be of length block_size(). |
out | The byte array designated to hold the encrypted block. Must be of length block_size(). |
Definition at line 49 of file block_cipher.h.
Referenced by Botan::aont_package(), Botan::aont_unpackage(), Botan::DESX::encrypt_n(), Botan::Camellia_128::encrypt_n(), Botan::Camellia_192::encrypt_n(), Botan::Camellia_256::encrypt_n(), Botan::XTS_Encryption::finish(), Botan::CTS_Encryption::finish(), Botan::CBC_Encryption::update(), Botan::CFB_Encryption::update(), and Botan::CFB_Decryption::update().
{ encrypt_n(in, out, 1); }
void Botan::BlockCipher::encrypt | ( | byte | block[] | ) | const [inline, inherited] |
Encrypt a block.
block | the plaintext block to be encrypted Must be of length block_size(). Will hold the result when the function has finished. |
Definition at line 68 of file block_cipher.h.
{ encrypt_n(block, block, 1); }
void Botan::BlockCipher::encrypt | ( | std::vector< byte, Alloc > & | block | ) | const [inline, inherited] |
Encrypt one or more blocks
block | the input/output buffer (multiple of block_size()) |
Definition at line 83 of file block_cipher.h.
{ return encrypt_n(&block[0], &block[0], block.size() / block_size()); }
void Botan::BlockCipher::encrypt | ( | const std::vector< byte, Alloc > & | in, |
std::vector< byte, Alloc2 > & | out | ||
) | const [inline, inherited] |
Encrypt one or more blocks
in | the input buffer (multiple of block_size()) |
out | the output buffer (same size as in) |
Definition at line 104 of file block_cipher.h.
{ return encrypt_n(&in[0], &out[0], in.size() / block_size()); }
void Botan::RC2::encrypt_n | ( | const byte | in[], |
byte | out[], | ||
size_t | blocks | ||
) | const [virtual] |
Encrypt one or more blocks
in | the input buffer (multiple of block_size()) |
out | the output buffer (same size as in) |
blocks | the number of blocks to process |
Implements Botan::BlockCipher.
Definition at line 18 of file rc2.cpp.
References Botan::Block_Cipher_Fixed_Params< 8, 1, 32 >::BLOCK_SIZE, Botan::load_le< u16bit >(), R0, R1, R2, R3, Botan::rotate_left(), and Botan::store_le().
{ for(size_t i = 0; i != blocks; ++i) { u16bit R0 = load_le<u16bit>(in, 0); u16bit R1 = load_le<u16bit>(in, 1); u16bit R2 = load_le<u16bit>(in, 2); u16bit R3 = load_le<u16bit>(in, 3); for(size_t j = 0; j != 16; ++j) { R0 += (R1 & ~R3) + (R2 & R3) + K[4*j]; R0 = rotate_left(R0, 1); R1 += (R2 & ~R0) + (R3 & R0) + K[4*j + 1]; R1 = rotate_left(R1, 2); R2 += (R3 & ~R1) + (R0 & R1) + K[4*j + 2]; R2 = rotate_left(R2, 3); R3 += (R0 & ~R2) + (R1 & R2) + K[4*j + 3]; R3 = rotate_left(R3, 5); if(j == 4 || j == 10) { R0 += K[R3 % 64]; R1 += K[R0 % 64]; R2 += K[R1 % 64]; R3 += K[R2 % 64]; } } store_le(out, R0, R1, R2, R3); in += BLOCK_SIZE; out += BLOCK_SIZE; } }
Key_Length_Specification Botan::Block_Cipher_Fixed_Params< BS, KMIN, KMAX, 1 >::key_spec | ( | ) | const [inline, virtual, inherited] |
Implements Botan::SymmetricAlgorithm.
Definition at line 156 of file block_cipher.h.
{
return Key_Length_Specification(KMIN, KMAX, KMOD);
}
size_t Botan::SymmetricAlgorithm::maximum_keylength | ( | ) | const [inline, inherited] |
Definition at line 36 of file sym_algo.h.
References Botan::Key_Length_Specification::maximum_keylength().
{ return key_spec().maximum_keylength(); }
size_t Botan::SymmetricAlgorithm::minimum_keylength | ( | ) | const [inline, inherited] |
Definition at line 44 of file sym_algo.h.
{ return key_spec().minimum_keylength(); }
std::string Botan::RC2::name | ( | ) | const [inline, virtual] |
size_t Botan::BlockCipher::parallel_bytes | ( | ) | const [inline, inherited] |
Definition at line 37 of file block_cipher.h.
Referenced by Botan::XTS_Mode::update_granularity(), Botan::ECB_Mode::update_granularity(), and Botan::CBC_Mode::update_granularity().
{ return parallelism() * block_size() * BOTAN_BLOCK_CIPHER_PAR_MULT; }
virtual size_t Botan::BlockCipher::parallelism | ( | ) | const [inline, virtual, inherited] |
Reimplemented in Botan::AES_256_NI, Botan::AES_192_NI, Botan::AES_128_NI, Botan::IDEA_SSE2, Botan::Noekeon_SIMD, Botan::Serpent_SIMD, and Botan::XTEA_SIMD.
Definition at line 32 of file block_cipher.h.
{ return 1; }
void Botan::SymmetricAlgorithm::set_key | ( | const SymmetricKey & | key | ) | [inline, inherited] |
Set the symmetric key of this object.
key | the SymmetricKey to be set. |
Definition at line 63 of file sym_algo.h.
References Botan::OctetString::begin(), and Botan::OctetString::length().
Referenced by Botan::aont_package(), Botan::aont_unpackage(), botan_mac_set_key(), Botan::TLS::Session::decrypt(), Botan::TLS::Session::encrypt(), and Botan::pbkdf2().
{ set_key(key.begin(), key.length()); }
void Botan::SymmetricAlgorithm::set_key | ( | const std::vector< byte, Alloc > & | key | ) | [inline, inherited] |
Definition at line 69 of file sym_algo.h.
{ set_key(&key[0], key.size()); }
void Botan::SymmetricAlgorithm::set_key | ( | const byte | key[], |
size_t | length | ||
) | [inline, inherited] |
Set the symmetric key of this object.
key | the to be set as a byte array. |
length | in bytes of key param |
Definition at line 79 of file sym_algo.h.
{ if(!valid_keylength(length)) throw Invalid_Key_Length(name(), length); key_schedule(key, length); }
bool Botan::SymmetricAlgorithm::valid_keylength | ( | size_t | length | ) | const [inline, inherited] |
Check whether a given key length is valid for this algorithm.
length | the key length to be checked. |
Definition at line 54 of file sym_algo.h.
Referenced by Botan::aont_package(), and Botan::aont_unpackage().
{ return key_spec().valid_keylength(length); }