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

Class for encryption and decryption using the RedPike algorithm. More...

#include <redpike.hpp>

Public Member Functions

void encrypt (uint32_t *x, const uint32_t *k)
 Encrypts the given data using the RedPike algorithm. More...
 
void decrypt (uint32_t *x, const uint32_t *k)
 Decrypts the given data using the RedPike algorithm. More...
 

Private Member Functions

uint32_t rotl (uint32_t X, int R)
 Performs left rotation on the given value. More...
 
uint32_t rotr (uint32_t X, int R)
 Performs right rotation on the given value. More...
 

Private Attributes

uint32_t CONST = 0x9E3779B9
 Constant value used in the RedPike algorithm. More...
 
int ROUNDS = 16
 Number of rounds in the RedPike algorithm. More...
 

Detailed Description

Class for encryption and decryption using the RedPike algorithm.

Definition at line 48 of file redpike.hpp.

Member Function Documentation

◆ decrypt()

void gpmp::nt::RedPike::decrypt ( uint32_t *  x,
const uint32_t *  k 
)

Decrypts the given data using the RedPike algorithm.

Parameters
xPointer to the data to be decrypted
kPointer to the key used for decryption

Definition at line 70 of file redpike.cpp.

70  {
71  uint32_t dk[2] = {k[1] - CONST * (ROUNDS + 1), k[0] + CONST * (ROUNDS + 1)};
72 
73  encrypt(x, dk);
74 }
uint32_t CONST
Constant value used in the RedPike algorithm.
Definition: redpike.hpp:70
int ROUNDS
Number of rounds in the RedPike algorithm.
Definition: redpike.hpp:75
void encrypt(uint32_t *x, const uint32_t *k)
Encrypts the given data using the RedPike algorithm.
Definition: redpike.cpp:48

◆ encrypt()

void gpmp::nt::RedPike::encrypt ( uint32_t *  x,
const uint32_t *  k 
)

Encrypts the given data using the RedPike algorithm.

Parameters
xPointer to the data to be encrypted
kPointer to the key used for encryption

Definition at line 48 of file redpike.cpp.

48  {
49  uint32_t rk0 = k[0];
50  uint32_t rk1 = k[1];
51 
52  for (int i = 0; i < ROUNDS; i++) {
53  rk0 += CONST;
54  rk1 -= CONST;
55 
56  x[0] ^= rk0;
57  x[0] += x[1];
58  x[0] = rotl(x[0], x[1]);
59 
60  x[1] = rotr(x[1], x[0]);
61  x[1] -= x[0];
62  x[1] ^= rk1;
63  }
64 
65  rk0 = x[0];
66  x[0] = x[1];
67  x[1] = rk0;
68 }
uint32_t rotl(uint32_t X, int R)
Performs left rotation on the given value.
Definition: redpike.cpp:40
uint32_t rotr(uint32_t X, int R)
Performs right rotation on the given value.
Definition: redpike.cpp:44

◆ rotl()

uint32_t gpmp::nt::RedPike::rotl ( uint32_t  X,
int  R 
)
private

Performs left rotation on the given value.

Parameters
XValue to be rotated
RNumber of bits to rotate left by
Returns
Rotated value

Definition at line 40 of file redpike.cpp.

40  {
41  return ((X) << ((R)&31)) | ((X) >> (32 - ((R)&31)));
42 }

◆ rotr()

uint32_t gpmp::nt::RedPike::rotr ( uint32_t  X,
int  R 
)
private

Performs right rotation on the given value.

Parameters
XValue to be rotated
RNumber of bits to rotate right by
Returns
Rotated value

Definition at line 44 of file redpike.cpp.

44  {
45  return ((X) >> ((R)&31)) | ((X) << (32 - ((R)&31)));
46 }

Member Data Documentation

◆ CONST

uint32_t gpmp::nt::RedPike::CONST = 0x9E3779B9
private

Constant value used in the RedPike algorithm.

Definition at line 70 of file redpike.hpp.

◆ ROUNDS

int gpmp::nt::RedPike::ROUNDS = 16
private

Number of rounds in the RedPike algorithm.

Definition at line 75 of file redpike.hpp.


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