-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsha256.c
More file actions
73 lines (60 loc) · 1.4 KB
/
sha256.c
File metadata and controls
73 lines (60 loc) · 1.4 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
/*
* 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 "sha256.h"
int find_sha256(char *base, size_t offset)
{
if (find_sha256_init(base + offset) == 0)
{
printf("SHA256 Init (0x%08x) found at 0x%08lx\n", SHA256_INIT[0], (unsigned long) offset);
}
if (find_sha256_constants(base + offset) == 0)
{
printf("SHA256 Constants (0x%08x) found at 0x%08lx\n", SHA256_CONSTANTS[0], (unsigned long) offset);
}
return 0;
}
int find_sha256_init(char *p)
{
int ret = -1;
unsigned int i;
if (memcmp(SHA256_INIT, p, sizeof(SHA256_INIT[0])) == 0)
{
ret = 0;
for (i = 0; i < sizeof(SHA256_INIT) / sizeof(SHA256_INIT[0]); i++)
{
if (memcmp(&SHA256_INIT[i], p + i * sizeof(SHA256_INIT[0]), sizeof(SHA256_INIT[0])) != 0)
{
ret = -1;
}
}
}
return ret;
}
int find_sha256_constants(char *p)
{
int ret = -1;
unsigned int i;
if (memcmp(SHA256_CONSTANTS, p, sizeof(SHA256_CONSTANTS[0])) == 0)
{
ret = 0;
for (i = 0; i < sizeof(SHA256_CONSTANTS) / sizeof(SHA256_CONSTANTS[0]); i++)
{
if (memcmp(&SHA256_CONSTANTS[i], p + i * sizeof(SHA256_CONSTANTS[0]), sizeof(SHA256_CONSTANTS[0])) != 0)
{
ret = -1;
}
}
}
return ret;
}