e_padlock-x86_64.masm 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191
  1. OPTION DOTNAME
  2. .text$ SEGMENT ALIGN(256) 'CODE'
  3. PUBLIC padlock_capability
  4. ALIGN 16
  5. padlock_capability PROC PUBLIC
  6. mov r8,rbx
  7. xor eax,eax
  8. cpuid
  9. xor eax,eax
  10. cmp ebx,0746e6543h
  11. jne $L$zhaoxin
  12. cmp edx,048727561h
  13. jne $L$noluck
  14. cmp ecx,0736c7561h
  15. jne $L$noluck
  16. jmp $L$zhaoxinEnd
  17. $L$zhaoxin::
  18. cmp ebx,068532020h
  19. jne $L$noluck
  20. cmp edx,068676e61h
  21. jne $L$noluck
  22. cmp ecx,020206961h
  23. jne $L$noluck
  24. $L$zhaoxinEnd::
  25. mov eax,0C0000000h
  26. cpuid
  27. mov edx,eax
  28. xor eax,eax
  29. cmp edx,0C0000001h
  30. jb $L$noluck
  31. mov eax,0C0000001h
  32. cpuid
  33. mov eax,edx
  34. and eax,0ffffffefh
  35. or eax,010h
  36. $L$noluck::
  37. mov rbx,r8
  38. DB 0F3h,0C3h ;repret
  39. padlock_capability ENDP
  40. PUBLIC padlock_key_bswap
  41. ALIGN 16
  42. padlock_key_bswap PROC PUBLIC
  43. mov edx,DWORD PTR[240+rcx]
  44. $L$bswap_loop::
  45. mov eax,DWORD PTR[rcx]
  46. bswap eax
  47. mov DWORD PTR[rcx],eax
  48. lea rcx,QWORD PTR[4+rcx]
  49. sub edx,1
  50. jnz $L$bswap_loop
  51. DB 0F3h,0C3h ;repret
  52. padlock_key_bswap ENDP
  53. PUBLIC padlock_verify_context
  54. ALIGN 16
  55. padlock_verify_context PROC PUBLIC
  56. mov rdx,rcx
  57. pushf
  58. lea rax,QWORD PTR[$L$padlock_saved_context]
  59. call _padlock_verify_ctx
  60. lea rsp,QWORD PTR[8+rsp]
  61. DB 0F3h,0C3h ;repret
  62. padlock_verify_context ENDP
  63. ALIGN 16
  64. _padlock_verify_ctx PROC PRIVATE
  65. mov r8,QWORD PTR[8+rsp]
  66. bt r8,30
  67. jnc $L$verified
  68. cmp rdx,QWORD PTR[rax]
  69. je $L$verified
  70. pushf
  71. popf
  72. $L$verified::
  73. mov QWORD PTR[rax],rdx
  74. DB 0F3h,0C3h ;repret
  75. _padlock_verify_ctx ENDP
  76. PUBLIC padlock_reload_key
  77. ALIGN 16
  78. padlock_reload_key PROC PUBLIC
  79. pushf
  80. popf
  81. DB 0F3h,0C3h ;repret
  82. padlock_reload_key ENDP
  83. PUBLIC padlock_aes_block
  84. ALIGN 16
  85. padlock_aes_block PROC PUBLIC
  86. mov QWORD PTR[8+rsp],rdi ;WIN64 prologue
  87. mov QWORD PTR[16+rsp],rsi
  88. mov rax,rsp
  89. $L$SEH_begin_padlock_aes_block::
  90. mov rdi,rcx
  91. mov rsi,rdx
  92. mov rdx,r8
  93. mov r8,rbx
  94. mov rcx,1
  95. lea rbx,QWORD PTR[32+rdx]
  96. lea rdx,QWORD PTR[16+rdx]
  97. DB 0f3h,00fh,0a7h,0c8h
  98. mov rbx,r8
  99. mov rdi,QWORD PTR[8+rsp] ;WIN64 epilogue
  100. mov rsi,QWORD PTR[16+rsp]
  101. DB 0F3h,0C3h ;repret
  102. $L$SEH_end_padlock_aes_block::
  103. padlock_aes_block ENDP
  104. PUBLIC padlock_xstore
  105. ALIGN 16
  106. padlock_xstore PROC PUBLIC
  107. mov QWORD PTR[8+rsp],rdi ;WIN64 prologue
  108. mov QWORD PTR[16+rsp],rsi
  109. mov rax,rsp
  110. $L$SEH_begin_padlock_xstore::
  111. mov rdi,rcx
  112. mov rsi,rdx
  113. mov edx,esi
  114. DB 00fh,0a7h,0c0h
  115. mov rdi,QWORD PTR[8+rsp] ;WIN64 epilogue
  116. mov rsi,QWORD PTR[16+rsp]
  117. DB 0F3h,0C3h ;repret
  118. $L$SEH_end_padlock_xstore::
  119. padlock_xstore ENDP
  120. PUBLIC padlock_sha1_oneshot
  121. ALIGN 16
  122. padlock_sha1_oneshot PROC PUBLIC
  123. mov QWORD PTR[8+rsp],rdi ;WIN64 prologue
  124. mov QWORD PTR[16+rsp],rsi
  125. mov rax,rsp
  126. $L$SEH_begin_padlock_sha1_oneshot::
  127. mov rdi,rcx
  128. mov rsi,rdx
  129. mov rdx,r8
  130. mov rcx,rdx
  131. mov rdx,rdi
  132. movups xmm0,XMMWORD PTR[rdi]
  133. sub rsp,128+8
  134. mov eax,DWORD PTR[16+rdi]
  135. movaps XMMWORD PTR[rsp],xmm0
  136. mov rdi,rsp
  137. mov DWORD PTR[16+rsp],eax
  138. xor rax,rax
  139. DB 0f3h,00fh,0a6h,0c8h
  140. movaps xmm0,XMMWORD PTR[rsp]
  141. mov eax,DWORD PTR[16+rsp]
  142. add rsp,128+8
  143. movups XMMWORD PTR[rdx],xmm0
  144. mov DWORD PTR[16+rdx],eax
  145. mov rdi,QWORD PTR[8+rsp] ;WIN64 epilogue
  146. mov rsi,QWORD PTR[16+rsp]
  147. DB 0F3h,0C3h ;repret
  148. $L$SEH_end_padlock_sha1_oneshot::
  149. padlock_sha1_oneshot ENDP
  150. PUBLIC padlock_sha1_blocks
  151. ALIGN 16
  152. padlock_sha1_blocks PROC PUBLIC
  153. mov QWORD PTR[8+rsp],rdi ;WIN64 prologue
  154. mov QWORD PTR[16+rsp],rsi
  155. mov rax,rsp
  156. $L$SEH_begin_padlock_sha1_blocks::
  157. mov rdi,rcx
  158. mov rsi,rdx
  159. mov rdx,r8
  160. mov rcx,rdx
  161. mov rdx,rdi
  162. movups xmm0,XMMWORD PTR[rdi]
  163. sub rsp,128+8
  164. mov eax,DWORD PTR[16+rdi]
  165. movaps XMMWORD PTR[rsp],xmm0
  166. mov rdi,rsp
  167. mov DWORD PTR[16+rsp],eax
  168. mov rax,-1
  169. DB 0f3h,00fh,0a6h,0c8h
  170. movaps xmm0,XMMWORD PTR[rsp]
  171. mov eax,DWORD PTR[16+rsp]
  172. add rsp,128+8
  173. movups XMMWORD PTR[rdx],xmm0
  174. mov DWORD PTR[16+rdx],eax
  175. mov rdi,QWORD PTR[8+rsp] ;WIN64 epilogue
  176. mov rsi,QWORD PTR[16+rsp]
  177. DB 0F3h,0C3h ;repret
  178. $L$SEH_end_padlock_sha1_blocks::
  179. padlock_sha1_blocks ENDP
  180. PUBLIC padlock_sha256_oneshot
  181. ALIGN 16
  182. padlock_sha256_oneshot PROC PUBLIC
  183. mov QWORD PTR[8+rsp],rdi ;WIN64 prologue
  184. mov QWORD PTR[16+rsp],rsi
  185. mov rax,rsp
  186. $L$SEH_begin_padlock_sha256_oneshot::
  187. mov rdi,rcx
  188. mov rsi,rdx
  189. mov rdx,r8
  190. mov rcx,rdx
  191. mov rdx,rdi
  192. movups xmm0,XMMWORD PTR[rdi]
  193. sub rsp,128+8
  194. movups xmm1,XMMWORD PTR[16+rdi]
  195. movaps XMMWORD PTR[rsp],xmm0
  196. mov rdi,rsp
  197. movaps XMMWORD PTR[16+rsp],xmm1
  198. xor rax,rax
  199. DB 0f3h,00fh,0a6h,0d0h
  200. movaps xmm0,XMMWORD PTR[rsp]
  201. movaps xmm1,XMMWORD PTR[16+rsp]
  202. add rsp,128+8
  203. movups XMMWORD PTR[rdx],xmm0
  204. movups XMMWORD PTR[16+rdx],xmm1
  205. mov rdi,QWORD PTR[8+rsp] ;WIN64 epilogue
  206. mov rsi,QWORD PTR[16+rsp]
  207. DB 0F3h,0C3h ;repret
  208. $L$SEH_end_padlock_sha256_oneshot::
  209. padlock_sha256_oneshot ENDP
  210. PUBLIC padlock_sha256_blocks
  211. ALIGN 16
  212. padlock_sha256_blocks PROC PUBLIC
  213. mov QWORD PTR[8+rsp],rdi ;WIN64 prologue
  214. mov QWORD PTR[16+rsp],rsi
  215. mov rax,rsp
  216. $L$SEH_begin_padlock_sha256_blocks::
  217. mov rdi,rcx
  218. mov rsi,rdx
  219. mov rdx,r8
  220. mov rcx,rdx
  221. mov rdx,rdi
  222. movups xmm0,XMMWORD PTR[rdi]
  223. sub rsp,128+8
  224. movups xmm1,XMMWORD PTR[16+rdi]
  225. movaps XMMWORD PTR[rsp],xmm0
  226. mov rdi,rsp
  227. movaps XMMWORD PTR[16+rsp],xmm1
  228. mov rax,-1
  229. DB 0f3h,00fh,0a6h,0d0h
  230. movaps xmm0,XMMWORD PTR[rsp]
  231. movaps xmm1,XMMWORD PTR[16+rsp]
  232. add rsp,128+8
  233. movups XMMWORD PTR[rdx],xmm0
  234. movups XMMWORD PTR[16+rdx],xmm1
  235. mov rdi,QWORD PTR[8+rsp] ;WIN64 epilogue
  236. mov rsi,QWORD PTR[16+rsp]
  237. DB 0F3h,0C3h ;repret
  238. $L$SEH_end_padlock_sha256_blocks::
  239. padlock_sha256_blocks ENDP
  240. PUBLIC padlock_sha512_blocks
  241. ALIGN 16
  242. padlock_sha512_blocks PROC PUBLIC
  243. mov QWORD PTR[8+rsp],rdi ;WIN64 prologue
  244. mov QWORD PTR[16+rsp],rsi
  245. mov rax,rsp
  246. $L$SEH_begin_padlock_sha512_blocks::
  247. mov rdi,rcx
  248. mov rsi,rdx
  249. mov rdx,r8
  250. mov rcx,rdx
  251. mov rdx,rdi
  252. movups xmm0,XMMWORD PTR[rdi]
  253. sub rsp,128+8
  254. movups xmm1,XMMWORD PTR[16+rdi]
  255. movups xmm2,XMMWORD PTR[32+rdi]
  256. movups xmm3,XMMWORD PTR[48+rdi]
  257. movaps XMMWORD PTR[rsp],xmm0
  258. mov rdi,rsp
  259. movaps XMMWORD PTR[16+rsp],xmm1
  260. movaps XMMWORD PTR[32+rsp],xmm2
  261. movaps XMMWORD PTR[48+rsp],xmm3
  262. DB 0f3h,00fh,0a6h,0e0h
  263. movaps xmm0,XMMWORD PTR[rsp]
  264. movaps xmm1,XMMWORD PTR[16+rsp]
  265. movaps xmm2,XMMWORD PTR[32+rsp]
  266. movaps xmm3,XMMWORD PTR[48+rsp]
  267. add rsp,128+8
  268. movups XMMWORD PTR[rdx],xmm0
  269. movups XMMWORD PTR[16+rdx],xmm1
  270. movups XMMWORD PTR[32+rdx],xmm2
  271. movups XMMWORD PTR[48+rdx],xmm3
  272. mov rdi,QWORD PTR[8+rsp] ;WIN64 epilogue
  273. mov rsi,QWORD PTR[16+rsp]
  274. DB 0F3h,0C3h ;repret
  275. $L$SEH_end_padlock_sha512_blocks::
  276. padlock_sha512_blocks ENDP
  277. PUBLIC padlock_ecb_encrypt
  278. ALIGN 16
  279. padlock_ecb_encrypt PROC PUBLIC
  280. mov QWORD PTR[8+rsp],rdi ;WIN64 prologue
  281. mov QWORD PTR[16+rsp],rsi
  282. mov rax,rsp
  283. $L$SEH_begin_padlock_ecb_encrypt::
  284. mov rdi,rcx
  285. mov rsi,rdx
  286. mov rdx,r8
  287. mov rcx,r9
  288. push rbp
  289. push rbx
  290. xor eax,eax
  291. test rdx,15
  292. jnz $L$ecb_abort
  293. test rcx,15
  294. jnz $L$ecb_abort
  295. lea rax,QWORD PTR[$L$padlock_saved_context]
  296. pushf
  297. cld
  298. call _padlock_verify_ctx
  299. lea rdx,QWORD PTR[16+rdx]
  300. xor eax,eax
  301. xor ebx,ebx
  302. test DWORD PTR[rdx],32
  303. jnz $L$ecb_aligned
  304. test rdi,00fh
  305. setz al
  306. test rsi,00fh
  307. setz bl
  308. test eax,ebx
  309. jnz $L$ecb_aligned
  310. neg rax
  311. mov rbx,512
  312. not rax
  313. lea rbp,QWORD PTR[rsp]
  314. cmp rcx,rbx
  315. cmovc rbx,rcx
  316. and rax,rbx
  317. mov rbx,rcx
  318. neg rax
  319. and rbx,512-1
  320. lea rsp,QWORD PTR[rbp*1+rax]
  321. mov rax,512
  322. cmovz rbx,rax
  323. cmp rcx,rbx
  324. ja $L$ecb_loop
  325. mov rax,rsi
  326. cmp rbp,rsp
  327. cmove rax,rdi
  328. add rax,rcx
  329. neg rax
  330. and rax,0fffh
  331. cmp rax,128
  332. mov rax,-128
  333. cmovae rax,rbx
  334. and rbx,rax
  335. jz $L$ecb_unaligned_tail
  336. jmp $L$ecb_loop
  337. ALIGN 16
  338. $L$ecb_loop::
  339. cmp rbx,rcx
  340. cmova rbx,rcx
  341. mov r8,rdi
  342. mov r9,rsi
  343. mov r10,rcx
  344. mov rcx,rbx
  345. mov r11,rbx
  346. test rdi,00fh
  347. cmovnz rdi,rsp
  348. test rsi,00fh
  349. jz $L$ecb_inp_aligned
  350. shr rcx,3
  351. DB 0f3h,048h,0a5h
  352. sub rdi,rbx
  353. mov rcx,rbx
  354. mov rsi,rdi
  355. $L$ecb_inp_aligned::
  356. lea rax,QWORD PTR[((-16))+rdx]
  357. lea rbx,QWORD PTR[16+rdx]
  358. shr rcx,4
  359. DB 0f3h,00fh,0a7h,200
  360. mov rdi,r8
  361. mov rbx,r11
  362. test rdi,00fh
  363. jz $L$ecb_out_aligned
  364. mov rcx,rbx
  365. lea rsi,QWORD PTR[rsp]
  366. shr rcx,3
  367. DB 0f3h,048h,0a5h
  368. sub rdi,rbx
  369. $L$ecb_out_aligned::
  370. mov rsi,r9
  371. mov rcx,r10
  372. add rdi,rbx
  373. add rsi,rbx
  374. sub rcx,rbx
  375. mov rbx,512
  376. jz $L$ecb_break
  377. cmp rcx,rbx
  378. jae $L$ecb_loop
  379. $L$ecb_unaligned_tail::
  380. xor eax,eax
  381. cmp rbp,rsp
  382. cmove rax,rcx
  383. mov r8,rdi
  384. mov rbx,rcx
  385. sub rsp,rax
  386. shr rcx,3
  387. lea rdi,QWORD PTR[rsp]
  388. DB 0f3h,048h,0a5h
  389. mov rsi,rsp
  390. mov rdi,r8
  391. mov rcx,rbx
  392. jmp $L$ecb_loop
  393. ALIGN 16
  394. $L$ecb_break::
  395. cmp rsp,rbp
  396. je $L$ecb_done
  397. pxor xmm0,xmm0
  398. lea rax,QWORD PTR[rsp]
  399. $L$ecb_bzero::
  400. movaps XMMWORD PTR[rax],xmm0
  401. lea rax,QWORD PTR[16+rax]
  402. cmp rbp,rax
  403. ja $L$ecb_bzero
  404. $L$ecb_done::
  405. lea rsp,QWORD PTR[rbp]
  406. jmp $L$ecb_exit
  407. ALIGN 16
  408. $L$ecb_aligned::
  409. lea rbp,QWORD PTR[rcx*1+rsi]
  410. neg rbp
  411. and rbp,0fffh
  412. xor eax,eax
  413. cmp rbp,128
  414. mov rbp,128-1
  415. cmovae rbp,rax
  416. and rbp,rcx
  417. sub rcx,rbp
  418. jz $L$ecb_aligned_tail
  419. lea rax,QWORD PTR[((-16))+rdx]
  420. lea rbx,QWORD PTR[16+rdx]
  421. shr rcx,4
  422. DB 0f3h,00fh,0a7h,200
  423. test rbp,rbp
  424. jz $L$ecb_exit
  425. $L$ecb_aligned_tail::
  426. mov r8,rdi
  427. mov rbx,rbp
  428. mov rcx,rbp
  429. lea rbp,QWORD PTR[rsp]
  430. sub rsp,rcx
  431. shr rcx,3
  432. lea rdi,QWORD PTR[rsp]
  433. DB 0f3h,048h,0a5h
  434. lea rdi,QWORD PTR[r8]
  435. lea rsi,QWORD PTR[rsp]
  436. mov rcx,rbx
  437. jmp $L$ecb_loop
  438. $L$ecb_exit::
  439. mov eax,1
  440. lea rsp,QWORD PTR[8+rsp]
  441. $L$ecb_abort::
  442. pop rbx
  443. pop rbp
  444. mov rdi,QWORD PTR[8+rsp] ;WIN64 epilogue
  445. mov rsi,QWORD PTR[16+rsp]
  446. DB 0F3h,0C3h ;repret
  447. $L$SEH_end_padlock_ecb_encrypt::
  448. padlock_ecb_encrypt ENDP
  449. PUBLIC padlock_cbc_encrypt
  450. ALIGN 16
  451. padlock_cbc_encrypt PROC PUBLIC
  452. mov QWORD PTR[8+rsp],rdi ;WIN64 prologue
  453. mov QWORD PTR[16+rsp],rsi
  454. mov rax,rsp
  455. $L$SEH_begin_padlock_cbc_encrypt::
  456. mov rdi,rcx
  457. mov rsi,rdx
  458. mov rdx,r8
  459. mov rcx,r9
  460. push rbp
  461. push rbx
  462. xor eax,eax
  463. test rdx,15
  464. jnz $L$cbc_abort
  465. test rcx,15
  466. jnz $L$cbc_abort
  467. lea rax,QWORD PTR[$L$padlock_saved_context]
  468. pushf
  469. cld
  470. call _padlock_verify_ctx
  471. lea rdx,QWORD PTR[16+rdx]
  472. xor eax,eax
  473. xor ebx,ebx
  474. test DWORD PTR[rdx],32
  475. jnz $L$cbc_aligned
  476. test rdi,00fh
  477. setz al
  478. test rsi,00fh
  479. setz bl
  480. test eax,ebx
  481. jnz $L$cbc_aligned
  482. neg rax
  483. mov rbx,512
  484. not rax
  485. lea rbp,QWORD PTR[rsp]
  486. cmp rcx,rbx
  487. cmovc rbx,rcx
  488. and rax,rbx
  489. mov rbx,rcx
  490. neg rax
  491. and rbx,512-1
  492. lea rsp,QWORD PTR[rbp*1+rax]
  493. mov rax,512
  494. cmovz rbx,rax
  495. cmp rcx,rbx
  496. ja $L$cbc_loop
  497. mov rax,rsi
  498. cmp rbp,rsp
  499. cmove rax,rdi
  500. add rax,rcx
  501. neg rax
  502. and rax,0fffh
  503. cmp rax,64
  504. mov rax,-64
  505. cmovae rax,rbx
  506. and rbx,rax
  507. jz $L$cbc_unaligned_tail
  508. jmp $L$cbc_loop
  509. ALIGN 16
  510. $L$cbc_loop::
  511. cmp rbx,rcx
  512. cmova rbx,rcx
  513. mov r8,rdi
  514. mov r9,rsi
  515. mov r10,rcx
  516. mov rcx,rbx
  517. mov r11,rbx
  518. test rdi,00fh
  519. cmovnz rdi,rsp
  520. test rsi,00fh
  521. jz $L$cbc_inp_aligned
  522. shr rcx,3
  523. DB 0f3h,048h,0a5h
  524. sub rdi,rbx
  525. mov rcx,rbx
  526. mov rsi,rdi
  527. $L$cbc_inp_aligned::
  528. lea rax,QWORD PTR[((-16))+rdx]
  529. lea rbx,QWORD PTR[16+rdx]
  530. shr rcx,4
  531. DB 0f3h,00fh,0a7h,208
  532. movdqa xmm0,XMMWORD PTR[rax]
  533. movdqa XMMWORD PTR[(-16)+rdx],xmm0
  534. mov rdi,r8
  535. mov rbx,r11
  536. test rdi,00fh
  537. jz $L$cbc_out_aligned
  538. mov rcx,rbx
  539. lea rsi,QWORD PTR[rsp]
  540. shr rcx,3
  541. DB 0f3h,048h,0a5h
  542. sub rdi,rbx
  543. $L$cbc_out_aligned::
  544. mov rsi,r9
  545. mov rcx,r10
  546. add rdi,rbx
  547. add rsi,rbx
  548. sub rcx,rbx
  549. mov rbx,512
  550. jz $L$cbc_break
  551. cmp rcx,rbx
  552. jae $L$cbc_loop
  553. $L$cbc_unaligned_tail::
  554. xor eax,eax
  555. cmp rbp,rsp
  556. cmove rax,rcx
  557. mov r8,rdi
  558. mov rbx,rcx
  559. sub rsp,rax
  560. shr rcx,3
  561. lea rdi,QWORD PTR[rsp]
  562. DB 0f3h,048h,0a5h
  563. mov rsi,rsp
  564. mov rdi,r8
  565. mov rcx,rbx
  566. jmp $L$cbc_loop
  567. ALIGN 16
  568. $L$cbc_break::
  569. cmp rsp,rbp
  570. je $L$cbc_done
  571. pxor xmm0,xmm0
  572. lea rax,QWORD PTR[rsp]
  573. $L$cbc_bzero::
  574. movaps XMMWORD PTR[rax],xmm0
  575. lea rax,QWORD PTR[16+rax]
  576. cmp rbp,rax
  577. ja $L$cbc_bzero
  578. $L$cbc_done::
  579. lea rsp,QWORD PTR[rbp]
  580. jmp $L$cbc_exit
  581. ALIGN 16
  582. $L$cbc_aligned::
  583. lea rbp,QWORD PTR[rcx*1+rsi]
  584. neg rbp
  585. and rbp,0fffh
  586. xor eax,eax
  587. cmp rbp,64
  588. mov rbp,64-1
  589. cmovae rbp,rax
  590. and rbp,rcx
  591. sub rcx,rbp
  592. jz $L$cbc_aligned_tail
  593. lea rax,QWORD PTR[((-16))+rdx]
  594. lea rbx,QWORD PTR[16+rdx]
  595. shr rcx,4
  596. DB 0f3h,00fh,0a7h,208
  597. movdqa xmm0,XMMWORD PTR[rax]
  598. movdqa XMMWORD PTR[(-16)+rdx],xmm0
  599. test rbp,rbp
  600. jz $L$cbc_exit
  601. $L$cbc_aligned_tail::
  602. mov r8,rdi
  603. mov rbx,rbp
  604. mov rcx,rbp
  605. lea rbp,QWORD PTR[rsp]
  606. sub rsp,rcx
  607. shr rcx,3
  608. lea rdi,QWORD PTR[rsp]
  609. DB 0f3h,048h,0a5h
  610. lea rdi,QWORD PTR[r8]
  611. lea rsi,QWORD PTR[rsp]
  612. mov rcx,rbx
  613. jmp $L$cbc_loop
  614. $L$cbc_exit::
  615. mov eax,1
  616. lea rsp,QWORD PTR[8+rsp]
  617. $L$cbc_abort::
  618. pop rbx
  619. pop rbp
  620. mov rdi,QWORD PTR[8+rsp] ;WIN64 epilogue
  621. mov rsi,QWORD PTR[16+rsp]
  622. DB 0F3h,0C3h ;repret
  623. $L$SEH_end_padlock_cbc_encrypt::
  624. padlock_cbc_encrypt ENDP
  625. PUBLIC padlock_cfb_encrypt
  626. ALIGN 16
  627. padlock_cfb_encrypt PROC PUBLIC
  628. mov QWORD PTR[8+rsp],rdi ;WIN64 prologue
  629. mov QWORD PTR[16+rsp],rsi
  630. mov rax,rsp
  631. $L$SEH_begin_padlock_cfb_encrypt::
  632. mov rdi,rcx
  633. mov rsi,rdx
  634. mov rdx,r8
  635. mov rcx,r9
  636. push rbp
  637. push rbx
  638. xor eax,eax
  639. test rdx,15
  640. jnz $L$cfb_abort
  641. test rcx,15
  642. jnz $L$cfb_abort
  643. lea rax,QWORD PTR[$L$padlock_saved_context]
  644. pushf
  645. cld
  646. call _padlock_verify_ctx
  647. lea rdx,QWORD PTR[16+rdx]
  648. xor eax,eax
  649. xor ebx,ebx
  650. test DWORD PTR[rdx],32
  651. jnz $L$cfb_aligned
  652. test rdi,00fh
  653. setz al
  654. test rsi,00fh
  655. setz bl
  656. test eax,ebx
  657. jnz $L$cfb_aligned
  658. neg rax
  659. mov rbx,512
  660. not rax
  661. lea rbp,QWORD PTR[rsp]
  662. cmp rcx,rbx
  663. cmovc rbx,rcx
  664. and rax,rbx
  665. mov rbx,rcx
  666. neg rax
  667. and rbx,512-1
  668. lea rsp,QWORD PTR[rbp*1+rax]
  669. mov rax,512
  670. cmovz rbx,rax
  671. jmp $L$cfb_loop
  672. ALIGN 16
  673. $L$cfb_loop::
  674. cmp rbx,rcx
  675. cmova rbx,rcx
  676. mov r8,rdi
  677. mov r9,rsi
  678. mov r10,rcx
  679. mov rcx,rbx
  680. mov r11,rbx
  681. test rdi,00fh
  682. cmovnz rdi,rsp
  683. test rsi,00fh
  684. jz $L$cfb_inp_aligned
  685. shr rcx,3
  686. DB 0f3h,048h,0a5h
  687. sub rdi,rbx
  688. mov rcx,rbx
  689. mov rsi,rdi
  690. $L$cfb_inp_aligned::
  691. lea rax,QWORD PTR[((-16))+rdx]
  692. lea rbx,QWORD PTR[16+rdx]
  693. shr rcx,4
  694. DB 0f3h,00fh,0a7h,224
  695. movdqa xmm0,XMMWORD PTR[rax]
  696. movdqa XMMWORD PTR[(-16)+rdx],xmm0
  697. mov rdi,r8
  698. mov rbx,r11
  699. test rdi,00fh
  700. jz $L$cfb_out_aligned
  701. mov rcx,rbx
  702. lea rsi,QWORD PTR[rsp]
  703. shr rcx,3
  704. DB 0f3h,048h,0a5h
  705. sub rdi,rbx
  706. $L$cfb_out_aligned::
  707. mov rsi,r9
  708. mov rcx,r10
  709. add rdi,rbx
  710. add rsi,rbx
  711. sub rcx,rbx
  712. mov rbx,512
  713. jnz $L$cfb_loop
  714. cmp rsp,rbp
  715. je $L$cfb_done
  716. pxor xmm0,xmm0
  717. lea rax,QWORD PTR[rsp]
  718. $L$cfb_bzero::
  719. movaps XMMWORD PTR[rax],xmm0
  720. lea rax,QWORD PTR[16+rax]
  721. cmp rbp,rax
  722. ja $L$cfb_bzero
  723. $L$cfb_done::
  724. lea rsp,QWORD PTR[rbp]
  725. jmp $L$cfb_exit
  726. ALIGN 16
  727. $L$cfb_aligned::
  728. lea rax,QWORD PTR[((-16))+rdx]
  729. lea rbx,QWORD PTR[16+rdx]
  730. shr rcx,4
  731. DB 0f3h,00fh,0a7h,224
  732. movdqa xmm0,XMMWORD PTR[rax]
  733. movdqa XMMWORD PTR[(-16)+rdx],xmm0
  734. $L$cfb_exit::
  735. mov eax,1
  736. lea rsp,QWORD PTR[8+rsp]
  737. $L$cfb_abort::
  738. pop rbx
  739. pop rbp
  740. mov rdi,QWORD PTR[8+rsp] ;WIN64 epilogue
  741. mov rsi,QWORD PTR[16+rsp]
  742. DB 0F3h,0C3h ;repret
  743. $L$SEH_end_padlock_cfb_encrypt::
  744. padlock_cfb_encrypt ENDP
  745. PUBLIC padlock_ofb_encrypt
  746. ALIGN 16
  747. padlock_ofb_encrypt PROC PUBLIC
  748. mov QWORD PTR[8+rsp],rdi ;WIN64 prologue
  749. mov QWORD PTR[16+rsp],rsi
  750. mov rax,rsp
  751. $L$SEH_begin_padlock_ofb_encrypt::
  752. mov rdi,rcx
  753. mov rsi,rdx
  754. mov rdx,r8
  755. mov rcx,r9
  756. push rbp
  757. push rbx
  758. xor eax,eax
  759. test rdx,15
  760. jnz $L$ofb_abort
  761. test rcx,15
  762. jnz $L$ofb_abort
  763. lea rax,QWORD PTR[$L$padlock_saved_context]
  764. pushf
  765. cld
  766. call _padlock_verify_ctx
  767. lea rdx,QWORD PTR[16+rdx]
  768. xor eax,eax
  769. xor ebx,ebx
  770. test DWORD PTR[rdx],32
  771. jnz $L$ofb_aligned
  772. test rdi,00fh
  773. setz al
  774. test rsi,00fh
  775. setz bl
  776. test eax,ebx
  777. jnz $L$ofb_aligned
  778. neg rax
  779. mov rbx,512
  780. not rax
  781. lea rbp,QWORD PTR[rsp]
  782. cmp rcx,rbx
  783. cmovc rbx,rcx
  784. and rax,rbx
  785. mov rbx,rcx
  786. neg rax
  787. and rbx,512-1
  788. lea rsp,QWORD PTR[rbp*1+rax]
  789. mov rax,512
  790. cmovz rbx,rax
  791. jmp $L$ofb_loop
  792. ALIGN 16
  793. $L$ofb_loop::
  794. cmp rbx,rcx
  795. cmova rbx,rcx
  796. mov r8,rdi
  797. mov r9,rsi
  798. mov r10,rcx
  799. mov rcx,rbx
  800. mov r11,rbx
  801. test rdi,00fh
  802. cmovnz rdi,rsp
  803. test rsi,00fh
  804. jz $L$ofb_inp_aligned
  805. shr rcx,3
  806. DB 0f3h,048h,0a5h
  807. sub rdi,rbx
  808. mov rcx,rbx
  809. mov rsi,rdi
  810. $L$ofb_inp_aligned::
  811. lea rax,QWORD PTR[((-16))+rdx]
  812. lea rbx,QWORD PTR[16+rdx]
  813. shr rcx,4
  814. DB 0f3h,00fh,0a7h,232
  815. movdqa xmm0,XMMWORD PTR[rax]
  816. movdqa XMMWORD PTR[(-16)+rdx],xmm0
  817. mov rdi,r8
  818. mov rbx,r11
  819. test rdi,00fh
  820. jz $L$ofb_out_aligned
  821. mov rcx,rbx
  822. lea rsi,QWORD PTR[rsp]
  823. shr rcx,3
  824. DB 0f3h,048h,0a5h
  825. sub rdi,rbx
  826. $L$ofb_out_aligned::
  827. mov rsi,r9
  828. mov rcx,r10
  829. add rdi,rbx
  830. add rsi,rbx
  831. sub rcx,rbx
  832. mov rbx,512
  833. jnz $L$ofb_loop
  834. cmp rsp,rbp
  835. je $L$ofb_done
  836. pxor xmm0,xmm0
  837. lea rax,QWORD PTR[rsp]
  838. $L$ofb_bzero::
  839. movaps XMMWORD PTR[rax],xmm0
  840. lea rax,QWORD PTR[16+rax]
  841. cmp rbp,rax
  842. ja $L$ofb_bzero
  843. $L$ofb_done::
  844. lea rsp,QWORD PTR[rbp]
  845. jmp $L$ofb_exit
  846. ALIGN 16
  847. $L$ofb_aligned::
  848. lea rax,QWORD PTR[((-16))+rdx]
  849. lea rbx,QWORD PTR[16+rdx]
  850. shr rcx,4
  851. DB 0f3h,00fh,0a7h,232
  852. movdqa xmm0,XMMWORD PTR[rax]
  853. movdqa XMMWORD PTR[(-16)+rdx],xmm0
  854. $L$ofb_exit::
  855. mov eax,1
  856. lea rsp,QWORD PTR[8+rsp]
  857. $L$ofb_abort::
  858. pop rbx
  859. pop rbp
  860. mov rdi,QWORD PTR[8+rsp] ;WIN64 epilogue
  861. mov rsi,QWORD PTR[16+rsp]
  862. DB 0F3h,0C3h ;repret
  863. $L$SEH_end_padlock_ofb_encrypt::
  864. padlock_ofb_encrypt ENDP
  865. PUBLIC padlock_ctr32_encrypt
  866. ALIGN 16
  867. padlock_ctr32_encrypt PROC PUBLIC
  868. mov QWORD PTR[8+rsp],rdi ;WIN64 prologue
  869. mov QWORD PTR[16+rsp],rsi
  870. mov rax,rsp
  871. $L$SEH_begin_padlock_ctr32_encrypt::
  872. mov rdi,rcx
  873. mov rsi,rdx
  874. mov rdx,r8
  875. mov rcx,r9
  876. push rbp
  877. push rbx
  878. xor eax,eax
  879. test rdx,15
  880. jnz $L$ctr32_abort
  881. test rcx,15
  882. jnz $L$ctr32_abort
  883. lea rax,QWORD PTR[$L$padlock_saved_context]
  884. pushf
  885. cld
  886. call _padlock_verify_ctx
  887. lea rdx,QWORD PTR[16+rdx]
  888. xor eax,eax
  889. xor ebx,ebx
  890. test DWORD PTR[rdx],32
  891. jnz $L$ctr32_aligned
  892. test rdi,00fh
  893. setz al
  894. test rsi,00fh
  895. setz bl
  896. test eax,ebx
  897. jnz $L$ctr32_aligned
  898. neg rax
  899. mov rbx,512
  900. not rax
  901. lea rbp,QWORD PTR[rsp]
  902. cmp rcx,rbx
  903. cmovc rbx,rcx
  904. and rax,rbx
  905. mov rbx,rcx
  906. neg rax
  907. and rbx,512-1
  908. lea rsp,QWORD PTR[rbp*1+rax]
  909. mov rax,512
  910. cmovz rbx,rax
  911. $L$ctr32_reenter::
  912. mov eax,DWORD PTR[((-4))+rdx]
  913. bswap eax
  914. neg eax
  915. and eax,31
  916. mov rbx,512
  917. shl eax,4
  918. cmovz rax,rbx
  919. cmp rcx,rax
  920. cmova rbx,rax
  921. cmovbe rbx,rcx
  922. cmp rcx,rbx
  923. ja $L$ctr32_loop
  924. mov rax,rsi
  925. cmp rbp,rsp
  926. cmove rax,rdi
  927. add rax,rcx
  928. neg rax
  929. and rax,0fffh
  930. cmp rax,32
  931. mov rax,-32
  932. cmovae rax,rbx
  933. and rbx,rax
  934. jz $L$ctr32_unaligned_tail
  935. jmp $L$ctr32_loop
  936. ALIGN 16
  937. $L$ctr32_loop::
  938. cmp rbx,rcx
  939. cmova rbx,rcx
  940. mov r8,rdi
  941. mov r9,rsi
  942. mov r10,rcx
  943. mov rcx,rbx
  944. mov r11,rbx
  945. test rdi,00fh
  946. cmovnz rdi,rsp
  947. test rsi,00fh
  948. jz $L$ctr32_inp_aligned
  949. shr rcx,3
  950. DB 0f3h,048h,0a5h
  951. sub rdi,rbx
  952. mov rcx,rbx
  953. mov rsi,rdi
  954. $L$ctr32_inp_aligned::
  955. lea rax,QWORD PTR[((-16))+rdx]
  956. lea rbx,QWORD PTR[16+rdx]
  957. shr rcx,4
  958. DB 0f3h,00fh,0a7h,216
  959. mov eax,DWORD PTR[((-4))+rdx]
  960. test eax,0ffff0000h
  961. jnz $L$ctr32_no_carry
  962. bswap eax
  963. add eax,010000h
  964. bswap eax
  965. mov DWORD PTR[((-4))+rdx],eax
  966. $L$ctr32_no_carry::
  967. mov rdi,r8
  968. mov rbx,r11
  969. test rdi,00fh
  970. jz $L$ctr32_out_aligned
  971. mov rcx,rbx
  972. lea rsi,QWORD PTR[rsp]
  973. shr rcx,3
  974. DB 0f3h,048h,0a5h
  975. sub rdi,rbx
  976. $L$ctr32_out_aligned::
  977. mov rsi,r9
  978. mov rcx,r10
  979. add rdi,rbx
  980. add rsi,rbx
  981. sub rcx,rbx
  982. mov rbx,512
  983. jz $L$ctr32_break
  984. cmp rcx,rbx
  985. jae $L$ctr32_loop
  986. mov rbx,rcx
  987. mov rax,rsi
  988. cmp rbp,rsp
  989. cmove rax,rdi
  990. add rax,rcx
  991. neg rax
  992. and rax,0fffh
  993. cmp rax,32
  994. mov rax,-32
  995. cmovae rax,rbx
  996. and rbx,rax
  997. jnz $L$ctr32_loop
  998. $L$ctr32_unaligned_tail::
  999. xor eax,eax
  1000. cmp rbp,rsp
  1001. cmove rax,rcx
  1002. mov r8,rdi
  1003. mov rbx,rcx
  1004. sub rsp,rax
  1005. shr rcx,3
  1006. lea rdi,QWORD PTR[rsp]
  1007. DB 0f3h,048h,0a5h
  1008. mov rsi,rsp
  1009. mov rdi,r8
  1010. mov rcx,rbx
  1011. jmp $L$ctr32_loop
  1012. ALIGN 16
  1013. $L$ctr32_break::
  1014. cmp rsp,rbp
  1015. je $L$ctr32_done
  1016. pxor xmm0,xmm0
  1017. lea rax,QWORD PTR[rsp]
  1018. $L$ctr32_bzero::
  1019. movaps XMMWORD PTR[rax],xmm0
  1020. lea rax,QWORD PTR[16+rax]
  1021. cmp rbp,rax
  1022. ja $L$ctr32_bzero
  1023. $L$ctr32_done::
  1024. lea rsp,QWORD PTR[rbp]
  1025. jmp $L$ctr32_exit
  1026. ALIGN 16
  1027. $L$ctr32_aligned::
  1028. mov eax,DWORD PTR[((-4))+rdx]
  1029. bswap eax
  1030. neg eax
  1031. and eax,0ffffh
  1032. mov rbx,1048576
  1033. shl eax,4
  1034. cmovz rax,rbx
  1035. cmp rcx,rax
  1036. cmova rbx,rax
  1037. cmovbe rbx,rcx
  1038. jbe $L$ctr32_aligned_skip
  1039. $L$ctr32_aligned_loop::
  1040. mov r10,rcx
  1041. mov rcx,rbx
  1042. mov r11,rbx
  1043. lea rax,QWORD PTR[((-16))+rdx]
  1044. lea rbx,QWORD PTR[16+rdx]
  1045. shr rcx,4
  1046. DB 0f3h,00fh,0a7h,216
  1047. mov eax,DWORD PTR[((-4))+rdx]
  1048. bswap eax
  1049. add eax,010000h
  1050. bswap eax
  1051. mov DWORD PTR[((-4))+rdx],eax
  1052. mov rcx,r10
  1053. sub rcx,r11
  1054. mov rbx,1048576
  1055. jz $L$ctr32_exit
  1056. cmp rcx,rbx
  1057. jae $L$ctr32_aligned_loop
  1058. $L$ctr32_aligned_skip::
  1059. lea rbp,QWORD PTR[rcx*1+rsi]
  1060. neg rbp
  1061. and rbp,0fffh
  1062. xor eax,eax
  1063. cmp rbp,32
  1064. mov rbp,32-1
  1065. cmovae rbp,rax
  1066. and rbp,rcx
  1067. sub rcx,rbp
  1068. jz $L$ctr32_aligned_tail
  1069. lea rax,QWORD PTR[((-16))+rdx]
  1070. lea rbx,QWORD PTR[16+rdx]
  1071. shr rcx,4
  1072. DB 0f3h,00fh,0a7h,216
  1073. test rbp,rbp
  1074. jz $L$ctr32_exit
  1075. $L$ctr32_aligned_tail::
  1076. mov r8,rdi
  1077. mov rbx,rbp
  1078. mov rcx,rbp
  1079. lea rbp,QWORD PTR[rsp]
  1080. sub rsp,rcx
  1081. shr rcx,3
  1082. lea rdi,QWORD PTR[rsp]
  1083. DB 0f3h,048h,0a5h
  1084. lea rdi,QWORD PTR[r8]
  1085. lea rsi,QWORD PTR[rsp]
  1086. mov rcx,rbx
  1087. jmp $L$ctr32_loop
  1088. $L$ctr32_exit::
  1089. mov eax,1
  1090. lea rsp,QWORD PTR[8+rsp]
  1091. $L$ctr32_abort::
  1092. pop rbx
  1093. pop rbp
  1094. mov rdi,QWORD PTR[8+rsp] ;WIN64 epilogue
  1095. mov rsi,QWORD PTR[16+rsp]
  1096. DB 0F3h,0C3h ;repret
  1097. $L$SEH_end_padlock_ctr32_encrypt::
  1098. padlock_ctr32_encrypt ENDP
  1099. DB 86,73,65,32,80,97,100,108,111,99,107,32,120,56,54,95
  1100. DB 54,52,32,109,111,100,117,108,101,44,32,67,82,89,80,84
  1101. DB 79,71,65,77,83,32,98,121,32,60,97,112,112,114,111,64
  1102. DB 111,112,101,110,115,115,108,46,111,114,103,62,0
  1103. ALIGN 16
  1104. .text$ ENDS
  1105. _DATA SEGMENT
  1106. ALIGN 8
  1107. $L$padlock_saved_context::
  1108. DQ 0
  1109. _DATA ENDS
  1110. END