MyWebUniversity.com Home Page
 



OpenSolaris man pages main menu


Extended Library Functions                              md5(3EXT)



NAME
     md5, md5calc, MD5Init, MD5Update,  MD5Final  -  MD5  digest
     functions

SYNOPSIS
     cc [ flag ... ] file ... -lmd5 [ library ... ]
     #include 

     void md5calc(unsigned char *output, unsigned char *input,
          unsigned int inlen);


     void MD5Init(MD5CTX *context);


     void MD5Update(MD5CTX *context, unsigned char *input,
          unsigned int inlen);


     void MD5Final(unsigned char *output, MD5CTX *context);


DESCRIPTION
     These functions implement the MD5 message-digest  algorithm,
     which  takes as input a message of arbitrary length and pro-
     duces as output a 128-bit "fingerprint" or "message  digest"
     of  the input. It is intended for digital signature applica-
     tions, where large file must be  "compressed"  in  a  secure
     manner  before  being  encrypted with a private (secret) key
     under a public-key cryptosystem such as RSA.

  md5calc()
     The md5calc() function computes an MD5 digest on  a  single
     message  block. The inlen-byte block is pointed to by input,
     and the 16-byte MD5 digest is written to output.

  MD5Init(), MD5Update(), MD5Final()
     The MD5Init(), MD5Update(), and MD5Final()  functions  allow
     an  MD5  digest to be computed over multiple message blocks;
     between blocks, the state of the MD5 computation is held  in
     an  MD5  context  structure, allocated by the caller. A com-
     plete digest computation consists of one call to  MD5Init(),
     one   or   more  calls  to  MD5Update(),  and  one  call  to
     MD5Final(), in that order.


     The MD5Init() function initializes the MD5 context structure
     pointed to by context.


     The MD5Update() function computes a partial  MD5  digest  on
     the  inlen-byte  message  block  pointed  to  by  input, and



SunOS 5.11          Last change: 13 Nov 2007                    1






Extended Library Functions                              md5(3EXT)



     updates the MD5 context  structure  pointed  to  by  context
     accordingly.


     The MD5Final() function  generates  the  final  MD5  digest,
     using  the  MD5 context structure pointed to by context; the
     16-byte MD5 digest  is  written  to  output.  After  calling
     MD5Final(), the state of the context structure is undefined;
     it must be reinitialized with MD5Init()  before  being  used
     again.

RETURN VALUES
     These functions do not return a value.

EXAMPLES
     Example 1 Authenticate a message found in multiple buffers


     The following is a sample function that must authenticate  a
     message that is found in multiple buffers. The calling func-
     tion provides an authentication buffer that will contain the
     result of the MD5 digest.


       #include 
       #include 
       #include 

       int
       AuthenticateMsg(unsigned char *authbuffer, struct iovec
                       *messageIov, unsigned int numbuffers)
       {
           MD5CTX md5context;
           unsigned int i;

           MD5Init(&md5context);

           for(i=0; iiovbase,
                          messageIov->iovlen);
                messageIov ]= sizeof(struct iovec);
           }

           MD5Final(authbuffer, &md5context);

           return 0;
       }


     Example 2 Use md5calc() to generate the MD5 digest




SunOS 5.11          Last change: 13 Nov 2007                    2






Extended Library Functions                              md5(3EXT)



     Since  the  buffer  to  be  computed  is   contiguous,   the
     md5calc() function can be used to generate the MD5 digest.


       int AuthenticateMsg(unsigned char *authbuffer, unsigned
                           char *buffer, unsigned int length)
       {
           md5calc(buffer, authbuffer, length);

           return (0);
       }


ATRIBUTES
     See attributes(5) for descriptions of the  following  attri-
     butes:



     
           ATRIBUTE TYPE               ATRIBUTE VALUE       
    
     Interface Stability          Committed                   
    
     MT-Level                     MT-Safe                     
    


SEE ALSO
     libmd5(3LIB)


     Rivest, R., The  MD5  Message-Digest  Algorithm,  RFC  1321,
     April 1992.





















SunOS 5.11          Last change: 13 Nov 2007                    3



OpenSolaris man pages main menu

Contact us      |       About us      |       Term of use      |       Copyright © 2000-2010 MyWebUniversity.com ™