Back to index

nordugrid-arc-nox  1.1.0~rc6
Public Member Functions | Private Attributes
Arc::MD5Sum Class Reference

Implementation of MD5 checksum. More...

#include <CheckSum.h>

Inheritance diagram for Arc::MD5Sum:
Inheritance graph
[legend]
Collaboration diagram for Arc::MD5Sum:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 MD5Sum (void)
virtual void start (void)
virtual void add (void *buf, unsigned long long int len)
virtual void end (void)
virtual void result (unsigned char *&res, unsigned int &len) const
virtual int print (char *buf, int len) const
virtual void scan (const char *buf)
virtual operator bool (void) const
virtual bool operator! (void) const

Private Attributes

bool computed
uint32_t A
uint32_t B
uint32_t C
uint32_t D
uint64_t count
uint32_t X [16]
unsigned int Xlen

Detailed Description

Implementation of MD5 checksum.

Definition at line 70 of file CheckSum.h.


Constructor & Destructor Documentation

Arc::MD5Sum::MD5Sum ( void  )

Definition at line 223 of file CheckSum.cpp.

                     {
    // for(u_int i = 1;i<=64;i++) T[i-1]=(uint32_t)(4294967296LL*fabs(sin(i)));
    start();
  }

Here is the call graph for this function:


Member Function Documentation

void Arc::MD5Sum::add ( void *  buf,
unsigned long long int  len 
) [virtual]

Implements Arc::CheckSum.

Definition at line 238 of file CheckSum.cpp.

                                                        {
    u_char *buf_ = (u_char*)buf;
    for (; len;) {
      if (Xlen < 64) { // 16 words = 64 bytes
        u_int l = 64 - Xlen;
        if (len < l)
          l = len;
        memcpy(((u_char*)X) + Xlen, buf_, l);
        Xlen += l;
        count += l;
        len -= l;
        buf_ += l;
      }
      if (Xlen < 64)
        return;

      uint32_t AA = A;
      uint32_t BB = B;
      uint32_t CC = C;
      uint32_t DD = D;


      OP1(A, B, C, D, 0, 7, 1);
      OP1(D, A, B, C, 1, 12, 2);
      OP1(C, D, A, B, 2, 17, 3);
      OP1(B, C, D, A, 3, 22, 4);

      OP1(A, B, C, D, 4, 7, 5);
      OP1(D, A, B, C, 5, 12, 6);
      OP1(C, D, A, B, 6, 17, 7);
      OP1(B, C, D, A, 7, 22, 8);

      OP1(A, B, C, D, 8, 7, 9);
      OP1(D, A, B, C, 9, 12, 10);
      OP1(C, D, A, B, 10, 17, 11);
      OP1(B, C, D, A, 11, 22, 12);

      OP1(A, B, C, D, 12, 7, 13);
      OP1(D, A, B, C, 13, 12, 14);
      OP1(C, D, A, B, 14, 17, 15);
      OP1(B, C, D, A, 15, 22, 16);


      OP2(A, B, C, D, 1, 5, 17);
      OP2(D, A, B, C, 6, 9, 18);
      OP2(C, D, A, B, 11, 14, 19);
      OP2(B, C, D, A, 0, 20, 20);

      OP2(A, B, C, D, 5, 5, 21);
      OP2(D, A, B, C, 10, 9, 22);
      OP2(C, D, A, B, 15, 14, 23);
      OP2(B, C, D, A, 4, 20, 24);

      OP2(A, B, C, D, 9, 5, 25);
      OP2(D, A, B, C, 14, 9, 26);
      OP2(C, D, A, B, 3, 14, 27);
      OP2(B, C, D, A, 8, 20, 28);

      OP2(A, B, C, D, 13, 5, 29);
      OP2(D, A, B, C, 2, 9, 30);
      OP2(C, D, A, B, 7, 14, 31);
      OP2(B, C, D, A, 12, 20, 32);


      OP3(A, B, C, D, 5, 4, 33);
      OP3(D, A, B, C, 8, 11, 34);
      OP3(C, D, A, B, 11, 16, 35);
      OP3(B, C, D, A, 14, 23, 36);

      OP3(A, B, C, D, 1, 4, 37);
      OP3(D, A, B, C, 4, 11, 38);
      OP3(C, D, A, B, 7, 16, 39);
      OP3(B, C, D, A, 10, 23, 40);

      OP3(A, B, C, D, 13, 4, 41);
      OP3(D, A, B, C, 0, 11, 42);
      OP3(C, D, A, B, 3, 16, 43);
      OP3(B, C, D, A, 6, 23, 44);

      OP3(A, B, C, D, 9, 4, 45);
      OP3(D, A, B, C, 12, 11, 46);
      OP3(C, D, A, B, 15, 16, 47);
      OP3(B, C, D, A, 2, 23, 48);


      OP4(A, B, C, D, 0, 6, 49);
      OP4(D, A, B, C, 7, 10, 50);
      OP4(C, D, A, B, 14, 15, 51);
      OP4(B, C, D, A, 5, 21, 52);

      OP4(A, B, C, D, 12, 6, 53);
      OP4(D, A, B, C, 3, 10, 54);
      OP4(C, D, A, B, 10, 15, 55);
      OP4(B, C, D, A, 1, 21, 56);

      OP4(A, B, C, D, 8, 6, 57);
      OP4(D, A, B, C, 15, 10, 58);
      OP4(C, D, A, B, 6, 15, 59);
      OP4(B, C, D, A, 13, 21, 60);

      OP4(A, B, C, D, 4, 6, 61);
      OP4(D, A, B, C, 11, 10, 62);
      OP4(C, D, A, B, 2, 15, 63);
      OP4(B, C, D, A, 9, 21, 64);


      A += AA;
      B += BB;
      C += CC;
      D += DD;
      Xlen = 0;
    }
  }

Here is the caller graph for this function:

void Arc::MD5Sum::end ( void  ) [virtual]

Implements Arc::CheckSum.

Definition at line 352 of file CheckSum.cpp.

                       {
    if (computed)
      return;
    // pad
    uint64_t l = 8 * count; // number of bits
    u_char c = 0x80;
    add(&c, 1);
    c = 0;
    for (; Xlen != 56;)
      add(&c, 1);
    add(&l, 8);
    computed = true;
  }

Here is the call graph for this function:

virtual Arc::MD5Sum::operator bool ( void  ) const [inline, virtual]

Reimplemented from Arc::CheckSum.

Definition at line 93 of file CheckSum.h.

                                      {
      return computed;
    }
virtual bool Arc::MD5Sum::operator! ( void  ) const [inline, virtual]

Reimplemented from Arc::CheckSum.

Definition at line 96 of file CheckSum.h.

                                       {
      return !computed;
    }
int Arc::MD5Sum::print ( char *  buf,
int  len 
) const [virtual]

Reimplemented from Arc::CheckSum.

Definition at line 366 of file CheckSum.cpp.

                                            {
    if (!computed) {
      if (len > 0)
        buf[0] = 0;
      return 0;
    }
    return snprintf(buf, len,
                    "md5: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
                    ((u_char*)&A)[0], ((u_char*)&A)[1], ((u_char*)&A)[2], ((u_char*)&A)[3],
                    ((u_char*)&B)[0], ((u_char*)&B)[1], ((u_char*)&B)[2], ((u_char*)&B)[3],
                    ((u_char*)&C)[0], ((u_char*)&C)[1], ((u_char*)&C)[2], ((u_char*)&C)[3],
                    ((u_char*)&D)[0], ((u_char*)&D)[1], ((u_char*)&D)[2], ((u_char*)&D)[3]
                    );
  }

Here is the caller graph for this function:

virtual void Arc::MD5Sum::result ( unsigned char *&  res,
unsigned int &  len 
) const [inline, virtual]

Implements Arc::CheckSum.

Definition at line 87 of file CheckSum.h.

                                                                      {
      res = (unsigned char*)&A;
      len = 16;
    }

Here is the caller graph for this function:

void Arc::MD5Sum::scan ( const char *  buf) [virtual]

Implements Arc::CheckSum.

Definition at line 381 of file CheckSum.cpp.

                                   {
    computed = false;
    if (strncasecmp("md5:", buf, 4) != 0)
      return;
    int l = sscanf(buf + 4,
                   "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
                   "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx",
                   ((u_char*)&A) + 0, ((u_char*)&A) + 1, ((u_char*)&A) + 2, ((u_char*)&A) + 3,
                   ((u_char*)&B) + 0, ((u_char*)&B) + 1, ((u_char*)&B) + 2, ((u_char*)&B) + 3,
                   ((u_char*)&C) + 0, ((u_char*)&C) + 1, ((u_char*)&C) + 2, ((u_char*)&C) + 3,
                   ((u_char*)&D) + 0, ((u_char*)&D) + 1, ((u_char*)&D) + 2, ((u_char*)&D) + 3
                   );
    if (l != 16)
      return;
    computed = true;
    return;
  }
void Arc::MD5Sum::start ( void  ) [virtual]

Implements Arc::CheckSum.

Definition at line 228 of file CheckSum.cpp.

                         {
    A = A_INIT;
    B = B_INIT;
    C = C_INIT;
    D = D_INIT;
    count = 0;
    Xlen = 0;
    computed = false;
  }

Here is the caller graph for this function:


Member Data Documentation

uint32_t Arc::MD5Sum::A [private]

Definition at line 74 of file CheckSum.h.

uint32_t Arc::MD5Sum::B [private]

Definition at line 75 of file CheckSum.h.

uint32_t Arc::MD5Sum::C [private]

Definition at line 76 of file CheckSum.h.

bool Arc::MD5Sum::computed [private]

Definition at line 73 of file CheckSum.h.

uint64_t Arc::MD5Sum::count [private]

Definition at line 78 of file CheckSum.h.

uint32_t Arc::MD5Sum::D [private]

Definition at line 77 of file CheckSum.h.

uint32_t Arc::MD5Sum::X[16] [private]

Definition at line 79 of file CheckSum.h.

unsigned int Arc::MD5Sum::Xlen [private]

Definition at line 80 of file CheckSum.h.


The documentation for this class was generated from the following files: