openGPMP
Open Source Mathematics Package
rc4.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 
53 #ifndef RC4_H
54 #define RC4_H
55 #include <stdint.h>
56 #include <stdio.h>
57 #include <stdlib.h>
58 #include <string.h>
59 #include <string>
60 
61 // (2^8)-1, bitmask for a byte
62 #define BITS 255
63 #define BYTE_LIMIT 256
64 
65 namespace gpmp {
66 
71 class RC4 {
72  public:
73  /* swaps two values using uint8_t type */
74  void byte_swap(uint8_t *a, uint8_t *b);
75  /* swaps two values in a traditional way using chars */
76  void trad_swap(unsigned char *a, unsigned char *b);
77  /* swaps two values using the XOR operator */
78  void XOR_swap(unsigned char *a, unsigned char *b);
79  /* Key Scheduling Algorithm */
80  void KSA(char *key, unsigned char *S, int swap_type);
81  /* Pseudo-Random Generation Algorithm */
82  void PRGA(unsigned char *S,
83  char *plaintext,
84  unsigned char *ciphertext,
85  int swap_type);
86  /* function to display our hashed text */
87  std::string
88  store_hash(char *plaintext, unsigned char *hashtext, int swap_type);
89  /* compute our hash using the the RC4 encryption algorithm */
90  unsigned char *
91  compute(char *key, char *plaintext, unsigned char *hashtext, int swap_type);
92 };
93 
94 } // namespace gpmp
95 
96 #endif
void PRGA(unsigned char *S, char *plaintext, unsigned char *ciphertext, int swap_type)
Definition: rc4.cpp:90
std::string store_hash(char *plaintext, unsigned char *hashtext, int swap_type)
Definition: rc4.cpp:117
void XOR_swap(unsigned char *a, unsigned char *b)
Definition: rc4.cpp:62
void byte_swap(uint8_t *a, uint8_t *b)
Definition: rc4.cpp:49
void trad_swap(unsigned char *a, unsigned char *b)
Definition: rc4.cpp:56
unsigned char * compute(char *key, char *plaintext, unsigned char *hashtext, int swap_type)
Definition: rc4.cpp:142
void KSA(char *key, unsigned char *S, int swap_type)
Definition: rc4.cpp:68
The source C++ openGPMP namespace.