openGPMP
Open Source Mathematics Package
rc6.hpp
Go to the documentation of this file.
1 /*************************************************************************
2  *
3  * Project
4  * _____ _____ __ __ _____
5  * / ____| __ \| \/ | __ \
6  * ___ _ __ ___ _ __ | | __| |__) | \ / | |__) |
7  * / _ \| '_ \ / _ \ '_ \| | |_ | ___/| |\/| | ___/
8  *| (_) | |_) | __/ | | | |__| | | | | | | |
9  * \___/| .__/ \___|_| |_|\_____|_| |_| |_|_|
10  * | |
11  * |_|
12  *
13  * Copyright (C) Akiel Aries, <akiel@akiel.org>, et al.
14  *
15  * This software is licensed as described in the file LICENSE, which
16  * you should have received as part of this distribution. The terms
17  * among other details are referenced in the official documentation
18  * seen here : https://akielaries.github.io/openGPMP/ along with
19  * important files seen in this project.
20  *
21  * You may opt to use, copy, modify, merge, publish, distribute
22  * and/or sell copies of the Software, and permit persons to whom
23  * the Software is furnished to do so, under the terms of the
24  * LICENSE file. As this is an Open Source effort, all implementations
25  * must be of the same methodology.
26  *
27  *
28  *
29  * This software is distributed on an AS IS basis, WITHOUT
30  * WARRANTY OF ANY KIND, either express or implied.
31  *
32  ************************************************************************/
33 
34 #ifndef RC6_HPP
35 #define RC6_HPP
36 
37 #include <cstdint>
38 #include <vector>
39 
44 class RC6 {
45  public:
50  RC6(const std::vector<uint8_t> &key);
51 
57  std::vector<uint8_t> encrypt(const std::vector<uint8_t> &plaintext);
58 
64  std::vector<uint8_t> decrypt(const std::vector<uint8_t> &ciphertext);
65 
66  private:
67  const int w = 32;
68  const int r = 20;
69  const int b = 16;
71  std::vector<uint32_t> S;
77  void key_schedule(const std::vector<uint8_t> &key);
78 
84  std::vector<uint32_t> expand(const std::vector<uint8_t> &key);
85 
92  uint32_t rotl(uint32_t val, int shift);
93 
100  uint32_t rotr(uint32_t val, int shift);
101 
107  void encrypt_block(const uint32_t plaintext[2], uint32_t ciphertext[2]);
108 
114  void decrypt_block(const uint32_t ciphertext[2], uint32_t plaintext[2]);
115 };
116 
117 #endif
Class implementing the RC6 cipher algorithm.
Definition: rc6.hpp:44
std::vector< uint8_t > encrypt(const std::vector< uint8_t > &plaintext)
Encrypts plaintext using RC6 algorithm.
Definition: rc6.cpp:100
std::vector< uint32_t > expand(const std::vector< uint8_t > &key)
Performs key expansion.
Definition: rc6.cpp:60
std::vector< uint8_t > decrypt(const std::vector< uint8_t > &ciphertext)
Decrypts ciphertext using RC6 algorithm.
Definition: rc6.cpp:125
void key_schedule(const std::vector< uint8_t > &key)
Generates the key schedule from the given key.
Definition: rc6.cpp:41
const int r
Definition: rc6.hpp:68
const int b
Definition: rc6.hpp:69
std::vector< uint32_t > S
Definition: rc6.hpp:71
uint32_t rotl(uint32_t val, int shift)
Performs left rotation.
Definition: rc6.cpp:68
void decrypt_block(const uint32_t ciphertext[2], uint32_t plaintext[2])
Decrypts a single block of ciphertext.
Definition: rc6.cpp:88
void encrypt_block(const uint32_t plaintext[2], uint32_t ciphertext[2])
Encrypts a single block of plaintext.
Definition: rc6.cpp:76
RC6(const std::vector< uint8_t > &key)
Constructor for RC6 class.
Definition: rc6.cpp:37
const int w
Definition: rc6.hpp:67
uint32_t rotr(uint32_t val, int shift)
Performs right rotation.
Definition: rc6.cpp:72