-
Notifications
You must be signed in to change notification settings - Fork 63
/
DES.h
61 lines (49 loc) · 1.91 KB
/
DES.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//
/* Unlicensed original code taken from https://github.com/mimoo/DES
* Original contributors:
* - David Wong, [email protected]
* - Jacques Monin, [email protected]
* - Hugo Bonnin, [email protected]
*
* Additional modifications by: Charles Hubain <[email protected]>
*/
// Implementation of DES coded by:
// - David Wong, [email protected]
// - Jacques Monin, [email protected]
// - Hugo Bonnin, [email protected]
//
#include <inttypes.h>
#include <stdbool.h>
#ifndef DES_H
#define DES_H
//////////////////////////////////////////////////////
// USEFUL DEFINES //
////////////////////////////////////////////////////
#define FIRSTBIT 0x8000000000000000 // 1000000000...
//////////////////////////////////////////////////////
// PROTOTYPES //
////////////////////////////////////////////////////
// Addbit helper
// Takes the bit number "position_from" from "from"
// adds it to "block" in position "position_to"
void addbit(uint64_t *block, uint64_t from,
int position_from, int position_to);
// Initial and Final Permutations
void Permutation(uint64_t* data, bool initial);
// Verify if the parity bits are okay
bool key_parity_verify(uint64_t key);
// Key Schedule ( http://en.wikipedia.org/wiki/File:DES-key-schedule.png )
// input :
// * encrypt : false if decryption
// * next_key : uint64_t next_key 0
// * round : [[0, 15]]
// changes :
// * [key] is good to be used in the XOR in the rounds
// * [next_key] is the combined leftkey+rightkey to be used
// in the key_schedule for next round
void key_schedule(uint64_t* key, uint64_t* next_key, int round);
/* Reverse the key schedule from a round key and gives the 256 possible keys as output.
*/
void reverse_key_schedule(uint64_t round_key, int round, uint64_t* possible_keys);
void rounds(uint64_t *data, uint64_t key);
#endif