ghash-ce-core.S 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Accelerated GHASH implementation with ARMv8 vmull.p64 instructions.
  3. *
  4. * Copyright (C) 2015 Linaro Ltd. <ard.biesheuvel@linaro.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published
  8. * by the Free Software Foundation.
  9. */
  10. #include <linux/linkage.h>
  11. #include <asm/assembler.h>
  12. SHASH .req q0
  13. SHASH2 .req q1
  14. T1 .req q2
  15. T2 .req q3
  16. MASK .req q4
  17. XL .req q5
  18. XM .req q6
  19. XH .req q7
  20. IN1 .req q7
  21. SHASH_L .req d0
  22. SHASH_H .req d1
  23. SHASH2_L .req d2
  24. T1_L .req d4
  25. MASK_L .req d8
  26. XL_L .req d10
  27. XL_H .req d11
  28. XM_L .req d12
  29. XM_H .req d13
  30. XH_L .req d14
  31. .text
  32. .fpu crypto-neon-fp-armv8
  33. /*
  34. * void pmull_ghash_update(int blocks, u64 dg[], const char *src,
  35. * struct ghash_key const *k, const char *head)
  36. */
  37. ENTRY(pmull_ghash_update)
  38. vld1.64 {SHASH}, [r3]
  39. vld1.64 {XL}, [r1]
  40. vmov.i8 MASK, #0xe1
  41. vext.8 SHASH2, SHASH, SHASH, #8
  42. vshl.u64 MASK, MASK, #57
  43. veor SHASH2, SHASH2, SHASH
  44. /* do the head block first, if supplied */
  45. ldr ip, [sp]
  46. teq ip, #0
  47. beq 0f
  48. vld1.64 {T1}, [ip]
  49. teq r0, #0
  50. b 1f
  51. 0: vld1.64 {T1}, [r2]!
  52. subs r0, r0, #1
  53. 1: /* multiply XL by SHASH in GF(2^128) */
  54. #ifndef CONFIG_CPU_BIG_ENDIAN
  55. vrev64.8 T1, T1
  56. #endif
  57. vext.8 T2, XL, XL, #8
  58. vext.8 IN1, T1, T1, #8
  59. veor T1, T1, T2
  60. veor XL, XL, IN1
  61. vmull.p64 XH, SHASH_H, XL_H @ a1 * b1
  62. veor T1, T1, XL
  63. vmull.p64 XL, SHASH_L, XL_L @ a0 * b0
  64. vmull.p64 XM, SHASH2_L, T1_L @ (a1 + a0)(b1 + b0)
  65. vext.8 T1, XL, XH, #8
  66. veor T2, XL, XH
  67. veor XM, XM, T1
  68. veor XM, XM, T2
  69. vmull.p64 T2, XL_L, MASK_L
  70. vmov XH_L, XM_H
  71. vmov XM_H, XL_L
  72. veor XL, XM, T2
  73. vext.8 T2, XL, XL, #8
  74. vmull.p64 XL, XL_L, MASK_L
  75. veor T2, T2, XH
  76. veor XL, XL, T2
  77. bne 0b
  78. vst1.64 {XL}, [r1]
  79. bx lr
  80. ENDPROC(pmull_ghash_update)