des_asm.S 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. #include <linux/linkage.h>
  2. #include <asm/visasm.h>
  3. #include "opcodes.h"
  4. .align 32
  5. ENTRY(des_sparc64_key_expand)
  6. /* %o0=input_key, %o1=output_key */
  7. VISEntryHalf
  8. ld [%o0 + 0x00], %f0
  9. ld [%o0 + 0x04], %f1
  10. DES_KEXPAND(0, 0, 0)
  11. DES_KEXPAND(0, 1, 2)
  12. DES_KEXPAND(2, 3, 6)
  13. DES_KEXPAND(2, 2, 4)
  14. DES_KEXPAND(6, 3, 10)
  15. DES_KEXPAND(6, 2, 8)
  16. DES_KEXPAND(10, 3, 14)
  17. DES_KEXPAND(10, 2, 12)
  18. DES_KEXPAND(14, 1, 16)
  19. DES_KEXPAND(16, 3, 20)
  20. DES_KEXPAND(16, 2, 18)
  21. DES_KEXPAND(20, 3, 24)
  22. DES_KEXPAND(20, 2, 22)
  23. DES_KEXPAND(24, 3, 28)
  24. DES_KEXPAND(24, 2, 26)
  25. DES_KEXPAND(28, 1, 30)
  26. std %f0, [%o1 + 0x00]
  27. std %f2, [%o1 + 0x08]
  28. std %f4, [%o1 + 0x10]
  29. std %f6, [%o1 + 0x18]
  30. std %f8, [%o1 + 0x20]
  31. std %f10, [%o1 + 0x28]
  32. std %f12, [%o1 + 0x30]
  33. std %f14, [%o1 + 0x38]
  34. std %f16, [%o1 + 0x40]
  35. std %f18, [%o1 + 0x48]
  36. std %f20, [%o1 + 0x50]
  37. std %f22, [%o1 + 0x58]
  38. std %f24, [%o1 + 0x60]
  39. std %f26, [%o1 + 0x68]
  40. std %f28, [%o1 + 0x70]
  41. std %f30, [%o1 + 0x78]
  42. retl
  43. VISExitHalf
  44. ENDPROC(des_sparc64_key_expand)
  45. .align 32
  46. ENTRY(des_sparc64_crypt)
  47. /* %o0=key, %o1=input, %o2=output */
  48. VISEntry
  49. ldd [%o1 + 0x00], %f32
  50. ldd [%o0 + 0x00], %f0
  51. ldd [%o0 + 0x08], %f2
  52. ldd [%o0 + 0x10], %f4
  53. ldd [%o0 + 0x18], %f6
  54. ldd [%o0 + 0x20], %f8
  55. ldd [%o0 + 0x28], %f10
  56. ldd [%o0 + 0x30], %f12
  57. ldd [%o0 + 0x38], %f14
  58. ldd [%o0 + 0x40], %f16
  59. ldd [%o0 + 0x48], %f18
  60. ldd [%o0 + 0x50], %f20
  61. ldd [%o0 + 0x58], %f22
  62. ldd [%o0 + 0x60], %f24
  63. ldd [%o0 + 0x68], %f26
  64. ldd [%o0 + 0x70], %f28
  65. ldd [%o0 + 0x78], %f30
  66. DES_IP(32, 32)
  67. DES_ROUND(0, 2, 32, 32)
  68. DES_ROUND(4, 6, 32, 32)
  69. DES_ROUND(8, 10, 32, 32)
  70. DES_ROUND(12, 14, 32, 32)
  71. DES_ROUND(16, 18, 32, 32)
  72. DES_ROUND(20, 22, 32, 32)
  73. DES_ROUND(24, 26, 32, 32)
  74. DES_ROUND(28, 30, 32, 32)
  75. DES_IIP(32, 32)
  76. std %f32, [%o2 + 0x00]
  77. retl
  78. VISExit
  79. ENDPROC(des_sparc64_crypt)
  80. .align 32
  81. ENTRY(des_sparc64_load_keys)
  82. /* %o0=key */
  83. VISEntry
  84. ldd [%o0 + 0x00], %f0
  85. ldd [%o0 + 0x08], %f2
  86. ldd [%o0 + 0x10], %f4
  87. ldd [%o0 + 0x18], %f6
  88. ldd [%o0 + 0x20], %f8
  89. ldd [%o0 + 0x28], %f10
  90. ldd [%o0 + 0x30], %f12
  91. ldd [%o0 + 0x38], %f14
  92. ldd [%o0 + 0x40], %f16
  93. ldd [%o0 + 0x48], %f18
  94. ldd [%o0 + 0x50], %f20
  95. ldd [%o0 + 0x58], %f22
  96. ldd [%o0 + 0x60], %f24
  97. ldd [%o0 + 0x68], %f26
  98. ldd [%o0 + 0x70], %f28
  99. retl
  100. ldd [%o0 + 0x78], %f30
  101. ENDPROC(des_sparc64_load_keys)
  102. .align 32
  103. ENTRY(des_sparc64_ecb_crypt)
  104. /* %o0=input, %o1=output, %o2=len */
  105. 1: ldd [%o0 + 0x00], %f32
  106. add %o0, 0x08, %o0
  107. DES_IP(32, 32)
  108. DES_ROUND(0, 2, 32, 32)
  109. DES_ROUND(4, 6, 32, 32)
  110. DES_ROUND(8, 10, 32, 32)
  111. DES_ROUND(12, 14, 32, 32)
  112. DES_ROUND(16, 18, 32, 32)
  113. DES_ROUND(20, 22, 32, 32)
  114. DES_ROUND(24, 26, 32, 32)
  115. DES_ROUND(28, 30, 32, 32)
  116. DES_IIP(32, 32)
  117. std %f32, [%o1 + 0x00]
  118. subcc %o2, 0x08, %o2
  119. bne,pt %icc, 1b
  120. add %o1, 0x08, %o1
  121. retl
  122. nop
  123. ENDPROC(des_sparc64_ecb_crypt)
  124. .align 32
  125. ENTRY(des_sparc64_cbc_encrypt)
  126. /* %o0=input, %o1=output, %o2=len, %o3=IV */
  127. ldd [%o3 + 0x00], %f32
  128. 1: ldd [%o0 + 0x00], %f34
  129. fxor %f32, %f34, %f32
  130. DES_IP(32, 32)
  131. DES_ROUND(0, 2, 32, 32)
  132. DES_ROUND(4, 6, 32, 32)
  133. DES_ROUND(8, 10, 32, 32)
  134. DES_ROUND(12, 14, 32, 32)
  135. DES_ROUND(16, 18, 32, 32)
  136. DES_ROUND(20, 22, 32, 32)
  137. DES_ROUND(24, 26, 32, 32)
  138. DES_ROUND(28, 30, 32, 32)
  139. DES_IIP(32, 32)
  140. std %f32, [%o1 + 0x00]
  141. add %o0, 0x08, %o0
  142. subcc %o2, 0x08, %o2
  143. bne,pt %icc, 1b
  144. add %o1, 0x08, %o1
  145. retl
  146. std %f32, [%o3 + 0x00]
  147. ENDPROC(des_sparc64_cbc_encrypt)
  148. .align 32
  149. ENTRY(des_sparc64_cbc_decrypt)
  150. /* %o0=input, %o1=output, %o2=len, %o3=IV */
  151. ldd [%o3 + 0x00], %f34
  152. 1: ldd [%o0 + 0x00], %f36
  153. DES_IP(36, 32)
  154. DES_ROUND(0, 2, 32, 32)
  155. DES_ROUND(4, 6, 32, 32)
  156. DES_ROUND(8, 10, 32, 32)
  157. DES_ROUND(12, 14, 32, 32)
  158. DES_ROUND(16, 18, 32, 32)
  159. DES_ROUND(20, 22, 32, 32)
  160. DES_ROUND(24, 26, 32, 32)
  161. DES_ROUND(28, 30, 32, 32)
  162. DES_IIP(32, 32)
  163. fxor %f32, %f34, %f32
  164. fsrc2 %f36, %f34
  165. std %f32, [%o1 + 0x00]
  166. add %o0, 0x08, %o0
  167. subcc %o2, 0x08, %o2
  168. bne,pt %icc, 1b
  169. add %o1, 0x08, %o1
  170. retl
  171. std %f36, [%o3 + 0x00]
  172. ENDPROC(des_sparc64_cbc_decrypt)
  173. .align 32
  174. ENTRY(des3_ede_sparc64_crypt)
  175. /* %o0=key, %o1=input, %o2=output */
  176. VISEntry
  177. ldd [%o1 + 0x00], %f32
  178. ldd [%o0 + 0x00], %f0
  179. ldd [%o0 + 0x08], %f2
  180. ldd [%o0 + 0x10], %f4
  181. ldd [%o0 + 0x18], %f6
  182. ldd [%o0 + 0x20], %f8
  183. ldd [%o0 + 0x28], %f10
  184. ldd [%o0 + 0x30], %f12
  185. ldd [%o0 + 0x38], %f14
  186. ldd [%o0 + 0x40], %f16
  187. ldd [%o0 + 0x48], %f18
  188. ldd [%o0 + 0x50], %f20
  189. ldd [%o0 + 0x58], %f22
  190. ldd [%o0 + 0x60], %f24
  191. ldd [%o0 + 0x68], %f26
  192. ldd [%o0 + 0x70], %f28
  193. ldd [%o0 + 0x78], %f30
  194. DES_IP(32, 32)
  195. DES_ROUND(0, 2, 32, 32)
  196. ldd [%o0 + 0x80], %f0
  197. ldd [%o0 + 0x88], %f2
  198. DES_ROUND(4, 6, 32, 32)
  199. ldd [%o0 + 0x90], %f4
  200. ldd [%o0 + 0x98], %f6
  201. DES_ROUND(8, 10, 32, 32)
  202. ldd [%o0 + 0xa0], %f8
  203. ldd [%o0 + 0xa8], %f10
  204. DES_ROUND(12, 14, 32, 32)
  205. ldd [%o0 + 0xb0], %f12
  206. ldd [%o0 + 0xb8], %f14
  207. DES_ROUND(16, 18, 32, 32)
  208. ldd [%o0 + 0xc0], %f16
  209. ldd [%o0 + 0xc8], %f18
  210. DES_ROUND(20, 22, 32, 32)
  211. ldd [%o0 + 0xd0], %f20
  212. ldd [%o0 + 0xd8], %f22
  213. DES_ROUND(24, 26, 32, 32)
  214. ldd [%o0 + 0xe0], %f24
  215. ldd [%o0 + 0xe8], %f26
  216. DES_ROUND(28, 30, 32, 32)
  217. ldd [%o0 + 0xf0], %f28
  218. ldd [%o0 + 0xf8], %f30
  219. DES_IIP(32, 32)
  220. DES_IP(32, 32)
  221. DES_ROUND(0, 2, 32, 32)
  222. ldd [%o0 + 0x100], %f0
  223. ldd [%o0 + 0x108], %f2
  224. DES_ROUND(4, 6, 32, 32)
  225. ldd [%o0 + 0x110], %f4
  226. ldd [%o0 + 0x118], %f6
  227. DES_ROUND(8, 10, 32, 32)
  228. ldd [%o0 + 0x120], %f8
  229. ldd [%o0 + 0x128], %f10
  230. DES_ROUND(12, 14, 32, 32)
  231. ldd [%o0 + 0x130], %f12
  232. ldd [%o0 + 0x138], %f14
  233. DES_ROUND(16, 18, 32, 32)
  234. ldd [%o0 + 0x140], %f16
  235. ldd [%o0 + 0x148], %f18
  236. DES_ROUND(20, 22, 32, 32)
  237. ldd [%o0 + 0x150], %f20
  238. ldd [%o0 + 0x158], %f22
  239. DES_ROUND(24, 26, 32, 32)
  240. ldd [%o0 + 0x160], %f24
  241. ldd [%o0 + 0x168], %f26
  242. DES_ROUND(28, 30, 32, 32)
  243. ldd [%o0 + 0x170], %f28
  244. ldd [%o0 + 0x178], %f30
  245. DES_IIP(32, 32)
  246. DES_IP(32, 32)
  247. DES_ROUND(0, 2, 32, 32)
  248. DES_ROUND(4, 6, 32, 32)
  249. DES_ROUND(8, 10, 32, 32)
  250. DES_ROUND(12, 14, 32, 32)
  251. DES_ROUND(16, 18, 32, 32)
  252. DES_ROUND(20, 22, 32, 32)
  253. DES_ROUND(24, 26, 32, 32)
  254. DES_ROUND(28, 30, 32, 32)
  255. DES_IIP(32, 32)
  256. std %f32, [%o2 + 0x00]
  257. retl
  258. VISExit
  259. ENDPROC(des3_ede_sparc64_crypt)
  260. .align 32
  261. ENTRY(des3_ede_sparc64_load_keys)
  262. /* %o0=key */
  263. VISEntry
  264. ldd [%o0 + 0x00], %f0
  265. ldd [%o0 + 0x08], %f2
  266. ldd [%o0 + 0x10], %f4
  267. ldd [%o0 + 0x18], %f6
  268. ldd [%o0 + 0x20], %f8
  269. ldd [%o0 + 0x28], %f10
  270. ldd [%o0 + 0x30], %f12
  271. ldd [%o0 + 0x38], %f14
  272. ldd [%o0 + 0x40], %f16
  273. ldd [%o0 + 0x48], %f18
  274. ldd [%o0 + 0x50], %f20
  275. ldd [%o0 + 0x58], %f22
  276. ldd [%o0 + 0x60], %f24
  277. ldd [%o0 + 0x68], %f26
  278. ldd [%o0 + 0x70], %f28
  279. ldd [%o0 + 0x78], %f30
  280. ldd [%o0 + 0x80], %f32
  281. ldd [%o0 + 0x88], %f34
  282. ldd [%o0 + 0x90], %f36
  283. ldd [%o0 + 0x98], %f38
  284. ldd [%o0 + 0xa0], %f40
  285. ldd [%o0 + 0xa8], %f42
  286. ldd [%o0 + 0xb0], %f44
  287. ldd [%o0 + 0xb8], %f46
  288. ldd [%o0 + 0xc0], %f48
  289. ldd [%o0 + 0xc8], %f50
  290. ldd [%o0 + 0xd0], %f52
  291. ldd [%o0 + 0xd8], %f54
  292. ldd [%o0 + 0xe0], %f56
  293. retl
  294. ldd [%o0 + 0xe8], %f58
  295. ENDPROC(des3_ede_sparc64_load_keys)
  296. #define DES3_LOOP_BODY(X) \
  297. DES_IP(X, X) \
  298. DES_ROUND(0, 2, X, X) \
  299. DES_ROUND(4, 6, X, X) \
  300. DES_ROUND(8, 10, X, X) \
  301. DES_ROUND(12, 14, X, X) \
  302. DES_ROUND(16, 18, X, X) \
  303. ldd [%o0 + 0xf0], %f16; \
  304. ldd [%o0 + 0xf8], %f18; \
  305. DES_ROUND(20, 22, X, X) \
  306. ldd [%o0 + 0x100], %f20; \
  307. ldd [%o0 + 0x108], %f22; \
  308. DES_ROUND(24, 26, X, X) \
  309. ldd [%o0 + 0x110], %f24; \
  310. ldd [%o0 + 0x118], %f26; \
  311. DES_ROUND(28, 30, X, X) \
  312. ldd [%o0 + 0x120], %f28; \
  313. ldd [%o0 + 0x128], %f30; \
  314. DES_IIP(X, X) \
  315. DES_IP(X, X) \
  316. DES_ROUND(32, 34, X, X) \
  317. ldd [%o0 + 0x130], %f0; \
  318. ldd [%o0 + 0x138], %f2; \
  319. DES_ROUND(36, 38, X, X) \
  320. ldd [%o0 + 0x140], %f4; \
  321. ldd [%o0 + 0x148], %f6; \
  322. DES_ROUND(40, 42, X, X) \
  323. ldd [%o0 + 0x150], %f8; \
  324. ldd [%o0 + 0x158], %f10; \
  325. DES_ROUND(44, 46, X, X) \
  326. ldd [%o0 + 0x160], %f12; \
  327. ldd [%o0 + 0x168], %f14; \
  328. DES_ROUND(48, 50, X, X) \
  329. DES_ROUND(52, 54, X, X) \
  330. DES_ROUND(56, 58, X, X) \
  331. DES_ROUND(16, 18, X, X) \
  332. ldd [%o0 + 0x170], %f16; \
  333. ldd [%o0 + 0x178], %f18; \
  334. DES_IIP(X, X) \
  335. DES_IP(X, X) \
  336. DES_ROUND(20, 22, X, X) \
  337. ldd [%o0 + 0x50], %f20; \
  338. ldd [%o0 + 0x58], %f22; \
  339. DES_ROUND(24, 26, X, X) \
  340. ldd [%o0 + 0x60], %f24; \
  341. ldd [%o0 + 0x68], %f26; \
  342. DES_ROUND(28, 30, X, X) \
  343. ldd [%o0 + 0x70], %f28; \
  344. ldd [%o0 + 0x78], %f30; \
  345. DES_ROUND(0, 2, X, X) \
  346. ldd [%o0 + 0x00], %f0; \
  347. ldd [%o0 + 0x08], %f2; \
  348. DES_ROUND(4, 6, X, X) \
  349. ldd [%o0 + 0x10], %f4; \
  350. ldd [%o0 + 0x18], %f6; \
  351. DES_ROUND(8, 10, X, X) \
  352. ldd [%o0 + 0x20], %f8; \
  353. ldd [%o0 + 0x28], %f10; \
  354. DES_ROUND(12, 14, X, X) \
  355. ldd [%o0 + 0x30], %f12; \
  356. ldd [%o0 + 0x38], %f14; \
  357. DES_ROUND(16, 18, X, X) \
  358. ldd [%o0 + 0x40], %f16; \
  359. ldd [%o0 + 0x48], %f18; \
  360. DES_IIP(X, X)
  361. .align 32
  362. ENTRY(des3_ede_sparc64_ecb_crypt)
  363. /* %o0=key, %o1=input, %o2=output, %o3=len */
  364. 1: ldd [%o1 + 0x00], %f60
  365. DES3_LOOP_BODY(60)
  366. std %f60, [%o2 + 0x00]
  367. add %o1, 0x08, %o1
  368. subcc %o3, 0x08, %o3
  369. bne,pt %icc, 1b
  370. add %o2, 0x08, %o2
  371. retl
  372. nop
  373. ENDPROC(des3_ede_sparc64_ecb_crypt)
  374. .align 32
  375. ENTRY(des3_ede_sparc64_cbc_encrypt)
  376. /* %o0=key, %o1=input, %o2=output, %o3=len, %o4=IV */
  377. ldd [%o4 + 0x00], %f60
  378. 1: ldd [%o1 + 0x00], %f62
  379. fxor %f60, %f62, %f60
  380. DES3_LOOP_BODY(60)
  381. std %f60, [%o2 + 0x00]
  382. add %o1, 0x08, %o1
  383. subcc %o3, 0x08, %o3
  384. bne,pt %icc, 1b
  385. add %o2, 0x08, %o2
  386. retl
  387. std %f60, [%o4 + 0x00]
  388. ENDPROC(des3_ede_sparc64_cbc_encrypt)
  389. .align 32
  390. ENTRY(des3_ede_sparc64_cbc_decrypt)
  391. /* %o0=key, %o1=input, %o2=output, %o3=len, %o4=IV */
  392. ldd [%o4 + 0x00], %f62
  393. 1: ldx [%o1 + 0x00], %g1
  394. MOVXTOD_G1_F60
  395. DES3_LOOP_BODY(60)
  396. fxor %f62, %f60, %f60
  397. MOVXTOD_G1_F62
  398. std %f60, [%o2 + 0x00]
  399. add %o1, 0x08, %o1
  400. subcc %o3, 0x08, %o3
  401. bne,pt %icc, 1b
  402. add %o2, 0x08, %o2
  403. retl
  404. stx %g1, [%o4 + 0x00]
  405. ENDPROC(des3_ede_sparc64_cbc_decrypt)