Error log: http://pastebin.org/84467
Code: Select all
#include <string.h>
#include "Crypto.h"
const uint32 sha256_k[] = {0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2};
struct SHA256_STATE {
uint32 h[8];
};
void sha256_transform(struct SHA256_STATE* st, byte* buf) {
uint32 w[64], s0, s1, t1, maj, ch, a = st->h[0], b = st->h[1], c = st->h[2], d = st->h[3], e = st->h[4], f = st->h[5], g = st->h[6], h = st->h[7];
uint8 j;
memcpy(w, buf, 64);
for (j = 0; j < 16; j++) {
w[j] = swap_endian_32(w[j]);
}
for (j = 16; j < 64; j++) {
s0 = ROTR(w[j - 15], 7) ^ ROTR(w[j - 15], 18) ^ (w[j - 15] >> 3);
s1 = ROTR(w[j - 2], 17) ^ ROTR(w[j - 2], 19) ^ (w[j - 2] >> 10);
w[j] = w[j - 16] + s0 + w[j - 7] + s1;
}
for (j = 0; j < 64; j++) {
s0 = ROTR(a, 2) ^ ROTR(a, 13) ^ ROTR(a, 22);
s1 = ROTR(e, 6) ^ ROTR(e, 11) ^ ROTR(e, 25);
maj = (a & b) ^ (a & c) ^ (b & c);
ch = (e & f) ^ ((~e) & g);
t1 = h + s1 + ch + sha256_k[j] + w[j];
h = g;
g = f;
f = e;
e = d + t1;
d = c;
c = b;
b = a;
a = t1 + s0 + maj;
}
st->h[0] += a;
st->h[1] += b;
st->h[2] += c;
st->h[3] += d;
st->h[4] += e;
st->h[5] += f;
st->h[6] += g;
st->h[7] += h;
}
byte* SHA224(byte* msg, uint16 length, byte* ret) {
byte buf[64];
uint32 cCount = length * 8;
uint8 i;
struct SHA256_STATE st;
st.h[0] = 0xc1059ed8;
st.h[1] = 0x367cd507;
st.h[2] = 0x3070dd17;
st.h[3] = 0xf70e5939;
st.h[4] = 0xffc00b31;
st.h[5] = 0x68581511;
st.h[6] = 0x64f98fa7;
st.h[7] = 0xbefa4fa4;
while (length > 0) {
if (length >= 64) {
sha256_transform(&st, msg);
length -= 64;
msg += 64;
} else {
memcpy(buf, msg, length);
break;
}
}
buf[length++] = (byte) 0x80;
if (length > 56) {
while (length < 64) {
buf[length++] = (byte) 0;
}
sha256_transform(&st, buf);
length = 0;
}
while (length < 56) {
buf[length++] = (byte) 0;
}
buf[length++] = 0;
buf[length++] = 0;
buf[length++] = 0;
buf[length++] = 0;
buf[length++] = ((cCount >> 24) & 0xFF);
buf[length++] = ((cCount >> 16) & 0xFF);
buf[length++] = ((cCount >> 8) & 0xFF);
buf[length++] = (cCount & 0xFF);
sha256_transform(&st, buf);
for (i = 0; i < 8; i++) {
st.h[i] = swap_endian_32(st.h[i]);
}
memcpy(ret, st.h, 28);
return ret;
}
byte* SHA256(byte* msg, uint16 length, byte* ret) {
byte buf[64];
uint32 cCount = length * 8;
uint8 i;
struct SHA256_STATE st;
st.h[0] = 0x6a09e667;
st.h[1] = 0xbb67ae85;
st.h[2] = 0x3c6ef372;
st.h[3] = 0xa54ff53a;
st.h[4] = 0x510e527f;
st.h[5] = 0x9b05688c;
st.h[6] = 0x1f83d9ab;
st.h[7] = 0x5be0cd19;
while (length > 0) {
if (length >= 64) {
sha256_transform(&st, msg);
length -= 64;
msg += 64;
} else {
memcpy(buf, msg, length);
break;
}
}
buf[length++] = (byte) 0x80;
if (length > 56) {
while (length < 64) {
buf[length++] = (byte) 0;
}
sha256_transform(&st, buf);
length = 0;
}
while (length < 56) {
buf[length++] = (byte) 0;
}
buf[length++] = 0;
buf[length++] = 0;
buf[length++] = 0;
buf[length++] = 0;
buf[length++] = ((cCount >> 24) & 0xFF);
buf[length++] = ((cCount >> 16) & 0xFF);
buf[length++] = ((cCount >> 8) & 0xFF);
buf[length++] = (cCount & 0xFF);
sha256_transform(&st, buf);
for (i = 0; i < 8; i++) {
st.h[i] = swap_endian_32(st.h[i]);
}
memcpy(ret, st.h, 32);
return ret;
}