Skip to content

Commit 4eb8aca

Browse files
authored
Move udiv and sencond tweak calculations to when needed (#2726)
### Issues: Addresses CryptoAlg-2941 ### Description of changes: - We don't need to do `len DIV 0x50` until before the loop that processes 5 blocks at a time. - We don't need the computation of the second block's tweak (iv) until we know we will use it. Note: that iv was not needed in the case of 1 block + k bytes, k < 16, i.e. cipher-stealing case of tail1x, because that iv is anyway computed before cipher-stealing, so it was actually computed twice before this move. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.
1 parent 2c370b0 commit 4eb8aca

File tree

1 file changed

+9
-10
lines changed
  • third_party/s2n-bignum/s2n-bignum-to-be-imported/arm/aes

1 file changed

+9
-10
lines changed

third_party/s2n-bignum/s2n-bignum-to-be-imported/arm/aes/aes-xts-enc.S

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ S2N_BN_SYMBOL(aes_hw_xts_encrypt):
6565
save_vregs
6666
save_regs
6767

68-
udiv_by_80(x2, x8) // Number of 5x-unrolled iterations
69-
7068
cmp x2, #16 // AES-XTS needs at least one block
7169
b.lt .Lxts_enc_abort
7270
.align 4
@@ -94,14 +92,6 @@ S2N_BN_SYMBOL(aes_hw_xts_encrypt):
9492
aese v6.16b, v1.16b
9593
eor v6.16b, v6.16b, v0.16b
9694

97-
// The iv for second block
98-
// x9- iv(low), x10 - iv(high)
99-
// the five ivs stored into, v6.16b,v8.16b,v9.16b,v10.16b,v11.16b
100-
fmov x9, d6
101-
fmov x10, v6.d[1]
102-
mov w19, #0x87
103-
tweak(d8, v8.d[1])
104-
10595
mov x7, x3
10696
ld1 {v16.4s,v17.4s},[x7], #32 // load key schedule
10797
ld1 {v12.4s,v13.4s},[x7], #32
@@ -117,6 +107,14 @@ S2N_BN_SYMBOL(aes_hw_xts_encrypt):
117107
cmp x2, #0x20
118108
b.lo .Lxts_enc_tail1x // when input = 1 with tail
119109

110+
// The iv for second block
111+
// x9- iv(low), x10 - iv(high)
112+
// the five ivs stored into, v6.16b,v8.16b,v9.16b,v10.16b,v11.16b
113+
fmov x9, d6
114+
fmov x10, v6.d[1]
115+
mov w19, #0x87
116+
tweak(d8, v8.d[1])
117+
120118
cmp x2, #0x30
121119
b.lo .Lxts_enc_tail2x // when input size = 2
122120

@@ -135,6 +133,7 @@ S2N_BN_SYMBOL(aes_hw_xts_encrypt):
135133
// The iv for fifth block
136134
tweak(d11,v11.d[1])
137135

136+
udiv_by_80(x2, x8) // Number of 5x-unrolled iterations
138137
.align 4
139138
.Loop5x_xts_enc:
140139
ldp q0, q1, [x0], #0x50

0 commit comments

Comments
 (0)