Horizon Official Technical Documentation
DES.hpp
Go to the documentation of this file.
1/***************************************************
2 * _ _ _ *
3 * | | | | (_) *
4 * | |_| | ___ _ __ _ _______ _ __ *
5 * | _ |/ _ \| '__| |_ / _ \| '_ \ *
6 * | | | | (_) | | | |/ / (_) | | | | *
7 * \_| |_/\___/|_| |_/___\___/|_| |_| *
8 ***************************************************
9 * This file is part of Horizon (c).
10 * Copyright (c) 2019 Sagun K. (sagunxp@gmail.com).
11 * Copyright (c) 2019 Horizon Dev Team.
12 *
13 * Base Author - Sagun K. (sagunxp@gmail.com)
14 *
15 * This library is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation, either version 3 of the License, or
18 * (at your option) any later version.
19 *
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this library. If not, see <http://www.gnu.org/licenses/>.
27 **************************************************/
28
29#ifndef HORIZON_LIBRARIES_GRF_DES_HPP
30#define HORIZON_LIBRARIES_GRF_DES_HPP
31
32#include <cstdint>
33#include <cstddef>
34
35#define USE_OPENSSL_DES 0
36
37#if USE_OPENSSL_DES
38#include <openssl/des.h>
39#else
40
42typedef struct BIT64 { uint8_t b[8]; } BIT64;
43#endif
44
45class DES
46{
47public:
48#if USE_OPENSSL_DES
49 DES(const unsigned char *key);
50
51 void decryptBlock(DES_cblock *block);
52 void decrypt(unsigned char *data, size_t size);
53
54#else
55 void decryptBlock(BIT64 *block);
56 void decrypt(unsigned char *data, size_t size);
57 void roundFunction(BIT64 *src);
58 void SBOX(BIT64 *src);
59 void E(BIT64* src);
60 void TP(BIT64 *src);
61 void IP(BIT64 *src);
62 void FP(BIT64 *src);
63#endif
64#if USE_OPENSSL_DES
65 DES_key_schedule _schedule;
66#endif
67};
68
69
70#endif // HORIZON_LIBRARIES_GRF_DES_HPP
struct BIT64 BIT64
One 64-bit block.
Definition: DES.hpp:46
void roundFunction(BIT64 *src)
DES round function. XORs src[0..3] with TP(SBOX(E(src[4..7]))).
Definition: DES.cpp:194
void decryptBlock(BIT64 *block)
Definition: DES.cpp:208
void TP(BIT64 *src)
Transposition (P-BOX).
Definition: DES.cpp:167
void decrypt(unsigned char *data, size_t size)
Definition: DES.cpp:215
void IP(BIT64 *src)
Initial permutation (IP).
Definition: DES.cpp:76
void FP(BIT64 *src)
Final permutation (IP^-1).
Definition: DES.cpp:104
void SBOX(BIT64 *src)
Definition: DES.cpp:130
void E(BIT64 *src)
Expansion (E). Expands upper four 8-bits (32b) into eight 6-bits (48b).
Definition: DES.cpp:54
One 64-bit block.
Definition: DES.hpp:42
uint8_t b[8]
Definition: DES.hpp:42