des_asm.S 9.4 KB

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