RipeMD320Digest.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Utilities;
  5. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  6. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Digests
  7. {
  8. /// <remarks>
  9. /// <p>Implementation of RipeMD 320.</p>
  10. /// <p><b>Note:</b> this algorithm offers the same level of security as RipeMD160.</p>
  11. /// </remarks>
  12. public class RipeMD320Digest
  13. : GeneralDigest
  14. {
  15. public override string AlgorithmName
  16. {
  17. get { return "RIPEMD320"; }
  18. }
  19. public override int GetDigestSize()
  20. {
  21. return DigestLength;
  22. }
  23. private const int DigestLength = 40;
  24. private int H0, H1, H2, H3, H4, H5, H6, H7, H8, H9; // IV's
  25. private int[] X = new int[16];
  26. private int xOff;
  27. /// <summary> Standard constructor</summary>
  28. public RipeMD320Digest()
  29. {
  30. Reset();
  31. }
  32. /// <summary> Copy constructor. This will copy the state of the provided
  33. /// message digest.
  34. /// </summary>
  35. public RipeMD320Digest(RipeMD320Digest t)
  36. : base(t)
  37. {
  38. CopyIn(t);
  39. }
  40. private void CopyIn(RipeMD320Digest t)
  41. {
  42. base.CopyIn(t);
  43. H0 = t.H0;
  44. H1 = t.H1;
  45. H2 = t.H2;
  46. H3 = t.H3;
  47. H4 = t.H4;
  48. H5 = t.H5;
  49. H6 = t.H6;
  50. H7 = t.H7;
  51. H8 = t.H8;
  52. H9 = t.H9;
  53. Array.Copy(t.X, 0, X, 0, t.X.Length);
  54. xOff = t.xOff;
  55. }
  56. internal override void ProcessWord(byte[] input, int inOff)
  57. {
  58. X[xOff++] = (int)Pack.LE_To_UInt32(input, inOff);
  59. if (xOff == 16)
  60. {
  61. ProcessBlock();
  62. }
  63. }
  64. #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
  65. internal override void ProcessWord(ReadOnlySpan<byte> word)
  66. {
  67. X[xOff++] = (int)Pack.LE_To_UInt32(word);
  68. if (xOff == 16)
  69. {
  70. ProcessBlock();
  71. }
  72. }
  73. #endif
  74. internal override void ProcessLength(
  75. long bitLength)
  76. {
  77. if (xOff > 14)
  78. {
  79. ProcessBlock();
  80. }
  81. X[14] = (int)(bitLength & 0xffffffff);
  82. X[15] = (int)((ulong)bitLength >> 32);
  83. }
  84. public override int DoFinal(byte[] output, int outOff)
  85. {
  86. Finish();
  87. Pack.UInt32_To_LE((uint)H0, output, outOff);
  88. Pack.UInt32_To_LE((uint)H1, output, outOff + 4);
  89. Pack.UInt32_To_LE((uint)H2, output, outOff + 8);
  90. Pack.UInt32_To_LE((uint)H3, output, outOff + 12);
  91. Pack.UInt32_To_LE((uint)H4, output, outOff + 16);
  92. Pack.UInt32_To_LE((uint)H5, output, outOff + 20);
  93. Pack.UInt32_To_LE((uint)H6, output, outOff + 24);
  94. Pack.UInt32_To_LE((uint)H7, output, outOff + 28);
  95. Pack.UInt32_To_LE((uint)H8, output, outOff + 32);
  96. Pack.UInt32_To_LE((uint)H9, output, outOff + 36);
  97. Reset();
  98. return DigestLength;
  99. }
  100. #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
  101. public override int DoFinal(Span<byte> output)
  102. {
  103. Finish();
  104. Pack.UInt32_To_LE((uint)H0, output);
  105. Pack.UInt32_To_LE((uint)H1, output[4..]);
  106. Pack.UInt32_To_LE((uint)H2, output[8..]);
  107. Pack.UInt32_To_LE((uint)H3, output[12..]);
  108. Pack.UInt32_To_LE((uint)H4, output[16..]);
  109. Pack.UInt32_To_LE((uint)H5, output[20..]);
  110. Pack.UInt32_To_LE((uint)H6, output[24..]);
  111. Pack.UInt32_To_LE((uint)H7, output[28..]);
  112. Pack.UInt32_To_LE((uint)H8, output[32..]);
  113. Pack.UInt32_To_LE((uint)H9, output[36..]);
  114. Reset();
  115. return DigestLength;
  116. }
  117. #endif
  118. /// <summary> reset the chaining variables to the IV values.</summary>
  119. public override void Reset()
  120. {
  121. base.Reset();
  122. H0 = unchecked((int) 0x67452301);
  123. H1 = unchecked((int) 0xefcdab89);
  124. H2 = unchecked((int) 0x98badcfe);
  125. H3 = unchecked((int) 0x10325476);
  126. H4 = unchecked((int) 0xc3d2e1f0);
  127. H5 = unchecked((int) 0x76543210);
  128. H6 = unchecked((int) 0xFEDCBA98);
  129. H7 = unchecked((int) 0x89ABCDEF);
  130. H8 = unchecked((int) 0x01234567);
  131. H9 = unchecked((int) 0x3C2D1E0F);
  132. xOff = 0;
  133. for (int i = 0; i != X.Length; i++)
  134. {
  135. X[i] = 0;
  136. }
  137. }
  138. /*
  139. * rotate int x left n bits.
  140. */
  141. private int RL(
  142. int x,
  143. int n)
  144. {
  145. return (x << n) | (int)(((uint)x) >> (32 - n));
  146. }
  147. /*
  148. * f1,f2,f3,f4,f5 are the basic RipeMD160 functions.
  149. */
  150. /*
  151. * rounds 0-15
  152. */
  153. private int F1(int x, int y, int z)
  154. {
  155. return x ^ y ^ z;
  156. }
  157. /*
  158. * rounds 16-31
  159. */
  160. private int F2(int x, int y, int z)
  161. {
  162. return (x & y) | (~ x & z);
  163. }
  164. /*
  165. * rounds 32-47
  166. */
  167. private int F3(int x, int y, int z)
  168. {
  169. return (x | ~ y) ^ z;
  170. }
  171. /*
  172. * rounds 48-63
  173. */
  174. private int F4(int x, int y, int z)
  175. {
  176. return (x & z) | (y & ~ z);
  177. }
  178. /*
  179. * rounds 64-79
  180. */
  181. private int F5(int x, int y, int z)
  182. {
  183. return x ^ (y | ~z);
  184. }
  185. internal override void ProcessBlock()
  186. {
  187. int a, aa;
  188. int b, bb;
  189. int c, cc;
  190. int d, dd;
  191. int e, ee;
  192. int t;
  193. a = H0;
  194. b = H1;
  195. c = H2;
  196. d = H3;
  197. e = H4;
  198. aa = H5;
  199. bb = H6;
  200. cc = H7;
  201. dd = H8;
  202. ee = H9;
  203. //
  204. // Rounds 1 - 16
  205. //
  206. // left
  207. a = RL(a + F1(b, c, d) + X[0], 11) + e; c = RL(c, 10);
  208. e = RL(e + F1(a, b, c) + X[1], 14) + d; b = RL(b, 10);
  209. d = RL(d + F1(e, a, b) + X[2], 15) + c; a = RL(a, 10);
  210. c = RL(c + F1(d, e, a) + X[3], 12) + b; e = RL(e, 10);
  211. b = RL(b + F1(c, d, e) + X[4], 5) + a; d = RL(d, 10);
  212. a = RL(a + F1(b, c, d) + X[5], 8) + e; c = RL(c, 10);
  213. e = RL(e + F1(a, b, c) + X[6], 7) + d; b = RL(b, 10);
  214. d = RL(d + F1(e, a, b) + X[7], 9) + c; a = RL(a, 10);
  215. c = RL(c + F1(d, e, a) + X[8], 11) + b; e = RL(e, 10);
  216. b = RL(b + F1(c, d, e) + X[9], 13) + a; d = RL(d, 10);
  217. a = RL(a + F1(b, c, d) + X[10], 14) + e; c = RL(c, 10);
  218. e = RL(e + F1(a, b, c) + X[11], 15) + d; b = RL(b, 10);
  219. d = RL(d + F1(e, a, b) + X[12], 6) + c; a = RL(a, 10);
  220. c = RL(c + F1(d, e, a) + X[13], 7) + b; e = RL(e, 10);
  221. b = RL(b + F1(c, d, e) + X[14], 9) + a; d = RL(d, 10);
  222. a = RL(a + F1(b, c, d) + X[15], 8) + e; c = RL(c, 10);
  223. // right
  224. aa = RL(aa + F5(bb, cc, dd) + X[5] + unchecked((int)0x50a28be6), 8) + ee; cc = RL(cc, 10);
  225. ee = RL(ee + F5(aa, bb, cc) + X[14] + unchecked((int)0x50a28be6), 9) + dd; bb = RL(bb, 10);
  226. dd = RL(dd + F5(ee, aa, bb) + X[7] + unchecked((int)0x50a28be6), 9) + cc; aa = RL(aa, 10);
  227. cc = RL(cc + F5(dd, ee, aa) + X[0] + unchecked((int)0x50a28be6), 11) + bb; ee = RL(ee, 10);
  228. bb = RL(bb + F5(cc, dd, ee) + X[9] + unchecked((int)0x50a28be6), 13) + aa; dd = RL(dd, 10);
  229. aa = RL(aa + F5(bb, cc, dd) + X[2] + unchecked((int)0x50a28be6), 15) + ee; cc = RL(cc, 10);
  230. ee = RL(ee + F5(aa, bb, cc) + X[11] + unchecked((int)0x50a28be6), 15) + dd; bb = RL(bb, 10);
  231. dd = RL(dd + F5(ee, aa, bb) + X[4] + unchecked((int)0x50a28be6), 5) + cc; aa = RL(aa, 10);
  232. cc = RL(cc + F5(dd, ee, aa) + X[13] + unchecked((int)0x50a28be6), 7) + bb; ee = RL(ee, 10);
  233. bb = RL(bb + F5(cc, dd, ee) + X[6] + unchecked((int)0x50a28be6), 7) + aa; dd = RL(dd, 10);
  234. aa = RL(aa + F5(bb, cc, dd) + X[15] + unchecked((int)0x50a28be6), 8) + ee; cc = RL(cc, 10);
  235. ee = RL(ee + F5(aa, bb, cc) + X[8] + unchecked((int)0x50a28be6), 11) + dd; bb = RL(bb, 10);
  236. dd = RL(dd + F5(ee, aa, bb) + X[1] + unchecked((int)0x50a28be6), 14) + cc; aa = RL(aa, 10);
  237. cc = RL(cc + F5(dd, ee, aa) + X[10] + unchecked((int)0x50a28be6), 14) + bb; ee = RL(ee, 10);
  238. bb = RL(bb + F5(cc, dd, ee) + X[3] + unchecked((int)0x50a28be6), 12) + aa; dd = RL(dd, 10);
  239. aa = RL(aa + F5(bb, cc, dd) + X[12] + unchecked((int)0x50a28be6), 6) + ee; cc = RL(cc, 10);
  240. t = a; a = aa; aa = t;
  241. //
  242. // Rounds 16-31
  243. //
  244. // left
  245. e = RL(e + F2(a, b, c) + X[7] + unchecked((int)0x5a827999), 7) + d; b = RL(b, 10);
  246. d = RL(d + F2(e, a, b) + X[4] + unchecked((int)0x5a827999), 6) + c; a = RL(a, 10);
  247. c = RL(c + F2(d, e, a) + X[13] + unchecked((int)0x5a827999), 8) + b; e = RL(e, 10);
  248. b = RL(b + F2(c, d, e) + X[1] + unchecked((int)0x5a827999), 13) + a; d = RL(d, 10);
  249. a = RL(a + F2(b, c, d) + X[10] + unchecked((int)0x5a827999), 11) + e; c = RL(c, 10);
  250. e = RL(e + F2(a, b, c) + X[6] + unchecked((int)0x5a827999), 9) + d; b = RL(b, 10);
  251. d = RL(d + F2(e, a, b) + X[15] + unchecked((int)0x5a827999), 7) + c; a = RL(a, 10);
  252. c = RL(c + F2(d, e, a) + X[3] + unchecked((int)0x5a827999), 15) + b; e = RL(e, 10);
  253. b = RL(b + F2(c, d, e) + X[12] + unchecked((int)0x5a827999), 7) + a; d = RL(d, 10);
  254. a = RL(a + F2(b, c, d) + X[0] + unchecked((int)0x5a827999), 12) + e; c = RL(c, 10);
  255. e = RL(e + F2(a, b, c) + X[9] + unchecked((int)0x5a827999), 15) + d; b = RL(b, 10);
  256. d = RL(d + F2(e, a, b) + X[5] + unchecked((int)0x5a827999), 9) + c; a = RL(a, 10);
  257. c = RL(c + F2(d, e, a) + X[2] + unchecked((int)0x5a827999), 11) + b; e = RL(e, 10);
  258. b = RL(b + F2(c, d, e) + X[14] + unchecked((int)0x5a827999), 7) + a; d = RL(d, 10);
  259. a = RL(a + F2(b, c, d) + X[11] + unchecked((int)0x5a827999), 13) + e; c = RL(c, 10);
  260. e = RL(e + F2(a, b, c) + X[8] + unchecked((int)0x5a827999), 12) + d; b = RL(b, 10);
  261. // right
  262. ee = RL(ee + F4(aa, bb, cc) + X[6] + unchecked((int)0x5c4dd124), 9) + dd; bb = RL(bb, 10);
  263. dd = RL(dd + F4(ee, aa, bb) + X[11] + unchecked((int)0x5c4dd124), 13) + cc; aa = RL(aa, 10);
  264. cc = RL(cc + F4(dd, ee, aa) + X[3] + unchecked((int)0x5c4dd124), 15) + bb; ee = RL(ee, 10);
  265. bb = RL(bb + F4(cc, dd, ee) + X[7] + unchecked((int)0x5c4dd124), 7) + aa; dd = RL(dd, 10);
  266. aa = RL(aa + F4(bb, cc, dd) + X[0] + unchecked((int)0x5c4dd124), 12) + ee; cc = RL(cc, 10);
  267. ee = RL(ee + F4(aa, bb, cc) + X[13] + unchecked((int)0x5c4dd124), 8) + dd; bb = RL(bb, 10);
  268. dd = RL(dd + F4(ee, aa, bb) + X[5] + unchecked((int)0x5c4dd124), 9) + cc; aa = RL(aa, 10);
  269. cc = RL(cc + F4(dd, ee, aa) + X[10] + unchecked((int)0x5c4dd124), 11) + bb; ee = RL(ee, 10);
  270. bb = RL(bb + F4(cc, dd, ee) + X[14] + unchecked((int)0x5c4dd124), 7) + aa; dd = RL(dd, 10);
  271. aa = RL(aa + F4(bb, cc, dd) + X[15] + unchecked((int)0x5c4dd124), 7) + ee; cc = RL(cc, 10);
  272. ee = RL(ee + F4(aa, bb, cc) + X[8] + unchecked((int)0x5c4dd124), 12) + dd; bb = RL(bb, 10);
  273. dd = RL(dd + F4(ee, aa, bb) + X[12] + unchecked((int)0x5c4dd124), 7) + cc; aa = RL(aa, 10);
  274. cc = RL(cc + F4(dd, ee, aa) + X[4] + unchecked((int)0x5c4dd124), 6) + bb; ee = RL(ee, 10);
  275. bb = RL(bb + F4(cc, dd, ee) + X[9] + unchecked((int)0x5c4dd124), 15) + aa; dd = RL(dd, 10);
  276. aa = RL(aa + F4(bb, cc, dd) + X[1] + unchecked((int)0x5c4dd124), 13) + ee; cc = RL(cc, 10);
  277. ee = RL(ee + F4(aa, bb, cc) + X[2] + unchecked((int)0x5c4dd124), 11) + dd; bb = RL(bb, 10);
  278. t = b; b = bb; bb = t;
  279. //
  280. // Rounds 32-47
  281. //
  282. // left
  283. d = RL(d + F3(e, a, b) + X[3] + unchecked((int)0x6ed9eba1), 11) + c; a = RL(a, 10);
  284. c = RL(c + F3(d, e, a) + X[10] + unchecked((int)0x6ed9eba1), 13) + b; e = RL(e, 10);
  285. b = RL(b + F3(c, d, e) + X[14] + unchecked((int)0x6ed9eba1), 6) + a; d = RL(d, 10);
  286. a = RL(a + F3(b, c, d) + X[4] + unchecked((int)0x6ed9eba1), 7) + e; c = RL(c, 10);
  287. e = RL(e + F3(a, b, c) + X[9] + unchecked((int)0x6ed9eba1), 14) + d; b = RL(b, 10);
  288. d = RL(d + F3(e, a, b) + X[15] + unchecked((int)0x6ed9eba1), 9) + c; a = RL(a, 10);
  289. c = RL(c + F3(d, e, a) + X[8] + unchecked((int)0x6ed9eba1), 13) + b; e = RL(e, 10);
  290. b = RL(b + F3(c, d, e) + X[1] + unchecked((int)0x6ed9eba1), 15) + a; d = RL(d, 10);
  291. a = RL(a + F3(b, c, d) + X[2] + unchecked((int)0x6ed9eba1), 14) + e; c = RL(c, 10);
  292. e = RL(e + F3(a, b, c) + X[7] + unchecked((int)0x6ed9eba1), 8) + d; b = RL(b, 10);
  293. d = RL(d + F3(e, a, b) + X[0] + unchecked((int)0x6ed9eba1), 13) + c; a = RL(a, 10);
  294. c = RL(c + F3(d, e, a) + X[6] + unchecked((int)0x6ed9eba1), 6) + b; e = RL(e, 10);
  295. b = RL(b + F3(c, d, e) + X[13] + unchecked((int)0x6ed9eba1), 5) + a; d = RL(d, 10);
  296. a = RL(a + F3(b, c, d) + X[11] + unchecked((int)0x6ed9eba1), 12) + e; c = RL(c, 10);
  297. e = RL(e + F3(a, b, c) + X[5] + unchecked((int)0x6ed9eba1), 7) + d; b = RL(b, 10);
  298. d = RL(d + F3(e, a, b) + X[12] + unchecked((int)0x6ed9eba1), 5) + c; a = RL(a, 10);
  299. // right
  300. dd = RL(dd + F3(ee, aa, bb) + X[15] + unchecked((int)0x6d703ef3), 9) + cc; aa = RL(aa, 10);
  301. cc = RL(cc + F3(dd, ee, aa) + X[5] + unchecked((int)0x6d703ef3), 7) + bb; ee = RL(ee, 10);
  302. bb = RL(bb + F3(cc, dd, ee) + X[1] + unchecked((int)0x6d703ef3), 15) + aa; dd = RL(dd, 10);
  303. aa = RL(aa + F3(bb, cc, dd) + X[3] + unchecked((int)0x6d703ef3), 11) + ee; cc = RL(cc, 10);
  304. ee = RL(ee + F3(aa, bb, cc) + X[7] + unchecked((int)0x6d703ef3), 8) + dd; bb = RL(bb, 10);
  305. dd = RL(dd + F3(ee, aa, bb) + X[14] + unchecked((int)0x6d703ef3), 6) + cc; aa = RL(aa, 10);
  306. cc = RL(cc + F3(dd, ee, aa) + X[6] + unchecked((int)0x6d703ef3), 6) + bb; ee = RL(ee, 10);
  307. bb = RL(bb + F3(cc, dd, ee) + X[9] + unchecked((int)0x6d703ef3), 14) + aa; dd = RL(dd, 10);
  308. aa = RL(aa + F3(bb, cc, dd) + X[11] + unchecked((int)0x6d703ef3), 12) + ee; cc = RL(cc, 10);
  309. ee = RL(ee + F3(aa, bb, cc) + X[8] + unchecked((int)0x6d703ef3), 13) + dd; bb = RL(bb, 10);
  310. dd = RL(dd + F3(ee, aa, bb) + X[12] + unchecked((int)0x6d703ef3), 5) + cc; aa = RL(aa, 10);
  311. cc = RL(cc + F3(dd, ee, aa) + X[2] + unchecked((int)0x6d703ef3), 14) + bb; ee = RL(ee, 10);
  312. bb = RL(bb + F3(cc, dd, ee) + X[10] + unchecked((int)0x6d703ef3), 13) + aa; dd = RL(dd, 10);
  313. aa = RL(aa + F3(bb, cc, dd) + X[0] + unchecked((int)0x6d703ef3), 13) + ee; cc = RL(cc, 10);
  314. ee = RL(ee + F3(aa, bb, cc) + X[4] + unchecked((int)0x6d703ef3), 7) + dd; bb = RL(bb, 10);
  315. dd = RL(dd + F3(ee, aa, bb) + X[13] + unchecked((int)0x6d703ef3), 5) + cc; aa = RL(aa, 10);
  316. t = c; c = cc; cc = t;
  317. //
  318. // Rounds 48-63
  319. //
  320. // left
  321. c = RL(c + F4(d, e, a) + X[1] + unchecked((int)0x8f1bbcdc), 11) + b; e = RL(e, 10);
  322. b = RL(b + F4(c, d, e) + X[9] + unchecked((int)0x8f1bbcdc), 12) + a; d = RL(d, 10);
  323. a = RL(a + F4(b, c, d) + X[11] + unchecked((int)0x8f1bbcdc), 14) + e; c = RL(c, 10);
  324. e = RL(e + F4(a, b, c) + X[10] + unchecked((int)0x8f1bbcdc), 15) + d; b = RL(b, 10);
  325. d = RL(d + F4(e, a, b) + X[0] + unchecked((int)0x8f1bbcdc), 14) + c; a = RL(a, 10);
  326. c = RL(c + F4(d, e, a) + X[8] + unchecked((int)0x8f1bbcdc), 15) + b; e = RL(e, 10);
  327. b = RL(b + F4(c, d, e) + X[12] + unchecked((int)0x8f1bbcdc), 9) + a; d = RL(d, 10);
  328. a = RL(a + F4(b, c, d) + X[4] + unchecked((int)0x8f1bbcdc), 8) + e; c = RL(c, 10);
  329. e = RL(e + F4(a, b, c) + X[13] + unchecked((int)0x8f1bbcdc), 9) + d; b = RL(b, 10);
  330. d = RL(d + F4(e, a, b) + X[3] + unchecked((int)0x8f1bbcdc), 14) + c; a = RL(a, 10);
  331. c = RL(c + F4(d, e, a) + X[7] + unchecked((int)0x8f1bbcdc), 5) + b; e = RL(e, 10);
  332. b = RL(b + F4(c, d, e) + X[15] + unchecked((int)0x8f1bbcdc), 6) + a; d = RL(d, 10);
  333. a = RL(a + F4(b, c, d) + X[14] + unchecked((int)0x8f1bbcdc), 8) + e; c = RL(c, 10);
  334. e = RL(e + F4(a, b, c) + X[5] + unchecked((int)0x8f1bbcdc), 6) + d; b = RL(b, 10);
  335. d = RL(d + F4(e, a, b) + X[6] + unchecked((int)0x8f1bbcdc), 5) + c; a = RL(a, 10);
  336. c = RL(c + F4(d, e, a) + X[2] + unchecked((int)0x8f1bbcdc), 12) + b; e = RL(e, 10);
  337. // right
  338. cc = RL(cc + F2(dd, ee, aa) + X[8] + unchecked((int)0x7a6d76e9), 15) + bb; ee = RL(ee, 10);
  339. bb = RL(bb + F2(cc, dd, ee) + X[6] + unchecked((int)0x7a6d76e9), 5) + aa; dd = RL(dd, 10);
  340. aa = RL(aa + F2(bb, cc, dd) + X[4] + unchecked((int)0x7a6d76e9), 8) + ee; cc = RL(cc, 10);
  341. ee = RL(ee + F2(aa, bb, cc) + X[1] + unchecked((int)0x7a6d76e9), 11) + dd; bb = RL(bb, 10);
  342. dd = RL(dd + F2(ee, aa, bb) + X[3] + unchecked((int)0x7a6d76e9), 14) + cc; aa = RL(aa, 10);
  343. cc = RL(cc + F2(dd, ee, aa) + X[11] + unchecked((int)0x7a6d76e9), 14) + bb; ee = RL(ee, 10);
  344. bb = RL(bb + F2(cc, dd, ee) + X[15] + unchecked((int)0x7a6d76e9), 6) + aa; dd = RL(dd, 10);
  345. aa = RL(aa + F2(bb, cc, dd) + X[0] + unchecked((int)0x7a6d76e9), 14) + ee; cc = RL(cc, 10);
  346. ee = RL(ee + F2(aa, bb, cc) + X[5] + unchecked((int)0x7a6d76e9), 6) + dd; bb = RL(bb, 10);
  347. dd = RL(dd + F2(ee, aa, bb) + X[12] + unchecked((int)0x7a6d76e9), 9) + cc; aa = RL(aa, 10);
  348. cc = RL(cc + F2(dd, ee, aa) + X[2] + unchecked((int)0x7a6d76e9), 12) + bb; ee = RL(ee, 10);
  349. bb = RL(bb + F2(cc, dd, ee) + X[13] + unchecked((int)0x7a6d76e9), 9) + aa; dd = RL(dd, 10);
  350. aa = RL(aa + F2(bb, cc, dd) + X[9] + unchecked((int)0x7a6d76e9), 12) + ee; cc = RL(cc, 10);
  351. ee = RL(ee + F2(aa, bb, cc) + X[7] + unchecked((int)0x7a6d76e9), 5) + dd; bb = RL(bb, 10);
  352. dd = RL(dd + F2(ee, aa, bb) + X[10] + unchecked((int)0x7a6d76e9), 15) + cc; aa = RL(aa, 10);
  353. cc = RL(cc + F2(dd, ee, aa) + X[14] + unchecked((int)0x7a6d76e9), 8) + bb; ee = RL(ee, 10);
  354. t = d; d = dd; dd = t;
  355. //
  356. // Rounds 64-79
  357. //
  358. // left
  359. b = RL(b + F5(c, d, e) + X[4] + unchecked((int)0xa953fd4e), 9) + a; d = RL(d, 10);
  360. a = RL(a + F5(b, c, d) + X[0] + unchecked((int)0xa953fd4e), 15) + e; c = RL(c, 10);
  361. e = RL(e + F5(a, b, c) + X[5] + unchecked((int)0xa953fd4e), 5) + d; b = RL(b, 10);
  362. d = RL(d + F5(e, a, b) + X[9] + unchecked((int)0xa953fd4e), 11) + c; a = RL(a, 10);
  363. c = RL(c + F5(d, e, a) + X[7] + unchecked((int)0xa953fd4e), 6) + b; e = RL(e, 10);
  364. b = RL(b + F5(c, d, e) + X[12] + unchecked((int)0xa953fd4e), 8) + a; d = RL(d, 10);
  365. a = RL(a + F5(b, c, d) + X[2] + unchecked((int)0xa953fd4e), 13) + e; c = RL(c, 10);
  366. e = RL(e + F5(a, b, c) + X[10] + unchecked((int)0xa953fd4e), 12) + d; b = RL(b, 10);
  367. d = RL(d + F5(e, a, b) + X[14] + unchecked((int)0xa953fd4e), 5) + c; a = RL(a, 10);
  368. c = RL(c + F5(d, e, a) + X[1] + unchecked((int)0xa953fd4e), 12) + b; e = RL(e, 10);
  369. b = RL(b + F5(c, d, e) + X[3] + unchecked((int)0xa953fd4e), 13) + a; d = RL(d, 10);
  370. a = RL(a + F5(b, c, d) + X[8] + unchecked((int)0xa953fd4e), 14) + e; c = RL(c, 10);
  371. e = RL(e + F5(a, b, c) + X[11] + unchecked((int)0xa953fd4e), 11) + d; b = RL(b, 10);
  372. d = RL(d + F5(e, a, b) + X[6] + unchecked((int)0xa953fd4e), 8) + c; a = RL(a, 10);
  373. c = RL(c + F5(d, e, a) + X[15] + unchecked((int)0xa953fd4e), 5) + b; e = RL(e, 10);
  374. b = RL(b + F5(c, d, e) + X[13] + unchecked((int)0xa953fd4e), 6) + a; d = RL(d, 10);
  375. // right
  376. bb = RL(bb + F1(cc, dd, ee) + X[12], 8) + aa; dd = RL(dd, 10);
  377. aa = RL(aa + F1(bb, cc, dd) + X[15], 5) + ee; cc = RL(cc, 10);
  378. ee = RL(ee + F1(aa, bb, cc) + X[10], 12) + dd; bb = RL(bb, 10);
  379. dd = RL(dd + F1(ee, aa, bb) + X[4], 9) + cc; aa = RL(aa, 10);
  380. cc = RL(cc + F1(dd, ee, aa) + X[1], 12) + bb; ee = RL(ee, 10);
  381. bb = RL(bb + F1(cc, dd, ee) + X[5], 5) + aa; dd = RL(dd, 10);
  382. aa = RL(aa + F1(bb, cc, dd) + X[8], 14) + ee; cc = RL(cc, 10);
  383. ee = RL(ee + F1(aa, bb, cc) + X[7], 6) + dd; bb = RL(bb, 10);
  384. dd = RL(dd + F1(ee, aa, bb) + X[6], 8) + cc; aa = RL(aa, 10);
  385. cc = RL(cc + F1(dd, ee, aa) + X[2], 13) + bb; ee = RL(ee, 10);
  386. bb = RL(bb + F1(cc, dd, ee) + X[13], 6) + aa; dd = RL(dd, 10);
  387. aa = RL(aa + F1(bb, cc, dd) + X[14], 5) + ee; cc = RL(cc, 10);
  388. ee = RL(ee + F1(aa, bb, cc) + X[0], 15) + dd; bb = RL(bb, 10);
  389. dd = RL(dd + F1(ee, aa, bb) + X[3], 13) + cc; aa = RL(aa, 10);
  390. cc = RL(cc + F1(dd, ee, aa) + X[9], 11) + bb; ee = RL(ee, 10);
  391. bb = RL(bb + F1(cc, dd, ee) + X[11], 11) + aa; dd = RL(dd, 10);
  392. //
  393. // do (e, ee) swap as part of assignment.
  394. //
  395. H0 += a;
  396. H1 += b;
  397. H2 += c;
  398. H3 += d;
  399. H4 += ee;
  400. H5 += aa;
  401. H6 += bb;
  402. H7 += cc;
  403. H8 += dd;
  404. H9 += e;
  405. //
  406. // reset the offset and clean out the word buffer.
  407. //
  408. xOff = 0;
  409. for (int i = 0; i != X.Length; i++)
  410. {
  411. X[i] = 0;
  412. }
  413. }
  414. public override IMemoable Copy()
  415. {
  416. return new RipeMD320Digest(this);
  417. }
  418. public override void Reset(IMemoable other)
  419. {
  420. RipeMD320Digest d = (RipeMD320Digest)other;
  421. CopyIn(d);
  422. }
  423. }
  424. }
  425. #pragma warning restore
  426. #endif