b_win32.asm 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896
  1. %ifidn __OUTPUT_FORMAT__,obj
  2. section code use32 class=code align=256
  3. %elifidn __OUTPUT_FORMAT__,win32
  4. [email protected] equ 1
  5. section .text code align=256
  6. %else
  7. section .text code
  8. %endif
  9. global _BF_encrypt
  10. align 16
  11. _BF_encrypt:
  12. L$_BF_encrypt_begin:
  13. ;
  14. push ebp
  15. push ebx
  16. mov ebx,DWORD [12+esp]
  17. mov ebp,DWORD [16+esp]
  18. push esi
  19. push edi
  20. ; Load the 2 words
  21. mov edi,DWORD [ebx]
  22. mov esi,DWORD [4+ebx]
  23. xor eax,eax
  24. mov ebx,DWORD [ebp]
  25. xor ecx,ecx
  26. xor edi,ebx
  27. ;
  28. ; Round 0
  29. mov edx,DWORD [4+ebp]
  30. mov ebx,edi
  31. xor esi,edx
  32. shr ebx,16
  33. mov edx,edi
  34. mov al,bh
  35. and ebx,255
  36. mov cl,dh
  37. and edx,255
  38. mov eax,DWORD [72+eax*4+ebp]
  39. mov ebx,DWORD [1096+ebx*4+ebp]
  40. add ebx,eax
  41. mov eax,DWORD [2120+ecx*4+ebp]
  42. xor ebx,eax
  43. mov edx,DWORD [3144+edx*4+ebp]
  44. add ebx,edx
  45. xor eax,eax
  46. xor esi,ebx
  47. ;
  48. ; Round 1
  49. mov edx,DWORD [8+ebp]
  50. mov ebx,esi
  51. xor edi,edx
  52. shr ebx,16
  53. mov edx,esi
  54. mov al,bh
  55. and ebx,255
  56. mov cl,dh
  57. and edx,255
  58. mov eax,DWORD [72+eax*4+ebp]
  59. mov ebx,DWORD [1096+ebx*4+ebp]
  60. add ebx,eax
  61. mov eax,DWORD [2120+ecx*4+ebp]
  62. xor ebx,eax
  63. mov edx,DWORD [3144+edx*4+ebp]
  64. add ebx,edx
  65. xor eax,eax
  66. xor edi,ebx
  67. ;
  68. ; Round 2
  69. mov edx,DWORD [12+ebp]
  70. mov ebx,edi
  71. xor esi,edx
  72. shr ebx,16
  73. mov edx,edi
  74. mov al,bh
  75. and ebx,255
  76. mov cl,dh
  77. and edx,255
  78. mov eax,DWORD [72+eax*4+ebp]
  79. mov ebx,DWORD [1096+ebx*4+ebp]
  80. add ebx,eax
  81. mov eax,DWORD [2120+ecx*4+ebp]
  82. xor ebx,eax
  83. mov edx,DWORD [3144+edx*4+ebp]
  84. add ebx,edx
  85. xor eax,eax
  86. xor esi,ebx
  87. ;
  88. ; Round 3
  89. mov edx,DWORD [16+ebp]
  90. mov ebx,esi
  91. xor edi,edx
  92. shr ebx,16
  93. mov edx,esi
  94. mov al,bh
  95. and ebx,255
  96. mov cl,dh
  97. and edx,255
  98. mov eax,DWORD [72+eax*4+ebp]
  99. mov ebx,DWORD [1096+ebx*4+ebp]
  100. add ebx,eax
  101. mov eax,DWORD [2120+ecx*4+ebp]
  102. xor ebx,eax
  103. mov edx,DWORD [3144+edx*4+ebp]
  104. add ebx,edx
  105. xor eax,eax
  106. xor edi,ebx
  107. ;
  108. ; Round 4
  109. mov edx,DWORD [20+ebp]
  110. mov ebx,edi
  111. xor esi,edx
  112. shr ebx,16
  113. mov edx,edi
  114. mov al,bh
  115. and ebx,255
  116. mov cl,dh
  117. and edx,255
  118. mov eax,DWORD [72+eax*4+ebp]
  119. mov ebx,DWORD [1096+ebx*4+ebp]
  120. add ebx,eax
  121. mov eax,DWORD [2120+ecx*4+ebp]
  122. xor ebx,eax
  123. mov edx,DWORD [3144+edx*4+ebp]
  124. add ebx,edx
  125. xor eax,eax
  126. xor esi,ebx
  127. ;
  128. ; Round 5
  129. mov edx,DWORD [24+ebp]
  130. mov ebx,esi
  131. xor edi,edx
  132. shr ebx,16
  133. mov edx,esi
  134. mov al,bh
  135. and ebx,255
  136. mov cl,dh
  137. and edx,255
  138. mov eax,DWORD [72+eax*4+ebp]
  139. mov ebx,DWORD [1096+ebx*4+ebp]
  140. add ebx,eax
  141. mov eax,DWORD [2120+ecx*4+ebp]
  142. xor ebx,eax
  143. mov edx,DWORD [3144+edx*4+ebp]
  144. add ebx,edx
  145. xor eax,eax
  146. xor edi,ebx
  147. ;
  148. ; Round 6
  149. mov edx,DWORD [28+ebp]
  150. mov ebx,edi
  151. xor esi,edx
  152. shr ebx,16
  153. mov edx,edi
  154. mov al,bh
  155. and ebx,255
  156. mov cl,dh
  157. and edx,255
  158. mov eax,DWORD [72+eax*4+ebp]
  159. mov ebx,DWORD [1096+ebx*4+ebp]
  160. add ebx,eax
  161. mov eax,DWORD [2120+ecx*4+ebp]
  162. xor ebx,eax
  163. mov edx,DWORD [3144+edx*4+ebp]
  164. add ebx,edx
  165. xor eax,eax
  166. xor esi,ebx
  167. ;
  168. ; Round 7
  169. mov edx,DWORD [32+ebp]
  170. mov ebx,esi
  171. xor edi,edx
  172. shr ebx,16
  173. mov edx,esi
  174. mov al,bh
  175. and ebx,255
  176. mov cl,dh
  177. and edx,255
  178. mov eax,DWORD [72+eax*4+ebp]
  179. mov ebx,DWORD [1096+ebx*4+ebp]
  180. add ebx,eax
  181. mov eax,DWORD [2120+ecx*4+ebp]
  182. xor ebx,eax
  183. mov edx,DWORD [3144+edx*4+ebp]
  184. add ebx,edx
  185. xor eax,eax
  186. xor edi,ebx
  187. ;
  188. ; Round 8
  189. mov edx,DWORD [36+ebp]
  190. mov ebx,edi
  191. xor esi,edx
  192. shr ebx,16
  193. mov edx,edi
  194. mov al,bh
  195. and ebx,255
  196. mov cl,dh
  197. and edx,255
  198. mov eax,DWORD [72+eax*4+ebp]
  199. mov ebx,DWORD [1096+ebx*4+ebp]
  200. add ebx,eax
  201. mov eax,DWORD [2120+ecx*4+ebp]
  202. xor ebx,eax
  203. mov edx,DWORD [3144+edx*4+ebp]
  204. add ebx,edx
  205. xor eax,eax
  206. xor esi,ebx
  207. ;
  208. ; Round 9
  209. mov edx,DWORD [40+ebp]
  210. mov ebx,esi
  211. xor edi,edx
  212. shr ebx,16
  213. mov edx,esi
  214. mov al,bh
  215. and ebx,255
  216. mov cl,dh
  217. and edx,255
  218. mov eax,DWORD [72+eax*4+ebp]
  219. mov ebx,DWORD [1096+ebx*4+ebp]
  220. add ebx,eax
  221. mov eax,DWORD [2120+ecx*4+ebp]
  222. xor ebx,eax
  223. mov edx,DWORD [3144+edx*4+ebp]
  224. add ebx,edx
  225. xor eax,eax
  226. xor edi,ebx
  227. ;
  228. ; Round 10
  229. mov edx,DWORD [44+ebp]
  230. mov ebx,edi
  231. xor esi,edx
  232. shr ebx,16
  233. mov edx,edi
  234. mov al,bh
  235. and ebx,255
  236. mov cl,dh
  237. and edx,255
  238. mov eax,DWORD [72+eax*4+ebp]
  239. mov ebx,DWORD [1096+ebx*4+ebp]
  240. add ebx,eax
  241. mov eax,DWORD [2120+ecx*4+ebp]
  242. xor ebx,eax
  243. mov edx,DWORD [3144+edx*4+ebp]
  244. add ebx,edx
  245. xor eax,eax
  246. xor esi,ebx
  247. ;
  248. ; Round 11
  249. mov edx,DWORD [48+ebp]
  250. mov ebx,esi
  251. xor edi,edx
  252. shr ebx,16
  253. mov edx,esi
  254. mov al,bh
  255. and ebx,255
  256. mov cl,dh
  257. and edx,255
  258. mov eax,DWORD [72+eax*4+ebp]
  259. mov ebx,DWORD [1096+ebx*4+ebp]
  260. add ebx,eax
  261. mov eax,DWORD [2120+ecx*4+ebp]
  262. xor ebx,eax
  263. mov edx,DWORD [3144+edx*4+ebp]
  264. add ebx,edx
  265. xor eax,eax
  266. xor edi,ebx
  267. ;
  268. ; Round 12
  269. mov edx,DWORD [52+ebp]
  270. mov ebx,edi
  271. xor esi,edx
  272. shr ebx,16
  273. mov edx,edi
  274. mov al,bh
  275. and ebx,255
  276. mov cl,dh
  277. and edx,255
  278. mov eax,DWORD [72+eax*4+ebp]
  279. mov ebx,DWORD [1096+ebx*4+ebp]
  280. add ebx,eax
  281. mov eax,DWORD [2120+ecx*4+ebp]
  282. xor ebx,eax
  283. mov edx,DWORD [3144+edx*4+ebp]
  284. add ebx,edx
  285. xor eax,eax
  286. xor esi,ebx
  287. ;
  288. ; Round 13
  289. mov edx,DWORD [56+ebp]
  290. mov ebx,esi
  291. xor edi,edx
  292. shr ebx,16
  293. mov edx,esi
  294. mov al,bh
  295. and ebx,255
  296. mov cl,dh
  297. and edx,255
  298. mov eax,DWORD [72+eax*4+ebp]
  299. mov ebx,DWORD [1096+ebx*4+ebp]
  300. add ebx,eax
  301. mov eax,DWORD [2120+ecx*4+ebp]
  302. xor ebx,eax
  303. mov edx,DWORD [3144+edx*4+ebp]
  304. add ebx,edx
  305. xor eax,eax
  306. xor edi,ebx
  307. ;
  308. ; Round 14
  309. mov edx,DWORD [60+ebp]
  310. mov ebx,edi
  311. xor esi,edx
  312. shr ebx,16
  313. mov edx,edi
  314. mov al,bh
  315. and ebx,255
  316. mov cl,dh
  317. and edx,255
  318. mov eax,DWORD [72+eax*4+ebp]
  319. mov ebx,DWORD [1096+ebx*4+ebp]
  320. add ebx,eax
  321. mov eax,DWORD [2120+ecx*4+ebp]
  322. xor ebx,eax
  323. mov edx,DWORD [3144+edx*4+ebp]
  324. add ebx,edx
  325. xor eax,eax
  326. xor esi,ebx
  327. ;
  328. ; Round 15
  329. mov edx,DWORD [64+ebp]
  330. mov ebx,esi
  331. xor edi,edx
  332. shr ebx,16
  333. mov edx,esi
  334. mov al,bh
  335. and ebx,255
  336. mov cl,dh
  337. and edx,255
  338. mov eax,DWORD [72+eax*4+ebp]
  339. mov ebx,DWORD [1096+ebx*4+ebp]
  340. add ebx,eax
  341. mov eax,DWORD [2120+ecx*4+ebp]
  342. xor ebx,eax
  343. mov edx,DWORD [3144+edx*4+ebp]
  344. add ebx,edx
  345. ; Load parameter 0 (16) enc=1
  346. mov eax,DWORD [20+esp]
  347. xor edi,ebx
  348. mov edx,DWORD [68+ebp]
  349. xor esi,edx
  350. mov DWORD [4+eax],edi
  351. mov DWORD [eax],esi
  352. pop edi
  353. pop esi
  354. pop ebx
  355. pop ebp
  356. ret
  357. global _BF_decrypt
  358. align 16
  359. _BF_decrypt:
  360. L$_BF_decrypt_begin:
  361. ;
  362. push ebp
  363. push ebx
  364. mov ebx,DWORD [12+esp]
  365. mov ebp,DWORD [16+esp]
  366. push esi
  367. push edi
  368. ; Load the 2 words
  369. mov edi,DWORD [ebx]
  370. mov esi,DWORD [4+ebx]
  371. xor eax,eax
  372. mov ebx,DWORD [68+ebp]
  373. xor ecx,ecx
  374. xor edi,ebx
  375. ;
  376. ; Round 16
  377. mov edx,DWORD [64+ebp]
  378. mov ebx,edi
  379. xor esi,edx
  380. shr ebx,16
  381. mov edx,edi
  382. mov al,bh
  383. and ebx,255
  384. mov cl,dh
  385. and edx,255
  386. mov eax,DWORD [72+eax*4+ebp]
  387. mov ebx,DWORD [1096+ebx*4+ebp]
  388. add ebx,eax
  389. mov eax,DWORD [2120+ecx*4+ebp]
  390. xor ebx,eax
  391. mov edx,DWORD [3144+edx*4+ebp]
  392. add ebx,edx
  393. xor eax,eax
  394. xor esi,ebx
  395. ;
  396. ; Round 15
  397. mov edx,DWORD [60+ebp]
  398. mov ebx,esi
  399. xor edi,edx
  400. shr ebx,16
  401. mov edx,esi
  402. mov al,bh
  403. and ebx,255
  404. mov cl,dh
  405. and edx,255
  406. mov eax,DWORD [72+eax*4+ebp]
  407. mov ebx,DWORD [1096+ebx*4+ebp]
  408. add ebx,eax
  409. mov eax,DWORD [2120+ecx*4+ebp]
  410. xor ebx,eax
  411. mov edx,DWORD [3144+edx*4+ebp]
  412. add ebx,edx
  413. xor eax,eax
  414. xor edi,ebx
  415. ;
  416. ; Round 14
  417. mov edx,DWORD [56+ebp]
  418. mov ebx,edi
  419. xor esi,edx
  420. shr ebx,16
  421. mov edx,edi
  422. mov al,bh
  423. and ebx,255
  424. mov cl,dh
  425. and edx,255
  426. mov eax,DWORD [72+eax*4+ebp]
  427. mov ebx,DWORD [1096+ebx*4+ebp]
  428. add ebx,eax
  429. mov eax,DWORD [2120+ecx*4+ebp]
  430. xor ebx,eax
  431. mov edx,DWORD [3144+edx*4+ebp]
  432. add ebx,edx
  433. xor eax,eax
  434. xor esi,ebx
  435. ;
  436. ; Round 13
  437. mov edx,DWORD [52+ebp]
  438. mov ebx,esi
  439. xor edi,edx
  440. shr ebx,16
  441. mov edx,esi
  442. mov al,bh
  443. and ebx,255
  444. mov cl,dh
  445. and edx,255
  446. mov eax,DWORD [72+eax*4+ebp]
  447. mov ebx,DWORD [1096+ebx*4+ebp]
  448. add ebx,eax
  449. mov eax,DWORD [2120+ecx*4+ebp]
  450. xor ebx,eax
  451. mov edx,DWORD [3144+edx*4+ebp]
  452. add ebx,edx
  453. xor eax,eax
  454. xor edi,ebx
  455. ;
  456. ; Round 12
  457. mov edx,DWORD [48+ebp]
  458. mov ebx,edi
  459. xor esi,edx
  460. shr ebx,16
  461. mov edx,edi
  462. mov al,bh
  463. and ebx,255
  464. mov cl,dh
  465. and edx,255
  466. mov eax,DWORD [72+eax*4+ebp]
  467. mov ebx,DWORD [1096+ebx*4+ebp]
  468. add ebx,eax
  469. mov eax,DWORD [2120+ecx*4+ebp]
  470. xor ebx,eax
  471. mov edx,DWORD [3144+edx*4+ebp]
  472. add ebx,edx
  473. xor eax,eax
  474. xor esi,ebx
  475. ;
  476. ; Round 11
  477. mov edx,DWORD [44+ebp]
  478. mov ebx,esi
  479. xor edi,edx
  480. shr ebx,16
  481. mov edx,esi
  482. mov al,bh
  483. and ebx,255
  484. mov cl,dh
  485. and edx,255
  486. mov eax,DWORD [72+eax*4+ebp]
  487. mov ebx,DWORD [1096+ebx*4+ebp]
  488. add ebx,eax
  489. mov eax,DWORD [2120+ecx*4+ebp]
  490. xor ebx,eax
  491. mov edx,DWORD [3144+edx*4+ebp]
  492. add ebx,edx
  493. xor eax,eax
  494. xor edi,ebx
  495. ;
  496. ; Round 10
  497. mov edx,DWORD [40+ebp]
  498. mov ebx,edi
  499. xor esi,edx
  500. shr ebx,16
  501. mov edx,edi
  502. mov al,bh
  503. and ebx,255
  504. mov cl,dh
  505. and edx,255
  506. mov eax,DWORD [72+eax*4+ebp]
  507. mov ebx,DWORD [1096+ebx*4+ebp]
  508. add ebx,eax
  509. mov eax,DWORD [2120+ecx*4+ebp]
  510. xor ebx,eax
  511. mov edx,DWORD [3144+edx*4+ebp]
  512. add ebx,edx
  513. xor eax,eax
  514. xor esi,ebx
  515. ;
  516. ; Round 9
  517. mov edx,DWORD [36+ebp]
  518. mov ebx,esi
  519. xor edi,edx
  520. shr ebx,16
  521. mov edx,esi
  522. mov al,bh
  523. and ebx,255
  524. mov cl,dh
  525. and edx,255
  526. mov eax,DWORD [72+eax*4+ebp]
  527. mov ebx,DWORD [1096+ebx*4+ebp]
  528. add ebx,eax
  529. mov eax,DWORD [2120+ecx*4+ebp]
  530. xor ebx,eax
  531. mov edx,DWORD [3144+edx*4+ebp]
  532. add ebx,edx
  533. xor eax,eax
  534. xor edi,ebx
  535. ;
  536. ; Round 8
  537. mov edx,DWORD [32+ebp]
  538. mov ebx,edi
  539. xor esi,edx
  540. shr ebx,16
  541. mov edx,edi
  542. mov al,bh
  543. and ebx,255
  544. mov cl,dh
  545. and edx,255
  546. mov eax,DWORD [72+eax*4+ebp]
  547. mov ebx,DWORD [1096+ebx*4+ebp]
  548. add ebx,eax
  549. mov eax,DWORD [2120+ecx*4+ebp]
  550. xor ebx,eax
  551. mov edx,DWORD [3144+edx*4+ebp]
  552. add ebx,edx
  553. xor eax,eax
  554. xor esi,ebx
  555. ;
  556. ; Round 7
  557. mov edx,DWORD [28+ebp]
  558. mov ebx,esi
  559. xor edi,edx
  560. shr ebx,16
  561. mov edx,esi
  562. mov al,bh
  563. and ebx,255
  564. mov cl,dh
  565. and edx,255
  566. mov eax,DWORD [72+eax*4+ebp]
  567. mov ebx,DWORD [1096+ebx*4+ebp]
  568. add ebx,eax
  569. mov eax,DWORD [2120+ecx*4+ebp]
  570. xor ebx,eax
  571. mov edx,DWORD [3144+edx*4+ebp]
  572. add ebx,edx
  573. xor eax,eax
  574. xor edi,ebx
  575. ;
  576. ; Round 6
  577. mov edx,DWORD [24+ebp]
  578. mov ebx,edi
  579. xor esi,edx
  580. shr ebx,16
  581. mov edx,edi
  582. mov al,bh
  583. and ebx,255
  584. mov cl,dh
  585. and edx,255
  586. mov eax,DWORD [72+eax*4+ebp]
  587. mov ebx,DWORD [1096+ebx*4+ebp]
  588. add ebx,eax
  589. mov eax,DWORD [2120+ecx*4+ebp]
  590. xor ebx,eax
  591. mov edx,DWORD [3144+edx*4+ebp]
  592. add ebx,edx
  593. xor eax,eax
  594. xor esi,ebx
  595. ;
  596. ; Round 5
  597. mov edx,DWORD [20+ebp]
  598. mov ebx,esi
  599. xor edi,edx
  600. shr ebx,16
  601. mov edx,esi
  602. mov al,bh
  603. and ebx,255
  604. mov cl,dh
  605. and edx,255
  606. mov eax,DWORD [72+eax*4+ebp]
  607. mov ebx,DWORD [1096+ebx*4+ebp]
  608. add ebx,eax
  609. mov eax,DWORD [2120+ecx*4+ebp]
  610. xor ebx,eax
  611. mov edx,DWORD [3144+edx*4+ebp]
  612. add ebx,edx
  613. xor eax,eax
  614. xor edi,ebx
  615. ;
  616. ; Round 4
  617. mov edx,DWORD [16+ebp]
  618. mov ebx,edi
  619. xor esi,edx
  620. shr ebx,16
  621. mov edx,edi
  622. mov al,bh
  623. and ebx,255
  624. mov cl,dh
  625. and edx,255
  626. mov eax,DWORD [72+eax*4+ebp]
  627. mov ebx,DWORD [1096+ebx*4+ebp]
  628. add ebx,eax
  629. mov eax,DWORD [2120+ecx*4+ebp]
  630. xor ebx,eax
  631. mov edx,DWORD [3144+edx*4+ebp]
  632. add ebx,edx
  633. xor eax,eax
  634. xor esi,ebx
  635. ;
  636. ; Round 3
  637. mov edx,DWORD [12+ebp]
  638. mov ebx,esi
  639. xor edi,edx
  640. shr ebx,16
  641. mov edx,esi
  642. mov al,bh
  643. and ebx,255
  644. mov cl,dh
  645. and edx,255
  646. mov eax,DWORD [72+eax*4+ebp]
  647. mov ebx,DWORD [1096+ebx*4+ebp]
  648. add ebx,eax
  649. mov eax,DWORD [2120+ecx*4+ebp]
  650. xor ebx,eax
  651. mov edx,DWORD [3144+edx*4+ebp]
  652. add ebx,edx
  653. xor eax,eax
  654. xor edi,ebx
  655. ;
  656. ; Round 2
  657. mov edx,DWORD [8+ebp]
  658. mov ebx,edi
  659. xor esi,edx
  660. shr ebx,16
  661. mov edx,edi
  662. mov al,bh
  663. and ebx,255
  664. mov cl,dh
  665. and edx,255
  666. mov eax,DWORD [72+eax*4+ebp]
  667. mov ebx,DWORD [1096+ebx*4+ebp]
  668. add ebx,eax
  669. mov eax,DWORD [2120+ecx*4+ebp]
  670. xor ebx,eax
  671. mov edx,DWORD [3144+edx*4+ebp]
  672. add ebx,edx
  673. xor eax,eax
  674. xor esi,ebx
  675. ;
  676. ; Round 1
  677. mov edx,DWORD [4+ebp]
  678. mov ebx,esi
  679. xor edi,edx
  680. shr ebx,16
  681. mov edx,esi
  682. mov al,bh
  683. and ebx,255
  684. mov cl,dh
  685. and edx,255
  686. mov eax,DWORD [72+eax*4+ebp]
  687. mov ebx,DWORD [1096+ebx*4+ebp]
  688. add ebx,eax
  689. mov eax,DWORD [2120+ecx*4+ebp]
  690. xor ebx,eax
  691. mov edx,DWORD [3144+edx*4+ebp]
  692. add ebx,edx
  693. ; Load parameter 0 (1) enc=0
  694. mov eax,DWORD [20+esp]
  695. xor edi,ebx
  696. mov edx,DWORD [ebp]
  697. xor esi,edx
  698. mov DWORD [4+eax],edi
  699. mov DWORD [eax],esi
  700. pop edi
  701. pop esi
  702. pop ebx
  703. pop ebp
  704. ret
  705. global _BF_cbc_encrypt
  706. align 16
  707. _BF_cbc_encrypt:
  708. L$_BF_cbc_encrypt_begin:
  709. ;
  710. push ebp
  711. push ebx
  712. push esi
  713. push edi
  714. mov ebp,DWORD [28+esp]
  715. ; getting iv ptr from parameter 4
  716. mov ebx,DWORD [36+esp]
  717. mov esi,DWORD [ebx]
  718. mov edi,DWORD [4+ebx]
  719. push edi
  720. push esi
  721. push edi
  722. push esi
  723. mov ebx,esp
  724. mov esi,DWORD [36+esp]
  725. mov edi,DWORD [40+esp]
  726. ; getting encrypt flag from parameter 5
  727. mov ecx,DWORD [56+esp]
  728. ; get and push parameter 3
  729. mov eax,DWORD [48+esp]
  730. push eax
  731. push ebx
  732. cmp ecx,0
  733. jz NEAR L$000decrypt
  734. and ebp,4294967288
  735. mov eax,DWORD [8+esp]
  736. mov ebx,DWORD [12+esp]
  737. jz NEAR L$001encrypt_finish
  738. L$002encrypt_loop:
  739. mov ecx,DWORD [esi]
  740. mov edx,DWORD [4+esi]
  741. xor eax,ecx
  742. xor ebx,edx
  743. bswap eax
  744. bswap ebx
  745. mov DWORD [8+esp],eax
  746. mov DWORD [12+esp],ebx
  747. call L$_BF_encrypt_begin
  748. mov eax,DWORD [8+esp]
  749. mov ebx,DWORD [12+esp]
  750. bswap eax
  751. bswap ebx
  752. mov DWORD [edi],eax
  753. mov DWORD [4+edi],ebx
  754. add esi,8
  755. add edi,8
  756. sub ebp,8
  757. jnz NEAR L$002encrypt_loop
  758. L$001encrypt_finish:
  759. mov ebp,DWORD [52+esp]
  760. and ebp,7
  761. jz NEAR L$003finish
  762. call L$004PIC_point
  763. L$004PIC_point:
  764. pop edx
  765. lea ecx,[(L$005cbc_enc_jmp_table-L$004PIC_point)+edx]
  766. mov ebp,DWORD [ebp*4+ecx]
  767. add ebp,edx
  768. xor ecx,ecx
  769. xor edx,edx
  770. jmp ebp
  771. L$006ej7:
  772. mov dh,BYTE [6+esi]
  773. shl edx,8
  774. L$007ej6:
  775. mov dh,BYTE [5+esi]
  776. L$008ej5:
  777. mov dl,BYTE [4+esi]
  778. L$009ej4:
  779. mov ecx,DWORD [esi]
  780. jmp NEAR L$010ejend
  781. L$011ej3:
  782. mov ch,BYTE [2+esi]
  783. shl ecx,8
  784. L$012ej2:
  785. mov ch,BYTE [1+esi]
  786. L$013ej1:
  787. mov cl,BYTE [esi]
  788. L$010ejend:
  789. xor eax,ecx
  790. xor ebx,edx
  791. bswap eax
  792. bswap ebx
  793. mov DWORD [8+esp],eax
  794. mov DWORD [12+esp],ebx
  795. call L$_BF_encrypt_begin
  796. mov eax,DWORD [8+esp]
  797. mov ebx,DWORD [12+esp]
  798. bswap eax
  799. bswap ebx
  800. mov DWORD [edi],eax
  801. mov DWORD [4+edi],ebx
  802. jmp NEAR L$003finish
  803. L$000decrypt:
  804. and ebp,4294967288
  805. mov eax,DWORD [16+esp]
  806. mov ebx,DWORD [20+esp]
  807. jz NEAR L$014decrypt_finish
  808. L$015decrypt_loop:
  809. mov eax,DWORD [esi]
  810. mov ebx,DWORD [4+esi]
  811. bswap eax
  812. bswap ebx
  813. mov DWORD [8+esp],eax
  814. mov DWORD [12+esp],ebx
  815. call L$_BF_decrypt_begin
  816. mov eax,DWORD [8+esp]
  817. mov ebx,DWORD [12+esp]
  818. bswap eax
  819. bswap ebx
  820. mov ecx,DWORD [16+esp]
  821. mov edx,DWORD [20+esp]
  822. xor ecx,eax
  823. xor edx,ebx
  824. mov eax,DWORD [esi]
  825. mov ebx,DWORD [4+esi]
  826. mov DWORD [edi],ecx
  827. mov DWORD [4+edi],edx
  828. mov DWORD [16+esp],eax
  829. mov DWORD [20+esp],ebx
  830. add esi,8
  831. add edi,8
  832. sub ebp,8
  833. jnz NEAR L$015decrypt_loop
  834. L$014decrypt_finish:
  835. mov ebp,DWORD [52+esp]
  836. and ebp,7
  837. jz NEAR L$003finish
  838. mov eax,DWORD [esi]
  839. mov ebx,DWORD [4+esi]
  840. bswap eax
  841. bswap ebx
  842. mov DWORD [8+esp],eax
  843. mov DWORD [12+esp],ebx
  844. call L$_BF_decrypt_begin
  845. mov eax,DWORD [8+esp]
  846. mov ebx,DWORD [12+esp]
  847. bswap eax
  848. bswap ebx
  849. mov ecx,DWORD [16+esp]
  850. mov edx,DWORD [20+esp]
  851. xor ecx,eax
  852. xor edx,ebx
  853. mov eax,DWORD [esi]
  854. mov ebx,DWORD [4+esi]
  855. L$016dj7:
  856. ror edx,16
  857. mov BYTE [6+edi],dl
  858. shr edx,16
  859. L$017dj6:
  860. mov BYTE [5+edi],dh
  861. L$018dj5:
  862. mov BYTE [4+edi],dl
  863. L$019dj4:
  864. mov DWORD [edi],ecx
  865. jmp NEAR L$020djend
  866. L$021dj3:
  867. ror ecx,16
  868. mov BYTE [2+edi],cl
  869. shl ecx,16
  870. L$022dj2:
  871. mov BYTE [1+esi],ch
  872. L$023dj1:
  873. mov BYTE [esi],cl
  874. L$020djend:
  875. jmp NEAR L$003finish
  876. L$003finish:
  877. mov ecx,DWORD [60+esp]
  878. add esp,24
  879. mov DWORD [ecx],eax
  880. mov DWORD [4+ecx],ebx
  881. pop edi
  882. pop esi
  883. pop ebx
  884. pop ebp
  885. ret
  886. align 64
  887. L$005cbc_enc_jmp_table:
  888. dd 0
  889. dd L$013ej1-L$004PIC_point
  890. dd L$012ej2-L$004PIC_point
  891. dd L$011ej3-L$004PIC_point
  892. dd L$009ej4-L$004PIC_point
  893. dd L$008ej5-L$004PIC_point
  894. dd L$007ej6-L$004PIC_point
  895. dd L$006ej7-L$004PIC_point
  896. align 64