ghashv8-armx.S 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. #include "arm_arch.h"
  2. #if __ARM_MAX_ARCH__>=7
  3. .text
  4. .arch armv8-a+crypto
  5. .globl gcm_init_v8
  6. .type gcm_init_v8,%function
  7. .align 4
  8. gcm_init_v8:
  9. ld1 {v17.2d},[x1] //load input H
  10. movi v19.16b,#0xe1
  11. shl v19.2d,v19.2d,#57 //0xc2.0
  12. ext v3.16b,v17.16b,v17.16b,#8
  13. ushr v18.2d,v19.2d,#63
  14. dup v17.4s,v17.s[1]
  15. ext v16.16b,v18.16b,v19.16b,#8 //t0=0xc2....01
  16. ushr v18.2d,v3.2d,#63
  17. sshr v17.4s,v17.4s,#31 //broadcast carry bit
  18. and v18.16b,v18.16b,v16.16b
  19. shl v3.2d,v3.2d,#1
  20. ext v18.16b,v18.16b,v18.16b,#8
  21. and v16.16b,v16.16b,v17.16b
  22. orr v3.16b,v3.16b,v18.16b //H<<<=1
  23. eor v20.16b,v3.16b,v16.16b //twisted H
  24. st1 {v20.2d},[x0],#16 //store Htable[0]
  25. //calculate H^2
  26. ext v16.16b,v20.16b,v20.16b,#8 //Karatsuba pre-processing
  27. pmull v0.1q,v20.1d,v20.1d
  28. eor v16.16b,v16.16b,v20.16b
  29. pmull2 v2.1q,v20.2d,v20.2d
  30. pmull v1.1q,v16.1d,v16.1d
  31. ext v17.16b,v0.16b,v2.16b,#8 //Karatsuba post-processing
  32. eor v18.16b,v0.16b,v2.16b
  33. eor v1.16b,v1.16b,v17.16b
  34. eor v1.16b,v1.16b,v18.16b
  35. pmull v18.1q,v0.1d,v19.1d //1st phase
  36. ins v2.d[0],v1.d[1]
  37. ins v1.d[1],v0.d[0]
  38. eor v0.16b,v1.16b,v18.16b
  39. ext v18.16b,v0.16b,v0.16b,#8 //2nd phase
  40. pmull v0.1q,v0.1d,v19.1d
  41. eor v18.16b,v18.16b,v2.16b
  42. eor v22.16b,v0.16b,v18.16b
  43. ext v17.16b,v22.16b,v22.16b,#8 //Karatsuba pre-processing
  44. eor v17.16b,v17.16b,v22.16b
  45. ext v21.16b,v16.16b,v17.16b,#8 //pack Karatsuba pre-processed
  46. st1 {v21.2d,v22.2d},[x0],#32 //store Htable[1..2]
  47. //calculate H^3 and H^4
  48. pmull v0.1q,v20.1d, v22.1d
  49. pmull v5.1q,v22.1d,v22.1d
  50. pmull2 v2.1q,v20.2d, v22.2d
  51. pmull2 v7.1q,v22.2d,v22.2d
  52. pmull v1.1q,v16.1d,v17.1d
  53. pmull v6.1q,v17.1d,v17.1d
  54. ext v16.16b,v0.16b,v2.16b,#8 //Karatsuba post-processing
  55. ext v17.16b,v5.16b,v7.16b,#8
  56. eor v18.16b,v0.16b,v2.16b
  57. eor v1.16b,v1.16b,v16.16b
  58. eor v4.16b,v5.16b,v7.16b
  59. eor v6.16b,v6.16b,v17.16b
  60. eor v1.16b,v1.16b,v18.16b
  61. pmull v18.1q,v0.1d,v19.1d //1st phase
  62. eor v6.16b,v6.16b,v4.16b
  63. pmull v4.1q,v5.1d,v19.1d
  64. ins v2.d[0],v1.d[1]
  65. ins v7.d[0],v6.d[1]
  66. ins v1.d[1],v0.d[0]
  67. ins v6.d[1],v5.d[0]
  68. eor v0.16b,v1.16b,v18.16b
  69. eor v5.16b,v6.16b,v4.16b
  70. ext v18.16b,v0.16b,v0.16b,#8 //2nd phase
  71. ext v4.16b,v5.16b,v5.16b,#8
  72. pmull v0.1q,v0.1d,v19.1d
  73. pmull v5.1q,v5.1d,v19.1d
  74. eor v18.16b,v18.16b,v2.16b
  75. eor v4.16b,v4.16b,v7.16b
  76. eor v20.16b, v0.16b,v18.16b //H^3
  77. eor v22.16b,v5.16b,v4.16b //H^4
  78. ext v16.16b,v20.16b, v20.16b,#8 //Karatsuba pre-processing
  79. ext v17.16b,v22.16b,v22.16b,#8
  80. eor v16.16b,v16.16b,v20.16b
  81. eor v17.16b,v17.16b,v22.16b
  82. ext v21.16b,v16.16b,v17.16b,#8 //pack Karatsuba pre-processed
  83. st1 {v20.2d,v21.2d,v22.2d},[x0] //store Htable[3..5]
  84. ret
  85. .size gcm_init_v8,.-gcm_init_v8
  86. .globl gcm_gmult_v8
  87. .type gcm_gmult_v8,%function
  88. .align 4
  89. gcm_gmult_v8:
  90. ld1 {v17.2d},[x0] //load Xi
  91. movi v19.16b,#0xe1
  92. ld1 {v20.2d,v21.2d},[x1] //load twisted H, ...
  93. shl v19.2d,v19.2d,#57
  94. #ifndef __ARMEB__
  95. rev64 v17.16b,v17.16b
  96. #endif
  97. ext v3.16b,v17.16b,v17.16b,#8
  98. pmull v0.1q,v20.1d,v3.1d //H.lo·Xi.lo
  99. eor v17.16b,v17.16b,v3.16b //Karatsuba pre-processing
  100. pmull2 v2.1q,v20.2d,v3.2d //H.hi·Xi.hi
  101. pmull v1.1q,v21.1d,v17.1d //(H.lo+H.hi)·(Xi.lo+Xi.hi)
  102. ext v17.16b,v0.16b,v2.16b,#8 //Karatsuba post-processing
  103. eor v18.16b,v0.16b,v2.16b
  104. eor v1.16b,v1.16b,v17.16b
  105. eor v1.16b,v1.16b,v18.16b
  106. pmull v18.1q,v0.1d,v19.1d //1st phase of reduction
  107. ins v2.d[0],v1.d[1]
  108. ins v1.d[1],v0.d[0]
  109. eor v0.16b,v1.16b,v18.16b
  110. ext v18.16b,v0.16b,v0.16b,#8 //2nd phase of reduction
  111. pmull v0.1q,v0.1d,v19.1d
  112. eor v18.16b,v18.16b,v2.16b
  113. eor v0.16b,v0.16b,v18.16b
  114. #ifndef __ARMEB__
  115. rev64 v0.16b,v0.16b
  116. #endif
  117. ext v0.16b,v0.16b,v0.16b,#8
  118. st1 {v0.2d},[x0] //write out Xi
  119. ret
  120. .size gcm_gmult_v8,.-gcm_gmult_v8
  121. .globl gcm_ghash_v8
  122. .type gcm_ghash_v8,%function
  123. .align 4
  124. gcm_ghash_v8:
  125. cmp x3,#64
  126. b.hs .Lgcm_ghash_v8_4x
  127. ld1 {v0.2d},[x0] //load [rotated] Xi
  128. //"[rotated]" means that
  129. //loaded value would have
  130. //to be rotated in order to
  131. //make it appear as in
  132. //algorithm specification
  133. subs x3,x3,#32 //see if x3 is 32 or larger
  134. mov x12,#16 //x12 is used as post-
  135. //increment for input pointer;
  136. //as loop is modulo-scheduled
  137. //x12 is zeroed just in time
  138. //to preclude overstepping
  139. //inp[len], which means that
  140. //last block[s] are actually
  141. //loaded twice, but last
  142. //copy is not processed
  143. ld1 {v20.2d,v21.2d},[x1],#32 //load twisted H, ..., H^2
  144. movi v19.16b,#0xe1
  145. ld1 {v22.2d},[x1]
  146. csel x12,xzr,x12,eq //is it time to zero x12?
  147. ext v0.16b,v0.16b,v0.16b,#8 //rotate Xi
  148. ld1 {v16.2d},[x2],#16 //load [rotated] I[0]
  149. shl v19.2d,v19.2d,#57 //compose 0xc2.0 constant
  150. #ifndef __ARMEB__
  151. rev64 v16.16b,v16.16b
  152. rev64 v0.16b,v0.16b
  153. #endif
  154. ext v3.16b,v16.16b,v16.16b,#8 //rotate I[0]
  155. b.lo .Lodd_tail_v8 //x3 was less than 32
  156. ld1 {v17.2d},[x2],x12 //load [rotated] I[1]
  157. #ifndef __ARMEB__
  158. rev64 v17.16b,v17.16b
  159. #endif
  160. ext v7.16b,v17.16b,v17.16b,#8
  161. eor v3.16b,v3.16b,v0.16b //I[i]^=Xi
  162. pmull v4.1q,v20.1d,v7.1d //H·Ii+1
  163. eor v17.16b,v17.16b,v7.16b //Karatsuba pre-processing
  164. pmull2 v6.1q,v20.2d,v7.2d
  165. b .Loop_mod2x_v8
  166. .align 4
  167. .Loop_mod2x_v8:
  168. ext v18.16b,v3.16b,v3.16b,#8
  169. subs x3,x3,#32 //is there more data?
  170. pmull v0.1q,v22.1d,v3.1d //H^2.lo·Xi.lo
  171. csel x12,xzr,x12,lo //is it time to zero x12?
  172. pmull v5.1q,v21.1d,v17.1d
  173. eor v18.16b,v18.16b,v3.16b //Karatsuba pre-processing
  174. pmull2 v2.1q,v22.2d,v3.2d //H^2.hi·Xi.hi
  175. eor v0.16b,v0.16b,v4.16b //accumulate
  176. pmull2 v1.1q,v21.2d,v18.2d //(H^2.lo+H^2.hi)·(Xi.lo+Xi.hi)
  177. ld1 {v16.2d},[x2],x12 //load [rotated] I[i+2]
  178. eor v2.16b,v2.16b,v6.16b
  179. csel x12,xzr,x12,eq //is it time to zero x12?
  180. eor v1.16b,v1.16b,v5.16b
  181. ext v17.16b,v0.16b,v2.16b,#8 //Karatsuba post-processing
  182. eor v18.16b,v0.16b,v2.16b
  183. eor v1.16b,v1.16b,v17.16b
  184. ld1 {v17.2d},[x2],x12 //load [rotated] I[i+3]
  185. #ifndef __ARMEB__
  186. rev64 v16.16b,v16.16b
  187. #endif
  188. eor v1.16b,v1.16b,v18.16b
  189. pmull v18.1q,v0.1d,v19.1d //1st phase of reduction
  190. #ifndef __ARMEB__
  191. rev64 v17.16b,v17.16b
  192. #endif
  193. ins v2.d[0],v1.d[1]
  194. ins v1.d[1],v0.d[0]
  195. ext v7.16b,v17.16b,v17.16b,#8
  196. ext v3.16b,v16.16b,v16.16b,#8
  197. eor v0.16b,v1.16b,v18.16b
  198. pmull v4.1q,v20.1d,v7.1d //H·Ii+1
  199. eor v3.16b,v3.16b,v2.16b //accumulate v3.16b early
  200. ext v18.16b,v0.16b,v0.16b,#8 //2nd phase of reduction
  201. pmull v0.1q,v0.1d,v19.1d
  202. eor v3.16b,v3.16b,v18.16b
  203. eor v17.16b,v17.16b,v7.16b //Karatsuba pre-processing
  204. eor v3.16b,v3.16b,v0.16b
  205. pmull2 v6.1q,v20.2d,v7.2d
  206. b.hs .Loop_mod2x_v8 //there was at least 32 more bytes
  207. eor v2.16b,v2.16b,v18.16b
  208. ext v3.16b,v16.16b,v16.16b,#8 //re-construct v3.16b
  209. adds x3,x3,#32 //re-construct x3
  210. eor v0.16b,v0.16b,v2.16b //re-construct v0.16b
  211. b.eq .Ldone_v8 //is x3 zero?
  212. .Lodd_tail_v8:
  213. ext v18.16b,v0.16b,v0.16b,#8
  214. eor v3.16b,v3.16b,v0.16b //inp^=Xi
  215. eor v17.16b,v16.16b,v18.16b //v17.16b is rotated inp^Xi
  216. pmull v0.1q,v20.1d,v3.1d //H.lo·Xi.lo
  217. eor v17.16b,v17.16b,v3.16b //Karatsuba pre-processing
  218. pmull2 v2.1q,v20.2d,v3.2d //H.hi·Xi.hi
  219. pmull v1.1q,v21.1d,v17.1d //(H.lo+H.hi)·(Xi.lo+Xi.hi)
  220. ext v17.16b,v0.16b,v2.16b,#8 //Karatsuba post-processing
  221. eor v18.16b,v0.16b,v2.16b
  222. eor v1.16b,v1.16b,v17.16b
  223. eor v1.16b,v1.16b,v18.16b
  224. pmull v18.1q,v0.1d,v19.1d //1st phase of reduction
  225. ins v2.d[0],v1.d[1]
  226. ins v1.d[1],v0.d[0]
  227. eor v0.16b,v1.16b,v18.16b
  228. ext v18.16b,v0.16b,v0.16b,#8 //2nd phase of reduction
  229. pmull v0.1q,v0.1d,v19.1d
  230. eor v18.16b,v18.16b,v2.16b
  231. eor v0.16b,v0.16b,v18.16b
  232. .Ldone_v8:
  233. #ifndef __ARMEB__
  234. rev64 v0.16b,v0.16b
  235. #endif
  236. ext v0.16b,v0.16b,v0.16b,#8
  237. st1 {v0.2d},[x0] //write out Xi
  238. ret
  239. .size gcm_ghash_v8,.-gcm_ghash_v8
  240. .type gcm_ghash_v8_4x,%function
  241. .align 4
  242. gcm_ghash_v8_4x:
  243. .Lgcm_ghash_v8_4x:
  244. ld1 {v0.2d},[x0] //load [rotated] Xi
  245. ld1 {v20.2d,v21.2d,v22.2d},[x1],#48 //load twisted H, ..., H^2
  246. movi v19.16b,#0xe1
  247. ld1 {v26.2d,v27.2d,v28.2d},[x1] //load twisted H^3, ..., H^4
  248. shl v19.2d,v19.2d,#57 //compose 0xc2.0 constant
  249. ld1 {v4.2d,v5.2d,v6.2d,v7.2d},[x2],#64
  250. #ifndef __ARMEB__
  251. rev64 v0.16b,v0.16b
  252. rev64 v5.16b,v5.16b
  253. rev64 v6.16b,v6.16b
  254. rev64 v7.16b,v7.16b
  255. rev64 v4.16b,v4.16b
  256. #endif
  257. ext v25.16b,v7.16b,v7.16b,#8
  258. ext v24.16b,v6.16b,v6.16b,#8
  259. ext v23.16b,v5.16b,v5.16b,#8
  260. pmull v29.1q,v20.1d,v25.1d //H·Ii+3
  261. eor v7.16b,v7.16b,v25.16b
  262. pmull2 v31.1q,v20.2d,v25.2d
  263. pmull v30.1q,v21.1d,v7.1d
  264. pmull v16.1q,v22.1d,v24.1d //H^2·Ii+2
  265. eor v6.16b,v6.16b,v24.16b
  266. pmull2 v24.1q,v22.2d,v24.2d
  267. pmull2 v6.1q,v21.2d,v6.2d
  268. eor v29.16b,v29.16b,v16.16b
  269. eor v31.16b,v31.16b,v24.16b
  270. eor v30.16b,v30.16b,v6.16b
  271. pmull v7.1q,v26.1d,v23.1d //H^3·Ii+1
  272. eor v5.16b,v5.16b,v23.16b
  273. pmull2 v23.1q,v26.2d,v23.2d
  274. pmull v5.1q,v27.1d,v5.1d
  275. eor v29.16b,v29.16b,v7.16b
  276. eor v31.16b,v31.16b,v23.16b
  277. eor v30.16b,v30.16b,v5.16b
  278. subs x3,x3,#128
  279. b.lo .Ltail4x
  280. b .Loop4x
  281. .align 4
  282. .Loop4x:
  283. eor v16.16b,v4.16b,v0.16b
  284. ld1 {v4.2d,v5.2d,v6.2d,v7.2d},[x2],#64
  285. ext v3.16b,v16.16b,v16.16b,#8
  286. #ifndef __ARMEB__
  287. rev64 v5.16b,v5.16b
  288. rev64 v6.16b,v6.16b
  289. rev64 v7.16b,v7.16b
  290. rev64 v4.16b,v4.16b
  291. #endif
  292. pmull v0.1q,v28.1d,v3.1d //H^4·(Xi+Ii)
  293. eor v16.16b,v16.16b,v3.16b
  294. pmull2 v2.1q,v28.2d,v3.2d
  295. ext v25.16b,v7.16b,v7.16b,#8
  296. pmull2 v1.1q,v27.2d,v16.2d
  297. eor v0.16b,v0.16b,v29.16b
  298. eor v2.16b,v2.16b,v31.16b
  299. ext v24.16b,v6.16b,v6.16b,#8
  300. eor v1.16b,v1.16b,v30.16b
  301. ext v23.16b,v5.16b,v5.16b,#8
  302. ext v17.16b,v0.16b,v2.16b,#8 //Karatsuba post-processing
  303. eor v18.16b,v0.16b,v2.16b
  304. pmull v29.1q,v20.1d,v25.1d //H·Ii+3
  305. eor v7.16b,v7.16b,v25.16b
  306. eor v1.16b,v1.16b,v17.16b
  307. pmull2 v31.1q,v20.2d,v25.2d
  308. eor v1.16b,v1.16b,v18.16b
  309. pmull v30.1q,v21.1d,v7.1d
  310. pmull v18.1q,v0.1d,v19.1d //1st phase of reduction
  311. ins v2.d[0],v1.d[1]
  312. ins v1.d[1],v0.d[0]
  313. pmull v16.1q,v22.1d,v24.1d //H^2·Ii+2
  314. eor v6.16b,v6.16b,v24.16b
  315. pmull2 v24.1q,v22.2d,v24.2d
  316. eor v0.16b,v1.16b,v18.16b
  317. pmull2 v6.1q,v21.2d,v6.2d
  318. eor v29.16b,v29.16b,v16.16b
  319. eor v31.16b,v31.16b,v24.16b
  320. eor v30.16b,v30.16b,v6.16b
  321. ext v18.16b,v0.16b,v0.16b,#8 //2nd phase of reduction
  322. pmull v0.1q,v0.1d,v19.1d
  323. pmull v7.1q,v26.1d,v23.1d //H^3·Ii+1
  324. eor v5.16b,v5.16b,v23.16b
  325. eor v18.16b,v18.16b,v2.16b
  326. pmull2 v23.1q,v26.2d,v23.2d
  327. pmull v5.1q,v27.1d,v5.1d
  328. eor v0.16b,v0.16b,v18.16b
  329. eor v29.16b,v29.16b,v7.16b
  330. eor v31.16b,v31.16b,v23.16b
  331. ext v0.16b,v0.16b,v0.16b,#8
  332. eor v30.16b,v30.16b,v5.16b
  333. subs x3,x3,#64
  334. b.hs .Loop4x
  335. .Ltail4x:
  336. eor v16.16b,v4.16b,v0.16b
  337. ext v3.16b,v16.16b,v16.16b,#8
  338. pmull v0.1q,v28.1d,v3.1d //H^4·(Xi+Ii)
  339. eor v16.16b,v16.16b,v3.16b
  340. pmull2 v2.1q,v28.2d,v3.2d
  341. pmull2 v1.1q,v27.2d,v16.2d
  342. eor v0.16b,v0.16b,v29.16b
  343. eor v2.16b,v2.16b,v31.16b
  344. eor v1.16b,v1.16b,v30.16b
  345. adds x3,x3,#64
  346. b.eq .Ldone4x
  347. cmp x3,#32
  348. b.lo .Lone
  349. b.eq .Ltwo
  350. .Lthree:
  351. ext v17.16b,v0.16b,v2.16b,#8 //Karatsuba post-processing
  352. eor v18.16b,v0.16b,v2.16b
  353. eor v1.16b,v1.16b,v17.16b
  354. ld1 {v4.2d,v5.2d,v6.2d},[x2]
  355. eor v1.16b,v1.16b,v18.16b
  356. #ifndef __ARMEB__
  357. rev64 v5.16b,v5.16b
  358. rev64 v6.16b,v6.16b
  359. rev64 v4.16b,v4.16b
  360. #endif
  361. pmull v18.1q,v0.1d,v19.1d //1st phase of reduction
  362. ins v2.d[0],v1.d[1]
  363. ins v1.d[1],v0.d[0]
  364. ext v24.16b,v6.16b,v6.16b,#8
  365. ext v23.16b,v5.16b,v5.16b,#8
  366. eor v0.16b,v1.16b,v18.16b
  367. pmull v29.1q,v20.1d,v24.1d //H·Ii+2
  368. eor v6.16b,v6.16b,v24.16b
  369. ext v18.16b,v0.16b,v0.16b,#8 //2nd phase of reduction
  370. pmull v0.1q,v0.1d,v19.1d
  371. eor v18.16b,v18.16b,v2.16b
  372. pmull2 v31.1q,v20.2d,v24.2d
  373. pmull v30.1q,v21.1d,v6.1d
  374. eor v0.16b,v0.16b,v18.16b
  375. pmull v7.1q,v22.1d,v23.1d //H^2·Ii+1
  376. eor v5.16b,v5.16b,v23.16b
  377. ext v0.16b,v0.16b,v0.16b,#8
  378. pmull2 v23.1q,v22.2d,v23.2d
  379. eor v16.16b,v4.16b,v0.16b
  380. pmull2 v5.1q,v21.2d,v5.2d
  381. ext v3.16b,v16.16b,v16.16b,#8
  382. eor v29.16b,v29.16b,v7.16b
  383. eor v31.16b,v31.16b,v23.16b
  384. eor v30.16b,v30.16b,v5.16b
  385. pmull v0.1q,v26.1d,v3.1d //H^3·(Xi+Ii)
  386. eor v16.16b,v16.16b,v3.16b
  387. pmull2 v2.1q,v26.2d,v3.2d
  388. pmull v1.1q,v27.1d,v16.1d
  389. eor v0.16b,v0.16b,v29.16b
  390. eor v2.16b,v2.16b,v31.16b
  391. eor v1.16b,v1.16b,v30.16b
  392. b .Ldone4x
  393. .align 4
  394. .Ltwo:
  395. ext v17.16b,v0.16b,v2.16b,#8 //Karatsuba post-processing
  396. eor v18.16b,v0.16b,v2.16b
  397. eor v1.16b,v1.16b,v17.16b
  398. ld1 {v4.2d,v5.2d},[x2]
  399. eor v1.16b,v1.16b,v18.16b
  400. #ifndef __ARMEB__
  401. rev64 v5.16b,v5.16b
  402. rev64 v4.16b,v4.16b
  403. #endif
  404. pmull v18.1q,v0.1d,v19.1d //1st phase of reduction
  405. ins v2.d[0],v1.d[1]
  406. ins v1.d[1],v0.d[0]
  407. ext v23.16b,v5.16b,v5.16b,#8
  408. eor v0.16b,v1.16b,v18.16b
  409. ext v18.16b,v0.16b,v0.16b,#8 //2nd phase of reduction
  410. pmull v0.1q,v0.1d,v19.1d
  411. eor v18.16b,v18.16b,v2.16b
  412. eor v0.16b,v0.16b,v18.16b
  413. ext v0.16b,v0.16b,v0.16b,#8
  414. pmull v29.1q,v20.1d,v23.1d //H·Ii+1
  415. eor v5.16b,v5.16b,v23.16b
  416. eor v16.16b,v4.16b,v0.16b
  417. ext v3.16b,v16.16b,v16.16b,#8
  418. pmull2 v31.1q,v20.2d,v23.2d
  419. pmull v30.1q,v21.1d,v5.1d
  420. pmull v0.1q,v22.1d,v3.1d //H^2·(Xi+Ii)
  421. eor v16.16b,v16.16b,v3.16b
  422. pmull2 v2.1q,v22.2d,v3.2d
  423. pmull2 v1.1q,v21.2d,v16.2d
  424. eor v0.16b,v0.16b,v29.16b
  425. eor v2.16b,v2.16b,v31.16b
  426. eor v1.16b,v1.16b,v30.16b
  427. b .Ldone4x
  428. .align 4
  429. .Lone:
  430. ext v17.16b,v0.16b,v2.16b,#8 //Karatsuba post-processing
  431. eor v18.16b,v0.16b,v2.16b
  432. eor v1.16b,v1.16b,v17.16b
  433. ld1 {v4.2d},[x2]
  434. eor v1.16b,v1.16b,v18.16b
  435. #ifndef __ARMEB__
  436. rev64 v4.16b,v4.16b
  437. #endif
  438. pmull v18.1q,v0.1d,v19.1d //1st phase of reduction
  439. ins v2.d[0],v1.d[1]
  440. ins v1.d[1],v0.d[0]
  441. eor v0.16b,v1.16b,v18.16b
  442. ext v18.16b,v0.16b,v0.16b,#8 //2nd phase of reduction
  443. pmull v0.1q,v0.1d,v19.1d
  444. eor v18.16b,v18.16b,v2.16b
  445. eor v0.16b,v0.16b,v18.16b
  446. ext v0.16b,v0.16b,v0.16b,#8
  447. eor v16.16b,v4.16b,v0.16b
  448. ext v3.16b,v16.16b,v16.16b,#8
  449. pmull v0.1q,v20.1d,v3.1d
  450. eor v16.16b,v16.16b,v3.16b
  451. pmull2 v2.1q,v20.2d,v3.2d
  452. pmull v1.1q,v21.1d,v16.1d
  453. .Ldone4x:
  454. ext v17.16b,v0.16b,v2.16b,#8 //Karatsuba post-processing
  455. eor v18.16b,v0.16b,v2.16b
  456. eor v1.16b,v1.16b,v17.16b
  457. eor v1.16b,v1.16b,v18.16b
  458. pmull v18.1q,v0.1d,v19.1d //1st phase of reduction
  459. ins v2.d[0],v1.d[1]
  460. ins v1.d[1],v0.d[0]
  461. eor v0.16b,v1.16b,v18.16b
  462. ext v18.16b,v0.16b,v0.16b,#8 //2nd phase of reduction
  463. pmull v0.1q,v0.1d,v19.1d
  464. eor v18.16b,v18.16b,v2.16b
  465. eor v0.16b,v0.16b,v18.16b
  466. ext v0.16b,v0.16b,v0.16b,#8
  467. #ifndef __ARMEB__
  468. rev64 v0.16b,v0.16b
  469. #endif
  470. st1 {v0.2d},[x0] //write out Xi
  471. ret
  472. .size gcm_ghash_v8_4x,.-gcm_ghash_v8_4x
  473. .byte 71,72,65,83,72,32,102,111,114,32,65,82,77,118,56,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103,62,0
  474. .align 2
  475. .align 2
  476. #endif