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.

107 lines
3.2KB

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