X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/6e52073fac7be205251b222f63cf2f61d1519364..22dcc318d978813b3c4d1ae1a1f41933d0e1d69b:/apt-pkg/contrib/md5.cc diff --git a/apt-pkg/contrib/md5.cc b/apt-pkg/contrib/md5.cc index 0d0a59696..fded5c864 100644 --- a/apt-pkg/contrib/md5.cc +++ b/apt-pkg/contrib/md5.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: md5.cc,v 1.3 1999/08/02 03:07:47 jgg Exp $ +// $Id: md5.cc,v 1.12 2001/05/13 05:15:03 jgg Exp $ /* ###################################################################### MD5Sum - MD5 Message Digest Algorithm. @@ -28,8 +28,9 @@ Still in the public domain. The classes use arrays of char that are a specific size. We cast those - arrays to UINT32's and go from there. This allows us to advoid using - config.h in a public header or internally newing memory. + arrays to uint8_t's and go from there. This allows us to advoid using + the uncommon inttypes.h in a public header or internally newing memory. + In theory if C9x becomes nicely accepted ##################################################################### */ /*}}}*/ @@ -42,22 +43,24 @@ #include #include -#include #include +#include // For htonl +#include #include +#include /*}}}*/ // byteSwap - Swap bytes in a buffer /*{{{*/ // --------------------------------------------------------------------- -/* This byteswap function will swap byte in a buffer of data */ +/* Swap n 32 bit longs in given buffer */ #ifdef WORDS_BIGENDIAN -static void byteSwap(UINT32 *buf, unsigned words) +static void byteSwap(uint32_t *buf, unsigned words) { - unsigned char *p = (unsigned char *)buf; + uint8_t *p = (uint8_t *)buf; do { - *buf++ = (UINT32)((unsigned)p[3] << 8 | p[2]) << 16 | + *buf++ = (uint32_t)((unsigned)p[3] << 8 | p[2]) << 16 | ((unsigned)p[1] << 8 | p[0]); p += 4; } while (--words); @@ -83,9 +86,9 @@ static void byteSwap(UINT32 *buf, unsigned words) #define MD5STEP(f,w,x,y,z,in,s) \ (w += f(x,y,z) + in, w = (w<>(32-s)) + x) -static void MD5Transform(UINT32 buf[4], UINT32 const in[16]) +static void MD5Transform(uint32_t buf[4], uint32_t const in[16]) { - register UINT32 a, b, c, d; + register uint32_t a, b, c, d; a = buf[0]; b = buf[1]; @@ -188,7 +191,7 @@ MD5SumValue::MD5SumValue() /* Converts the hex string into a set of chars */ bool MD5SumValue::Set(string Str) { - return Hex2Num(Str.begin(),Str.end(),Sum,sizeof(Sum)); + return Hex2Num(Str,Sum,sizeof(Sum)); } /*}}}*/ // MD5SumValue::Value - Convert the number into a string /*{{{*/ @@ -226,8 +229,8 @@ bool MD5SumValue::operator ==(const MD5SumValue &rhs) const /* This assigns the deep magic initial values */ MD5Summation::MD5Summation() { - UINT32 *buf = (UINT32 *)Buf; - UINT32 *bytes = (UINT32 *)Bytes; + uint32_t *buf = (uint32_t *)Buf; + uint32_t *bytes = (uint32_t *)Bytes; buf[0] = 0x67452301; buf[1] = 0xefcdab89; @@ -247,12 +250,12 @@ bool MD5Summation::Add(const unsigned char *data,unsigned long len) if (Done == true) return false; - UINT32 *buf = (UINT32 *)Buf; - UINT32 *bytes = (UINT32 *)Bytes; - UINT32 *in = (UINT32 *)In; + uint32_t *buf = (uint32_t *)Buf; + uint32_t *bytes = (uint32_t *)Bytes; + uint32_t *in = (uint32_t *)In; // Update byte count and carry (this could be done with a long long?) - UINT32 t = bytes[0]; + uint32_t t = bytes[0]; if ((bytes[0] = t + len) < t) bytes[1]++; @@ -296,8 +299,8 @@ bool MD5Summation::AddFD(int Fd,unsigned long Size) int Res = 0; while (Size != 0) { - Res = read(Fd,Buf,MIN(Size,sizeof(Buf))); - if (Res < 0 || (unsigned)Res != MIN(Size,sizeof(Buf))) + Res = read(Fd,Buf,min(Size,(unsigned long)sizeof(Buf))); + if (Res < 0 || (unsigned)Res != min(Size,(unsigned long)sizeof(Buf))) return false; Size -= Res; Add(Buf,Res); @@ -311,9 +314,9 @@ bool MD5Summation::AddFD(int Fd,unsigned long Size) from calling add after. */ MD5SumValue MD5Summation::Result() { - UINT32 *buf = (UINT32 *)Buf; - UINT32 *bytes = (UINT32 *)Bytes; - UINT32 *in = (UINT32 *)In; + uint32_t *buf = (uint32_t *)Buf; + uint32_t *bytes = (uint32_t *)Bytes; + uint32_t *in = (uint32_t *)In; if (Done == false) {