summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/sha/sha256_amd64_generic.S
diff options
context:
space:
mode:
authorjsing <>2026-05-07 15:38:03 +0000
committerjsing <>2026-05-07 15:38:03 +0000
commitccc4eae3de33ef320762657c4be6c9dfd9c2de82 (patch)
tree81f773dc013844248de1103391a3e49d252c1587 /src/lib/libcrypto/sha/sha256_amd64_generic.S
parent97930339bcae324ce6c463f52bdcdf98c4be2941 (diff)
downloadopenbsd-ccc4eae3de33ef320762657c4be6c9dfd9c2de82.tar.gz
openbsd-ccc4eae3de33ef320762657c4be6c9dfd9c2de82.tar.bz2
openbsd-ccc4eae3de33ef320762657c4be6c9dfd9c2de82.zip
Use a define based instruction separator in SHA assembly.
Unfortunately, not all assemblers use the same instruction separator. In particular, LLVM on macOS uses %% as an instruction separator, while most other assemblers use a semi-colon. ok kenjiro@ tb@
Diffstat (limited to 'src/lib/libcrypto/sha/sha256_amd64_generic.S')
-rw-r--r--src/lib/libcrypto/sha/sha256_amd64_generic.S104
1 files changed, 53 insertions, 51 deletions
diff --git a/src/lib/libcrypto/sha/sha256_amd64_generic.S b/src/lib/libcrypto/sha/sha256_amd64_generic.S
index 52ad974eab..f74af0b145 100644
--- a/src/lib/libcrypto/sha/sha256_amd64_generic.S
+++ b/src/lib/libcrypto/sha/sha256_amd64_generic.S
@@ -1,4 +1,4 @@
1/* $OpenBSD: sha256_amd64_generic.S,v 1.6 2026/03/28 13:11:28 jsing Exp $ */ 1/* $OpenBSD: sha256_amd64_generic.S,v 1.7 2026/05/07 15:38:03 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2024 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2024 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -17,6 +17,8 @@
17 17
18#include "crypto_assembly.h" 18#include "crypto_assembly.h"
19 19
20#define _SEP CRYPTO_ASSEMBLY_SEPARATOR
21
20#define ctx %rdi 22#define ctx %rdi
21#define in %rsi 23#define in %rsi
22#define num %rdx 24#define num %rdx
@@ -45,8 +47,8 @@
45 * Wt = Mt 47 * Wt = Mt
46 */ 48 */
47#define sha256_message_schedule_load(idx, m, w, wt) \ 49#define sha256_message_schedule_load(idx, m, w, wt) \
48 movl (m, round, 4), wt; \ 50 movl (m, round, 4), wt _SEP \
49 bswapl wt; \ 51 bswapl wt _SEP \
50 movl wt, ((idx&0xf)*4)(w) 52 movl wt, ((idx&0xf)*4)(w)
51 53
52/* 54/*
@@ -58,25 +60,25 @@
58 * sigma1(x) = ror(x, 17) ^ ror(x, 19) ^ (x >> 10) 60 * sigma1(x) = ror(x, 17) ^ ror(x, 19) ^ (x >> 10)
59 */ 61 */
60#define sha256_message_schedule_update(idx, w, wt) \ 62#define sha256_message_schedule_update(idx, w, wt) \
61 movl (((idx-2)&0xf)*4)(w), wt; /* sigma1 */ \ 63 movl (((idx-2)&0xf)*4)(w), wt /* sigma1 */ _SEP \
62 movl wt, tmp1; /* sigma1 */ \ 64 movl wt, tmp1 /* sigma1 */ _SEP \
63 rorl $(19-17), tmp1; /* sigma1 */ \ 65 rorl $(19-17), tmp1 /* sigma1 */ _SEP \
64 xorl wt, tmp1; /* sigma1 */ \ 66 xorl wt, tmp1 /* sigma1 */ _SEP \
65 rorl $17, tmp1; /* sigma1 */ \ 67 rorl $17, tmp1 /* sigma1 */ _SEP \
66 shrl $10, wt; /* sigma1 */ \ 68 shrl $10, wt /* sigma1 */ _SEP \
67 xorl tmp1, wt; /* sigma1 */ \ 69 xorl tmp1, wt /* sigma1 */ _SEP \
68 \ 70 \
69 addl (((idx-7)&0xf)*4)(w), wt; /* Wt-7 */ \ 71 addl (((idx-7)&0xf)*4)(w), wt /* Wt-7 */ _SEP \
70 addl (((idx-16)&0xf)*4)(w), wt; /* Wt-16 */ \ 72 addl (((idx-16)&0xf)*4)(w), wt /* Wt-16 */ _SEP \
71 \ 73 \
72 movl (((idx-15)&0xf)*4)(w), tmp2; /* sigma0 */ \ 74 movl (((idx-15)&0xf)*4)(w), tmp2 /* sigma0 */ _SEP \
73 movl tmp2, tmp3; /* sigma0 */ \ 75 movl tmp2, tmp3 /* sigma0 */ _SEP \
74 rorl $(18-7), tmp2; /* sigma0 */ \ 76 rorl $(18-7), tmp2 /* sigma0 */ _SEP \
75 xorl tmp3, tmp2; /* sigma0 */ \ 77 xorl tmp3, tmp2 /* sigma0 */ _SEP \
76 rorl $7, tmp2; /* sigma0 */ \ 78 rorl $7, tmp2 /* sigma0 */ _SEP \
77 shrl $3, tmp3; /* sigma0 */ \ 79 shrl $3, tmp3 /* sigma0 */ _SEP \
78 xorl tmp3, tmp2; /* sigma0 */ \ 80 xorl tmp3, tmp2 /* sigma0 */ _SEP \
79 addl tmp2, wt; /* sigma0 */ \ 81 addl tmp2, wt /* sigma0 */ _SEP \
80 \ 82 \
81 movl wt, ((idx&0xf)*4)(w) 83 movl wt, ((idx&0xf)*4)(w)
82 84
@@ -94,49 +96,49 @@
94 * Upon completion d = d + T1, h = T1 + T2, pending rotation. 96 * Upon completion d = d + T1, h = T1 + T2, pending rotation.
95 */ 97 */
96#define sha256_round(idx, a, b, c, d, e, f, g, h, k, w, wt) \ 98#define sha256_round(idx, a, b, c, d, e, f, g, h, k, w, wt) \
97 addl wt, h; /* T1 Wt */ \ 99 addl wt, h /* T1 Wt */ _SEP \
98 addl (k256, round, 4), h; /* T1 Kt */ \ 100 addl (k256, round, 4), h /* T1 Kt */ _SEP \
99 \ 101 \
100 movl e, tmp1; /* T1 Sigma1 */ \ 102 movl e, tmp1 /* T1 Sigma1 */ _SEP \
101 rorl $(25-11), tmp1; /* T1 Sigma1 */ \ 103 rorl $(25-11), tmp1 /* T1 Sigma1 */ _SEP \
102 xorl e, tmp1; /* T1 Sigma1 */ \ 104 xorl e, tmp1 /* T1 Sigma1 */ _SEP \
103 rorl $(11-6), tmp1; /* T1 Sigma1 */ \ 105 rorl $(11-6), tmp1 /* T1 Sigma1 */ _SEP \
104 xorl e, tmp1; /* T1 Sigma1 */ \ 106 xorl e, tmp1 /* T1 Sigma1 */ _SEP \
105 rorl $6, tmp1; /* T1 Sigma1 */ \ 107 rorl $6, tmp1 /* T1 Sigma1 */ _SEP \
106 addl tmp1, h; /* T1 Sigma1 */ \ 108 addl tmp1, h /* T1 Sigma1 */ _SEP \
107 \ 109 \
108 movl f, tmp2; /* T1 Ch */ \ 110 movl f, tmp2 /* T1 Ch */ _SEP \
109 xorl g, tmp2; /* T1 Ch */ \ 111 xorl g, tmp2 /* T1 Ch */ _SEP \
110 andl e, tmp2; /* T1 Ch */ \ 112 andl e, tmp2 /* T1 Ch */ _SEP \
111 xorl g, tmp2; /* T1 Ch */ \ 113 xorl g, tmp2 /* T1 Ch */ _SEP \
112 addl tmp2, h; /* T1 Ch */ \ 114 addl tmp2, h /* T1 Ch */ _SEP \
113 \ 115 \
114 addl h, d; /* d += T1 */ \ 116 addl h, d /* d += T1 */ _SEP \
115 \ 117 \
116 movl a, tmp1; /* T2 Sigma0 */ \ 118 movl a, tmp1 /* T2 Sigma0 */ _SEP \
117 rorl $(22-13), tmp1; /* T2 Sigma0 */ \ 119 rorl $(22-13), tmp1 /* T2 Sigma0 */ _SEP \
118 xorl a, tmp1; /* T2 Sigma0 */ \ 120 xorl a, tmp1 /* T2 Sigma0 */ _SEP \
119 rorl $(13-2), tmp1; /* T2 Sigma0 */ \ 121 rorl $(13-2), tmp1 /* T2 Sigma0 */ _SEP \
120 xorl a, tmp1; /* T2 Sigma0 */ \ 122 xorl a, tmp1 /* T2 Sigma0 */ _SEP \
121 rorl $2, tmp1; /* T2 Sigma0 */ \ 123 rorl $2, tmp1 /* T2 Sigma0 */ _SEP \
122 addl tmp1, h; /* T2 Sigma0 */ \ 124 addl tmp1, h /* T2 Sigma0 */ _SEP \
123 \ 125 \
124 movl b, tmp2; /* T2 Maj */ \ 126 movl b, tmp2 /* T2 Maj */ _SEP \
125 xorl c, tmp2; /* T2 Maj */ \ 127 xorl c, tmp2 /* T2 Maj */ _SEP \
126 andl a, tmp2; /* T2 Maj */ \ 128 andl a, tmp2 /* T2 Maj */ _SEP \
127 movl b, tmp3; /* T2 Maj */ \ 129 movl b, tmp3 /* T2 Maj */ _SEP \
128 andl c, tmp3; /* T2 Maj */ \ 130 andl c, tmp3 /* T2 Maj */ _SEP \
129 xorl tmp2, tmp3; /* T2 Maj */ \ 131 xorl tmp2, tmp3 /* T2 Maj */ _SEP \
130 addl tmp3, h; /* T2 Maj */ \ 132 addl tmp3, h /* T2 Maj */ _SEP \
131 \ 133 \
132 addq $1, round 134 addq $1, round
133 135
134#define sha256_round_load(idx, a, b, c, d, e, f, g, h) \ 136#define sha256_round_load(idx, a, b, c, d, e, f, g, h) \
135 sha256_message_schedule_load(idx, in, %rsp, tmp0); \ 137 sha256_message_schedule_load(idx, in, %rsp, tmp0) _SEP \
136 sha256_round(idx, a, b, c, d, e, f, g, h, k256, %rsp, tmp0) 138 sha256_round(idx, a, b, c, d, e, f, g, h, k256, %rsp, tmp0)
137 139
138#define sha256_round_update(idx, a, b, c, d, e, f, g, h) \ 140#define sha256_round_update(idx, a, b, c, d, e, f, g, h) \
139 sha256_message_schedule_update(idx, %rsp, tmp0); \ 141 sha256_message_schedule_update(idx, %rsp, tmp0) _SEP \
140 sha256_round(idx, a, b, c, d, e, f, g, h, k256, %rsp, tmp0) 142 sha256_round(idx, a, b, c, d, e, f, g, h, k256, %rsp, tmp0)
141 143
142.section .text 144.section .text