aes-ce-core.S 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2013 - 2017 Linaro Ltd <ard.biesheuvel@linaro.org>
  4. */
  5. #include <linux/linkage.h>
  6. #include <asm/assembler.h>
  7. .arch armv8-a+crypto
  8. SYM_FUNC_START(__aes_ce_encrypt)
  9. sub w3, w3, #2
  10. ld1 {v0.16b}, [x2]
  11. ld1 {v1.4s}, [x0], #16
  12. cmp w3, #10
  13. bmi 0f
  14. bne 3f
  15. mov v3.16b, v1.16b
  16. b 2f
  17. 0: mov v2.16b, v1.16b
  18. ld1 {v3.4s}, [x0], #16
  19. 1: aese v0.16b, v2.16b
  20. aesmc v0.16b, v0.16b
  21. 2: ld1 {v1.4s}, [x0], #16
  22. aese v0.16b, v3.16b
  23. aesmc v0.16b, v0.16b
  24. 3: ld1 {v2.4s}, [x0], #16
  25. subs w3, w3, #3
  26. aese v0.16b, v1.16b
  27. aesmc v0.16b, v0.16b
  28. ld1 {v3.4s}, [x0], #16
  29. bpl 1b
  30. aese v0.16b, v2.16b
  31. eor v0.16b, v0.16b, v3.16b
  32. st1 {v0.16b}, [x1]
  33. ret
  34. SYM_FUNC_END(__aes_ce_encrypt)
  35. SYM_FUNC_START(__aes_ce_decrypt)
  36. sub w3, w3, #2
  37. ld1 {v0.16b}, [x2]
  38. ld1 {v1.4s}, [x0], #16
  39. cmp w3, #10
  40. bmi 0f
  41. bne 3f
  42. mov v3.16b, v1.16b
  43. b 2f
  44. 0: mov v2.16b, v1.16b
  45. ld1 {v3.4s}, [x0], #16
  46. 1: aesd v0.16b, v2.16b
  47. aesimc v0.16b, v0.16b
  48. 2: ld1 {v1.4s}, [x0], #16
  49. aesd v0.16b, v3.16b
  50. aesimc v0.16b, v0.16b
  51. 3: ld1 {v2.4s}, [x0], #16
  52. subs w3, w3, #3
  53. aesd v0.16b, v1.16b
  54. aesimc v0.16b, v0.16b
  55. ld1 {v3.4s}, [x0], #16
  56. bpl 1b
  57. aesd v0.16b, v2.16b
  58. eor v0.16b, v0.16b, v3.16b
  59. st1 {v0.16b}, [x1]
  60. ret
  61. SYM_FUNC_END(__aes_ce_decrypt)
  62. /*
  63. * __aes_ce_sub() - use the aese instruction to perform the AES sbox
  64. * substitution on each byte in 'input'
  65. */
  66. SYM_FUNC_START(__aes_ce_sub)
  67. dup v1.4s, w0
  68. movi v0.16b, #0
  69. aese v0.16b, v1.16b
  70. umov w0, v0.s[0]
  71. ret
  72. SYM_FUNC_END(__aes_ce_sub)
  73. SYM_FUNC_START(__aes_ce_invert)
  74. ld1 {v0.4s}, [x1]
  75. aesimc v1.16b, v0.16b
  76. st1 {v1.4s}, [x0]
  77. ret
  78. SYM_FUNC_END(__aes_ce_invert)