summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/sha/sha1_amd64_generic.S
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/sha/sha1_amd64_generic.S')
-rw-r--r--src/lib/libcrypto/sha/sha1_amd64_generic.S70
1 files changed, 36 insertions, 34 deletions
diff --git a/src/lib/libcrypto/sha/sha1_amd64_generic.S b/src/lib/libcrypto/sha/sha1_amd64_generic.S
index 57709c0a1f..a44bd2fdec 100644
--- a/src/lib/libcrypto/sha/sha1_amd64_generic.S
+++ b/src/lib/libcrypto/sha/sha1_amd64_generic.S
@@ -1,4 +1,4 @@
1/* $OpenBSD: sha1_amd64_generic.S,v 1.5 2026/03/28 13:11:28 jsing Exp $ */ 1/* $OpenBSD: sha1_amd64_generic.S,v 1.6 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
@@ -40,8 +42,8 @@
40 * Wt = Mt 42 * Wt = Mt
41 */ 43 */
42#define sha1_message_schedule_load(idx, m, w, wt) \ 44#define sha1_message_schedule_load(idx, m, w, wt) \
43 movl ((idx&0xf)*4)(m), wt; \ 45 movl ((idx&0xf)*4)(m), wt _SEP \
44 bswapl wt; \ 46 bswapl wt _SEP \
45 movl wt, ((idx&0xf)*4)(w) 47 movl wt, ((idx&0xf)*4)(w)
46 48
47/* 49/*
@@ -50,11 +52,11 @@
50 * W0 = rol(W13 ^ W8 ^ W2 ^ W0, 1) 52 * W0 = rol(W13 ^ W8 ^ W2 ^ W0, 1)
51 */ 53 */
52#define sha1_message_schedule_update(idx, w, wt) \ 54#define sha1_message_schedule_update(idx, w, wt) \
53 movl (((idx-3)&0xf)*4)(w), wt; /* W13 */ \ 55 movl (((idx-3)&0xf)*4)(w), wt /* W13 */ _SEP \
54 xorl (((idx-8)&0xf)*4)(w), wt; /* W8 */ \ 56 xorl (((idx-8)&0xf)*4)(w), wt /* W8 */ _SEP \
55 xorl (((idx-14)&0xf)*4)(w), wt; /* W2 */ \ 57 xorl (((idx-14)&0xf)*4)(w), wt /* W2 */ _SEP \
56 xorl (((idx)&0xf)*4)(w), wt; /* W0 */ \ 58 xorl (((idx)&0xf)*4)(w), wt /* W0 */ _SEP \
57 roll $1, wt; \ 59 roll $1, wt _SEP \
58 \ 60 \
59 movl wt, ((idx&0xf)*4)(w) 61 movl wt, ((idx&0xf)*4)(w)
60 62
@@ -69,13 +71,13 @@
69 * Upon completion b = rol(b, 30), e = T, pending rotation. 71 * Upon completion b = rol(b, 30), e = T, pending rotation.
70 */ 72 */
71#define sha1_round(a, b, c, d, e, kt, wt) \ 73#define sha1_round(a, b, c, d, e, kt, wt) \
72 leal kt(wt, e, 1), e; /* Kt + Wt */ \ 74 leal kt(wt, e, 1), e /* Kt + Wt */ _SEP \
73 \ 75 \
74 movl a, tmp1; /* rol(a, 5) */ \ 76 movl a, tmp1 /* rol(a, 5) */ _SEP \
75 roll $5, tmp1; \ 77 roll $5, tmp1 _SEP \
76 addl tmp1, e; \ 78 addl tmp1, e _SEP \
77 \ 79 \
78 roll $30, b; /* rol(b, 30) */ 80 roll $30, b /* rol(b, 30) */
79 81
80/* 82/*
81 * Compute a SHA-1 round with Ch: 83 * Compute a SHA-1 round with Ch:
@@ -87,11 +89,11 @@
87 * Upon completion b = rol(b, 30), e = T, pending rotation. 89 * Upon completion b = rol(b, 30), e = T, pending rotation.
88 */ 90 */
89#define sha1_round_ch(a, b, c, d, e, kt, wt) \ 91#define sha1_round_ch(a, b, c, d, e, kt, wt) \
90 movl c, tmp2; /* Ch */ \ 92 movl c, tmp2 /* Ch */ _SEP \
91 xorl d, tmp2; /* Ch */ \ 93 xorl d, tmp2 /* Ch */ _SEP \
92 andl b, tmp2; /* Ch */ \ 94 andl b, tmp2 /* Ch */ _SEP \
93 xorl d, tmp2; /* Ch */ \ 95 xorl d, tmp2 /* Ch */ _SEP \
94 addl tmp2, e; /* Ch */ \ 96 addl tmp2, e /* Ch */ _SEP \
95 \ 97 \
96 sha1_round(a, b, c, d, e, kt, wt) 98 sha1_round(a, b, c, d, e, kt, wt)
97 99
@@ -105,10 +107,10 @@
105 * Upon completion b = rol(b, 30), e = T, pending rotation. 107 * Upon completion b = rol(b, 30), e = T, pending rotation.
106 */ 108 */
107#define sha1_round_parity(a, b, c, d, e, kt, wt) \ 109#define sha1_round_parity(a, b, c, d, e, kt, wt) \
108 movl b, tmp2; /* Parity */ \ 110 movl b, tmp2 /* Parity */ _SEP \
109 xorl c, tmp2; /* Parity */ \ 111 xorl c, tmp2 /* Parity */ _SEP \
110 xorl d, tmp2; /* Parity */ \ 112 xorl d, tmp2 /* Parity */ _SEP \
111 addl tmp2, e; /* Parity */ \ 113 addl tmp2, e /* Parity */ _SEP \
112 \ 114 \
113 sha1_round(a, b, c, d, e, kt, wt) 115 sha1_round(a, b, c, d, e, kt, wt)
114 116
@@ -122,34 +124,34 @@
122 * Upon completion b = rol(b, 30), e = T, pending rotation. 124 * Upon completion b = rol(b, 30), e = T, pending rotation.
123 */ 125 */
124#define sha1_round_maj(a, b, c, d, e, kt, wt) \ 126#define sha1_round_maj(a, b, c, d, e, kt, wt) \
125 movl c, tmp2; /* Maj */ \ 127 movl c, tmp2 /* Maj */ _SEP \
126 xorl d, tmp2; /* Maj */ \ 128 xorl d, tmp2 /* Maj */ _SEP \
127 andl b, tmp2; /* Maj */ \ 129 andl b, tmp2 /* Maj */ _SEP \
128 movl c, tmp3; /* Maj */ \ 130 movl c, tmp3 /* Maj */ _SEP \
129 andl d, tmp3; /* Maj */ \ 131 andl d, tmp3 /* Maj */ _SEP \
130 xorl tmp2, tmp3; /* Maj */ \ 132 xorl tmp2, tmp3 /* Maj */ _SEP \
131 addl tmp3, e; /* Maj */ \ 133 addl tmp3, e /* Maj */ _SEP \
132 \ 134 \
133 sha1_round(a, b, c, d, e, kt, wt) 135 sha1_round(a, b, c, d, e, kt, wt)
134 136
135#define sha1_round1_load(idx, a, b, c, d, e) \ 137#define sha1_round1_load(idx, a, b, c, d, e) \
136 sha1_message_schedule_load(idx, in, %rsp, tmp0); \ 138 sha1_message_schedule_load(idx, in, %rsp, tmp0) _SEP \
137 sha1_round_ch(a, b, c, d, e, 0x5a827999, tmp0) 139 sha1_round_ch(a, b, c, d, e, 0x5a827999, tmp0)
138 140
139#define sha1_round1_update(idx, a, b, c, d, e) \ 141#define sha1_round1_update(idx, a, b, c, d, e) \
140 sha1_message_schedule_update(idx, %rsp, tmp0); \ 142 sha1_message_schedule_update(idx, %rsp, tmp0) _SEP \
141 sha1_round_ch(a, b, c, d, e, 0x5a827999, tmp0) 143 sha1_round_ch(a, b, c, d, e, 0x5a827999, tmp0)
142 144
143#define sha1_round2_update(idx, a, b, c, d, e) \ 145#define sha1_round2_update(idx, a, b, c, d, e) \
144 sha1_message_schedule_update(idx, %rsp, tmp0); \ 146 sha1_message_schedule_update(idx, %rsp, tmp0) _SEP \
145 sha1_round_parity(a, b, c, d, e, 0x6ed9eba1, tmp0) 147 sha1_round_parity(a, b, c, d, e, 0x6ed9eba1, tmp0)
146 148
147#define sha1_round3_update(idx, a, b, c, d, e) \ 149#define sha1_round3_update(idx, a, b, c, d, e) \
148 sha1_message_schedule_update(idx, %rsp, tmp0); \ 150 sha1_message_schedule_update(idx, %rsp, tmp0) _SEP \
149 sha1_round_maj(a, b, c, d, e, 0x8f1bbcdc, tmp0) 151 sha1_round_maj(a, b, c, d, e, 0x8f1bbcdc, tmp0)
150 152
151#define sha1_round4_update(idx, a, b, c, d, e) \ 153#define sha1_round4_update(idx, a, b, c, d, e) \
152 sha1_message_schedule_update(idx, %rsp, tmp0); \ 154 sha1_message_schedule_update(idx, %rsp, tmp0) _SEP \
153 sha1_round_parity(a, b, c, d, e, 0xca62c1d6, tmp0) 155 sha1_round_parity(a, b, c, d, e, 0xca62c1d6, tmp0)
154 156
155.section .text 157.section .text