-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdes.c
More file actions
81 lines (67 loc) · 1.47 KB
/
des.c
File metadata and controls
81 lines (67 loc) · 1.47 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* Copyright (C) 2011 <fwhacking|gmail:com>
*
* This is free software, licensed under the GNU General Public License v2.
* See /LICENSE for more information.
*
*/
#include <stddef.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "bfcrypt.h"
#include "des.h"
int find_des(char *base, size_t offset)
{
unsigned int i;
for (i = 0; i < 2; i++)
{
if (find_des_keyswap(base + offset, i) == 0)
{
printf("DES Keyswap (0x%08x) found at 0x%08lx\n", DES_KEYSWAP[i][0], (unsigned long) offset);
}
}
for (i = 0; i < 8; i++)
{
if (find_des_sbox(base + offset, i) == 0)
{
printf("DES S-box[%d] (0x%08x) found at 0x%08lx\n", i, DES_SBOX[i][0], (unsigned long) offset);
}
}
return 0;
}
int find_des_keyswap(char *p, int n)
{
int ret = -1;
unsigned int i;
if (memcmp(DES_KEYSWAP[n], p, sizeof(DES_KEYSWAP[n][0])) == 0)
{
ret = 0;
for (i = 0; i < sizeof(DES_KEYSWAP[n]) / sizeof(DES_KEYSWAP[n][0]); i++)
{
if (memcmp(&(DES_KEYSWAP[n][i]), p + i * sizeof(DES_KEYSWAP[n][0]), sizeof(DES_KEYSWAP[n][0])) != 0)
{
ret = -1;
}
}
}
return ret;
}
int find_des_sbox(char *p, int n)
{
int ret = -1;
unsigned int i;
if (memcmp(DES_SBOX[n], p, sizeof(DES_SBOX[n][0])) == 0)
{
ret = 0;
for (i = 0; i < sizeof(DES_SBOX[n]) / sizeof(DES_SBOX[n][0]); i++)
{
if (memcmp(&(DES_SBOX[n][i]), p + i * sizeof(DES_SBOX[n][0]), sizeof(DES_SBOX[n][0])) != 0)
{
ret = -1;
}
}
}
return ret;
}