Botan: Botan::RC2 Class Reference

Botan 1.10.12

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

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Types | Public Member Functions | Static Public Member Functions | List of all members
Botan::RC2 Class Reference

`#include <rc2.h>`

Inheritance diagram for Botan::RC2:

## Public Types
enum |

## 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
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
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
| RC2 ()
void | set_key (const SymmetricKey &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)

## Detailed Description

RC2

Definition at line 18 of file rc2.h.

## Member Enumeration Documentation

anonymous enum
| inherited

Definition at line 107 of file block_cipher.h.

107 { BLOCK_SIZE = BS };
Botan::Block_Cipher_Fixed_Params< 8, 1, 32 >::BLOCK_SIZE
Definition: block_cipher.h:107

## Constructor & Destructor Documentation

Botan::RC2::RC2 | ( |  | ) |
| inline

Definition at line 35 of file rc2.h.

35 : K(64) {}

## Member Function Documentation

size_t Botan::Block_Cipher_Fixed_Params< BS, KMIN, KMAX, 1 >::block_size | ( |  | ) | const
| inlinevirtualinherited

Returns
  block size of this algorithm

Implements Botan::BlockCipher.

Definition at line 108 of file block_cipher.h.

108 { return BS; }

void Botan::RC2::clear | ( |  | ) |
| inlinevirtual

Zeroize internal state

Implements Botan::Algorithm.

Definition at line 31 of file rc2.h.

References Botan::zeroise().

31 { zeroise(K); }
Botan::zeroise
void zeroise(MemoryRegion< T > &vec)
Definition: secmem.h:415

BlockCipher* Botan::RC2::clone | ( |  | ) | const
| inlinevirtual

Get a new object representing the same algorithm as *this

Implements Botan::BlockCipher.

Definition at line 33 of file rc2.h.

33 { return new RC2; }
Botan::RC2::RC2
RC2()
Definition: rc2.h:35

void Botan::BlockCipher::decrypt | ( | const byte | in[],
|  | byte | out[]
| ) |  | const
| inlineinherited

Decrypt a block.

Parameters

  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 57 of file block_cipher.h.

Referenced by Botan::DESX::decrypt_n(), Botan::ECB_Decryption::name(), Botan::CTS_Decryption::set_iv(), and Botan::CBC_Decryption::set_iv().

58 { decrypt_n(in, out, 1); }
Botan::BlockCipher::decrypt_n
virtual void decrypt_n(const byte in[], byte out[], size_t blocks) const =0

void Botan::BlockCipher::decrypt | ( | byte | block[] | ) | const
| inlineinherited

Decrypt a block.

Parameters

  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 74 of file block_cipher.h.

74 { decrypt_n(block, block, 1); }
Botan::BlockCipher::decrypt_n
virtual void decrypt_n(const byte in[], byte out[], size_t blocks) const =0

void Botan::RC2::decrypt_n | ( | const byte | in[],
|  | byte | out[],
|  | size_t | blocks
| ) |  | const
| virtual

Decrypt one or more blocks

Parameters

  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 59 of file rc2.cpp.

References Botan::Block_Cipher_Fixed_Params< 8, 1, 32 >::BLOCK_SIZE, Botan::MemoryRegion< T >::copy(), Botan::load_le< u16bit >(), R0, R1, R2, R3, Botan::rotate_right(), and Botan::store_le().

60 {
61 for(size_t i = 0; i != blocks; ++i)
62 {
63 u16bit R0 = load_le<u16bit>(in, 0);
64 u16bit R1 = load_le<u16bit>(in, 1);
65 u16bit R2 = load_le<u16bit>(in, 2);
66 u16bit R3 = load_le<u16bit>(in, 3);
67
68 for(size_t j = 0; j != 16; ++j)
69 {
70 R3 = rotate_right(R3, 5);
71 R3 -= (R0 & ~R2) + (R1 & R2) + K[63 - (4*j + 0)];
72
73 R2 = rotate_right(R2, 3);
74 R2 -= (R3 & ~R1) + (R0 & R1) + K[63 - (4*j + 1)];
75
76 R1 = rotate_right(R1, 2);
77 R1 -= (R2 & ~R0) + (R3 & R0) + K[63 - (4*j + 2)];
78
79 R0 = rotate_right(R0, 1);
80 R0 -= (R1 & ~R3) + (R2 & R3) + K[63 - (4*j + 3)];
81
82 if(j == 4 || j == 10)
83 {
84 R3 -= K[R2 % 64];
85 R2 -= K[R1 % 64];
86 R1 -= K[R0 % 64];
87 R0 -= K[R3 % 64];
88 }
89 }
90
91 store_le(out, R0, R1, R2, R3);
92
93 in += BLOCK_SIZE;
94 out += BLOCK_SIZE;
95 }
96 }
Botan::Block_Cipher_Fixed_Params< 8, 1, 32 >::BLOCK_SIZE
Definition: block_cipher.h:107
Botan::store_le
void store_le(u16bit in, byte out[2])
Definition: loadstor.h:427
R0
#define R0
Definition: asm_x86_64.h:51
Botan::rotate_right
T rotate_right(T input, size_t rot)
Definition: rotate.h:34
R2
#define R2
Definition: asm_x86_64.h:53
Botan::u16bit
unsigned short u16bit
Definition: types.h:27
R1
#define R1
Definition: asm_x86_64.h:52
Botan::load_le< u16bit >
u16bit load_le< u16bit >(const byte in[], size_t off)
Definition: loadstor.h:149
R3
#define R3
Definition: asm_x86_64.h:55

byte Botan::RC2::EKB_code | ( | size_t | bits | ) |
| static

Return the code of the effective key bits

Parameters

  bits | key length

Returns
  EKB code

Definition at line 144 of file rc2.cpp.

145 {
146 const byte EKB[256] = {
147 0xBD, 0x56, 0xEA, 0xF2, 0xA2, 0xF1, 0xAC, 0x2A, 0xB0, 0x93, 0xD1, 0x9C,
148 0x1B, 0x33, 0xFD, 0xD0, 0x30, 0x04, 0xB6, 0xDC, 0x7D, 0xDF, 0x32, 0x4B,
149 0xF7, 0xCB, 0x45, 0x9B, 0x31, 0xBB, 0x21, 0x5A, 0x41, 0x9F, 0xE1, 0xD9,
150 0x4A, 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97,
165 0x25, 0x54, 0xB1, 0x28, 0xAA, 0x98, 0x9D, 0xA5, 0x64, 0x6D, 0x7A, 0xD4,
166 0x10, 0x81, 0x44, 0xEF, 0x49, 0xD6, 0xAE, 0x2E, 0xDD, 0x76, 0x5C, 0x2F,
167 0xA7, 0x1C, 0xC9, 0x09, 0x69, 0x9A, 0x83, 0xCF, 0x29, 0x39, 0xB9, 0xE9,
168 0x4C, 0xFF, 0x43, 0xAB };
169
170 if(ekb < 256)
171 return EKB[ekb];
172 else
173 throw Encoding_Error("RC2::EKB_code: EKB is too large");
174 }
Botan::byte
unsigned char byte
Definition: types.h:22

void Botan::BlockCipher::encrypt | ( | const byte | in[],
|  | byte | out[]
| ) |  | const
| inlineinherited

Encrypt a block.

Parameters

  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 47 of file block_cipher.h.

Referenced by Botan::aont_package(), Botan::aont_unpackage(), Botan::OFB::cipher(), Botan::GOST_34_11::clear(), Botan::DESX::encrypt_n(), Botan::CMAC::poly_double(), Botan::ANSI_X931_RNG::randomize(), Botan::Randpool::randomize(), Botan::CTS_Encryption::set_iv(), Botan::CFB_Encryption::set_iv(), Botan::OFB::set_iv(), Botan::XTS_Encryption::set_iv(), Botan::CBC_Encryption::set_iv(), Botan::CFB_Decryption::set_iv(), and Botan::XTS_Decryption::set_iv().

48 { encrypt_n(in, out, 1); }
Botan::BlockCipher::encrypt_n
virtual void encrypt_n(const byte in[], byte out[], size_t blocks) const =0

void Botan::BlockCipher::encrypt | ( | byte | block[] | ) | const
| inlineinherited

Encrypt a block.

Parameters

  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 66 of file block_cipher.h.

66 { encrypt_n(block, block, 1); }
Botan::BlockCipher::encrypt_n
virtual void encrypt_n(const byte in[], byte out[], size_t blocks) const =0

void Botan::RC2::encrypt_n | ( | const byte | in[],
|  | byte | out[],
|  | size_t | blocks
| ) |  | const
| virtual

Encrypt one or more blocks

Parameters

  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 17 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().

18 {
19 for(size_t i = 0; i != blocks; ++i)
20 {
21 u16bit R0 = load_le<u16bit>(in, 0);
22 u16bit R1 = load_le<u16bit>(in, 1);
23 u16bit R2 = load_le<u16bit>(in, 2);
24 u16bit R3 = load_le<u16bit>(in, 3);
25
26 for(size_t j = 0; j != 16; ++j)
27 {
28 R0 += (R1 & ~R3) + (R2 & R3) + K[4*j];
29 R0 = rotate_left(R0, 1);
30
31 R1 += (R2 & ~R0) + (R3 & R0) + K[4*j + 1];
32 R1 = rotate_left(R1, 2);
33
34 R2 += (R3 & ~R1) + (R0 & R1) + K[4*j + 2];
35 R2 = rotate_left(R2, 3);
36
37 R3 += (R0 & ~R2) + (R1 & R2) + K[4*j + 3];
38 R3 = rotate_left(R3, 5);
39
40 if(j == 4 || j == 10)
41 {
42 R0 += K[R3 % 64];
43 R1 += K[R0 % 64];
44 R2 += K[R1 % 64];
45 R3 += K[R2 % 64];
46 }
47 }
48
49 store_le(out, R0, R1, R2, R3);
50
51 in += BLOCK_SIZE;
52 out += BLOCK_SIZE;
53 }
54 }
Botan::Block_Cipher_Fixed_Params< 8, 1, 32 >::BLOCK_SIZE
Definition: block_cipher.h:107
Botan::store_le
void store_le(u16bit in, byte out[2])
Definition: loadstor.h:427
Botan::rotate_left
T rotate_left(T input, size_t rot)
Definition: rotate.h:21
R0
#define R0
Definition: asm_x86_64.h:51
R2
#define R2
Definition: asm_x86_64.h:53
Botan::u16bit
unsigned short u16bit
Definition: types.h:27
R1
#define R1
Definition: asm_x86_64.h:52
Botan::load_le< u16bit >
u16bit load_le< u16bit >(const byte in[], size_t off)
Definition: loadstor.h:149
R3
#define R3
Definition: asm_x86_64.h:55

Key_Length_Specification Botan::Block_Cipher_Fixed_Params< BS, KMIN, KMAX, 1 >::key_spec | ( |  | ) | const
| inlinevirtualinherited

Returns
  object describing limits on key size

Implements Botan::SymmetricAlgorithm.

Definition at line 110 of file block_cipher.h.

111 {
112 return Key_Length_Specification(KMIN, KMAX, KMOD);
113 }

size_t Botan::SymmetricAlgorithm::maximum_keylength | ( |  | ) | const
| inlineinherited

Returns
  minimum allowed key length

Definition at line 33 of file sym_algo.h.

Referenced by Botan::Cascade_Cipher::decrypt_n(), Botan::PBE_PKCS5v20::end_msg(), and Botan::ANSI_X931_RNG::randomize().

34 {
35 return key_spec().maximum_keylength();
36 }
Botan::SymmetricAlgorithm::key_spec
virtual Key_Length_Specification key_spec() const =0
Botan::Key_Length_Specification::maximum_keylength
size_t maximum_keylength() const
Definition: key_spec.h:69

size_t Botan::SymmetricAlgorithm::minimum_keylength | ( |  | ) | const
| inlineinherited

Returns
  maxmium allowed key length

Definition at line 41 of file sym_algo.h.

42 {
43 return key_spec().minimum_keylength();
44 }
Botan::SymmetricAlgorithm::key_spec
virtual Key_Length_Specification key_spec() const =0
Botan::Key_Length_Specification::minimum_keylength
size_t minimum_keylength() const
Definition: key_spec.h:61

std::string Botan::RC2::name | ( |  | ) | const
| inlinevirtual

Returns
  name of this algorithm

Implements Botan::Algorithm.

Definition at line 32 of file rc2.h.

32 { return "RC2"; }

size_t Botan::BlockCipher::parallel_bytes | ( |  | ) | const
| inlineinherited

Returns
  prefererred parallelism of this cipher in bytes

Definition at line 35 of file block_cipher.h.

36 {
37 return parallelism() * block_size() * BOTAN_BLOCK_CIPHER_PAR_MULT;
38 }
Botan::BlockCipher::block_size
virtual size_t block_size() const =0
Botan::BlockCipher::parallelism
virtual size_t parallelism() const
Definition: block_cipher.h:30

virtual size_t Botan::BlockCipher::parallelism | ( |  | ) | const
| inlinevirtualinherited

Returns
  native parallelism of this cipher in blocks

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 30 of file block_cipher.h.

30 { return 1; }

void Botan::SymmetricAlgorithm::set_key | ( | const SymmetricKey & | key | ) |
| inlineinherited

Set the symmetric key of this object.

Parameters

  key | the SymmetricKey to be set.

Definition at line 60 of file sym_algo.h.

References Botan::OctetString::begin(), and Botan::OctetString::length().

Referenced by Botan::aont_package(), Botan::aont_unpackage(), Botan::GOST_34_11::clear(), Botan::CTR_BE::clear(), Botan::OFB::clear(), Botan::Cascade_Cipher::decrypt_n(), Botan::DESX::decrypt_n(), Botan::Lion::decrypt_n(), Botan::PKCS5_PBKDF2::derive_key(), Botan::ECB_Decryption::ECB_Decryption(), Botan::ECB_Encryption::ECB_Encryption(), Botan::Lion::encrypt_n(), Botan::HMAC_RNG::HMAC_RNG(), Botan::MAC_Filter::MAC_Filter(), Botan::CMAC::poly_double(), Botan::ANSI_X931_RNG::randomize(), Botan::Randpool::randomize(), Botan::HMAC_RNG::reseed(), Botan::EAX_Base::set_key(), Botan::XTS_Encryption::set_key(), Botan::XTS_Decryption::set_key(), Botan::Record_Writer::set_keys(), Botan::Record_Reader::set_keys(), Botan::StreamCipher_Filter::StreamCipher_Filter(), Botan::DLIES_Decryptor::~DLIES_Decryptor(), and Botan::DLIES_Encryptor::~DLIES_Encryptor().

61 { set_key(key.begin(), key.length()); }
Botan::SymmetricAlgorithm::set_key
void set_key(const SymmetricKey &key)
Definition: sym_algo.h:60

void Botan::SymmetricAlgorithm::set_key | ( | const byte | key[],
|  | size_t | length
| ) |  |
| inlineinherited

Set the symmetric key of this object.

Parameters

  key | the to be set as a byte array.
  length | in bytes of key param

Definition at line 68 of file sym_algo.h.

69 {
70 if(!valid_keylength(length))
71 throw Invalid_Key_Length(name(), length);
72 key_schedule(key, length);
73 }
Botan::SymmetricAlgorithm::valid_keylength
bool valid_keylength(size_t length) const
Definition: sym_algo.h:51
Botan::Algorithm::name
virtual std::string name() const =0

bool Botan::SymmetricAlgorithm::valid_keylength | ( | size_t | length | ) | const
| inlineinherited

Check whether a given key length is valid for this algorithm.

Parameters

  length | the key length to be checked.

Returns
  true if the key length is valid.

Definition at line 51 of file sym_algo.h.

Referenced by Botan::aont_package(), Botan::aont_unpackage(), Botan::HMAC_RNG::HMAC_RNG(), Botan::Lion::Lion(), Botan::Randpool::Randpool(), and Botan::EAX_Base::valid_keylength().

52 {
53 return key_spec().valid_keylength(length);
54 }
Botan::SymmetricAlgorithm::key_spec
virtual Key_Length_Specification key_spec() const =0
Botan::Key_Length_Specification::valid_keylength
bool valid_keylength(size_t length) const
Definition: key_spec.h:51

The documentation for this class was generated from the following files:

- src/block/rc2/rc2.h
- src/block/rc2/rc2.cpp