aes-ce-core.S 1.8 KB

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