forked from BitzenyCoreDevelopers/cpuminer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsha2-x86-notextrel-test.c
81 lines (64 loc) · 1.94 KB
/
sha2-x86-notextrel-test.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
#include<stdio.h>
#include<stdint.h>
#include<stdlib.h>
#define STATE_NUM 32
int sha256_use_4way();
void sha256_init_4way(uint32_t *state);
void sha256_transform_4way(uint32_t *state, const uint32_t *block, int swap);
void sha256d_ms_4way(uint32_t *hash, uint32_t *data, const uint32_t *midstate, const uint32_t *prehash);
void test_sha256_use_4way() {
printf("%d\n", sha256_use_4way());
}
void test_sha256_init_4way() {
uint32_t state[STATE_NUM];
sha256_init_4way(state);
for(int i = 0; i < STATE_NUM; i++) {
printf("%08x", state[i]);
}
printf("\n");
}
void test_sha256_transform_4way() {
uint32_t state[STATE_NUM] __attribute__((aligned(128))) = { 0 };
uint32_t block[STATE_NUM] __attribute__((aligned(128))) = { 0 };
for (int i = 0; i < STATE_NUM; i++) {
state[i] = rand();
block[i] = rand();
}
sha256_transform_4way(state, block, 0);
for(int i = 0; i < STATE_NUM; i++) {
printf("%08x ", state[i]);
}
printf("\n");
}
void test_sha256d_ms_4way() {
uint32_t hash[STATE_NUM] __attribute__((aligned(32))) = { 0 };
uint32_t data[8 * STATE_NUM] __attribute__((aligned(128))) = { 0 };
uint32_t midstate[STATE_NUM] __attribute__((aligned(32))) = { 0 };
uint32_t prehash[STATE_NUM] __attribute__((aligned(32))) = { 0 };
for (int i = 0; i < STATE_NUM; i++) {
hash[i] = rand();
midstate[i] = rand();
prehash[i] = rand();
}
for (int i = 0; i < 8 * STATE_NUM; i++) {
data[i] = rand();
}
sha256d_ms_4way(hash, data, midstate, prehash);
for(int i = 0; i < STATE_NUM; i++) {
printf("%08x ", hash[i]);
}
printf("\n");
for(int i = 0; i < 8 * STATE_NUM; i++) {
printf("%08x ", data[i]);
}
printf("\n");
}
int main() {
test_sha256_use_4way();
test_sha256_init_4way();
for (int i = 0; i < 100; i++) {
test_sha256_transform_4way();
test_sha256d_ms_4way();
}
return 0;
}