_chacha20.ssa 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. export function $chacha20_rounds_qbe(l %out, l %in) {
  2. @start
  3. %t0 =w loadw %in
  4. %in =l add %in, 4
  5. %t1 =w loadw %in
  6. %in =l add %in, 4
  7. %t2 =w loadw %in
  8. %in =l add %in, 4
  9. %t3 =w loadw %in
  10. %in =l add %in, 4
  11. %t4 =w loadw %in
  12. %in =l add %in, 4
  13. %t5 =w loadw %in
  14. %in =l add %in, 4
  15. %t6 =w loadw %in
  16. %in =l add %in, 4
  17. %t7 =w loadw %in
  18. %in =l add %in, 4
  19. %t8 =w loadw %in
  20. %in =l add %in, 4
  21. %t9 =w loadw %in
  22. %in =l add %in, 4
  23. %t10 =w loadw %in
  24. %in =l add %in, 4
  25. %t11 =w loadw %in
  26. %in =l add %in, 4
  27. %t12 =w loadw %in
  28. %in =l add %in, 4
  29. %t13 =w loadw %in
  30. %in =l add %in, 4
  31. %t14 =w loadw %in
  32. %in =l add %in, 4
  33. %t15 =w loadw %in
  34. %in =l add %in, 4
  35. %counter =w copy 10
  36. @loop
  37. %t0 =w add %t0, %t4
  38. %t12 =w xor %t12, %t0
  39. %rotl32_a =w shl %t12, 16
  40. %rotl32_b =w shr %t12, 16
  41. %t12 =w xor %rotl32_a, %rotl32_b
  42. %t8 =w add %t8, %t12
  43. %t4 =w xor %t4, %t8
  44. %rotl32_a =w shl %t4, 12
  45. %rotl32_b =w shr %t4, 20
  46. %t4 =w xor %rotl32_a, %rotl32_b
  47. %t0 =w add %t0, %t4
  48. %t12 =w xor %t12, %t0
  49. %rotl32_a =w shl %t12, 8
  50. %rotl32_b =w shr %t12, 24
  51. %t12 =w xor %rotl32_a, %rotl32_b
  52. %t8 =w add %t8, %t12
  53. %t4 =w xor %t4, %t8
  54. %rotl32_a =w shl %t4, 7
  55. %rotl32_b =w shr %t4, 25
  56. %t4 =w xor %rotl32_a, %rotl32_b
  57. %t1 =w add %t1, %t5
  58. %t13 =w xor %t13, %t1
  59. %rotl32_a =w shl %t13, 16
  60. %rotl32_b =w shr %t13, 16
  61. %t13 =w xor %rotl32_a, %rotl32_b
  62. %t9 =w add %t9, %t13
  63. %t5 =w xor %t5, %t9
  64. %rotl32_a =w shl %t5, 12
  65. %rotl32_b =w shr %t5, 20
  66. %t5 =w xor %rotl32_a, %rotl32_b
  67. %t1 =w add %t1, %t5
  68. %t13 =w xor %t13, %t1
  69. %rotl32_a =w shl %t13, 8
  70. %rotl32_b =w shr %t13, 24
  71. %t13 =w xor %rotl32_a, %rotl32_b
  72. %t9 =w add %t9, %t13
  73. %t5 =w xor %t5, %t9
  74. %rotl32_a =w shl %t5, 7
  75. %rotl32_b =w shr %t5, 25
  76. %t5 =w xor %rotl32_a, %rotl32_b
  77. %t2 =w add %t2, %t6
  78. %t14 =w xor %t14, %t2
  79. %rotl32_a =w shl %t14, 16
  80. %rotl32_b =w shr %t14, 16
  81. %t14 =w xor %rotl32_a, %rotl32_b
  82. %t10 =w add %t10, %t14
  83. %t6 =w xor %t6, %t10
  84. %rotl32_a =w shl %t6, 12
  85. %rotl32_b =w shr %t6, 20
  86. %t6 =w xor %rotl32_a, %rotl32_b
  87. %t2 =w add %t2, %t6
  88. %t14 =w xor %t14, %t2
  89. %rotl32_a =w shl %t14, 8
  90. %rotl32_b =w shr %t14, 24
  91. %t14 =w xor %rotl32_a, %rotl32_b
  92. %t10 =w add %t10, %t14
  93. %t6 =w xor %t6, %t10
  94. %rotl32_a =w shl %t6, 7
  95. %rotl32_b =w shr %t6, 25
  96. %t6 =w xor %rotl32_a, %rotl32_b
  97. %t3 =w add %t3, %t7
  98. %t15 =w xor %t15, %t3
  99. %rotl32_a =w shl %t15, 16
  100. %rotl32_b =w shr %t15, 16
  101. %t15 =w xor %rotl32_a, %rotl32_b
  102. %t11 =w add %t11, %t15
  103. %t7 =w xor %t7, %t11
  104. %rotl32_a =w shl %t7, 12
  105. %rotl32_b =w shr %t7, 20
  106. %t7 =w xor %rotl32_a, %rotl32_b
  107. %t3 =w add %t3, %t7
  108. %t15 =w xor %t15, %t3
  109. %rotl32_a =w shl %t15, 8
  110. %rotl32_b =w shr %t15, 24
  111. %t15 =w xor %rotl32_a, %rotl32_b
  112. %t11 =w add %t11, %t15
  113. %t7 =w xor %t7, %t11
  114. %rotl32_a =w shl %t7, 7
  115. %rotl32_b =w shr %t7, 25
  116. %t7 =w xor %rotl32_a, %rotl32_b
  117. %t0 =w add %t0, %t5
  118. %t15 =w xor %t15, %t0
  119. %rotl32_a =w shl %t15, 16
  120. %rotl32_b =w shr %t15, 16
  121. %t15 =w xor %rotl32_a, %rotl32_b
  122. %t10 =w add %t10, %t15
  123. %t5 =w xor %t5, %t10
  124. %rotl32_a =w shl %t5, 12
  125. %rotl32_b =w shr %t5, 20
  126. %t5 =w xor %rotl32_a, %rotl32_b
  127. %t0 =w add %t0, %t5
  128. %t15 =w xor %t15, %t0
  129. %rotl32_a =w shl %t15, 8
  130. %rotl32_b =w shr %t15, 24
  131. %t15 =w xor %rotl32_a, %rotl32_b
  132. %t10 =w add %t10, %t15
  133. %t5 =w xor %t5, %t10
  134. %rotl32_a =w shl %t5, 7
  135. %rotl32_b =w shr %t5, 25
  136. %t5 =w xor %rotl32_a, %rotl32_b
  137. %t1 =w add %t1, %t6
  138. %t12 =w xor %t12, %t1
  139. %rotl32_a =w shl %t12, 16
  140. %rotl32_b =w shr %t12, 16
  141. %t12 =w xor %rotl32_a, %rotl32_b
  142. %t11 =w add %t11, %t12
  143. %t6 =w xor %t6, %t11
  144. %rotl32_a =w shl %t6, 12
  145. %rotl32_b =w shr %t6, 20
  146. %t6 =w xor %rotl32_a, %rotl32_b
  147. %t1 =w add %t1, %t6
  148. %t12 =w xor %t12, %t1
  149. %rotl32_a =w shl %t12, 8
  150. %rotl32_b =w shr %t12, 24
  151. %t12 =w xor %rotl32_a, %rotl32_b
  152. %t11 =w add %t11, %t12
  153. %t6 =w xor %t6, %t11
  154. %rotl32_a =w shl %t6, 7
  155. %rotl32_b =w shr %t6, 25
  156. %t6 =w xor %rotl32_a, %rotl32_b
  157. %t2 =w add %t2, %t7
  158. %t13 =w xor %t13, %t2
  159. %rotl32_a =w shl %t13, 16
  160. %rotl32_b =w shr %t13, 16
  161. %t13 =w xor %rotl32_a, %rotl32_b
  162. %t8 =w add %t8, %t13
  163. %t7 =w xor %t7, %t8
  164. %rotl32_a =w shl %t7, 12
  165. %rotl32_b =w shr %t7, 20
  166. %t7 =w xor %rotl32_a, %rotl32_b
  167. %t2 =w add %t2, %t7
  168. %t13 =w xor %t13, %t2
  169. %rotl32_a =w shl %t13, 8
  170. %rotl32_b =w shr %t13, 24
  171. %t13 =w xor %rotl32_a, %rotl32_b
  172. %t8 =w add %t8, %t13
  173. %t7 =w xor %t7, %t8
  174. %rotl32_a =w shl %t7, 7
  175. %rotl32_b =w shr %t7, 25
  176. %t7 =w xor %rotl32_a, %rotl32_b
  177. %t3 =w add %t3, %t4
  178. %t14 =w xor %t14, %t3
  179. %rotl32_a =w shl %t14, 16
  180. %rotl32_b =w shr %t14, 16
  181. %t14 =w xor %rotl32_a, %rotl32_b
  182. %t9 =w add %t9, %t14
  183. %t4 =w xor %t4, %t9
  184. %rotl32_a =w shl %t4, 12
  185. %rotl32_b =w shr %t4, 20
  186. %t4 =w xor %rotl32_a, %rotl32_b
  187. %t3 =w add %t3, %t4
  188. %t14 =w xor %t14, %t3
  189. %rotl32_a =w shl %t14, 8
  190. %rotl32_b =w shr %t14, 24
  191. %t14 =w xor %rotl32_a, %rotl32_b
  192. %t9 =w add %t9, %t14
  193. %t4 =w xor %t4, %t9
  194. %rotl32_a =w shl %t4, 7
  195. %rotl32_b =w shr %t4, 25
  196. %t4 =w xor %rotl32_a, %rotl32_b
  197. %counter =w sub %counter, 10
  198. jnz %counter, @loop, @done
  199. @done
  200. storew %t0, %out
  201. %out =l add %out, 4
  202. storew %t1, %out
  203. %out =l add %out, 4
  204. storew %t2, %out
  205. %out =l add %out, 4
  206. storew %t3, %out
  207. %out =l add %out, 4
  208. storew %t4, %out
  209. %out =l add %out, 4
  210. storew %t5, %out
  211. %out =l add %out, 4
  212. storew %t6, %out
  213. %out =l add %out, 4
  214. storew %t7, %out
  215. %out =l add %out, 4
  216. storew %t8, %out
  217. %out =l add %out, 4
  218. storew %t9, %out
  219. %out =l add %out, 4
  220. storew %t10, %out
  221. %out =l add %out, 4
  222. storew %t11, %out
  223. %out =l add %out, 4
  224. storew %t12, %out
  225. %out =l add %out, 4
  226. storew %t13, %out
  227. %out =l add %out, 4
  228. storew %t14, %out
  229. %out =l add %out, 4
  230. storew %t15, %out
  231. %out =l add %out, 4
  232. ret
  233. }