|
|
|
|
@ -20,17 +20,17 @@ static uint8_t chunk_cnt; |
|
|
|
|
|
|
|
|
|
void sha1_addbyte(uint8_t c){ |
|
|
|
|
uint8_t* p=(uint8_t*)chunk; |
|
|
|
|
uint8_t i; |
|
|
|
|
uint8_t i=(chunk_cnt & 0x03); |
|
|
|
|
|
|
|
|
|
p[(chunk_cnt&0xfc)+3-(chunk_cnt & 0x03)]=c; |
|
|
|
|
p[(chunk_cnt-i)+3-i]=c; |
|
|
|
|
chunk_cnt++; |
|
|
|
|
if(chunk_cnt==64){ |
|
|
|
|
/*chunk extension*/ |
|
|
|
|
uint32_t a,b,c,d,e,chunk_e[64]; |
|
|
|
|
for(i=0; i<64; i++){ |
|
|
|
|
chunk_e[i]= _LROT32( _W(i+16-3) ^ _W(i+16-8) ^ _W(i+16-14) ^ _W(i+16-16), 1 );
|
|
|
|
|
//chunk_e[i]= _LROT32( _W(i+16-3) ^ _W(i+16-8) ^ _W(i+16-14) ^ _W(i+16-16), 1 );
|
|
|
|
|
chunk_e[i]= _LROT32( _W(i+16-3) ^ _W(i+16-8) ^ _W(i+16-14) ^ _W(i+16-16), 1 );
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
a=sha1_digest[4]; |
|
|
|
|
b=sha1_digest[3]; |
|
|
|
|
c=sha1_digest[2]; |
|
|
|
|
@ -54,7 +54,7 @@ void sha1_addbyte(uint8_t c){ |
|
|
|
|
k=K4; |
|
|
|
|
f=b ^ c ^ d; |
|
|
|
|
} |
|
|
|
|
temp = e + _LROT32(a,5) + f + k + _W(i); |
|
|
|
|
temp = e + k + f + _LROT32(a,5) + _W(i); |
|
|
|
|
e = d; |
|
|
|
|
d = c; |
|
|
|
|
c = _LROT32(b,30); |
|
|
|
|
@ -87,7 +87,7 @@ void sha1_fill(int32_t len){ |
|
|
|
|
} |
|
|
|
|
{ |
|
|
|
|
uint64_t l=len*8; |
|
|
|
|
/*pay attention to the endiness here*/ |
|
|
|
|
//pay attention to the endiness here
|
|
|
|
|
sha1_addbyte( ((char*)(&l))[7]); |
|
|
|
|
sha1_addbyte( ((char*)(&l))[6]); |
|
|
|
|
sha1_addbyte( ((char*)(&l))[5]); |
|
|
|
|
|