ghash-ce-core.S 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Accelerated GHASH implementation with ARMv8 PMULL instructions.
  3. *
  4. * Copyright (C) 2014 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 v0
  13. SHASH2 .req v1
  14. T1 .req v2
  15. T2 .req v3
  16. MASK .req v4
  17. XL .req v5
  18. XM .req v6
  19. XH .req v7
  20. IN1 .req v7
  21. .text
  22. .arch armv8-a+crypto
  23. /*
  24. * void pmull_ghash_update(int blocks, u64 dg[], const char *src,
  25. * struct ghash_key const *k, const char *head)
  26. */
  27. ENTRY(pmull_ghash_update)
  28. ld1 {SHASH.2d}, [x3]
  29. ld1 {XL.2d}, [x1]
  30. movi MASK.16b, #0xe1
  31. ext SHASH2.16b, SHASH.16b, SHASH.16b, #8
  32. shl MASK.2d, MASK.2d, #57
  33. eor SHASH2.16b, SHASH2.16b, SHASH.16b
  34. /* do the head block first, if supplied */
  35. cbz x4, 0f
  36. ld1 {T1.2d}, [x4]
  37. b 1f
  38. 0: ld1 {T1.2d}, [x2], #16
  39. sub w0, w0, #1
  40. 1: /* multiply XL by SHASH in GF(2^128) */
  41. CPU_LE( rev64 T1.16b, T1.16b )
  42. ext T2.16b, XL.16b, XL.16b, #8
  43. ext IN1.16b, T1.16b, T1.16b, #8
  44. eor T1.16b, T1.16b, T2.16b
  45. eor XL.16b, XL.16b, IN1.16b
  46. pmull2 XH.1q, SHASH.2d, XL.2d // a1 * b1
  47. eor T1.16b, T1.16b, XL.16b
  48. pmull XL.1q, SHASH.1d, XL.1d // a0 * b0
  49. pmull XM.1q, SHASH2.1d, T1.1d // (a1 + a0)(b1 + b0)
  50. ext T1.16b, XL.16b, XH.16b, #8
  51. eor T2.16b, XL.16b, XH.16b
  52. eor XM.16b, XM.16b, T1.16b
  53. eor XM.16b, XM.16b, T2.16b
  54. pmull T2.1q, XL.1d, MASK.1d
  55. mov XH.d[0], XM.d[1]
  56. mov XM.d[1], XL.d[0]
  57. eor XL.16b, XM.16b, T2.16b
  58. ext T2.16b, XL.16b, XL.16b, #8
  59. pmull XL.1q, XL.1d, MASK.1d
  60. eor T2.16b, T2.16b, XH.16b
  61. eor XL.16b, XL.16b, T2.16b
  62. cbnz w0, 0b
  63. st1 {XL.2d}, [x1]
  64. ret
  65. ENDPROC(pmull_ghash_update)