jack1 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
3.3KB

  1. /*
  2. * Local defines for the md5 functions.
  3. *
  4. * $Id$
  5. */
  6. /*
  7. * Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
  8. * rights reserved.
  9. *
  10. * License to copy and use this software is granted provided that it is
  11. * identified as the "RSA Data Security, Inc. MD5 Message-Digest
  12. * Algorithm" in all material mentioning or referencing this software
  13. * or this function.
  14. *
  15. * License is also granted to make and use derivative works provided that
  16. * such works are identified as "derived from the RSA Data Security,
  17. * Inc. MD5 Message-Digest Algorithm" in all material mentioning or
  18. * referencing the derived work.
  19. *
  20. * RSA Data Security, Inc. makes no representations concerning either the
  21. * merchantability of this software or the suitability of this
  22. * software for any particular purpose. It is provided "as is" without
  23. * express or implied warranty of any kind.
  24. *
  25. * These notices must be retained in any copies of any part of this
  26. * documentation and/or software.
  27. */
  28. #ifndef __MD5_LOC_H__
  29. #define __MD5_LOC_H__
  30. #define HEX_STRING "0123456789abcdef" /* to convert to hex */
  31. #define BLOCK_SIZE_MASK (MD5_BLOCK_SIZE - 1)
  32. #include <config.h>
  33. /*
  34. * Define my endian-ness. Could not do in a portable manner using the
  35. * include files -- grumble.
  36. */
  37. #ifdef WORDS_BIGENDIAN
  38. /*
  39. * big endian - big is better
  40. */
  41. #define SWAP(n) \
  42. (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
  43. #else
  44. /*
  45. + * little endian
  46. + */
  47. #define SWAP(n) (n)
  48. #endif
  49. /*
  50. * These are the four functions used in the four steps of the MD5
  51. * algorithm and defined in the RFC 1321. The first function is a
  52. * little bit optimized (as found in Colin Plumbs public domain
  53. * implementation).
  54. */
  55. /* #define FF(b, c, d) ((b & c) | (~b & d)) */
  56. #define FF(b, c, d) (d ^ (b & (c ^ d)))
  57. #define FG(b, c, d) FF(d, b, c)
  58. #define FH(b, c, d) (b ^ c ^ d)
  59. #define FI(b, c, d) (c ^ (b | ~d))
  60. /*
  61. * It is unfortunate that C does not provide an operator for cyclic
  62. * rotation. Hope the C compiler is smart enough. -- Modified to
  63. * remove the w = at the front - Gray 2/97
  64. */
  65. #define CYCLIC(w, s) ((w << s) | (w >> (32 - s)))
  66. /*
  67. * First Round: using the given function, the context and a constant
  68. * the next context is computed. Because the algorithms processing
  69. * unit is a 32-bit word and it is determined to work on words in
  70. * little endian byte order we perhaps have to change the byte order
  71. * before the computation. To reduce the work for the next steps we
  72. * store the swapped words in the array CORRECT_WORDS. -- Modified to
  73. * fix the handling of unaligned buffer spaces - Gray 7/97
  74. */
  75. #define OP1(a, b, c, d, b_p, c_p, s, T) \
  76. do { \
  77. memcpy(c_p, b_p, sizeof(md5_uint32)); \
  78. *c_p = SWAP(*c_p); \
  79. a += FF (b, c, d) + *c_p + T; \
  80. a = CYCLIC (a, s); \
  81. a += b; \
  82. b_p = (char *)b_p + sizeof(md5_uint32); \
  83. c_p++; \
  84. } while (0)
  85. /*
  86. * Second to Fourth Round: we have the possibly swapped words in
  87. * CORRECT_WORDS. Redefine the macro to take an additional first
  88. * argument specifying the function to use.
  89. */
  90. #define OP234(FUNC, a, b, c, d, k, s, T) \
  91. do { \
  92. a += FUNC (b, c, d) + k + T; \
  93. a = CYCLIC (a, s); \
  94. a += b; \
  95. } while (0)
  96. #endif /* ! __MD5_LOC_H__ */