Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .global sha1_chunk
- .text
- counter: .asciz "counter: %ld "
- w1: .asciz "w[i-3]: %ld "
- w2: .asciz "w[i-8]: %ld "
- w3: .asciz "w[i-14]: %ld "
- w4: .asciz "w[i-16]: %ld "
- xor: .asciz "XOR: %ld "
- lor: .asciz "ROTATE: %ld\n"
- offset: .asciz "OFFSET: %ld "
- address: .asciz "ADDRESS: %ld\n"
- test: .asciz "TEST: %ld\n"
- # First parameter (rdi): address of h0
- # Second parameter (rsi): address of the first 32-bit word of an array of 80 32-bit words.
- sha1_chunk:
- # Setting up subroutine
- pushq %rbp # Push the base pointer on the stack
- movq %rsp, %rbp # Put the stack pointer into rbp
- pushq %rdi # -8
- pushq %rsi # -16
- # Extend the 16 32-bit words into 80 32-bit words
- # for i from 16 to 79
- # w[i] = (w[i-3] xor w[i-8] xor w[i-14] xor w[i-16]) leftrotate 1
- # Create memory space for loop counter
- pushq $16
- loopextend:
- pushq %rdi
- pushq %rsi
- movq $0, %rax
- movq -24(%rbp), %rsi
- movq $counter, %rdi
- call printf
- popq %rsi
- popq %rdi
- # w[i-3]
- movq -24(%rbp), %r9
- subq $3, %r9
- movq $4, %rax
- imulq %r9, %rax
- addq %rsi, %rax
- movl (%rax), %r9d # address of w[i-3] is now in %r9d
- pushq %rdi
- pushq %rsi
- movq $0, %rax
- movl %r9d, %esi
- movq $w1, %rdi
- call printf
- popq %rsi
- popq %rdi
- # w[i-8]
- movq -24(%rbp), %r10
- subq $8, %r10
- movq $4, %rax
- imulq %r10, %rax
- addq %rsi, %rax
- movl (%rax), %r10d # address of w[i-8] is now in %r10d
- pushq %rdi
- pushq %rsi
- movq $0, %rax
- movl %r10d, %esi
- movq $w2, %rdi
- call printf
- popq %rsi
- popq %rdi
- # w[i-14]
- movq -24(%rbp), %r11
- subq $14, %r11
- movq $4, %rax
- imulq %r11, %rax
- addq %rsi, %rax
- movl (%rax), %r11d # address of w[i-14] is now in %r11d
- pushq %rdi
- pushq %rsi
- movq $0, %rax
- movl %r11d, %esi
- movq $w3, %rdi
- call printf
- popq %rsi
- popq %rdi
- # w[i-16]
- movq -24(%rbp), %r12
- subq $16, %r12
- movq $4, %rax
- imulq %r12, %rax
- addq %rsi, %rax
- movl (%rax), %r12d # address of w[i-14] is now in %r12d
- pushq %rdi
- pushq %rsi
- movq $0, %rax
- movl %r12d, %esi
- movq $w4, %rdi
- call printf
- popq %rsi
- popq %rdi
- # xor's
- xorl %r9d, %r10d
- xorl %r10d, %r11d
- xorl %r11d, %r12d
- # (w[i-3] xor w[i-8] xor w[i-14] xor w[i-16]) leftrotate 1
- rol %r12d
- # Assign value
- movq $4, %rax
- imulq -24(%rbp), %rax
- addq %rsi, %rax
- movl %r12d, (%rax)
- pushq %rdi
- pushq %rsi
- movq $0, %rax
- movl %r12d, %esi
- movq $lor, %rdi
- call printf
- popq %rsi
- popq %rdi
- incq -24(%rbp)
- cmp $79, -24(%rbp)
- jle loopextend
- # Print loop counter
- movq $0, %rax
- movl 64(%rsi), %esi
- movq $test, %rdi
- call printf
- # Cleaning up subroutine
- movq %rbp, %rsp
- popq %rbp
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement