Sha1.c (p7zip_15.14.1_src_all) | : | Sha1.c (p7zip_16.02_src_all) | ||
---|---|---|---|---|
/* Sha1.c -- SHA-1 Hash | /* Sha1.c -- SHA-1 Hash | |||
2015-05-10 : Igor Pavlov : Public domain | 2016-05-20 : Igor Pavlov : Public domain | |||
This code is based on public domain code of Steve Reid from Wei Dai's Crypto++ l ibrary. */ | This code is based on public domain code of Steve Reid from Wei Dai's Crypto++ l ibrary. */ | |||
#include "Precomp.h" | #include "Precomp.h" | |||
#include <string.h> | #include <string.h> | |||
#include "CpuArch.h" | #include "CpuArch.h" | |||
#include "RotateDefs.h" | #include "RotateDefs.h" | |||
#include "Sha1.h" | #include "Sha1.h" | |||
skipping to change at line 153 | skipping to change at line 153 | |||
unsigned pos, pos2; | unsigned pos, pos2; | |||
if (size == 0) | if (size == 0) | |||
return; | return; | |||
pos = (unsigned)p->count & 0x3F; | pos = (unsigned)p->count & 0x3F; | |||
p->count += size; | p->count += size; | |||
pos2 = pos & 3; | pos2 = pos & 3; | |||
pos >>= 2; | pos >>= 2; | |||
if (pos2 != 0) | if (pos2 != 0) | |||
{ | { | |||
UInt32 w = ((UInt32)data[0]) << 24; | UInt32 w; | |||
if (--size && pos2 < 3) | pos2 = (3 - pos2) * 8; | |||
w = ((UInt32)*data++) << pos2; | ||||
if (--size && pos2) | ||||
{ | { | |||
w |= ((UInt32)data[1]) << 16; | pos2 -= 8; | |||
if (--size && pos2 < 2) | w |= ((UInt32)*data++) << pos2; | |||
if (--size && pos2) | ||||
{ | { | |||
w |= ((UInt32)data[2]) << 8; | pos2 -= 8; | |||
--size; | w |= ((UInt32)*data++) << pos2; | |||
size--; | ||||
} | } | |||
} | } | |||
data += 4 - pos2; | p->buffer[pos] |= w; | |||
p->buffer[pos++] |= (w >> (8 * pos2)); | if (pos2 == 0) | |||
pos++; | ||||
} | } | |||
for (;;) | for (;;) | |||
{ | { | |||
if (pos == SHA1_NUM_BLOCK_WORDS) | if (pos == SHA1_NUM_BLOCK_WORDS) | |||
{ | { | |||
for (;;) | for (;;) | |||
{ | { | |||
unsigned i; | unsigned i; | |||
Sha1_UpdateBlock(p); | Sha1_UpdateBlock(p); | |||
skipping to change at line 209 | skipping to change at line 214 | |||
if (size > 1) | if (size > 1) | |||
{ | { | |||
w |= ((UInt32)data[1]) << 16; | w |= ((UInt32)data[1]) << 16; | |||
if (size > 2) | if (size > 2) | |||
w |= ((UInt32)data[2]) << 8; | w |= ((UInt32)data[2]) << 8; | |||
} | } | |||
p->buffer[pos] = w; | p->buffer[pos] = w; | |||
} | } | |||
} | } | |||
void Sha1_Update_Rar(CSha1 *p, Byte *data, size_t size, int rar350Mode) | void Sha1_Update_Rar(CSha1 *p, Byte *data, size_t size /* , int rar350Mode */) | |||
{ | { | |||
int returnRes = False; | int returnRes = False; | |||
unsigned pos = (unsigned)p->count & 0x3F; | unsigned pos = (unsigned)p->count & 0x3F; | |||
p->count += size; | p->count += size; | |||
while (size--) | while (size--) | |||
{ | { | |||
unsigned pos2 = (pos & 3); | unsigned pos2 = (pos & 3); | |||
UInt32 v = ((UInt32)*data++) << (8 * (3 - pos2)); | UInt32 v = ((UInt32)*data++) << (8 * (3 - pos2)); | |||
skipping to change at line 243 | skipping to change at line 248 | |||
if (returnRes) | if (returnRes) | |||
{ | { | |||
unsigned i; | unsigned i; | |||
for (i = 0; i < SHA1_NUM_BLOCK_WORDS; i++) | for (i = 0; i < SHA1_NUM_BLOCK_WORDS; i++) | |||
{ | { | |||
UInt32 d = p->buffer[i]; | UInt32 d = p->buffer[i]; | |||
Byte *prev = data + i * 4 - SHA1_BLOCK_SIZE; | Byte *prev = data + i * 4 - SHA1_BLOCK_SIZE; | |||
SetUi32(prev, d); | SetUi32(prev, d); | |||
} | } | |||
} | } | |||
returnRes = rar350Mode; | // returnRes = rar350Mode; | |||
returnRes = True; | ||||
} | } | |||
} | } | |||
} | } | |||
void Sha1_Final(CSha1 *p, Byte *digest) | void Sha1_Final(CSha1 *p, Byte *digest) | |||
{ | { | |||
unsigned pos = (unsigned)p->count & 0x3F; | unsigned pos = (unsigned)p->count & 0x3F; | |||
unsigned pos2 = (pos & 3); | unsigned pos2 = (pos & 3); | |||
UInt64 numBits; | UInt64 numBits; | |||
UInt32 w; | UInt32 w; | |||
End of changes. 7 change blocks. | ||||
11 lines changed or deleted | 17 lines changed or added |