Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. .global sha1_chunk
  2.  
  3. .text
  4. counter: .asciz "counter: %ld "
  5. w1: .asciz "w[i-3]: %ld "
  6. w2: .asciz "w[i-8]: %ld "
  7. w3: .asciz "w[i-14]: %ld "
  8. w4: .asciz "w[i-16]: %ld "
  9. xor: .asciz "XOR: %ld "
  10. lor: .asciz "ROTATE: %ld\n"
  11. offset: .asciz "OFFSET: %ld "
  12. address: .asciz "ADDRESS: %ld\n"
  13. test: .asciz "TEST: %ld\n"
  14.  
  15. # First parameter (rdi): address of h0
  16. # Second parameter (rsi): address of the first 32-bit word of an array of 80 32-bit words.
  17.  
  18. sha1_chunk:
  19. # Setting up subroutine
  20. pushq %rbp # Push the base pointer on the stack
  21. movq %rsp, %rbp # Put the stack pointer into rbp
  22.  
  23. pushq %rdi # -8
  24. pushq %rsi # -16
  25.  
  26. # Extend the 16 32-bit words into 80 32-bit words
  27. # for i from 16 to 79
  28. # w[i] = (w[i-3] xor w[i-8] xor w[i-14] xor w[i-16]) leftrotate 1
  29.  
  30. # Create memory space for loop counter
  31. pushq $16
  32.  
  33. loopextend:
  34. pushq %rdi
  35. pushq %rsi
  36. movq $0, %rax
  37. movq -24(%rbp), %rsi
  38. movq $counter, %rdi
  39. call printf
  40. popq %rsi
  41. popq %rdi
  42.  
  43. # w[i-3]
  44. movq -24(%rbp), %r9
  45. subq $3, %r9
  46. movq $4, %rax
  47. imulq %r9, %rax
  48. addq %rsi, %rax
  49. movl (%rax), %r9d # address of w[i-3] is now in %r9d
  50.  
  51. pushq %rdi
  52. pushq %rsi
  53. movq $0, %rax
  54. movl %r9d, %esi
  55. movq $w1, %rdi
  56. call printf
  57. popq %rsi
  58. popq %rdi
  59.  
  60. # w[i-8]
  61. movq -24(%rbp), %r10
  62. subq $8, %r10
  63. movq $4, %rax
  64. imulq %r10, %rax
  65. addq %rsi, %rax
  66. movl (%rax), %r10d # address of w[i-8] is now in %r10d
  67.  
  68. pushq %rdi
  69. pushq %rsi
  70. movq $0, %rax
  71. movl %r10d, %esi
  72. movq $w2, %rdi
  73. call printf
  74. popq %rsi
  75. popq %rdi
  76.  
  77. # w[i-14]
  78. movq -24(%rbp), %r11
  79. subq $14, %r11
  80. movq $4, %rax
  81. imulq %r11, %rax
  82. addq %rsi, %rax
  83. movl (%rax), %r11d # address of w[i-14] is now in %r11d
  84.  
  85. pushq %rdi
  86. pushq %rsi
  87. movq $0, %rax
  88. movl %r11d, %esi
  89. movq $w3, %rdi
  90. call printf
  91. popq %rsi
  92. popq %rdi
  93.  
  94. # w[i-16]
  95. movq -24(%rbp), %r12
  96. subq $16, %r12
  97. movq $4, %rax
  98. imulq %r12, %rax
  99. addq %rsi, %rax
  100. movl (%rax), %r12d # address of w[i-14] is now in %r12d
  101.  
  102. pushq %rdi
  103. pushq %rsi
  104. movq $0, %rax
  105. movl %r12d, %esi
  106. movq $w4, %rdi
  107. call printf
  108. popq %rsi
  109. popq %rdi
  110.  
  111. # xor's
  112. xorl %r9d, %r10d
  113. xorl %r10d, %r11d
  114. xorl %r11d, %r12d
  115.  
  116. # (w[i-3] xor w[i-8] xor w[i-14] xor w[i-16]) leftrotate 1
  117. rol %r12d
  118.  
  119. # Assign value
  120. movq $4, %rax
  121. imulq -24(%rbp), %rax
  122. addq %rsi, %rax
  123. movl %r12d, (%rax)
  124.  
  125. pushq %rdi
  126. pushq %rsi
  127. movq $0, %rax
  128. movl %r12d, %esi
  129. movq $lor, %rdi
  130. call printf
  131. popq %rsi
  132. popq %rdi
  133.  
  134. incq -24(%rbp)
  135. cmp $79, -24(%rbp)
  136. jle loopextend
  137.  
  138. # Print loop counter
  139.  
  140. movq $0, %rax
  141. movl 64(%rsi), %esi
  142. movq $test, %rdi
  143. call printf
  144.  
  145. # Cleaning up subroutine
  146. movq %rbp, %rsp
  147. popq %rbp
  148.  
  149. ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement