openGPMP
Open Source Mathematics Package
Public Member Functions | Private Member Functions | Private Attributes | List of all members
gpmp::nt::RC5 Class Reference

RC5 encryption and decryption class. More...

#include <rc5.hpp>

Public Member Functions

 RC5 (uint32_t rounds=12, uint32_t wordSize=32, uint32_t blockSize=16)
 Constructs an RC5 object. More...
 
void encrypt (uint32_t &A, uint32_t &B)
 Encrypts the given block. More...
 
void decrypt (uint32_t &A, uint32_t &B)
 Decrypts the given block. More...
 

Private Member Functions

uint32_t rotl (uint32_t value, uint32_t shift)
 
uint32_t rotr (uint32_t value, uint32_t shift)
 
void init ()
 

Private Attributes

uint32_t w
 
uint32_t r
 
uint32_t b
 
std::vector< uint32_t > S
 
const uint32_t P = 0xB7E15163
 
const uint32_t Q = 0x9E3779B9
 

Detailed Description

RC5 encryption and decryption class.

Definition at line 47 of file rc5.hpp.

Constructor & Destructor Documentation

◆ RC5()

gpmp::nt::RC5::RC5 ( uint32_t  rounds = 12,
uint32_t  wordSize = 32,
uint32_t  blockSize = 16 
)

Constructs an RC5 object.

Parameters
roundsNumber of rounds
wordSizeSize of the word in bits
blockSizeSize of the block in bytes

Definition at line 36 of file rc5.cpp.

37  : w(wordSize), r(rounds), b(blockSize) {
38  init();
39 }
uint32_t r
Definition: rc5.hpp:79
uint32_t w
Definition: rc5.hpp:79
uint32_t b
Definition: rc5.hpp:79
void init()
Definition: rc5.cpp:41

References init().

Member Function Documentation

◆ decrypt()

void gpmp::nt::RC5::decrypt ( uint32_t &  A,
uint32_t &  B 
)

Decrypts the given block.

Parameters
AFirst half of the block
BSecond half of the block

Definition at line 58 of file rc5.cpp.

58  {
59  for (uint32_t i = r; i > 0; --i) {
60  B = rotr(B - S[2 * i + 1], A) ^ A;
61  A = rotr(A - S[2 * i], B) ^ B;
62  }
63  B -= S[1];
64  A -= S[0];
65 }
uint32_t rotr(uint32_t value, uint32_t shift)
Definition: rc5.cpp:71
std::vector< uint32_t > S
Definition: rc5.hpp:80
list A
Definition: linalg.py:22
list B
Definition: linalg.py:23

References python.linalg::A, and python.linalg::B.

◆ encrypt()

void gpmp::nt::RC5::encrypt ( uint32_t &  A,
uint32_t &  B 
)

Encrypts the given block.

Parameters
AFirst half of the block
BSecond half of the block

Definition at line 49 of file rc5.cpp.

49  {
50  A += S[0];
51  B += S[1];
52  for (uint32_t i = 1; i <= r; ++i) {
53  A = rotl((A ^ B), B) + S[2 * i];
54  B = rotl((B ^ A), A) + S[2 * i + 1];
55  }
56 }
uint32_t rotl(uint32_t value, uint32_t shift)
Definition: rc5.cpp:67

References python.linalg::A, and python.linalg::B.

◆ init()

void gpmp::nt::RC5::init ( )
private

Definition at line 41 of file rc5.cpp.

41  {
42  S.resize(2 * r + 2);
43  S[0] = P;
44  for (uint32_t i = 1; i < 2 * r + 2; ++i) {
45  S[i] = S[i - 1] + Q;
46  }
47 }
const uint32_t P
Definition: rc5.hpp:82
const uint32_t Q
Definition: rc5.hpp:83

Referenced by RC5().

◆ rotl()

uint32_t gpmp::nt::RC5::rotl ( uint32_t  value,
uint32_t  shift 
)
private

Definition at line 67 of file rc5.cpp.

67  {
68  return (value << shift) | (value >> (w - shift));
69 }

◆ rotr()

uint32_t gpmp::nt::RC5::rotr ( uint32_t  value,
uint32_t  shift 
)
private

Definition at line 71 of file rc5.cpp.

71  {
72  return (value >> shift) | (value << (w - shift));
73 }

Member Data Documentation

◆ b

uint32_t gpmp::nt::RC5::b
private

Definition at line 79 of file rc5.hpp.

◆ P

const uint32_t gpmp::nt::RC5::P = 0xB7E15163
private

Definition at line 82 of file rc5.hpp.

◆ Q

const uint32_t gpmp::nt::RC5::Q = 0x9E3779B9
private

Definition at line 83 of file rc5.hpp.

◆ r

uint32_t gpmp::nt::RC5::r
private

Definition at line 79 of file rc5.hpp.

◆ S

std::vector<uint32_t> gpmp::nt::RC5::S
private

Definition at line 80 of file rc5.hpp.

◆ w

uint32_t gpmp::nt::RC5::w
private

Definition at line 79 of file rc5.hpp.


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