forked from MatthewGaber/ESP8266BitcoinMiner
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBitcoinTests.ino
More file actions
62 lines (47 loc) · 1.46 KB
/
Copy pathBitcoinTests.ino
File metadata and controls
62 lines (47 loc) · 1.46 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
#include <SPI.h>
#include "Crypto.h"
#include <stdint.h>
SHA256 hasher;
SHA256 hashagain;
char header_hex[] = "0100000081cd02ab7e569e8bcd9317e2fe99f2de44d49ab2b8851ba4a308000000000000e320b6c2fffc8d750423db8b1eb942ae710e951ed797f7affc8892b0f1fc122bc7f5d74df2b9441a42a14695";
uint8_t hashbytes[80];
uint8_t* hex_decode(const char *in, size_t len, uint8_t *out)
{
unsigned int i, mg, ng, rg;
for (mg = 0, i = 0; i < len; i+=2,++mg){
ng = in[i] > '9' ? in[i] - 'a' + 10 : in[i] - '0';
rg = in[i+1] > '9' ? in[i+1] - 'a' + 10 : in[i+1] - '0';
out[mg] = (ng << 4 ) | rg;
}
return out;
}
void hash(){
hex_decode(header_hex,strlen(header_hex),hashbytes);
unsigned long start = micros();
hasher.doUpdate(hashbytes, sizeof(hashbytes));
byte hash[SHA256_SIZE];
hasher.doFinal(hash);
hashagain.doUpdate(hash, sizeof(hash));
byte hash2[SHA256_SIZE];
hashagain.doFinal(hash2);
unsigned long ended = micros();
unsigned long delta = ended - start;
Serial.println(delta);
Serial.print("Big Endian: ");
for (byte i=32; i > 0; i--){
if (hash2[i-1]<0x10) { Serial.print('0'); }
Serial.print(hash2[i-1], HEX);
}
Serial.println();
Serial.print("Little Endian: ");
for (byte i=0; i < SHA256_SIZE ; i++){
if (hash2[i]<0x10) { Serial.print('0'); }
Serial.print(hash2[i], HEX);
}
}
void setup() {
Serial.begin(115200);
hash();
}
void loop() {
}