Counter Strike : Global Offensive Source Code
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.

110 lines
2.7 KiB

  1. // md4.cpp - modified by Wei Dai from Andrew M. Kuchling's md4.c
  2. // The original code and all modifications are in the public domain.
  3. // This is the original introductory comment:
  4. /*
  5. * md4.c : MD4 hash algorithm.
  6. *
  7. * Part of the Python Cryptography Toolkit, version 1.1
  8. *
  9. * Distribute and use freely; there are no restrictions on further
  10. * dissemination and usage except those imposed by the laws of your
  11. * country of residence.
  12. *
  13. */
  14. #include "pch.h"
  15. #define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1
  16. #include "md4.h"
  17. #include "misc.h"
  18. NAMESPACE_BEGIN(CryptoPP)
  19. namespace Weak1 {
  20. void MD4::InitState(HashWordType *state)
  21. {
  22. state[0] = 0x67452301L;
  23. state[1] = 0xefcdab89L;
  24. state[2] = 0x98badcfeL;
  25. state[3] = 0x10325476L;
  26. }
  27. void MD4::Transform (word32 *digest, const word32 *in)
  28. {
  29. // #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
  30. #define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
  31. #define G(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z)))
  32. #define H(x, y, z) ((x) ^ (y) ^ (z))
  33. word32 A, B, C, D;
  34. A=digest[0];
  35. B=digest[1];
  36. C=digest[2];
  37. D=digest[3];
  38. #define function(a,b,c,d,k,s) a=rotlFixed(a+F(b,c,d)+in[k],s);
  39. function(A,B,C,D, 0, 3);
  40. function(D,A,B,C, 1, 7);
  41. function(C,D,A,B, 2,11);
  42. function(B,C,D,A, 3,19);
  43. function(A,B,C,D, 4, 3);
  44. function(D,A,B,C, 5, 7);
  45. function(C,D,A,B, 6,11);
  46. function(B,C,D,A, 7,19);
  47. function(A,B,C,D, 8, 3);
  48. function(D,A,B,C, 9, 7);
  49. function(C,D,A,B,10,11);
  50. function(B,C,D,A,11,19);
  51. function(A,B,C,D,12, 3);
  52. function(D,A,B,C,13, 7);
  53. function(C,D,A,B,14,11);
  54. function(B,C,D,A,15,19);
  55. #undef function
  56. #define function(a,b,c,d,k,s) a=rotlFixed(a+G(b,c,d)+in[k]+0x5a827999,s);
  57. function(A,B,C,D, 0, 3);
  58. function(D,A,B,C, 4, 5);
  59. function(C,D,A,B, 8, 9);
  60. function(B,C,D,A,12,13);
  61. function(A,B,C,D, 1, 3);
  62. function(D,A,B,C, 5, 5);
  63. function(C,D,A,B, 9, 9);
  64. function(B,C,D,A,13,13);
  65. function(A,B,C,D, 2, 3);
  66. function(D,A,B,C, 6, 5);
  67. function(C,D,A,B,10, 9);
  68. function(B,C,D,A,14,13);
  69. function(A,B,C,D, 3, 3);
  70. function(D,A,B,C, 7, 5);
  71. function(C,D,A,B,11, 9);
  72. function(B,C,D,A,15,13);
  73. #undef function
  74. #define function(a,b,c,d,k,s) a=rotlFixed(a+H(b,c,d)+in[k]+0x6ed9eba1,s);
  75. function(A,B,C,D, 0, 3);
  76. function(D,A,B,C, 8, 9);
  77. function(C,D,A,B, 4,11);
  78. function(B,C,D,A,12,15);
  79. function(A,B,C,D, 2, 3);
  80. function(D,A,B,C,10, 9);
  81. function(C,D,A,B, 6,11);
  82. function(B,C,D,A,14,15);
  83. function(A,B,C,D, 1, 3);
  84. function(D,A,B,C, 9, 9);
  85. function(C,D,A,B, 5,11);
  86. function(B,C,D,A,13,15);
  87. function(A,B,C,D, 3, 3);
  88. function(D,A,B,C,11, 9);
  89. function(C,D,A,B, 7,11);
  90. function(B,C,D,A,15,15);
  91. digest[0]+=A;
  92. digest[1]+=B;
  93. digest[2]+=C;
  94. digest[3]+=D;
  95. }
  96. }
  97. NAMESPACE_END