openGPMP
Open Source Mathematics Package
rc5.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 RC5_HPP
35 #define RC5_HPP
36 
37 #include <cstdint>
38 #include <vector>
39 
40 namespace gpmp {
41 
42 namespace nt {
43 
47 class RC5 {
48  public:
56  RC5(uint32_t rounds = 12, uint32_t wordSize = 32, uint32_t blockSize = 16);
57 
64  void encrypt(uint32_t &A, uint32_t &B);
65 
72  void decrypt(uint32_t &A, uint32_t &B);
73 
74  private:
75  uint32_t rotl(uint32_t value, uint32_t shift);
76  uint32_t rotr(uint32_t value, uint32_t shift);
77  void init();
78 
79  uint32_t w, r, b;
80  std::vector<uint32_t> S;
81 
82  const uint32_t P = 0xB7E15163;
83  const uint32_t Q = 0x9E3779B9;
84 };
85 
86 } // namespace nt
87 
88 } // namespace gpmp
89 
90 #endif
RC5 encryption and decryption class.
Definition: rc5.hpp:47
uint32_t r
Definition: rc5.hpp:79
uint32_t w
Definition: rc5.hpp:79
uint32_t rotr(uint32_t value, uint32_t shift)
Definition: rc5.cpp:71
const uint32_t P
Definition: rc5.hpp:82
uint32_t b
Definition: rc5.hpp:79
void decrypt(uint32_t &A, uint32_t &B)
Decrypts the given block.
Definition: rc5.cpp:58
void encrypt(uint32_t &A, uint32_t &B)
Encrypts the given block.
Definition: rc5.cpp:49
const uint32_t Q
Definition: rc5.hpp:83
void init()
Definition: rc5.cpp:41
RC5(uint32_t rounds=12, uint32_t wordSize=32, uint32_t blockSize=16)
Constructs an RC5 object.
Definition: rc5.cpp:36
std::vector< uint32_t > S
Definition: rc5.hpp:80
uint32_t rotl(uint32_t value, uint32_t shift)
Definition: rc5.cpp:67
The source C++ openGPMP namespace.
list A
Definition: linalg.py:22
list B
Definition: linalg.py:23