Back to index

courier  0.68.2
Defines | Typedefs | Functions
md5.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define MD5_DIGEST_SIZE   16
#define MD5_BLOCK_SIZE   64
#define md5_crypt   md5_crypt_redhat

Typedefs

typedef unsigned char MD5_DIGEST [MD5_DIGEST_SIZE]

Functions

void md5_digest (const void *msg, unsigned int len, MD5_DIGEST)
char * md5_crypt_redhat (const char *, const char *)
const char * md5_hash_courier (const char *)
const char * md5_hash_raw (const char *)

Define Documentation

#define MD5_BLOCK_SIZE   64

Definition at line 28 of file md5.h.

Definition at line 56 of file md5.h.

#define MD5_DIGEST_SIZE   16

Definition at line 27 of file md5.h.


Typedef Documentation

typedef unsigned char MD5_DIGEST[MD5_DIGEST_SIZE]

Definition at line 30 of file md5.h.


Function Documentation

char* md5_crypt_redhat ( const char *  ,
const char *   
)

Definition at line 14 of file redhat-crypt-md5.c.

{
struct MD5_CONTEXT outer_context, inner_context;
MD5_DIGEST digest;
unsigned pwl=strlen(pw);
unsigned l;
unsigned i, j;
char   *p;
static char buffer[100];

       if (*salt == '$' && salt[1] == '1' && salt[2] == '$')
              salt += 3;

       for (l=0; l<8 && salt[l] && salt[l] != '$'; l++)
              ;

       md5_context_init(&inner_context);
       md5_context_hashstream(&inner_context, pw, pwl);
       md5_context_hashstream(&inner_context, salt, l);
       md5_context_hashstream(&inner_context, pw, pwl);
       md5_context_endstream(&inner_context, pwl*2+l);
       md5_context_digest(&inner_context, digest);

       md5_context_init(&outer_context);
       md5_context_hashstream(&outer_context, pw, pwl);
       md5_context_hashstream(&outer_context, "$1$", 3);
       md5_context_hashstream(&outer_context, salt, l);

       for (i=pwl; i; )
       {
              j=i;
              if (j > 16)   j=16;
              md5_context_hashstream(&outer_context, digest, j);
              i -= j;
       }

       j=pwl*2+l+3;

       for (i=pwl; i; i >>= 1)
       {
              md5_context_hashstream(&outer_context, (i & 1) ? "": pw, 1);
              ++j;
       }


       md5_context_endstream(&outer_context, j);
       md5_context_digest(&outer_context, digest);

       for (i=0; i<1000; i++)
       {
              j=0;

              md5_context_init(&outer_context);
              if (i & 1)
              {
                     md5_context_hashstream(&outer_context, pw, pwl);
                     j += pwl;
              }
              else
              {
                     md5_context_hashstream(&outer_context, digest, 16);
                     j += 16;
              }
    
              if (i % 3)
              {
                     md5_context_hashstream(&outer_context, salt, l);
                     j += l;
              }
    
              if (i % 7)
              {
                     md5_context_hashstream(&outer_context, pw, pwl);
                     j += pwl;
              }
    
              if (i & 1)
              {
                     md5_context_hashstream(&outer_context, digest, 16);
                     j += 16;
              }
              else
              {
                     md5_context_hashstream(&outer_context, pw, pwl);
                     j += pwl;
              }

              md5_context_endstream(&outer_context, j);
              md5_context_digest(&outer_context, digest);
       }

       strcpy(buffer, "$1$");
       strncat(buffer, salt, l);
       strcat(buffer, "$");

       p=buffer+strlen(buffer);
       for (i=0; i<5; i++)
       {
       unsigned char *d=digest;

              j= (d[i] << 16) | (d[i+6] << 8) | d[i == 4 ? 5:12+i];
              *p++= base64[j & 63] ; j=j >> 6;
              *p++= base64[j & 63] ; j=j >> 6;
              *p++= base64[j & 63] ; j=j >> 6;
              *p++= base64[j & 63];
       }
       j=digest[11];
       *p++ = base64[j & 63]; j=j >> 6;
       *p++ = base64[j & 63];
       *p=0;
       return (buffer);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void md5_digest ( const void *  msg,
unsigned int  len,
MD5_DIGEST   
)

Definition at line 270 of file md5.c.

{
struct MD5_CONTEXT   c;

       md5_context_init(&c);
       md5_context_hashstream(&c, msg, len);
       md5_context_endstream(&c, len);
       md5_context_digest(&c, d);
}

Here is the call graph for this function:

Here is the caller graph for this function:

const char* md5_hash_courier ( const char *  )

Definition at line 14 of file md5_hash.c.

{
MD5_DIGEST md5buf;
static char hash_buffer[1+(sizeof(md5buf)+2)/3*4];
int    a=0,b=0,c=0;
int    i, j;
int    d, e, f, g;

       md5_digest(passw, strlen(passw), md5buf);

       j=0;

       for (i=0; i<sizeof(md5buf); i += 3)
       {
              a=md5buf[i];
              b= i+1 < sizeof(md5buf) ? md5buf[i+1]:0;
              c= i+2 < sizeof(md5buf) ? md5buf[i+2]:0;

              d=base64tab[ a >> 2 ];
              e=base64tab[ ((a & 3 ) << 4) | (b >> 4)];
              f=base64tab[ ((b & 15) << 2) | (c >> 6)];
              g=base64tab[ c & 63 ];
              if (i + 1 >= sizeof(md5buf))       f='=';
              if (i + 2 >= sizeof(md5buf)) g='=';
              hash_buffer[j++]=d;
              hash_buffer[j++]=e;
              hash_buffer[j++]=f;
              hash_buffer[j++]=g;
       }

       hash_buffer[j]=0;
       return (hash_buffer);
}

Here is the call graph for this function:

Here is the caller graph for this function:

const char* md5_hash_raw ( const char *  )

Definition at line 48 of file md5_hash.c.

{
       MD5_DIGEST digest;
       static char hash_buffer[sizeof(digest)*2+1];
       size_t j=0,i=0;

       char
              tmp_buf[3];

       md5_digest(passw, strlen(passw), digest);
       for (j=0; j<sizeof(digest); j++)
       {
              sprintf(tmp_buf,"%02x",digest[j]);
              hash_buffer[i++]=tmp_buf[0];
              hash_buffer[i++]=tmp_buf[1];
       }
       hash_buffer[i]=0;

       return(hash_buffer);
}

Here is the call graph for this function: