fr_md5.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * md5.h Structures and prototypes for md5.
  3. *
  4. * Version: $Id: md5.h,v 1.2 2007/06/21 18:07:24 cparker Exp $
  5. * License: BSD, but largely derived from a public domain source.
  6. *
  7. */
  8. #ifndef _RCRAD_MD5_H
  9. #define _RCRAD_MD5_H
  10. #include "radius_config.h"
  11. #ifdef HAVE_NETTLE
  12. #include <nettle/md5-compat.h>
  13. #else
  14. #ifdef HAVE_INTTYPES_H
  15. #include <inttypes.h>
  16. #endif
  17. #ifdef HAVE_SYS_TYPES_H
  18. #include <sys/types.h>
  19. #endif
  20. #ifdef HAVE_STDINT_H
  21. #include <stdint.h>
  22. #endif
  23. #include <string.h>
  24. /*
  25. * FreeRADIUS Client defines to ensure globally unique MD5 function names,
  26. * so that we don't pick up vendor-specific broken MD5 libraries.
  27. */
  28. #define MD5_CTX librad_MD5_CTX
  29. #define MD5Init librad_MD5Init
  30. #define MD5Update librad_MD5Update
  31. #define MD5Final librad_MD5Final
  32. #define MD5Transform librad_MD5Transform
  33. /* The below was retrieved from
  34. * http://www.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/crypto/md5.h?rev=1.1
  35. * With the following changes: uint64_t => uint32_t[2]
  36. * Commented out #include <sys/cdefs.h>
  37. * Commented out the __BEGIN and __END _DECLS, and the __attributes.
  38. */
  39. /*
  40. * This code implements the MD5 message-digest algorithm.
  41. * The algorithm is due to Ron Rivest. This code was
  42. * written by Colin Plumb in 1993, no copyright is claimed.
  43. * This code is in the public domain; do with it what you wish.
  44. *
  45. * Equivalent code is available from RSA Data Security, Inc.
  46. * This code has been tested against that, and is equivalent,
  47. * except that you don't need to include two pages of legalese
  48. * with every copy.
  49. */
  50. #define MD5_BLOCK_LENGTH 64
  51. #define MD5_DIGEST_LENGTH 16
  52. typedef struct MD5Context {
  53. uint32_t state[4]; //!< State.
  54. uint32_t count[2]; //!< Number of bits, mod 2^64.
  55. uint8_t buffer[MD5_BLOCK_LENGTH]; //!< Input buffer.
  56. } MD5_CTX;
  57. /* include <sys/cdefs.h> */
  58. /* __BEGIN_DECLS */
  59. void MD5Init(MD5_CTX *);
  60. void MD5Update(MD5_CTX *, uint8_t const *, size_t)
  61. /* __attribute__((__bounded__(__string__,2,3)))*/;
  62. void MD5Final(uint8_t [MD5_DIGEST_LENGTH], MD5_CTX *)
  63. /* __attribute__((__bounded__(__minbytes__,1,MD5_DIGEST_LENGTH)))*/;
  64. void MD5Transform(uint32_t [4], uint8_t const [MD5_BLOCK_LENGTH])
  65. /* __attribute__((__bounded__(__minbytes__,1,4)))*/
  66. /* __attribute__((__bounded__(__minbytes__,2,MD5_BLOCK_LENGTH)))*/;
  67. /* __END_DECLS */
  68. #endif /* HAVE_NETTLE */
  69. #endif /* _RCRAD_MD5_H */