Botan 1.10.17
Botan::RC2 Class Reference

#include <rc2.h>

Inheritance diagram for Botan::RC2:
Botan::Block_Cipher_Fixed_Params< 8, 1, 32 > Botan::BlockCipher Botan::SymmetricAlgorithm Botan::Algorithm

Public Types

enum  

Public Member Functions

size_t block_size () const
void clear ()
BlockCipherclone () const
void decrypt (byte block[]) const
void decrypt (const byte in[], byte out[]) const
void decrypt_n (const byte in[], byte out[], size_t blocks) const
void encrypt (byte block[]) const
void encrypt (const byte in[], byte 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
 RC2 ()
void set_key (const byte key[], size_t length)
void set_key (const SymmetricKey &key)
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

anonymous enum
inherited

Definition at line 107 of file block_cipher.h.

Constructor & Destructor Documentation

◆ RC2()

Botan::RC2::RC2 ( )
inline

Definition at line 35 of file rc2.h.

35: K(64) {}

Referenced by clone().

Member Function Documentation

◆ block_size()

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; }

◆ clear()

void Botan::RC2::clear ( )
inlinevirtual

Zeroize internal state

Implements Botan::Algorithm.

Definition at line 31 of file rc2.h.

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

References Botan::zeroise().

◆ clone()

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; }
RC2()
Definition rc2.h:35

References RC2().

◆ decrypt() [1/2]

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

Decrypt a block.

Parameters
blockthe 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); }

◆ decrypt() [2/2]

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

Decrypt a block.

Parameters
inThe ciphertext block to be decypted as a byte array. Must be of length block_size().
outThe byte array designated to hold the decrypted block. Must be of length block_size().

Definition at line 57 of file block_cipher.h.

58 { decrypt_n(in, out, 1); }

◆ decrypt_n()

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

Decrypt one or more blocks

Parameters
inthe input buffer (multiple of block_size())
outthe output buffer (same size as in)
blocksthe number of blocks to process

Implements Botan::BlockCipher.

Definition at line 59 of file rc2.cpp.

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 }
#define R0
Definition asm_x86_64.h:51
#define R3
Definition asm_x86_64.h:55
#define R2
Definition asm_x86_64.h:53
#define R1
Definition asm_x86_64.h:52
u16bit load_le< u16bit >(const byte in[], size_t off)
Definition loadstor.h:149
T rotate_right(T input, size_t rot)
Definition rotate.h:34
unsigned short u16bit
Definition types.h:27
void store_le(u16bit in, byte out[2])
Definition loadstor.h:427

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

◆ EKB_code()

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

Return the code of the effective key bits

Parameters
bitskey 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, 0x4D, 0x9E, 0xDA, 0xA0, 0x68, 0x2C, 0xC3, 0x27, 0x5F, 0x80, 0x36,
151 0x3E, 0xEE, 0xFB, 0x95, 0x1A, 0xFE, 0xCE, 0xA8, 0x34, 0xA9, 0x13, 0xF0,
152 0xA6, 0x3F, 0xD8, 0x0C, 0x78, 0x24, 0xAF, 0x23, 0x52, 0xC1, 0x67, 0x17,
153 0xF5, 0x66, 0x90, 0xE7, 0xE8, 0x07, 0xB8, 0x60, 0x48, 0xE6, 0x1E, 0x53,
154 0xF3, 0x92, 0xA4, 0x72, 0x8C, 0x08, 0x15, 0x6E, 0x86, 0x00, 0x84, 0xFA,
155 0xF4, 0x7F, 0x8A, 0x42, 0x19, 0xF6, 0xDB, 0xCD, 0x14, 0x8D, 0x50, 0x12,
156 0xBA, 0x3C, 0x06, 0x4E, 0xEC, 0xB3, 0x35, 0x11, 0xA1, 0x88, 0x8E, 0x2B,
157 0x94, 0x99, 0xB7, 0x71, 0x74, 0xD3, 0xE4, 0xBF, 0x3A, 0xDE, 0x96, 0x0E,
158 0xBC, 0x0A, 0xED, 0x77, 0xFC, 0x37, 0x6B, 0x03, 0x79, 0x89, 0x62, 0xC6,
159 0xD7, 0xC0, 0xD2, 0x7C, 0x6A, 0x8B, 0x22, 0xA3, 0x5B, 0x05, 0x5D, 0x02,
160 0x75, 0xD5, 0x61, 0xE3, 0x18, 0x8F, 0x55, 0x51, 0xAD, 0x1F, 0x0B, 0x5E,
161 0x85, 0xE5, 0xC2, 0x57, 0x63, 0xCA, 0x3D, 0x6C, 0xB4, 0xC5, 0xCC, 0x70,
162 0xB2, 0x91, 0x59, 0x0D, 0x47, 0x20, 0xC8, 0x4F, 0x58, 0xE0, 0x01, 0xE2,
163 0x16, 0x38, 0xC4, 0x6F, 0x3B, 0x0F, 0x65, 0x46, 0xBE, 0x7E, 0x2D, 0x7B,
164 0x82, 0xF9, 0x40, 0xB5, 0x1D, 0x73, 0xF8, 0xEB, 0x26, 0xC7, 0x87, 0x97,
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 }
Encoding_Error(const std::string &name)
Definition exceptn.h:131

References Botan::Encoding_Error::Encoding_Error().

◆ encrypt() [1/2]

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

Encrypt a block.

Parameters
blockthe 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); }

◆ encrypt() [2/2]

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

Encrypt a block.

Parameters
inThe plaintext block to be encrypted as a byte array. Must be of length block_size().
outThe byte array designated to hold the encrypted block. Must be of length block_size().

Definition at line 47 of file block_cipher.h.

48 { encrypt_n(in, out, 1); }

◆ encrypt_n()

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

Encrypt one or more blocks

Parameters
inthe input buffer (multiple of block_size())
outthe output buffer (same size as in)
blocksthe number of blocks to process

Implements Botan::BlockCipher.

Definition at line 17 of file rc2.cpp.

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 }
T rotate_left(T input, size_t rot)
Definition rotate.h:21

References Botan::Block_Cipher_Fixed_Params< 8, 1, 32 >::BLOCK_SIZE, Botan::load_le(), R0, R1, R2, R3, Botan::rotate_left(), and Botan::store_le().

◆ key_spec()

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 {
113 }
Key_Length_Specification(size_t keylen)
Definition key_spec.h:25

◆ maximum_keylength()

size_t Botan::SymmetricAlgorithm::maximum_keylength ( ) const
inlineinherited
Returns
minimum allowed key length

Definition at line 33 of file sym_algo.h.

34 {
35 return key_spec().maximum_keylength();
36 }
size_t maximum_keylength() const
Definition sym_algo.h:33

◆ minimum_keylength()

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 }
size_t minimum_keylength() const
Definition sym_algo.h:41

◆ name()

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"; }

◆ parallel_bytes()

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 {
38 }

◆ parallelism()

virtual size_t Botan::BlockCipher::parallelism ( ) const
inlinevirtualinherited
Returns
native parallelism of this cipher in blocks

Definition at line 30 of file block_cipher.h.

30{ return 1; }

◆ set_key() [1/2]

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

Set the symmetric key of this object.

Parameters
keythe to be set as a byte array.
lengthin bytes of key param

Definition at line 68 of file sym_algo.h.

69 {
73 }
Invalid_Key_Length(const std::string &name, size_t length)
Definition exceptn.h:57

◆ set_key() [2/2]

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

Set the symmetric key of this object.

Parameters
keythe SymmetricKey to be set.

Definition at line 60 of file sym_algo.h.

61 { set_key(key.begin(), key.length()); }

◆ valid_keylength()

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

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

Parameters
lengththe key length to be checked.
Returns
true if the key length is valid.

Definition at line 51 of file sym_algo.h.

52 {
54 }
bool valid_keylength(size_t length) const
Definition sym_algo.h:51

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