Skip to main content

5. Sample Implementation

The following code implements the H(A1), H(A2), request-digest, and response-digest calculations as well as a test program that computes the values used in the examples in section 3.5. It uses the MD5 implementation from RFC 1321.

Note: This section contains C language sample code demonstrating how to implement the core calculations for digest authentication. The code examples include:

  • digcalc.h - Header file defining data structures and function declarations required for digest authentication calculations
  • digcalc.c - Implementation file containing the concrete implementations of H(A1) and response calculations
  • digtest.c - Test program verifying the correctness of the implementation

These code examples demonstrate:

  1. How to compute the H(A1) value (hash of username, realm, and password)
  2. How to compute request-digest and response-digest
  3. Application of the MD5 algorithm in digest authentication
  4. How to handle different qop (quality of protection) options

Implementation Key Points:

  • Uses MD5 algorithm for hash calculations
  • Properly handles hexadecimal conversion
  • Supports both "MD5" and "MD5-sess" algorithms
  • Supports both "auth" and "auth-int" qop values

For the complete C code implementation, please refer to section 5 of RFC 2617 original text.