Skip to content

Commit 6ae51ff

Browse files
bulwahnherbertx
authored andcommitted
crypto: sha512 - remove imaginary and mystifying clearing of variables
The function sha512_transform() assigns all local variables to 0 before returning to its caller with the intent to erase sensitive data. However, make clang-analyzer warns that all these assignments are dead stores, and as commit 7a4295f ("crypto: lib/sha256 - Don't clear temporary variables") already points out for sha256_transform(): The assignments to clear a through h and t1/t2 are optimized out by the compiler because they are unused after the assignments. Clearing individual scalar variables is unlikely to be useful, as they may have been assigned to registers, and even if stack spilling was required, there may be compiler-generated temporaries that are impossible to clear in any case. This applies here again as well. Drop meaningless clearing of local variables and avoid this way that the code suggests that data is erased, which simply does not happen. Signed-off-by: Lukas Bulwahn <[email protected]> Reviewed-by: Nick Desaulniers <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 72ff2bf commit 6ae51ff

File tree

1 file changed

+0
-3
lines changed

1 file changed

+0
-3
lines changed

crypto/sha512_generic.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,6 @@ sha512_transform(u64 *state, const u8 *input)
143143

144144
state[0] += a; state[1] += b; state[2] += c; state[3] += d;
145145
state[4] += e; state[5] += f; state[6] += g; state[7] += h;
146-
147-
/* erase our data */
148-
a = b = c = d = e = f = g = h = t1 = t2 = 0;
149146
}
150147

151148
static void sha512_generic_block_fn(struct sha512_state *sst, u8 const *src,

0 commit comments

Comments
 (0)