1 C x86_64/sha512-compress.asm
4 Copyright (C) 2013 Niels Möller
6 This file is part of GNU Nettle.
8 GNU Nettle is free software: you can redistribute it and/or
9 modify it under the terms of either:
11 * the GNU Lesser General Public License as published by the Free
12 Software Foundation; either version 3 of the License, or (at your
13 option) any later version.
17 * the GNU General Public License as published by the Free
18 Software Foundation; either version 2 of the License, or (at your
19 option) any later version.
21 or both in parallel, as here.
23 GNU Nettle is distributed in the hope that it will be useful,
24 but WITHOUT ANY WARRANTY; without even the implied warranty of
25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 General Public License for more details.
28 You should have received copies of the GNU General Public License and
29 the GNU Lesser General Public License along with this program. If
30 not, see http://www.gnu.org/licenses/.
33 .file "sha512-compress.asm"
34 define(<STATE>, <%rdi>)
35 define(<INPUT>, <%rsi>)
46 define(<T1>, <%rdi>) C Overlap STATE
47 define(<COUNT>, <%r14>)
51 mov OFFSET64($1)(%rsp), W
52 mov OFFSET64(eval(($1 + 14) % 16))(%rsp), T0
60 mov OFFSET64(eval(($1 + 1) % 16))(%rsp), T0
68 add OFFSET64(eval(($1 + 9) % 16))(%rsp), W
69 mov W, OFFSET64($1)(%rsp)
72 C ROUND(A,B,C,D,E,F,G,H,K)
74 C H += S1(E) + Choice(E,F,G) + K + W
76 C H += S0(A) + Majority(A,B,C)
80 C S1(E) = E<<<50 ^ E<<<46 ^ E<<<23
81 C S0(A) = A<<<36 ^ A<<<30 ^ A<<<25
82 C Choice (E, F, G) = G^(E&(F^G))
83 C Majority (A,B,C) = (A&B) + (C&(A^B))
99 add OFFSET64($9)(K,COUNT,8), $8
121 mov OFFSET64($1)(INPUT, COUNT, 8), W
123 mov W, OFFSET64($1)(%rsp, COUNT, 8)
127 C _nettle_sha512_compress(uint64_t *state, const uint8_t *input, const uint64_t *k)
132 PROLOGUE(_nettle_sha512_compress)
137 mov STATE, 136(%rsp) C Save state, to free a register
156 NOEXPN(0) ROUND(SA,SB,SC,SD,SE,SF,SG,SH,0)
157 NOEXPN(1) ROUND(SH,SA,SB,SC,SD,SE,SF,SG,1)
158 NOEXPN(2) ROUND(SG,SH,SA,SB,SC,SD,SE,SF,2)
159 NOEXPN(3) ROUND(SF,SG,SH,SA,SB,SC,SD,SE,3)
160 NOEXPN(4) ROUND(SE,SF,SG,SH,SA,SB,SC,SD,4)
161 NOEXPN(5) ROUND(SD,SE,SF,SG,SH,SA,SB,SC,5)
162 NOEXPN(6) ROUND(SC,SD,SE,SF,SG,SH,SA,SB,6)
163 NOEXPN(7) ROUND(SB,SC,SD,SE,SF,SG,SH,SA,7)
169 EXPN( 0) ROUND(SA,SB,SC,SD,SE,SF,SG,SH,0)
170 EXPN( 1) ROUND(SH,SA,SB,SC,SD,SE,SF,SG,1)
171 EXPN( 2) ROUND(SG,SH,SA,SB,SC,SD,SE,SF,2)
172 EXPN( 3) ROUND(SF,SG,SH,SA,SB,SC,SD,SE,3)
173 EXPN( 4) ROUND(SE,SF,SG,SH,SA,SB,SC,SD,4)
174 EXPN( 5) ROUND(SD,SE,SF,SG,SH,SA,SB,SC,5)
175 EXPN( 6) ROUND(SC,SD,SE,SF,SG,SH,SA,SB,6)
176 EXPN( 7) ROUND(SB,SC,SD,SE,SF,SG,SH,SA,7)
177 EXPN( 8) ROUND(SA,SB,SC,SD,SE,SF,SG,SH,8)
178 EXPN( 9) ROUND(SH,SA,SB,SC,SD,SE,SF,SG,9)
179 EXPN(10) ROUND(SG,SH,SA,SB,SC,SD,SE,SF,10)
180 EXPN(11) ROUND(SF,SG,SH,SA,SB,SC,SD,SE,11)
181 EXPN(12) ROUND(SE,SF,SG,SH,SA,SB,SC,SD,12)
182 EXPN(13) ROUND(SD,SE,SF,SG,SH,SA,SB,SC,13)
183 EXPN(14) ROUND(SC,SD,SE,SF,SG,SH,SA,SB,14)
184 EXPN(15) ROUND(SB,SC,SD,SE,SF,SG,SH,SA,15)
210 EPILOGUE(_nettle_sha512_compress)