keccak1600-x86_64.masm 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. OPTION DOTNAME
  2. .text$ SEGMENT ALIGN(256) 'CODE'
  3. ALIGN 32
  4. __KeccakF1600 PROC PRIVATE
  5. mov rax,QWORD PTR[60+rdi]
  6. mov rbx,QWORD PTR[68+rdi]
  7. mov rcx,QWORD PTR[76+rdi]
  8. mov rdx,QWORD PTR[84+rdi]
  9. mov rbp,QWORD PTR[92+rdi]
  10. jmp $L$oop
  11. ALIGN 32
  12. $L$oop::
  13. mov r8,QWORD PTR[((-100))+rdi]
  14. mov r9,QWORD PTR[((-52))+rdi]
  15. mov r10,QWORD PTR[((-4))+rdi]
  16. mov r11,QWORD PTR[44+rdi]
  17. xor rcx,QWORD PTR[((-84))+rdi]
  18. xor rdx,QWORD PTR[((-76))+rdi]
  19. xor rax,r8
  20. xor rbx,QWORD PTR[((-92))+rdi]
  21. xor rcx,QWORD PTR[((-44))+rdi]
  22. xor rax,QWORD PTR[((-60))+rdi]
  23. mov r12,rbp
  24. xor rbp,QWORD PTR[((-68))+rdi]
  25. xor rcx,r10
  26. xor rax,QWORD PTR[((-20))+rdi]
  27. xor rdx,QWORD PTR[((-36))+rdi]
  28. xor rbx,r9
  29. xor rbp,QWORD PTR[((-28))+rdi]
  30. xor rcx,QWORD PTR[36+rdi]
  31. xor rax,QWORD PTR[20+rdi]
  32. xor rdx,QWORD PTR[4+rdi]
  33. xor rbx,QWORD PTR[((-12))+rdi]
  34. xor rbp,QWORD PTR[12+rdi]
  35. mov r13,rcx
  36. rol rcx,1
  37. xor rcx,rax
  38. xor rdx,r11
  39. rol rax,1
  40. xor rax,rdx
  41. xor rbx,QWORD PTR[28+rdi]
  42. rol rdx,1
  43. xor rdx,rbx
  44. xor rbp,QWORD PTR[52+rdi]
  45. rol rbx,1
  46. xor rbx,rbp
  47. rol rbp,1
  48. xor rbp,r13
  49. xor r9,rcx
  50. xor r10,rdx
  51. rol r9,44
  52. xor r11,rbp
  53. xor r12,rax
  54. rol r10,43
  55. xor r8,rbx
  56. mov r13,r9
  57. rol r11,21
  58. or r9,r10
  59. xor r9,r8
  60. rol r12,14
  61. xor r9,QWORD PTR[r15]
  62. lea r15,QWORD PTR[8+r15]
  63. mov r14,r12
  64. and r12,r11
  65. mov QWORD PTR[((-100))+rsi],r9
  66. xor r12,r10
  67. not r10
  68. mov QWORD PTR[((-84))+rsi],r12
  69. or r10,r11
  70. mov r12,QWORD PTR[76+rdi]
  71. xor r10,r13
  72. mov QWORD PTR[((-92))+rsi],r10
  73. and r13,r8
  74. mov r9,QWORD PTR[((-28))+rdi]
  75. xor r13,r14
  76. mov r10,QWORD PTR[((-20))+rdi]
  77. mov QWORD PTR[((-68))+rsi],r13
  78. or r14,r8
  79. mov r8,QWORD PTR[((-76))+rdi]
  80. xor r14,r11
  81. mov r11,QWORD PTR[28+rdi]
  82. mov QWORD PTR[((-76))+rsi],r14
  83. xor r8,rbp
  84. xor r12,rdx
  85. rol r8,28
  86. xor r11,rcx
  87. xor r9,rax
  88. rol r12,61
  89. rol r11,45
  90. xor r10,rbx
  91. rol r9,20
  92. mov r13,r8
  93. or r8,r12
  94. rol r10,3
  95. xor r8,r11
  96. mov QWORD PTR[((-36))+rsi],r8
  97. mov r14,r9
  98. and r9,r13
  99. mov r8,QWORD PTR[((-92))+rdi]
  100. xor r9,r12
  101. not r12
  102. mov QWORD PTR[((-28))+rsi],r9
  103. or r12,r11
  104. mov r9,QWORD PTR[((-44))+rdi]
  105. xor r12,r10
  106. mov QWORD PTR[((-44))+rsi],r12
  107. and r11,r10
  108. mov r12,QWORD PTR[60+rdi]
  109. xor r11,r14
  110. mov QWORD PTR[((-52))+rsi],r11
  111. or r14,r10
  112. mov r10,QWORD PTR[4+rdi]
  113. xor r14,r13
  114. mov r11,QWORD PTR[52+rdi]
  115. mov QWORD PTR[((-60))+rsi],r14
  116. xor r10,rbp
  117. xor r11,rax
  118. rol r10,25
  119. xor r9,rdx
  120. rol r11,8
  121. xor r12,rbx
  122. rol r9,6
  123. xor r8,rcx
  124. rol r12,18
  125. mov r13,r10
  126. and r10,r11
  127. rol r8,1
  128. not r11
  129. xor r10,r9
  130. mov QWORD PTR[((-12))+rsi],r10
  131. mov r14,r12
  132. and r12,r11
  133. mov r10,QWORD PTR[((-12))+rdi]
  134. xor r12,r13
  135. mov QWORD PTR[((-4))+rsi],r12
  136. or r13,r9
  137. mov r12,QWORD PTR[84+rdi]
  138. xor r13,r8
  139. mov QWORD PTR[((-20))+rsi],r13
  140. and r9,r8
  141. xor r9,r14
  142. mov QWORD PTR[12+rsi],r9
  143. or r14,r8
  144. mov r9,QWORD PTR[((-60))+rdi]
  145. xor r14,r11
  146. mov r11,QWORD PTR[36+rdi]
  147. mov QWORD PTR[4+rsi],r14
  148. mov r8,QWORD PTR[((-68))+rdi]
  149. xor r10,rcx
  150. xor r11,rdx
  151. rol r10,10
  152. xor r9,rbx
  153. rol r11,15
  154. xor r12,rbp
  155. rol r9,36
  156. xor r8,rax
  157. rol r12,56
  158. mov r13,r10
  159. or r10,r11
  160. rol r8,27
  161. not r11
  162. xor r10,r9
  163. mov QWORD PTR[28+rsi],r10
  164. mov r14,r12
  165. or r12,r11
  166. xor r12,r13
  167. mov QWORD PTR[36+rsi],r12
  168. and r13,r9
  169. xor r13,r8
  170. mov QWORD PTR[20+rsi],r13
  171. or r9,r8
  172. xor r9,r14
  173. mov QWORD PTR[52+rsi],r9
  174. and r8,r14
  175. xor r8,r11
  176. mov QWORD PTR[44+rsi],r8
  177. xor rdx,QWORD PTR[((-84))+rdi]
  178. xor rbp,QWORD PTR[((-36))+rdi]
  179. rol rdx,62
  180. xor rcx,QWORD PTR[68+rdi]
  181. rol rbp,55
  182. xor rax,QWORD PTR[12+rdi]
  183. rol rcx,2
  184. xor rbx,QWORD PTR[20+rdi]
  185. xchg rdi,rsi
  186. rol rax,39
  187. rol rbx,41
  188. mov r13,rdx
  189. and rdx,rbp
  190. not rbp
  191. xor rdx,rcx
  192. mov QWORD PTR[92+rdi],rdx
  193. mov r14,rax
  194. and rax,rbp
  195. xor rax,r13
  196. mov QWORD PTR[60+rdi],rax
  197. or r13,rcx
  198. xor r13,rbx
  199. mov QWORD PTR[84+rdi],r13
  200. and rcx,rbx
  201. xor rcx,r14
  202. mov QWORD PTR[76+rdi],rcx
  203. or rbx,r14
  204. xor rbx,rbp
  205. mov QWORD PTR[68+rdi],rbx
  206. mov rbp,rdx
  207. mov rdx,r13
  208. test r15,255
  209. jnz $L$oop
  210. lea r15,QWORD PTR[((-192))+r15]
  211. DB 0F3h,0C3h ;repret
  212. __KeccakF1600 ENDP
  213. ALIGN 32
  214. KeccakF1600 PROC PRIVATE
  215. push rbx
  216. push rbp
  217. push r12
  218. push r13
  219. push r14
  220. push r15
  221. lea rdi,QWORD PTR[100+rdi]
  222. sub rsp,200
  223. not QWORD PTR[((-92))+rdi]
  224. not QWORD PTR[((-84))+rdi]
  225. not QWORD PTR[((-36))+rdi]
  226. not QWORD PTR[((-4))+rdi]
  227. not QWORD PTR[36+rdi]
  228. not QWORD PTR[60+rdi]
  229. lea r15,QWORD PTR[iotas]
  230. lea rsi,QWORD PTR[100+rsp]
  231. call __KeccakF1600
  232. not QWORD PTR[((-92))+rdi]
  233. not QWORD PTR[((-84))+rdi]
  234. not QWORD PTR[((-36))+rdi]
  235. not QWORD PTR[((-4))+rdi]
  236. not QWORD PTR[36+rdi]
  237. not QWORD PTR[60+rdi]
  238. lea rdi,QWORD PTR[((-100))+rdi]
  239. add rsp,200
  240. pop r15
  241. pop r14
  242. pop r13
  243. pop r12
  244. pop rbp
  245. pop rbx
  246. DB 0F3h,0C3h ;repret
  247. KeccakF1600 ENDP
  248. PUBLIC SHA3_absorb
  249. ALIGN 32
  250. SHA3_absorb PROC PUBLIC
  251. mov QWORD PTR[8+rsp],rdi ;WIN64 prologue
  252. mov QWORD PTR[16+rsp],rsi
  253. mov rax,rsp
  254. $L$SEH_begin_SHA3_absorb::
  255. mov rdi,rcx
  256. mov rsi,rdx
  257. mov rdx,r8
  258. mov rcx,r9
  259. push rbx
  260. push rbp
  261. push r12
  262. push r13
  263. push r14
  264. push r15
  265. lea rdi,QWORD PTR[100+rdi]
  266. sub rsp,232
  267. mov r9,rsi
  268. lea rsi,QWORD PTR[100+rsp]
  269. not QWORD PTR[((-92))+rdi]
  270. not QWORD PTR[((-84))+rdi]
  271. not QWORD PTR[((-36))+rdi]
  272. not QWORD PTR[((-4))+rdi]
  273. not QWORD PTR[36+rdi]
  274. not QWORD PTR[60+rdi]
  275. lea r15,QWORD PTR[iotas]
  276. mov QWORD PTR[((216-100))+rsi],rcx
  277. $L$oop_absorb::
  278. cmp rdx,rcx
  279. jc $L$done_absorb
  280. shr rcx,3
  281. lea r8,QWORD PTR[((-100))+rdi]
  282. $L$block_absorb::
  283. mov rax,QWORD PTR[r9]
  284. lea r9,QWORD PTR[8+r9]
  285. xor rax,QWORD PTR[r8]
  286. lea r8,QWORD PTR[8+r8]
  287. sub rdx,8
  288. mov QWORD PTR[((-8))+r8],rax
  289. sub rcx,1
  290. jnz $L$block_absorb
  291. mov QWORD PTR[((200-100))+rsi],r9
  292. mov QWORD PTR[((208-100))+rsi],rdx
  293. call __KeccakF1600
  294. mov r9,QWORD PTR[((200-100))+rsi]
  295. mov rdx,QWORD PTR[((208-100))+rsi]
  296. mov rcx,QWORD PTR[((216-100))+rsi]
  297. jmp $L$oop_absorb
  298. ALIGN 32
  299. $L$done_absorb::
  300. mov rax,rdx
  301. not QWORD PTR[((-92))+rdi]
  302. not QWORD PTR[((-84))+rdi]
  303. not QWORD PTR[((-36))+rdi]
  304. not QWORD PTR[((-4))+rdi]
  305. not QWORD PTR[36+rdi]
  306. not QWORD PTR[60+rdi]
  307. add rsp,232
  308. pop r15
  309. pop r14
  310. pop r13
  311. pop r12
  312. pop rbp
  313. pop rbx
  314. mov rdi,QWORD PTR[8+rsp] ;WIN64 epilogue
  315. mov rsi,QWORD PTR[16+rsp]
  316. DB 0F3h,0C3h ;repret
  317. $L$SEH_end_SHA3_absorb::
  318. SHA3_absorb ENDP
  319. PUBLIC SHA3_squeeze
  320. ALIGN 32
  321. SHA3_squeeze PROC PUBLIC
  322. mov QWORD PTR[8+rsp],rdi ;WIN64 prologue
  323. mov QWORD PTR[16+rsp],rsi
  324. mov rax,rsp
  325. $L$SEH_begin_SHA3_squeeze::
  326. mov rdi,rcx
  327. mov rsi,rdx
  328. mov rdx,r8
  329. mov rcx,r9
  330. push r12
  331. push r13
  332. push r14
  333. shr rcx,3
  334. mov r8,rdi
  335. mov r12,rsi
  336. mov r13,rdx
  337. mov r14,rcx
  338. jmp $L$oop_squeeze
  339. ALIGN 32
  340. $L$oop_squeeze::
  341. cmp r13,8
  342. jb $L$tail_squeeze
  343. mov rax,QWORD PTR[r8]
  344. lea r8,QWORD PTR[8+r8]
  345. mov QWORD PTR[r12],rax
  346. lea r12,QWORD PTR[8+r12]
  347. sub r13,8
  348. jz $L$done_squeeze
  349. sub rcx,1
  350. jnz $L$oop_squeeze
  351. call KeccakF1600
  352. mov r8,rdi
  353. mov rcx,r14
  354. jmp $L$oop_squeeze
  355. $L$tail_squeeze::
  356. mov rsi,r8
  357. mov rdi,r12
  358. mov rcx,r13
  359. DB 0f3h,0a4h
  360. $L$done_squeeze::
  361. pop r14
  362. pop r13
  363. pop r12
  364. mov rdi,QWORD PTR[8+rsp] ;WIN64 epilogue
  365. mov rsi,QWORD PTR[16+rsp]
  366. DB 0F3h,0C3h ;repret
  367. $L$SEH_end_SHA3_squeeze::
  368. SHA3_squeeze ENDP
  369. ALIGN 256
  370. DQ 0,0,0,0,0,0,0,0
  371. iotas::
  372. DQ 00000000000000001h
  373. DQ 00000000000008082h
  374. DQ 0800000000000808ah
  375. DQ 08000000080008000h
  376. DQ 0000000000000808bh
  377. DQ 00000000080000001h
  378. DQ 08000000080008081h
  379. DQ 08000000000008009h
  380. DQ 0000000000000008ah
  381. DQ 00000000000000088h
  382. DQ 00000000080008009h
  383. DQ 0000000008000000ah
  384. DQ 0000000008000808bh
  385. DQ 0800000000000008bh
  386. DQ 08000000000008089h
  387. DQ 08000000000008003h
  388. DQ 08000000000008002h
  389. DQ 08000000000000080h
  390. DQ 0000000000000800ah
  391. DQ 0800000008000000ah
  392. DQ 08000000080008081h
  393. DQ 08000000000008080h
  394. DQ 00000000080000001h
  395. DQ 08000000080008008h
  396. DB 75,101,99,99,97,107,45,49,54,48,48,32,97,98,115,111
  397. DB 114,98,32,97,110,100,32,115,113,117,101,101,122,101,32,102
  398. DB 111,114,32,120,56,54,95,54,52,44,32,67,82,89,80,84
  399. DB 79,71,65,77,83,32,98,121,32,60,97,112,112,114,111,64
  400. DB 111,112,101,110,115,115,108,46,111,114,103,62,0
  401. .text$ ENDS
  402. END