Skip to content

Commit

Permalink
Clear stack with saved SIMD registers
Browse files Browse the repository at this point in the history
If SAFE_DATA is set, clear stack containing saved
SIMD registers, which could be storing sensitive data.

Change-Id: Ie0b72d5b29e65e59656f89f805163b83bc0e3f55
  • Loading branch information
pablodelara committed Oct 24, 2019
1 parent 2fcad13 commit 3a1bc6a
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 2 deletions.
10 changes: 9 additions & 1 deletion avx/sha1_one_block_avx.asm
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,17 @@ loop3_5:
vmovdqa xmm7, [rsp + 1 * 16]
vmovdqa xmm6, [rsp + 0 * 16]

mov rsp,[_RSP]
%ifdef SAFE_DATA
;; Clear potential sensitive data stored in stack
vpxor xmm0, xmm0
vmovdqa [rsp + 0 * 16], xmm0
vmovdqa [rsp + 1 * 16], xmm0
vmovdqa [rsp + 2 * 16], xmm0
%endif

mov rsp,[_RSP]
%endif ;; LINUX

pop r13
pop r12
pop rdi
Expand Down
12 changes: 12 additions & 0 deletions avx/sha256_one_block_avx.asm
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,19 @@ done_hash:
vmovdqa xmm11,[rsp + _XMM_SAVE + 5*16]
vmovdqa xmm12,[rsp + _XMM_SAVE + 6*16]
vmovdqa xmm13,[rsp + _XMM_SAVE + 7*16]
%ifdef SAFE_DATA
;; Clear potential sensitive data stored in stack
vpxor xmm0, xmm0
vmovdqa [rsp + _XMM_SAVE + 0 * 16], xmm0
vmovdqa [rsp + _XMM_SAVE + 1 * 16], xmm0
vmovdqa [rsp + _XMM_SAVE + 2 * 16], xmm0
vmovdqa [rsp + _XMM_SAVE + 3 * 16], xmm0
vmovdqa [rsp + _XMM_SAVE + 4 * 16], xmm0
vmovdqa [rsp + _XMM_SAVE + 5 * 16], xmm0
vmovdqa [rsp + _XMM_SAVE + 6 * 16], xmm0
vmovdqa [rsp + _XMM_SAVE + 7 * 16], xmm0
%endif
%endif ;; LINUX

add rsp, STACK_size

Expand Down
12 changes: 12 additions & 0 deletions avx/sha512_one_block_avx.asm
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,19 @@ done_hash:
vmovdqa xmm11,[rsp + _XMM_SAVE + 5*16]
vmovdqa xmm12,[rsp + _XMM_SAVE + 6*16]
vmovdqa xmm13,[rsp + _XMM_SAVE + 7*16]
%ifdef SAFE_DATA
;; Clear potential sensitive data stored in stack
vpxor xmm0, xmm0
vmovdqa [rsp + _XMM_SAVE + 0 * 16], xmm0
vmovdqa [rsp + _XMM_SAVE + 1 * 16], xmm0
vmovdqa [rsp + _XMM_SAVE + 2 * 16], xmm0
vmovdqa [rsp + _XMM_SAVE + 3 * 16], xmm0
vmovdqa [rsp + _XMM_SAVE + 4 * 16], xmm0
vmovdqa [rsp + _XMM_SAVE + 5 * 16], xmm0
vmovdqa [rsp + _XMM_SAVE + 6 * 16], xmm0
vmovdqa [rsp + _XMM_SAVE + 7 * 16], xmm0
%endif
%endif ;; LINUX

add rsp, STACK_size

Expand Down
30 changes: 30 additions & 0 deletions include/save_xmms.asm
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ restore_xmms:
movdqa xmm13, [ARG1 + 7*16]
movdqa xmm14, [ARG1 + 8*16]
movdqa xmm15, [ARG1 + 9*16]
%ifdef SAFE_DATA
;; Clear potential sensitive data stored in stack
pxor xmm0, xmm0
movdqa [ARG1 + 0 * 16], xmm0
movdqa [ARG1 + 1 * 16], xmm0
movdqa [ARG1 + 2 * 16], xmm0
movdqa [ARG1 + 3 * 16], xmm0
movdqa [ARG1 + 4 * 16], xmm0
movdqa [ARG1 + 5 * 16], xmm0
movdqa [ARG1 + 6 * 16], xmm0
movdqa [ARG1 + 7 * 16], xmm0
movdqa [ARG1 + 8 * 16], xmm0
movdqa [ARG1 + 9 * 16], xmm0
%endif

ret


Expand Down Expand Up @@ -95,6 +110,21 @@ restore_xmms_avx:
vmovdqa xmm13, [ARG1 + 7*16]
vmovdqa xmm14, [ARG1 + 8*16]
vmovdqa xmm15, [ARG1 + 9*16]

%ifdef SAFE_DATA
;; Clear potential sensitive data stored in stack
vpxor xmm0, xmm0
vmovdqa [ARG1 + 0 * 16], xmm0
vmovdqa [ARG1 + 1 * 16], xmm0
vmovdqa [ARG1 + 2 * 16], xmm0
vmovdqa [ARG1 + 3 * 16], xmm0
vmovdqa [ARG1 + 4 * 16], xmm0
vmovdqa [ARG1 + 5 * 16], xmm0
vmovdqa [ARG1 + 6 * 16], xmm0
vmovdqa [ARG1 + 7 * 16], xmm0
vmovdqa [ARG1 + 8 * 16], xmm0
vmovdqa [ARG1 + 9 * 16], xmm0
%endif
ret

%ifdef LINUX
Expand Down
10 changes: 9 additions & 1 deletion sse/sha1_one_block_sse.asm
Original file line number Diff line number Diff line change
Expand Up @@ -488,9 +488,17 @@ loop3_5:
movdqa xmm7, [rsp + 1 * 16]
movdqa xmm6, [rsp + 0 * 16]

mov rsp, [_RSP]
%ifdef SAFE_DATA
;; Clear potential sensitive data stored in stack
pxor xmm0, xmm0
movdqa [rsp + 0 * 16], xmm0
movdqa [rsp + 1 * 16], xmm0
movdqa [rsp + 2 * 16], xmm0
%endif

mov rsp, [_RSP]
%endif ;; LINUX

pop r13
pop r12
pop rdi
Expand Down
11 changes: 11 additions & 0 deletions sse/sha256_one_block_sse.asm
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,18 @@ done_hash:
movdqa xmm10,[rsp + _XMM_SAVE + 4*16]
movdqa xmm11,[rsp + _XMM_SAVE + 5*16]
movdqa xmm12,[rsp + _XMM_SAVE + 6*16]
%ifdef SAFE_DATA
;; Clear potential sensitive data stored in stack
pxor xmm0, xmm0
movdqa [rsp + _XMM_SAVE + 0 * 16], xmm0
movdqa [rsp + _XMM_SAVE + 1 * 16], xmm0
movdqa [rsp + _XMM_SAVE + 2 * 16], xmm0
movdqa [rsp + _XMM_SAVE + 3 * 16], xmm0
movdqa [rsp + _XMM_SAVE + 4 * 16], xmm0
movdqa [rsp + _XMM_SAVE + 5 * 16], xmm0
movdqa [rsp + _XMM_SAVE + 6 * 16], xmm0
%endif
%endif ;; LINUX

add rsp, STACK_size

Expand Down
13 changes: 13 additions & 0 deletions sse/sha512_one_block_sse.asm
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,20 @@ done_hash:
movdqa xmm11,[rsp + _XMM_SAVE + 5*16]
movdqa xmm12,[rsp + _XMM_SAVE + 6*16]
movdqa xmm13,[rsp + _XMM_SAVE + 7*16]

%ifdef SAFE_DATA
;; Clear potential sensitive data stored in stack
pxor xmm0, xmm0
movdqa [rsp + _XMM_SAVE + 0 * 16], xmm0
movdqa [rsp + _XMM_SAVE + 1 * 16], xmm0
movdqa [rsp + _XMM_SAVE + 2 * 16], xmm0
movdqa [rsp + _XMM_SAVE + 3 * 16], xmm0
movdqa [rsp + _XMM_SAVE + 4 * 16], xmm0
movdqa [rsp + _XMM_SAVE + 5 * 16], xmm0
movdqa [rsp + _XMM_SAVE + 6 * 16], xmm0
movdqa [rsp + _XMM_SAVE + 7 * 16], xmm0
%endif
%endif ;; LINUX

add rsp, STACK_size

Expand Down

0 comments on commit 3a1bc6a

Please sign in to comment.