openGPMP
Open Source Mathematics Package
|
Class implementing the RC6 cipher algorithm. More...
#include <rc6.hpp>
Public Member Functions | |
RC6 (const std::vector< uint8_t > &key) | |
Constructor for RC6 class. More... | |
std::vector< uint8_t > | encrypt (const std::vector< uint8_t > &plaintext) |
Encrypts plaintext using RC6 algorithm. More... | |
std::vector< uint8_t > | decrypt (const std::vector< uint8_t > &ciphertext) |
Decrypts ciphertext using RC6 algorithm. More... | |
Private Member Functions | |
void | key_schedule (const std::vector< uint8_t > &key) |
Generates the key schedule from the given key. More... | |
std::vector< uint32_t > | expand (const std::vector< uint8_t > &key) |
Performs key expansion. More... | |
uint32_t | rotl (uint32_t val, int shift) |
Performs left rotation. More... | |
uint32_t | rotr (uint32_t val, int shift) |
Performs right rotation. More... | |
void | encrypt_block (const uint32_t plaintext[2], uint32_t ciphertext[2]) |
Encrypts a single block of plaintext. More... | |
void | decrypt_block (const uint32_t ciphertext[2], uint32_t plaintext[2]) |
Decrypts a single block of ciphertext. More... | |
Private Attributes | |
const int | w = 32 |
const int | r = 20 |
const int | b = 16 |
std::vector< uint32_t > | S |
RC6::RC6 | ( | const std::vector< uint8_t > & | key | ) |
Constructor for RC6 class.
key | The encryption key |
Definition at line 37 of file rc6.cpp.
References key_schedule().
std::vector< uint8_t > RC6::decrypt | ( | const std::vector< uint8_t > & | ciphertext | ) |
Decrypts ciphertext using RC6 algorithm.
ciphertext | The ciphertext to decrypt |
Definition at line 125 of file rc6.cpp.
References decrypt_block().
|
private |
Decrypts a single block of ciphertext.
ciphertext | The ciphertext block to decrypt |
plaintext | The resulting plaintext block |
Definition at line 88 of file rc6.cpp.
References python.linalg::A, python.linalg::B, r, rotr(), and S.
Referenced by decrypt().
std::vector< uint8_t > RC6::encrypt | ( | const std::vector< uint8_t > & | plaintext | ) |
Encrypts plaintext using RC6 algorithm.
plaintext | The plaintext to encrypt |
Definition at line 100 of file rc6.cpp.
References encrypt_block().
|
private |
Encrypts a single block of plaintext.
plaintext | The plaintext block to encrypt |
ciphertext | The resulting ciphertext block |
Definition at line 76 of file rc6.cpp.
References python.linalg::A, python.linalg::B, r, rotl(), and S.
Referenced by encrypt().
|
private |
Performs key expansion.
key | The encryption key |
Definition at line 60 of file rc6.cpp.
References b.
Referenced by key_schedule().
|
private |
Generates the key schedule from the given key.
key | The encryption key |
Definition at line 41 of file rc6.cpp.
References python.linalg::A, b, python.linalg::B, expand(), r, rotl(), and S.
Referenced by RC6().
|
private |
Performs left rotation.
val | The value to rotate |
shift | The number of bits to rotate by |
Definition at line 68 of file rc6.cpp.
References w.
Referenced by encrypt_block(), and key_schedule().
|
private |
Performs right rotation.
val | The value to rotate |
shift | The number of bits to rotate by |
Definition at line 72 of file rc6.cpp.
References w.
Referenced by decrypt_block().
|
private |
Number of bytes in key
Definition at line 69 of file rc6.hpp.
Referenced by expand(), and key_schedule().
|
private |
Number of rounds
Definition at line 68 of file rc6.hpp.
Referenced by decrypt_block(), encrypt_block(), and key_schedule().
|
private |
Internal state array
Definition at line 71 of file rc6.hpp.
Referenced by decrypt_block(), encrypt_block(), and key_schedule().
|
private |