-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtesthash.c
94 lines (83 loc) · 2.11 KB
/
testhash.c
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
82
83
84
85
86
87
88
89
90
91
92
93
94
#include "argon2d/argon2.h"
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
static const size_t INPUT_BYTES = 80;
static const size_t OUTPUT_BYTES = 32;
static const unsigned int DEFAULT_ARGON2_FLAG = 2;
void argon2m_hash(void* input, void* output)
{
argon2_context context;
context.out = (uint8_t *)output;
context.outlen = (uint32_t)OUTPUT_BYTES;
context.pwd = (unsigned char*)input;
context.pwdlen = (uint32_t)INPUT_BYTES;
context.salt = context.pwd;
context.saltlen = context.pwdlen;
context.secret = NULL;
context.secretlen = 0;
context.ad = NULL;
context.adlen = 0;
context.allocate_cbk = NULL;
context.free_cbk = NULL;
context.flags = DEFAULT_ARGON2_FLAG;
context.m_cost = 2;
context.lanes = 1;
context.threads = 1;
context.t_cost = 1;
context.version = ARGON2_VERSION_13;
argon2_ctx( &context, Argon2_id );
}
long grabtime()
{
struct timeval time;
gettimeofday(&time, NULL);
return time.tv_sec * 1000 + time.tv_usec / 1000;
}
int main()
{
long s1;
int w, x, y, z, hsec = 0;
unsigned char header[80];
unsigned char hash[32];
srand(time(NULL));
printf("");
for (int i=0; i<80; i++)
header[i] = rand() % 256;
uint32_t htarget, hetarget;
uint32_t best = 0xffffffff;
s1 = grabtime();
for (header[76]=0; header[76]<256; header[76]++)
{
for (header[77]=0; header[77]<256; header[77]++)
{
for (header[78]=0; header[78]<256; header[78]++)
{
for (header[79]=0; header[79]<256; header[79]++)
{
hsec++;
argon2m_hash(header,hash);
htarget = *(uint32_t*)&hash;
hetarget = ((htarget>>24)&0xff) | ((htarget<<8)&0xff0000) |
((htarget>>8)&0xff00) | ((htarget<<24)&0xff000000);
if (hetarget < best)
{
best = hetarget;
for (int i=0;i<32;i++)
printf("%02hhx",hash[i]);
printf("\n");
}
if ((grabtime()-s1) > 1000) {
printf("%d h/s\n", hsec);
s1 = grabtime();
hsec = 0;
}
}
}
}
}
return 0;
}