1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * sha1-ce-core.S - SHA-1 secure hash using ARMv8 Crypto Extensions
5 * Copyright (C) 2014 Linaro Ltd <ard.biesheuvel@linaro.org>
8 #include <linux/linkage.h>
9 #include <asm/assembler.h>
34 .macro add_only, op, ev, rc, s0, dg1
36 add t1.4s, v\s0\().4s, \rc\().4s
39 sha1\op dg0q, \dg1, t0.4s
41 sha1\op dg0q, dg1s, t0.4s
45 add t0.4s, v\s0\().4s, \rc\().4s
48 sha1\op dg0q, dg2s, t1.4s
52 .macro add_update, op, ev, rc, s0, s1, s2, s3, dg1
53 sha1su0 v\s0\().4s, v\s1\().4s, v\s2\().4s
54 add_only \op, \ev, \rc, \s1, \dg1
55 sha1su1 v\s0\().4s, v\s3\().4s
58 .macro loadrc, k, val, tmp
59 movz \tmp, :abs_g0_nc:\val
60 movk \tmp, :abs_g1:\val
65 * int __sha1_ce_transform(struct sha1_ce_state *sst, u8 const *src,
68 SYM_FUNC_START(__sha1_ce_transform)
69 /* load round constants */
70 loadrc k0.4s, 0x5a827999, w6
71 loadrc k1.4s, 0x6ed9eba1, w6
72 loadrc k2.4s, 0x8f1bbcdc, w6
73 loadrc k3.4s, 0xca62c1d6, w6
79 /* load sha1_ce_state::finalize */
80 ldr_l w4, sha1_ce_offsetof_finalize, x4
84 0: ld1 {v8.4s-v11.4s}, [x1], #64
87 CPU_LE( rev32 v8.16b, v8.16b )
88 CPU_LE( rev32 v9.16b, v9.16b )
89 CPU_LE( rev32 v10.16b, v10.16b )
90 CPU_LE( rev32 v11.16b, v11.16b )
92 1: add t0.4s, v8.4s, k0.4s
93 mov dg0v.16b, dgav.16b
95 add_update c, ev, k0, 8, 9, 10, 11, dgb
96 add_update c, od, k0, 9, 10, 11, 8
97 add_update c, ev, k0, 10, 11, 8, 9
98 add_update c, od, k0, 11, 8, 9, 10
99 add_update c, ev, k1, 8, 9, 10, 11
101 add_update p, od, k1, 9, 10, 11, 8
102 add_update p, ev, k1, 10, 11, 8, 9
103 add_update p, od, k1, 11, 8, 9, 10
104 add_update p, ev, k1, 8, 9, 10, 11
105 add_update p, od, k2, 9, 10, 11, 8
107 add_update m, ev, k2, 10, 11, 8, 9
108 add_update m, od, k2, 11, 8, 9, 10
109 add_update m, ev, k2, 8, 9, 10, 11
110 add_update m, od, k2, 9, 10, 11, 8
111 add_update m, ev, k3, 10, 11, 8, 9
113 add_update p, od, k3, 11, 8, 9, 10
114 add_only p, ev, k3, 9
115 add_only p, od, k3, 10
116 add_only p, ev, k3, 11
120 add dgbv.2s, dgbv.2s, dg1v.2s
121 add dgav.4s, dgav.4s, dg0v.4s
124 cond_yield 3f, x5, x6
128 * Final block: add padding and total bit count.
129 * Skip if the input size was not a round multiple of the block size,
130 * the padding is handled by the C code in that case.
133 ldr_l w4, sha1_ce_offsetof_count, x4
138 ror x7, x4, #29 // ror(lsl(x4, 3), 32)
145 /* store new state */
146 3: st1 {dgav.4s}, [x0]
150 SYM_FUNC_END(__sha1_ce_transform)