md5block_386.s 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. // Original source:
  2. // http://www.zorinaq.com/papers/md5-amd64.html
  3. // http://www.zorinaq.com/papers/md5-amd64.tar.bz2
  4. //
  5. // Translated from Perl generating GNU assembly into
  6. // #defines generating 8a assembly, and adjusted for 386,
  7. // by the Go Authors.
  8. #include "textflag.h"
  9. // MD5 optimized for AMD64.
  10. //
  11. // Author: Marc Bevand <bevand_m (at) epita.fr>
  12. // Licence: I hereby disclaim the copyright on this code and place it
  13. // in the public domain.
  14. #define ROUND1(a, b, c, d, index, const, shift) \
  15. XORL c, BP; \
  16. LEAL const(a)(DI*1), a; \
  17. ANDL b, BP; \
  18. XORL d, BP; \
  19. MOVL (index*4)(SI), DI; \
  20. ADDL BP, a; \
  21. ROLL $shift, a; \
  22. MOVL c, BP; \
  23. ADDL b, a
  24. #define ROUND2(a, b, c, d, index, const, shift) \
  25. LEAL const(a)(DI*1),a; \
  26. MOVL d, DI; \
  27. ANDL b, DI; \
  28. MOVL d, BP; \
  29. NOTL BP; \
  30. ANDL c, BP; \
  31. ORL DI, BP; \
  32. MOVL (index*4)(SI),DI; \
  33. ADDL BP, a; \
  34. ROLL $shift, a; \
  35. ADDL b, a
  36. #define ROUND3(a, b, c, d, index, const, shift) \
  37. LEAL const(a)(DI*1),a; \
  38. MOVL (index*4)(SI),DI; \
  39. XORL d, BP; \
  40. XORL b, BP; \
  41. ADDL BP, a; \
  42. ROLL $shift, a; \
  43. MOVL b, BP; \
  44. ADDL b, a
  45. #define ROUND4(a, b, c, d, index, const, shift) \
  46. LEAL const(a)(DI*1),a; \
  47. ORL b, BP; \
  48. XORL c, BP; \
  49. ADDL BP, a; \
  50. MOVL (index*4)(SI),DI; \
  51. MOVL $0xffffffff, BP; \
  52. ROLL $shift, a; \
  53. XORL c, BP; \
  54. ADDL b, a
  55. TEXT ·block(SB),NOSPLIT,$24-16
  56. MOVL dig+0(FP), BP
  57. MOVL p+4(FP), SI
  58. MOVL p_len+8(FP), DX
  59. SHRL $6, DX
  60. SHLL $6, DX
  61. LEAL (SI)(DX*1), DI
  62. MOVL (0*4)(BP), AX
  63. MOVL (1*4)(BP), BX
  64. MOVL (2*4)(BP), CX
  65. MOVL (3*4)(BP), DX
  66. CMPL SI, DI
  67. JEQ end
  68. MOVL DI, 16(SP)
  69. loop:
  70. MOVL AX, 0(SP)
  71. MOVL BX, 4(SP)
  72. MOVL CX, 8(SP)
  73. MOVL DX, 12(SP)
  74. MOVL (0*4)(SI), DI
  75. MOVL DX, BP
  76. ROUND1(AX,BX,CX,DX, 1,0xd76aa478, 7);
  77. ROUND1(DX,AX,BX,CX, 2,0xe8c7b756,12);
  78. ROUND1(CX,DX,AX,BX, 3,0x242070db,17);
  79. ROUND1(BX,CX,DX,AX, 4,0xc1bdceee,22);
  80. ROUND1(AX,BX,CX,DX, 5,0xf57c0faf, 7);
  81. ROUND1(DX,AX,BX,CX, 6,0x4787c62a,12);
  82. ROUND1(CX,DX,AX,BX, 7,0xa8304613,17);
  83. ROUND1(BX,CX,DX,AX, 8,0xfd469501,22);
  84. ROUND1(AX,BX,CX,DX, 9,0x698098d8, 7);
  85. ROUND1(DX,AX,BX,CX,10,0x8b44f7af,12);
  86. ROUND1(CX,DX,AX,BX,11,0xffff5bb1,17);
  87. ROUND1(BX,CX,DX,AX,12,0x895cd7be,22);
  88. ROUND1(AX,BX,CX,DX,13,0x6b901122, 7);
  89. ROUND1(DX,AX,BX,CX,14,0xfd987193,12);
  90. ROUND1(CX,DX,AX,BX,15,0xa679438e,17);
  91. ROUND1(BX,CX,DX,AX, 0,0x49b40821,22);
  92. MOVL (1*4)(SI), DI
  93. MOVL DX, BP
  94. ROUND2(AX,BX,CX,DX, 6,0xf61e2562, 5);
  95. ROUND2(DX,AX,BX,CX,11,0xc040b340, 9);
  96. ROUND2(CX,DX,AX,BX, 0,0x265e5a51,14);
  97. ROUND2(BX,CX,DX,AX, 5,0xe9b6c7aa,20);
  98. ROUND2(AX,BX,CX,DX,10,0xd62f105d, 5);
  99. ROUND2(DX,AX,BX,CX,15, 0x2441453, 9);
  100. ROUND2(CX,DX,AX,BX, 4,0xd8a1e681,14);
  101. ROUND2(BX,CX,DX,AX, 9,0xe7d3fbc8,20);
  102. ROUND2(AX,BX,CX,DX,14,0x21e1cde6, 5);
  103. ROUND2(DX,AX,BX,CX, 3,0xc33707d6, 9);
  104. ROUND2(CX,DX,AX,BX, 8,0xf4d50d87,14);
  105. ROUND2(BX,CX,DX,AX,13,0x455a14ed,20);
  106. ROUND2(AX,BX,CX,DX, 2,0xa9e3e905, 5);
  107. ROUND2(DX,AX,BX,CX, 7,0xfcefa3f8, 9);
  108. ROUND2(CX,DX,AX,BX,12,0x676f02d9,14);
  109. ROUND2(BX,CX,DX,AX, 0,0x8d2a4c8a,20);
  110. MOVL (5*4)(SI), DI
  111. MOVL CX, BP
  112. ROUND3(AX,BX,CX,DX, 8,0xfffa3942, 4);
  113. ROUND3(DX,AX,BX,CX,11,0x8771f681,11);
  114. ROUND3(CX,DX,AX,BX,14,0x6d9d6122,16);
  115. ROUND3(BX,CX,DX,AX, 1,0xfde5380c,23);
  116. ROUND3(AX,BX,CX,DX, 4,0xa4beea44, 4);
  117. ROUND3(DX,AX,BX,CX, 7,0x4bdecfa9,11);
  118. ROUND3(CX,DX,AX,BX,10,0xf6bb4b60,16);
  119. ROUND3(BX,CX,DX,AX,13,0xbebfbc70,23);
  120. ROUND3(AX,BX,CX,DX, 0,0x289b7ec6, 4);
  121. ROUND3(DX,AX,BX,CX, 3,0xeaa127fa,11);
  122. ROUND3(CX,DX,AX,BX, 6,0xd4ef3085,16);
  123. ROUND3(BX,CX,DX,AX, 9, 0x4881d05,23);
  124. ROUND3(AX,BX,CX,DX,12,0xd9d4d039, 4);
  125. ROUND3(DX,AX,BX,CX,15,0xe6db99e5,11);
  126. ROUND3(CX,DX,AX,BX, 2,0x1fa27cf8,16);
  127. ROUND3(BX,CX,DX,AX, 0,0xc4ac5665,23);
  128. MOVL (0*4)(SI), DI
  129. MOVL $0xffffffff, BP
  130. XORL DX, BP
  131. ROUND4(AX,BX,CX,DX, 7,0xf4292244, 6);
  132. ROUND4(DX,AX,BX,CX,14,0x432aff97,10);
  133. ROUND4(CX,DX,AX,BX, 5,0xab9423a7,15);
  134. ROUND4(BX,CX,DX,AX,12,0xfc93a039,21);
  135. ROUND4(AX,BX,CX,DX, 3,0x655b59c3, 6);
  136. ROUND4(DX,AX,BX,CX,10,0x8f0ccc92,10);
  137. ROUND4(CX,DX,AX,BX, 1,0xffeff47d,15);
  138. ROUND4(BX,CX,DX,AX, 8,0x85845dd1,21);
  139. ROUND4(AX,BX,CX,DX,15,0x6fa87e4f, 6);
  140. ROUND4(DX,AX,BX,CX, 6,0xfe2ce6e0,10);
  141. ROUND4(CX,DX,AX,BX,13,0xa3014314,15);
  142. ROUND4(BX,CX,DX,AX, 4,0x4e0811a1,21);
  143. ROUND4(AX,BX,CX,DX,11,0xf7537e82, 6);
  144. ROUND4(DX,AX,BX,CX, 2,0xbd3af235,10);
  145. ROUND4(CX,DX,AX,BX, 9,0x2ad7d2bb,15);
  146. ROUND4(BX,CX,DX,AX, 0,0xeb86d391,21);
  147. ADDL 0(SP), AX
  148. ADDL 4(SP), BX
  149. ADDL 8(SP), CX
  150. ADDL 12(SP), DX
  151. ADDL $64, SI
  152. CMPL SI, 16(SP)
  153. JB loop
  154. end:
  155. MOVL dig+0(FP), BP
  156. MOVL AX, (0*4)(BP)
  157. MOVL BX, (1*4)(BP)
  158. MOVL CX, (2*4)(BP)
  159. MOVL DX, (3*4)(BP)
  160. RET