X-Git-Url: https://git.ozlabs.org/?p=ppp.git;a=blobdiff_plain;f=pppd%2Fsha1.c;h=4e51cee506c237ce2385ad3ed94003e31c9f1914;hp=b8701b4306e03621de80102d362818f2fce3b887;hb=f1a34da3b2f5336e4993a729e5ac2130d0e0595a;hpb=b38527fb14af5ebe3d2559e2f861575c722a1ce9 diff --git a/pppd/sha1.c b/pppd/sha1.c index b8701b4..4e51cee 100644 --- a/pppd/sha1.c +++ b/pppd/sha1.c @@ -17,11 +17,13 @@ /* #define SHA1HANDSOFF * Copies data before messing with it. */ #include +#include #include /* htonl() */ +#include #include "sha1.h" static void -SHA1_Transform(unsigned long[5], const unsigned char[64]); +SHA1_Transform(u_int32_t[5], const unsigned char[64]); #define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits)))) @@ -42,12 +44,12 @@ SHA1_Transform(unsigned long[5], const unsigned char[64]); /* Hash a single 512-bit block. This is the core of the algorithm. */ static void -SHA1_Transform(unsigned long state[5], const unsigned char buffer[64]) +SHA1_Transform(u_int32_t state[5], const unsigned char buffer[64]) { - unsigned long a, b, c, d, e; + u_int32_t a, b, c, d, e; typedef union { unsigned char c[64]; - unsigned long l[16]; + u_int32_t l[16]; } CHAR64LONG16; CHAR64LONG16 *block; @@ -121,18 +123,17 @@ SHA1_Update(SHA1_CTX *context, const unsigned char *data, unsigned int len) j = (context->count[0] >> 3) & 63; if ((context->count[0] += len << 3) < (len << 3)) context->count[1]++; context->count[1] += (len >> 29); - if ((j + len) > 63) { - memcpy(&context->buffer[j], data, (i = 64-j)); + i = 64 - j; + while (len >= i) { + memcpy(&context->buffer[j], data, i); SHA1_Transform(context->state, context->buffer); - for ( ; i + 63 < len; i += 64) { - SHA1_Transform(context->state, &data[i]); - } + data += i; + len -= i; + i = 64; j = 0; } - else - i = 0; - memcpy(&context->buffer[j], &data[i], len - i); + memcpy(&context->buffer[j], data, len); } @@ -141,7 +142,7 @@ SHA1_Update(SHA1_CTX *context, const unsigned char *data, unsigned int len) void SHA1_Final(unsigned char digest[20], SHA1_CTX *context) { - unsigned long i, j; + u_int32_t i, j; unsigned char finalcount[8]; for (i = 0; i < 8; i++) {