vpaes-x86_64.masm 22 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169
  1. OPTION DOTNAME
  2. .text$ SEGMENT ALIGN(256) 'CODE'
  3. ALIGN 16
  4. _vpaes_encrypt_core PROC PRIVATE
  5. mov r9,rdx
  6. mov r11,16
  7. mov eax,DWORD PTR[240+rdx]
  8. movdqa xmm1,xmm9
  9. movdqa xmm2,XMMWORD PTR[$L$k_ipt]
  10. pandn xmm1,xmm0
  11. movdqu xmm5,XMMWORD PTR[r9]
  12. psrld xmm1,4
  13. pand xmm0,xmm9
  14. DB 102,15,56,0,208
  15. movdqa xmm0,XMMWORD PTR[(($L$k_ipt+16))]
  16. DB 102,15,56,0,193
  17. pxor xmm2,xmm5
  18. add r9,16
  19. pxor xmm0,xmm2
  20. lea r10,QWORD PTR[$L$k_mc_backward]
  21. jmp $L$enc_entry
  22. ALIGN 16
  23. $L$enc_loop::
  24. movdqa xmm4,xmm13
  25. movdqa xmm0,xmm12
  26. DB 102,15,56,0,226
  27. DB 102,15,56,0,195
  28. pxor xmm4,xmm5
  29. movdqa xmm5,xmm15
  30. pxor xmm0,xmm4
  31. movdqa xmm1,XMMWORD PTR[((-64))+r10*1+r11]
  32. DB 102,15,56,0,234
  33. movdqa xmm4,XMMWORD PTR[r10*1+r11]
  34. movdqa xmm2,xmm14
  35. DB 102,15,56,0,211
  36. movdqa xmm3,xmm0
  37. pxor xmm2,xmm5
  38. DB 102,15,56,0,193
  39. add r9,16
  40. pxor xmm0,xmm2
  41. DB 102,15,56,0,220
  42. add r11,16
  43. pxor xmm3,xmm0
  44. DB 102,15,56,0,193
  45. and r11,030h
  46. sub rax,1
  47. pxor xmm0,xmm3
  48. $L$enc_entry::
  49. movdqa xmm1,xmm9
  50. movdqa xmm5,xmm11
  51. pandn xmm1,xmm0
  52. psrld xmm1,4
  53. pand xmm0,xmm9
  54. DB 102,15,56,0,232
  55. movdqa xmm3,xmm10
  56. pxor xmm0,xmm1
  57. DB 102,15,56,0,217
  58. movdqa xmm4,xmm10
  59. pxor xmm3,xmm5
  60. DB 102,15,56,0,224
  61. movdqa xmm2,xmm10
  62. pxor xmm4,xmm5
  63. DB 102,15,56,0,211
  64. movdqa xmm3,xmm10
  65. pxor xmm2,xmm0
  66. DB 102,15,56,0,220
  67. movdqu xmm5,XMMWORD PTR[r9]
  68. pxor xmm3,xmm1
  69. jnz $L$enc_loop
  70. movdqa xmm4,XMMWORD PTR[((-96))+r10]
  71. movdqa xmm0,XMMWORD PTR[((-80))+r10]
  72. DB 102,15,56,0,226
  73. pxor xmm4,xmm5
  74. DB 102,15,56,0,195
  75. movdqa xmm1,XMMWORD PTR[64+r10*1+r11]
  76. pxor xmm0,xmm4
  77. DB 102,15,56,0,193
  78. DB 0F3h,0C3h ;repret
  79. _vpaes_encrypt_core ENDP
  80. ALIGN 16
  81. _vpaes_decrypt_core PROC PRIVATE
  82. mov r9,rdx
  83. mov eax,DWORD PTR[240+rdx]
  84. movdqa xmm1,xmm9
  85. movdqa xmm2,XMMWORD PTR[$L$k_dipt]
  86. pandn xmm1,xmm0
  87. mov r11,rax
  88. psrld xmm1,4
  89. movdqu xmm5,XMMWORD PTR[r9]
  90. shl r11,4
  91. pand xmm0,xmm9
  92. DB 102,15,56,0,208
  93. movdqa xmm0,XMMWORD PTR[(($L$k_dipt+16))]
  94. xor r11,030h
  95. lea r10,QWORD PTR[$L$k_dsbd]
  96. DB 102,15,56,0,193
  97. and r11,030h
  98. pxor xmm2,xmm5
  99. movdqa xmm5,XMMWORD PTR[(($L$k_mc_forward+48))]
  100. pxor xmm0,xmm2
  101. add r9,16
  102. add r11,r10
  103. jmp $L$dec_entry
  104. ALIGN 16
  105. $L$dec_loop::
  106. movdqa xmm4,XMMWORD PTR[((-32))+r10]
  107. movdqa xmm1,XMMWORD PTR[((-16))+r10]
  108. DB 102,15,56,0,226
  109. DB 102,15,56,0,203
  110. pxor xmm0,xmm4
  111. movdqa xmm4,XMMWORD PTR[r10]
  112. pxor xmm0,xmm1
  113. movdqa xmm1,XMMWORD PTR[16+r10]
  114. DB 102,15,56,0,226
  115. DB 102,15,56,0,197
  116. DB 102,15,56,0,203
  117. pxor xmm0,xmm4
  118. movdqa xmm4,XMMWORD PTR[32+r10]
  119. pxor xmm0,xmm1
  120. movdqa xmm1,XMMWORD PTR[48+r10]
  121. DB 102,15,56,0,226
  122. DB 102,15,56,0,197
  123. DB 102,15,56,0,203
  124. pxor xmm0,xmm4
  125. movdqa xmm4,XMMWORD PTR[64+r10]
  126. pxor xmm0,xmm1
  127. movdqa xmm1,XMMWORD PTR[80+r10]
  128. DB 102,15,56,0,226
  129. DB 102,15,56,0,197
  130. DB 102,15,56,0,203
  131. pxor xmm0,xmm4
  132. add r9,16
  133. DB 102,15,58,15,237,12
  134. pxor xmm0,xmm1
  135. sub rax,1
  136. $L$dec_entry::
  137. movdqa xmm1,xmm9
  138. pandn xmm1,xmm0
  139. movdqa xmm2,xmm11
  140. psrld xmm1,4
  141. pand xmm0,xmm9
  142. DB 102,15,56,0,208
  143. movdqa xmm3,xmm10
  144. pxor xmm0,xmm1
  145. DB 102,15,56,0,217
  146. movdqa xmm4,xmm10
  147. pxor xmm3,xmm2
  148. DB 102,15,56,0,224
  149. pxor xmm4,xmm2
  150. movdqa xmm2,xmm10
  151. DB 102,15,56,0,211
  152. movdqa xmm3,xmm10
  153. pxor xmm2,xmm0
  154. DB 102,15,56,0,220
  155. movdqu xmm0,XMMWORD PTR[r9]
  156. pxor xmm3,xmm1
  157. jnz $L$dec_loop
  158. movdqa xmm4,XMMWORD PTR[96+r10]
  159. DB 102,15,56,0,226
  160. pxor xmm4,xmm0
  161. movdqa xmm0,XMMWORD PTR[112+r10]
  162. movdqa xmm2,XMMWORD PTR[((-352))+r11]
  163. DB 102,15,56,0,195
  164. pxor xmm0,xmm4
  165. DB 102,15,56,0,194
  166. DB 0F3h,0C3h ;repret
  167. _vpaes_decrypt_core ENDP
  168. ALIGN 16
  169. _vpaes_schedule_core PROC PRIVATE
  170. call _vpaes_preheat
  171. movdqa xmm8,XMMWORD PTR[$L$k_rcon]
  172. movdqu xmm0,XMMWORD PTR[rdi]
  173. movdqa xmm3,xmm0
  174. lea r11,QWORD PTR[$L$k_ipt]
  175. call _vpaes_schedule_transform
  176. movdqa xmm7,xmm0
  177. lea r10,QWORD PTR[$L$k_sr]
  178. test rcx,rcx
  179. jnz $L$schedule_am_decrypting
  180. movdqu XMMWORD PTR[rdx],xmm0
  181. jmp $L$schedule_go
  182. $L$schedule_am_decrypting::
  183. movdqa xmm1,XMMWORD PTR[r10*1+r8]
  184. DB 102,15,56,0,217
  185. movdqu XMMWORD PTR[rdx],xmm3
  186. xor r8,030h
  187. $L$schedule_go::
  188. cmp esi,192
  189. ja $L$schedule_256
  190. je $L$schedule_192
  191. $L$schedule_128::
  192. mov esi,10
  193. $L$oop_schedule_128::
  194. call _vpaes_schedule_round
  195. dec rsi
  196. jz $L$schedule_mangle_last
  197. call _vpaes_schedule_mangle
  198. jmp $L$oop_schedule_128
  199. ALIGN 16
  200. $L$schedule_192::
  201. movdqu xmm0,XMMWORD PTR[8+rdi]
  202. call _vpaes_schedule_transform
  203. movdqa xmm6,xmm0
  204. pxor xmm4,xmm4
  205. movhlps xmm6,xmm4
  206. mov esi,4
  207. $L$oop_schedule_192::
  208. call _vpaes_schedule_round
  209. DB 102,15,58,15,198,8
  210. call _vpaes_schedule_mangle
  211. call _vpaes_schedule_192_smear
  212. call _vpaes_schedule_mangle
  213. call _vpaes_schedule_round
  214. dec rsi
  215. jz $L$schedule_mangle_last
  216. call _vpaes_schedule_mangle
  217. call _vpaes_schedule_192_smear
  218. jmp $L$oop_schedule_192
  219. ALIGN 16
  220. $L$schedule_256::
  221. movdqu xmm0,XMMWORD PTR[16+rdi]
  222. call _vpaes_schedule_transform
  223. mov esi,7
  224. $L$oop_schedule_256::
  225. call _vpaes_schedule_mangle
  226. movdqa xmm6,xmm0
  227. call _vpaes_schedule_round
  228. dec rsi
  229. jz $L$schedule_mangle_last
  230. call _vpaes_schedule_mangle
  231. pshufd xmm0,xmm0,0FFh
  232. movdqa xmm5,xmm7
  233. movdqa xmm7,xmm6
  234. call _vpaes_schedule_low_round
  235. movdqa xmm7,xmm5
  236. jmp $L$oop_schedule_256
  237. ALIGN 16
  238. $L$schedule_mangle_last::
  239. lea r11,QWORD PTR[$L$k_deskew]
  240. test rcx,rcx
  241. jnz $L$schedule_mangle_last_dec
  242. movdqa xmm1,XMMWORD PTR[r10*1+r8]
  243. DB 102,15,56,0,193
  244. lea r11,QWORD PTR[$L$k_opt]
  245. add rdx,32
  246. $L$schedule_mangle_last_dec::
  247. add rdx,-16
  248. pxor xmm0,XMMWORD PTR[$L$k_s63]
  249. call _vpaes_schedule_transform
  250. movdqu XMMWORD PTR[rdx],xmm0
  251. pxor xmm0,xmm0
  252. pxor xmm1,xmm1
  253. pxor xmm2,xmm2
  254. pxor xmm3,xmm3
  255. pxor xmm4,xmm4
  256. pxor xmm5,xmm5
  257. pxor xmm6,xmm6
  258. pxor xmm7,xmm7
  259. DB 0F3h,0C3h ;repret
  260. _vpaes_schedule_core ENDP
  261. ALIGN 16
  262. _vpaes_schedule_192_smear PROC PRIVATE
  263. pshufd xmm1,xmm6,080h
  264. pshufd xmm0,xmm7,0FEh
  265. pxor xmm6,xmm1
  266. pxor xmm1,xmm1
  267. pxor xmm6,xmm0
  268. movdqa xmm0,xmm6
  269. movhlps xmm6,xmm1
  270. DB 0F3h,0C3h ;repret
  271. _vpaes_schedule_192_smear ENDP
  272. ALIGN 16
  273. _vpaes_schedule_round PROC PRIVATE
  274. pxor xmm1,xmm1
  275. DB 102,65,15,58,15,200,15
  276. DB 102,69,15,58,15,192,15
  277. pxor xmm7,xmm1
  278. pshufd xmm0,xmm0,0FFh
  279. DB 102,15,58,15,192,1
  280. _vpaes_schedule_low_round::
  281. movdqa xmm1,xmm7
  282. pslldq xmm7,4
  283. pxor xmm7,xmm1
  284. movdqa xmm1,xmm7
  285. pslldq xmm7,8
  286. pxor xmm7,xmm1
  287. pxor xmm7,XMMWORD PTR[$L$k_s63]
  288. movdqa xmm1,xmm9
  289. pandn xmm1,xmm0
  290. psrld xmm1,4
  291. pand xmm0,xmm9
  292. movdqa xmm2,xmm11
  293. DB 102,15,56,0,208
  294. pxor xmm0,xmm1
  295. movdqa xmm3,xmm10
  296. DB 102,15,56,0,217
  297. pxor xmm3,xmm2
  298. movdqa xmm4,xmm10
  299. DB 102,15,56,0,224
  300. pxor xmm4,xmm2
  301. movdqa xmm2,xmm10
  302. DB 102,15,56,0,211
  303. pxor xmm2,xmm0
  304. movdqa xmm3,xmm10
  305. DB 102,15,56,0,220
  306. pxor xmm3,xmm1
  307. movdqa xmm4,xmm13
  308. DB 102,15,56,0,226
  309. movdqa xmm0,xmm12
  310. DB 102,15,56,0,195
  311. pxor xmm0,xmm4
  312. pxor xmm0,xmm7
  313. movdqa xmm7,xmm0
  314. DB 0F3h,0C3h ;repret
  315. _vpaes_schedule_round ENDP
  316. ALIGN 16
  317. _vpaes_schedule_transform PROC PRIVATE
  318. movdqa xmm1,xmm9
  319. pandn xmm1,xmm0
  320. psrld xmm1,4
  321. pand xmm0,xmm9
  322. movdqa xmm2,XMMWORD PTR[r11]
  323. DB 102,15,56,0,208
  324. movdqa xmm0,XMMWORD PTR[16+r11]
  325. DB 102,15,56,0,193
  326. pxor xmm0,xmm2
  327. DB 0F3h,0C3h ;repret
  328. _vpaes_schedule_transform ENDP
  329. ALIGN 16
  330. _vpaes_schedule_mangle PROC PRIVATE
  331. movdqa xmm4,xmm0
  332. movdqa xmm5,XMMWORD PTR[$L$k_mc_forward]
  333. test rcx,rcx
  334. jnz $L$schedule_mangle_dec
  335. add rdx,16
  336. pxor xmm4,XMMWORD PTR[$L$k_s63]
  337. DB 102,15,56,0,229
  338. movdqa xmm3,xmm4
  339. DB 102,15,56,0,229
  340. pxor xmm3,xmm4
  341. DB 102,15,56,0,229
  342. pxor xmm3,xmm4
  343. jmp $L$schedule_mangle_both
  344. ALIGN 16
  345. $L$schedule_mangle_dec::
  346. lea r11,QWORD PTR[$L$k_dksd]
  347. movdqa xmm1,xmm9
  348. pandn xmm1,xmm4
  349. psrld xmm1,4
  350. pand xmm4,xmm9
  351. movdqa xmm2,XMMWORD PTR[r11]
  352. DB 102,15,56,0,212
  353. movdqa xmm3,XMMWORD PTR[16+r11]
  354. DB 102,15,56,0,217
  355. pxor xmm3,xmm2
  356. DB 102,15,56,0,221
  357. movdqa xmm2,XMMWORD PTR[32+r11]
  358. DB 102,15,56,0,212
  359. pxor xmm2,xmm3
  360. movdqa xmm3,XMMWORD PTR[48+r11]
  361. DB 102,15,56,0,217
  362. pxor xmm3,xmm2
  363. DB 102,15,56,0,221
  364. movdqa xmm2,XMMWORD PTR[64+r11]
  365. DB 102,15,56,0,212
  366. pxor xmm2,xmm3
  367. movdqa xmm3,XMMWORD PTR[80+r11]
  368. DB 102,15,56,0,217
  369. pxor xmm3,xmm2
  370. DB 102,15,56,0,221
  371. movdqa xmm2,XMMWORD PTR[96+r11]
  372. DB 102,15,56,0,212
  373. pxor xmm2,xmm3
  374. movdqa xmm3,XMMWORD PTR[112+r11]
  375. DB 102,15,56,0,217
  376. pxor xmm3,xmm2
  377. add rdx,-16
  378. $L$schedule_mangle_both::
  379. movdqa xmm1,XMMWORD PTR[r10*1+r8]
  380. DB 102,15,56,0,217
  381. add r8,-16
  382. and r8,030h
  383. movdqu XMMWORD PTR[rdx],xmm3
  384. DB 0F3h,0C3h ;repret
  385. _vpaes_schedule_mangle ENDP
  386. PUBLIC vpaes_set_encrypt_key
  387. ALIGN 16
  388. vpaes_set_encrypt_key PROC PUBLIC
  389. mov QWORD PTR[8+rsp],rdi ;WIN64 prologue
  390. mov QWORD PTR[16+rsp],rsi
  391. mov rax,rsp
  392. $L$SEH_begin_vpaes_set_encrypt_key::
  393. mov rdi,rcx
  394. mov rsi,rdx
  395. mov rdx,r8
  396. lea rsp,QWORD PTR[((-184))+rsp]
  397. movaps XMMWORD PTR[16+rsp],xmm6
  398. movaps XMMWORD PTR[32+rsp],xmm7
  399. movaps XMMWORD PTR[48+rsp],xmm8
  400. movaps XMMWORD PTR[64+rsp],xmm9
  401. movaps XMMWORD PTR[80+rsp],xmm10
  402. movaps XMMWORD PTR[96+rsp],xmm11
  403. movaps XMMWORD PTR[112+rsp],xmm12
  404. movaps XMMWORD PTR[128+rsp],xmm13
  405. movaps XMMWORD PTR[144+rsp],xmm14
  406. movaps XMMWORD PTR[160+rsp],xmm15
  407. $L$enc_key_body::
  408. mov eax,esi
  409. shr eax,5
  410. add eax,5
  411. mov DWORD PTR[240+rdx],eax
  412. mov ecx,0
  413. mov r8d,030h
  414. call _vpaes_schedule_core
  415. movaps xmm6,XMMWORD PTR[16+rsp]
  416. movaps xmm7,XMMWORD PTR[32+rsp]
  417. movaps xmm8,XMMWORD PTR[48+rsp]
  418. movaps xmm9,XMMWORD PTR[64+rsp]
  419. movaps xmm10,XMMWORD PTR[80+rsp]
  420. movaps xmm11,XMMWORD PTR[96+rsp]
  421. movaps xmm12,XMMWORD PTR[112+rsp]
  422. movaps xmm13,XMMWORD PTR[128+rsp]
  423. movaps xmm14,XMMWORD PTR[144+rsp]
  424. movaps xmm15,XMMWORD PTR[160+rsp]
  425. lea rsp,QWORD PTR[184+rsp]
  426. $L$enc_key_epilogue::
  427. xor eax,eax
  428. mov rdi,QWORD PTR[8+rsp] ;WIN64 epilogue
  429. mov rsi,QWORD PTR[16+rsp]
  430. DB 0F3h,0C3h ;repret
  431. $L$SEH_end_vpaes_set_encrypt_key::
  432. vpaes_set_encrypt_key ENDP
  433. PUBLIC vpaes_set_decrypt_key
  434. ALIGN 16
  435. vpaes_set_decrypt_key PROC PUBLIC
  436. mov QWORD PTR[8+rsp],rdi ;WIN64 prologue
  437. mov QWORD PTR[16+rsp],rsi
  438. mov rax,rsp
  439. $L$SEH_begin_vpaes_set_decrypt_key::
  440. mov rdi,rcx
  441. mov rsi,rdx
  442. mov rdx,r8
  443. lea rsp,QWORD PTR[((-184))+rsp]
  444. movaps XMMWORD PTR[16+rsp],xmm6
  445. movaps XMMWORD PTR[32+rsp],xmm7
  446. movaps XMMWORD PTR[48+rsp],xmm8
  447. movaps XMMWORD PTR[64+rsp],xmm9
  448. movaps XMMWORD PTR[80+rsp],xmm10
  449. movaps XMMWORD PTR[96+rsp],xmm11
  450. movaps XMMWORD PTR[112+rsp],xmm12
  451. movaps XMMWORD PTR[128+rsp],xmm13
  452. movaps XMMWORD PTR[144+rsp],xmm14
  453. movaps XMMWORD PTR[160+rsp],xmm15
  454. $L$dec_key_body::
  455. mov eax,esi
  456. shr eax,5
  457. add eax,5
  458. mov DWORD PTR[240+rdx],eax
  459. shl eax,4
  460. lea rdx,QWORD PTR[16+rax*1+rdx]
  461. mov ecx,1
  462. mov r8d,esi
  463. shr r8d,1
  464. and r8d,32
  465. xor r8d,32
  466. call _vpaes_schedule_core
  467. movaps xmm6,XMMWORD PTR[16+rsp]
  468. movaps xmm7,XMMWORD PTR[32+rsp]
  469. movaps xmm8,XMMWORD PTR[48+rsp]
  470. movaps xmm9,XMMWORD PTR[64+rsp]
  471. movaps xmm10,XMMWORD PTR[80+rsp]
  472. movaps xmm11,XMMWORD PTR[96+rsp]
  473. movaps xmm12,XMMWORD PTR[112+rsp]
  474. movaps xmm13,XMMWORD PTR[128+rsp]
  475. movaps xmm14,XMMWORD PTR[144+rsp]
  476. movaps xmm15,XMMWORD PTR[160+rsp]
  477. lea rsp,QWORD PTR[184+rsp]
  478. $L$dec_key_epilogue::
  479. xor eax,eax
  480. mov rdi,QWORD PTR[8+rsp] ;WIN64 epilogue
  481. mov rsi,QWORD PTR[16+rsp]
  482. DB 0F3h,0C3h ;repret
  483. $L$SEH_end_vpaes_set_decrypt_key::
  484. vpaes_set_decrypt_key ENDP
  485. PUBLIC vpaes_encrypt
  486. ALIGN 16
  487. vpaes_encrypt PROC PUBLIC
  488. mov QWORD PTR[8+rsp],rdi ;WIN64 prologue
  489. mov QWORD PTR[16+rsp],rsi
  490. mov rax,rsp
  491. $L$SEH_begin_vpaes_encrypt::
  492. mov rdi,rcx
  493. mov rsi,rdx
  494. mov rdx,r8
  495. lea rsp,QWORD PTR[((-184))+rsp]
  496. movaps XMMWORD PTR[16+rsp],xmm6
  497. movaps XMMWORD PTR[32+rsp],xmm7
  498. movaps XMMWORD PTR[48+rsp],xmm8
  499. movaps XMMWORD PTR[64+rsp],xmm9
  500. movaps XMMWORD PTR[80+rsp],xmm10
  501. movaps XMMWORD PTR[96+rsp],xmm11
  502. movaps XMMWORD PTR[112+rsp],xmm12
  503. movaps XMMWORD PTR[128+rsp],xmm13
  504. movaps XMMWORD PTR[144+rsp],xmm14
  505. movaps XMMWORD PTR[160+rsp],xmm15
  506. $L$enc_body::
  507. movdqu xmm0,XMMWORD PTR[rdi]
  508. call _vpaes_preheat
  509. call _vpaes_encrypt_core
  510. movdqu XMMWORD PTR[rsi],xmm0
  511. movaps xmm6,XMMWORD PTR[16+rsp]
  512. movaps xmm7,XMMWORD PTR[32+rsp]
  513. movaps xmm8,XMMWORD PTR[48+rsp]
  514. movaps xmm9,XMMWORD PTR[64+rsp]
  515. movaps xmm10,XMMWORD PTR[80+rsp]
  516. movaps xmm11,XMMWORD PTR[96+rsp]
  517. movaps xmm12,XMMWORD PTR[112+rsp]
  518. movaps xmm13,XMMWORD PTR[128+rsp]
  519. movaps xmm14,XMMWORD PTR[144+rsp]
  520. movaps xmm15,XMMWORD PTR[160+rsp]
  521. lea rsp,QWORD PTR[184+rsp]
  522. $L$enc_epilogue::
  523. mov rdi,QWORD PTR[8+rsp] ;WIN64 epilogue
  524. mov rsi,QWORD PTR[16+rsp]
  525. DB 0F3h,0C3h ;repret
  526. $L$SEH_end_vpaes_encrypt::
  527. vpaes_encrypt ENDP
  528. PUBLIC vpaes_decrypt
  529. ALIGN 16
  530. vpaes_decrypt PROC PUBLIC
  531. mov QWORD PTR[8+rsp],rdi ;WIN64 prologue
  532. mov QWORD PTR[16+rsp],rsi
  533. mov rax,rsp
  534. $L$SEH_begin_vpaes_decrypt::
  535. mov rdi,rcx
  536. mov rsi,rdx
  537. mov rdx,r8
  538. lea rsp,QWORD PTR[((-184))+rsp]
  539. movaps XMMWORD PTR[16+rsp],xmm6
  540. movaps XMMWORD PTR[32+rsp],xmm7
  541. movaps XMMWORD PTR[48+rsp],xmm8
  542. movaps XMMWORD PTR[64+rsp],xmm9
  543. movaps XMMWORD PTR[80+rsp],xmm10
  544. movaps XMMWORD PTR[96+rsp],xmm11
  545. movaps XMMWORD PTR[112+rsp],xmm12
  546. movaps XMMWORD PTR[128+rsp],xmm13
  547. movaps XMMWORD PTR[144+rsp],xmm14
  548. movaps XMMWORD PTR[160+rsp],xmm15
  549. $L$dec_body::
  550. movdqu xmm0,XMMWORD PTR[rdi]
  551. call _vpaes_preheat
  552. call _vpaes_decrypt_core
  553. movdqu XMMWORD PTR[rsi],xmm0
  554. movaps xmm6,XMMWORD PTR[16+rsp]
  555. movaps xmm7,XMMWORD PTR[32+rsp]
  556. movaps xmm8,XMMWORD PTR[48+rsp]
  557. movaps xmm9,XMMWORD PTR[64+rsp]
  558. movaps xmm10,XMMWORD PTR[80+rsp]
  559. movaps xmm11,XMMWORD PTR[96+rsp]
  560. movaps xmm12,XMMWORD PTR[112+rsp]
  561. movaps xmm13,XMMWORD PTR[128+rsp]
  562. movaps xmm14,XMMWORD PTR[144+rsp]
  563. movaps xmm15,XMMWORD PTR[160+rsp]
  564. lea rsp,QWORD PTR[184+rsp]
  565. $L$dec_epilogue::
  566. mov rdi,QWORD PTR[8+rsp] ;WIN64 epilogue
  567. mov rsi,QWORD PTR[16+rsp]
  568. DB 0F3h,0C3h ;repret
  569. $L$SEH_end_vpaes_decrypt::
  570. vpaes_decrypt ENDP
  571. PUBLIC vpaes_cbc_encrypt
  572. ALIGN 16
  573. vpaes_cbc_encrypt PROC PUBLIC
  574. mov QWORD PTR[8+rsp],rdi ;WIN64 prologue
  575. mov QWORD PTR[16+rsp],rsi
  576. mov rax,rsp
  577. $L$SEH_begin_vpaes_cbc_encrypt::
  578. mov rdi,rcx
  579. mov rsi,rdx
  580. mov rdx,r8
  581. mov rcx,r9
  582. mov r8,QWORD PTR[40+rsp]
  583. mov r9,QWORD PTR[48+rsp]
  584. xchg rdx,rcx
  585. sub rcx,16
  586. jc $L$cbc_abort
  587. lea rsp,QWORD PTR[((-184))+rsp]
  588. movaps XMMWORD PTR[16+rsp],xmm6
  589. movaps XMMWORD PTR[32+rsp],xmm7
  590. movaps XMMWORD PTR[48+rsp],xmm8
  591. movaps XMMWORD PTR[64+rsp],xmm9
  592. movaps XMMWORD PTR[80+rsp],xmm10
  593. movaps XMMWORD PTR[96+rsp],xmm11
  594. movaps XMMWORD PTR[112+rsp],xmm12
  595. movaps XMMWORD PTR[128+rsp],xmm13
  596. movaps XMMWORD PTR[144+rsp],xmm14
  597. movaps XMMWORD PTR[160+rsp],xmm15
  598. $L$cbc_body::
  599. movdqu xmm6,XMMWORD PTR[r8]
  600. sub rsi,rdi
  601. call _vpaes_preheat
  602. cmp r9d,0
  603. je $L$cbc_dec_loop
  604. jmp $L$cbc_enc_loop
  605. ALIGN 16
  606. $L$cbc_enc_loop::
  607. movdqu xmm0,XMMWORD PTR[rdi]
  608. pxor xmm0,xmm6
  609. call _vpaes_encrypt_core
  610. movdqa xmm6,xmm0
  611. movdqu XMMWORD PTR[rdi*1+rsi],xmm0
  612. lea rdi,QWORD PTR[16+rdi]
  613. sub rcx,16
  614. jnc $L$cbc_enc_loop
  615. jmp $L$cbc_done
  616. ALIGN 16
  617. $L$cbc_dec_loop::
  618. movdqu xmm0,XMMWORD PTR[rdi]
  619. movdqa xmm7,xmm0
  620. call _vpaes_decrypt_core
  621. pxor xmm0,xmm6
  622. movdqa xmm6,xmm7
  623. movdqu XMMWORD PTR[rdi*1+rsi],xmm0
  624. lea rdi,QWORD PTR[16+rdi]
  625. sub rcx,16
  626. jnc $L$cbc_dec_loop
  627. $L$cbc_done::
  628. movdqu XMMWORD PTR[r8],xmm6
  629. movaps xmm6,XMMWORD PTR[16+rsp]
  630. movaps xmm7,XMMWORD PTR[32+rsp]
  631. movaps xmm8,XMMWORD PTR[48+rsp]
  632. movaps xmm9,XMMWORD PTR[64+rsp]
  633. movaps xmm10,XMMWORD PTR[80+rsp]
  634. movaps xmm11,XMMWORD PTR[96+rsp]
  635. movaps xmm12,XMMWORD PTR[112+rsp]
  636. movaps xmm13,XMMWORD PTR[128+rsp]
  637. movaps xmm14,XMMWORD PTR[144+rsp]
  638. movaps xmm15,XMMWORD PTR[160+rsp]
  639. lea rsp,QWORD PTR[184+rsp]
  640. $L$cbc_epilogue::
  641. $L$cbc_abort::
  642. mov rdi,QWORD PTR[8+rsp] ;WIN64 epilogue
  643. mov rsi,QWORD PTR[16+rsp]
  644. DB 0F3h,0C3h ;repret
  645. $L$SEH_end_vpaes_cbc_encrypt::
  646. vpaes_cbc_encrypt ENDP
  647. ALIGN 16
  648. _vpaes_preheat PROC PRIVATE
  649. lea r10,QWORD PTR[$L$k_s0F]
  650. movdqa xmm10,XMMWORD PTR[((-32))+r10]
  651. movdqa xmm11,XMMWORD PTR[((-16))+r10]
  652. movdqa xmm9,XMMWORD PTR[r10]
  653. movdqa xmm13,XMMWORD PTR[48+r10]
  654. movdqa xmm12,XMMWORD PTR[64+r10]
  655. movdqa xmm15,XMMWORD PTR[80+r10]
  656. movdqa xmm14,XMMWORD PTR[96+r10]
  657. DB 0F3h,0C3h ;repret
  658. _vpaes_preheat ENDP
  659. ALIGN 64
  660. _vpaes_consts::
  661. $L$k_inv::
  662. DQ 00E05060F0D080180h,0040703090A0B0C02h
  663. DQ 001040A060F0B0780h,0030D0E0C02050809h
  664. $L$k_s0F::
  665. DQ 00F0F0F0F0F0F0F0Fh,00F0F0F0F0F0F0F0Fh
  666. $L$k_ipt::
  667. DQ 0C2B2E8985A2A7000h,0CABAE09052227808h
  668. DQ 04C01307D317C4D00h,0CD80B1FCB0FDCC81h
  669. $L$k_sb1::
  670. DQ 0B19BE18FCB503E00h,0A5DF7A6E142AF544h
  671. DQ 03618D415FAE22300h,03BF7CCC10D2ED9EFh
  672. $L$k_sb2::
  673. DQ 0E27A93C60B712400h,05EB7E955BC982FCDh
  674. DQ 069EB88400AE12900h,0C2A163C8AB82234Ah
  675. $L$k_sbo::
  676. DQ 0D0D26D176FBDC700h,015AABF7AC502A878h
  677. DQ 0CFE474A55FBB6A00h,08E1E90D1412B35FAh
  678. $L$k_mc_forward::
  679. DQ 00407060500030201h,00C0F0E0D080B0A09h
  680. DQ 0080B0A0904070605h,0000302010C0F0E0Dh
  681. DQ 00C0F0E0D080B0A09h,00407060500030201h
  682. DQ 0000302010C0F0E0Dh,0080B0A0904070605h
  683. $L$k_mc_backward::
  684. DQ 00605040702010003h,00E0D0C0F0A09080Bh
  685. DQ 0020100030E0D0C0Fh,00A09080B06050407h
  686. DQ 00E0D0C0F0A09080Bh,00605040702010003h
  687. DQ 00A09080B06050407h,0020100030E0D0C0Fh
  688. $L$k_sr::
  689. DQ 00706050403020100h,00F0E0D0C0B0A0908h
  690. DQ 0030E09040F0A0500h,00B06010C07020D08h
  691. DQ 00F060D040B020900h,0070E050C030A0108h
  692. DQ 00B0E0104070A0D00h,00306090C0F020508h
  693. $L$k_rcon::
  694. DQ 01F8391B9AF9DEEB6h,0702A98084D7C7D81h
  695. $L$k_s63::
  696. DQ 05B5B5B5B5B5B5B5Bh,05B5B5B5B5B5B5B5Bh
  697. $L$k_opt::
  698. DQ 0FF9F4929D6B66000h,0F7974121DEBE6808h
  699. DQ 001EDBD5150BCEC00h,0E10D5DB1B05C0CE0h
  700. $L$k_deskew::
  701. DQ 007E4A34047A4E300h,01DFEB95A5DBEF91Ah
  702. DQ 05F36B5DC83EA6900h,02841C2ABF49D1E77h
  703. $L$k_dksd::
  704. DQ 0FEB91A5DA3E44700h,00740E3A45A1DBEF9h
  705. DQ 041C277F4B5368300h,05FDC69EAAB289D1Eh
  706. $L$k_dksb::
  707. DQ 09A4FCA1F8550D500h,003D653861CC94C99h
  708. DQ 0115BEDA7B6FC4A00h,0D993256F7E3482C8h
  709. $L$k_dkse::
  710. DQ 0D5031CCA1FC9D600h,053859A4C994F5086h
  711. DQ 0A23196054FDC7BE8h,0CD5EF96A20B31487h
  712. $L$k_dks9::
  713. DQ 0B6116FC87ED9A700h,04AED933482255BFCh
  714. DQ 04576516227143300h,08BB89FACE9DAFDCEh
  715. $L$k_dipt::
  716. DQ 00F505B040B545F00h,0154A411E114E451Ah
  717. DQ 086E383E660056500h,012771772F491F194h
  718. $L$k_dsb9::
  719. DQ 0851C03539A86D600h,0CAD51F504F994CC9h
  720. DQ 0C03B1789ECD74900h,0725E2C9EB2FBA565h
  721. $L$k_dsbd::
  722. DQ 07D57CCDFE6B1A200h,0F56E9B13882A4439h
  723. DQ 03CE2FAF724C6CB00h,02931180D15DEEFD3h
  724. $L$k_dsbb::
  725. DQ 0D022649296B44200h,0602646F6B0F2D404h
  726. DQ 0C19498A6CD596700h,0F3FF0C3E3255AA6Bh
  727. $L$k_dsbe::
  728. DQ 046F2929626D4D000h,02242600464B4F6B0h
  729. DQ 00C55A6CDFFAAC100h,09467F36B98593E32h
  730. $L$k_dsbo::
  731. DQ 01387EA537EF94000h,0C7AA6DB9D4943E2Dh
  732. DQ 012D7560F93441D00h,0CA4B8159D8C58E9Ch
  733. DB 86,101,99,116,111,114,32,80,101,114,109,117,116,97,116,105
  734. DB 111,110,32,65,69,83,32,102,111,114,32,120,56,54,95,54
  735. DB 52,47,83,83,83,69,51,44,32,77,105,107,101,32,72,97
  736. DB 109,98,117,114,103,32,40,83,116,97,110,102,111,114,100,32
  737. DB 85,110,105,118,101,114,115,105,116,121,41,0
  738. ALIGN 64
  739. EXTERN __imp_RtlVirtualUnwind:NEAR
  740. ALIGN 16
  741. se_handler PROC PRIVATE
  742. push rsi
  743. push rdi
  744. push rbx
  745. push rbp
  746. push r12
  747. push r13
  748. push r14
  749. push r15
  750. pushfq
  751. sub rsp,64
  752. mov rax,QWORD PTR[120+r8]
  753. mov rbx,QWORD PTR[248+r8]
  754. mov rsi,QWORD PTR[8+r9]
  755. mov r11,QWORD PTR[56+r9]
  756. mov r10d,DWORD PTR[r11]
  757. lea r10,QWORD PTR[r10*1+rsi]
  758. cmp rbx,r10
  759. jb $L$in_prologue
  760. mov rax,QWORD PTR[152+r8]
  761. mov r10d,DWORD PTR[4+r11]
  762. lea r10,QWORD PTR[r10*1+rsi]
  763. cmp rbx,r10
  764. jae $L$in_prologue
  765. lea rsi,QWORD PTR[16+rax]
  766. lea rdi,QWORD PTR[512+r8]
  767. mov ecx,20
  768. DD 0a548f3fch
  769. lea rax,QWORD PTR[184+rax]
  770. $L$in_prologue::
  771. mov rdi,QWORD PTR[8+rax]
  772. mov rsi,QWORD PTR[16+rax]
  773. mov QWORD PTR[152+r8],rax
  774. mov QWORD PTR[168+r8],rsi
  775. mov QWORD PTR[176+r8],rdi
  776. mov rdi,QWORD PTR[40+r9]
  777. mov rsi,r8
  778. mov ecx,154
  779. DD 0a548f3fch
  780. mov rsi,r9
  781. xor rcx,rcx
  782. mov rdx,QWORD PTR[8+rsi]
  783. mov r8,QWORD PTR[rsi]
  784. mov r9,QWORD PTR[16+rsi]
  785. mov r10,QWORD PTR[40+rsi]
  786. lea r11,QWORD PTR[56+rsi]
  787. lea r12,QWORD PTR[24+rsi]
  788. mov QWORD PTR[32+rsp],r10
  789. mov QWORD PTR[40+rsp],r11
  790. mov QWORD PTR[48+rsp],r12
  791. mov QWORD PTR[56+rsp],rcx
  792. call QWORD PTR[__imp_RtlVirtualUnwind]
  793. mov eax,1
  794. add rsp,64
  795. popfq
  796. pop r15
  797. pop r14
  798. pop r13
  799. pop r12
  800. pop rbp
  801. pop rbx
  802. pop rdi
  803. pop rsi
  804. DB 0F3h,0C3h ;repret
  805. se_handler ENDP
  806. .text$ ENDS
  807. .pdata SEGMENT READONLY ALIGN(4)
  808. ALIGN 4
  809. DD imagerel $L$SEH_begin_vpaes_set_encrypt_key
  810. DD imagerel $L$SEH_end_vpaes_set_encrypt_key
  811. DD imagerel $L$SEH_info_vpaes_set_encrypt_key
  812. DD imagerel $L$SEH_begin_vpaes_set_decrypt_key
  813. DD imagerel $L$SEH_end_vpaes_set_decrypt_key
  814. DD imagerel $L$SEH_info_vpaes_set_decrypt_key
  815. DD imagerel $L$SEH_begin_vpaes_encrypt
  816. DD imagerel $L$SEH_end_vpaes_encrypt
  817. DD imagerel $L$SEH_info_vpaes_encrypt
  818. DD imagerel $L$SEH_begin_vpaes_decrypt
  819. DD imagerel $L$SEH_end_vpaes_decrypt
  820. DD imagerel $L$SEH_info_vpaes_decrypt
  821. DD imagerel $L$SEH_begin_vpaes_cbc_encrypt
  822. DD imagerel $L$SEH_end_vpaes_cbc_encrypt
  823. DD imagerel $L$SEH_info_vpaes_cbc_encrypt
  824. .pdata ENDS
  825. .xdata SEGMENT READONLY ALIGN(8)
  826. ALIGN 8
  827. $L$SEH_info_vpaes_set_encrypt_key::
  828. DB 9,0,0,0
  829. DD imagerel se_handler
  830. DD imagerel $L$enc_key_body,imagerel $L$enc_key_epilogue
  831. $L$SEH_info_vpaes_set_decrypt_key::
  832. DB 9,0,0,0
  833. DD imagerel se_handler
  834. DD imagerel $L$dec_key_body,imagerel $L$dec_key_epilogue
  835. $L$SEH_info_vpaes_encrypt::
  836. DB 9,0,0,0
  837. DD imagerel se_handler
  838. DD imagerel $L$enc_body,imagerel $L$enc_epilogue
  839. $L$SEH_info_vpaes_decrypt::
  840. DB 9,0,0,0
  841. DD imagerel se_handler
  842. DD imagerel $L$dec_body,imagerel $L$dec_epilogue
  843. $L$SEH_info_vpaes_cbc_encrypt::
  844. DB 9,0,0,0
  845. DD imagerel se_handler
  846. DD imagerel $L$cbc_body,imagerel $L$cbc_epilogue
  847. .xdata ENDS
  848. END