clarify the purpose of this project
[nyanglibc.git] / crypt / sha256.s
blob2f5ca8ce31253e6d91121174e0ea904b36e00bc8
1 .text
2 .p2align 4,,15
3 .globl __sha256_init_ctx
4 .type __sha256_init_ctx, @function
5 __sha256_init_ctx:
6 movabsq $-4942790177982912921, %rax
7 movq $0, 32(%rdi)
8 movl $0, 40(%rdi)
9 movq %rax, (%rdi)
10 movabsq $-6534734903820487822, %rax
11 movq %rax, 8(%rdi)
12 movabsq $-7276294671082564993, %rax
13 movq %rax, 16(%rdi)
14 movabsq $6620516960021240235, %rax
15 movq %rax, 24(%rdi)
16 ret
17 .size __sha256_init_ctx, .-__sha256_init_ctx
18 .p2align 4,,15
19 .globl __sha256_process_block
20 .type __sha256_process_block, @function
21 __sha256_process_block:
22 pushq %r15
23 pushq %r14
24 pushq %r13
25 pushq %r12
26 pushq %rbp
27 pushq %rbx
28 movq %rsi, %rbx
29 shrq $2, %rbx
30 subq $208, %rsp
31 addq %rsi, 32(%rdx)
32 testq %rbx, %rbx
33 movq %rdi, -88(%rsp)
34 movl (%rdx), %edi
35 movq %rdx, -64(%rsp)
36 movq %rbx, -80(%rsp)
37 movl %edi, -108(%rsp)
38 movl 4(%rdx), %edi
39 movl %edi, -104(%rsp)
40 movl 8(%rdx), %edi
41 movl %edi, -100(%rsp)
42 movl 12(%rdx), %edi
43 movl %edi, -112(%rsp)
44 movl 16(%rdx), %edi
45 movl %edi, -96(%rsp)
46 movl 20(%rdx), %edi
47 movl %edi, -116(%rsp)
48 movl 24(%rdx), %edi
49 movl %edi, -92(%rsp)
50 movl 28(%rdx), %edi
51 movl %edi, -120(%rsp)
52 je .L4
53 leaq -56(%rsp), %r14
54 leaq K(%rip), %r15
55 leaq 192(%r14), %rax
56 movq %rax, -72(%rsp)
57 .p2align 4,,10
58 .p2align 3
59 .L9:
60 movq -88(%rsp), %rcx
61 xorl %eax, %eax
62 .p2align 4,,10
63 .p2align 3
64 .L5:
65 movl (%rcx,%rax), %edx
66 bswap %edx
67 movl %edx, (%r14,%rax)
68 addq $4, %rax
69 cmpq $64, %rax
70 jne .L5
71 addq $64, -88(%rsp)
72 movq -72(%rsp), %rdi
73 movq %r14, %rsi
74 .p2align 4,,10
75 .p2align 3
76 .L6:
77 movl 56(%rsi), %eax
78 movl 4(%rsi), %ecx
79 addq $4, %rsi
80 movl %eax, %edx
81 movl %eax, %r8d
82 shrl $10, %eax
83 roll $13, %r8d
84 roll $15, %edx
85 xorl %r8d, %edx
86 movl %ecx, %r8d
87 xorl %eax, %edx
88 movl -4(%rsi), %eax
89 addl 32(%rsi), %eax
90 roll $14, %r8d
91 addl %eax, %edx
92 movl %ecx, %eax
93 shrl $3, %ecx
94 rorl $7, %eax
95 xorl %r8d, %eax
96 xorl %ecx, %eax
97 addl %edx, %eax
98 movl %eax, 60(%rsi)
99 cmpq %rsi, %rdi
100 jne .L6
101 movl -120(%rsp), %eax
102 movl -92(%rsp), %ebx
103 xorl %r9d, %r9d
104 movl -116(%rsp), %ebp
105 movl -96(%rsp), %edi
106 movl $1116352408, %r12d
107 movl -112(%rsp), %r13d
108 movl -100(%rsp), %r10d
109 movl -104(%rsp), %r11d
110 movl -108(%rsp), %r8d
111 movl %eax, %esi
112 jmp .L8
113 .p2align 4,,10
114 .p2align 3
115 .L17:
116 movl (%r15,%r9), %r12d
117 movl %r10d, %r13d
118 movl %ebx, %esi
119 movl %r11d, %r10d
120 movl %ebp, %ebx
121 movl %r8d, %r11d
122 movl %edi, %ebp
123 movl %eax, %r8d
124 movl %ecx, %edi
125 .L8:
126 movl %edi, %eax
127 movl %edi, %edx
128 movl %edi, %ecx
129 rorl $11, %edx
130 rorl $6, %eax
131 andl %ebp, %ecx
132 xorl %edx, %eax
133 movl %edi, %edx
134 roll $7, %edx
135 xorl %eax, %edx
136 movl %edi, %eax
137 notl %eax
138 andl %ebx, %eax
139 xorl %ecx, %eax
140 movl %r8d, %ecx
141 addl %edx, %eax
142 movl %r8d, %edx
143 addl (%r14,%r9), %eax
144 rorl $13, %ecx
145 rorl $2, %edx
146 addq $4, %r9
147 xorl %ecx, %edx
148 movl %r8d, %ecx
149 roll $10, %ecx
150 xorl %edx, %ecx
151 movl %r11d, %edx
152 addl %esi, %eax
153 xorl %r10d, %edx
154 movl %r11d, %esi
155 addl %r12d, %eax
156 andl %r8d, %edx
157 andl %r10d, %esi
158 xorl %esi, %edx
159 addl %ecx, %edx
160 leal (%rax,%r13), %ecx
161 addl %edx, %eax
162 cmpq $256, %r9
163 jne .L17
164 addl %eax, -108(%rsp)
165 addl %r8d, -104(%rsp)
166 addl %r11d, -100(%rsp)
167 addl %r10d, -112(%rsp)
168 addl %ecx, -96(%rsp)
169 addl %edi, -116(%rsp)
170 addl %ebp, -92(%rsp)
171 addl %ebx, -120(%rsp)
172 subq $16, -80(%rsp)
173 jne .L9
174 .L4:
175 movq -64(%rsp), %rax
176 movl -108(%rsp), %ebx
177 movl %ebx, (%rax)
178 movl -104(%rsp), %ebx
179 movl %ebx, 4(%rax)
180 movl -100(%rsp), %ebx
181 movl %ebx, 8(%rax)
182 movl -112(%rsp), %ebx
183 movl %ebx, 12(%rax)
184 movl -96(%rsp), %ebx
185 movl %ebx, 16(%rax)
186 movl -116(%rsp), %ebx
187 movl %ebx, 20(%rax)
188 movl -92(%rsp), %ebx
189 movl %ebx, 24(%rax)
190 movl -120(%rsp), %ebx
191 movl %ebx, 28(%rax)
192 addq $208, %rsp
193 popq %rbx
194 popq %rbp
195 popq %r12
196 popq %r13
197 popq %r14
198 popq %r15
200 .size __sha256_process_block, .-__sha256_process_block
201 .p2align 4,,15
202 .globl __sha256_finish_ctx
203 .type __sha256_finish_ctx, @function
204 __sha256_finish_ctx:
205 pushq %r13
206 pushq %r12
207 pushq %rbp
208 pushq %rbx
209 movq %rsi, %rbp
210 movq %rdi, %rbx
211 subq $8, %rsp
212 movl 40(%rdi), %r12d
213 addq %r12, 32(%rdi)
214 cmpl $55, %r12d
215 jbe .L19
216 movl $120, %r13d
217 subl %r12d, %r13d
218 .L20:
219 leaq 48(%rbx,%r12), %rdi
220 leaq fillbuf(%rip), %rsi
221 movq %r13, %rdx
222 addq %r13, %r12
223 call memcpy@PLT
224 movq 32(%rbx), %rax
225 movq %r12, %rdx
226 leaq 8(%r12), %rsi
227 shrq $3, %rdx
228 leaq 48(%rbx), %rdi
229 salq $3, %rax
230 bswap %rax
231 movq %rax, 48(%rbx,%rdx,8)
232 movq %rbx, %rdx
233 call __sha256_process_block
234 xorl %eax, %eax
235 .p2align 4,,10
236 .p2align 3
237 .L21:
238 movl (%rbx,%rax), %edx
239 bswap %edx
240 movl %edx, 0(%rbp,%rax)
241 addq $4, %rax
242 cmpq $32, %rax
243 jne .L21
244 addq $8, %rsp
245 movq %rbp, %rax
246 popq %rbx
247 popq %rbp
248 popq %r12
249 popq %r13
251 .p2align 4,,10
252 .p2align 3
253 .L19:
254 movl $56, %r13d
255 subl %r12d, %r13d
256 jmp .L20
257 .size __sha256_finish_ctx, .-__sha256_finish_ctx
258 .p2align 4,,15
259 .globl __sha256_process_bytes
260 .type __sha256_process_bytes, @function
261 __sha256_process_bytes:
262 pushq %r15
263 pushq %r14
264 pushq %r13
265 pushq %r12
266 movq %rdi, %r12
267 pushq %rbp
268 pushq %rbx
269 movq %rdx, %rbp
270 movq %rsi, %rbx
271 subq $8, %rsp
272 movl 40(%rdx), %eax
273 testl %eax, %eax
274 jne .L63
275 .L25:
276 cmpq $63, %rbx
277 ja .L64
278 .L33:
279 testq %rbx, %rbx
280 jne .L65
281 addq $8, %rsp
282 popq %rbx
283 popq %rbp
284 popq %r12
285 popq %r13
286 popq %r14
287 popq %r15
289 .p2align 4,,10
290 .p2align 3
291 .L65:
292 movl 40(%rbp), %esi
293 cmpl $8, %ebx
294 movl %ebx, %eax
295 leaq 48(%rbp,%rsi), %rcx
296 jnb .L35
297 testb $4, %bl
298 jne .L66
299 testl %ebx, %ebx
300 je .L36
301 movzbl (%r12), %edx
302 testb $2, %al
303 movb %dl, (%rcx)
304 jne .L67
305 .L36:
306 addq %rsi, %rbx
307 cmpq $63, %rbx
308 jbe .L41
309 leaq 48(%rbp), %r12
310 movq %rbp, %rdx
311 movl $64, %esi
312 subq $64, %rbx
313 movq %r12, %rdi
314 call __sha256_process_block
315 leaq 112(%rbp), %rsi
316 movq %rbx, %rdx
317 movq %r12, %rdi
318 call memcpy@PLT
319 .L41:
320 movl %ebx, 40(%rbp)
321 addq $8, %rsp
322 popq %rbx
323 popq %rbp
324 popq %r12
325 popq %r13
326 popq %r14
327 popq %r15
329 .p2align 4,,10
330 .p2align 3
331 .L64:
332 movq %rbx, %r13
333 movq %r12, %rdi
334 movq %rbp, %rdx
335 andq $-64, %r13
336 andl $63, %ebx
337 movq %r13, %rsi
338 addq %r13, %r12
339 call __sha256_process_block
340 jmp .L33
341 .p2align 4,,10
342 .p2align 3
343 .L63:
344 movl %eax, %r13d
345 movl $128, %edx
346 subq %r13, %rdx
347 leaq 48(%rbp,%r13), %rdi
348 cmpq %rsi, %rdx
349 cmova %rsi, %rdx
350 movq %r12, %rsi
351 movq %rdx, %r14
352 call memcpy@PLT
353 movl 40(%rbp), %esi
354 addl %r14d, %esi
355 cmpl $64, %esi
356 movl %esi, 40(%rbp)
357 ja .L68
358 .L26:
359 addq %r14, %r12
360 subq %r14, %rbx
361 jmp .L25
362 .p2align 4,,10
363 .p2align 3
364 .L35:
365 movq (%r12), %rax
366 movq %rax, (%rcx)
367 movl %ebx, %eax
368 movq -8(%r12,%rax), %rdx
369 movq %rdx, -8(%rcx,%rax)
370 leaq 8(%rcx), %rdx
371 andq $-8, %rdx
372 subq %rdx, %rcx
373 leal (%rbx,%rcx), %eax
374 subq %rcx, %r12
375 andl $-8, %eax
376 cmpl $8, %eax
377 jb .L36
378 andl $-8, %eax
379 xorl %ecx, %ecx
380 .L39:
381 movl %ecx, %edi
382 addl $8, %ecx
383 movq (%r12,%rdi), %r8
384 cmpl %eax, %ecx
385 movq %r8, (%rdx,%rdi)
386 jb .L39
387 jmp .L36
388 .p2align 4,,10
389 .p2align 3
390 .L68:
391 leaq 48(%rbp), %r15
392 andl $-64, %esi
393 movq %rbp, %rdx
394 movq %r15, %rdi
395 call __sha256_process_block
396 movl 40(%rbp), %ecx
397 leaq 0(%r13,%r14), %rax
398 andq $-64, %rax
399 movl %ecx, %edx
400 leaq 48(%rbp,%rax), %rax
401 andl $63, %edx
402 cmpl $8, %edx
403 movl %edx, 40(%rbp)
404 jnb .L27
405 testb $4, %cl
406 jne .L69
407 testl %edx, %edx
408 je .L26
409 movzbl (%rax), %esi
410 andl $2, %ecx
411 movb %sil, 48(%rbp)
412 je .L26
413 movzwl -2(%rax,%rdx), %eax
414 movw %ax, -2(%r15,%rdx)
415 jmp .L26
416 .p2align 4,,10
417 .p2align 3
418 .L27:
419 movq (%rax), %rcx
420 movq %rcx, 48(%rbp)
421 movl %edx, %ecx
422 movq -8(%rax,%rcx), %rsi
423 movq %rsi, -8(%r15,%rcx)
424 leaq 56(%rbp), %rcx
425 andq $-8, %rcx
426 subq %rcx, %r15
427 addl %r15d, %edx
428 subq %r15, %rax
429 andl $-8, %edx
430 cmpl $8, %edx
431 jb .L26
432 andl $-8, %edx
433 xorl %esi, %esi
434 .L31:
435 movl %esi, %edi
436 addl $8, %esi
437 movq (%rax,%rdi), %r8
438 cmpl %edx, %esi
439 movq %r8, (%rcx,%rdi)
440 jb .L31
441 jmp .L26
442 .L69:
443 movl (%rax), %ecx
444 movl %ecx, 48(%rbp)
445 movl -4(%rax,%rdx), %eax
446 movl %eax, -4(%r15,%rdx)
447 jmp .L26
448 .p2align 4,,10
449 .p2align 3
450 .L66:
451 movl (%r12), %edx
452 movl %edx, (%rcx)
453 movl %ebx, %edx
454 movl -4(%r12,%rdx), %eax
455 movl %eax, -4(%rcx,%rdx)
456 jmp .L36
457 .L67:
458 movl %ebx, %edx
459 movzwl -2(%r12,%rdx), %eax
460 movw %ax, -2(%rcx,%rdx)
461 jmp .L36
462 .size __sha256_process_bytes, .-__sha256_process_bytes
463 .section .rodata
464 .align 32
465 .type K, @object
466 .size K, 256
468 .long 1116352408
469 .long 1899447441
470 .long -1245643825
471 .long -373957723
472 .long 961987163
473 .long 1508970993
474 .long -1841331548
475 .long -1424204075
476 .long -670586216
477 .long 310598401
478 .long 607225278
479 .long 1426881987
480 .long 1925078388
481 .long -2132889090
482 .long -1680079193
483 .long -1046744716
484 .long -459576895
485 .long -272742522
486 .long 264347078
487 .long 604807628
488 .long 770255983
489 .long 1249150122
490 .long 1555081692
491 .long 1996064986
492 .long -1740746414
493 .long -1473132947
494 .long -1341970488
495 .long -1084653625
496 .long -958395405
497 .long -710438585
498 .long 113926993
499 .long 338241895
500 .long 666307205
501 .long 773529912
502 .long 1294757372
503 .long 1396182291
504 .long 1695183700
505 .long 1986661051
506 .long -2117940946
507 .long -1838011259
508 .long -1564481375
509 .long -1474664885
510 .long -1035236496
511 .long -949202525
512 .long -778901479
513 .long -694614492
514 .long -200395387
515 .long 275423344
516 .long 430227734
517 .long 506948616
518 .long 659060556
519 .long 883997877
520 .long 958139571
521 .long 1322822218
522 .long 1537002063
523 .long 1747873779
524 .long 1955562222
525 .long 2024104815
526 .long -2067236844
527 .long -1933114872
528 .long -1866530822
529 .long -1538233109
530 .long -1090935817
531 .long -965641998
532 .align 32
533 .type fillbuf, @object
534 .size fillbuf, 64
535 fillbuf:
536 .byte -128
537 .byte 0
538 .zero 62