2 * sha1-ce-core.S - SHA-1 secure hash using ARMv8 Crypto Extensions
4 * Copyright (C) 2014 Linaro Ltd <ard.biesheuvel@linaro.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #include <linux/linkage.h>
12 #include <asm/assembler.h>
37 .macro add_only, op, ev, rc, s0, dg1
39 add t1.4s, v\s0\().4s, \rc\().4s
42 sha1\op dg0q, \dg1, t0.4s
44 sha1\op dg0q, dg1s, t0.4s
48 add t0.4s, v\s0\().4s, \rc\().4s
51 sha1\op dg0q, dg2s, t1.4s
55 .macro add_update, op, ev, rc, s0, s1, s2, s3, dg1
56 sha1su0 v\s0\().4s, v\s1\().4s, v\s2\().4s
57 add_only \op, \ev, \rc, \s1, \dg1
58 sha1su1 v\s0\().4s, v\s3\().4s
62 * The SHA1 round constants
66 .word 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6
69 * void sha1_ce_transform(int blocks, u8 const *src, u32 *state,
70 * u8 *head, long bytes)
72 ENTRY(sha1_ce_transform)
73 /* load round constants */
75 ld1r {k0.4s}, [x6], #4
76 ld1r {k1.4s}, [x6], #4
77 ld1r {k2.4s}, [x6], #4
84 /* load partial state (if supplied) */
86 ld1 {v8.4s-v11.4s}, [x3]
90 0: ld1 {v8.4s-v11.4s}, [x1], #64
94 CPU_LE( rev32 v8.16b, v8.16b )
95 CPU_LE( rev32 v9.16b, v9.16b )
96 CPU_LE( rev32 v10.16b, v10.16b )
97 CPU_LE( rev32 v11.16b, v11.16b )
99 2: add t0.4s, v8.4s, k0.4s
100 mov dg0v.16b, dgav.16b
102 add_update c, ev, k0, 8, 9, 10, 11, dgb
103 add_update c, od, k0, 9, 10, 11, 8
104 add_update c, ev, k0, 10, 11, 8, 9
105 add_update c, od, k0, 11, 8, 9, 10
106 add_update c, ev, k1, 8, 9, 10, 11
108 add_update p, od, k1, 9, 10, 11, 8
109 add_update p, ev, k1, 10, 11, 8, 9
110 add_update p, od, k1, 11, 8, 9, 10
111 add_update p, ev, k1, 8, 9, 10, 11
112 add_update p, od, k2, 9, 10, 11, 8
114 add_update m, ev, k2, 10, 11, 8, 9
115 add_update m, od, k2, 11, 8, 9, 10
116 add_update m, ev, k2, 8, 9, 10, 11
117 add_update m, od, k2, 9, 10, 11, 8
118 add_update m, ev, k3, 10, 11, 8, 9
120 add_update p, od, k3, 11, 8, 9, 10
121 add_only p, ev, k3, 9
122 add_only p, od, k3, 10
123 add_only p, ev, k3, 11
127 add dgbv.2s, dgbv.2s, dg1v.2s
128 add dgav.4s, dgav.4s, dg0v.4s
133 * Final block: add padding and total bit count.
134 * Skip if we have no total byte count in x4. In that case, the input
135 * size was not a round multiple of the block size, and the padding is
136 * handled by the C code.
142 ror x7, x4, #29 // ror(lsl(x4, 3), 32)
149 /* store new state */
153 ENDPROC(sha1_ce_transform)