Panowie mam problem kodem do liczenia hashy sha1 i nie wiem co jest nie tak niby wszystko cacy a po porównaniu z innym haserem jest inny klucz o to kod
#include <iostream>
#include <string>
#define rol(x,n) ((x << n) | (x >> (32-n)))
using namespace std;
char SHA1_result[50];
void block(unsigned char* str, unsigned long &h0, unsigned long &h1, unsigned long &h2, unsigned long &h3, unsigned long &h4){
unsigned long w[80], a = h0, b = h1, c = h2, d = h3, e = h4, f, k;
for(int j = 0; j < 16; j++){ //ustawienie 16 32 bitowych słów
w[j] = str[j * 4 + 0] * 0x1000000
+ str[j * 4 + 1] * 0x10000
+ str[j * 4 + 2] * 0x100
+ str[j * 4 + 3];
}
for(int j = 16; j < 80; j++){ //rozszeżenie 16 słów do 80
w[j] = rol((w[j-3] ^ w[j-8] ^ w[j - 14] ^ w[j - 16]), 1);
}
for(int m = 0; m < 80; m++){
if(m <= 19){
f = (b & c) | ((~b) & d);
k = 0x5A827999;
}else if(m <= 39){
f = b ^ c ^ d;
k = 0x6ED9EBA1;
}else if(m <= 59){
f = (b & c) | (b & d) | (c & d);
k = 0x8F1BBCDC;
}else{
f = b ^ c ^ d;
k = 0xCA62C1D6;
}
e = d;
d = c;
c = rol(b,30);
b = a;
a = ((rol(a,5) + f + e + k + w[m]) & 0xFFFFFFFF);
h0 = h0 + a;
h1 = h1 + b;
h2 = h2 + c;
h3 = h3 + d;
h4 = h4 + e;
sprintf(SHA1_result, "%08x%08x%08x%08x%08x", h0, h1, h2, h3, h4);
}
}
int main (int argc, char* argv[]){
string str = "aaa";
//cout << "Wpisz klucz do zakodowania nie duższy niz 56 znakow:" << endl;
//cin >> str;
unsigned int size = str.length();
unsigned char cstr[65];
for(unsigned short int i = 0; i < 65; i++){
cstr[i] = char(0x00);
}
for(unsigned int i = 0; i < size; i++){
cstr[i] = str[i];
}
cstr[size] = 0x80;
size *= 8;
cstr[63] = size;
cstr[64] = '\0';
unsigned long h1 = 0x67453201, h2 = 0xEFCDAB89, h3 = 0x98BADCFE, h4 = 0x10325476, h5 = 0xC3D2E1F0;
block(cstr, h1, h2, h3, h4, h5);
system("PAUSE");
return EXIT_SUCCESS;
}