e_padlock-x86.masm 20 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037
  1. IF @Version LT 800
  2. ECHO MASM version 8.00 or later is strongly recommended.
  3. ENDIF
  4. .686
  5. .XMM
  6. IF @Version LT 800
  7. XMMWORD STRUCT 16
  8. DQ 2 dup (?)
  9. XMMWORD ENDS
  10. ENDIF
  11. .MODEL FLAT
  12. OPTION DOTNAME
  13. IF @Version LT 800
  14. .text$ SEGMENT PAGE 'CODE'
  15. ELSE
  16. .text$ SEGMENT ALIGN(64) 'CODE'
  17. ENDIF
  18. ALIGN 16
  19. _padlock_capability PROC PUBLIC
  20. $L_padlock_capability_begin::
  21. push ebx
  22. pushfd
  23. pop eax
  24. mov ecx,eax
  25. xor eax,2097152
  26. push eax
  27. popfd
  28. pushfd
  29. pop eax
  30. xor ecx,eax
  31. xor eax,eax
  32. bt ecx,21
  33. jnc $L000noluck
  34. cpuid
  35. xor eax,eax
  36. cmp ebx,0746e6543h
  37. jne $L001zhaoxin
  38. cmp edx,048727561h
  39. jne $L000noluck
  40. cmp ecx,0736c7561h
  41. jne $L000noluck
  42. jmp $L002zhaoxinEnd
  43. $L001zhaoxin:
  44. cmp ebx,068532020h
  45. jne $L000noluck
  46. cmp edx,068676e61h
  47. jne $L000noluck
  48. cmp ecx,020206961h
  49. jne $L000noluck
  50. $L002zhaoxinEnd:
  51. mov eax,3221225472
  52. cpuid
  53. mov edx,eax
  54. xor eax,eax
  55. cmp edx,3221225473
  56. jb $L000noluck
  57. mov eax,1
  58. cpuid
  59. or eax,15
  60. xor ebx,ebx
  61. and eax,4095
  62. cmp eax,1791
  63. sete bl
  64. mov eax,3221225473
  65. push ebx
  66. cpuid
  67. pop ebx
  68. mov eax,edx
  69. shl ebx,4
  70. and eax,4294967279
  71. or eax,ebx
  72. $L000noluck:
  73. pop ebx
  74. ret
  75. _padlock_capability ENDP
  76. ALIGN 16
  77. _padlock_key_bswap PROC PUBLIC
  78. $L_padlock_key_bswap_begin::
  79. mov edx,DWORD PTR 4[esp]
  80. mov ecx,DWORD PTR 240[edx]
  81. $L003bswap_loop:
  82. mov eax,DWORD PTR [edx]
  83. bswap eax
  84. mov DWORD PTR [edx],eax
  85. lea edx,DWORD PTR 4[edx]
  86. sub ecx,1
  87. jnz $L003bswap_loop
  88. ret
  89. _padlock_key_bswap ENDP
  90. ALIGN 16
  91. _padlock_verify_context PROC PUBLIC
  92. $L_padlock_verify_context_begin::
  93. mov edx,DWORD PTR 4[esp]
  94. lea eax,DWORD PTR $Lpadlock_saved_context
  95. pushfd
  96. call __padlock_verify_ctx
  97. $L004verify_pic_point:
  98. lea esp,DWORD PTR 4[esp]
  99. ret
  100. _padlock_verify_context ENDP
  101. ALIGN 16
  102. __padlock_verify_ctx PROC PRIVATE
  103. bt DWORD PTR 4[esp],30
  104. jnc $L005verified
  105. cmp edx,DWORD PTR [eax]
  106. je $L005verified
  107. pushfd
  108. popfd
  109. $L005verified:
  110. mov DWORD PTR [eax],edx
  111. ret
  112. __padlock_verify_ctx ENDP
  113. ALIGN 16
  114. _padlock_reload_key PROC PUBLIC
  115. $L_padlock_reload_key_begin::
  116. pushfd
  117. popfd
  118. ret
  119. _padlock_reload_key ENDP
  120. ALIGN 16
  121. _padlock_aes_block PROC PUBLIC
  122. $L_padlock_aes_block_begin::
  123. push edi
  124. push esi
  125. push ebx
  126. mov edi,DWORD PTR 16[esp]
  127. mov esi,DWORD PTR 20[esp]
  128. mov edx,DWORD PTR 24[esp]
  129. mov ecx,1
  130. lea ebx,DWORD PTR 32[edx]
  131. lea edx,DWORD PTR 16[edx]
  132. DB 243,15,167,200
  133. pop ebx
  134. pop esi
  135. pop edi
  136. ret
  137. _padlock_aes_block ENDP
  138. ALIGN 16
  139. _padlock_ecb_encrypt PROC PUBLIC
  140. $L_padlock_ecb_encrypt_begin::
  141. push ebp
  142. push ebx
  143. push esi
  144. push edi
  145. mov edi,DWORD PTR 20[esp]
  146. mov esi,DWORD PTR 24[esp]
  147. mov edx,DWORD PTR 28[esp]
  148. mov ecx,DWORD PTR 32[esp]
  149. test edx,15
  150. jnz $L006ecb_abort
  151. test ecx,15
  152. jnz $L006ecb_abort
  153. lea eax,DWORD PTR $Lpadlock_saved_context
  154. pushfd
  155. cld
  156. call __padlock_verify_ctx
  157. $L007ecb_pic_point:
  158. lea edx,DWORD PTR 16[edx]
  159. xor eax,eax
  160. xor ebx,ebx
  161. test DWORD PTR [edx],32
  162. jnz $L008ecb_aligned
  163. test edi,15
  164. setz al
  165. test esi,15
  166. setz bl
  167. test eax,ebx
  168. jnz $L008ecb_aligned
  169. neg eax
  170. mov ebx,512
  171. not eax
  172. lea ebp,DWORD PTR [esp-24]
  173. cmp ecx,ebx
  174. cmovc ebx,ecx
  175. and eax,ebx
  176. mov ebx,ecx
  177. neg eax
  178. and ebx,511
  179. lea esp,DWORD PTR [ebp*1+eax]
  180. mov eax,512
  181. cmovz ebx,eax
  182. mov eax,ebp
  183. and ebp,-16
  184. and esp,-16
  185. mov DWORD PTR 16[ebp],eax
  186. cmp ecx,ebx
  187. ja $L009ecb_loop
  188. mov eax,esi
  189. cmp ebp,esp
  190. cmove eax,edi
  191. add eax,ecx
  192. neg eax
  193. and eax,4095
  194. cmp eax,128
  195. mov eax,-128
  196. cmovae eax,ebx
  197. and ebx,eax
  198. jz $L010ecb_unaligned_tail
  199. jmp $L009ecb_loop
  200. ALIGN 16
  201. $L009ecb_loop:
  202. mov DWORD PTR [ebp],edi
  203. mov DWORD PTR 4[ebp],esi
  204. mov DWORD PTR 8[ebp],ecx
  205. mov ecx,ebx
  206. mov DWORD PTR 12[ebp],ebx
  207. test edi,15
  208. cmovnz edi,esp
  209. test esi,15
  210. jz $L011ecb_inp_aligned
  211. shr ecx,2
  212. DB 243,165
  213. sub edi,ebx
  214. mov ecx,ebx
  215. mov esi,edi
  216. $L011ecb_inp_aligned:
  217. lea eax,DWORD PTR [edx-16]
  218. lea ebx,DWORD PTR 16[edx]
  219. shr ecx,4
  220. DB 243,15,167,200
  221. mov edi,DWORD PTR [ebp]
  222. mov ebx,DWORD PTR 12[ebp]
  223. test edi,15
  224. jz $L012ecb_out_aligned
  225. mov ecx,ebx
  226. lea esi,DWORD PTR [esp]
  227. shr ecx,2
  228. DB 243,165
  229. sub edi,ebx
  230. $L012ecb_out_aligned:
  231. mov esi,DWORD PTR 4[ebp]
  232. mov ecx,DWORD PTR 8[ebp]
  233. add edi,ebx
  234. add esi,ebx
  235. sub ecx,ebx
  236. mov ebx,512
  237. jz $L013ecb_break
  238. cmp ecx,ebx
  239. jae $L009ecb_loop
  240. $L010ecb_unaligned_tail:
  241. xor eax,eax
  242. cmp esp,ebp
  243. cmove eax,ecx
  244. sub esp,eax
  245. mov eax,edi
  246. mov ebx,ecx
  247. shr ecx,2
  248. lea edi,DWORD PTR [esp]
  249. DB 243,165
  250. mov esi,esp
  251. mov edi,eax
  252. mov ecx,ebx
  253. jmp $L009ecb_loop
  254. ALIGN 16
  255. $L013ecb_break:
  256. cmp esp,ebp
  257. je $L014ecb_done
  258. pxor xmm0,xmm0
  259. lea eax,DWORD PTR [esp]
  260. $L015ecb_bzero:
  261. movaps XMMWORD PTR [eax],xmm0
  262. lea eax,DWORD PTR 16[eax]
  263. cmp ebp,eax
  264. ja $L015ecb_bzero
  265. $L014ecb_done:
  266. mov ebp,DWORD PTR 16[ebp]
  267. lea esp,DWORD PTR 24[ebp]
  268. jmp $L016ecb_exit
  269. ALIGN 16
  270. $L008ecb_aligned:
  271. lea ebp,DWORD PTR [ecx*1+esi]
  272. neg ebp
  273. and ebp,4095
  274. xor eax,eax
  275. cmp ebp,128
  276. mov ebp,127
  277. cmovae ebp,eax
  278. and ebp,ecx
  279. sub ecx,ebp
  280. jz $L017ecb_aligned_tail
  281. lea eax,DWORD PTR [edx-16]
  282. lea ebx,DWORD PTR 16[edx]
  283. shr ecx,4
  284. DB 243,15,167,200
  285. test ebp,ebp
  286. jz $L016ecb_exit
  287. $L017ecb_aligned_tail:
  288. mov ecx,ebp
  289. lea ebp,DWORD PTR [esp-24]
  290. mov esp,ebp
  291. mov eax,ebp
  292. sub esp,ecx
  293. and ebp,-16
  294. and esp,-16
  295. mov DWORD PTR 16[ebp],eax
  296. mov eax,edi
  297. mov ebx,ecx
  298. shr ecx,2
  299. lea edi,DWORD PTR [esp]
  300. DB 243,165
  301. mov esi,esp
  302. mov edi,eax
  303. mov ecx,ebx
  304. jmp $L009ecb_loop
  305. $L016ecb_exit:
  306. mov eax,1
  307. lea esp,DWORD PTR 4[esp]
  308. $L006ecb_abort:
  309. pop edi
  310. pop esi
  311. pop ebx
  312. pop ebp
  313. ret
  314. _padlock_ecb_encrypt ENDP
  315. ALIGN 16
  316. _padlock_cbc_encrypt PROC PUBLIC
  317. $L_padlock_cbc_encrypt_begin::
  318. push ebp
  319. push ebx
  320. push esi
  321. push edi
  322. mov edi,DWORD PTR 20[esp]
  323. mov esi,DWORD PTR 24[esp]
  324. mov edx,DWORD PTR 28[esp]
  325. mov ecx,DWORD PTR 32[esp]
  326. test edx,15
  327. jnz $L018cbc_abort
  328. test ecx,15
  329. jnz $L018cbc_abort
  330. lea eax,DWORD PTR $Lpadlock_saved_context
  331. pushfd
  332. cld
  333. call __padlock_verify_ctx
  334. $L019cbc_pic_point:
  335. lea edx,DWORD PTR 16[edx]
  336. xor eax,eax
  337. xor ebx,ebx
  338. test DWORD PTR [edx],32
  339. jnz $L020cbc_aligned
  340. test edi,15
  341. setz al
  342. test esi,15
  343. setz bl
  344. test eax,ebx
  345. jnz $L020cbc_aligned
  346. neg eax
  347. mov ebx,512
  348. not eax
  349. lea ebp,DWORD PTR [esp-24]
  350. cmp ecx,ebx
  351. cmovc ebx,ecx
  352. and eax,ebx
  353. mov ebx,ecx
  354. neg eax
  355. and ebx,511
  356. lea esp,DWORD PTR [ebp*1+eax]
  357. mov eax,512
  358. cmovz ebx,eax
  359. mov eax,ebp
  360. and ebp,-16
  361. and esp,-16
  362. mov DWORD PTR 16[ebp],eax
  363. cmp ecx,ebx
  364. ja $L021cbc_loop
  365. mov eax,esi
  366. cmp ebp,esp
  367. cmove eax,edi
  368. add eax,ecx
  369. neg eax
  370. and eax,4095
  371. cmp eax,64
  372. mov eax,-64
  373. cmovae eax,ebx
  374. and ebx,eax
  375. jz $L022cbc_unaligned_tail
  376. jmp $L021cbc_loop
  377. ALIGN 16
  378. $L021cbc_loop:
  379. mov DWORD PTR [ebp],edi
  380. mov DWORD PTR 4[ebp],esi
  381. mov DWORD PTR 8[ebp],ecx
  382. mov ecx,ebx
  383. mov DWORD PTR 12[ebp],ebx
  384. test edi,15
  385. cmovnz edi,esp
  386. test esi,15
  387. jz $L023cbc_inp_aligned
  388. shr ecx,2
  389. DB 243,165
  390. sub edi,ebx
  391. mov ecx,ebx
  392. mov esi,edi
  393. $L023cbc_inp_aligned:
  394. lea eax,DWORD PTR [edx-16]
  395. lea ebx,DWORD PTR 16[edx]
  396. shr ecx,4
  397. DB 243,15,167,208
  398. movaps xmm0,XMMWORD PTR [eax]
  399. movaps XMMWORD PTR [edx-16],xmm0
  400. mov edi,DWORD PTR [ebp]
  401. mov ebx,DWORD PTR 12[ebp]
  402. test edi,15
  403. jz $L024cbc_out_aligned
  404. mov ecx,ebx
  405. lea esi,DWORD PTR [esp]
  406. shr ecx,2
  407. DB 243,165
  408. sub edi,ebx
  409. $L024cbc_out_aligned:
  410. mov esi,DWORD PTR 4[ebp]
  411. mov ecx,DWORD PTR 8[ebp]
  412. add edi,ebx
  413. add esi,ebx
  414. sub ecx,ebx
  415. mov ebx,512
  416. jz $L025cbc_break
  417. cmp ecx,ebx
  418. jae $L021cbc_loop
  419. $L022cbc_unaligned_tail:
  420. xor eax,eax
  421. cmp esp,ebp
  422. cmove eax,ecx
  423. sub esp,eax
  424. mov eax,edi
  425. mov ebx,ecx
  426. shr ecx,2
  427. lea edi,DWORD PTR [esp]
  428. DB 243,165
  429. mov esi,esp
  430. mov edi,eax
  431. mov ecx,ebx
  432. jmp $L021cbc_loop
  433. ALIGN 16
  434. $L025cbc_break:
  435. cmp esp,ebp
  436. je $L026cbc_done
  437. pxor xmm0,xmm0
  438. lea eax,DWORD PTR [esp]
  439. $L027cbc_bzero:
  440. movaps XMMWORD PTR [eax],xmm0
  441. lea eax,DWORD PTR 16[eax]
  442. cmp ebp,eax
  443. ja $L027cbc_bzero
  444. $L026cbc_done:
  445. mov ebp,DWORD PTR 16[ebp]
  446. lea esp,DWORD PTR 24[ebp]
  447. jmp $L028cbc_exit
  448. ALIGN 16
  449. $L020cbc_aligned:
  450. lea ebp,DWORD PTR [ecx*1+esi]
  451. neg ebp
  452. and ebp,4095
  453. xor eax,eax
  454. cmp ebp,64
  455. mov ebp,63
  456. cmovae ebp,eax
  457. and ebp,ecx
  458. sub ecx,ebp
  459. jz $L029cbc_aligned_tail
  460. lea eax,DWORD PTR [edx-16]
  461. lea ebx,DWORD PTR 16[edx]
  462. shr ecx,4
  463. DB 243,15,167,208
  464. movaps xmm0,XMMWORD PTR [eax]
  465. movaps XMMWORD PTR [edx-16],xmm0
  466. test ebp,ebp
  467. jz $L028cbc_exit
  468. $L029cbc_aligned_tail:
  469. mov ecx,ebp
  470. lea ebp,DWORD PTR [esp-24]
  471. mov esp,ebp
  472. mov eax,ebp
  473. sub esp,ecx
  474. and ebp,-16
  475. and esp,-16
  476. mov DWORD PTR 16[ebp],eax
  477. mov eax,edi
  478. mov ebx,ecx
  479. shr ecx,2
  480. lea edi,DWORD PTR [esp]
  481. DB 243,165
  482. mov esi,esp
  483. mov edi,eax
  484. mov ecx,ebx
  485. jmp $L021cbc_loop
  486. $L028cbc_exit:
  487. mov eax,1
  488. lea esp,DWORD PTR 4[esp]
  489. $L018cbc_abort:
  490. pop edi
  491. pop esi
  492. pop ebx
  493. pop ebp
  494. ret
  495. _padlock_cbc_encrypt ENDP
  496. ALIGN 16
  497. _padlock_cfb_encrypt PROC PUBLIC
  498. $L_padlock_cfb_encrypt_begin::
  499. push ebp
  500. push ebx
  501. push esi
  502. push edi
  503. mov edi,DWORD PTR 20[esp]
  504. mov esi,DWORD PTR 24[esp]
  505. mov edx,DWORD PTR 28[esp]
  506. mov ecx,DWORD PTR 32[esp]
  507. test edx,15
  508. jnz $L030cfb_abort
  509. test ecx,15
  510. jnz $L030cfb_abort
  511. lea eax,DWORD PTR $Lpadlock_saved_context
  512. pushfd
  513. cld
  514. call __padlock_verify_ctx
  515. $L031cfb_pic_point:
  516. lea edx,DWORD PTR 16[edx]
  517. xor eax,eax
  518. xor ebx,ebx
  519. test DWORD PTR [edx],32
  520. jnz $L032cfb_aligned
  521. test edi,15
  522. setz al
  523. test esi,15
  524. setz bl
  525. test eax,ebx
  526. jnz $L032cfb_aligned
  527. neg eax
  528. mov ebx,512
  529. not eax
  530. lea ebp,DWORD PTR [esp-24]
  531. cmp ecx,ebx
  532. cmovc ebx,ecx
  533. and eax,ebx
  534. mov ebx,ecx
  535. neg eax
  536. and ebx,511
  537. lea esp,DWORD PTR [ebp*1+eax]
  538. mov eax,512
  539. cmovz ebx,eax
  540. mov eax,ebp
  541. and ebp,-16
  542. and esp,-16
  543. mov DWORD PTR 16[ebp],eax
  544. jmp $L033cfb_loop
  545. ALIGN 16
  546. $L033cfb_loop:
  547. mov DWORD PTR [ebp],edi
  548. mov DWORD PTR 4[ebp],esi
  549. mov DWORD PTR 8[ebp],ecx
  550. mov ecx,ebx
  551. mov DWORD PTR 12[ebp],ebx
  552. test edi,15
  553. cmovnz edi,esp
  554. test esi,15
  555. jz $L034cfb_inp_aligned
  556. shr ecx,2
  557. DB 243,165
  558. sub edi,ebx
  559. mov ecx,ebx
  560. mov esi,edi
  561. $L034cfb_inp_aligned:
  562. lea eax,DWORD PTR [edx-16]
  563. lea ebx,DWORD PTR 16[edx]
  564. shr ecx,4
  565. DB 243,15,167,224
  566. movaps xmm0,XMMWORD PTR [eax]
  567. movaps XMMWORD PTR [edx-16],xmm0
  568. mov edi,DWORD PTR [ebp]
  569. mov ebx,DWORD PTR 12[ebp]
  570. test edi,15
  571. jz $L035cfb_out_aligned
  572. mov ecx,ebx
  573. lea esi,DWORD PTR [esp]
  574. shr ecx,2
  575. DB 243,165
  576. sub edi,ebx
  577. $L035cfb_out_aligned:
  578. mov esi,DWORD PTR 4[ebp]
  579. mov ecx,DWORD PTR 8[ebp]
  580. add edi,ebx
  581. add esi,ebx
  582. sub ecx,ebx
  583. mov ebx,512
  584. jnz $L033cfb_loop
  585. cmp esp,ebp
  586. je $L036cfb_done
  587. pxor xmm0,xmm0
  588. lea eax,DWORD PTR [esp]
  589. $L037cfb_bzero:
  590. movaps XMMWORD PTR [eax],xmm0
  591. lea eax,DWORD PTR 16[eax]
  592. cmp ebp,eax
  593. ja $L037cfb_bzero
  594. $L036cfb_done:
  595. mov ebp,DWORD PTR 16[ebp]
  596. lea esp,DWORD PTR 24[ebp]
  597. jmp $L038cfb_exit
  598. ALIGN 16
  599. $L032cfb_aligned:
  600. lea eax,DWORD PTR [edx-16]
  601. lea ebx,DWORD PTR 16[edx]
  602. shr ecx,4
  603. DB 243,15,167,224
  604. movaps xmm0,XMMWORD PTR [eax]
  605. movaps XMMWORD PTR [edx-16],xmm0
  606. $L038cfb_exit:
  607. mov eax,1
  608. lea esp,DWORD PTR 4[esp]
  609. $L030cfb_abort:
  610. pop edi
  611. pop esi
  612. pop ebx
  613. pop ebp
  614. ret
  615. _padlock_cfb_encrypt ENDP
  616. ALIGN 16
  617. _padlock_ofb_encrypt PROC PUBLIC
  618. $L_padlock_ofb_encrypt_begin::
  619. push ebp
  620. push ebx
  621. push esi
  622. push edi
  623. mov edi,DWORD PTR 20[esp]
  624. mov esi,DWORD PTR 24[esp]
  625. mov edx,DWORD PTR 28[esp]
  626. mov ecx,DWORD PTR 32[esp]
  627. test edx,15
  628. jnz $L039ofb_abort
  629. test ecx,15
  630. jnz $L039ofb_abort
  631. lea eax,DWORD PTR $Lpadlock_saved_context
  632. pushfd
  633. cld
  634. call __padlock_verify_ctx
  635. $L040ofb_pic_point:
  636. lea edx,DWORD PTR 16[edx]
  637. xor eax,eax
  638. xor ebx,ebx
  639. test DWORD PTR [edx],32
  640. jnz $L041ofb_aligned
  641. test edi,15
  642. setz al
  643. test esi,15
  644. setz bl
  645. test eax,ebx
  646. jnz $L041ofb_aligned
  647. neg eax
  648. mov ebx,512
  649. not eax
  650. lea ebp,DWORD PTR [esp-24]
  651. cmp ecx,ebx
  652. cmovc ebx,ecx
  653. and eax,ebx
  654. mov ebx,ecx
  655. neg eax
  656. and ebx,511
  657. lea esp,DWORD PTR [ebp*1+eax]
  658. mov eax,512
  659. cmovz ebx,eax
  660. mov eax,ebp
  661. and ebp,-16
  662. and esp,-16
  663. mov DWORD PTR 16[ebp],eax
  664. jmp $L042ofb_loop
  665. ALIGN 16
  666. $L042ofb_loop:
  667. mov DWORD PTR [ebp],edi
  668. mov DWORD PTR 4[ebp],esi
  669. mov DWORD PTR 8[ebp],ecx
  670. mov ecx,ebx
  671. mov DWORD PTR 12[ebp],ebx
  672. test edi,15
  673. cmovnz edi,esp
  674. test esi,15
  675. jz $L043ofb_inp_aligned
  676. shr ecx,2
  677. DB 243,165
  678. sub edi,ebx
  679. mov ecx,ebx
  680. mov esi,edi
  681. $L043ofb_inp_aligned:
  682. lea eax,DWORD PTR [edx-16]
  683. lea ebx,DWORD PTR 16[edx]
  684. shr ecx,4
  685. DB 243,15,167,232
  686. movaps xmm0,XMMWORD PTR [eax]
  687. movaps XMMWORD PTR [edx-16],xmm0
  688. mov edi,DWORD PTR [ebp]
  689. mov ebx,DWORD PTR 12[ebp]
  690. test edi,15
  691. jz $L044ofb_out_aligned
  692. mov ecx,ebx
  693. lea esi,DWORD PTR [esp]
  694. shr ecx,2
  695. DB 243,165
  696. sub edi,ebx
  697. $L044ofb_out_aligned:
  698. mov esi,DWORD PTR 4[ebp]
  699. mov ecx,DWORD PTR 8[ebp]
  700. add edi,ebx
  701. add esi,ebx
  702. sub ecx,ebx
  703. mov ebx,512
  704. jnz $L042ofb_loop
  705. cmp esp,ebp
  706. je $L045ofb_done
  707. pxor xmm0,xmm0
  708. lea eax,DWORD PTR [esp]
  709. $L046ofb_bzero:
  710. movaps XMMWORD PTR [eax],xmm0
  711. lea eax,DWORD PTR 16[eax]
  712. cmp ebp,eax
  713. ja $L046ofb_bzero
  714. $L045ofb_done:
  715. mov ebp,DWORD PTR 16[ebp]
  716. lea esp,DWORD PTR 24[ebp]
  717. jmp $L047ofb_exit
  718. ALIGN 16
  719. $L041ofb_aligned:
  720. lea eax,DWORD PTR [edx-16]
  721. lea ebx,DWORD PTR 16[edx]
  722. shr ecx,4
  723. DB 243,15,167,232
  724. movaps xmm0,XMMWORD PTR [eax]
  725. movaps XMMWORD PTR [edx-16],xmm0
  726. $L047ofb_exit:
  727. mov eax,1
  728. lea esp,DWORD PTR 4[esp]
  729. $L039ofb_abort:
  730. pop edi
  731. pop esi
  732. pop ebx
  733. pop ebp
  734. ret
  735. _padlock_ofb_encrypt ENDP
  736. ALIGN 16
  737. _padlock_ctr32_encrypt PROC PUBLIC
  738. $L_padlock_ctr32_encrypt_begin::
  739. push ebp
  740. push ebx
  741. push esi
  742. push edi
  743. mov edi,DWORD PTR 20[esp]
  744. mov esi,DWORD PTR 24[esp]
  745. mov edx,DWORD PTR 28[esp]
  746. mov ecx,DWORD PTR 32[esp]
  747. test edx,15
  748. jnz $L048ctr32_abort
  749. test ecx,15
  750. jnz $L048ctr32_abort
  751. lea eax,DWORD PTR $Lpadlock_saved_context
  752. pushfd
  753. cld
  754. call __padlock_verify_ctx
  755. $L049ctr32_pic_point:
  756. lea edx,DWORD PTR 16[edx]
  757. xor eax,eax
  758. movq mm0,QWORD PTR [edx-16]
  759. mov ebx,512
  760. not eax
  761. lea ebp,DWORD PTR [esp-24]
  762. cmp ecx,ebx
  763. cmovc ebx,ecx
  764. and eax,ebx
  765. mov ebx,ecx
  766. neg eax
  767. and ebx,511
  768. lea esp,DWORD PTR [ebp*1+eax]
  769. mov eax,512
  770. cmovz ebx,eax
  771. mov eax,ebp
  772. and ebp,-16
  773. and esp,-16
  774. mov DWORD PTR 16[ebp],eax
  775. jmp $L050ctr32_loop
  776. ALIGN 16
  777. $L050ctr32_loop:
  778. mov DWORD PTR [ebp],edi
  779. mov DWORD PTR 4[ebp],esi
  780. mov DWORD PTR 8[ebp],ecx
  781. mov ecx,ebx
  782. mov DWORD PTR 12[ebp],ebx
  783. mov ecx,DWORD PTR [edx-4]
  784. xor edi,edi
  785. mov eax,DWORD PTR [edx-8]
  786. $L051ctr32_prepare:
  787. mov DWORD PTR 12[edi*1+esp],ecx
  788. bswap ecx
  789. movq QWORD PTR [edi*1+esp],mm0
  790. inc ecx
  791. mov DWORD PTR 8[edi*1+esp],eax
  792. bswap ecx
  793. lea edi,DWORD PTR 16[edi]
  794. cmp edi,ebx
  795. jb $L051ctr32_prepare
  796. mov DWORD PTR [edx-4],ecx
  797. lea esi,DWORD PTR [esp]
  798. lea edi,DWORD PTR [esp]
  799. mov ecx,ebx
  800. lea eax,DWORD PTR [edx-16]
  801. lea ebx,DWORD PTR 16[edx]
  802. shr ecx,4
  803. DB 243,15,167,200
  804. mov edi,DWORD PTR [ebp]
  805. mov ebx,DWORD PTR 12[ebp]
  806. mov esi,DWORD PTR 4[ebp]
  807. xor ecx,ecx
  808. $L052ctr32_xor:
  809. movups xmm1,XMMWORD PTR [ecx*1+esi]
  810. lea ecx,DWORD PTR 16[ecx]
  811. pxor xmm1,XMMWORD PTR [ecx*1+esp-16]
  812. movups XMMWORD PTR [ecx*1+edi-16],xmm1
  813. cmp ecx,ebx
  814. jb $L052ctr32_xor
  815. mov ecx,DWORD PTR 8[ebp]
  816. add edi,ebx
  817. add esi,ebx
  818. sub ecx,ebx
  819. mov ebx,512
  820. jnz $L050ctr32_loop
  821. pxor xmm0,xmm0
  822. lea eax,DWORD PTR [esp]
  823. $L053ctr32_bzero:
  824. movaps XMMWORD PTR [eax],xmm0
  825. lea eax,DWORD PTR 16[eax]
  826. cmp ebp,eax
  827. ja $L053ctr32_bzero
  828. $L054ctr32_done:
  829. mov ebp,DWORD PTR 16[ebp]
  830. lea esp,DWORD PTR 24[ebp]
  831. mov eax,1
  832. lea esp,DWORD PTR 4[esp]
  833. emms
  834. $L048ctr32_abort:
  835. pop edi
  836. pop esi
  837. pop ebx
  838. pop ebp
  839. ret
  840. _padlock_ctr32_encrypt ENDP
  841. ALIGN 16
  842. _padlock_xstore PROC PUBLIC
  843. $L_padlock_xstore_begin::
  844. push edi
  845. mov edi,DWORD PTR 8[esp]
  846. mov edx,DWORD PTR 12[esp]
  847. DB 15,167,192
  848. pop edi
  849. ret
  850. _padlock_xstore ENDP
  851. ALIGN 16
  852. __win32_segv_handler PROC PRIVATE
  853. mov eax,1
  854. mov edx,DWORD PTR 4[esp]
  855. mov ecx,DWORD PTR 12[esp]
  856. cmp DWORD PTR [edx],3221225477
  857. jne $L055ret
  858. add DWORD PTR 184[ecx],4
  859. mov eax,0
  860. $L055ret:
  861. ret
  862. __win32_segv_handler ENDP
  863. IF @Version GE 710
  864. .SAFESEH __win32_segv_handler
  865. ENDIF
  866. ALIGN 16
  867. _padlock_sha1_oneshot PROC PUBLIC
  868. $L_padlock_sha1_oneshot_begin::
  869. push edi
  870. push esi
  871. xor eax,eax
  872. mov edi,DWORD PTR 12[esp]
  873. mov esi,DWORD PTR 16[esp]
  874. mov ecx,DWORD PTR 20[esp]
  875. push __win32_segv_handler
  876. DB 100,255,48
  877. DB 100,137,32
  878. mov edx,esp
  879. add esp,-128
  880. movups xmm0,XMMWORD PTR [edi]
  881. and esp,-16
  882. mov eax,DWORD PTR 16[edi]
  883. movaps XMMWORD PTR [esp],xmm0
  884. mov edi,esp
  885. mov DWORD PTR 16[esp],eax
  886. xor eax,eax
  887. DB 243,15,166,200
  888. movaps xmm0,XMMWORD PTR [esp]
  889. mov eax,DWORD PTR 16[esp]
  890. mov esp,edx
  891. DB 100,143,5,0,0,0,0
  892. lea esp,DWORD PTR 4[esp]
  893. mov edi,DWORD PTR 16[esp]
  894. movups XMMWORD PTR [edi],xmm0
  895. mov DWORD PTR 16[edi],eax
  896. pop esi
  897. pop edi
  898. ret
  899. _padlock_sha1_oneshot ENDP
  900. ALIGN 16
  901. _padlock_sha1_blocks PROC PUBLIC
  902. $L_padlock_sha1_blocks_begin::
  903. push edi
  904. push esi
  905. mov edi,DWORD PTR 12[esp]
  906. mov esi,DWORD PTR 16[esp]
  907. mov edx,esp
  908. mov ecx,DWORD PTR 20[esp]
  909. add esp,-128
  910. movups xmm0,XMMWORD PTR [edi]
  911. and esp,-16
  912. mov eax,DWORD PTR 16[edi]
  913. movaps XMMWORD PTR [esp],xmm0
  914. mov edi,esp
  915. mov DWORD PTR 16[esp],eax
  916. mov eax,-1
  917. DB 243,15,166,200
  918. movaps xmm0,XMMWORD PTR [esp]
  919. mov eax,DWORD PTR 16[esp]
  920. mov esp,edx
  921. mov edi,DWORD PTR 12[esp]
  922. movups XMMWORD PTR [edi],xmm0
  923. mov DWORD PTR 16[edi],eax
  924. pop esi
  925. pop edi
  926. ret
  927. _padlock_sha1_blocks ENDP
  928. ALIGN 16
  929. _padlock_sha256_oneshot PROC PUBLIC
  930. $L_padlock_sha256_oneshot_begin::
  931. push edi
  932. push esi
  933. xor eax,eax
  934. mov edi,DWORD PTR 12[esp]
  935. mov esi,DWORD PTR 16[esp]
  936. mov ecx,DWORD PTR 20[esp]
  937. push __win32_segv_handler
  938. DB 100,255,48
  939. DB 100,137,32
  940. mov edx,esp
  941. add esp,-128
  942. movups xmm0,XMMWORD PTR [edi]
  943. and esp,-16
  944. movups xmm1,XMMWORD PTR 16[edi]
  945. movaps XMMWORD PTR [esp],xmm0
  946. mov edi,esp
  947. movaps XMMWORD PTR 16[esp],xmm1
  948. xor eax,eax
  949. DB 243,15,166,208
  950. movaps xmm0,XMMWORD PTR [esp]
  951. movaps xmm1,XMMWORD PTR 16[esp]
  952. mov esp,edx
  953. DB 100,143,5,0,0,0,0
  954. lea esp,DWORD PTR 4[esp]
  955. mov edi,DWORD PTR 16[esp]
  956. movups XMMWORD PTR [edi],xmm0
  957. movups XMMWORD PTR 16[edi],xmm1
  958. pop esi
  959. pop edi
  960. ret
  961. _padlock_sha256_oneshot ENDP
  962. ALIGN 16
  963. _padlock_sha256_blocks PROC PUBLIC
  964. $L_padlock_sha256_blocks_begin::
  965. push edi
  966. push esi
  967. mov edi,DWORD PTR 12[esp]
  968. mov esi,DWORD PTR 16[esp]
  969. mov ecx,DWORD PTR 20[esp]
  970. mov edx,esp
  971. add esp,-128
  972. movups xmm0,XMMWORD PTR [edi]
  973. and esp,-16
  974. movups xmm1,XMMWORD PTR 16[edi]
  975. movaps XMMWORD PTR [esp],xmm0
  976. mov edi,esp
  977. movaps XMMWORD PTR 16[esp],xmm1
  978. mov eax,-1
  979. DB 243,15,166,208
  980. movaps xmm0,XMMWORD PTR [esp]
  981. movaps xmm1,XMMWORD PTR 16[esp]
  982. mov esp,edx
  983. mov edi,DWORD PTR 12[esp]
  984. movups XMMWORD PTR [edi],xmm0
  985. movups XMMWORD PTR 16[edi],xmm1
  986. pop esi
  987. pop edi
  988. ret
  989. _padlock_sha256_blocks ENDP
  990. ALIGN 16
  991. _padlock_sha512_blocks PROC PUBLIC
  992. $L_padlock_sha512_blocks_begin::
  993. push edi
  994. push esi
  995. mov edi,DWORD PTR 12[esp]
  996. mov esi,DWORD PTR 16[esp]
  997. mov ecx,DWORD PTR 20[esp]
  998. mov edx,esp
  999. add esp,-128
  1000. movups xmm0,XMMWORD PTR [edi]
  1001. and esp,-16
  1002. movups xmm1,XMMWORD PTR 16[edi]
  1003. movups xmm2,XMMWORD PTR 32[edi]
  1004. movups xmm3,XMMWORD PTR 48[edi]
  1005. movaps XMMWORD PTR [esp],xmm0
  1006. mov edi,esp
  1007. movaps XMMWORD PTR 16[esp],xmm1
  1008. movaps XMMWORD PTR 32[esp],xmm2
  1009. movaps XMMWORD PTR 48[esp],xmm3
  1010. DB 243,15,166,224
  1011. movaps xmm0,XMMWORD PTR [esp]
  1012. movaps xmm1,XMMWORD PTR 16[esp]
  1013. movaps xmm2,XMMWORD PTR 32[esp]
  1014. movaps xmm3,XMMWORD PTR 48[esp]
  1015. mov esp,edx
  1016. mov edi,DWORD PTR 12[esp]
  1017. movups XMMWORD PTR [edi],xmm0
  1018. movups XMMWORD PTR 16[edi],xmm1
  1019. movups XMMWORD PTR 32[edi],xmm2
  1020. movups XMMWORD PTR 48[edi],xmm3
  1021. pop esi
  1022. pop edi
  1023. ret
  1024. _padlock_sha512_blocks ENDP
  1025. DB 86,73,65,32,80,97,100,108,111,99,107,32,120,56,54,32
  1026. DB 109,111,100,117,108,101,44,32,67,82,89,80,84,79,71,65
  1027. DB 77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101
  1028. DB 110,115,115,108,46,111,114,103,62,0
  1029. ALIGN 16
  1030. .text$ ENDS
  1031. _DATA SEGMENT
  1032. ALIGN 4
  1033. $Lpadlock_saved_context::
  1034. DD 0
  1035. _DATA ENDS
  1036. END