md5block.s 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. /*
  2. * rfc1321 requires that I include this. The code is new. The constants
  3. * all come from the rfc (hence the copyright). We trade a table for the
  4. * macros in rfc. The total size is a lot less. -- presotto
  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
  10. * is 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
  15. * that such works are identified as "derived from the RSA Data
  16. * Security, Inc. MD5 Message-Digest Algorithm" in all material
  17. * mentioning or referencing the derived work.
  18. *
  19. * RSA Data Security, Inc. makes no representations concerning either
  20. * the merchantability of this software or the suitability of this
  21. * software forany particular purpose. It is provided "as is"
  22. * without express or implied warranty of any kind.
  23. * These notices must be retained in any copies of any part of this
  24. * documentation and/or software.
  25. */
  26. /* round 1 */
  27. DATA md5tab<>+( 0*4)(SB)/4,$0xd76aa478
  28. DATA md5tab<>+( 1*4)(SB)/4,$0xe8c7b756
  29. DATA md5tab<>+( 2*4)(SB)/4,$0x242070db
  30. DATA md5tab<>+( 3*4)(SB)/4,$0xc1bdceee
  31. DATA md5tab<>+( 4*4)(SB)/4,$0xf57c0faf
  32. DATA md5tab<>+( 5*4)(SB)/4,$0x4787c62a
  33. DATA md5tab<>+( 6*4)(SB)/4,$0xa8304613
  34. DATA md5tab<>+( 7*4)(SB)/4,$0xfd469501
  35. DATA md5tab<>+( 8*4)(SB)/4,$0x698098d8
  36. DATA md5tab<>+( 9*4)(SB)/4,$0x8b44f7af
  37. DATA md5tab<>+(10*4)(SB)/4,$0xffff5bb1
  38. DATA md5tab<>+(11*4)(SB)/4,$0x895cd7be
  39. DATA md5tab<>+(12*4)(SB)/4,$0x6b901122
  40. DATA md5tab<>+(13*4)(SB)/4,$0xfd987193
  41. DATA md5tab<>+(14*4)(SB)/4,$0xa679438e
  42. DATA md5tab<>+(15*4)(SB)/4,$0x49b40821
  43. /* round 2 */
  44. DATA md5tab<>+(16*4)(SB)/4,$0xf61e2562
  45. DATA md5tab<>+(17*4)(SB)/4,$0xc040b340
  46. DATA md5tab<>+(18*4)(SB)/4,$0x265e5a51
  47. DATA md5tab<>+(19*4)(SB)/4,$0xe9b6c7aa
  48. DATA md5tab<>+(20*4)(SB)/4,$0xd62f105d
  49. DATA md5tab<>+(21*4)(SB)/4,$0x02441453
  50. DATA md5tab<>+(22*4)(SB)/4,$0xd8a1e681
  51. DATA md5tab<>+(23*4)(SB)/4,$0xe7d3fbc8
  52. DATA md5tab<>+(24*4)(SB)/4,$0x21e1cde6
  53. DATA md5tab<>+(25*4)(SB)/4,$0xc33707d6
  54. DATA md5tab<>+(26*4)(SB)/4,$0xf4d50d87
  55. DATA md5tab<>+(27*4)(SB)/4,$0x455a14ed
  56. DATA md5tab<>+(28*4)(SB)/4,$0xa9e3e905
  57. DATA md5tab<>+(29*4)(SB)/4,$0xfcefa3f8
  58. DATA md5tab<>+(30*4)(SB)/4,$0x676f02d9
  59. DATA md5tab<>+(31*4)(SB)/4,$0x8d2a4c8a
  60. /* round 3 */
  61. DATA md5tab<>+(32*4)(SB)/4,$0xfffa3942
  62. DATA md5tab<>+(33*4)(SB)/4,$0x8771f681
  63. DATA md5tab<>+(34*4)(SB)/4,$0x6d9d6122
  64. DATA md5tab<>+(35*4)(SB)/4,$0xfde5380c
  65. DATA md5tab<>+(36*4)(SB)/4,$0xa4beea44
  66. DATA md5tab<>+(37*4)(SB)/4,$0x4bdecfa9
  67. DATA md5tab<>+(38*4)(SB)/4,$0xf6bb4b60
  68. DATA md5tab<>+(39*4)(SB)/4,$0xbebfbc70
  69. DATA md5tab<>+(40*4)(SB)/4,$0x289b7ec6
  70. DATA md5tab<>+(41*4)(SB)/4,$0xeaa127fa
  71. DATA md5tab<>+(42*4)(SB)/4,$0xd4ef3085
  72. DATA md5tab<>+(43*4)(SB)/4,$0x04881d05
  73. DATA md5tab<>+(44*4)(SB)/4,$0xd9d4d039
  74. DATA md5tab<>+(45*4)(SB)/4,$0xe6db99e5
  75. DATA md5tab<>+(46*4)(SB)/4,$0x1fa27cf8
  76. DATA md5tab<>+(47*4)(SB)/4,$0xc4ac5665
  77. /* round 4 */
  78. DATA md5tab<>+(48*4)(SB)/4,$0xf4292244
  79. DATA md5tab<>+(49*4)(SB)/4,$0x432aff97
  80. DATA md5tab<>+(50*4)(SB)/4,$0xab9423a7
  81. DATA md5tab<>+(51*4)(SB)/4,$0xfc93a039
  82. DATA md5tab<>+(52*4)(SB)/4,$0x655b59c3
  83. DATA md5tab<>+(53*4)(SB)/4,$0x8f0ccc92
  84. DATA md5tab<>+(54*4)(SB)/4,$0xffeff47d
  85. DATA md5tab<>+(55*4)(SB)/4,$0x85845dd1
  86. DATA md5tab<>+(56*4)(SB)/4,$0x6fa87e4f
  87. DATA md5tab<>+(57*4)(SB)/4,$0xfe2ce6e0
  88. DATA md5tab<>+(58*4)(SB)/4,$0xa3014314
  89. DATA md5tab<>+(59*4)(SB)/4,$0x4e0811a1
  90. DATA md5tab<>+(60*4)(SB)/4,$0xf7537e82
  91. DATA md5tab<>+(61*4)(SB)/4,$0xbd3af235
  92. DATA md5tab<>+(62*4)(SB)/4,$0x2ad7d2bb
  93. DATA md5tab<>+(63*4)(SB)/4,$0xeb86d391
  94. #define S11 7
  95. #define S12 12
  96. #define S13 17
  97. #define S14 22
  98. #define S21 5
  99. #define S22 9
  100. #define S23 14
  101. #define S24 20
  102. #define S31 4
  103. #define S32 11
  104. #define S33 16
  105. #define S34 23
  106. #define S41 6
  107. #define S42 10
  108. #define S43 15
  109. #define S44 21
  110. #define AREG R5
  111. #define BREG R6
  112. #define CREG R7
  113. #define DREG R8
  114. #define DATAREG R1
  115. #define TABREG R10
  116. #define STREG R11
  117. #define XREG R12
  118. #define ELOOPREG R13
  119. #define EDREG R14
  120. #define IREG R15
  121. #define TMP1 R9
  122. #define TMP2 R2
  123. #define TMP3 R3
  124. #define TMP4 R4
  125. /*
  126. * decode little endian data into x[off], then the body
  127. * bodies have this form:
  128. * a += FN(B,C,D);
  129. * a += x[off] + t[off];
  130. * a = (a << S11) | (a >> (32 - S11));
  131. * a += b;
  132. */
  133. #define BODY1(off,FN,SH,A,B,C,D)\
  134. MOVBU off(DATAREG),TMP2;\
  135. MOVBU (off+1)(DATAREG),TMP3;\
  136. MOVBU (off+2)(DATAREG),TMP1;\
  137. MOVBU (off+3)(DATAREG),TMP4;\
  138. SLL $8,TMP3;\
  139. OR TMP3,TMP2;\
  140. SLL $16,TMP1;\
  141. OR TMP1,TMP2;\
  142. SLL $24,TMP4;\
  143. OR TMP4,TMP2;\
  144. MOVW off(TABREG),TMP3;\
  145. FN(B,C,D)\
  146. ADDU TMP1,A;\
  147. MOVW TMP2,off(XREG);\
  148. ADDU TMP2,A;\
  149. ADDU TMP3,A;\
  150. SLL $SH,A,TMP1;\
  151. SRL $(32-SH),A;\
  152. OR TMP1,A;\
  153. ADDU B,A;\
  154. #define BODY(off,inc,FN,SH,A,B,C,D)\
  155. MOVW off(TABREG),TMP3;\
  156. ADDU XREG,IREG,TMP4;\
  157. MOVW (TMP4),TMP2;\
  158. ADDU $(inc*4),IREG;\
  159. AND $63,IREG;\
  160. FN(B,C,D)\
  161. ADDU TMP1,A;\
  162. ADDU TMP2,A;\
  163. ADDU TMP3,A;\
  164. SLL $SH,A,TMP1;\
  165. SRL $(32-SH),A;\
  166. OR TMP1,A;\
  167. ADDU B,A;\
  168. /*
  169. * fn1 = ((c ^ d) & b) ^ d
  170. */
  171. #define FN1(B,C,D)\
  172. XOR C,D,TMP1;\
  173. AND B,TMP1;\
  174. XOR D,TMP1;\
  175. /*
  176. * fn2 = ((b ^ c) & d) ^ c;
  177. */
  178. #define FN2(B,C,D)\
  179. XOR B,C,TMP1;\
  180. AND D,TMP1;\
  181. XOR C,TMP1;\
  182. /*
  183. * fn3 = b ^ c ^ d;
  184. */
  185. #define FN3(B,C,D)\
  186. XOR B,C,TMP1;\
  187. XOR D,TMP1;\
  188. /*
  189. * fn4 = c ^ (b | ~d);
  190. */
  191. #define FN4(B,C,D)\
  192. XOR $-1,D,TMP1;\
  193. OR B,TMP1;\
  194. XOR C,TMP1;\
  195. #define DATA 0
  196. #define LEN 4
  197. #define STATE 8
  198. #define XOFF (-4-16*4)
  199. TEXT _md5block+0(SB),$68
  200. MOVW len+LEN(FP),TMP1
  201. ADDU DATAREG,TMP1,EDREG
  202. MOVW state+STATE(FP),STREG
  203. MOVW 0(STREG),AREG
  204. MOVW 4(STREG),BREG
  205. MOVW 8(STREG),CREG
  206. MOVW 12(STREG),DREG
  207. mainloop:
  208. MOVW $md5tab<>+0(SB),TABREG
  209. ADDU $(16*4),DATAREG,ELOOPREG
  210. MOVW $x+XOFF(SP),XREG
  211. loop1:
  212. BODY1(0,FN1,S11,AREG,BREG,CREG,DREG)
  213. BODY1(4,FN1,S12,DREG,AREG,BREG,CREG)
  214. BODY1(8,FN1,S13,CREG,DREG,AREG,BREG)
  215. BODY1(12,FN1,S14,BREG,CREG,DREG,AREG)
  216. ADDU $16,DATAREG
  217. ADDU $16,TABREG
  218. ADDU $16,XREG
  219. BNE DATAREG,ELOOPREG,loop1
  220. MOVW $x+XOFF(SP),XREG
  221. MOVW $(1*4),IREG
  222. MOVW $(1*4),ELOOPREG
  223. loop2:
  224. BODY(0,5,FN2,S21,AREG,BREG,CREG,DREG)
  225. BODY(4,5,FN2,S22,DREG,AREG,BREG,CREG)
  226. BODY(8,5,FN2,S23,CREG,DREG,AREG,BREG)
  227. BODY(12,5,FN2,S24,BREG,CREG,DREG,AREG)
  228. ADDU $16,TABREG
  229. BNE IREG,ELOOPREG,loop2
  230. MOVW $(5*4),IREG
  231. MOVW $(5*4),ELOOPREG
  232. loop3:
  233. BODY(0,3,FN3,S31,AREG,BREG,CREG,DREG)
  234. BODY(4,3,FN3,S32,DREG,AREG,BREG,CREG)
  235. BODY(8,3,FN3,S33,CREG,DREG,AREG,BREG)
  236. BODY(12,3,FN3,S34,BREG,CREG,DREG,AREG)
  237. ADDU $16,TABREG
  238. BNE IREG,ELOOPREG,loop3
  239. MOVW $0,IREG
  240. loop4:
  241. BODY(0,7,FN4,S41,AREG,BREG,CREG,DREG)
  242. BODY(4,7,FN4,S42,DREG,AREG,BREG,CREG)
  243. BODY(8,7,FN4,S43,CREG,DREG,AREG,BREG)
  244. BODY(12,7,FN4,S44,BREG,CREG,DREG,AREG)
  245. ADDU $16,TABREG
  246. BNE IREG,R0,loop4
  247. MOVW 0(STREG),TMP1
  248. MOVW 4(STREG),TMP2
  249. MOVW 8(STREG),TMP3
  250. MOVW 12(STREG),TMP4
  251. ADDU TMP1,AREG
  252. ADDU TMP2,BREG
  253. ADDU TMP3,CREG
  254. ADDU TMP4,DREG
  255. MOVW AREG,0(STREG)
  256. MOVW BREG,4(STREG)
  257. MOVW CREG,8(STREG)
  258. MOVW DREG,12(STREG)
  259. BNE DATAREG,EDREG,mainloop
  260. RET
  261. GLOBL md5tab<>+0(SB),$256
  262. END