]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/contrib/md5.cc
test/integration/test-ubuntu-bug-346386-apt-get-update-paywall: use downloadfile()
[apt.git] / apt-pkg / contrib / md5.cc
index ec8228c2bac49f3b1c8ba13a02e0e6aabf79227b..b487a96f9bb30ca289be03f6f0f073b7e6f542f5 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: md5.cc,v 1.8 1999/11/16 01:41:49 jgg Exp $
+// $Id: md5.cc,v 1.12 2001/05/13 05:15:03 jgg Exp $
 /* ######################################################################
    
    MD5Sum - MD5 Message Digest Algorithm.
 /* ######################################################################
    
    MD5Sum - MD5 Message Digest Algorithm.
    ##################################################################### */
                                                                        /*}}}*/
 // Include Files                                                       /*{{{*/
    ##################################################################### */
                                                                        /*}}}*/
 // Include Files                                                       /*{{{*/
-#ifdef __GNUG__
-#pragma implementation "apt-pkg/md5.h"
-#endif
+#include <config.h>
 
 #include <apt-pkg/md5.h>
 
 #include <apt-pkg/md5.h>
-#include <apt-pkg/strutl.h>
 
 
+#include <stdint.h>
 #include <string.h>
 #include <string.h>
-#include <system.h>
-#include <unistd.h>
-#include <netinet/in.h>                          // For htonl
-#include <inttypes.h>
-#include <config.h>
                                                                        /*}}}*/
 
 // byteSwap - Swap bytes in a buffer                                   /*{{{*/
 // ---------------------------------------------------------------------
 /* Swap n 32 bit longs in given buffer */
 #ifdef WORDS_BIGENDIAN
                                                                        /*}}}*/
 
 // byteSwap - Swap bytes in a buffer                                   /*{{{*/
 // ---------------------------------------------------------------------
 /* Swap n 32 bit longs in given buffer */
 #ifdef WORDS_BIGENDIAN
-static void byteSwap(uint8_t *buf, unsigned words)
+static void byteSwap(uint32_t *buf, unsigned words)
 {
    uint8_t *p = (uint8_t *)buf;
    
 {
    uint8_t *p = (uint8_t *)buf;
    
@@ -169,61 +162,6 @@ static void MD5Transform(uint32_t buf[4], uint32_t const in[16])
    buf[3] += d;
 }
                                                                        /*}}}*/
    buf[3] += d;
 }
                                                                        /*}}}*/
-// MD5SumValue::MD5SumValue - Constructs the summation from a string   /*{{{*/
-// ---------------------------------------------------------------------
-/* The string form of a MD5 is a 32 character hex number */
-MD5SumValue::MD5SumValue(string Str)
-{
-   memset(Sum,0,sizeof(Sum));
-   Set(Str);
-}
-                                                                       /*}}}*/
-// MD5SumValue::MD5SumValue - Default constructor                      /*{{{*/
-// ---------------------------------------------------------------------
-/* Sets the value to 0 */
-MD5SumValue::MD5SumValue()
-{
-   memset(Sum,0,sizeof(Sum));
-}
-                                                                       /*}}}*/
-// MD5SumValue::Set - Set the sum from a string                                /*{{{*/
-// ---------------------------------------------------------------------
-/* Converts the hex string into a set of chars */
-bool MD5SumValue::Set(string Str)
-{
-   return Hex2Num(Str.begin(),Str.end(),Sum,sizeof(Sum));
-}
-                                                                       /*}}}*/
-// MD5SumValue::Value - Convert the number into a string               /*{{{*/
-// ---------------------------------------------------------------------
-/* Converts the set of chars into a hex string in lower case */
-string MD5SumValue::Value() const
-{
-   char Conv[16] = {'0','1','2','3','4','5','6','7','8','9','a','b',
-                    'c','d','e','f'};
-   char Result[33];
-   Result[32] = 0;
-   
-   // Convert each char into two letters
-   int J = 0;
-   int I = 0;
-   for (; I != 32; J++, I += 2)
-   {
-      Result[I] = Conv[Sum[J] >> 4];
-      Result[I + 1] = Conv[Sum[J] & 0xF];
-   } 
-
-   return string(Result);
-}
-                                                                       /*}}}*/
-// MD5SumValue::operator == - Comparitor                               /*{{{*/
-// ---------------------------------------------------------------------
-/* Call memcmp on the buffer */
-bool MD5SumValue::operator ==(const MD5SumValue &rhs) const
-{
-   return memcmp(Sum,rhs.Sum,sizeof(Sum)) == 0;
-}
-                                                                       /*}}}*/
 // MD5Summation::MD5Summation - Initialize the summer                  /*{{{*/
 // ---------------------------------------------------------------------
 /* This assigns the deep magic initial values */
 // MD5Summation::MD5Summation - Initialize the summer                  /*{{{*/
 // ---------------------------------------------------------------------
 /* This assigns the deep magic initial values */
@@ -245,7 +183,7 @@ MD5Summation::MD5Summation()
 // MD5Summation::Add - 'Add' a data set to the hash                    /*{{{*/
 // ---------------------------------------------------------------------
 /* */
 // MD5Summation::Add - 'Add' a data set to the hash                    /*{{{*/
 // ---------------------------------------------------------------------
 /* */
-bool MD5Summation::Add(const unsigned char *data,unsigned long len)
+bool MD5Summation::Add(const unsigned char *data,unsigned long long len)
 {
    if (Done == true)
       return false;
 {
    if (Done == true)
       return false;
@@ -269,7 +207,7 @@ bool MD5Summation::Add(const unsigned char *data,unsigned long len)
 
    // First chunk is an odd size
    memcpy((unsigned char *)in + 64 - t,data,t);
 
    // First chunk is an odd size
    memcpy((unsigned char *)in + 64 - t,data,t);
-   byteSwap((uint8_t *)in, 16);
+   byteSwap(in, 16);
    MD5Transform(buf,in);
    data += t;
    len -= t;
    MD5Transform(buf,in);
    data += t;
    len -= t;
@@ -278,7 +216,7 @@ bool MD5Summation::Add(const unsigned char *data,unsigned long len)
    while (len >= 64)
    {
       memcpy(in,data,64);
    while (len >= 64)
    {
       memcpy(in,data,64);
-      byteSwap((uint8_t *)in,16);
+      byteSwap(in,16);
       MD5Transform(buf,in);
       data += 64;
       len -= 64;
       MD5Transform(buf,in);
       data += 64;
       len -= 64;
@@ -290,24 +228,6 @@ bool MD5Summation::Add(const unsigned char *data,unsigned long len)
    return true;   
 }
                                                                        /*}}}*/
    return true;   
 }
                                                                        /*}}}*/
-// MD5Summation::AddFD - Add the contents of a FD to the hash          /*{{{*/
-// ---------------------------------------------------------------------
-/* */
-bool MD5Summation::AddFD(int Fd,unsigned long Size)
-{
-   unsigned char Buf[64*64];
-   int Res = 0;
-   while (Size != 0)
-   {
-      Res = read(Fd,Buf,MIN(Size,sizeof(Buf)));
-      if (Res < 0 || (unsigned)Res != MIN(Size,sizeof(Buf)))
-        return false;
-      Size -= Res;
-      Add(Buf,Res);
-   }
-   return true;
-}
-                                                                       /*}}}*/
 // MD5Summation::Result - Returns the value of the sum                 /*{{{*/
 // ---------------------------------------------------------------------
 /* Because this must add in the last bytes of the series it prevents anyone
 // MD5Summation::Result - Returns the value of the sum                 /*{{{*/
 // ---------------------------------------------------------------------
 /* Because this must add in the last bytes of the series it prevents anyone
@@ -334,25 +254,25 @@ MD5SumValue MD5Summation::Result()
       if (count < 0) 
       {
         memset(p,0,count + 8);
       if (count < 0) 
       {
         memset(p,0,count + 8);
-        byteSwap((uint8_t *)in, 16);
+        byteSwap(in, 16);
         MD5Transform(buf,in);
         p = (unsigned char *)in;
         count = 56;
       }
       
       memset(p, 0, count);
         MD5Transform(buf,in);
         p = (unsigned char *)in;
         count = 56;
       }
       
       memset(p, 0, count);
-      byteSwap((unit8_t *)in, 14);
+      byteSwap(in, 14);
       
       // Append length in bits and transform
       in[14] = bytes[0] << 3;
       in[15] = bytes[1] << 3 | bytes[0] >> 29;
       MD5Transform(buf,in);   
       
       // Append length in bits and transform
       in[14] = bytes[0] << 3;
       in[15] = bytes[1] << 3 | bytes[0] >> 29;
       MD5Transform(buf,in);   
-      byteSwap((uint8_t *)buf,4);
+      byteSwap(buf,4);
       Done = true;
    }
    
    MD5SumValue V;
       Done = true;
    }
    
    MD5SumValue V;
-   memcpy(V.Sum,buf,16);
+   V.Set((unsigned char *)buf);
    return V;
 }
                                                                        /*}}}*/
    return V;
 }
                                                                        /*}}}*/